public V45Packet(byte[] indata, int start = 0, bool ignoreLength = false) { try { this.m_status = indata[start]; this.m_command = (V45Commands)indata[start + 1]; this.m_sender = indata[start + 2]; this.m_receiver = indata[start + 3]; this.m_length = BitConverter.ToUInt16(indata, start + 4); if (m_length != indata.Length && !ignoreLength) { throw new LengthException("Length error. Suggested: " + this.m_length.ToString() + " Received: " + indata.Length.ToString()); } this.m_payLoad = new byte[m_length - 8]; Array.Copy(indata, start + 6, m_payLoad, 0, m_length - 8); //.AddRange(indata.Skip(6).Take(this.Length - 8).ToArray()); CRC16CITT tmpCRC = new CRC16CITT(CRC16CITT.InitialCrcValue.Zeros); this.m_CRC = BitConverter.ToUInt16(indata, start + 6 + this.Payload.Length); UInt16 tmprc = tmpCRC.ComputeChecksum(indata.Skip(start).Take(this.Length - 2).ToArray()); if (this.m_CRC != tmprc)//steve--skip calibration commmand { throw new CrcException("CRC error. Computed: " + tmprc.ToString() + " Received: " + this.m_CRC.ToString()); } } catch (Exception) { throw; } }
public V45Packet(V45Commands command) { this.m_status = 0; this.m_command = command; this.m_length = 6; this.m_CRC = 0; m_sender = 0; m_receiver = 0; }
public V45Packet(V45Commands command, byte[] data, byte sender = 0, byte receiver = 0) { this.m_status = 0; this.m_command = command; this.m_payLoad = data; this.m_sender = sender; this.m_receiver = receiver; this.m_length = this.getLength(); this.m_CRC = this.getCRC(); }