RECEIVE_MESSAGE: InBuffer = GetValue (_CF) IF (InBuffer > 0) THEN ID = GetValue (_CAN, 1) 'extract target, if target = toRoboteq handle confirmation handshage messages or handle incoming messages Target = ID AND 0b111 'target mask IF (Target = toRoboteq) THEN 'handle confirmation handshake messages (only for Fault and Status flags) IF (ID = RoboteqFault_confirm) THEN LastFaultFlags = FaultFlags ELSEIF (ID = RoboteqStatus_confirm) THEN LastStatusFlags = StatusFlags 'handle incoming messages: retrieve data and parse ID to get Category and Name, and set MsgReceived to TRUE ELSE 'probably not necessary, but clear old data out of array FOR i = 0 AndWhile (i <= 7) ReceivedData[i] = 0 NEXT 'extract data from message NumData = GetValue (_CAN, 2) IF (NumData > 0) THEN FOR i = 0 AndWhile (i <= NumData-1) 'changed from NumData so can't go out-of-range ReceivedData[i] = GetValue (_CAN, 3+i) NEXT END IF 'check for bit-wise complement integrity Pairs = NumData/2 Check = TRUE IF (Pairs > 0) THEN FOR i = 0 AndWhile (i <= Pairs-1) IF (ReceivedData[i] + ReceivedData[i+pairs] <> 0xFF) THEN check = false END IF IF (check = false) THEN EXIT FOR END IF NEXT END IF 'if all OK, extract Category and Name and set MsgReceived to TRUE IF (Check = TRUE) THEN Category = (ID >>9) AND 0b11 'category mask Name = (ID >> 3) AND 0b111111 'name mask MsgReceived = TRUE END IF END IF 'handling confirmation messages or END IF '(Target = toRoboteq) END IF '(InBuffer = TRUE) RETURN 'RECEIVE_MESSAGE