/// <summary> /// This method is used for parsing received data. /// </summary> protected static ResponseType ParseReceivedData(byte[] checkedData, UInt16 checksum, ref ReceivedData receivedData) { // Checking CRC. //var expectedCRC = CalcCRC(checkedData); var expectedCRC = BitConverter.ToUInt16(bytesU16CalcCRC(checkedData), 0); if (checksum != expectedCRC) { var message = string.Format("Invalid checksum {0}( expected {1}) for packet: {2}", checksum, expectedCRC, receivedData.Text); log.Warn(message); return(ResponseType.None); } // Read index data_pointer: UInt32 DataPointer = (UInt32)BitConverter.ToUInt64(checkedData, checkedData.Length - 8); // // Execute a COMMAND. // byte command = checkedData.First(); // if (command == Command.ANSWER) // { // // Determine address. // /* receivedData.Address = BitConverter.ToUInt32(checkedData, 1); */ // receivedData.Address = BitConverter.ToUInt16(checkedData, 1); // // Determine value - copy to byte array. // /* receivedData.Data = new byte[checkedData.Length - 5]; */ // receivedData.Data = new byte[checkedData.Length - 3]; // /* Array.Copy(checkedData, 5, receivedData.Data, 0, receivedData.Data.Length); */ // Array.Copy(checkedData, 3, receivedData.Data, 0, receivedData.Data.Length); // // return ResponseType.Answer; // } // else if (command == Command.WRITE_OK) // { // return ResponseType.WriteOk; // } // else if (command == Command.ERROR) // { // return ResponseType.Error; // } return(ResponseType.ParceOK); }