Fixed bug in extras segment parsing
This commit is contained in:
44
src/frame.ts
44
src/frame.ts
@@ -427,12 +427,11 @@ export class Frame implements IFrame {
|
|||||||
|
|
||||||
// Emit comment section as we parse
|
// Emit comment section as we parse
|
||||||
if (withStructure) {
|
if (withStructure) {
|
||||||
const commentFields: Field[] = [{ type: FieldType.STRING, name: "text", length: comment.length }];
|
|
||||||
structure.push({
|
structure.push({
|
||||||
name: "comment",
|
name: "comment",
|
||||||
data: new TextEncoder().encode(remainder).buffer,
|
data: new TextEncoder().encode(remainder).buffer,
|
||||||
isString: true,
|
isString: true,
|
||||||
fields: [...(extras.fields || []), ...commentFields]
|
fields: extras.fields || []
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (withStructure && extras.fields) {
|
} else if (withStructure && extras.fields) {
|
||||||
@@ -441,7 +440,7 @@ export class Frame implements IFrame {
|
|||||||
name: "comment",
|
name: "comment",
|
||||||
data: new TextEncoder().encode("").buffer,
|
data: new TextEncoder().encode("").buffer,
|
||||||
isString: true,
|
isString: true,
|
||||||
fields: [...(extras.fields || [])]
|
fields: extras.fields || []
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -807,7 +806,7 @@ export class Frame implements IFrame {
|
|||||||
type: FieldType.STRING,
|
type: FieldType.STRING,
|
||||||
name: "altitude",
|
name: "altitude",
|
||||||
data: new TextEncoder().encode(altMatch[1]).buffer,
|
data: new TextEncoder().encode(altMatch[1]).buffer,
|
||||||
value: altitude.toFixed(3) + "m",
|
value: altitude.toFixed(1) + "m",
|
||||||
length: 6
|
length: 6
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
@@ -845,7 +844,7 @@ export class Frame implements IFrame {
|
|||||||
type: FieldType.STRING,
|
type: FieldType.STRING,
|
||||||
name: "range (rrrr)",
|
name: "range (rrrr)",
|
||||||
length: 4,
|
length: 4,
|
||||||
value: extras.range.toString() + "km"
|
value: extras.range.toFixed(1) + "km"
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1091,7 +1090,6 @@ export class Frame implements IFrame {
|
|||||||
{
|
{
|
||||||
type: FieldType.STRING,
|
type: FieldType.STRING,
|
||||||
name: "comment",
|
name: "comment",
|
||||||
value: commentBefore,
|
|
||||||
length: commentBefore.length
|
length: commentBefore.length
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -1102,7 +1100,6 @@ export class Frame implements IFrame {
|
|||||||
{
|
{
|
||||||
type: FieldType.STRING,
|
type: FieldType.STRING,
|
||||||
name: "comment",
|
name: "comment",
|
||||||
value: comment,
|
|
||||||
length: comment.length
|
length: comment.length
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -1324,14 +1321,11 @@ export class Frame implements IFrame {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (comment && comment.length > 0) {
|
if (comment && comment.length > 0) {
|
||||||
const commentFields: Field[] = [
|
|
||||||
{ type: FieldType.STRING, name: "comment", length: comment.length, value: comment }
|
|
||||||
];
|
|
||||||
segments.push({
|
segments.push({
|
||||||
name: "comment",
|
name: "comment",
|
||||||
data: new TextEncoder().encode(remainder).buffer,
|
data: new TextEncoder().encode(remainder).buffer,
|
||||||
isString: true,
|
isString: true,
|
||||||
fields: [...(extras.fields || []), ...commentFields]
|
fields: extras.fields || []
|
||||||
});
|
});
|
||||||
} else if (extras.fields) {
|
} else if (extras.fields) {
|
||||||
segments.push({
|
segments.push({
|
||||||
@@ -1648,20 +1642,19 @@ export class Frame implements IFrame {
|
|||||||
position.comment = comment;
|
position.comment = comment;
|
||||||
|
|
||||||
if (withStructure) {
|
if (withStructure) {
|
||||||
const commentFields: Field[] = [{ type: FieldType.STRING, name: "comment", length: comment.length }];
|
|
||||||
segment.push({
|
segment.push({
|
||||||
name: "Comment",
|
name: "comment",
|
||||||
data: new TextEncoder().encode(remainder).buffer,
|
data: new TextEncoder().encode(remainder).buffer,
|
||||||
isString: true,
|
isString: true,
|
||||||
fields: [...(extras.fields || []), ...commentFields]
|
fields: extras.fields || []
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (withStructure && extras.fields) {
|
} else if (withStructure && extras.fields) {
|
||||||
segment.push({
|
segment.push({
|
||||||
name: "Comment",
|
name: "comment",
|
||||||
data: new TextEncoder().encode(remainder).buffer,
|
data: new TextEncoder().encode(remainder).buffer,
|
||||||
isString: true,
|
isString: true,
|
||||||
fields: [...(extras.fields || [])]
|
fields: extras.fields || []
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1784,29 +1777,26 @@ export class Frame implements IFrame {
|
|||||||
const doNotArchive = remainder.includes(DO_NOT_ARCHIVE_MARKER);
|
const doNotArchive = remainder.includes(DO_NOT_ARCHIVE_MARKER);
|
||||||
let comment = remainder;
|
let comment = remainder;
|
||||||
|
|
||||||
const extrasItem = this.parseCommentExtras(comment, withStructure);
|
const extras = this.parseCommentExtras(comment, withStructure);
|
||||||
comment = extrasItem.comment;
|
comment = extras.comment;
|
||||||
|
|
||||||
if (comment) {
|
if (comment) {
|
||||||
position.comment = comment;
|
position.comment = comment;
|
||||||
if (withStructure) {
|
if (withStructure) {
|
||||||
const commentFields: Field[] = [
|
|
||||||
{ type: FieldType.STRING, name: "comment", length: comment.length, value: comment }
|
|
||||||
];
|
|
||||||
segment.push({
|
segment.push({
|
||||||
name: "Comment",
|
name: "comment",
|
||||||
data: new TextEncoder().encode(remainder).buffer,
|
data: new TextEncoder().encode(remainder).buffer,
|
||||||
isString: true,
|
isString: true,
|
||||||
fields: [...(extrasItem.fields || []), ...commentFields]
|
fields: extras.fields || []
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (withStructure && extrasItem.fields) {
|
} else if (withStructure && extras.fields) {
|
||||||
// No free-text comment, but extras fields exist: emit comment-only segment
|
// No free-text comment, but extras fields exist: emit comment-only segment
|
||||||
segment.push({
|
segment.push({
|
||||||
name: "Comment",
|
name: "comment",
|
||||||
data: new TextEncoder().encode(remainder).buffer,
|
data: new TextEncoder().encode(remainder).buffer,
|
||||||
isString: true,
|
isString: true,
|
||||||
fields: [...(extrasItem.fields || [])]
|
fields: extras.fields || []
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1817,7 +1807,7 @@ export class Frame implements IFrame {
|
|||||||
alive,
|
alive,
|
||||||
position
|
position
|
||||||
};
|
};
|
||||||
this.attachExtras(payload, extrasItem);
|
this.attachExtras(payload, extras);
|
||||||
|
|
||||||
if (withStructure) {
|
if (withStructure) {
|
||||||
return { payload, segment };
|
return { payload, segment };
|
||||||
|
|||||||
Reference in New Issue
Block a user