UNPKG

@iotize/tap

Version:

IoTize Device client for Javascript

16 lines (14 loc) 16.2 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@iotize/tap/client/impl"),require("@iotize/tap/client/api"),require("@iotize/tap/service/core"),require("@iotize/tap/service/impl/bundle"),require("@iotize/tap")):"function"==typeof define&&define.amd?define("@iotize/tap/service/impl/variable",["exports","@iotize/tap/client/impl","@iotize/tap/client/api","@iotize/tap/service/core","@iotize/tap/service/impl/bundle","@iotize/tap"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).iotize=e.iotize||{},e.iotize.tap=e.iotize.tap||{},e.iotize.tap.service=e.iotize.tap.service||{},e.iotize.tap.service.impl=e.iotize.tap.service.impl||{},e.iotize.tap.service.impl.variable={}),e.iotize.tap.client.impl,e.iotize.tap.client.api,e.iotize.tap.service.core,e.iotize.tap.service.impl.bundle,e.iotize.tap)}(this,(function(e,t,a,r,i,n){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */var o=function(e,t){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a])},o(e,t)};Object.create;function s(e,t){var a="function"==typeof Symbol&&e[Symbol.iterator];if(!a)return e;var r,i,n=a.call(e),o=[];try{for(;(void 0===t||t-- >0)&&!(r=n.next()).done;)o.push(r.value)}catch(e){i={error:e}}finally{try{r&&!r.done&&(a=n.return)&&a.call(n)}finally{if(i)throw i.error}}return o}function l(e,t,a){if(a||2===arguments.length)for(var r,i=0,n=t.length;i<n;i++)!r&&i in t||(r||(r=Array.prototype.slice.call(t,0,i)),r[i]=t[i]);return e.concat(r||Array.prototype.slice.call(t))}var u,p,d;Object.create;e.VariableType=void 0,d=e.VariableType||(e.VariableType={}),(p=d.Data||(d.Data={}))[p.BOOLEAN=0]="BOOLEAN",p[p.INT8=1]="INT8",p[p.INT16=2]="INT16",p[p.INT32=3]="INT32",p[p.ASCII=8]="ASCII",p[p.FLOAT32=19]="FLOAT32",p[p.UINT8=33]="UINT8",p[p.UINT16=34]="UINT16",p[p.UINT32=35]="UINT32",(u=d.Domain||(d.Domain={}))[u.TARGET=0]="TARGET",u[u.GPIO=1]="GPIO",u[u.IN_TAP_STATIC=2]="IN_TAP_STATIC",u[u.IN_TAP_VOLATIL=3]="IN_TAP_VOLATIL",t.TapStreamReader.prototype.readModbusVariableAddress=function(){var e={};return e.functionCode=this.readUnsigned(1),e.slave=this.readUnsigned(1),e.address=this.readUnsigned(2),e},t.TapStreamReader.prototype.readVariableType=function(){var e={};return e.domain=this.readBits(2),e.data=this.readBits(6),e},t.TapStreamReader.prototype.readVariableMeta=function(){var e={};return e.name=this.readStringTerminator(":"),e.unit=this.readString(),e},t.TapStreamWriter.prototype.writeModbusVariableAddress=function(e){return this.writeUnsigned(e.functionCode,1),this.writeUnsigned(e.slave,1),this.writeUnsigned(e.address,2),this},t.TapStreamWriter.prototype.writeVariableType=function(a){return this.writeBitsInt(t.enumKeyOrValueToNumber(a.domain,e.VariableType.Domain),2),this.writeBitsInt(t.enumKeyOrValueToNumber(a.data,e.VariableType.Data),6),this},t.TapStreamWriter.prototype.writeVariableMeta=function(e){return this.writeString(e.name+":"),this.writeString(e.unit),this};var c=function(){function e(){}return e.prototype.encode=function(e,a){return void 0===a&&(a=new t.TapStreamWriter),a.writeModbusVariableAddress(e),a.toBytes},e.prototype.decode=function(e){return(e instanceof t.TapStreamReader?e:t.TapStreamReader.create(e)).readModbusVariableAddress()},e}(),b=function(){function e(){}return e.prototype.encode=function(e,a){return void 0===a&&(a=new t.TapStreamWriter),a.writeVariableType(e),a.toBytes},e.prototype.decode=function(e){return(e instanceof t.TapStreamReader?e:t.TapStreamReader.create(e)).readVariableType()},e}(),h=function(){function e(){}return e.prototype.encode=function(e,a){return void 0===a&&(a=new t.TapStreamWriter),a.writeVariableMeta(e),a.toBytes},e.prototype.decode=function(e){return(e instanceof t.TapStreamReader?e:t.TapStreamReader.create(e)).readVariableMeta()},e}(),v=new c,y=new b,m=new h,f=Object.freeze({__proto__:null,modbusVariableAddress:v,variableType:y,variableMeta:m}),T=Object.assign(Object.assign(Object.assign({},r.converters),f),i.bundleConverters),I={getVariableAddress:{method:a.TapRequestFrame.MethodType.GET,pathAlias:"/variable/{variableId}/variable-address",path:"/1029/{variableId}/0",responseBodyDecoder:T.uint32},putVariableAddress:{method:a.TapRequestFrame.MethodType.PUT,pathAlias:"/variable/{variableId}/variable-address",path:"/1029/{variableId}/0",bodyEncoder:T.uint32},putModbusVariableAddress:{method:a.TapRequestFrame.MethodType.PUT,pathAlias:"/variable/{variableId}/modbus-variable-address",path:"/1029/{variableId}/0",bodyEncoder:T.modbusVariableAddress},getType:{method:a.TapRequestFrame.MethodType.GET,pathAlias:"/variable/{variableId}/type",path:"/1029/{variableId}/1",responseBodyDecoder:T.variableType},putType:{method:a.TapRequestFrame.MethodType.PUT,pathAlias:"/variable/{variableId}/type",path:"/1029/{variableId}/1",bodyEncoder:T.variableType},getRawMeta:{method:a.TapRequestFrame.MethodType.GET,pathAlias:"/variable/{variableId}/raw-meta",path:"/1029/{variableId}/8"},putRawMeta:{method:a.TapRequestFrame.MethodType.PUT,pathAlias:"/variable/{variableId}/raw-meta",path:"/1029/{variableId}/8"},getMeta:{method:a.TapRequestFrame.MethodType.GET,pathAlias:"/variable/{variableId}/meta",path:"/1029/{variableId}/8",responseBodyDecoder:T.variableMeta},putMeta:{method:a.TapRequestFrame.MethodType.PUT,pathAlias:"/variable/{variableId}/meta",path:"/1029/{variableId}/8",bodyEncoder:T.variableMeta},getUnit:{method:a.TapRequestFrame.MethodType.GET,pathAlias:"/variable/{variableId}/unit",path:"/1029/{variableId}/9",responseBodyDecoder:T.ascii},putUnit:{method:a.TapRequestFrame.MethodType.PUT,pathAlias:"/variable/{variableId}/unit",path:"/1029/{variableId}/9",bodyEncoder:T.ascii},getNumberOfElements:{method:a.TapRequestFrame.MethodType.GET,pathAlias:"/variable/{variableId}/number-of-elements",path:"/1029/{variableId}/2",responseBodyDecoder:T.uint8},putNumberOfElements:{method:a.TapRequestFrame.MethodType.PUT,pathAlias:"/variable/{variableId}/number-of-elements",path:"/1029/{variableId}/2",bodyEncoder:T.uint8},getCurrentAccess:{method:a.TapRequestFrame.MethodType.GET,pathAlias:"/variable/{variableId}/current-access",path:"/1029/{variableId}/3",responseBodyDecoder:T.readWriteRights},readProfile:{method:a.TapRequestFrame.MethodType.GET,pathAlias:"/variable/read-profile",path:"/1029//4"},getValue:{method:a.TapRequestFrame.MethodType.GET,pathAlias:"/variable/{variableId}/value",path:"/1029/{variableId}/4"},setValue:{method:a.TapRequestFrame.MethodType.POST,pathAlias:"/variable/{variableId}/value",path:"/1029/{variableId}/5"},putValue:{method:a.TapRequestFrame.MethodType.PUT,pathAlias:"/variable/{variableId}/value",path:"/1029/{variableId}/4"},getBundleId:{method:a.TapRequestFrame.MethodType.GET,pathAlias:"/variable/{variableId}/bundle/id",path:"/1029/{variableId}/6",responseBodyDecoder:T.uint16},putBundleId:{method:a.TapRequestFrame.MethodType.PUT,pathAlias:"/variable/{variableId}/bundle/id",path:"/1029/{variableId}/6",bodyEncoder:T.uint16},getBundleValues:{method:a.TapRequestFrame.MethodType.GET,pathAlias:"/variable/{variableId}/bundle/values",path:"/1029/{variableId}/7"},create:{method:a.TapRequestFrame.MethodType.POST,pathAlias:"/variable/{variableId}/create",path:"/1029/{variableId}/65535",bodyEncoder:T.uint8}},g=function(e){function t(){var t=e.apply(this,l([],s(arguments)))||this;return t.resources=I,t}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function a(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(a.prototype=t.prototype,new a)}(t,e),t.prototype.getVariableAddress=function(e){return this.serviceCallRunner.execute(this.getVariableAddressCall(e))},t.prototype.getVariableAddressCall=function(e){var t=Object.assign({},this.resources.getVariableAddress);return t.pathParameters={variableId:e},t},t.prototype.putVariableAddress=function(e,t){return this.serviceCallRunner.execute(this.putVariableAddressCall(e,t))},t.prototype.putVariableAddressCall=function(e,t){var a=Object.assign({},this.resources.putVariableAddress);return a.body=t,a.pathParameters={variableId:e},a},t.prototype.putModbusVariableAddress=function(e,t){return this.serviceCallRunner.execute(this.putModbusVariableAddressCall(e,t))},t.prototype.putModbusVariableAddressCall=function(e,t){var a=Object.assign({},this.resources.putModbusVariableAddress);return a.body=t,a.pathParameters={variableId:e},a},t.prototype.getType=function(e){return this.serviceCallRunner.execute(this.getTypeCall(e))},t.prototype.getTypeCall=function(e){var t=Object.assign({},this.resources.getType);return t.pathParameters={variableId:e},t},t.prototype.putType=function(e,t){return this.serviceCallRunner.execute(this.putTypeCall(e,t))},t.prototype.putTypeCall=function(e,t){var a=Object.assign({},this.resources.putType);return a.body=t,a.pathParameters={variableId:e},a},t.prototype.getRawMeta=function(e){return this.serviceCallRunner.execute(this.getRawMetaCall(e))},t.prototype.getRawMetaCall=function(e){var t=Object.assign({},this.resources.getRawMeta);return t.pathParameters={variableId:e},t},t.prototype.putRawMeta=function(e,t){return this.serviceCallRunner.execute(this.putRawMetaCall(e,t))},t.prototype.putRawMetaCall=function(e,t){var a=Object.assign({},this.resources.putRawMeta);return a.body=t,a.pathParameters={variableId:e},a},t.prototype.getMeta=function(e){return this.serviceCallRunner.execute(this.getMetaCall(e))},t.prototype.getMetaCall=function(e){var t=Object.assign({},this.resources.getMeta);return t.pathParameters={variableId:e},t},t.prototype.putMeta=function(e,t){return this.serviceCallRunner.execute(this.putMetaCall(e,t))},t.prototype.putMetaCall=function(e,t){var a=Object.assign({},this.resources.putMeta);return a.body=t,a.pathParameters={variableId:e},a},t.prototype.getUnit=function(e){return this.serviceCallRunner.execute(this.getUnitCall(e))},t.prototype.getUnitCall=function(e){var t=Object.assign({},this.resources.getUnit);return t.pathParameters={variableId:e},t},t.prototype.putUnit=function(e,t){return this.serviceCallRunner.execute(this.putUnitCall(e,t))},t.prototype.putUnitCall=function(e,t){var a=Object.assign({},this.resources.putUnit);return a.body=t,a.pathParameters={variableId:e},a},t.prototype.getNumberOfElements=function(e){return this.serviceCallRunner.execute(this.getNumberOfElementsCall(e))},t.prototype.getNumberOfElementsCall=function(e){var t=Object.assign({},this.resources.getNumberOfElements);return t.pathParameters={variableId:e},t},t.prototype.putNumberOfElements=function(e,t){return this.serviceCallRunner.execute(this.putNumberOfElementsCall(e,t))},t.prototype.putNumberOfElementsCall=function(e,t){var a=Object.assign({},this.resources.putNumberOfElements);return a.body=t,a.pathParameters={variableId:e},a},t.prototype.getCurrentAccess=function(e){return this.serviceCallRunner.execute(this.getCurrentAccessCall(e))},t.prototype.getCurrentAccessCall=function(e){var t=Object.assign({},this.resources.getCurrentAccess);return t.pathParameters={variableId:e},t},t.prototype.readProfile=function(){return this.serviceCallRunner.execute(this.readProfileCall())},t.prototype.readProfileCall=function(){return Object.assign({},this.resources.readProfile)},t.prototype.getValue=function(e){return this.serviceCallRunner.execute(this.getValueCall(e))},t.prototype.getValueCall=function(e){var t=Object.assign({},this.resources.getValue);return t.pathParameters={variableId:e},t},t.prototype.setValue=function(e,t){return this.serviceCallRunner.execute(this.setValueCall(e,t))},t.prototype.setValueCall=function(e,t){var a=Object.assign({},this.resources.setValue);return a.body=t,a.pathParameters={variableId:e},a},t.prototype.putValue=function(e,t){return this.serviceCallRunner.execute(this.putValueCall(e,t))},t.prototype.putValueCall=function(e,t){var a=Object.assign({},this.resources.putValue);return a.body=t,a.pathParameters={variableId:e},a},t.prototype.getBundleId=function(e){return this.serviceCallRunner.execute(this.getBundleIdCall(e))},t.prototype.getBundleIdCall=function(e){var t=Object.assign({},this.resources.getBundleId);return t.pathParameters={variableId:e},t},t.prototype.putBundleId=function(e,t){return this.serviceCallRunner.execute(this.putBundleIdCall(e,t))},t.prototype.putBundleIdCall=function(e,t){var a=Object.assign({},this.resources.putBundleId);return a.body=t,a.pathParameters={variableId:e},a},t.prototype.getBundleValues=function(e){return this.serviceCallRunner.execute(this.getBundleValuesCall(e))},t.prototype.getBundleValuesCall=function(e){var t=Object.assign({},this.resources.getBundleValues);return t.pathParameters={variableId:e},t},t.prototype.create=function(e,t){return this.serviceCallRunner.execute(this.createCall(e,t))},t.prototype.createCall=function(e,t){var a=Object.assign({},this.resources.create);return a.body=t,a.pathParameters={variableId:e},a},t}(n.AbstractService),C=new t.StringConverter("utf8");g.prototype.getMeta=function(e){return this.getRawMeta(e).then((function(e){var t=e;return t.setBodyDecoder({decode:function(e){var t=s(C.decode(e).split(":")),a=t[0],r=t.slice(1);return{name:a,unit:r.length>0?r[0]:""}}}),t}))},g.prototype.putMeta=function(e,t){var a=C.encode(t.name+":"+t.unit);return this.putRawMeta(e,a)},g.prototype.getAllValues=function(){return this.readProfile().then((function(e){var a=e;if(a.isSuccessful()){var r=a.rawBody(),i=(new t.TlvBundleConverter).decode(r);a.setBody(i)}return a}))};var A=function(){function e(){this.utf8Converter=new t.StringConverter("utf8")}return e.prototype.encode=function(e){return this.utf8Converter.encode((e.name||"")+":"+(e.unit||""))},e.prototype.decode=function(e){var t=this.utf8Converter.decode(e).split(":");return{name:t[0],unit:t.length>=2?t[1]:""}},e}(),R=n.extendServiceContainer("variable",g),V=new A;I.getMeta.responseBodyDecoder=V,I.putMeta.bodyEncoder=V,e.ModbusVariableAddressConverter=c,e.VARIABLE_SERVICE_CALLS=I,e.VariableMetaConfigConverter=A,e.VariableMetaConverter=h,e.VariableResourceMetaData={"/variable/{variableId}/variable-address":{put:{minApiVersion:1,configModeRequired:!0,schema:{type:"integer",format:"uint32"}}},"/variable/{variableId}/modbus-variable-address":{put:{minApiVersion:1,configModeRequired:!0,schema:{$ref:"./definitions.yaml#/ModbusVariableAddress"}}},"/variable/{variableId}/type":{put:{minApiVersion:1,configModeRequired:!0,schema:{$ref:"./definitions.yaml#/VariableType"}}},"/variable/{variableId}/raw-meta":{put:{minApiVersion:1.73,configModeRequired:!0,schema:{$ref:"./definitions.yaml#/Bytes"}}},"/variable/{variableId}/meta":{put:{minApiVersion:1.73,configModeRequired:!0,schema:{$ref:"./definitions.yaml#/VariableMeta"}}},"/variable/{variableId}/unit":{put:{minApiVersion:1.6,configModeRequired:!0,schema:{type:"string"}}},"/variable/{variableId}/number-of-elements":{put:{minApiVersion:1,configModeRequired:!0,schema:{type:"integer",format:"uint8"}}},"/variable/{variableId}/value":{put:{minApiVersion:1,configModeRequired:!0,schema:{$ref:"./definitions.yaml#/Bytes"}}},"/variable/{variableId}/bundle/id":{put:{minApiVersion:1,configModeRequired:!0,schema:{type:"integer",format:"uint16"}}}},e.VariableService=g,e.VariableTypeConverter=b,e._TAP_SERVICE_EXTENSION_VARIABLE_=R,e.variableConverters=f,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=iotize-tap-service-impl-variable.umd.min.js.map