示例#1
0
        public static RadioPacket parse(Bytes data)
        {
            if (data.Length < 5)
            {
                return(null);
            }

            var crc_computed = CrcUtil.Crc8(data.Sub(0, data.Length - 1).ToArray());
            var crc          = data[data.Length - 1];

            if (crc != crc_computed)
            {
                return(null);
            }

            var address  = data.DWord(0);
            var d4       = data.Byte(4);
            var type     = (PacketType)(d4 >> 5);
            var sequence = d4 & 0b00011111;
            var body     = data.Sub(5, data.Length - 1);

            return(new RadioPacket(address, type, sequence, body));
        }