EasyManua.ls Logo

Scanse Sweep V1 - Appendix

Scanse Sweep V1
14 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
APPENDIX USER’S MANUAL SWEEP V1.0
13
Copyright ©2014-2017 Scanse LLC - www.scanse.io
Authenticating Receipts (Does not apply to Data Block)
Authentication of a valid receipt is accomplished by a checksum, which uses the Status (2 bytes) and Sum of
Status (1 byte) from the receipt. To perform the checksum, the received Sum of Status bytes is checked against a
calculated sum of the 2 Status bytes. The protocol design allows for performing the checksum visually in a
terminal, which requires all bytes in a receipt to be legible ASCII values (ex: '00P'). Therefore, performing the
checksum in code is not intuitive. It works like this:
The status bytes are summed
The lower 6 bits (Least Significant) of that sum are then added to 30Hex
The resultant value is compared with the checksum byte
//statusByte#1 + statusByte#2
let sumOfStatusBytes = status1_byteValue + status2_byteValue;
//grab the lower (least significant) 6 bits by performing a bit-wise AND with 0x3F (ie: 00111111)
let lowerSixBits = sumOfStatusBytes & 0x3F;
//add 30Hex to it
let sum = lowerSixBits + 0x30;
return ( sum === checkSumByteValue );
Example: Consider the common case of '00P' (decimal -> [48, 48, 80], hex -> [0x30, 0x30, 0x50])
0x30 + 0x30 = 0x60 // sum of the status bytes
0x60 & 0x3F = 0x20 // retrieve only the lower 6 bits
0x20 + 0x30 = 0x50 // calculate the ASCII legible sum
0x50 = 'P' // translate to ASCII
Parsing Data Block 16-bit integers and floats
The Data Block receipt includes int-16 and float values (distance & azimuth). In the case of distance, the value is a
16-bit integer. In the case of the azimuth, the value is a float which is sent as a 16bit integer and must be
converted back to a float.
In either case, the 16-bit int is sent as two individual bytes. The lower order byte is received first, and the higher
order byte is received second. For example, parsing the distance:
//assume dataBlock holds the DATA_BLOCK byte array
//such that indices 3 & 4 correspond to the two distance bytes
let distance = (dataBlock[4] << 8) + (dataBlock[3]);
For floats, start by using the same technique to acquire the 16-bit int. Once you have it, you can perform the
conversion to float like so:
//assume dataBlock holds the DATA_BLOCK byte array,
//such that indices 1 & 2 correspond to the two azimuth bytes
let angle_int = (dataBlock[2] << 8) + (dataBlock[1]);
let degree = 1.0 * ( (angle_int >> 4) + ( (angle_int & 15) / 16.0 ) );