UNPKG

node-djiparsetxt

Version:

command-line application that reads a DJI '.txt' file and outputs a json.

102 lines 4.5 kB
"use strict"; 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 __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.PrintInfoCommand = void 0; var ServiceManager_1 = require("../common/ServiceManager"); var RecordTypes_1 = require("../services/RecordTypes"); var Command_1 = require("./Command"); var PrintInfoCommand = /** @class */ (function (_super) { __extends(PrintInfoCommand, _super); function PrintInfoCommand() { return _super !== null && _super.apply(this, arguments) || this; } PrintInfoCommand.prototype.exec = function (options) { var serviceMan = this.serviceMan; var fileInfoService = serviceMan.get_service(ServiceManager_1.ServiceTypes.FileInfo); var fileParsingService = serviceMan.get_service(ServiceManager_1.ServiceTypes.FileParsing); var file = options.file; if (file.buffer === null) { return ""; } // show header details this.log("file \"" + file.path + "\""); if (options.printHeader) { var headerInfo = fileInfoService.get_header_info(file.buffer); this.log(" Header Info:"); this.log(" file size = " + headerInfo.file_size + " B"); this.log(" records area size = " + headerInfo.records_size + " B"); this.log(" details area size = " + headerInfo.details_size + " B"); this.log(" version:", headerInfo.version); } var records = null; if (options.printRecords) { this.log(" Records Info:"); records = fileParsingService.parse_records(file.buffer); if (records !== null) { var stats = records.stats; this.log(" records area size = " + stats.records_area_size + " B"); this.log(" record count = " + stats.record_count + " Records"); this.log(" invalid records = " + stats.invalid_records); this.log(" Records in File:"); this.print_type_count_table(stats.type_count, " "); } } if (options.printDetails) { this.log(" Details:"); var details = fileInfoService.get_details(file.buffer); for (var key in details) { if (details.hasOwnProperty(key)) { this.log(" " + key + " = " + details[key]); } } } if (options.printDistribution) { if (records === null) { records = fileParsingService.parse_records(file.buffer); } if (records !== null) { this.log(" Record Distribution:"); this.log(records.records.map(function (val) { return val.type; })); } } return this.getLog(); }; PrintInfoCommand.prototype.print_type_count_table = function (typeCount, indent) { var maxWidth = Object.keys(typeCount).reduce(function (acc, val) { var name = RecordTypes_1.RecordTypes[parseInt(val, 10)]; if (name === undefined) { return acc; } return Math.max(acc, name.length); }, 0); // hacky way of aligning for (var key in typeCount) { if (typeCount.hasOwnProperty(key)) { var hexRep = parseInt(key, 10).toString(16); if (hexRep.length === 1) { hexRep = "0" + hexRep; } var part = "(" + RecordTypes_1.RecordTypes[key] + ")"; if (maxWidth - (part.length - 2) !== 0) { part += " ".repeat(maxWidth - part.length + 2); } console.log(indent + "0x" + hexRep, part, "= " + typeCount[key]); } } }; return PrintInfoCommand; }(Command_1.Command)); exports.PrintInfoCommand = PrintInfoCommand; //# sourceMappingURL=PrintInfoCommand.js.map