UNPKG

@iotize/tap

Version:

IoTize Device client for Javascript

16 lines (14 loc) 30.2 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@iotize/common/error"),require("@iotize/tap/service/impl/variable"),require("@iotize/common/byte-converter"),require("@iotize/common/byte-stream"),require("@iotize/common/data-accessor"),require("@iotize/tap"),require("@iotize/tap/configurator"),require("@iotize/tap/service/all"),require("@iotize/tap/service/core"),require("fast-xml-parser")):"function"==typeof define&&define.amd?define("@iotize/tap/config/iotize-studio",["exports","@iotize/common/error","@iotize/tap/service/impl/variable","@iotize/common/byte-converter","@iotize/common/byte-stream","@iotize/common/data-accessor","@iotize/tap","@iotize/tap/configurator","@iotize/tap/service/all","@iotize/tap/service/core","fast-xml-parser"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).iotize=t.iotize||{},t.iotize.tap=t.iotize.tap||{},t.iotize.tap.config=t.iotize.tap.config||{},t.iotize.tap.config["iotize-studio"]={}),t.error,t.iotize.tap.service.impl.variable,t.byteConverter,t.byteStream,t.dataAccessor,t.iotize.tap,t.iotize.tap.configurator,t.iotize.tap.service.all,t.iotize.tap.service.core,t.fastXmlParser)}(this,(function(t,e,r,i,o,n,a,u,s,l,f){"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 d=function(t,e){return d=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},d(t,e)};function c(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}d(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}Object.create;function p(t){var e="function"==typeof Symbol&&Symbol.iterator,r=e&&t[e],i=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function v(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var i,o,n=r.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(i=n.next()).done;)a.push(i.value)}catch(t){o={error:t}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return a}function h(t,e,r){if(r||2===arguments.length)for(var i,o=0,n=e.length;o<n;o++)!i&&o in e||(i||(i=Array.prototype.slice.call(e,0,o)),i[o]=e[o]);return t.concat(i||Array.prototype.slice.call(e))}Object.create;var g,y,T=function(t){function e(e){return t.call(this,e)||this}return c(e,t),e}(e.BaseError);function C(t,e){var r=Object.keys(t).map((function(e){return t[e]}));if(void 0===r.find((function(t){return t.toString()===e})))throw new Error('Missing value "'+e+'" in enum. Available keys are '+r.join(", "));return e in t?t[t[e]]:e}function I(t,e){if(!(t in e))throw new Error("Missing mapping for "+t+". Available: "+Object.keys(e).join(", "));return e[t]}t.ByteOrder32Bits=void 0,(g=t.ByteOrder32Bits||(t.ByteOrder32Bits={}))[g.B3_B2_B1_B0=0]="B3_B2_B1_B0",g[g.B1_B0_B3_B2=1]="B1_B0_B3_B2",g[g.B2_B3_B0_B1=2]="B2_B3_B0_B1",g[g.B0_B1_B2_B3=3]="B0_B1_B2_B3",t.ByteOrder16Bits=void 0,(y=t.ByteOrder16Bits||(t.ByteOrder16Bits={}))[y.B1_B0=0]="B1_B0",y[y.B0_B1=1]="B0_B1";var m=function(){function e(t,e,r){this.data=t,this.iotizeModule=e,r&&(this._bundle=r)}return e.prototype.toJson=function(){return this.data},e.prototype.module=function(){return this.iotizeModule},e.prototype.valueSize=function(){return e.unitSizeToBitSize(parseInt(this.data.$.Unit))},e.prototype.valueQuantity=function(){return Number(this.data.$.Quantity)},e.prototype.name=function(){return this.data.$.GUI_Name},e.prototype.id=function(){return this.data.$.Id},e.prototype.alias=function(){return this.data.$.GUI_Alias},e.prototype.description=function(){return this.data.$.GUI_Description},e.prototype.unit=function(){return this.data.$.GUI_DispUnit},e.prototype.bundle=function(){return this._bundle},e.prototype.dataType=function(){var t=parseInt(this.data.$.Unit,10);if(this.data.$.GUI_float&&1==this.data.$.GUI_float)return r.VariableType.Data.FLOAT32;if(this.data.$.GUI_unsigned&&1==this.data.$.GUI_unsigned)switch(t){case 0:return r.VariableType.Data.BOOLEAN;case 1:return r.VariableType.Data.UINT8;case 2:return r.VariableType.Data.UINT16;case 3:return r.VariableType.Data.UINT32;default:throw new Error('Invalid data size "'+t+'" for variable '+this.name())}else switch(t){case 0:return r.VariableType.Data.BOOLEAN;case 1:return r.VariableType.Data.INT8;case 2:return r.VariableType.Data.INT16;case 3:return r.VariableType.Data.INT32;default:throw new Error('Invalid data size "'+t+'" for variable '+this.name())}},e.prototype.attribute=function(t){return this.data.$[t]},e.prototype.byteOrder=function(){var e=this.attribute("GUI_coding");if(e){if(16===this.valueSize())return C(t.ByteOrder16Bits,e);if(32===this.valueSize())return C(t.ByteOrder32Bits,e)}},e.unitSizeToBitSize=function(t){switch(t){case 0:return 1;case 1:return 8;case 2:return 16;case 3:return 32;default:throw new Error("Invalid unit size: "+t)}},e}(),b=function(){function t(t){this.data=t}return t.prototype.toJson=function(){return this.data},t.prototype.description=function(){return this.data.$.GUI_Description},t.prototype.name=function(){return this.data.$.Name},t.prototype.id=function(){return this.data.$.Id},t}(),S=function(){function t(t,e){this.aclGroup=e,this.data=t}return t.create=function(e,r){return new t({$:{ProfileName:e,Rights:""}},r)},t.prototype.toJson=function(){return this.data},t.prototype.listRights=function(){var t=this._getProperty("Rights","");return 0===t.length?[]:t.split(",").map((function(t){return t.trim()}))},t.prototype.username=function(){return this._getProperty("ProfileName")},t.prototype.hasRight=function(t){return"admin"===this.username()||-1!==this.listRights().indexOf(t)},t.prototype._getProperty=function(t,e){if(!(t in this.data.$)){if(void 0===e)throw new T("Missing key "+t+" in IoTize ACL");return e}return this.data.$[t]},t}(),P="anonymous",O=function(){function t(t,e){this.bundle=e,this.data=t}return t.prototype.toJson=function(){return this.data},t.prototype.getByProfileName=function(t){var e,r,i=this.listProfiles();try{for(var o=p(i),n=o.next();!n.done;n=o.next()){var a=n.value;if(a.username()===t)return a}}catch(t){e={error:t}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(e)throw e.error}}return S.create(t,this)},t.prototype.hasRight=function(t,e){var r=this.getByProfileName(P);if(r&&r.hasRight(e))return!0;if(t!==P){var i=this.getByProfileName(t);if(i)return i.hasRight(e)}return!1},t.prototype.listProfiles=function(){var t,e;if(!this.data.IOTizeACL)return[];var r=[];try{for(var i=p(this.data.IOTizeACL),o=i.next();!o.done;o=i.next()){var n=o.value;r.push(new S(n,this))}}catch(e){t={error:e}}finally{try{o&&!o.done&&(e=i.return)&&e.call(i)}finally{if(t)throw t.error}}return r},t}(),_=function(){function t(t,e){this.data=t,this.iotizeModule=e}return t.prototype.toJson=function(){return this.data},t.prototype.module=function(){return this.iotizeModule},t.prototype.id=function(){if(!this.data.$.Id)throw new T("This bundle does not have an id");return this.data.$.Id},t.prototype.name=function(){return this.data.$.GUI_Name||"#"+this.id()},t.prototype.dataLogPeriod=function(){return this.data.$.DataLogPeriod?Number(this.data.$.DataLogPeriod):0},t.prototype.hasDataLog=function(){return this.dataLogPeriod()>0},t.prototype.description=function(){return this.data.$.GUI_Description},t.prototype.variable=function(t){var e,r;try{for(var i=p(this.variables()),o=i.next();!o.done;o=i.next()){var n=o.value;if(n.id()===t)return n}}catch(t){e={error:t}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}throw new w(t,this.iotizeModule)},t.prototype.hasVariable=function(t){var e,r;try{for(var i=p(this.variables()),o=i.next();!o.done;o=i.next()){var n=o.value;if(n.id()===t)return n}}catch(t){e={error:t}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}return!1},t.prototype.profiles=function(){var t,e;if(!this.data.IOTizeAccessControl)return[];var r=[];try{for(var i=p(this.data.IOTizeAccessControl),o=i.next();!o.done;o=i.next()){var n=o.value;r.push(new b(n))}}catch(e){t={error:e}}finally{try{o&&!o.done&&(e=i.return)&&e.call(i)}finally{if(t)throw t.error}}return r},t.prototype.variables=function(){var t,e;if(!this.data.IOTizeVariable)return[];var r=[];try{for(var i=p(this.data.IOTizeVariable),o=i.next();!o.done;o=i.next()){var n=o.value;r.push(new m(n,this.iotizeModule,this))}}catch(e){t={error:e}}finally{try{o&&!o.done&&(e=i.return)&&e.call(i)}finally{if(t)throw t.error}}return r},t.prototype.getACLGroup=function(){var t={};return this.data.IOTizeAccessControl||(this.data.IOTizeAccessControl=[]),this.data.IOTizeAccessControl.length>0&&(t=this.data.IOTizeAccessControl[0]),new O(t,this)},t}(),A=function(t){function e(e,r){var i=t.call(this,'Bundle "'+e+'" does not exist.')||this;return i.bundleId=e,i.config=r,i}return c(e,t),e}(e.BaseError),w=function(t){function e(e,r){var i=t.call(this,'Variable "'+e+'" does not exist.')||this;return i.variableId=e,i.config=r,i}return c(e,t),e}(e.BaseError),N=function(){function t(t){if(!t.IOTizeConfiguration)throw new T("Key IOTizeConfiguration must exists");if(!t.IOTizeConfiguration.IOTizeApp)throw new T("Key IOTizeConfiguration.IOTizeApp must exists");if(0===t.IOTizeConfiguration.IOTizeApp.length||!t.IOTizeConfiguration.IOTizeApp[0].$)throw new T("No IOTizeConfiguration.IOTizeApp defined in this configuration file");this.data=t}return t.prototype.toJson=function(){return this.data},t.prototype.getAppConfig=function(){return this.data.IOTizeConfiguration.IOTizeApp[0]},t.prototype.appName=function(){if(!this.getAppConfig().$.Name)throw new T("Application Name is not set");return this.getAppConfig().$.Name},t.prototype.version=function(){if(!this.getAppConfig().$.Config)throw new T("App config version is not set");return this.getAppConfig().$.Config},t.prototype.id=function(){if(!this.getAppConfig().$.DevIoTizeSN)throw new T("Serial number is not set");return this.getAppConfig().$.DevIoTizeSN},t.prototype.setId=function(t){return this.getAppConfig().$.DevIoTizeSN=t,this},t.prototype.serialNumber=function(){return this.id()},t.prototype.bundles=function(){var t,e;if(!this.data.IOTizeConfiguration.IOTizeBundle)return[];var r=[];try{for(var i=p(this.data.IOTizeConfiguration.IOTizeBundle),o=i.next();!o.done;o=i.next()){var n=o.value;r.push(new _(n,this))}}catch(e){t={error:e}}finally{try{o&&!o.done&&(e=i.return)&&e.call(i)}finally{if(t)throw t.error}}return r},t.prototype.bundleAvailableForProfileName=function(t){return this.bundles().reduce((function(e,r){return r.getACLGroup().hasRight(t,"read")&&e.push(r),e}),[])},t.prototype.variables=function(){var t,e;if(!this.data.IOTizeConfiguration.IOTizeBundle)return[];var r=[];try{for(var i=p(this.data.IOTizeConfiguration.IOTizeBundle),o=i.next();!o.done;o=i.next()){var n=o.value;n=new _(n,this),r.push.apply(r,h([],v(n.variables())))}}catch(e){t={error:e}}finally{try{o&&!o.done&&(e=i.return)&&e.call(i)}finally{if(t)throw t.error}}return r},t.prototype.bundle=function(t){var e,r;try{for(var i=p(this.bundles()),o=i.next();!o.done;o=i.next()){var n=o.value;if(n.id()===t)return n}}catch(t){e={error:t}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}throw new A(t,this)},t.prototype.hasBundle=function(t){var e,r;try{for(var i=p(this.bundles()),o=i.next();!o.done;o=i.next()){var n=o.value;if(n.id()===t)return n}}catch(t){e={error:t}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}return!1},t.prototype.variable=function(t){var e,r;try{for(var i=p(this.variables()),o=i.next();!o.done;o=i.next()){var n=o.value;if(n.id()==t)return n}}catch(t){e={error:t}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}throw new w(t,this)},t.prototype.profiles=function(){var t,e;if(!this.data.IOTizeConfiguration.IOTizeProfile)return[];var r=[];try{for(var i=p(this.data.IOTizeConfiguration.IOTizeProfile),o=i.next();!o.done;o=i.next()){var n=o.value;r.push(new b(n))}}catch(e){t={error:e}}finally{try{o&&!o.done&&(e=i.return)&&e.call(i)}finally{if(t)throw t.error}}return r},t.prototype.description=function(){return this.getAppConfig().$.GUI_Description},t.prototype.name=function(){return this.getAppConfig().$.GUI_Name},t}(),B=function(){function t(){}return t.fromXML=function(t){throw new Error("Add import to @iotize/tap/config/iotize-studio/parser/xml to create configuration model from XML file")},t.fromJson=function(t){return new N(JSON.parse(t))},t.create=function(e){if("string"==typeof e){if(e.trim(),0===e.length)throw new Error("Cannot create configuration from empty data");return"{"===e[0]?t.fromJson(e):t.fromXML(e)}return new N(e)},t}(),z=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return c(e,t),e.invalidKeyValue=function(t,r){return new e('Invalid IoTize studio value for configuration key "'+t+'". '+r,e.Code.InvalidConfigKeyValue)},e}(e.CodeError);!function(t){!function(t){t.InvalidConfigKeyValue="IoTizeStudioErrorInvalidConfigKeyValue"}(t.Code||(t.Code={}))}(z||(z={}));var E={P2P:"PEER_TO_PEER",NETWORK:"NETWORK",INFRA:"NETWORK",INFRA_CLOUD:"NETWORK"},D={0:"NO",1:"SHUTDOWN",2:"STANDBY"},U={0:"VISIBLE",1:"HIDDEN"},M={0:"EMULATION",1:"INDEXED"},R={0:"VISIBLE",1:"HIDDEN",2:"HIDDEN_FROM_SCAN"},L={1:["B"],3:["B","G"],7:["B","G","N"]},x={JTAG:"JTAG",MODBUS:"MODBUS",NONE:"NONE",S3P:"S3P",SERIAL:"SERIAL",SERIAL_STANDARD:"SERIAL",SERIAL_VIA_TAPNPASS:"SERIAL",CUSTOM:"CUSTOM",SWD:"SWD",GPIO:"DIRECT_IO",DIRECT_IO:"DIRECT_IO",DIRECTIO:"DIRECT_IO",CAN:"CAN",NO_TARGET_PROTOCOL:"NONE",MODBUSTCP:"MODBUS_TCP"},V={NO:"NO",PAIRING:"MANDATORY","PAIRING+LOGIN":"MANDATORY_FOR_LOGIN"},F={0:"NFC_NON_PRIORITY",1:"NFC_PRIORITY"};function G(t,e){return void 0===e&&(e=["no","false","0"]),void 0!==t&&(!(e.indexOf(t.toString().toLowerCase())>=0)&&!!t)}function k(t){var e=G(t.value("GUI_unsigned","string","0")),i=G(t.value("GUI_float","string","0")),o=t.value("Unit","number",1);if(1===o){var n=t.get("XAppRender",void 0);if(n)if("ASCII"===n.value("GUI_UnitType","string",void 0))return r.VariableType.Data.ASCII}var a=t.value("UnitType","string","");if(a){if("boolean"===a)return r.VariableType.Data.BOOLEAN;if("ASCII"===a)return r.VariableType.Data.ASCII;e="unsigned integer"===a,i="float"===a}if(i)return r.VariableType.Data.FLOAT32;switch(o){case 0:case 1:return e?r.VariableType.Data.UINT8:r.VariableType.Data.INT8;case 2:return e?r.VariableType.Data.UINT16:r.VariableType.Data.INT16;case 3:return e?r.VariableType.Data.UINT32:r.VariableType.Data.INT32;default:throw new Error('Unknown unit size: "'+o+'" (type='+typeof o+")")}}function $(t,e,r,i){var o=t.value(e,"string",i);if(o){if(!((o=o.replace(/ /g,"_").toUpperCase())in r))throw new Error('Invalid value "'+o+'" for key "'+e+'"');return r[o]}}function K(t,e,r,i,o){var n=null==t?void 0:t.value(r,o,void 0);void 0!==n&&""!==n&&(e[i]=n)}function W(t,e,r,i){void 0===i&&(i="string"),Object.entries(r).forEach((function(r){var o=v(r,2),n=o[0],a=o[1];K(t,e,n,a,i)}))}var H=function(){function t(t,e){void 0===t&&(t={strict:!1}),this.options=t,this.host=e,this.warnings=[],this.modbusSerialConfigConverter=new s.TapnpassProtocolConfigurationConverter}return t.prototype.convert=function(t){var e=t.get("IOTizeConfiguration"),r=e.get("IOTizeApp"),i=r.get("WIFI_Info",void 0),o=e.list("IOTizeBundle",[]),n=e.list("IOTizeProfile",[]),a={version:e.value("Version","string","1.0.0"),application:this.readApplicationConfig(r),data:{bundles:this.readBundlesConfig(o),profiles:this.readProfilesConfig(n)},cloud:this.readCloudConfig(r),jvm:this.readJvmConfig(e),wireless:{options:this.readWirelessOptionsConfig(r),protocols:{wifi:this.readWifiConfig(i),mqtt:this.readMqttConfig(i),ble:this.readBleConfig(r),lora:this.readLoraConfig(r),nfc:this.readNfcConfig(r)}},tap:this.readTapConfig(r),target:this.readTargetConfig(r)},u=this.readSlaveServerConfig(r);u&&(a.slaveServer=u);var s=this.readEthernetConfig(r);return s&&(a.ports={ethernet:s}),this.warnings.length,a},t.prototype.reportError=function(t,e){if(void 0===e&&(e=t.message),this.options.strict)throw t;this.warnings.push({error:t,message:e})},t.prototype.readSlaveServerConfig=function(t){if(t)switch(t.value("MBS_Com_Channel","number",0)){case s.SlaveServerRawConfig.Channel.CAN:return{type:"CAN",config:this.readCanProtocolConfig(t)};case s.SlaveServerRawConfig.Channel.MODBUS_RTU:var e=t.value("MBSProtocolConfDataLen","number",0),r=i.hexStringToBuffer(t.value("MBSProtocolConfData","string",""));return{type:"MODBUS_RTU",config:this._protocolDataToJsonConfig(r,e)};case s.SlaveServerRawConfig.Channel.MODBUS_TCP:return{type:"MODBUS_TCP",config:{port:t.value("MBS_ModbusTCP_Port","number",502),firstRegisterAddress:t.value("MBS_ModbusTCP_Addr0","number",0)}};case s.SlaveServerRawConfig.Channel.SPI:return{type:"SPI"};case s.SlaveServerRawConfig.Channel.DISABLED:return;default:throw new Error("Invalid config")}},t.prototype.readMqttConfig=function(t){var e;if(t){var r={};!function(t,e,r,i){void 0===i&&(i="string"),Object.entries(r).forEach((function(r){var o,n=v(r,2),a=n[0],u=n[1],s=null===(o=t.get(a,void 0))||void 0===o?void 0:o.value("Name",i,void 0);s&&(e[u]=s)}))}(t,r,{CloudHostName:"brokerHostname",CloudServiceName:"brokerPort",CloudMQTT_UID:"password",GUI_DevNetkey:"relayNetKey",GUI_DevMQTT_ClientID:"clientId",CloudMQTT_USERNAME:"username"});var i=this.readFileContentAsHexString(null===(e=t.get("AWSRootCertificate",void 0))||void 0===e?void 0:e.value("Name","string",void 0));return i&&(r.brokerCertificate=i),r}},t.prototype.readLoraConfig=function(t){return{config:void 0,ids:void 0}},t.prototype.readBleConfig=function(t){return{}},t.prototype.readNfcConfig=function(t){return{autoLogProfileId:t.value("NFCLogin","number",void 0),connectionPriority:$(t,"NFCInterruptionLock",F,void 0)}},t.prototype.readWifiConfig=function(t){if(t){var e=$(t,"Network",E,"P2P"),r="PEER_TO_PEER"===e,i={mode:e};K(t,i,"ModuleIPMask","mask","string"),K(t,i,"ModuleIPGateway","gatewayIp","string"),K(t,i,"ModuleIPAddress","ip","string"),K(t,i,"Wifi_TxLevel","txPower","number");var o=$(t,"Wifi_WEPKey_Hidden",U,void 0);void 0!==o&&(i.keyVisibility=o);var n=$(t,"Wifi_Protocol",L,void 0);n&&(i.protocol=n),K(t,i,"Wifi_Region","countryCode","number");var a=$(t,"Wifi_SSID_Hidden",R,void 0);return a&&(i.ssidVisibility=a),K(t,i,r?"Module_AP_SSID":"ModuleSSID","ssid","string"),K(t,i,r?"Module_AP_WEPKey":"ModuleWEPKey","key","string"),i}},t.prototype.toAuthorizedHostProtocols=function(t){var e=this;if(t&&"ALL"!==t&&"FFFF"!==t){if("string"==typeof(o=t)&&o.match(/^(0x)?([a-fA-F0-9])*$/)){var r=i.hexStringToBuffer(t);return l.converters.hostProtocolArray.decode(r).map((function(t){return a.HostProtocol[t]}))}return t.split(",").reduce((function(t,r){r=r.trim();try{t.push(r)}catch(t){e.reportError(t)}return t}),[]);var o}},t.prototype.readAuthorizedHostProtocols=function(t){var e=void 0,r=t.value("HostProtocol","string",void 0);try{e=this.toAuthorizedHostProtocols(r)}catch(t){this.reportError(t,'Cannot convert HostProtocol value "'+r+'"')}return e&&e.length>0?e:void 0},t.prototype.readWirelessOptionsConfig=function(t){var e={inactivityTimeout:t.value("LowPowerHostTimeout","number",0)},r=this.readAuthorizedHostProtocols(t);r&&(e.authorizedProtocols=r);var i=$(t,"NFCPairingMandatory",V,void 0),o=t.value("BLEPairingRequest","boolean",void 0);return void 0===i&&void 0===o||(e.pairing={blePairing:o,nfcPairingMode:i}),e},t.prototype.readJvmConfig=function(t){var e=t.get("IOTizeApp"),r=t.get("GUI_Environment",void 0),i=e.value("JVM_Custom_Code","string",void 0);if(null==r?void 0:r.value("UseInternalJVM","boolean",!1))return{code:i?this.readFileContentAsHexString(i):void 0}},t.prototype.readEthernetConfig=function(t){var e={};if(W(t,e,{EthernetIPAddress:"ip",EthernetIPGateway:"gatewayIp",EthernetIPMask:"ipMask"}),0!==Object.keys(e).length)return e},t.prototype.readFileContentAsHexString=function(t){if(t&&(this.host||this.reportError(new Error('External file reference "'+t+'" cannot be resolved')),this.host))try{var e=this.host.getFileContent(t);return"0x"+i.bufferToHexString(e)}catch(t){this.reportError(t)}},t.prototype.readCloudConfig=function(t){var e=t.get("CloudServices",void 0),r=t.get("WIFI_Info",void 0),i={},o={};return r&&W(r,o,{Cloud_Publish_Topic:"mqttPublishTopic",Cloud_Subscribe_Topic:"mqttSubscribeTopic"}),e&&W(e,o,{CloudMqttPeriod:"uploadPeriod"},"number"),Object.keys(o).length>0&&(i.dataLog=o),Object.keys(i).length>0?i:void 0},t.prototype.readApplicationConfig=function(t){var e=t.has("GUI_Path")?t.value("GUI_Path","string",""):t.value("Path","string",""),r={name:t.value("Name","string","Tap"),universalLink:t.value("WebLink","string",""),uri:e},o=t.value("ProductCode","string",void 0);void 0!==o&&(r.productCode=o);var n=t.value("Data","string",void 0);return void 0!==n&&(r.data="0x"+i.bufferToHexString(i.asciiStringToByteBuffer(n))),r},t.prototype.readTapConfig=function(t){var e,r,i=t.value("InterfaceLock","number",0),o={security:(new s.SecurityOptionsConverter).decode(Uint8Array.from([0,i])),powerOptimization:$(t,"LowPowerLevel",D,void 0),scram:{hashIteration:t.value("Scram_Hash_It","number",5e3)},certificate:{publicKey:this.readFileContentAsHexString(null===(e=t.get("DeviceCertificate",void 0))||void 0===e?void 0:e.value("Name","string",void 0)),privateKey:this.readFileContentAsHexString(null===(r=t.get("DevicePrivateKey",void 0))||void 0===r?void 0:r.value("Name","string",void 0))}},n=t.value("TimeZoneStr","string",void 0),a=t.value("NTP_URL","string",void 0);return(n||a)&&(o.time={zone:n,ntpServer:a}),o},t.prototype.readTapTimeConfig=function(t){var e=t.value("TimeZoneStr","string",void 0),r=t.value("NTP_URL","string",void 0);if(e||r)return{zone:e,ntpServer:r}},t.prototype.readTargetConfig=function(t){var e=t.value("Firmware","string",void 0);if("1"===t.value("GUI_TargetType","string","0"))return{type:"TAPNPASS",protocol:{config:this.readTapnpassTargetProtocolConfig(t)},firmwareVersion:e};var r=this.readMCUTargetProtocol(t);return r?{type:"MCU",protocol:r,firmwareVersion:e}:void 0},t.prototype.readTargetProtocol=function(t){return $(t,"TargetProtocol",x,"NONE")},t.prototype.readTapnpassTargetProtocol=function(t){var e=this.readTargetProtocol(t);switch(e){case"SERIAL":return{type:"SERIAL",config:this.readTapnpassTargetProtocolConfig(t)};case"MODBUS":return{type:"MODBUS",config:this.readTapnpassTargetProtocolConfig(t)};default:throw new Error('Illegal target protocol "'+(null==e?void 0:e.toString())+'" for TapNPass target type.')}},t.prototype.readTapnpassTargetProtocolConfig=function(t){var e=t.value("TargetProtocolConfDataLen","number",0),r=i.hexStringToBuffer(t.value("TargetProtocolConfData","string",""));return this._protocolDataToJsonConfig(r,e)},t.prototype.readMCUTargetProtocol=function(t){var e=this.readTargetProtocol(t);switch(e){case"SWD":return{type:e};case"CUSTOM":return{type:"CUSTOM"};case"MODBUS":return{type:"MODBUS",config:this.readModbusProtocolConfig(t)};case"S3P":return{type:"S3P",config:this.readS3PProtocolConfig(t)};case"SERIAL":return{type:"SERIAL",config:this.readTapnpassTargetProtocolConfig(t)};case"NONE":return;case"DIRECT_IO":return{type:"DIRECT_IO"};case"CAN":return{type:"CAN",config:this.readCanProtocolConfig(t)};case"MODBUS_TCP":return{type:"MODBUS_TCP",config:this.readModbusTcpProtocolConfig(t)};default:throw new Error('Target protocol convertion from "'+(null==e?void 0:e.toString())+'" is not supported yet.')}},t.prototype.readSerialProtocolConfig=function(t){var e=this.readModbusProtocolConfig(t);if(e)return null==e?void 0:e.serial},t.prototype.readS3PProtocolConfig=function(t){return{mode:$(t,"S3Pmode",M)||"EMULATION",delay:t.value("S3PDelay","number",1)}},t.prototype.readCanProtocolConfig=function(t){return{frequency:t.value("CAN_Freqkbps","number",25),mode:$(t,"CAN_Mode",s.TargetCanProtocolConfiguration.Mode)||"NORMAL",filter:$(t,"CAN_Filter",s.TargetCanProtocolConfiguration.Filter)||"SINGLE",code:j(t.value("CAN_Code","number",0)),mask:j(t.value("CAN_Mask","number",4294967295))}},t.prototype.readModbusTcpProtocolConfig=function(t){var e={modbus:{}};if(W(t,e.modbus,{ModbusTCPDefSlaveAddr:"defaultSlaveAddress"}),W(t,e.modbus,{ModbusTCPAddr0:"firstRegisterAddress",ModbusTCPPort:"port",ModbusTCPTimeout:"timeout"},"number"),0!==Object.keys(e).length)return e},t.prototype.readModbusProtocolConfig=function(t){var e=this.readTapnpassTargetProtocolConfig(t),r=e.serial;return delete r.identification,delete r.physicalPort,delete r.hardwareFlowControl,delete r.ledStatus,{modbus:e.modbus,serial:e.serial}},t.prototype.toEnumKey=function(t,e){return t in e||this.reportError(new Error('Cannot find corresponding key for value "'+t.toString()+'". Available keys: '+Object.keys(e).join(", "))),e[t]},t.prototype.readProfilesConfig=function(t){for(var e=[],r=0;r<t.length;r++){var i=t[r],o=i.value("Name"),n=void 0;if(o!==u.ANONYMOUS_USER.username){n=u.isSpecialUser(o)?{username:i.value("Name","string"),lifeTime:i.value("LifeTime","number",0),key:this.readUserKey(i)}:{username:i.value("Name","string",""),id:i.value("Id","number",0),lifeTime:i.value("LifeTime","number",0),key:this.readUserKey(i)};var a=i.list("IOTizeUser",[]);if(a.length>0){var s=this.readUserProfile(a);n.users=s}e.push(n)}}return e},t.prototype.readUserKey=function(t){var e=t.value("Scram_Pwd","string",void 0);if(e)return"0x"+e;var r=t.value("Pwd","string",void 0);return r?"0x"+r:void 0},t.prototype.readUserProfile=function(t){for(var e=[],r=0;r<t.length;r++){var i=t[r],o={username:i.value("Name","string",""),id:i.value("Id","number",0),key:this.readUserKey(i)};e.push(o)}return e},t.prototype.readBundlesConfig=function(t){for(var e=[],r=0;r<t.length;r++){var i=t[r],o=[],n=i.get("IOTizeAccessControl",void 0);n&&(o=n.list("IOTizeACL",[]));for(var a={},s=0;s<o.length;s++){var l=o[s],f=l.value("ProfileName");if(f!==u.ADMIN_USER.username){var d=l.value("Rights");a[f]={read:d.includes("read"),write:d.includes("write")}}}var c={name:i.value("GUI_Name"),id:parseInt(i.value("Id")),variables:this.readVariablesConfig(i.list("IOTizeVariable",[])),acls:a,dataLog:{period:i.value("DataLogPeriod","number",0)},features:this.readSpecialFeatures(i.list("Feature",[]))};e.push(c)}return e},t.prototype.readSpecialFeatures=function(t){if(t.length>0){for(var e=[],r=0;r<t.length;r++){var i=t[r].value("FeatureResId","number");if(!(i in a.SpecialFeature))throw new Error("Unexpected feature id: "+i);var o=a.SpecialFeature[i];e.push(o)}return e}},t.prototype.readVariablesConfig=function(t){for(var e,r=[],i=0;i<t.length;i++){var o=t[i],n=o.value("Id","number"),a=o.value("Quantity","number",1),u=I(k(o),s.VariableType.Data),l=o.value("GUI_Name","string",""),f=o.value("GUI_DispUnit","string","")||void 0,d=void 0;(l||f)&&(d={name:l,unit:f});var c=G(o.value("IsInTap","string","0")),p=G(o.value("IsInTapVolatile","string","0"));if(p||c){var v=o.value("InTap_InitialValueString","string",""),h={domain:p?"IN_TAP_VOLATIL":"IN_TAP_STATIC",id:n,length:a,dataType:u,meta:d,value:(e=void 0,(e=v.split(";").reduce((function(t,e){return 0===e.length||(e.startsWith("0x")?t.push(e):t.push(parseFloat(e))),t}),[])).length>0?1===e.length?e[0]:e:void 0)};r.push(h)}else{var g=parseInt(o.value("Address","string"));if(isNaN(g))throw new Error("Failed to parse variable "+l+" #"+n+": address is not a number.");var y={domain:"TARGET",address:j(g),id:n,length:a,dataType:u,meta:d};r.push(y)}}return r},t.prototype._protocolDataToJsonConfig=function(t,e){if(0===e)return{modbus:{offsetFirstRegister:!1,slave:0},serial:{baudRate:115200,bitParity:"EVEN",dataBits:"_8",handshakeDelimiter:"NONE",hardwareFlowControl:"NONE",identification:!1,ledStatus:!0,physicalPort:"AUTO",stopBits:"ONE",timeout:255},usb:{aliases:[]}};if(t.length<8)throw z.invalidKeyValue("TargetProtocolConfData","Protocol configuration data should be at least 8 bytes");var r=t.slice(0,4),i=t.slice(4,8),n=t.slice(8);t=o.KaitaiStreamWriter.mergeArrays(r.reverse(),i.reverse(),n);var a=o.KaitaiStreamWriter.mergeArrays(t.slice(0,8).reverse(),t.slice(8)),u=s.tapnpassConverters.tapnpassProtocolConfiguration.decode(a),l=u.serial,f=u.usb;return{modbus:u.modbus,serial:{baudRate:l.baudRate,bitParity:this.toEnumKey(l.bitParity,s.SerialSettings.BitParity),dataBits:this.toEnumKey(l.dataBits,s.SerialSettings.DataBits),handshakeDelimiter:this.toEnumKey(l.handshakeDelimiter,s.SerialSettings.HandshakeDelimiter),hardwareFlowControl:this.toEnumKey(l.hardwareFlowControl,s.SerialSettings.HardwareFlowControl),physicalPort:this.toEnumKey(l.physicalPort,s.SerialSettings.PhysicalPort),stopBits:this.toEnumKey(l.stopBits,s.SerialSettings.StopBits),timeout:l.timeout,identification:!1,ledStatus:!1},usb:f}},t}();function j(t){return"0x"+t.toString(16)}t.BundleDoesNotExistError=A,t.InvalidConfigurationError=T,t.IoTizeStudioToTapConfigConverter=H,t.IotizeBundleModel=_,t.IotizeConfigFactory=B,t.IotizeConfigModel=N,t.IotizeProfileModel=b,t.IotizeVariableModel=m,t.VariableDoesNotExistError=w,t.convertIoTizeStudioConfigToTapConfig=function(t){var e;return(new H).convert(new n.DotAccessor((e=t,f.parse(e,{attributeNamePrefix:"",ignoreAttributes:!1}))))},Object.defineProperty(t,"__esModule",{value:!0})})); //# sourceMappingURL=iotize-tap-config-iotize-studio.umd.min.js.map