Also parse the extras from the comment field
This commit is contained in:
862
src/frame.ts
862
src/frame.ts
File diff suppressed because it is too large
Load Diff
@@ -57,7 +57,7 @@ export enum DataType {
|
||||
ThirdParty = "}",
|
||||
|
||||
// Invalid/Test Data
|
||||
InvalidOrTest = ",",
|
||||
InvalidOrTest = ","
|
||||
}
|
||||
|
||||
export interface ISymbol {
|
||||
@@ -77,12 +77,39 @@ export interface IPosition {
|
||||
course?: number; // Course in degrees
|
||||
symbol?: ISymbol;
|
||||
comment?: string;
|
||||
/**
|
||||
* Optional reported radio range in miles (from RNG token in comment)
|
||||
*/
|
||||
range?: number;
|
||||
/**
|
||||
* Optional power/height/gain information from PHG token
|
||||
* PHG format: PHGpphhgg (pp=power, hh=height, gg=gain) as numeric values
|
||||
*/
|
||||
phg?: IPowerHeightGain;
|
||||
/** Direction-finding / DF information parsed from comment tokens */
|
||||
dfs?: IDirectionFinding;
|
||||
|
||||
toString(): string; // Return combined position representation (e.g., "lat,lon,alt")
|
||||
toCompressed?(): CompressedPosition; // Optional method to convert to compressed format
|
||||
distanceTo?(other: IPosition): number; // Optional method to calculate distance to another position
|
||||
}
|
||||
|
||||
export interface IPowerHeightGain {
|
||||
power?: number; // Transmit power in watts
|
||||
height?: number; // Antenna height in meters
|
||||
gain?: number; // Antenna gain in dBi
|
||||
directivity?: number | "omni" | "unknown"; // Optional directivity pattern (numeric code or "omni")
|
||||
}
|
||||
|
||||
export interface IDirectionFinding {
|
||||
bearing?: number; // Direction finding bearing in degrees
|
||||
strength?: number; // Relative signal strength (0-9)
|
||||
height?: number; // Antenna height in meters
|
||||
gain?: number; // Antenna gain in dBi
|
||||
quality?: number; // Signal quality or other metric (0-9)
|
||||
directivity?: number | "omni" | "unknown"; // Optional directivity pattern (numeric code or "omni")
|
||||
}
|
||||
|
||||
export interface ITimestamp {
|
||||
day?: number; // Day of month (DHM format)
|
||||
month?: number; // Month (MDHM format)
|
||||
@@ -197,12 +224,7 @@ export interface QueryPayload {
|
||||
target?: string; // Target callsign or area
|
||||
}
|
||||
|
||||
export type TelemetryVariant =
|
||||
| "data"
|
||||
| "parameters"
|
||||
| "unit"
|
||||
| "coefficients"
|
||||
| "bitsense";
|
||||
export type TelemetryVariant = "data" | "parameters" | "unit" | "coefficients" | "bitsense";
|
||||
|
||||
// Telemetry Data Payload
|
||||
export interface TelemetryDataPayload {
|
||||
|
||||
10
src/index.ts
10
src/index.ts
@@ -1,10 +1,6 @@
|
||||
export { Frame, Address, Timestamp } from "./frame";
|
||||
|
||||
export {
|
||||
type IAddress,
|
||||
type IFrame,
|
||||
DataType as DataTypeIdentifier,
|
||||
} from "./frame.types";
|
||||
export { type IAddress, type IFrame, DataType as DataTypeIdentifier } from "./frame.types";
|
||||
|
||||
export {
|
||||
DataType,
|
||||
@@ -33,7 +29,7 @@ export {
|
||||
type DFReportPayload,
|
||||
type BasePayload,
|
||||
type Payload,
|
||||
type DecodedFrame,
|
||||
type DecodedFrame
|
||||
} from "./frame.types";
|
||||
|
||||
export {
|
||||
@@ -43,5 +39,5 @@ export {
|
||||
feetToMeters,
|
||||
metersToFeet,
|
||||
celsiusToFahrenheit,
|
||||
fahrenheitToCelsius,
|
||||
fahrenheitToCelsius
|
||||
} from "./parser";
|
||||
|
||||
@@ -15,9 +15,7 @@ export const base91ToNumber = (str: string): number => {
|
||||
const digit = charCode - 33; // Base91 uses chars 33-123 (! to {)
|
||||
|
||||
if (digit < 0 || digit >= base) {
|
||||
throw new Error(
|
||||
`Invalid Base91 character: '${str[i]}' (code ${charCode})`,
|
||||
);
|
||||
throw new Error(`Invalid Base91 character: '${str[i]}' (code ${charCode})`);
|
||||
}
|
||||
|
||||
value = value * base + digit;
|
||||
@@ -62,6 +60,15 @@ export const feetToMeters = (feet: number): number => {
|
||||
return feet * FEET_TO_METERS;
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert miles to meters.
|
||||
* @param miles number of miles
|
||||
* @returns meters
|
||||
*/
|
||||
export const milesToMeters = (miles: number): number => {
|
||||
return miles * 1609.344;
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert altitude from meters to feet.
|
||||
*
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IPosition, ISymbol } from "./frame.types";
|
||||
import { IDirectionFinding, IPosition, IPowerHeightGain, ISymbol } from "./frame.types";
|
||||
|
||||
export class Symbol implements ISymbol {
|
||||
table: string; // Symbol table identifier
|
||||
@@ -10,9 +10,7 @@ export class Symbol implements ISymbol {
|
||||
this.code = table[1];
|
||||
this.table = table[0];
|
||||
} else {
|
||||
throw new Error(
|
||||
`Invalid symbol format: '${table}' (expected 2 characters if code is not provided)`,
|
||||
);
|
||||
throw new Error(`Invalid symbol format: '${table}' (expected 2 characters if code is not provided)`);
|
||||
}
|
||||
} else {
|
||||
this.table = table;
|
||||
@@ -34,6 +32,9 @@ export class Position implements IPosition {
|
||||
course?: number; // Course in degrees
|
||||
symbol?: Symbol;
|
||||
comment?: string;
|
||||
range?: number;
|
||||
phg?: IPowerHeightGain;
|
||||
dfs?: IDirectionFinding;
|
||||
|
||||
constructor(data: Partial<IPosition>) {
|
||||
this.latitude = data.latitude ?? 0;
|
||||
@@ -48,6 +49,9 @@ export class Position implements IPosition {
|
||||
this.symbol = new Symbol(data.symbol.table, data.symbol.code);
|
||||
}
|
||||
this.comment = data.comment;
|
||||
this.range = data.range;
|
||||
this.phg = data.phg;
|
||||
this.dfs = data.dfs;
|
||||
}
|
||||
|
||||
public toString(): string {
|
||||
|
||||
Reference in New Issue
Block a user