node-djiparsetxt
Version:
command-line application that reads a DJI '.txt' file and outputs a json.
115 lines • 5.38 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BinaryParserService = exports.ParserTypes = void 0;
var ServiceManager_1 = require("../common/ServiceManager");
var BaseService_1 = __importDefault(require("./BaseService"));
var BinaryParserTable_1 = require("./BinaryParserTable");
var RecordTypes_1 = require("./RecordTypes");
var ParserTypes;
(function (ParserTypes) {
ParserTypes["Header"] = "header";
ParserTypes["BaseRecord"] = "base_record";
ParserTypes["StartRecord"] = "start_record";
ParserTypes["Details"] = "details";
ParserTypes["OsdRecord"] = "osd_record";
ParserTypes["HomeRecord"] = "home_record";
ParserTypes["GimbalRecord"] = "gimbal_record";
ParserTypes["RcRecord"] = "rc_record";
ParserTypes["CustomRecord"] = "custom_record";
ParserTypes["DeformRecord"] = "deform_record";
ParserTypes["CenterBatteryRecord"] = "center_battery_record";
ParserTypes["SmartBatteryRecord"] = "smart_battery_record";
ParserTypes["AppTipRecord"] = "app_tip_record";
ParserTypes["AppWarnRecord"] = "app_warn_record";
ParserTypes["RecoverRecord"] = "recover_record";
ParserTypes["AppGpsRecord"] = "app_gps_record";
ParserTypes["FirmwareRecord"] = "firmware_record";
})(ParserTypes = exports.ParserTypes || (exports.ParserTypes = {}));
var BinaryParserService = /** @class */ (function (_super) {
__extends(BinaryParserService, _super);
function BinaryParserService() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Returns an instance of the requested parser by the type of parser.
* @param type Entry in ParserTypes enum for the requested parser.
*/
BinaryParserService.prototype.get_parser = function (type) {
if (BinaryParserTable_1.PARSER_TABLE[type] == null) {
return undefined;
}
if (BinaryParserTable_1.PARSER_TABLE[type].instance == null) {
var factory = BinaryParserTable_1.PARSER_TABLE[type].factory;
BinaryParserTable_1.PARSER_TABLE[type].instance = factory();
}
return BinaryParserTable_1.PARSER_TABLE[type].instance;
};
/**
* Returns an instance of a parser based on given record type. This
* parser should be able to parse the given record type.
* @param recordType The type of the record parsed by the parser.
*/
BinaryParserService.prototype.get_record_parser = function (recordType) {
var parserService = this.serviceMan.get_service(ServiceManager_1.ServiceTypes.Parsers);
var parserType = this.parser_record_mapping(recordType);
if (parserType === null) {
throw new Error("record type '" + recordType + "' not recognized");
}
return parserService.get_parser(parserType);
};
/**
* Mapping between record type and the parser that can parse them.
* @param recordType The type of the record to get its corresponding parser type.
*/
BinaryParserService.prototype.parser_record_mapping = function (recordType) {
switch (recordType) {
case RecordTypes_1.RecordTypes.OSD:
return ParserTypes.OsdRecord;
case RecordTypes_1.RecordTypes.CUSTOM:
return ParserTypes.CustomRecord;
case RecordTypes_1.RecordTypes.RC:
return ParserTypes.RcRecord;
case RecordTypes_1.RecordTypes.GIMBAL:
return ParserTypes.GimbalRecord;
case RecordTypes_1.RecordTypes.HOME:
return ParserTypes.HomeRecord;
case RecordTypes_1.RecordTypes.DEFORM:
return ParserTypes.DeformRecord;
case RecordTypes_1.RecordTypes.CENTER_BATTERY:
return ParserTypes.CenterBatteryRecord;
case RecordTypes_1.RecordTypes.SMART_BATTERY:
return ParserTypes.SmartBatteryRecord;
case RecordTypes_1.RecordTypes.APP_TIP:
return ParserTypes.AppTipRecord;
case RecordTypes_1.RecordTypes.APP_WARN:
return ParserTypes.AppWarnRecord;
case RecordTypes_1.RecordTypes.RECOVER:
return ParserTypes.RecoverRecord;
case RecordTypes_1.RecordTypes.APP_GPS:
return ParserTypes.AppGpsRecord;
case RecordTypes_1.RecordTypes.FIRMWARE:
return ParserTypes.FirmwareRecord;
default:
return null;
}
};
return BinaryParserService;
}(BaseService_1.default));
exports.BinaryParserService = BinaryParserService;
//# sourceMappingURL=BinaryParserService.js.map