More bugfixes in comment offsets
This commit is contained in:
20
src/frame.ts
20
src/frame.ts
@@ -931,7 +931,11 @@ export class Frame implements IFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// remove PHG token from ext and advance ext for further parsing
|
// remove PHG token from ext and advance ext for further parsing
|
||||||
commentOffset += 7;
|
if (commentBefore !== undefined && commentBefore.length > 0) {
|
||||||
|
commentBefore = commentBefore.substring(7);
|
||||||
|
} else {
|
||||||
|
commentOffset += 7;
|
||||||
|
}
|
||||||
ext = ext.substring(7).trimStart();
|
ext = ext.substring(7).trimStart();
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
@@ -1015,7 +1019,11 @@ export class Frame implements IFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// remove DFS token from ext and advance ext for further parsing
|
// remove DFS token from ext and advance ext for further parsing
|
||||||
commentOffset += 7;
|
if (commentBefore !== undefined && commentBefore.length > 0) {
|
||||||
|
commentBefore = commentBefore.substring(7);
|
||||||
|
} else {
|
||||||
|
commentOffset += 7;
|
||||||
|
}
|
||||||
ext = ext.substring(7).trimStart();
|
ext = ext.substring(7).trimStart();
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
@@ -1062,7 +1070,11 @@ export class Frame implements IFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// remove DF token from ext and advance ext for further parsing
|
// remove DF token from ext and advance ext for further parsing
|
||||||
commentOffset += 8;
|
if (commentBefore !== undefined && commentBefore.length > 0) {
|
||||||
|
commentBefore = commentBefore.substring(8);
|
||||||
|
} else {
|
||||||
|
commentOffset += 8;
|
||||||
|
}
|
||||||
ext = ext.substring(8).trimStart();
|
ext = ext.substring(8).trimStart();
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
@@ -1081,7 +1093,7 @@ export class Frame implements IFrame {
|
|||||||
} else if (commentBefore !== undefined && commentBefore.length > 0) {
|
} else if (commentBefore !== undefined && commentBefore.length > 0) {
|
||||||
extras.comment = commentBefore + comment;
|
extras.comment = commentBefore + comment;
|
||||||
} else {
|
} else {
|
||||||
extras.comment = comment;
|
extras.comment = comment.substring(commentOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (withStructure) {
|
if (withStructure) {
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ describe("APRS extras test vectors", () => {
|
|||||||
expect(payload!.position.phg!.power).toBe(25);
|
expect(payload!.position.phg!.power).toBe(25);
|
||||||
expect(payload!.position.phg!.height).toBeCloseTo(3.048, 3);
|
expect(payload!.position.phg!.height).toBeCloseTo(3.048, 3);
|
||||||
expect(payload!.position.phg!.gain).toBe(0);
|
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)", () => {
|
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 res = frame.decode(true) as { payload: PositionPayload | null; structure: Dissected };
|
||||||
const { payload, structure } = res;
|
const { payload, structure } = res;
|
||||||
|
|
||||||
|
// console.log(structure[structure.length - 1]); // Log the last segment for debugging
|
||||||
|
|
||||||
expect(payload).not.toBeNull();
|
expect(payload).not.toBeNull();
|
||||||
// Use a spec PHG example: PHG0210 -> p=0 -> power 0 W, h=2 -> 40 ft
|
// Use a spec PHG example: PHG0210 -> p=0 -> power 0 W, h=2 -> 40 ft
|
||||||
expect(payload!.position.phg).toBeDefined();
|
expect(payload!.position.phg).toBeDefined();
|
||||||
|
|||||||
Reference in New Issue
Block a user