The Start byte is always 0xAA and indicates the beginning of a packet. It is important to verify that the payload length is
between (inclusive) 0 to 1023 and that the checksum is valid before processing a packet, rather than just relying on the
start byte.
The Flags bytes form a 16 bit integer that represents the payload length and read/write status of the packet. The
payload length is inclusive of the ID byte and the required number of data bytes. The write bit is set to 1 to indicate
write mode, or 0 to indicate read mode.
**Bit:*
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
Payload length (0 to 1023)
Reserved
W
The ID byte represents which command the request/response relates to.
There will be between 1 and 1023 Payload bytes (inclusive) depending on the command type. Each command under
the detailed command descriptions section documents how the data bytes are used. The ID byte will always be present
in the payload.
The CRC bytes form a 16 bit checksum value used to validate the integrity of the packet data. Every byte in the packet
except for the CRC itself is included in the checksum calculation.
Checksum
Each packet has a 2 byte checksum which is used to validate data integrity. The algorithm is CRC-16-CCITT 0x1021.
The CRC must be correctly formed for the LW24/C to accept and process packets. Below are some examples in various
languages for CRC calculation:
C/C++
uint16_t
createCRC
(uint8_t* Data, uint16_t Size)
{
uint16_t crc =
0
;
for (uint32_t i =
0
; i < Size; ++i)
{
uint16_t code = crc >>
8
;
code ^= Data[i];
code ^= code >>
4
;
crc = crc <<
8
;
crc ^= code;
code = code <<
5
;
crc ^= code;
code = code <<
7
;
crc ^= code;
}
return crc;
}
JavaScript
function
createCRC
(data, size) {
let crc =
0
;
LW24/C/SI microLiDAR™ sensor - Product guide
|
Version 0
|
03 March 2022
Page
21
of
36