@airframes/acars-decoder 1.9.2 → 1.9.4

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.
package/dist/index.mjs CHANGED
@@ -172,7 +172,9 @@ var DateTimeUtils = class {
172
172
  const hours = +timeString.substr(0, 2);
173
173
  const minutes = +timeString.substr(2, 2);
174
174
  const seconds = timeString.length === 6 ? +timeString.substr(4, 2) : 0;
175
- const utcDate = new Date(Date.UTC(year, month, day, hours, minutes, seconds));
175
+ const utcDate = new Date(
176
+ Date.UTC(year, month, day, hours, minutes, seconds)
177
+ );
176
178
  return utcDate.toUTCString();
177
179
  }
178
180
  /**
@@ -229,8 +231,9 @@ var DateTimeUtils = class {
229
231
  if (time < 86400) {
230
232
  return date.toISOString().slice(11, 19);
231
233
  }
232
- if (time < 2678400) {
233
- return `YYYY-MM-${date.toISOString().slice(8, 19)}`;
234
+ if (time < 32 * 86400) {
235
+ const day = String(Math.floor(time / 86400)).padStart(2, "0");
236
+ return `YYYY-MM-${day}T${date.toISOString().slice(11, 19)}`;
234
237
  }
235
238
  return date.toISOString().slice(0, -5) + "Z";
236
239
  }
@@ -864,6 +867,9 @@ var ResultFormatter = class {
864
867
  }
865
868
  }
866
869
  static version(decodeResult, value) {
870
+ if (isNaN(value)) {
871
+ return;
872
+ }
867
873
  decodeResult.raw.version = value;
868
874
  decodeResult.formatted.items.push({
869
875
  type: "version",
@@ -900,6 +906,9 @@ var ResultFormatter = class {
900
906
  });
901
907
  }
902
908
  static desiredAltitude(decodeResult, value) {
909
+ if (isNaN(value)) {
910
+ return;
911
+ }
903
912
  decodeResult.raw.desired_alt = value;
904
913
  decodeResult.formatted.items.push({
905
914
  type: "desired_altitude",
@@ -1076,6 +1085,43 @@ var DecoderPlugin = class {
1076
1085
  }
1077
1086
  };
1078
1087
 
1088
+ // lib/plugins/Lib_ACARS.ts
1089
+ var LibAcars = class extends DecoderPlugin {
1090
+ name = "libacars";
1091
+ qualifiers() {
1092
+ return {
1093
+ labels: ["*"],
1094
+ preambles: ["- #"]
1095
+ };
1096
+ }
1097
+ decode(message, options = {}) {
1098
+ const text = message.text;
1099
+ const prefix = message.text.slice(0, 5);
1100
+ const decoded = this.decoder.decode(
1101
+ {
1102
+ label: message.label,
1103
+ sublabel: message.sublabel,
1104
+ text: text.replaceAll(prefix, "")
1105
+ // Remove the prefix before decoding
1106
+ },
1107
+ options
1108
+ );
1109
+ const decodeResult = this.defaultResult();
1110
+ decodeResult.decoder.name = this.name;
1111
+ decodeResult.message = message;
1112
+ if (decoded.decoded) {
1113
+ decodeResult.decoded = true;
1114
+ decodeResult.decoder.decodeLevel = decoded.decoder.decodeLevel;
1115
+ decodeResult.decoder.name = this.name + "-" + decoded.decoder.name;
1116
+ decodeResult.raw = { ...decodeResult.raw, ...decoded.raw };
1117
+ decodeResult.formatted.description = decoded.formatted.description;
1118
+ decodeResult.formatted.items.push(...decoded.formatted.items);
1119
+ decodeResult.remaining = decoded.remaining;
1120
+ }
1121
+ return decodeResult;
1122
+ }
1123
+ };
1124
+
1079
1125
  // lib/plugins/CBand.ts
1080
1126
  var CBAND_HEADER = /^(?<msgno>[A-Z]\d{2}[A-Z])(?<airline>[A-Z0-9]{2})(?<number>[0-9]{4})/;
1081
1127
  var CBand = class extends DecoderPlugin {
@@ -1437,6 +1483,9 @@ var Arinc702Helper = class _Arinc702Helper {
1437
1483
  case "TD":
1438
1484
  processTimeOfDeparture(decodeResult, data2.split(","));
1439
1485
  break;
1486
+ case "TR":
1487
+ processTR(decodeResult, data2.split(","));
1488
+ break;
1440
1489
  case "TS":
1441
1490
  _Arinc702Helper.processTimeStamp(decodeResult, data2.split(","));
1442
1491
  break;
@@ -1617,6 +1666,21 @@ function processLandingReport(decodeResult, data) {
1617
1666
  ResultFormatter.unknown(decodeResult, data.join(","));
1618
1667
  }
1619
1668
  }
1669
+ function processTR(decodeResult, data) {
1670
+ if (data.length !== 21) {
1671
+ ResultFormatter.unknownArr(decodeResult, data, ",");
1672
+ return;
1673
+ }
1674
+ ResultFormatter.unknownArr(decodeResult, data.slice(0, 5), ",");
1675
+ ResultFormatter.off(decodeResult, DateTimeUtils.convertHHMMSSToTod(data[5]));
1676
+ ResultFormatter.unknownArr(decodeResult, data.slice(6, 11), ",");
1677
+ ResultFormatter.departureAirport(decodeResult, data[11]);
1678
+ ResultFormatter.arrivalAirport(decodeResult, data[12]);
1679
+ ResultFormatter.departureRunway(decodeResult, data[13]);
1680
+ ResultFormatter.unknownArr(decodeResult, data.slice(14, 16), ",");
1681
+ ResultFormatter.flightNumber(decodeResult, data[16]);
1682
+ ResultFormatter.unknownArr(decodeResult, data.slice(17), ",");
1683
+ }
1620
1684
  function processCenterOfGravity(decodeResult, data) {
1621
1685
  if (data.length === 1) {
1622
1686
  if (data[0] !== void 0 && data[0] !== "") {
@@ -1677,6 +1741,8 @@ function processIMI(decodeResult, type) {
1677
1741
  decodeResult.formatted.description = "Load Distribution Information";
1678
1742
  } else if (type === "PER") {
1679
1743
  decodeResult.formatted.description = "Performance Report";
1744
+ } else if (type === "PRF") {
1745
+ decodeResult.formatted.description = "Profile Report";
1680
1746
  } else if (type === "POS") {
1681
1747
  decodeResult.formatted.description = "Position Report";
1682
1748
  } else if (type === "PRG") {
@@ -1916,7 +1982,7 @@ var Arinc702 = class extends DecoderPlugin {
1916
1982
  }
1917
1983
  const hashParts = msg.split("#");
1918
1984
  if (hashParts.length == 2) {
1919
- const offset = hashParts[0] === "- " || isNaN(parseInt(hashParts[1][1])) ? 3 : 4;
1985
+ const offset = isNaN(parseInt(hashParts[1][1])) ? 3 : 4;
1920
1986
  decoded = Arinc702Helper.decodeH1Message(
1921
1987
  decodeResult,
1922
1988
  msg.slice(hashParts[0].length + offset)
@@ -4702,91 +4768,60 @@ var Label_ColonComma = class extends DecoderPlugin {
4702
4768
  }
4703
4769
  };
4704
4770
 
4705
- // lib/plugins/Label_H2_02E.ts
4706
- var Label_H2_02E = class extends DecoderPlugin {
4707
- name = "label-h2-02e";
4771
+ // lib/plugins/Label_H1_76401.ts
4772
+ var Label_H1_76401 = class extends DecoderPlugin {
4773
+ name = "label-h1-76401";
4708
4774
  qualifiers() {
4709
4775
  return {
4710
- labels: ["H2"],
4711
- preambles: ["02E"]
4776
+ labels: ["H1"],
4777
+ preambles: ["76401\r\n"]
4712
4778
  };
4713
4779
  }
4714
4780
  decode(message, options = {}) {
4715
- let decodeResult = this.defaultResult();
4716
- decodeResult.decoder.name = this.name;
4717
- decodeResult.formatted.description = "Weather Report";
4718
- decodeResult.message = message;
4719
- const parts = message.text.split(" ");
4720
- if (parts[parts.length - 1] !== "Q") {
4721
- decodeResult.remaining.text = message.text;
4722
- decodeResult.decoded = false;
4723
- decodeResult.decoder.decodeLevel = "none";
4781
+ const decodeResult = this.initResult(message, "Position Report");
4782
+ const lines = message.text.split("\r\n");
4783
+ if (lines.length < 3) {
4724
4784
  return decodeResult;
4725
4785
  }
4726
- const windData = [];
4727
- decodeResult.remaining.text = "";
4728
- const header = parts[0];
4729
- if (header.length === 45) {
4730
- ResultFormatter.day(decodeResult, parseInt(header.substring(3, 5), 10));
4731
- ResultFormatter.departureAirport(decodeResult, header.substring(5, 9));
4732
- ResultFormatter.arrivalAirport(decodeResult, header.substring(9, 13));
4733
- const firstWind = this.parseWeatherReport(header.substring(13));
4734
- if (firstWind) {
4735
- windData.push(firstWind);
4786
+ ResultFormatter.unknown(decodeResult, lines[0], "\r\n");
4787
+ ResultFormatter.unknown(decodeResult, lines[1].substring(0, 5), "\r\n");
4788
+ ResultFormatter.departureAirport(decodeResult, lines[1].substring(5, 9));
4789
+ ResultFormatter.arrivalAirport(decodeResult, lines[1].substring(9, 13));
4790
+ ResultFormatter.unknown(decodeResult, lines[1].substring(13), "");
4791
+ const waypoints = [];
4792
+ for (const line of lines.slice(2)) {
4793
+ const position = CoordinateUtils.decodeStringCoordinates(
4794
+ line.substring(0, 13)
4795
+ );
4796
+ if (position) {
4797
+ waypoints.push({
4798
+ name: CoordinateUtils.coordinateString(position),
4799
+ latitude: position.latitude,
4800
+ longitude: position.longitude,
4801
+ time: DateTimeUtils.convertHHMMSSToTod(line.substring(13, 19))
4802
+ });
4736
4803
  } else {
4737
- decodeResult.remaining.text += (decodeResult.remaining.text ? " " : "") + header.substring(13);
4804
+ ResultFormatter.unknown(decodeResult, line.substring(0, 19), "");
4738
4805
  }
4806
+ ResultFormatter.unknown(decodeResult, line.substring(19), "\r\n");
4739
4807
  }
4740
- for (let i = 1; i < parts.length - 1; i++) {
4741
- const part = parts[i];
4742
- if (part[0] !== "Q") {
4743
- decodeResult.remaining.text += (decodeResult.remaining.text ? " " : "") + part;
4744
- continue;
4808
+ ResultFormatter.route(decodeResult, { waypoints });
4809
+ if (waypoints.length > 0) {
4810
+ const lastWaypoint = waypoints[waypoints.length - 1];
4811
+ if (lastWaypoint.latitude !== void 0 && lastWaypoint.longitude !== void 0) {
4812
+ ResultFormatter.position(decodeResult, {
4813
+ latitude: lastWaypoint.latitude,
4814
+ longitude: lastWaypoint.longitude
4815
+ });
4745
4816
  }
4746
- const wind = this.parseWeatherReport(part.substring(1));
4747
- if (wind) {
4748
- windData.push(wind);
4749
- } else {
4750
- decodeResult.remaining.text += (decodeResult.remaining.text ? " " : "") + part;
4817
+ if (lastWaypoint.time !== void 0) {
4818
+ ResultFormatter.timestamp(decodeResult, lastWaypoint.time);
4751
4819
  }
4752
4820
  }
4753
- ResultFormatter.windData(decodeResult, windData);
4754
4821
  decodeResult.decoded = true;
4755
- decodeResult.decoder.decodeLevel = decodeResult.remaining.text.length === 0 ? "full" : "partial";
4822
+ decodeResult.decoder.decodeLevel = "partial";
4756
4823
  return decodeResult;
4757
4824
  }
4758
- parseWeatherReport(text) {
4759
- const posString = text.substring(0, 13);
4760
- const pos = CoordinateUtils.decodeStringCoordinatesDecimalMinutes(posString);
4761
- if (text.length !== 32 || !pos) {
4762
- return null;
4763
- }
4764
- const tod = DateTimeUtils.convertHHMMSSToTod(text.substring(13, 17));
4765
- const flightLevel = parseInt(text.substring(17, 20), 10);
4766
- const tempSign = text[21] === "M" ? -1 : 1;
4767
- const tempDegreesRaw = parseInt(text.substring(22, 25), 10);
4768
- const tempDegrees = tempSign * (tempDegreesRaw / 10);
4769
- const windDirection = parseInt(text.substring(25, 28), 10);
4770
- const windSpeed = parseInt(text.substring(28, 31), 10);
4771
- if (text[31] !== "G") {
4772
- return null;
4773
- }
4774
- return {
4775
- waypoint: {
4776
- name: posString,
4777
- latitude: pos.latitude,
4778
- longitude: pos.longitude,
4779
- time: tod
4780
- },
4781
- flightLevel,
4782
- windDirection,
4783
- windSpeed,
4784
- temperature: {
4785
- flightLevel,
4786
- degreesC: tempDegrees
4787
- }
4788
- };
4789
- }
4790
4825
  };
4791
4826
 
4792
4827
  // lib/plugins/Label_H1_ATIS.ts
@@ -5444,6 +5479,93 @@ var Label_H1_WRN = class extends DecoderPlugin {
5444
5479
  }
5445
5480
  };
5446
5481
 
5482
+ // lib/plugins/Label_H2_02E.ts
5483
+ var Label_H2_02E = class extends DecoderPlugin {
5484
+ name = "label-h2-02e";
5485
+ qualifiers() {
5486
+ return {
5487
+ labels: ["H2"],
5488
+ preambles: ["02E"]
5489
+ };
5490
+ }
5491
+ decode(message, options = {}) {
5492
+ let decodeResult = this.defaultResult();
5493
+ decodeResult.decoder.name = this.name;
5494
+ decodeResult.formatted.description = "Weather Report";
5495
+ decodeResult.message = message;
5496
+ const parts = message.text.split(" ");
5497
+ if (parts[parts.length - 1] !== "Q") {
5498
+ decodeResult.remaining.text = message.text;
5499
+ decodeResult.decoded = false;
5500
+ decodeResult.decoder.decodeLevel = "none";
5501
+ return decodeResult;
5502
+ }
5503
+ const windData = [];
5504
+ decodeResult.remaining.text = "";
5505
+ const header = parts[0];
5506
+ if (header.length === 45) {
5507
+ ResultFormatter.day(decodeResult, parseInt(header.substring(3, 5), 10));
5508
+ ResultFormatter.departureAirport(decodeResult, header.substring(5, 9));
5509
+ ResultFormatter.arrivalAirport(decodeResult, header.substring(9, 13));
5510
+ const firstWind = this.parseWeatherReport(header.substring(13));
5511
+ if (firstWind) {
5512
+ windData.push(firstWind);
5513
+ } else {
5514
+ decodeResult.remaining.text += (decodeResult.remaining.text ? " " : "") + header.substring(13);
5515
+ }
5516
+ }
5517
+ for (let i = 1; i < parts.length - 1; i++) {
5518
+ const part = parts[i];
5519
+ if (part[0] !== "Q") {
5520
+ decodeResult.remaining.text += (decodeResult.remaining.text ? " " : "") + part;
5521
+ continue;
5522
+ }
5523
+ const wind = this.parseWeatherReport(part.substring(1));
5524
+ if (wind) {
5525
+ windData.push(wind);
5526
+ } else {
5527
+ decodeResult.remaining.text += (decodeResult.remaining.text ? " " : "") + part;
5528
+ }
5529
+ }
5530
+ ResultFormatter.windData(decodeResult, windData);
5531
+ decodeResult.decoded = true;
5532
+ decodeResult.decoder.decodeLevel = decodeResult.remaining.text.length === 0 ? "full" : "partial";
5533
+ return decodeResult;
5534
+ }
5535
+ parseWeatherReport(text) {
5536
+ const posString = text.substring(0, 13);
5537
+ const pos = CoordinateUtils.decodeStringCoordinatesDecimalMinutes(posString);
5538
+ if (text.length !== 32 || !pos) {
5539
+ return null;
5540
+ }
5541
+ const tod = DateTimeUtils.convertHHMMSSToTod(text.substring(13, 17));
5542
+ const flightLevel = parseInt(text.substring(17, 20), 10);
5543
+ const tempSign = text[21] === "M" ? -1 : 1;
5544
+ const tempDegreesRaw = parseInt(text.substring(22, 25), 10);
5545
+ const tempDegrees = tempSign * (tempDegreesRaw / 10);
5546
+ const windDirection = parseInt(text.substring(25, 28), 10);
5547
+ const windSpeed = parseInt(text.substring(28, 31), 10);
5548
+ if (text[31] !== "G") {
5549
+ return null;
5550
+ }
5551
+ return {
5552
+ waypoint: {
5553
+ name: posString,
5554
+ latitude: pos.latitude,
5555
+ longitude: pos.longitude,
5556
+ time: tod
5557
+ },
5558
+ flightLevel,
5559
+ windDirection,
5560
+ windSpeed,
5561
+ temperature: {
5562
+ flightLevel,
5563
+ degreesC: tempDegrees
5564
+ }
5565
+ };
5566
+ }
5567
+ };
5568
+
5447
5569
  // lib/plugins/Label_HX.ts
5448
5570
  var Label_HX = class extends DecoderPlugin {
5449
5571
  name = "label-hx";
@@ -5516,8 +5638,8 @@ function ascii85Decode(input) {
5516
5638
  if (digit < 0 || digit > 84) return null;
5517
5639
  value = value * 85 + digit;
5518
5640
  }
5519
- if (chunkLen === 5 && value > 4294967295) return null;
5520
- const v = value >>> 0;
5641
+ if (value > 4294967295) return null;
5642
+ const v = value;
5521
5643
  const numBytes = chunkLen === 5 ? 4 : chunkLen - 1;
5522
5644
  if (numBytes >= 1) output.push(v >>> 24 & 255);
5523
5645
  if (numBytes >= 2) output.push(v >>> 16 & 255);
@@ -6734,6 +6856,7 @@ var Label_QQ = class extends DecoderPlugin {
6734
6856
  // lib/MessageDecoder.ts
6735
6857
  var pluginClasses = [
6736
6858
  CBand,
6859
+ LibAcars,
6737
6860
  Arinc702,
6738
6861
  Label_ColonComma,
6739
6862
  Label_5Z_Slash,
@@ -6778,7 +6901,7 @@ var pluginClasses = [
6778
6901
  Label_4T_AGFSR,
6779
6902
  Label_4T_ETA,
6780
6903
  Label_B6_Forwardslash,
6781
- Label_H2_02E,
6904
+ Label_H1_76401,
6782
6905
  Label_H1_ATIS,
6783
6906
  Label_H1_EZF,
6784
6907
  Label_H1_FLR,
@@ -6788,6 +6911,7 @@ var pluginClasses = [
6788
6911
  Label_H1_Paren,
6789
6912
  Label_H1_WRN,
6790
6913
  Label_H1_StarPOS,
6914
+ Label_H2_02E,
6791
6915
  Label_HX,
6792
6916
  Label_58,
6793
6917
  Label_80,
@@ -6833,6 +6957,9 @@ var MessageDecoder = class {
6833
6957
  this.wildcardSet.add(plugin);
6834
6958
  const wildcardInsertIndex = this.wildcardEntries.length - 1;
6835
6959
  for (const bucket of this.candidatesByLabel.values()) {
6960
+ if (bucket.some((e) => e.plugin === plugin)) {
6961
+ continue;
6962
+ }
6836
6963
  bucket.splice(wildcardInsertIndex, 0, entry);
6837
6964
  }
6838
6965
  }