Preserve C/H bits and extension bit
This commit is contained in:
26
test/address.chbit.test.ts
Normal file
26
test/address.chbit.test.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Address } from "../src/address";
|
||||
import { describe, it, expect } from "vitest";
|
||||
|
||||
describe("Address C/H and reserved bits", () => {
|
||||
it("encodes and decodes C/H and reserved", () => {
|
||||
const addr = new Address("NOCALL", 7, true, 0b10);
|
||||
const bytes = addr.toBytes();
|
||||
expect((bytes[6] & 0x80) !== 0).toBe(true); // C/H
|
||||
expect(((bytes[6] >> 5) & 0b11)).toBe(0b10); // reserved
|
||||
expect(((bytes[6] >> 1) & 0x0f)).toBe(7); // SSID
|
||||
const decoded = Address.fromBytes(bytes);
|
||||
expect(decoded.callsign).toBe("NOCALL");
|
||||
expect(decoded.ssid).toBe(7);
|
||||
expect(decoded.getCH()).toBe(true);
|
||||
expect(decoded.getReserved()).toBe(0b10);
|
||||
});
|
||||
|
||||
it("sets and detects last address extension", () => {
|
||||
const addr = new Address("TEST", 1, false, 0b11);
|
||||
const bytes = addr.toBytes(true);
|
||||
expect(Address.isLastAddress(bytes)).toBe(true);
|
||||
expect((bytes[6] & 0x01)).toBe(1);
|
||||
const notLast = addr.toBytes(false);
|
||||
expect(Address.isLastAddress(notLast)).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user