ads-b
Version:
Library for decoding ADS-B messages emitted from Aircraft
43 lines (42 loc) • 1.85 kB
JavaScript
;
/**
* MIT License
* Copyright (c) 2019 Matt Laver
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/mattlaver/ads-b/blob/master/LICENSE
*/
Object.defineProperty(exports, "__esModule", { value: true });
var IMessage_1 = require("../messages/IMessage");
var AircraftIdentificationDecoder = /** @class */ (function () {
function AircraftIdentificationDecoder() {
var _this = this;
this.characterSet = '#ABCDEFGHIJKLMNOPQRSTUVWXYZ _ 0123456789 ';
this.decodeAircraftCallsign = function (data) {
return _this.chunkFour(data.substr(2, 6)) + _this.chunkFour(data.substr(8, 6));
};
this.chunkFour = function (data) {
var firstByte = parseInt(data.substr(0, 2), 16);
var secondByte = parseInt(data.substr(2, 2), 16);
var thirdByte = parseInt(data.substr(4, 2), 16);
var one = firstByte >> 2;
var two = ((firstByte & 0x3) << 4) | (secondByte >> 4);
var three = ((secondByte & 0xf) << 2) | (thirdByte >> 6);
var four = thirdByte & 0x3f;
return _this.characterSet[one] + _this.characterSet[two] + _this.characterSet[three] + _this.characterSet[four];
};
}
AircraftIdentificationDecoder.prototype.isValid = function (typeCode) {
return typeCode >= 0 && typeCode <= 4;
};
AircraftIdentificationDecoder.prototype.decode = function (message) {
return {
data: {
callsign: this.decodeAircraftCallsign(message),
},
messageType: IMessage_1.MessageType.AircraftIdentifier,
};
};
return AircraftIdentificationDecoder;
}());
exports.AircraftIdentificationDecoder = AircraftIdentificationDecoder;