Skip to main content
Version: v0.0.6

Function: parseChecksumHex()

parseChecksumHex(bytes, i0, i1): number | undefined

Read the two-hex-char checksum at bytes[i0]/bytes[i1], case-insensitively (a lowercase checksum is a tolerated real-vendor quirk). Returns undefined when either position is out of range or not a hex digit: the caller then treats the frame as having no readable declared checksum, never as a match.

Parameters

bytes

Uint8Array

The full decoded byte stream.

i0

number

Index of the high hex nibble (immediately after the terminator).

i1

number

Index of the low hex nibble.

Returns

number | undefined

The declared checksum in 0255, or undefined if unreadable.

Example

import { parseChecksumHex } from "@cosyte/astm";
parseChecksumHex(new Uint8Array([0x37, 0x35]), 0, 1); // 0x75 ("75")
parseChecksumHex(new Uint8Array([0x37, 0x35]), 5, 6); // undefined (out of range)