@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.js CHANGED
@@ -209,7 +209,9 @@ var DateTimeUtils = class {
209
209
  const hours = +timeString.substr(0, 2);
210
210
  const minutes = +timeString.substr(2, 2);
211
211
  const seconds = timeString.length === 6 ? +timeString.substr(4, 2) : 0;
212
- const utcDate = new Date(Date.UTC(year, month, day, hours, minutes, seconds));
212
+ const utcDate = new Date(
213
+ Date.UTC(year, month, day, hours, minutes, seconds)
214
+ );
213
215
  return utcDate.toUTCString();
214
216
  }
215
217
  /**
@@ -266,8 +268,9 @@ var DateTimeUtils = class {
266
268
  if (time < 86400) {
267
269
  return date.toISOString().slice(11, 19);
268
270
  }
269
- if (time < 2678400) {
270
- return `YYYY-MM-${date.toISOString().slice(8, 19)}`;
271
+ if (time < 32 * 86400) {
272
+ const day = String(Math.floor(time / 86400)).padStart(2, "0");
273
+ return `YYYY-MM-${day}T${date.toISOString().slice(11, 19)}`;
271
274
  }
272
275
  return date.toISOString().slice(0, -5) + "Z";
273
276
  }
@@ -901,6 +904,9 @@ var ResultFormatter = class {
901
904
  }
902
905
  }
903
906
  static version(decodeResult, value) {
907
+ if (isNaN(value)) {
908
+ return;
909
+ }
904
910
  decodeResult.raw.version = value;
905
911
  decodeResult.formatted.items.push({
906
912
  type: "version",
@@ -937,6 +943,9 @@ var ResultFormatter = class {
937
943
  });
938
944
  }
939
945
  static desiredAltitude(decodeResult, value) {
946
+ if (isNaN(value)) {
947
+ return;
948
+ }
940
949
  decodeResult.raw.desired_alt = value;
941
950
  decodeResult.formatted.items.push({
942
951
  type: "desired_altitude",
@@ -1113,6 +1122,43 @@ var DecoderPlugin = class {
1113
1122
  }
1114
1123
  };
1115
1124
 
1125
+ // lib/plugins/Lib_ACARS.ts
1126
+ var LibAcars = class extends DecoderPlugin {
1127
+ name = "libacars";
1128
+ qualifiers() {
1129
+ return {
1130
+ labels: ["*"],
1131
+ preambles: ["- #"]
1132
+ };
1133
+ }
1134
+ decode(message, options = {}) {
1135
+ const text = message.text;
1136
+ const prefix = message.text.slice(0, 5);
1137
+ const decoded = this.decoder.decode(
1138
+ {
1139
+ label: message.label,
1140
+ sublabel: message.sublabel,
1141
+ text: text.replaceAll(prefix, "")
1142
+ // Remove the prefix before decoding
1143
+ },
1144
+ options
1145
+ );
1146
+ const decodeResult = this.defaultResult();
1147
+ decodeResult.decoder.name = this.name;
1148
+ decodeResult.message = message;
1149
+ if (decoded.decoded) {
1150
+ decodeResult.decoded = true;
1151
+ decodeResult.decoder.decodeLevel = decoded.decoder.decodeLevel;
1152
+ decodeResult.decoder.name = this.name + "-" + decoded.decoder.name;
1153
+ decodeResult.raw = { ...decodeResult.raw, ...decoded.raw };
1154
+ decodeResult.formatted.description = decoded.formatted.description;
1155
+ decodeResult.formatted.items.push(...decoded.formatted.items);
1156
+ decodeResult.remaining = decoded.remaining;
1157
+ }
1158
+ return decodeResult;
1159
+ }
1160
+ };
1161
+
1116
1162
  // lib/plugins/CBand.ts
1117
1163
  var CBAND_HEADER = /^(?<msgno>[A-Z]\d{2}[A-Z])(?<airline>[A-Z0-9]{2})(?<number>[0-9]{4})/;
1118
1164
  var CBand = class extends DecoderPlugin {
@@ -1474,6 +1520,9 @@ var Arinc702Helper = class _Arinc702Helper {
1474
1520
  case "TD":
1475
1521
  processTimeOfDeparture(decodeResult, data2.split(","));
1476
1522
  break;
1523
+ case "TR":
1524
+ processTR(decodeResult, data2.split(","));
1525
+ break;
1477
1526
  case "TS":
1478
1527
  _Arinc702Helper.processTimeStamp(decodeResult, data2.split(","));
1479
1528
  break;
@@ -1654,6 +1703,21 @@ function processLandingReport(decodeResult, data) {
1654
1703
  ResultFormatter.unknown(decodeResult, data.join(","));
1655
1704
  }
1656
1705
  }
1706
+ function processTR(decodeResult, data) {
1707
+ if (data.length !== 21) {
1708
+ ResultFormatter.unknownArr(decodeResult, data, ",");
1709
+ return;
1710
+ }
1711
+ ResultFormatter.unknownArr(decodeResult, data.slice(0, 5), ",");
1712
+ ResultFormatter.off(decodeResult, DateTimeUtils.convertHHMMSSToTod(data[5]));
1713
+ ResultFormatter.unknownArr(decodeResult, data.slice(6, 11), ",");
1714
+ ResultFormatter.departureAirport(decodeResult, data[11]);
1715
+ ResultFormatter.arrivalAirport(decodeResult, data[12]);
1716
+ ResultFormatter.departureRunway(decodeResult, data[13]);
1717
+ ResultFormatter.unknownArr(decodeResult, data.slice(14, 16), ",");
1718
+ ResultFormatter.flightNumber(decodeResult, data[16]);
1719
+ ResultFormatter.unknownArr(decodeResult, data.slice(17), ",");
1720
+ }
1657
1721
  function processCenterOfGravity(decodeResult, data) {
1658
1722
  if (data.length === 1) {
1659
1723
  if (data[0] !== void 0 && data[0] !== "") {
@@ -1714,6 +1778,8 @@ function processIMI(decodeResult, type) {
1714
1778
  decodeResult.formatted.description = "Load Distribution Information";
1715
1779
  } else if (type === "PER") {
1716
1780
  decodeResult.formatted.description = "Performance Report";
1781
+ } else if (type === "PRF") {
1782
+ decodeResult.formatted.description = "Profile Report";
1717
1783
  } else if (type === "POS") {
1718
1784
  decodeResult.formatted.description = "Position Report";
1719
1785
  } else if (type === "PRG") {
@@ -1953,7 +2019,7 @@ var Arinc702 = class extends DecoderPlugin {
1953
2019
  }
1954
2020
  const hashParts = msg.split("#");
1955
2021
  if (hashParts.length == 2) {
1956
- const offset = hashParts[0] === "- " || isNaN(parseInt(hashParts[1][1])) ? 3 : 4;
2022
+ const offset = isNaN(parseInt(hashParts[1][1])) ? 3 : 4;
1957
2023
  decoded = Arinc702Helper.decodeH1Message(
1958
2024
  decodeResult,
1959
2025
  msg.slice(hashParts[0].length + offset)
@@ -4739,91 +4805,60 @@ var Label_ColonComma = class extends DecoderPlugin {
4739
4805
  }
4740
4806
  };
4741
4807
 
4742
- // lib/plugins/Label_H2_02E.ts
4743
- var Label_H2_02E = class extends DecoderPlugin {
4744
- name = "label-h2-02e";
4808
+ // lib/plugins/Label_H1_76401.ts
4809
+ var Label_H1_76401 = class extends DecoderPlugin {
4810
+ name = "label-h1-76401";
4745
4811
  qualifiers() {
4746
4812
  return {
4747
- labels: ["H2"],
4748
- preambles: ["02E"]
4813
+ labels: ["H1"],
4814
+ preambles: ["76401\r\n"]
4749
4815
  };
4750
4816
  }
4751
4817
  decode(message, options = {}) {
4752
- let decodeResult = this.defaultResult();
4753
- decodeResult.decoder.name = this.name;
4754
- decodeResult.formatted.description = "Weather Report";
4755
- decodeResult.message = message;
4756
- const parts = message.text.split(" ");
4757
- if (parts[parts.length - 1] !== "Q") {
4758
- decodeResult.remaining.text = message.text;
4759
- decodeResult.decoded = false;
4760
- decodeResult.decoder.decodeLevel = "none";
4818
+ const decodeResult = this.initResult(message, "Position Report");
4819
+ const lines = message.text.split("\r\n");
4820
+ if (lines.length < 3) {
4761
4821
  return decodeResult;
4762
4822
  }
4763
- const windData = [];
4764
- decodeResult.remaining.text = "";
4765
- const header = parts[0];
4766
- if (header.length === 45) {
4767
- ResultFormatter.day(decodeResult, parseInt(header.substring(3, 5), 10));
4768
- ResultFormatter.departureAirport(decodeResult, header.substring(5, 9));
4769
- ResultFormatter.arrivalAirport(decodeResult, header.substring(9, 13));
4770
- const firstWind = this.parseWeatherReport(header.substring(13));
4771
- if (firstWind) {
4772
- windData.push(firstWind);
4823
+ ResultFormatter.unknown(decodeResult, lines[0], "\r\n");
4824
+ ResultFormatter.unknown(decodeResult, lines[1].substring(0, 5), "\r\n");
4825
+ ResultFormatter.departureAirport(decodeResult, lines[1].substring(5, 9));
4826
+ ResultFormatter.arrivalAirport(decodeResult, lines[1].substring(9, 13));
4827
+ ResultFormatter.unknown(decodeResult, lines[1].substring(13), "");
4828
+ const waypoints = [];
4829
+ for (const line of lines.slice(2)) {
4830
+ const position = CoordinateUtils.decodeStringCoordinates(
4831
+ line.substring(0, 13)
4832
+ );
4833
+ if (position) {
4834
+ waypoints.push({
4835
+ name: CoordinateUtils.coordinateString(position),
4836
+ latitude: position.latitude,
4837
+ longitude: position.longitude,
4838
+ time: DateTimeUtils.convertHHMMSSToTod(line.substring(13, 19))
4839
+ });
4773
4840
  } else {
4774
- decodeResult.remaining.text += (decodeResult.remaining.text ? " " : "") + header.substring(13);
4841
+ ResultFormatter.unknown(decodeResult, line.substring(0, 19), "");
4775
4842
  }
4843
+ ResultFormatter.unknown(decodeResult, line.substring(19), "\r\n");
4776
4844
  }
4777
- for (let i = 1; i < parts.length - 1; i++) {
4778
- const part = parts[i];
4779
- if (part[0] !== "Q") {
4780
- decodeResult.remaining.text += (decodeResult.remaining.text ? " " : "") + part;
4781
- continue;
4845
+ ResultFormatter.route(decodeResult, { waypoints });
4846
+ if (waypoints.length > 0) {
4847
+ const lastWaypoint = waypoints[waypoints.length - 1];
4848
+ if (lastWaypoint.latitude !== void 0 && lastWaypoint.longitude !== void 0) {
4849
+ ResultFormatter.position(decodeResult, {
4850
+ latitude: lastWaypoint.latitude,
4851
+ longitude: lastWaypoint.longitude
4852
+ });
4782
4853
  }
4783
- const wind = this.parseWeatherReport(part.substring(1));
4784
- if (wind) {
4785
- windData.push(wind);
4786
- } else {
4787
- decodeResult.remaining.text += (decodeResult.remaining.text ? " " : "") + part;
4854
+ if (lastWaypoint.time !== void 0) {
4855
+ ResultFormatter.timestamp(decodeResult, lastWaypoint.time);
4788
4856
  }
4789
4857
  }
4790
- ResultFormatter.windData(decodeResult, windData);
4791
4858
  decodeResult.decoded = true;
4792
- decodeResult.decoder.decodeLevel = decodeResult.remaining.text.length === 0 ? "full" : "partial";
4859
+ decodeResult.decoder.decodeLevel = "partial";
4793
4860
  return decodeResult;
4794
4861
  }
4795
- parseWeatherReport(text) {
4796
- const posString = text.substring(0, 13);
4797
- const pos = CoordinateUtils.decodeStringCoordinatesDecimalMinutes(posString);
4798
- if (text.length !== 32 || !pos) {
4799
- return null;
4800
- }
4801
- const tod = DateTimeUtils.convertHHMMSSToTod(text.substring(13, 17));
4802
- const flightLevel = parseInt(text.substring(17, 20), 10);
4803
- const tempSign = text[21] === "M" ? -1 : 1;
4804
- const tempDegreesRaw = parseInt(text.substring(22, 25), 10);
4805
- const tempDegrees = tempSign * (tempDegreesRaw / 10);
4806
- const windDirection = parseInt(text.substring(25, 28), 10);
4807
- const windSpeed = parseInt(text.substring(28, 31), 10);
4808
- if (text[31] !== "G") {
4809
- return null;
4810
- }
4811
- return {
4812
- waypoint: {
4813
- name: posString,
4814
- latitude: pos.latitude,
4815
- longitude: pos.longitude,
4816
- time: tod
4817
- },
4818
- flightLevel,
4819
- windDirection,
4820
- windSpeed,
4821
- temperature: {
4822
- flightLevel,
4823
- degreesC: tempDegrees
4824
- }
4825
- };
4826
- }
4827
4862
  };
4828
4863
 
4829
4864
  // lib/plugins/Label_H1_ATIS.ts
@@ -5481,6 +5516,93 @@ var Label_H1_WRN = class extends DecoderPlugin {
5481
5516
  }
5482
5517
  };
5483
5518
 
5519
+ // lib/plugins/Label_H2_02E.ts
5520
+ var Label_H2_02E = class extends DecoderPlugin {
5521
+ name = "label-h2-02e";
5522
+ qualifiers() {
5523
+ return {
5524
+ labels: ["H2"],
5525
+ preambles: ["02E"]
5526
+ };
5527
+ }
5528
+ decode(message, options = {}) {
5529
+ let decodeResult = this.defaultResult();
5530
+ decodeResult.decoder.name = this.name;
5531
+ decodeResult.formatted.description = "Weather Report";
5532
+ decodeResult.message = message;
5533
+ const parts = message.text.split(" ");
5534
+ if (parts[parts.length - 1] !== "Q") {
5535
+ decodeResult.remaining.text = message.text;
5536
+ decodeResult.decoded = false;
5537
+ decodeResult.decoder.decodeLevel = "none";
5538
+ return decodeResult;
5539
+ }
5540
+ const windData = [];
5541
+ decodeResult.remaining.text = "";
5542
+ const header = parts[0];
5543
+ if (header.length === 45) {
5544
+ ResultFormatter.day(decodeResult, parseInt(header.substring(3, 5), 10));
5545
+ ResultFormatter.departureAirport(decodeResult, header.substring(5, 9));
5546
+ ResultFormatter.arrivalAirport(decodeResult, header.substring(9, 13));
5547
+ const firstWind = this.parseWeatherReport(header.substring(13));
5548
+ if (firstWind) {
5549
+ windData.push(firstWind);
5550
+ } else {
5551
+ decodeResult.remaining.text += (decodeResult.remaining.text ? " " : "") + header.substring(13);
5552
+ }
5553
+ }
5554
+ for (let i = 1; i < parts.length - 1; i++) {
5555
+ const part = parts[i];
5556
+ if (part[0] !== "Q") {
5557
+ decodeResult.remaining.text += (decodeResult.remaining.text ? " " : "") + part;
5558
+ continue;
5559
+ }
5560
+ const wind = this.parseWeatherReport(part.substring(1));
5561
+ if (wind) {
5562
+ windData.push(wind);
5563
+ } else {
5564
+ decodeResult.remaining.text += (decodeResult.remaining.text ? " " : "") + part;
5565
+ }
5566
+ }
5567
+ ResultFormatter.windData(decodeResult, windData);
5568
+ decodeResult.decoded = true;
5569
+ decodeResult.decoder.decodeLevel = decodeResult.remaining.text.length === 0 ? "full" : "partial";
5570
+ return decodeResult;
5571
+ }
5572
+ parseWeatherReport(text) {
5573
+ const posString = text.substring(0, 13);
5574
+ const pos = CoordinateUtils.decodeStringCoordinatesDecimalMinutes(posString);
5575
+ if (text.length !== 32 || !pos) {
5576
+ return null;
5577
+ }
5578
+ const tod = DateTimeUtils.convertHHMMSSToTod(text.substring(13, 17));
5579
+ const flightLevel = parseInt(text.substring(17, 20), 10);
5580
+ const tempSign = text[21] === "M" ? -1 : 1;
5581
+ const tempDegreesRaw = parseInt(text.substring(22, 25), 10);
5582
+ const tempDegrees = tempSign * (tempDegreesRaw / 10);
5583
+ const windDirection = parseInt(text.substring(25, 28), 10);
5584
+ const windSpeed = parseInt(text.substring(28, 31), 10);
5585
+ if (text[31] !== "G") {
5586
+ return null;
5587
+ }
5588
+ return {
5589
+ waypoint: {
5590
+ name: posString,
5591
+ latitude: pos.latitude,
5592
+ longitude: pos.longitude,
5593
+ time: tod
5594
+ },
5595
+ flightLevel,
5596
+ windDirection,
5597
+ windSpeed,
5598
+ temperature: {
5599
+ flightLevel,
5600
+ degreesC: tempDegrees
5601
+ }
5602
+ };
5603
+ }
5604
+ };
5605
+
5484
5606
  // lib/plugins/Label_HX.ts
5485
5607
  var Label_HX = class extends DecoderPlugin {
5486
5608
  name = "label-hx";
@@ -5553,8 +5675,8 @@ function ascii85Decode(input) {
5553
5675
  if (digit < 0 || digit > 84) return null;
5554
5676
  value = value * 85 + digit;
5555
5677
  }
5556
- if (chunkLen === 5 && value > 4294967295) return null;
5557
- const v = value >>> 0;
5678
+ if (value > 4294967295) return null;
5679
+ const v = value;
5558
5680
  const numBytes = chunkLen === 5 ? 4 : chunkLen - 1;
5559
5681
  if (numBytes >= 1) output.push(v >>> 24 & 255);
5560
5682
  if (numBytes >= 2) output.push(v >>> 16 & 255);
@@ -6771,6 +6893,7 @@ var Label_QQ = class extends DecoderPlugin {
6771
6893
  // lib/MessageDecoder.ts
6772
6894
  var pluginClasses = [
6773
6895
  CBand,
6896
+ LibAcars,
6774
6897
  Arinc702,
6775
6898
  Label_ColonComma,
6776
6899
  Label_5Z_Slash,
@@ -6815,7 +6938,7 @@ var pluginClasses = [
6815
6938
  Label_4T_AGFSR,
6816
6939
  Label_4T_ETA,
6817
6940
  Label_B6_Forwardslash,
6818
- Label_H2_02E,
6941
+ Label_H1_76401,
6819
6942
  Label_H1_ATIS,
6820
6943
  Label_H1_EZF,
6821
6944
  Label_H1_FLR,
@@ -6825,6 +6948,7 @@ var pluginClasses = [
6825
6948
  Label_H1_Paren,
6826
6949
  Label_H1_WRN,
6827
6950
  Label_H1_StarPOS,
6951
+ Label_H2_02E,
6828
6952
  Label_HX,
6829
6953
  Label_58,
6830
6954
  Label_80,
@@ -6870,6 +6994,9 @@ var MessageDecoder = class {
6870
6994
  this.wildcardSet.add(plugin);
6871
6995
  const wildcardInsertIndex = this.wildcardEntries.length - 1;
6872
6996
  for (const bucket of this.candidatesByLabel.values()) {
6997
+ if (bucket.some((e) => e.plugin === plugin)) {
6998
+ continue;
6999
+ }
6873
7000
  bucket.splice(wildcardInsertIndex, 0, entry);
6874
7001
  }
6875
7002
  }