public void IsValid() { // Arrange var footer1 = new EnttecMessageFooter(); var footer2 = new EnttecMessageFooter(); // Act footer1.SetEndCodeByte(0x02); footer2.SetEndCodeByte(EnttecMessageFooter.EndCodeByte); // Assert Assert.False(footer1.IsValid()); Assert.True(footer2.IsValid()); }
public byte[] CreateMessage(ApplicationMessages messageType, byte[] messageData) { var header = new EnttecMessageHeader(); header.SetMessageType(messageType); header.SetDataLength(messageData.Length); var body = new EnttecMessageBody(messageData); var footer = new EnttecMessageFooter(); if (!header.IsValid() || !footer.IsValid()) { throw new ArgumentException("Invalid message data!"); } return(CreateMessageFromParts(header, body, footer)); }
private byte[] ReceiveInternal(ApplicationMessages messageType) { var startCode = new byte[1]; if (!_ftdiDriver.Read(startCode)) { return(null); } if (EnttecMessageHeader.StartCodeByte != startCode[0]) { return(null); } var byte1 = new byte[1]; var byte2 = new byte[1]; var byte3 = new byte[1]; if (!_ftdiDriver.Read(byte1)) { return(null); } if (!_ftdiDriver.Read(byte2)) { return(null); } if (!_ftdiDriver.Read(byte3)) { return(null); } if (byte1[0] != (byte)messageType) { return(null); } var header = new EnttecMessageHeader(new byte[] { startCode[0], byte1[0], byte2[0], byte3[0] }); if (!header.IsValid()) { return(null); } var body = new EnttecMessageBody(new byte[header.GetDataLength()]); if (!_ftdiDriver.Read(body.Data)) { return(null); } var footer = new EnttecMessageFooter(); if (!(_ftdiDriver.Read(footer.Data) & footer.IsValid())) { return(null); } return(body.Data); }