Skip to main content
Version: v0.0.6

Function: computeChecksum()

computeChecksum(bytes, start, endInclusive): number

Sum bytes [start, endInclusive] of bytes modulo 256: the ASTM frame checksum span (frame number through the terminator, inclusive).

Parameters

bytes

Uint8Array

The full decoded byte stream.

start

number

First index to include (the frame-number byte, one past STX).

endInclusive

number

Last index to include (the ETB/ETX terminator byte).

Returns

number

The checksum in 0255.

Example

import { computeChecksum } from "@cosyte/astm";
// bytes: STX '1' 'A' ETX → sum '1' + 'A' + ETX, mod 256.
computeChecksum(new Uint8Array([0x02, 0x31, 0x41, 0x03]), 1, 3); // 0x75