From 57a6476924edee315f43417c2253dc76f38e51c9 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 28 Apr 2020 16:04:21 -0400 Subject: [PATCH] Updated IRC Communication Module --- .gitignore | 8 ++++++- Modules/Func_Send_Capture_Complete.m | 2 +- Modules/Func_Send_Section_Statuses.m | 2 +- main.m | 11 +++++---- msgHandler.m | 36 +++++++++++++--------------- 5 files changed, 33 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index 21229f7..4d0415c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,7 @@ -*.asv \ No newline at end of file +*.asv +Data/RES101TrainedNET.mat +FSM.slx +FSM_grt_rtw/* +TCP_IP_Test.m +Test Packets/* +slprj/* \ No newline at end of file diff --git a/Modules/Func_Send_Capture_Complete.m b/Modules/Func_Send_Capture_Complete.m index 75c9d7b..fbd0540 100644 --- a/Modules/Func_Send_Capture_Complete.m +++ b/Modules/Func_Send_Capture_Complete.m @@ -2,7 +2,7 @@ function Func_Send_Capture_Complete(tcpConn) %FUNC_SEND_ROBOT_MSG Signals the robotics system that the image has been %captured. -bits = [true logical(zeros(1,63))]; +bits = [logical(zeros(1,63)) true]; % Convert bits to a uint8 (byte) array msg = uint8(bi2de(reshape(bits,8,[])','left-msb'))'; diff --git a/Modules/Func_Send_Section_Statuses.m b/Modules/Func_Send_Section_Statuses.m index edf1661..9839075 100644 --- a/Modules/Func_Send_Section_Statuses.m +++ b/Modules/Func_Send_Section_Statuses.m @@ -4,7 +4,7 @@ function Func_Send_Section_Statuses(tcpConn, sectionStatusRegister) % Right-Pad the section status register to a length of 63, and left-pad % with one zero (the camera done bit) -bits = [false, sectionStatusRegister, logical(zeros(1,63-length(sectionStatusRegister)))]; +bits = [logical(zeros(1,63-length(sectionStatusRegister))), flip(sectionStatusRegister), false]; % Convert bits to a uint8 (byte) array msg = uint8(bi2de(reshape(bits,8,[])','left-msb'))'; diff --git a/main.m b/main.m index 8ca5af2..fbfc7a1 100644 --- a/main.m +++ b/main.m @@ -12,6 +12,7 @@ %% Begin TCP Communication with the IRC tcpConn = tcpip(setup.IRC_IP_Address,setup.IRC_IP_Port) +%tcpConn.ByteOrder = 'littleEndian'; fsm.dataStore.tcpConn = tcpConn; fsm.dataStore.tcpSetup = setup; tcpConn.BytesAvailableFcn = {@msgRcv,fsm}; % Edit the callback function here @@ -34,9 +35,11 @@ function stepFSM(obj,event,fsm) function msgRcv(obj,event,fsm) % msgRcv: Event handler for receiving data from the robot - % Read data from the buffer - msgData = fread(obj,obj.BytesAvailable); - % Pass the relevant bytes along (last byte is message terminator) - msgHandler(msgData(1:end-1),fsm); + if(obj.BytesAvailable > 0) + % Read data from the buffer + msgData = fread(obj,obj.BytesAvailable); + % Pass the relevant bytes along (last byte is message terminator) + msgHandler(msgData(1:end-1),fsm); + end end \ No newline at end of file diff --git a/msgHandler.m b/msgHandler.m index 7659802..f17e1e0 100644 --- a/msgHandler.m +++ b/msgHandler.m @@ -2,34 +2,32 @@ function msgHandler(msgData,fsm) %MSGHANDLER Handles Robot-To-PC Messages % Robot-To-PC Status Packet % 0-Bit | 1-Bit | Name -% 1(LSB) Robot Ready Bit -% 2 Start Inspection Bit -% 3 Inspection Complete Bit +% 0-7 1-8 PoseID +% 8 9 Robot Ready Bit +% 9 10 Start Inspection Bit +% 10 11 Inspection Complete Bit - % Convert messaage bytes to bit array - msgBits = reshape(de2bi(uint8(msgData),'left-msb')',[],1)'; - - % Convert to bytes - msgByte = uint8(msgData(1)); + % Convert message bytes to bit array + msgBits = logical(reshape(de2bi(uint8(flip(msgData)),'right-msb',8)',[],1)'); %% Trigger events based on the incoming message data + % Start Inspection Bit + if(msgBits(10)) + fsm.ev_Req_Begin_Inspection(); + + % Inspection Complete Bit + elseif(msgBits(11)) + fsm.ev_Req_Complete_Inspection(); + % Robot Ready Bit (Capture Image) - if(bitand(uint8(1),msgByte,'uint8')) + elseif(msgBits(9)) % Pass the current PoseID to the FSM - fsm.curPoseID = bi2de(msgBits(3:10),'left-msb'); + fsm.curPoseID = uint8(msgData(2)); fsm.ev_Req_Image_Capture(); end - - % Inspection Complete Bit - if(bitand(uint8(4),msgByte)) - fsm.ev_Req_Complete_Inspection(); - end - % Start Inspection Bit - if(bitand(uint8(2),msgByte)) - fsm.ev_Req_Begin_Inspection(); - end + end