UNPKG

node-djiparsetxt

Version:

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

78 lines 3.07 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 __()); }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ScrambleTableService = void 0; var BaseService_1 = __importDefault(require("./BaseService")); var RecordTypes_1 = require("./RecordTypes"); var ScrambleTable_1 = require("./ScrambleTable"); var ScrambleTableService = /** @class */ (function (_super) { __extends(ScrambleTableService, _super); function ScrambleTableService() { var _this = _super !== null && _super.apply(this, arguments) || this; _this._scrambleTable = []; return _this; } Object.defineProperty(ScrambleTableService.prototype, "scrambleTable", { get: function () { if (this._scrambleTable.length === 0) { this._scrambleTable = ScrambleTable_1.scrambleTable; } return this._scrambleTable; }, enumerable: false, configurable: true }); ScrambleTableService.prototype.unscramble_record = function (record) { var data; if (record.type === RecordTypes_1.RecordTypes.JPEG) { data = record.data; } else { var uscrm = this.unscramble_buffer(record.data[0], record.type); if (uscrm == null) { data = record.data; } else { data = uscrm; } } return { type: record.type, length: record.length, data: data, }; }; ScrambleTableService.prototype.unscramble_buffer = function (buf, type) { var firstByte = buf.readUInt8(0); var scrambleKey = ((type - 1) << 8) | firstByte; var scrambleBytes = this.scrambleTable[scrambleKey]; if (scrambleBytes === undefined) { return null; } var unscrambledBuf = Buffer.alloc(buf.length - 1); for (var writeOffset = 1; writeOffset < buf.length; writeOffset++) { var scrambleEntry = scrambleBytes[(writeOffset - 1) % 8]; var val = buf.readUInt8(writeOffset) ^ scrambleEntry; unscrambledBuf.writeUInt8(val, writeOffset - 1); } return [unscrambledBuf]; }; return ScrambleTableService; }(BaseService_1.default)); exports.ScrambleTableService = ScrambleTableService; //# sourceMappingURL=ScrambleTableService.js.map