pub fn decode_nocrclen(&self, data: &[u8; 17]) -> Result<SparsnasPacket, SparsnasDecodeError> {
        #[rustfmt::skip] // rustfmt makes _some_ of these single line
        let pkt = SparsnasPacket {
            status: u16::from_be_bytes([
		data[02] ^ self.key[0],
		data[03] ^ self.key[1],
	    ]),
            serial: u32::from_be_bytes([
                data[04] ^ self.key[2],
                data[05] ^ self.key[3],
                data[06] ^ self.key[4],
                data[07] ^ self.key[0],
            ]),
            packet_seq: u16::from_be_bytes([
		data[08] ^ self.key[1],
		data[09] ^ self.key[2],
	    ]),
            time_between_pulses: u16::from_be_bytes([
                data[10] ^ self.key[3],
                data[11] ^ self.key[4],
            ]),
            pulse_count: u32::from_be_bytes([
                data[12] ^ self.key[0],
                data[13] ^ self.key[1],
                data[14] ^ self.key[2],
                data[15] ^ self.key[3],
            ]),
            battery_percentage: u8::from_be_bytes([
		data[16] ^ self.key[4],
	    ]),
        };

        if (pkt.packet_seq & 0x7f) as u8 != data[1] {
            return Err(SparsnasDecodeError::BadPacketCount);
        }

        if pkt.serial != self.serial % 1_000_000 {
            return Err(SparsnasDecodeError::BadSerial);
        }

        Ok(pkt)
    }
/// Decode a packet without CRC and length.
Decode a packet without CRC and length.
Decode a packet without CRC and length .
pub fn decode_nocrclen(&self, data: &[u8; 17]) -> Result<SparsnasPacket, SparsnasDecodeError> {
        #[rustfmt::skip] // rustfmt makes _some_ of these single line
        let pkt = SparsnasPacket {
            status: u16::from_be_bytes([
		data[02] ^ self.key[0],
		data[03] ^ self.key[1],
	    ]),
            serial: u32::from_be_bytes([
                data[04] ^ self.key[2],
                data[05] ^ self.key[3],
                data[06] ^ self.key[4],
                data[07] ^ self.key[0],
            ]),
            packet_seq: u16::from_be_bytes([
		data[08] ^ self.key[1],
		data[09] ^ self.key[2],
	    ]),
            time_between_pulses: u16::from_be_bytes([
                data[10] ^ self.key[3],
                data[11] ^ self.key[4],
            ]),
            pulse_count: u32::from_be_bytes([
                data[12] ^ self.key[0],
                data[13] ^ self.key[1],
                data[14] ^ self.key[2],
                data[15] ^ self.key[3],
            ]),
            battery_percentage: u8::from_be_bytes([
		data[16] ^ self.key[4],
	    ]),
        };
        if (pkt.packet_seq & 0x7f) as u8 != data[1] {
            return Err(SparsnasDecodeError::BadPacketCount);
        }
        if pkt.serial != self.serial % 1_000_000 {
            return Err(SparsnasDecodeError::BadSerial);
        }
        Ok(pkt)
    }
pub fn decode_nocrclen ( & self , data : & [ u8 ; 17 ] ) -> Result < SparsnasPacket , SparsnasDecodeError > { # [ rustfmt :: skip ] // rustfmt makes _some_ of these single line let pkt = SparsnasPacket { status : u16 :: from_be_bytes ( [ data [ 02 ] ^ self . key [ 0 ] , data [ 03 ] ^ self . key [ 1 ] , ] ) , serial : u32 :: from_be_bytes ( [ data [ 04 ] ^ self . key [ 2 ] , data [ 05 ] ^ self . key [ 3 ] , data [ 06 ] ^ self . key [ 4 ] , data [ 07 ] ^ self . key [ 0 ] , ] ) , packet_seq : u16 :: from_be_bytes ( [ data [ 08 ] ^ self . key [ 1 ] , data [ 09 ] ^ self . key [ 2 ] , ] ) , time_between_pulses : u16 :: from_be_bytes ( [ data [ 10 ] ^ self . key [ 3 ] , data [ 11 ] ^ self . key [ 4 ] , ] ) , pulse_count : u32 :: from_be_bytes ( [ data [ 12 ] ^ self . key [ 0 ] , data [ 13 ] ^ self . key [ 1 ] , data [ 14 ] ^ self . key [ 2 ] , data [ 15 ] ^ self . key [ 3 ] , ] ) , battery_percentage : u8 :: from_be_bytes ( [ data [ 16 ] ^ self . key [ 4 ] , ] ) , } ; if ( pkt . packet_seq & 0x7f ) as u8 != data [ 1 ] { return Err ( SparsnasDecodeError :: BadPacketCount ) ; } if pkt . serial != self . serial % 1_000_000 { return Err ( SparsnasDecodeError :: BadSerial ) ; } Ok ( pkt ) }
Decode a packet without CRC and length.
Decode a packet without CRC and length .
&self
data
&[u8; 17]
&self
data
&[u8; 17]