More bugfixes in comment offsets

This commit is contained in:
2026-03-18 19:17:53 +01:00
parent 46e7694ec6
commit 34240dfbd8
2 changed files with 19 additions and 4 deletions

View File

@@ -931,7 +931,11 @@ export class Frame implements IFrame {
}
// remove PHG token from ext and advance ext for further parsing
if (commentBefore !== undefined && commentBefore.length > 0) {
commentBefore = commentBefore.substring(7);
} else {
commentOffset += 7;
}
ext = ext.substring(7).trimStart();
continue;
@@ -1015,7 +1019,11 @@ export class Frame implements IFrame {
}
// remove DFS token from ext and advance ext for further parsing
if (commentBefore !== undefined && commentBefore.length > 0) {
commentBefore = commentBefore.substring(7);
} else {
commentOffset += 7;
}
ext = ext.substring(7).trimStart();
continue;
@@ -1062,7 +1070,11 @@ export class Frame implements IFrame {
}
// remove DF token from ext and advance ext for further parsing
if (commentBefore !== undefined && commentBefore.length > 0) {
commentBefore = commentBefore.substring(8);
} else {
commentOffset += 8;
}
ext = ext.substring(8).trimStart();
continue;
@@ -1081,7 +1093,7 @@ export class Frame implements IFrame {
} else if (commentBefore !== undefined && commentBefore.length > 0) {
extras.comment = commentBefore + comment;
} else {
extras.comment = comment;
extras.comment = comment.substring(commentOffset);
}
if (withStructure) {

View File

@@ -47,6 +47,7 @@ describe("APRS extras test vectors", () => {
expect(payload!.position.phg!.power).toBe(25);
expect(payload!.position.phg!.height).toBeCloseTo(3.048, 3);
expect(payload!.position.phg!.gain).toBe(0);
expect(payload!.position!.comment).toBe("73 de NOCALL");
});
it("parses PHG token with hyphen separators (spec vector 2)", () => {
@@ -55,6 +56,8 @@ describe("APRS extras test vectors", () => {
const res = frame.decode(true) as { payload: PositionPayload | null; structure: Dissected };
const { payload, structure } = res;
// console.log(structure[structure.length - 1]); // Log the last segment for debugging
expect(payload).not.toBeNull();
// Use a spec PHG example: PHG0210 -> p=0 -> power 0 W, h=2 -> 40 ft
expect(payload!.position.phg).toBeDefined();