public MessageFields Copy() { MessageFields result = new MessageFields(); result.messageId = this.messageId; result.commandId = this.commandId; result.argument0 = this.argument0; result.argument1 = this.argument1; return(result); }
public static MessageFields ParsePacket(byte value) { MessageFields output = null; switch (parserState) { case 0: //look for the first magic byte '#' if (value == '#') { parserState = 1; } break; case 1: //look for the second magic byte '#' if (value == '#') { parserState = 2; } else { parserState = 0; } break; case 2: //save the message id parserMessageFields.messageId = (MessageId)value;; parserState = 3; break; case 3: //save the command id parserMessageFields.commandId = (CommandId)value;; parserState = 4; break; case 4: //save arg0 parserMessageFields.argument0 = value; parserState = 5; break; case 5: //save arg1 parserMessageFields.argument1 = value;; parserState = 6; break; case 6: //Check the checksum if (CalculateCheckSum(parserMessageFields) == value) { output = parserMessageFields.Copy(); } parserState = 0; break; } return(output); }
public static byte CalculateCheckSum(MessageFields messageFields) { byte iChkSum = 0; iChkSum += (byte)messageFields.messageId; iChkSum += (byte)messageFields.commandId; iChkSum += (byte)messageFields.argument0; iChkSum += (byte)messageFields.argument1; return(iChkSum); }