@iotize/tap
Version:
IoTize Device client for Javascript
835 lines (822 loc) • 21.2 kB
JavaScript
import { CpuFrequencySpeed, AbstractService, extendServiceContainer } from '@iotize/tap';
import { TapRequestFrame } from '@iotize/tap/client/api';
import { createEnumConverter, createEnumArrayConverter, converters } from '@iotize/tap/service/core';
import { TapStreamReader, TapStreamWriter, enumKeyOrValueToNumber } from '@iotize/tap/client/impl';
/* 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.
*/
var AvailablePowerSource;
(function (AvailablePowerSource) {
AvailablePowerSource[AvailablePowerSource["DC_POWER"] = 1] = "DC_POWER";
AvailablePowerSource[AvailablePowerSource["S3P"] = 16] = "S3P";
AvailablePowerSource[AvailablePowerSource["AC_EXTERNAL_POWER"] = 32] = "AC_EXTERNAL_POWER";
})(AvailablePowerSource || (AvailablePowerSource = {}));
/**
* Generated file. Do not edit
*/
TapStreamReader.prototype.readDeviceCpuFrequencyOptions =
function () {
const model = {};
this.forwardBits(6);
model.speed = this.readBits(2);
return model;
};
// TapStreamWriter.prototype.write(model: DeviceCpuFrequencyOptions) : TapStreamWriter{
// return this.writeDeviceCpuFrequencyOptions(model)
// }
TapStreamWriter.prototype.writeDeviceCpuFrequencyOptions = function (model) {
this.forwardBits(6);
this.writeBitsInt(enumKeyOrValueToNumber(model.speed, CpuFrequencySpeed), 2);
return this;
};
/**
* Generated file. Do not edit
*/
class DeviceCpuFrequencyOptionsConverter {
encode(model, stream = new TapStreamWriter()) {
stream.writeDeviceCpuFrequencyOptions(model);
return stream.toBytes;
}
decode(data) {
const stream = data instanceof TapStreamReader ? data : TapStreamReader.create(data);
return stream.readDeviceCpuFrequencyOptions();
}
}
/**
* Generated file. Do not edit
*/
const availablePowerSource = createEnumConverter(AvailablePowerSource, 1);
const availablePowerSourceArray = createEnumArrayConverter(AvailablePowerSource, 1);
const deviceCpuFrequencyOptions = new DeviceCpuFrequencyOptionsConverter();
var serviceConverters = /*#__PURE__*/Object.freeze({
__proto__: null,
availablePowerSource: availablePowerSource,
availablePowerSourceArray: availablePowerSourceArray,
deviceCpuFrequencyOptions: deviceCpuFrequencyOptions
});
/**
* Generated file. Do not edit
*/
const allConverters = Object.assign(Object.assign({}, converters), serviceConverters);
const SERVICE_CALLS = {
getManufacturer: {
method: TapRequestFrame.MethodType.GET,
pathAlias: '/device/manufacturer',
path: '/3//0',
responseBodyDecoder: allConverters.ascii,
},
getFirmwareFlavor: {
method: TapRequestFrame.MethodType.GET,
pathAlias: '/device/firmware-flavor',
path: '/3//1',
responseBodyDecoder: allConverters.ascii,
},
getSerialNumber: {
method: TapRequestFrame.MethodType.GET,
pathAlias: '/device/serial-number',
path: '/3//2',
responseBodyDecoder: allConverters.ascii,
},
getFirmwareVersion: {
method: TapRequestFrame.MethodType.GET,
pathAlias: '/device/firmware-version',
path: '/3//3',
responseBodyDecoder: allConverters.ascii,
},
reboot: {
method: TapRequestFrame.MethodType.POST,
pathAlias: '/device/reboot',
path: '/3//4',
},
factoryReset: {
method: TapRequestFrame.MethodType.POST,
pathAlias: '/device/factory-reset',
path: '/3//5',
},
getAvailablePowerSource: {
method: TapRequestFrame.MethodType.GET,
pathAlias: '/device/available-power-source',
path: '/3//6',
responseBodyDecoder: allConverters.availablePowerSource,
},
getPowerSourceVoltage: {
method: TapRequestFrame.MethodType.GET,
pathAlias: '/device/power-source-voltage',
path: '/3//7',
responseBodyDecoder: allConverters.uint32,
},
getMemoryFree: {
method: TapRequestFrame.MethodType.GET,
pathAlias: '/device/memory-free',
path: '/3//10',
responseBodyDecoder: allConverters.uint32,
},
getLastErrorCode: {
method: TapRequestFrame.MethodType.GET,
pathAlias: '/device/last-error-code',
path: '/3//11',
responseBodyDecoder: allConverters.uint32,
},
postLastErrorCode: {
method: TapRequestFrame.MethodType.POST,
pathAlias: '/device/last-error-code',
path: '/3//11',
bodyEncoder: allConverters.uint32,
},
resetLastErrorCode: {
method: TapRequestFrame.MethodType.POST,
pathAlias: '/device/reset-last-error-code',
path: '/3//12',
},
getCurrentTime: {
method: TapRequestFrame.MethodType.GET,
pathAlias: '/device/current-time',
path: '/3//13',
responseBodyDecoder: allConverters.uint32,
},
setCurrentTime: {
method: TapRequestFrame.MethodType.POST,
pathAlias: '/device/current-time',
path: '/3//13',
bodyEncoder: allConverters.uint32,
},
putCurrentTime: {
method: TapRequestFrame.MethodType.PUT,
pathAlias: '/device/current-time',
path: '/3//13',
bodyEncoder: allConverters.uint32,
},
getJvmErrorCode: {
method: TapRequestFrame.MethodType.GET,
pathAlias: '/device/jvm-error-code',
path: '/3//14',
responseBodyDecoder: allConverters.uint32,
},
setJvmErrorCode: {
method: TapRequestFrame.MethodType.POST,
pathAlias: '/device/jvm-error-code',
path: '/3//14',
bodyEncoder: allConverters.uint32,
},
getInternalStatus: {
method: TapRequestFrame.MethodType.GET,
pathAlias: '/device/internal-status',
path: '/3//15',
responseBodyDecoder: allConverters.ascii,
},
getCommunicationUid: {
method: TapRequestFrame.MethodType.GET,
pathAlias: '/device/communication-uid',
path: '/3//16',
},
getTemperature: {
method: TapRequestFrame.MethodType.GET,
pathAlias: '/device/temperature',
path: '/3//17',
responseBodyDecoder: allConverters.int32,
},
getCpuFrequency: {
method: TapRequestFrame.MethodType.GET,
pathAlias: '/device/cpu-frequency',
path: '/3//141',
responseBodyDecoder: allConverters.deviceCpuFrequencyOptions,
},
setCpuFrequency: {
method: TapRequestFrame.MethodType.POST,
pathAlias: '/device/cpu-frequency',
path: '/3//141',
bodyEncoder: allConverters.deviceCpuFrequencyOptions,
},
activateStopMode: {
method: TapRequestFrame.MethodType.POST,
pathAlias: '/device/activate-stop-mode',
path: '/3//142',
bodyEncoder: allConverters.uint8,
},
};
class DeviceService extends AbstractService {
constructor() {
super(...arguments);
this.resources = SERVICE_CALLS;
}
/**
* Get manufacturer name
*
* LWM2M path: /3//0
*
* @tapVersion(">=1.0")
* @return
*/
getManufacturer() {
return this.serviceCallRunner.execute(this.getManufacturerCall());
}
/**
*
*
* LWM2M path: /3//0
*
* @tapVersion(">=1.0")
* @return call options
*/
getManufacturerCall() {
const callOptions = Object.assign({}, this.resources.getManufacturer);
return callOptions;
}
/**
* Get device firmware flavor name
*
* LWM2M path: /3//1
*
* @tapVersion(">=1.0")
* @return
*/
getFirmwareFlavor() {
return this.serviceCallRunner.execute(this.getFirmwareFlavorCall());
}
/**
*
*
* LWM2M path: /3//1
*
* @tapVersion(">=1.0")
* @return call options
*/
getFirmwareFlavorCall() {
const callOptions = Object.assign({}, this.resources.getFirmwareFlavor);
return callOptions;
}
/**
* Get device serial number
*
* LWM2M path: /3//2
*
* @tapVersion(">=1.0")
* @return
*/
getSerialNumber() {
return this.serviceCallRunner.execute(this.getSerialNumberCall());
}
/**
*
*
* LWM2M path: /3//2
*
* @tapVersion(">=1.0")
* @return call options
*/
getSerialNumberCall() {
const callOptions = Object.assign({}, this.resources.getSerialNumber);
return callOptions;
}
/**
* Get device firmware version
*
* LWM2M path: /3//3
*
* @tapVersion(">=1.0")
* @return
*/
getFirmwareVersion() {
return this.serviceCallRunner.execute(this.getFirmwareVersionCall());
}
/**
*
*
* LWM2M path: /3//3
*
* @tapVersion(">=1.0")
* @return call options
*/
getFirmwareVersionCall() {
const callOptions = Object.assign({}, this.resources.getFirmwareVersion);
return callOptions;
}
/**
* Reboot Tap device
*
* LWM2M path: /3//4
*
* @tapVersion(">=1.0")
* @return
*/
reboot() {
return this.serviceCallRunner.execute(this.rebootCall());
}
/**
*
*
* LWM2M path: /3//4
*
* @tapVersion(">=1.0")
* @return call options
*/
rebootCall() {
const callOptions = Object.assign({}, this.resources.reboot);
return callOptions;
}
/**
* Factory reset
*
* LWM2M path: /3//5
*
* @tapVersion(">=1.0")
* @return
*/
factoryReset() {
return this.serviceCallRunner.execute(this.factoryResetCall());
}
/**
*
*
* LWM2M path: /3//5
*
* @tapVersion(">=1.0")
* @return call options
*/
factoryResetCall() {
const callOptions = Object.assign({}, this.resources.factoryReset);
return callOptions;
}
/**
* Get available power sources
*
* LWM2M path: /3//6
*
* @tapVersion(">=1.0")
* @return
*/
getAvailablePowerSource() {
return this.serviceCallRunner.execute(this.getAvailablePowerSourceCall());
}
/**
*
*
* LWM2M path: /3//6
*
* @tapVersion(">=1.0")
* @return call options
*/
getAvailablePowerSourceCall() {
const callOptions = Object.assign({}, this.resources.getAvailablePowerSource);
return callOptions;
}
/**
* Get power source voltage
*
* LWM2M path: /3//7
*
* @tapVersion(">=1.0")
* @return
*/
getPowerSourceVoltage() {
return this.serviceCallRunner.execute(this.getPowerSourceVoltageCall());
}
/**
*
*
* LWM2M path: /3//7
*
* @tapVersion(">=1.0")
* @return call options
*/
getPowerSourceVoltageCall() {
const callOptions = Object.assign({}, this.resources.getPowerSourceVoltage);
return callOptions;
}
/**
* Get device memory free
*
* LWM2M path: /3//10
*
* @tapVersion(">=1.0")
* @return
*/
getMemoryFree() {
return this.serviceCallRunner.execute(this.getMemoryFreeCall());
}
/**
*
*
* LWM2M path: /3//10
*
* @tapVersion(">=1.0")
* @return call options
*/
getMemoryFreeCall() {
const callOptions = Object.assign({}, this.resources.getMemoryFree);
return callOptions;
}
/**
* Get device last error code
*
* LWM2M path: /3//11
*
* @tapVersion(">=1.0")
* @return
*/
getLastErrorCode() {
return this.serviceCallRunner.execute(this.getLastErrorCodeCall());
}
/**
*
*
* LWM2M path: /3//11
*
* @tapVersion(">=1.0")
* @return call options
*/
getLastErrorCodeCall() {
const callOptions = Object.assign({}, this.resources.getLastErrorCode);
return callOptions;
}
/**
* Set device last error code
*
* LWM2M path: /3//11
*
* @tapVersion(">=1.0")
* @param errorcode input
* @return
*/
postLastErrorCode(
/*
*
*/
errorcode) {
return this.serviceCallRunner.execute(this.postLastErrorCodeCall(errorcode));
}
/**
*
*
* LWM2M path: /3//11
*
* @tapVersion(">=1.0")
* @param errorcode input
* @return call options
*/
postLastErrorCodeCall(
/*
*
*/
errorcode) {
const callOptions = Object.assign({}, this.resources.postLastErrorCode);
callOptions.body = errorcode;
return callOptions;
}
/**
* Reset device last error code
*
* LWM2M path: /3//12
*
* @tapVersion(">=1.0")
* @return
*/
resetLastErrorCode() {
return this.serviceCallRunner.execute(this.resetLastErrorCodeCall());
}
/**
*
*
* LWM2M path: /3//12
*
* @tapVersion(">=1.0")
* @return call options
*/
resetLastErrorCodeCall() {
const callOptions = Object.assign({}, this.resources.resetLastErrorCode);
return callOptions;
}
/**
* Get device current time
*
* LWM2M path: /3//13
*
* @tapVersion(">=1.0")
* @return
*/
getCurrentTime() {
return this.serviceCallRunner.execute(this.getCurrentTimeCall());
}
/**
*
*
* LWM2M path: /3//13
*
* @tapVersion(">=1.0")
* @return call options
*/
getCurrentTimeCall() {
const callOptions = Object.assign({}, this.resources.getCurrentTime);
return callOptions;
}
/**
* Set device current time
*
* LWM2M path: /3//13
*
* @tapVersion(">=1.0")
* @param time input
* @return
*/
setCurrentTime(
/*
*
*/
time) {
return this.serviceCallRunner.execute(this.setCurrentTimeCall(time));
}
/**
*
*
* LWM2M path: /3//13
*
* @tapVersion(">=1.0")
* @param time input
* @return call options
*/
setCurrentTimeCall(
/*
*
*/
time) {
const callOptions = Object.assign({}, this.resources.setCurrentTime);
callOptions.body = time;
return callOptions;
}
/**
* Put device current time (Will be removed in next major release version)
*
* LWM2M path: /3//13
*
* @tapVersion(">=1.0")
* @param time input
* @return
*/
putCurrentTime(
/*
*
*/
time) {
return this.serviceCallRunner.execute(this.putCurrentTimeCall(time));
}
/**
*
*
* LWM2M path: /3//13
*
* @tapVersion(">=1.0")
* @param time input
* @return call options
*/
putCurrentTimeCall(
/*
*
*/
time) {
const callOptions = Object.assign({}, this.resources.putCurrentTime);
callOptions.body = time;
return callOptions;
}
/**
* Get jvm error code
*
* LWM2M path: /3//14
*
* @tapVersion(">=1.0")
* @return
*/
getJvmErrorCode() {
return this.serviceCallRunner.execute(this.getJvmErrorCodeCall());
}
/**
*
*
* LWM2M path: /3//14
*
* @tapVersion(">=1.0")
* @return call options
*/
getJvmErrorCodeCall() {
const callOptions = Object.assign({}, this.resources.getJvmErrorCode);
return callOptions;
}
/**
* Set jvm error code
*
* LWM2M path: /3//14
*
* @tapVersion(">=1.0")
* @param code input
* @return
*/
setJvmErrorCode(
/*
*
*/
code) {
return this.serviceCallRunner.execute(this.setJvmErrorCodeCall(code));
}
/**
*
*
* LWM2M path: /3//14
*
* @tapVersion(">=1.0")
* @param code input
* @return call options
*/
setJvmErrorCodeCall(
/*
*
*/
code) {
const callOptions = Object.assign({}, this.resources.setJvmErrorCode);
callOptions.body = code;
return callOptions;
}
/**
* Get device internal status
*
* LWM2M path: /3//15
*
* @tapVersion(">=2.11")
* @return
*/
getInternalStatus() {
return this.serviceCallRunner.execute(this.getInternalStatusCall());
}
/**
*
*
* LWM2M path: /3//15
*
* @tapVersion(">=2.11")
* @return call options
*/
getInternalStatusCall() {
const callOptions = Object.assign({}, this.resources.getInternalStatus);
return callOptions;
}
/**
* Get device com UID
*
* LWM2M path: /3//16
*
* @tapVersion(">=2.29")
* @return
*/
getCommunicationUid() {
return this.serviceCallRunner.execute(this.getCommunicationUidCall());
}
/**
*
*
* LWM2M path: /3//16
*
* @tapVersion(">=2.29")
* @return call options
*/
getCommunicationUidCall() {
const callOptions = Object.assign({}, this.resources.getCommunicationUid);
return callOptions;
}
/**
* Get device temperature
*
* LWM2M path: /3//17
*
* @tapVersion(">=2.37")
* @return
*/
getTemperature() {
return this.serviceCallRunner.execute(this.getTemperatureCall());
}
/**
*
*
* LWM2M path: /3//17
*
* @tapVersion(">=2.37")
* @return call options
*/
getTemperatureCall() {
const callOptions = Object.assign({}, this.resources.getTemperature);
return callOptions;
}
/**
* Get current CPU frequency
*
* LWM2M path: /3//141
*
* @tapVersion(">=2.37")
* @return
*/
getCpuFrequency() {
return this.serviceCallRunner.execute(this.getCpuFrequencyCall());
}
/**
*
*
* LWM2M path: /3//141
*
* @tapVersion(">=2.37")
* @return call options
*/
getCpuFrequencyCall() {
const callOptions = Object.assign({}, this.resources.getCpuFrequency);
return callOptions;
}
/**
* Set current CPU frequency
*
* LWM2M path: /3//141
*
* @tapVersion(">=2.37")
* @param mode input
* @return
*/
setCpuFrequency(
/*
*
*/
mode) {
return this.serviceCallRunner.execute(this.setCpuFrequencyCall(mode));
}
/**
*
*
* LWM2M path: /3//141
*
* @tapVersion(">=2.37")
* @param mode input
* @return call options
*/
setCpuFrequencyCall(
/*
*
*/
mode) {
const callOptions = Object.assign({}, this.resources.setCpuFrequency);
callOptions.body = mode;
return callOptions;
}
/**
* Activate stop mode
*
* LWM2M path: /3//142
*
* @tapVersion(">=2.37")
* @param duration input
* @return
*/
activateStopMode(
/*
*
*/
duration) {
return this.serviceCallRunner.execute(this.activateStopModeCall(duration));
}
/**
*
*
* LWM2M path: /3//142
*
* @tapVersion(">=2.37")
* @param duration input
* @return call options
*/
activateStopModeCall(
/*
*
*/
duration) {
const callOptions = Object.assign({}, this.resources.activateStopMode);
callOptions.body = duration;
return callOptions;
}
}
const _TAP_SERVICE_EXTENSION_DEVICE_ = extendServiceContainer('device', DeviceService);
/**
* Generated file. Do not edit
*/
const ResourceMetaData = {
'/device/current-time': {
put: {
minApiVersion: 1.0,
configModeRequired: true,
schema: {
type: 'integer',
format: 'uint32',
},
},
},
};
// import './lib/custom/extension';
/**
* Generated bundle index. Do not edit.
*/
export { AvailablePowerSource, SERVICE_CALLS as DEVICE_SERVICE_CALLS, DeviceCpuFrequencyOptionsConverter, ResourceMetaData as DeviceResourceMetaData, DeviceService, _TAP_SERVICE_EXTENSION_DEVICE_, serviceConverters as deviceConverters };
//# sourceMappingURL=iotize-tap-service-impl-device.js.map