20 lines
665 B
Python
20 lines
665 B
Python
from __future__ import annotations
|
|
|
|
import numpy as np
|
|
|
|
from galileo_rx.navigation.inav_crc import crc24q, validate_crc24q
|
|
|
|
|
|
def test_crc24q_independent_check_value() -> None:
|
|
bits = np.unpackbits(np.frombuffer(b"123456789", dtype=np.uint8), bitorder="big")
|
|
assert crc24q(bits) == 0xCDE703
|
|
|
|
|
|
def test_crc_rejects_one_bit_error() -> None:
|
|
protected = np.asarray([0, 1, 1, 0, 1] * 39 + [1], dtype=np.int8)
|
|
value = crc24q(protected)
|
|
crc_bits = np.asarray([(value >> shift) & 1 for shift in range(23, -1, -1)], dtype=np.int8)
|
|
assert validate_crc24q(protected, crc_bits)
|
|
protected[17] ^= 1
|
|
assert not validate_crc24q(protected, crc_bits)
|