Major change: switched to DataType enum
This commit is contained in:
137
src/frame.ts
137
src/frame.ts
@@ -1,26 +1,28 @@
|
||||
import type { Dissected, Segment, Field } from "@hamradio/packet";
|
||||
import { FieldType } from "@hamradio/packet";
|
||||
import type {
|
||||
IAddress,
|
||||
IFrame,
|
||||
Payload,
|
||||
ITimestamp,
|
||||
PositionPayload,
|
||||
MessagePayload,
|
||||
IPosition,
|
||||
ObjectPayload,
|
||||
ItemPayload,
|
||||
StatusPayload,
|
||||
QueryPayload,
|
||||
TelemetryDataPayload,
|
||||
TelemetryBitSensePayload,
|
||||
TelemetryCoefficientsPayload,
|
||||
TelemetryParameterPayload,
|
||||
TelemetryUnitPayload,
|
||||
WeatherPayload,
|
||||
RawGPSPayload,
|
||||
StationCapabilitiesPayload,
|
||||
ThirdPartyPayload,
|
||||
import {
|
||||
type IAddress,
|
||||
type IFrame,
|
||||
type Payload,
|
||||
type ITimestamp,
|
||||
type PositionPayload,
|
||||
type MessagePayload,
|
||||
type IPosition,
|
||||
type ObjectPayload,
|
||||
type ItemPayload,
|
||||
type StatusPayload,
|
||||
type QueryPayload,
|
||||
type TelemetryDataPayload,
|
||||
type TelemetryBitSensePayload,
|
||||
type TelemetryCoefficientsPayload,
|
||||
type TelemetryParameterPayload,
|
||||
type TelemetryUnitPayload,
|
||||
type WeatherPayload,
|
||||
type RawGPSPayload,
|
||||
type StationCapabilitiesPayload,
|
||||
type ThirdPartyPayload,
|
||||
DataType,
|
||||
MicEPayload,
|
||||
} from "./frame.types";
|
||||
import { Position } from "./position";
|
||||
import { base91ToNumber } from "./parser";
|
||||
@@ -498,8 +500,30 @@ export class Frame implements IFrame {
|
||||
}
|
||||
}
|
||||
|
||||
let payloadType:
|
||||
| DataType.PositionNoTimestampNoMessaging
|
||||
| DataType.PositionNoTimestampWithMessaging
|
||||
| DataType.PositionWithTimestampNoMessaging
|
||||
| DataType.PositionWithTimestampWithMessaging;
|
||||
switch (dataType) {
|
||||
case "!":
|
||||
payloadType = DataType.PositionNoTimestampNoMessaging;
|
||||
break;
|
||||
case "=":
|
||||
payloadType = DataType.PositionNoTimestampWithMessaging;
|
||||
break;
|
||||
case "/":
|
||||
payloadType = DataType.PositionWithTimestampNoMessaging;
|
||||
break;
|
||||
case "@":
|
||||
payloadType = DataType.PositionWithTimestampWithMessaging;
|
||||
break;
|
||||
default:
|
||||
return { payload: null };
|
||||
}
|
||||
|
||||
const payload: PositionPayload = {
|
||||
type: "position",
|
||||
type: payloadType,
|
||||
timestamp,
|
||||
position,
|
||||
messaging,
|
||||
@@ -897,8 +921,20 @@ export class Frame implements IFrame {
|
||||
}
|
||||
}
|
||||
|
||||
const result: PositionPayload = {
|
||||
type: "position",
|
||||
let payloadType: DataType.MicECurrent | DataType.MicEOld;
|
||||
switch (this.payload.charAt(0)) {
|
||||
case "`":
|
||||
payloadType = DataType.MicECurrent;
|
||||
break;
|
||||
case "'":
|
||||
payloadType = DataType.MicEOld;
|
||||
break;
|
||||
default:
|
||||
return { payload: null };
|
||||
}
|
||||
|
||||
const result: MicEPayload = {
|
||||
type: payloadType,
|
||||
position: {
|
||||
latitude,
|
||||
longitude,
|
||||
@@ -907,11 +943,8 @@ export class Frame implements IFrame {
|
||||
code: symbolCode,
|
||||
},
|
||||
},
|
||||
messaging: true, // Mic-E is always messaging-capable
|
||||
micE: {
|
||||
messageType,
|
||||
isStandard,
|
||||
},
|
||||
messageType,
|
||||
isStandard,
|
||||
};
|
||||
|
||||
if (speed > 0) {
|
||||
@@ -1133,6 +1166,13 @@ export class Frame implements IFrame {
|
||||
text = this.payload.substring(textStart + 1);
|
||||
}
|
||||
|
||||
const payload: MessagePayload = {
|
||||
type: DataType.Message,
|
||||
variant: "message",
|
||||
addressee: recipient,
|
||||
text,
|
||||
};
|
||||
|
||||
if (withStructure) {
|
||||
// Emit text section
|
||||
segments.push({
|
||||
@@ -1142,21 +1182,9 @@ export class Frame implements IFrame {
|
||||
fields: [{ type: FieldType.STRING, name: "text", length: text.length }],
|
||||
});
|
||||
|
||||
const payload: MessagePayload = {
|
||||
type: "message",
|
||||
addressee: recipient,
|
||||
text,
|
||||
};
|
||||
|
||||
return { payload, segment: segments };
|
||||
}
|
||||
|
||||
const payload: MessagePayload = {
|
||||
type: "message",
|
||||
addressee: recipient,
|
||||
text,
|
||||
};
|
||||
|
||||
return { payload };
|
||||
}
|
||||
|
||||
@@ -1285,7 +1313,7 @@ export class Frame implements IFrame {
|
||||
}
|
||||
|
||||
const payload: ObjectPayload = {
|
||||
type: "object",
|
||||
type: DataType.Object,
|
||||
name,
|
||||
timestamp,
|
||||
alive,
|
||||
@@ -1420,7 +1448,7 @@ export class Frame implements IFrame {
|
||||
}
|
||||
|
||||
const payload: ItemPayload = {
|
||||
type: "item",
|
||||
type: DataType.Item,
|
||||
name,
|
||||
alive,
|
||||
position,
|
||||
@@ -1472,7 +1500,7 @@ export class Frame implements IFrame {
|
||||
}
|
||||
|
||||
const payload: StatusPayload = {
|
||||
type: "status",
|
||||
type: DataType.Status,
|
||||
timestamp: undefined,
|
||||
text: statusText,
|
||||
};
|
||||
@@ -1557,7 +1585,7 @@ export class Frame implements IFrame {
|
||||
}
|
||||
|
||||
const payload: QueryPayload = {
|
||||
type: "query",
|
||||
type: DataType.Query,
|
||||
queryType,
|
||||
...(target ? { target } : {}),
|
||||
};
|
||||
@@ -1639,7 +1667,8 @@ export class Frame implements IFrame {
|
||||
}
|
||||
|
||||
const payload: TelemetryDataPayload = {
|
||||
type: "telemetry-data",
|
||||
type: DataType.TelemetryData,
|
||||
variant: "data",
|
||||
sequence: isNaN(seq) ? 0 : seq,
|
||||
analog,
|
||||
digital: isNaN(digital) ? 0 : digital,
|
||||
@@ -1664,7 +1693,8 @@ export class Frame implements IFrame {
|
||||
});
|
||||
}
|
||||
const payload: TelemetryParameterPayload = {
|
||||
type: "telemetry-parameters",
|
||||
type: DataType.TelemetryData,
|
||||
variant: "parameters",
|
||||
names,
|
||||
};
|
||||
if (withStructure) return { payload, segment: segments };
|
||||
@@ -1686,7 +1716,8 @@ export class Frame implements IFrame {
|
||||
});
|
||||
}
|
||||
const payload: TelemetryUnitPayload = {
|
||||
type: "telemetry-units",
|
||||
type: DataType.TelemetryData,
|
||||
variant: "unit",
|
||||
units,
|
||||
};
|
||||
if (withStructure) return { payload, segment: segments };
|
||||
@@ -1717,7 +1748,8 @@ export class Frame implements IFrame {
|
||||
});
|
||||
}
|
||||
const payload: TelemetryCoefficientsPayload = {
|
||||
type: "telemetry-coefficients",
|
||||
type: DataType.TelemetryData,
|
||||
variant: "coefficients",
|
||||
coefficients,
|
||||
};
|
||||
if (withStructure) return { payload, segment: segments };
|
||||
@@ -1741,7 +1773,8 @@ export class Frame implements IFrame {
|
||||
});
|
||||
}
|
||||
const payload: TelemetryBitSensePayload = {
|
||||
type: "telemetry-bitsense",
|
||||
type: DataType.TelemetryData,
|
||||
variant: "bitsense",
|
||||
sense: isNaN(sense) ? 0 : sense,
|
||||
...(projectName ? { projectName } : {}),
|
||||
};
|
||||
@@ -1818,7 +1851,9 @@ export class Frame implements IFrame {
|
||||
|
||||
const rest = this.payload.substring(offset).trim();
|
||||
|
||||
const payload: WeatherPayload = { type: "weather" };
|
||||
const payload: WeatherPayload = {
|
||||
type: DataType.WeatherReportNoPosition,
|
||||
};
|
||||
if (timestamp) payload.timestamp = timestamp;
|
||||
if (position) payload.position = position;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user