@packet-net/pdn-aprs 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/CHANGELOG.md +29 -1
  2. package/README.md +8 -4
  3. package/dist/builder.d.ts +33 -8
  4. package/dist/builder.d.ts.map +1 -1
  5. package/dist/builder.js +64 -10
  6. package/dist/builder.js.map +1 -1
  7. package/dist/decode/index.d.ts.map +1 -1
  8. package/dist/decode/index.js +5 -0
  9. package/dist/decode/index.js.map +1 -1
  10. package/dist/decode/other.js +1 -1
  11. package/dist/decode/other.js.map +1 -1
  12. package/dist/decode/positioned.d.ts +17 -1
  13. package/dist/decode/positioned.d.ts.map +1 -1
  14. package/dist/decode/positioned.js +21 -7
  15. package/dist/decode/positioned.js.map +1 -1
  16. package/dist/decode/reports.d.ts.map +1 -1
  17. package/dist/decode/reports.js +34 -12
  18. package/dist/decode/reports.js.map +1 -1
  19. package/dist/decoder.d.ts.map +1 -1
  20. package/dist/decoder.js +2 -4
  21. package/dist/decoder.js.map +1 -1
  22. package/dist/deviceid.d.ts +8 -2
  23. package/dist/deviceid.d.ts.map +1 -1
  24. package/dist/deviceid.js +10 -2
  25. package/dist/deviceid.js.map +1 -1
  26. package/dist/encode/common.d.ts +13 -2
  27. package/dist/encode/common.d.ts.map +1 -1
  28. package/dist/encode/common.js +36 -4
  29. package/dist/encode/common.js.map +1 -1
  30. package/dist/encode/index.d.ts.map +1 -1
  31. package/dist/encode/index.js +36 -16
  32. package/dist/encode/index.js.map +1 -1
  33. package/dist/encode/other.d.ts.map +1 -1
  34. package/dist/encode/other.js +10 -2
  35. package/dist/encode/other.js.map +1 -1
  36. package/dist/encode/position.d.ts +9 -5
  37. package/dist/encode/position.d.ts.map +1 -1
  38. package/dist/encode/position.js +219 -121
  39. package/dist/encode/position.js.map +1 -1
  40. package/dist/index.d.ts +1 -1
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js.map +1 -1
  43. package/dist/neutral.d.ts.map +1 -1
  44. package/dist/neutral.js +20 -3
  45. package/dist/neutral.js.map +1 -1
  46. package/dist/types.d.ts +13 -5
  47. package/dist/types.d.ts.map +1 -1
  48. package/package.json +1 -1
  49. package/src/builder.ts +77 -14
  50. package/src/decode/index.ts +4 -0
  51. package/src/decode/other.ts +1 -1
  52. package/src/decode/positioned.ts +33 -9
  53. package/src/decode/reports.ts +33 -9
  54. package/src/decoder.ts +2 -5
  55. package/src/deviceid.ts +12 -3
  56. package/src/encode/common.ts +34 -4
  57. package/src/encode/index.ts +33 -14
  58. package/src/encode/other.ts +12 -2
  59. package/src/encode/position.ts +227 -119
  60. package/src/index.ts +1 -0
  61. package/src/neutral.ts +22 -3
  62. package/src/types.ts +14 -1
package/src/neutral.ts CHANGED
@@ -3,7 +3,8 @@
3
3
  // sent. Used by the conformance tests and the differential dump, and handy for comparing this
4
4
  // library with another implementation.
5
5
 
6
- import { formatDiagnostic } from './diagnostics.js';
6
+ import type { DiagnosticCode } from './codes.js';
7
+ import { diagnostic, formatDiagnostic, type Diagnostic, type Severity } from './diagnostics.js';
7
8
  import type {
8
9
  AprsData,
9
10
  AprsPacket,
@@ -590,8 +591,26 @@ export function fromNeutralData(d: J): AprsData {
590
591
  case 'unrecognized':
591
592
  o.reason = d.reason;
592
593
  break;
593
- case 'third-party':
594
- throw new RangeError('third-party data cannot be built from the neutral form');
594
+ case 'third-party': {
595
+ // The inner packet as data: its information field is written from its data, and its
596
+ // diagnostics are kept, so one with a tolerated defect is refused, as the Encoding rule says.
597
+ const p: J = d.packet ?? {};
598
+ o.packet = {
599
+ source: p.source ?? '',
600
+ destination: p.destination ?? '',
601
+ path: ((p.path ?? []) as string[]).map((e) => (e.endsWith('*') ? { address: e.slice(0, -1), used: true } : { address: e, used: false })),
602
+ information: new Uint8Array(0),
603
+ data: fromNeutralData(p.data ?? { type: 'unrecognized', reason: 'empty' }),
604
+ diagnostics: ((p.diagnostics ?? []) as string[]).map(diagnosticFrom),
605
+ };
606
+ break;
607
+ }
595
608
  }
596
609
  return o as unknown as AprsData;
597
610
  }
611
+
612
+ /** A diagnostic from its neutral form, `severity:code`. */
613
+ function diagnosticFrom(text: string): Diagnostic {
614
+ const colon = text.indexOf(':');
615
+ return diagnostic(text.slice(0, colon) as Severity, text.slice(colon + 1) as DiagnosticCode);
616
+ }
package/src/types.ts CHANGED
@@ -442,11 +442,24 @@ export interface MaidenheadBeacon {
442
442
  readonly comment?: string;
443
443
  }
444
444
 
445
+ /** A general query's footprint: a latitude, a longitude and a radius (APRS12c ch. 15). */
446
+ export interface QueryFootprint {
447
+ /** Degrees, north positive. */
448
+ readonly latitude: number;
449
+ /** Degrees, east positive. */
450
+ readonly longitude: number;
451
+ readonly radiusMiles: number;
452
+ /** The latitude as sent (` 34.0`, `-.1715`), with any leading space, so it can be written back the same. */
453
+ readonly latitudeText?: string;
454
+ /** The longitude as sent, so it can be written back the same. */
455
+ readonly longitudeText?: string;
456
+ }
457
+
445
458
  /** A general query (`?`). */
446
459
  export interface Query {
447
460
  readonly type: 'query';
448
461
  readonly queryType: string;
449
- readonly footprint?: { readonly latitude: number; readonly longitude: number; readonly radiusMiles: number };
462
+ readonly footprint?: QueryFootprint;
450
463
  }
451
464
 
452
465
  /** A station capability: a token, or a token and its value. */