User Manual

APPENDIX USER’S MANUAL SWEEP V1.0
14
Copyright ©2014-2017 Scanse LLC - www.scanse.io
Performing Data Block Checksum
The last byte of a Data Block receipt is a checksum byte. It represents the sum of all bytes up until the checksum
byte (ie: the first 6 bytes). Obviously, a single byte caps at 255, so the checksum can't reliably hold the sum of 6
other bytes. Instead, the checksum byte uses the modulo operation and effectively contains the remainder after
dividing the sum by 255 (this is the same as saying sum % 255). Validating the checksum looks like:
//ONLY applies to receipts of type ReceiptEnum.DATA_BLOCK
//calculate the sum of the specified status or msg bytes
let calculatedSum = 0;
for(let i = 0; i < 6; i++){
//add each status byte to the running sum
calculatedSum += dataBlock[i];
}
calculatedSum = calculatedSum % 255;
let expectedSumVal = dataBlock[6];
return calculatedSum === expectedSumVal;