UNPKG

@iotize/tap

Version:

IoTize Device client for Javascript

768 lines (753 loc) 25.4 kB
import { AbstractService, extendServiceContainer } from '@iotize/tap'; import { TapRequestFrame } from '@iotize/tap/client/api'; import { SerialSettings } from '@iotize/tap/service/impl/target'; import { TapStreamReader, TapStreamWriter, enumKeyOrValueToNumber } from '@iotize/tap/client/impl'; import { converters } from '@iotize/tap/service/core'; import { KaitaiStreamWriter } from '@iotize/common/byte-stream'; var AdpControlIn; (function (AdpControlIn) { /* eslint-disable */ /** * This file was automatically generated by json-schema-to-typescript. * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, * and run json-schema-to-typescript to regenerate this file. */ let Command; (function (Command) { Command[Command["NONE"] = 0] = "NONE"; Command[Command["ZIP"] = 32769] = "ZIP"; Command[Command["UNZIP"] = 32770] = "UNZIP"; Command[Command["SET_TRANSMISSION_BUFFER_SIZE"] = 32771] = "SET_TRANSMISSION_BUFFER_SIZE"; Command[Command["TOTAL_BUFFER_SIZE"] = 32772] = "TOTAL_BUFFER_SIZE"; Command[Command["GET_TRANSMISSION_BUFFER_SIZE"] = 32773] = "GET_TRANSMISSION_BUFFER_SIZE"; Command[Command["SET_RESPONSE_DELIMITER_LOW"] = 32774] = "SET_RESPONSE_DELIMITER_LOW"; Command[Command["SET_RESPONSE_DELIMITER_HIGH"] = 32775] = "SET_RESPONSE_DELIMITER_HIGH"; Command[Command["SET_COMMAND_DELIMITER_LOW"] = 32776] = "SET_COMMAND_DELIMITER_LOW"; Command[Command["EXEC_COMMANDS"] = 32777] = "EXEC_COMMANDS"; })(Command = AdpControlIn.Command || (AdpControlIn.Command = {})); })(AdpControlIn || (AdpControlIn = {})); var AdpControlOut; (function (AdpControlOut) { /* eslint-disable */ /** * This file was automatically generated by json-schema-to-typescript. * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, * and run json-schema-to-typescript to regenerate this file. */ let ResultCode; (function (ResultCode) { ResultCode[ResultCode["NONE"] = 0] = "NONE"; ResultCode[ResultCode["OK"] = 32768] = "OK"; ResultCode[ResultCode["ZIP_TIMEOUT"] = 32769] = "ZIP_TIMEOUT"; ResultCode[ResultCode["UNZIP_TIMEOUT"] = 32770] = "UNZIP_TIMEOUT"; ResultCode[ResultCode["ZIP_ERROR"] = 32771] = "ZIP_ERROR"; ResultCode[ResultCode["UNZIP_ERROR"] = 32772] = "UNZIP_ERROR"; ResultCode[ResultCode["UNKNOWN_COMMAND"] = 32773] = "UNKNOWN_COMMAND"; ResultCode[ResultCode["INVALID_PARAM"] = 32774] = "INVALID_PARAM"; })(ResultCode = AdpControlOut.ResultCode || (AdpControlOut.ResultCode = {})); })(AdpControlOut || (AdpControlOut = {})); /** * Generated file. Do not edit */ TapStreamReader.prototype.readTapnpassProtocolConfiguration = function () { const model = {}; model.modbus = this.readTapnpassProtocolConfigurationModbus(); model.serial = this.readTapnpassProtocolConfigurationSerial(); model.usb = this.readTapnpassProtocolConfigurationUsb(); return model; }; TapStreamReader.prototype.readTapnpassProtocolConfigurationModbus = function () { const model = {}; model.slave = this.readUnsigned(1); this.forwardBits(3); model.offsetFirstRegister = this.readBoolean(1); return model; }; TapStreamReader.prototype.readTapnpassProtocolConfigurationSerial = function () { const model = {}; model.baudRate = this.readBits(20); model.identification = this.readBoolean(1); this.forwardBits(1); model.ledStatus = this.readBoolean(1); this.forwardBits(1); model.physicalPort = this.readBits(4); model.stopBits = this.readBits(2); model.bitParity = this.readBits(4); model.dataBits = this.readBits(2); model.handshakeDelimiter = this.readBits(4); model.hardwareFlowControl = this.readBits(4); model.timeout = this.readUnsigned(1); return model; }; TapStreamReader.prototype.readTapnpassProtocolConfigurationUsb = function () { const model = {}; model.aliases = []; while (!this.isEof()) { model.aliases.push(this.readTapnpassProtocolConfigurationUsbAlias()); } return model; }; TapStreamReader.prototype.readTapnpassProtocolConfigurationUsbAlias = function () { const model = {}; model.pid = this.readUnsigned(2); model.vid = this.readUnsigned(2); model.equ = this.readUnsigned(1); return model; }; TapStreamReader.prototype.readAdpStats = function () { const model = {}; model.header = this.readAdpStatsHeader(); model.state = this.readAdpStatsState(); model.uart = this.readAdpStatsUart(); model.usb = this.readAdpStatsUsb(); model.current = this.readBytes(4); model.com = this.readAdpStatsCom(); model.battery = this.readBytes(4); model.intern = this.readAdpStatsIntern(); return model; }; TapStreamReader.prototype.readAdpStatsHeader = function () { const model = {}; this.forwardBits(16); model.version = this.readAdpStatsVersion(); model.errorCode = this.readUnsigned(1); this.forwardBits(16); return model; }; TapStreamReader.prototype.readAdpStatsVersion = function () { const model = {}; model.major = this.readUnsigned(1); model.minor = this.readUnsigned(1); model.patch = this.readUnsigned(1); return model; }; TapStreamReader.prototype.readAdpStatsIntern = function () { const model = {}; model.time = this.readBytes(4); model.nbBoots = this.readBytes(4); model.nbShutdown = this.readBytes(2); model.nbAdpFault = this.readBytes(2); model.nbAdpMemFault = this.readBytes(2); model.nbAdpBusFault = this.readBytes(2); model.nbAdpUsageFault = this.readBytes(2); this.forwardBits(16); model.temperature = this.readBytes(4); return model; }; TapStreamReader.prototype.readAdpStatsState = function () { const model = {}; this.forwardBits(7); model.usbDisconnected = this.readBoolean(1); this.forwardBits(24); return model; }; TapStreamReader.prototype.readAdpStatsUart = function () { const model = {}; model.nbPartityError = this.readUnsigned(1); model.nbNoiseError = this.readUnsigned(1); model.nbFrameError = this.readUnsigned(1); model.nbDmaError = this.readUnsigned(1); model.nbTxError = this.readUnsigned(1); model.nbRxError = this.readUnsigned(1); model.nbOverRun = this.readUnsigned(1); this.forwardBits(8); return model; }; TapStreamReader.prototype.readAdpStatsUsb = function () { const model = {}; model.nbFail = this.readUnsigned(1); model.nbTimeout = this.readUnsigned(1); model.nbError = this.readUnsigned(1); model.nbUnknownClass = this.readUnsigned(1); model.nbDisconnect = this.readUnsigned(1); model.nbOff = this.readUnsigned(1); this.forwardBits(16); return model; }; TapStreamReader.prototype.readAdpStatsCom = function () { const model = {}; model.txBufferOverRun = this.readUnsigned(1); model.rxBufferOverRun = this.readUnsigned(1); model.nbErrorSettings = this.readUnsigned(1); this.forwardBits(8); model.nbComAdp = this.readBytes(4); return model; }; TapStreamReader.prototype.readAdpControlIn = function () { const model = {}; model.command = this.readUnsigned(2); model.param = this.readUnsigned(2); return model; }; TapStreamReader.prototype.readAdpControlOut = function () { const model = {}; model.resultCode = this.readUnsigned(2); model.param = this.readUnsigned(2); return model; }; // TapStreamWriter.prototype.write(model: TapnpassProtocolConfiguration) : TapStreamWriter{ // return this.writeTapnpassProtocolConfiguration(model) // } TapStreamWriter.prototype.writeTapnpassProtocolConfiguration = function (model) { this.writeTapnpassProtocolConfigurationModbus(model.modbus); this.writeTapnpassProtocolConfigurationSerial(model.serial); this.writeTapnpassProtocolConfigurationUsb(model.usb); return this; }; TapStreamWriter.prototype.writeTapnpassProtocolConfigurationModbus = function (model) { this.writeUnsigned(model.slave, 1); this.forwardBits(3); this.writeBoolean(model.offsetFirstRegister, 1); return this; }; TapStreamWriter.prototype.writeTapnpassProtocolConfigurationSerial = function (model) { this.writeBits(model.baudRate, 20); this.writeBoolean(model.identification, 1); this.forwardBits(1); this.writeBoolean(model.ledStatus, 1); this.forwardBits(1); this.writeBitsInt(enumKeyOrValueToNumber(model.physicalPort, SerialSettings.PhysicalPort), 4); this.writeBitsInt(enumKeyOrValueToNumber(model.stopBits, SerialSettings.StopBits), 2); this.writeBitsInt(enumKeyOrValueToNumber(model.bitParity, SerialSettings.BitParity), 4); this.writeBitsInt(enumKeyOrValueToNumber(model.dataBits, SerialSettings.DataBits), 2); this.writeBitsInt(enumKeyOrValueToNumber(model.handshakeDelimiter, SerialSettings.HandshakeDelimiter), 4); this.writeBitsInt(enumKeyOrValueToNumber(model.hardwareFlowControl, SerialSettings.HardwareFlowControl), 4); this.writeUnsigned(model.timeout, 1); return this; }; TapStreamWriter.prototype.writeTapnpassProtocolConfigurationUsb = function (model) { for (let item of model.aliases) { this.writeTapnpassProtocolConfigurationUsbAlias(item); } return this; }; TapStreamWriter.prototype.writeTapnpassProtocolConfigurationUsbAlias = function (model) { this.writeUnsigned(model.pid, 2); this.writeUnsigned(model.vid, 2); this.writeUnsigned(model.equ, 1); return this; }; // TapStreamWriter.prototype.write(model: AdpStats) : TapStreamWriter{ // return this.writeAdpStats(model) // } TapStreamWriter.prototype.writeAdpStats = function (model) { this.writeAdpStatsHeader(model.header); this.writeAdpStatsState(model.state); this.writeAdpStatsUart(model.uart); this.writeAdpStatsUsb(model.usb); this.writeBytes(model.current, 4); this.writeAdpStatsCom(model.com); this.writeBytes(model.battery, 4); this.writeAdpStatsIntern(model.intern); return this; }; TapStreamWriter.prototype.writeAdpStatsHeader = function (model) { this.forwardBits(16); this.writeAdpStatsVersion(model.version); this.writeUnsigned(model.errorCode, 1); this.forwardBits(16); return this; }; TapStreamWriter.prototype.writeAdpStatsVersion = function (model) { this.writeUnsigned(model.major, 1); this.writeUnsigned(model.minor, 1); this.writeUnsigned(model.patch, 1); return this; }; TapStreamWriter.prototype.writeAdpStatsIntern = function (model) { this.writeBytes(model.time, 4); this.writeBytes(model.nbBoots, 4); this.writeBytes(model.nbShutdown, 2); this.writeBytes(model.nbAdpFault, 2); this.writeBytes(model.nbAdpMemFault, 2); this.writeBytes(model.nbAdpBusFault, 2); this.writeBytes(model.nbAdpUsageFault, 2); this.forwardBits(16); this.writeBytes(model.temperature, 4); return this; }; TapStreamWriter.prototype.writeAdpStatsState = function (model) { this.forwardBits(7); this.writeBoolean(model.usbDisconnected, 1); this.forwardBits(24); return this; }; TapStreamWriter.prototype.writeAdpStatsUart = function (model) { this.writeUnsigned(model.nbPartityError, 1); this.writeUnsigned(model.nbNoiseError, 1); this.writeUnsigned(model.nbFrameError, 1); this.writeUnsigned(model.nbDmaError, 1); this.writeUnsigned(model.nbTxError, 1); this.writeUnsigned(model.nbRxError, 1); this.writeUnsigned(model.nbOverRun, 1); this.forwardBits(8); return this; }; TapStreamWriter.prototype.writeAdpStatsUsb = function (model) { this.writeUnsigned(model.nbFail, 1); this.writeUnsigned(model.nbTimeout, 1); this.writeUnsigned(model.nbError, 1); this.writeUnsigned(model.nbUnknownClass, 1); this.writeUnsigned(model.nbDisconnect, 1); this.writeUnsigned(model.nbOff, 1); this.forwardBits(16); return this; }; TapStreamWriter.prototype.writeAdpStatsCom = function (model) { this.writeUnsigned(model.txBufferOverRun, 1); this.writeUnsigned(model.rxBufferOverRun, 1); this.writeUnsigned(model.nbErrorSettings, 1); this.forwardBits(8); this.writeBytes(model.nbComAdp, 4); return this; }; // TapStreamWriter.prototype.write(model: AdpControlIn) : TapStreamWriter{ // return this.writeAdpControlIn(model) // } TapStreamWriter.prototype.writeAdpControlIn = function (model) { this.writeBitsInt(enumKeyOrValueToNumber(model.command, AdpControlIn.Command), 16); this.writeUnsigned(model.param, 2); return this; }; // TapStreamWriter.prototype.write(model: AdpControlOut) : TapStreamWriter{ // return this.writeAdpControlOut(model) // } TapStreamWriter.prototype.writeAdpControlOut = function (model) { this.writeBitsInt(enumKeyOrValueToNumber(model.resultCode, AdpControlOut.ResultCode), 16); this.writeUnsigned(model.param, 2); return this; }; /** * Generated file. Do not edit */ class TapnpassProtocolConfigurationConverter { encode(model, stream = new TapStreamWriter()) { stream.writeTapnpassProtocolConfiguration(model); return stream.toBytes; } decode(data) { const stream = data instanceof TapStreamReader ? data : TapStreamReader.create(data); return stream.readTapnpassProtocolConfiguration(); } } class AdpStatsConverter { encode(model, stream = new TapStreamWriter()) { stream.writeAdpStats(model); return stream.toBytes; } decode(data) { const stream = data instanceof TapStreamReader ? data : TapStreamReader.create(data); return stream.readAdpStats(); } } class AdpControlInConverter { encode(model, stream = new TapStreamWriter()) { stream.writeAdpControlIn(model); return stream.toBytes; } decode(data) { const stream = data instanceof TapStreamReader ? data : TapStreamReader.create(data); return stream.readAdpControlIn(); } } class AdpControlOutConverter { encode(model, stream = new TapStreamWriter()) { stream.writeAdpControlOut(model); return stream.toBytes; } decode(data) { const stream = data instanceof TapStreamReader ? data : TapStreamReader.create(data); return stream.readAdpControlOut(); } } /** * Generated file. Do not edit */ const tapnpassProtocolConfiguration = new TapnpassProtocolConfigurationConverter(); const adpStats = new AdpStatsConverter(); const adpControlIn = new AdpControlInConverter(); const adpControlOut = new AdpControlOutConverter(); var serviceConverters = /*#__PURE__*/Object.freeze({ __proto__: null, tapnpassProtocolConfiguration: tapnpassProtocolConfiguration, adpStats: adpStats, adpControlIn: adpControlIn, adpControlOut: adpControlOut }); const PROTOCOL_CONF_CTR_LENGHT = 8; const END_OF_USB_ALIASES = Uint8Array.from([0, 0, 0, 0, 0]); class ReversedTapnpassProtocolConfigurationConverter { constructor() { this.converter = new TapnpassProtocolConfigurationConverter(); } decode(data) { return this.converter.decode(this._reorderBytes(data.slice(0, data.length - END_OF_USB_ALIASES.length))); } encode(settings) { return KaitaiStreamWriter.mergeArrays(this._reorderBytes(this.converter.encode(settings)), END_OF_USB_ALIASES); } _reorderBytes(data) { return KaitaiStreamWriter.mergeArrays(data.slice(0, PROTOCOL_CONF_CTR_LENGHT).reverse(), data.slice(PROTOCOL_CONF_CTR_LENGHT)); } } const reversedTapnpassProtocolConfiguration = new ReversedTapnpassProtocolConfigurationConverter(); var customConverters = /*#__PURE__*/Object.freeze({ __proto__: null, reversedTapnpassProtocolConfiguration: reversedTapnpassProtocolConfiguration }); /** * Generated file. Do not edit */ const allConverters = Object.assign(Object.assign(Object.assign({}, converters), serviceConverters), customConverters); const SERVICE_CALLS = { getProtocolConfiguration: { method: TapRequestFrame.MethodType.GET, pathAlias: '/tapnpass/protocol-configuration', path: '/1027//21', responseBodyDecoder: allConverters.reversedTapnpassProtocolConfiguration, }, setProtocolConfiguration: { method: TapRequestFrame.MethodType.POST, pathAlias: '/tapnpass/protocol-configuration', path: '/1027//21', bodyEncoder: allConverters.reversedTapnpassProtocolConfiguration, }, putProtocolConfiguration: { method: TapRequestFrame.MethodType.PUT, pathAlias: '/tapnpass/protocol-configuration', path: '/1027//21', bodyEncoder: allConverters.reversedTapnpassProtocolConfiguration, }, getStatus: { method: TapRequestFrame.MethodType.GET, pathAlias: '/tapnpass/status', path: '/1027//36', responseBodyDecoder: allConverters.adpStats, }, postAction: { method: TapRequestFrame.MethodType.POST, pathAlias: '/tapnpass/action', path: '/1027//39', }, getControlIn: { method: TapRequestFrame.MethodType.GET, pathAlias: '/tapnpass/control-in', path: '/1027//41', responseBodyDecoder: allConverters.adpControlIn, }, setControlIn: { method: TapRequestFrame.MethodType.POST, pathAlias: '/tapnpass/control-in', path: '/1027//41', bodyEncoder: allConverters.adpControlIn, }, getControlOut: { method: TapRequestFrame.MethodType.GET, pathAlias: '/tapnpass/control-out', path: '/1027//42', responseBodyDecoder: allConverters.adpControlOut, }, setAdpControlOut: { method: TapRequestFrame.MethodType.POST, pathAlias: '/tapnpass/control-out', path: '/1027//42', responseBodyDecoder: allConverters.adpControlOut, bodyEncoder: allConverters.adpControlOut, }, }; class TapnpassService extends AbstractService { constructor() { super(...arguments); this.resources = SERVICE_CALLS; } /** * Get TAPNPass protocol configuration * * LWM2M path: /1027//21 * * @tapVersion(">=1.0") * @return */ getProtocolConfiguration() { return this.serviceCallRunner.execute(this.getProtocolConfigurationCall()); } /** * * * LWM2M path: /1027//21 * * @tapVersion(">=1.0") * @return call options */ getProtocolConfigurationCall() { const callOptions = Object.assign({}, this.resources.getProtocolConfiguration); return callOptions; } /** * Temporary update configuration * * LWM2M path: /1027//21 * * @tapVersion(">=1.0") * @param value input * @return */ setProtocolConfiguration( /* * */ value) { return this.serviceCallRunner.execute(this.setProtocolConfigurationCall(value)); } /** * * * LWM2M path: /1027//21 * * @tapVersion(">=1.0") * @param value input * @return call options */ setProtocolConfigurationCall( /* * */ value) { const callOptions = Object.assign({}, this.resources.setProtocolConfiguration); callOptions.body = value; return callOptions; } /** * Update protocol configuration * * LWM2M path: /1027//21 * * @tapVersion(">=1.0") * @param value input * @return */ putProtocolConfiguration( /* * */ value) { return this.serviceCallRunner.execute(this.putProtocolConfigurationCall(value)); } /** * * * LWM2M path: /1027//21 * * @tapVersion(">=1.0") * @param value input * @return call options */ putProtocolConfigurationCall( /* * */ value) { const callOptions = Object.assign({}, this.resources.putProtocolConfiguration); callOptions.body = value; return callOptions; } /** * Read target status. Requires access rights to TAPNPass Control Bundle. * * LWM2M path: /1027//36 * * @tapVersion(">=1.0") * @return */ getStatus() { return this.serviceCallRunner.execute(this.getStatusCall()); } /** * * * LWM2M path: /1027//36 * * @tapVersion(">=1.0") * @return call options */ getStatusCall() { const callOptions = Object.assign({}, this.resources.getStatus); return callOptions; } /** * Perform actions to ADP target. Requires access rights to TAPNPass Control Bundle. * * LWM2M path: /1027//39 * * @deprecated * @tapVersion(">=1.0") * @param data input * @return */ postAction( /* * */ data) { return this.serviceCallRunner.execute(this.postActionCall(data)); } /** * * * LWM2M path: /1027//39 * * @deprecated * @tapVersion(">=1.0") * @param data input * @return call options */ postActionCall( /* * */ data) { const callOptions = Object.assign({}, this.resources.postAction); callOptions.body = data; return callOptions; } /** * Read TAPNPass ADPCtrl1 Reg * * LWM2M path: /1027//41 * * @tapVersion(">=1.51") * @return */ getControlIn() { return this.serviceCallRunner.execute(this.getControlInCall()); } /** * * * LWM2M path: /1027//41 * * @tapVersion(">=1.51") * @return call options */ getControlInCall() { const callOptions = Object.assign({}, this.resources.getControlIn); return callOptions; } /** * Write TAPNPass ADPCtrl1 Reg * * LWM2M path: /1027//41 * * @tapVersion(">=1.51") * @param data input * @return */ setControlIn( /* * */ data) { return this.serviceCallRunner.execute(this.setControlInCall(data)); } /** * * * LWM2M path: /1027//41 * * @tapVersion(">=1.51") * @param data input * @return call options */ setControlInCall( /* * */ data) { const callOptions = Object.assign({}, this.resources.setControlIn); callOptions.body = data; return callOptions; } /** * Read TAPNPass ADPCtrl2 Reg * * LWM2M path: /1027//42 * * @tapVersion(">=1.51") * @return */ getControlOut() { return this.serviceCallRunner.execute(this.getControlOutCall()); } /** * * * LWM2M path: /1027//42 * * @tapVersion(">=1.51") * @return call options */ getControlOutCall() { const callOptions = Object.assign({}, this.resources.getControlOut); return callOptions; } /** * Write TAPNPass ADPCtrl2 Reg * * LWM2M path: /1027//42 * * @tapVersion(">=1.51") * @param data input * @return */ setAdpControlOut( /* * */ data) { return this.serviceCallRunner.execute(this.setAdpControlOutCall(data)); } /** * * * LWM2M path: /1027//42 * * @tapVersion(">=1.51") * @param data input * @return call options */ setAdpControlOutCall( /* * */ data) { const callOptions = Object.assign({}, this.resources.setAdpControlOut); callOptions.body = data; return callOptions; } } const _TAP_SERVICE_EXTENSION_TAPNPASS_ = extendServiceContainer('tapnpass', TapnpassService); /** * Generated file. Do not edit */ const ResourceMetaData = { '/tapnpass/protocol-configuration': { put: { minApiVersion: 1.0, configModeRequired: true, schema: { $ref: './definitions.yaml#/TapnpassProtocolConfiguration', }, }, }, }; /** * Generated bundle index. Do not edit. */ export { AdpControlIn, AdpControlInConverter, AdpControlOut, AdpControlOutConverter, AdpStatsConverter, ReversedTapnpassProtocolConfigurationConverter, SERVICE_CALLS as TAPNPASS_SERVICE_CALLS, TapnpassProtocolConfigurationConverter, ResourceMetaData as TapnpassResourceMetaData, TapnpassService, _TAP_SERVICE_EXTENSION_TAPNPASS_, reversedTapnpassProtocolConfiguration, serviceConverters as tapnpassConverters }; //# sourceMappingURL=iotize-tap-service-impl-tapnpass.js.map