2 Commits

Author SHA1 Message Date
c7c54984ba 1.4.1 2026-03-20 10:54:21 +01:00
83d05fb2e9 Correctly decode all embedded telemetry data 2026-03-20 10:54:10 +01:00
3 changed files with 23 additions and 5 deletions

View File

@@ -1,7 +1,7 @@
{ {
"name": "@hamradio/aprs", "name": "@hamradio/aprs",
"type": "module", "type": "module",
"version": "1.4.0", "version": "1.4.1",
"description": "APRS (Automatic Packet Reporting System) protocol support for Typescript", "description": "APRS (Automatic Packet Reporting System) protocol support for Typescript",
"keywords": [ "keywords": [
"APRS", "APRS",

View File

@@ -346,10 +346,11 @@ export const decodeCommentExtras = (comment: string, withStructure: boolean = fa
} }
// Parse embedded telemetry in comment. Look for |ss11|, |ss1122|, |ss112233|, |ss1122334455|, or |ss1122334455!"| patterns (where ss is sequence and each pair of digits is an analog channel in base91, and optional last pair is digital channel in base91). // Parse embedded telemetry in comment. Look for |ss11|, |ss1122|, |ss112233|, |ss1122334455|, or |ss1122334455!"| patterns (where ss is sequence and each pair of digits is an analog channel in base91, and optional last pair is digital channel in base91).
if ((match = comment.match(/\|([a-z0-9]{4,14})\|/i))) { if ((match = comment.match(/\|([^|]+)\|/))) {
try { try {
const telemetry = decodeTelemetry(match[1]); const telemetry = decodeTelemetry(match[1]);
extras.telemetry = telemetry; extras.telemetry = telemetry;
comment = comment.replace(match[0], "").trim();
if (withStructure) { if (withStructure) {
fields.push( fields.push(
{ {

View File

@@ -2,7 +2,7 @@ import type { Dissected, Field, Segment } from "@hamradio/packet";
import { describe, expect, it } from "vitest"; import { describe, expect, it } from "vitest";
import { Frame } from "../src/frame"; import { Frame } from "../src/frame";
import type { PositionPayload } from "../src/frame.types"; import { DataType, type ObjectPayload, type PositionPayload } from "../src/frame.types";
import { feetToMeters, milesToMeters } from "../src/parser"; import { feetToMeters, milesToMeters } from "../src/parser";
import { decodeTelemetry } from "../src/payload.extras"; import { decodeTelemetry } from "../src/payload.extras";
@@ -133,8 +133,7 @@ describe("APRS extras test vectors", () => {
it("parses combined tokens: DDD/SSS PHG and DFS", () => { it("parses combined tokens: DDD/SSS PHG and DFS", () => {
const raw = "N0CALL>APRS,WIDE1-1:!4500.00N/07000.00W>090/045PHG5132DFS2132"; const raw = "N0CALL>APRS,WIDE1-1:!4500.00N/07000.00W>090/045PHG5132DFS2132";
const frame = Frame.fromString(raw); const frame = Frame.fromString(raw);
const res = frame.decode(true) as { payload: PositionPayload | null; structure: Dissected }; const { payload, structure } = frame.decode(true) as { payload: PositionPayload | null; structure: Dissected };
const { payload, structure } = res;
expect(payload).not.toBeNull(); expect(payload).not.toBeNull();
expect(payload!.position.course).toBe(90); expect(payload!.position.course).toBe(90);
@@ -221,4 +220,22 @@ describe("decodeTelemetry", () => {
it("throws on invalid base91", () => { it("throws on invalid base91", () => {
expect(() => decodeTelemetry("ss11~~")).toThrow(); expect(() => decodeTelemetry("ss11~~")).toThrow();
}); });
it("decodes telemetry test vector", () => {
const result = decodeTelemetry("$T%R#`");
expect(result.sequence).toBe(324);
expect(result.analog).toEqual([413, 245]);
expect(result.digital).toBeUndefined();
});
it("decodes test vector with embedded telemetry", () => {
const raw = "N0CALL-11>APLRFT,qAR,N0CALL-10:!\\45;<P(6y>HIGLoRa APRS Tracker|$T%R#`|";
const frame = Frame.fromString(raw);
const { payload } = frame.decode(true) as { payload: ObjectPayload | null; structure: Dissected };
expect(payload).not.toBeNull();
expect(payload!.type).toBe(DataType.PositionNoTimestampNoMessaging);
expect(payload!.position).toBeDefined();
expect(payload!.position.comment).toBe("LoRa APRS Tracker");
});
}); });