@iotize/device-client.js
Version:
IoTize Device client for Javascript
41 lines (40 loc) • 1.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var lwm2m_command_converter_1 = require("./lwm2m-command-converter");
var core_1 = require("../../../core");
var error_1 = require("../../api/converter/error");
var DefaultCommandDecoder = /** @class */ (function () {
function DefaultCommandDecoder() {
this.iotizeFrameConverter = new lwm2m_command_converter_1.IotizeLWM2MCommandConverter();
this.apduDecoder = new core_1.APDU.Command.APDUCommandConverter();
}
DefaultCommandDecoder.instance = function () {
return new DefaultCommandDecoder();
};
DefaultCommandDecoder.prototype.decode = function (iotizeEncodedCommandWithAPDU) {
// logger.debug(DefaultCommandDecoder.TAG, "Decoding command (with APDU): ", FormatHelper.toHexString(iotizeEncodedCommandWithAPDU));
var apduModel = this.apduDecoder.decode(iotizeEncodedCommandWithAPDU);
// byte cmd = apduModel.getInstructionCode();
// Data
// var data;
// if (lenData > 0) {
// data = new byte[lenData];
// System.arraycopy(buffer, 12, data, 0, lenData);
// }
// else{
// data = null;
// }
var frame = apduModel.getData();
if (frame == null || frame.length == 0) {
throw error_1.ConverterError.nullBufferError("Cannot decode command, buffer is empty");
}
else if (frame.length < DefaultCommandDecoder.IOTIZE_TRAME_HEADER_LENGTH) {
throw new Error("Frame is smaller than the minimum iotize trame size");
}
return this.iotizeFrameConverter.decode(frame);
};
DefaultCommandDecoder.IOTIZE_TRAME_HEADER_LENGTH = 7;
DefaultCommandDecoder.TAG = "DefaultCommandDecoder";
return DefaultCommandDecoder;
}());
exports.DefaultCommandDecoder = DefaultCommandDecoder;