mini_program_gizwits_sdk 3.7.2-kuka → 3.7.3-kuka
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +4 -4
- package/package.json +1 -1
- package/src/handler/ble.ts +23 -1
- package/src/sdk.ts +43 -3
- package/src/wechatApi.ts +30 -2
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
module.exports=function(e){var t={};function i(n){if(t[n])return t[n].exports;var s=t[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,i),s.l=!0,s.exports}return i.m=e,i.c=t,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)i.d(n,s,function(t){return e[t]}.bind(null,s));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=34)}([function(e,t,i){(function(t){var n;e.exports=(n=n||function(e,n){var s;if("undefined"!=typeof window&&window.crypto&&(s=window.crypto),"undefined"!=typeof self&&self.crypto&&(s=self.crypto),"undefined"!=typeof globalThis&&globalThis.crypto&&(s=globalThis.crypto),!s&&"undefined"!=typeof window&&window.msCrypto&&(s=window.msCrypto),!s&&void 0!==t&&t.crypto&&(s=t.crypto),!s)try{s=i(38)}catch(e){}var r=function(){if(s){if("function"==typeof s.getRandomValues)try{return s.getRandomValues(new Uint32Array(1))[0]}catch(e){}if("function"==typeof s.randomBytes)try{return s.randomBytes(4).readInt32LE()}catch(e){}}throw new Error("Native crypto module could not be used to get secure random number.")},a=Object.create||function(){function e(){}return function(t){var i;return e.prototype=t,i=new e,e.prototype=null,i}}(),o={},c=o.lib={},l=c.Base={extend:function(e){var t=a(this);return e&&t.mixIn(e),t.hasOwnProperty("init")&&this.init!==t.init||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},u=c.WordArray=l.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||h).stringify(this)},concat:function(e){var t=this.words,i=e.words,n=this.sigBytes,s=e.sigBytes;if(this.clamp(),n%4)for(var r=0;r<s;r++){var a=i[r>>>2]>>>24-r%4*8&255;t[n+r>>>2]|=a<<24-(n+r)%4*8}else for(var o=0;o<s;o+=4)t[n+o>>>2]=i[o>>>2];return this.sigBytes+=s,this},clamp:function(){var t=this.words,i=this.sigBytes;t[i>>>2]&=4294967295<<32-i%4*8,t.length=e.ceil(i/4)},clone:function(){var e=l.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var t=[],i=0;i<e;i+=4)t.push(r());return new u.init(t,e)}}),d=o.enc={},h=d.Hex={stringify:function(e){for(var t=e.words,i=e.sigBytes,n=[],s=0;s<i;s++){var r=t[s>>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,i=[],n=0;n<t;n+=2)i[n>>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new u.init(i,t/2)}},f=d.Latin1={stringify:function(e){for(var t=e.words,i=e.sigBytes,n=[],s=0;s<i;s++){var r=t[s>>>2]>>>24-s%4*8&255;n.push(String.fromCharCode(r))}return n.join("")},parse:function(e){for(var t=e.length,i=[],n=0;n<t;n++)i[n>>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new u.init(i,t)}},p=d.Utf8={stringify:function(e){try{return decodeURIComponent(escape(f.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return f.parse(unescape(encodeURIComponent(e)))}},v=c.BufferedBlockAlgorithm=l.extend({reset:function(){this._data=new u.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=p.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var i,n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a),c=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,l=e.min(4*c,r);if(c){for(var d=0;d<c;d+=a)this._doProcessBlock(s,d);i=s.splice(0,c),n.sigBytes-=l}return new u.init(i,l)},clone:function(){var e=l.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0}),g=(c.Hasher=v.extend({cfg:l.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){v.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,i){return new e.init(i).finalize(t)}},_createHmacHelper:function(e){return function(t,i){return new g.HMAC.init(e,i).finalize(t)}}}),o.algo={});return o}(Math),n)}).call(this,i(23))},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(3);class s{constructor(e){this.header="",this.len=0,this.flag=[0],this.cmd="",this.content=[],this.formatP0=e=>{let t=n.checkHeader(e);if(!1===t)throw new Error("Header Error");this.header=n.arrayToString(e.slice(0,t));const i=e.slice(t,e.length),r=n.getProtocolLen(i);this.len=s.decodeLen(i.slice(0,r)),t+=r,this.flag=e.slice(t,t+1),t+=1,this.cmd=n.arrayToString(e.slice(t,t+2)),t+=2,this.content=e.slice(t,e.length)},e&&e.length>0&&this.formatP0(e)}}s.decodeLen=e=>{let t=1,i=0,n=0,s=0;do{n=e[s],i+=(127&n)*t,t*=128,s+=1}while(0!=(128&n));return i},t.default=s},function(e,t,i){var n,s,r,a,o,c,l,u,d,h,f,p,v,g,y,_,D,m,b;e.exports=(n=i(0),i(6),void(n.lib.Cipher||(s=n,r=s.lib,a=r.Base,o=r.WordArray,c=r.BufferedBlockAlgorithm,l=s.enc,l.Utf8,u=l.Base64,d=s.algo.EvpKDF,h=r.Cipher=c.extend({cfg:a.extend(),createEncryptor:function(e,t){return this.create(this._ENC_XFORM_MODE,e,t)},createDecryptor:function(e,t){return this.create(this._DEC_XFORM_MODE,e,t)},init:function(e,t,i){this.cfg=this.cfg.extend(i),this._xformMode=e,this._key=t,this.reset()},reset:function(){c.reset.call(this),this._doReset()},process:function(e){return this._append(e),this._process()},finalize:function(e){return e&&this._append(e),this._doFinalize()},keySize:4,ivSize:4,_ENC_XFORM_MODE:1,_DEC_XFORM_MODE:2,_createHelper:function(){function e(e){return"string"==typeof e?b:D}return function(t){return{encrypt:function(i,n,s){return e(n).encrypt(t,i,n,s)},decrypt:function(i,n,s){return e(n).decrypt(t,i,n,s)}}}}()}),r.StreamCipher=h.extend({_doFinalize:function(){return this._process(!0)},blockSize:1}),f=s.mode={},p=r.BlockCipherMode=a.extend({createEncryptor:function(e,t){return this.Encryptor.create(e,t)},createDecryptor:function(e,t){return this.Decryptor.create(e,t)},init:function(e,t){this._cipher=e,this._iv=t}}),v=f.CBC=function(){var e=p.extend();function t(e,t,i){var n,s=this._iv;s?(n=s,this._iv=void 0):n=this._prevBlock;for(var r=0;r<i;r++)e[t+r]^=n[r]}return e.Encryptor=e.extend({processBlock:function(e,i){var n=this._cipher,s=n.blockSize;t.call(this,e,i,s),n.encryptBlock(e,i),this._prevBlock=e.slice(i,i+s)}}),e.Decryptor=e.extend({processBlock:function(e,i){var n=this._cipher,s=n.blockSize,r=e.slice(i,i+s);n.decryptBlock(e,i),t.call(this,e,i,s),this._prevBlock=r}}),e}(),g=(s.pad={}).Pkcs7={pad:function(e,t){for(var i=4*t,n=i-e.sigBytes%i,s=n<<24|n<<16|n<<8|n,r=[],a=0;a<n;a+=4)r.push(s);var c=o.create(r,n);e.concat(c)},unpad:function(e){var t=255&e.words[e.sigBytes-1>>>2];e.sigBytes-=t}},r.BlockCipher=h.extend({cfg:h.cfg.extend({mode:v,padding:g}),reset:function(){var e;h.reset.call(this);var t=this.cfg,i=t.iv,n=t.mode;this._xformMode==this._ENC_XFORM_MODE?e=n.createEncryptor:(e=n.createDecryptor,this._minBufferSize=1),this._mode&&this._mode.__creator==e?this._mode.init(this,i&&i.words):(this._mode=e.call(n,this,i&&i.words),this._mode.__creator=e)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e,t=this.cfg.padding;return this._xformMode==this._ENC_XFORM_MODE?(t.pad(this._data,this.blockSize),e=this._process(!0)):(e=this._process(!0),t.unpad(e)),e},blockSize:4}),y=r.CipherParams=a.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),_=(s.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext,i=e.salt;return(i?o.create([1398893684,1701076831]).concat(i).concat(t):t).toString(u)},parse:function(e){var t,i=u.parse(e),n=i.words;return 1398893684==n[0]&&1701076831==n[1]&&(t=o.create(n.slice(2,4)),n.splice(0,4),i.sigBytes-=16),y.create({ciphertext:i,salt:t})}},D=r.SerializableCipher=a.extend({cfg:a.extend({format:_}),encrypt:function(e,t,i,n){n=this.cfg.extend(n);var s=e.createEncryptor(i,n),r=s.finalize(t),a=s.cfg;return y.create({ciphertext:r,key:i,iv:a.iv,algorithm:e,mode:a.mode,padding:a.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,i,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(i,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}}),m=(s.kdf={}).OpenSSL={execute:function(e,t,i,n,s){if(n||(n=o.random(8)),s)r=d.create({keySize:t+i,hasher:s}).compute(e,n);else var r=d.create({keySize:t+i}).compute(e,n);var a=o.create(r.words.slice(t),4*i);return r.sigBytes=4*t,y.create({key:r,iv:a,salt:n})}},b=r.PasswordBasedCipher=D.extend({cfg:D.cfg.extend({kdf:m}),encrypt:function(e,t,i,n){var s=(n=this.cfg.extend(n)).kdf.execute(i,e.keySize,e.ivSize,n.salt,n.hasher);n.iv=s.iv;var r=D.encrypt.call(this,e,t,s.key,n);return r.mixIn(s),r},decrypt:function(e,t,i,n){n=this.cfg.extend(n),t=this._parse(t,n.format);var s=n.kdf.execute(i,e.keySize,e.ivSize,t.salt,n.hasher);return n.iv=s.iv,D.decrypt.call(this,e,t,s.key,n)}}))))},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.checkHeader=e=>{let t=0;return 0===e[0]&&0===e[1]&&0===e[2]&&3===e[3]&&(t=4,4)},t.completeBlock=e=>{const t=n(e,8*Math.ceil(e.length/8)),i=[];for(let e=0;e<t.length;e+=8)i.push(parseInt(t.substring(e,e+8),2));return i};t.getProtocolLen=e=>{let t=0;for(;t<e.length&&"1"===n(e[t].toString(2),8)[0];t++);return t+1},t.arrayToString=function(e){let t="";return e.map(e=>(t+=n(e.toString(16),2),null)),t},t.arrayToASCII=function(e){let t="";return e.map(e=>(t+=String.fromCharCode(e),null)),t};const n=(e,t,i=!1)=>{const n=t-e.length,s=new Array(n).fill(0).join("");return i?e+=s:e=s+e,e};t.fillString=n;t.bytesToInt=e=>{let t=0;for(let i=0;i<e.length;i++)t=t<<8|e[i];return t};t.bytesToHexString=e=>Array.from(e,e=>("0"+e.toString(16)).slice(-2)).join("");t.string2Bytes=e=>{const t=[];for(let i=0;i<e.length;i++)t.push(e.charCodeAt(i));return t};t.hexStrint2byte=e=>{e.length%2!=0&&(e=`0${e}`);const t=Math.ceil(e.length/2),i=[];for(let n=0;n<t;n++){const t=2*n,s=t+2,r=e.substring(t,s);i.push(parseInt(r,16))}return i};const s=e=>{const t=encodeURI(e);return-1!==t.indexOf("%")&&"%"!==e?t.split("%").filter(e=>""!==e).map(e=>parseInt(e,16)):[t.charCodeAt(0)]};t.formatCode=s;t.formatCodesFromStr=e=>{const t=[0,0];let i=[];for(let n=0;n<e.length;n++){const r=s(e[n]);t[1]+=r.length,i=i.concat(r)}return[i,t]};t.arrayToUint8=e=>{const t=new ArrayBuffer(e.length),i=new Uint8Array(t);for(let n=0;n<t.byteLength;n++)i[n]=e[n];return i}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(5),s=i(37);t.default=new class{constructor(){this.logMap=[{id:"debug"},{id:"info"},{id:"warn"},{id:"error"}],this.console=console,this.debug=(...e)=>{this.console.debug(...e)},this.info=(...e)=>{this.console.info(...e)},this.log=(...e)=>{this.console.log(...e)},this.warn=(...e)=>{this.console.warn(...e)},this.error=(e,t)=>{this.console.error(e,t),s.default(t)},this.setLogLevel=e=>{const t=this.logMap.findIndex(t=>t.id===e);return-1!==t?(this.console=Object.assign({},console),this.logMap.map((e,i)=>{i<t&&(this.console[e.id]=()=>{})}),{success:!0,err:null}):{success:!1,err:n.default.GIZ_SDK_LOG_LEVEL_INVALID}}}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default={GIZ_OPENAPI_DEVICE_NOT_BOUND:{errorCode:9017,errorMessage:"not bind"},GIZ_SDK_HTTP_REQUEST_FAILED:{errorCode:8099,errorMessage:"网络请求失败"},GIZ_SDK_DEVICE_NO_RESPONSE:{errorCode:8030,errorMessage:"设备未响应"},GIZ_SDK_SDK_NOT_INITIALIZED:{errorCode:8300,errorMessage:"not init"},CONFIG_TIME_OUT:{errorCode:8023,errorMessage:"Config Timeout"},WECHAT_ERROR:{errorCode:1e4,errorMessage:"wechat error"},GIZ_SDK_ONBOARDING_STOPPED:{errorCode:8318,errorMessage:"配网中断"},GIZ_SDK_DEVICE_CONFIG_IS_RUNNING:{errorCode:8022,errorMessage:"配置正在进行中"},GIZ_OPENAPI_TOKEN_INVALID:{errorCode:9004,errorMessage:"token 失效"},GIZ_SDK_BIND_DEVICE_FAILED:{errorCode:8039,errorMessage:"设备绑定失败"},GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON:{errorCode:8281,errorMessage:"蓝牙未启用"},GIZ_SDK_OTHERWISE:{errorCode:8100,errorMessage:""},GIZ_SDK_DEVICE_NOT_SUBSCRIBED:{errorCode:8029,errorMessage:"设备还未订阅"},GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY:{errorCode:8250,errorMessage:"产品类型不在指定范围内"},GIZ_SDK_LOG_LEVEL_INVALID:{errorCode:8009,errorMessage:"产品类型不在指定范围内"},GIZ_SDK_OTA_DEVICE_NOT_SUPPORT:{errorCode:8360,errorMessage:"设备不支持手机OTA升级"},GIZ_SDK_OTA_DEVICE_BUSY_IN_UPGRADE:{errorCode:8354,errorMessage:"设备忙,固件正在升级"},GIZ_SDK_OTA_FIRMWARE_DOWNLOAD_FAILED:{errorCode:8353,errorMessage:"固件下载失败"},GIZ_SDK_OTA_FIRMWARE_TYPE_NOT_MATCH:{errorCode:8361,errorMessage:"蓝牙OTA设备返回的固件类型与当前要升级的固件类型不匹配"}}},function(e,t,i){var n,s,r,a,o,c,l,u;e.exports=(u=i(0),i(24),i(17),s=(n=u).lib,r=s.Base,a=s.WordArray,o=n.algo,c=o.MD5,l=o.EvpKDF=r.extend({cfg:r.extend({keySize:4,hasher:c,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var i,n=this.cfg,s=n.hasher.create(),r=a.create(),o=r.words,c=n.keySize,l=n.iterations;o.length<c;){i&&s.update(i),i=s.update(e).finalize(t),s.reset();for(var u=1;u<l;u++)i=s.finalize(i),s.reset();r.concat(i)}return r.sigBytes=4*c,r}}),n.EvpKDF=function(e,t,i){return l.create(i).compute(e,t)},u.EvpKDF)},function(e,t,i){var n,s,r;e.exports=(r=i(0),s=(n=r).lib.WordArray,n.enc.Base64={stringify:function(e){var t=e.words,i=e.sigBytes,n=this._map;e.clamp();for(var s=[],r=0;r<i;r+=3)for(var a=(t[r>>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;o<4&&r+.75*o<i;o++)s.push(n.charAt(a>>>6*(3-o)&63));var c=n.charAt(64);if(c)for(;s.length%4;)s.push(c);return s.join("")},parse:function(e){var t=e.length,i=this._map,n=this._reverseMap;if(!n){n=this._reverseMap=[];for(var r=0;r<i.length;r++)n[i.charCodeAt(r)]=r}var a=i.charAt(64);if(a){var o=e.indexOf(a);-1!==o&&(t=o)}return function(e,t,i){for(var n=[],r=0,a=0;a<t;a++)if(a%4){var o=i[e.charCodeAt(a-1)]<<a%4*2,c=i[e.charCodeAt(a)]>>>6-a%4*2,l=o|c;n[r>>>2]|=l<<24-r%4*8,r++}return s.create(n,r)}(e,t,n)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},r.enc.Base64)},function(e,t,i){var n;e.exports=(n=i(0),function(e){var t=n,i=t.lib,s=i.WordArray,r=i.Hasher,a=t.algo,o=[];!function(){for(var t=0;t<64;t++)o[t]=4294967296*e.abs(e.sin(t+1))|0}();var c=a.MD5=r.extend({_doReset:function(){this._hash=new s.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,t){for(var i=0;i<16;i++){var n=t+i,s=e[n];e[n]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8)}var r=this._hash.words,a=e[t+0],c=e[t+1],f=e[t+2],p=e[t+3],v=e[t+4],g=e[t+5],y=e[t+6],_=e[t+7],D=e[t+8],m=e[t+9],b=e[t+10],S=e[t+11],w=e[t+12],I=e[t+13],B=e[t+14],A=e[t+15],k=r[0],C=r[1],E=r[2],T=r[3];k=l(k,C,E,T,a,7,o[0]),T=l(T,k,C,E,c,12,o[1]),E=l(E,T,k,C,f,17,o[2]),C=l(C,E,T,k,p,22,o[3]),k=l(k,C,E,T,v,7,o[4]),T=l(T,k,C,E,g,12,o[5]),E=l(E,T,k,C,y,17,o[6]),C=l(C,E,T,k,_,22,o[7]),k=l(k,C,E,T,D,7,o[8]),T=l(T,k,C,E,m,12,o[9]),E=l(E,T,k,C,b,17,o[10]),C=l(C,E,T,k,S,22,o[11]),k=l(k,C,E,T,w,7,o[12]),T=l(T,k,C,E,I,12,o[13]),E=l(E,T,k,C,B,17,o[14]),k=u(k,C=l(C,E,T,k,A,22,o[15]),E,T,c,5,o[16]),T=u(T,k,C,E,y,9,o[17]),E=u(E,T,k,C,S,14,o[18]),C=u(C,E,T,k,a,20,o[19]),k=u(k,C,E,T,g,5,o[20]),T=u(T,k,C,E,b,9,o[21]),E=u(E,T,k,C,A,14,o[22]),C=u(C,E,T,k,v,20,o[23]),k=u(k,C,E,T,m,5,o[24]),T=u(T,k,C,E,B,9,o[25]),E=u(E,T,k,C,p,14,o[26]),C=u(C,E,T,k,D,20,o[27]),k=u(k,C,E,T,I,5,o[28]),T=u(T,k,C,E,f,9,o[29]),E=u(E,T,k,C,_,14,o[30]),k=d(k,C=u(C,E,T,k,w,20,o[31]),E,T,g,4,o[32]),T=d(T,k,C,E,D,11,o[33]),E=d(E,T,k,C,S,16,o[34]),C=d(C,E,T,k,B,23,o[35]),k=d(k,C,E,T,c,4,o[36]),T=d(T,k,C,E,v,11,o[37]),E=d(E,T,k,C,_,16,o[38]),C=d(C,E,T,k,b,23,o[39]),k=d(k,C,E,T,I,4,o[40]),T=d(T,k,C,E,a,11,o[41]),E=d(E,T,k,C,p,16,o[42]),C=d(C,E,T,k,y,23,o[43]),k=d(k,C,E,T,m,4,o[44]),T=d(T,k,C,E,w,11,o[45]),E=d(E,T,k,C,A,16,o[46]),k=h(k,C=d(C,E,T,k,f,23,o[47]),E,T,a,6,o[48]),T=h(T,k,C,E,_,10,o[49]),E=h(E,T,k,C,B,15,o[50]),C=h(C,E,T,k,g,21,o[51]),k=h(k,C,E,T,w,6,o[52]),T=h(T,k,C,E,p,10,o[53]),E=h(E,T,k,C,b,15,o[54]),C=h(C,E,T,k,c,21,o[55]),k=h(k,C,E,T,D,6,o[56]),T=h(T,k,C,E,A,10,o[57]),E=h(E,T,k,C,y,15,o[58]),C=h(C,E,T,k,I,21,o[59]),k=h(k,C,E,T,v,6,o[60]),T=h(T,k,C,E,S,10,o[61]),E=h(E,T,k,C,f,15,o[62]),C=h(C,E,T,k,m,21,o[63]),r[0]=r[0]+k|0,r[1]=r[1]+C|0,r[2]=r[2]+E|0,r[3]=r[3]+T|0},_doFinalize:function(){var t=this._data,i=t.words,n=8*this._nDataBytes,s=8*t.sigBytes;i[s>>>5]|=128<<24-s%32;var r=e.floor(n/4294967296),a=n;i[15+(s+64>>>9<<4)]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),i[14+(s+64>>>9<<4)]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),t.sigBytes=4*(i.length+1),this._process();for(var o=this._hash,c=o.words,l=0;l<4;l++){var u=c[l];c[l]=16711935&(u<<8|u>>>24)|4278255360&(u<<24|u>>>8)}return o},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});function l(e,t,i,n,s,r,a){var o=e+(t&i|~t&n)+s+a;return(o<<r|o>>>32-r)+t}function u(e,t,i,n,s,r,a){var o=e+(t&n|i&~n)+s+a;return(o<<r|o>>>32-r)+t}function d(e,t,i,n,s,r,a){var o=e+(t^i^n)+s+a;return(o<<r|o>>>32-r)+t}function h(e,t,i,n,s,r,a){var o=e+(i^(t|~n))+s+a;return(o<<r|o>>>32-r)+t}t.MD5=r._createHelper(c),t.HmacMD5=r._createHmacHelper(c)}(Math),n.MD5)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=e=>new Promise(t=>setTimeout(()=>t(),e))},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(4),s=i(0);function r(e){return Array.prototype.map.call(new Uint8Array(e),(function(e){return("00"+e.toString(16)).slice(-2)})).join("")}t.ab2hex=r,t.compareWXSDKVersion=function(e,t){const i=e.split("."),n=t.split("."),s=Math.max(e.length,t.length);for(;i.length<s;)i.push("0");for(;n.length<s;)n.push("0");for(let i=0;i<s;i++){const n=parseInt(e[i]),s=parseInt(t[i]);if(n>s)return 1;if(n<s)return-1}return 0},t.isError=e=>null!=e&&"symbol"==typeof e.errorCode,t.wrapErrorInfo=e=>({errorCode:e,errorMessage:e}),t.unionBy=(e,t)=>e.reduce((e,i)=>{const n=i[t];return e.some(e=>e[t]===n)||e.push(i),e},[]),t.isWXDevicesResult=function(e){return e.success&&"[object Array]"===Object.prototype.toString.call(e.bleDevices)},t.str2Buf=function(e){var t=e.length,i=new ArrayBuffer(t+2),n=new DataView(i);for(let i=0;i<t;i++)n.setUint8(i,parseInt(e[i],16));return i},t.numberArray2Uint8Array=e=>{const t=new ArrayBuffer(e.length),i=new Uint8Array(t);for(let n=0;n<t.byteLength;n++)i[n]=e[n];return i};function a(e){if(25!=(e=e.slice(0,25)).length)throw new Error("数据不合法");const t=`${c(e[0])}${c(e[1])}`;if(e[2]!==(255&e.slice(3).reduce((e,t)=>e+t,0)))throw new Error("校验和不合法");const i=c(e[3]),n=e.slice(5,5+e[4]).map(e=>c(e));return{mac:t,cmd:parseInt(i,16),data:n}}function o(e){return Array.prototype.map.call(new Uint8Array(e),(function(e){return e}))}function c(e,t=2){return`${new Array(t).fill(0).join("")}${e.toString(16)}`.slice(-t)}t.advertisData2PkAndMac=(e,t)=>e&&e.byteLength>=22&&e.byteLength<=24?Object.assign(Object.assign({},((e,t)=>{let i=e.slice(e.byteLength-16),n=e.slice(0,e.byteLength-16),s=r(i);if(t.find(e=>e===s)){const e=r(n);return{productKey:s,mac:e}}{i=e.slice(0,16),n=e.slice(16),s=r(i);const t=r(n);return{productKey:s,mac:t}}})(e,t)),{bleWorkStatus:1}):e&&e.byteLength>24?((e,t)=>{if(!e||0===e.byteLength)return{bleWorkStatus:0,mac:"",productKey:""};let i=0,n="",s="",a=1;const o=new Uint8Array(e);for(;!(i>e.byteLength-1);){const c=o[i];if(c<=0||!c)break;if(e.byteLength<c+i+1)break;const l=e.slice(i+1,i+c+1);if(c>=6&&c<=8&&(n=r(l),16==n.length&&(n=n.substring(0,15))),16==c){const e=r(l).toLowerCase();t.find(t=>t===e)&&(s=e)}1==c&&(a=new Uint8Array(l)[0]),i+=1+c}return{bleWorkStatus:a,mac:n,productKey:s}})(e,t):{mac:"",productKey:"",bleWorkStatus:1},t.isSameDevice=(e,t)=>e.mac.toLocaleLowerCase()===t.mac.toLocaleLowerCase()&&e.productKey===t.productKey,t.merageBleLocalDevices=(e,i)=>(e.map(e=>{e.isBleOnline=!1,e.bleWorkStatus=0}),i.map(i=>{const n=e.find(e=>t.isSameDevice(e,i));n?(n.isBleOnline=!0,n.bleDeviceID=i.bleDeviceID,n.connectType=i.connectType,n.bleWorkStatus=i.bleWorkStatus):e.push(i)}),e),t.merageLanLocalDevices=(e,i)=>(e.map(e=>{e.isLanOnline=!1}),i.map(i=>{const n=e.find(e=>t.isSameDevice(e,i));n?n.isLanOnline=!0:e.push(i)}),e),t.BTDevice2GDevice=(e,i)=>{let s={productKey:"",mac:"",bleWorkStatus:0},r={did:"",productKey:"",mac:"",bleWorkStatus:0,connectType:"NONE",isBleOnline:!0,isLanOnline:!1,isOnline:!1,name:e.name,isBind:!1,bleDeviceID:e.deviceId,ctime:(new Date).getTime(),RSSI:e.RSSI};switch(e.communicationType){case"BLE_BROADCAST":try{n.default.log("parse BLE_BROADCAST");const t=a(o(e.advertisData));s.productKey=t.data.join(""),s.mac=t.mac,r.connectType="BLE_BROADCAST"}catch(e){}break;default:s=t.advertisData2PkAndMac(e.advertisData,i)}return r=Object.assign(Object.assign({},r),s),r},t.getFirstConnectType=(e,t)=>{if(!t)return e.isLanOnline?"LAN":e.isBleOnline?"BLE":"WAN";if("WAN"===t)return"WAN";switch(t){case"BLE":return e.isBleOnline?"BLE":"NONE";case"LAN":return e.isLanOnline?"LAN":"NONE"}return"WAN"},t.getProductInfoThroughPK=(e,t)=>t.find(t=>t.productKey===e),t.mergeObject=(e,t)=>{for(let i in t)null!=t[i]&&""!==t[i]&&(e[i]=t[i]);return e},t.hex2ab=function(e){const t=[];for(let n=0;n<e.length;n+=2){var i=e.slice(n,n+2);t.push(parseInt(i,16))}return new Uint8Array(t)},t.parseBroadcastData=a,t.ab2numbers=o;let l=0;function u(e,t){let i=1,n=t;return e.map(e=>{const t=65535&(e^n);return n=i-t&65535,i<<=1,c(t,4)})}function d(e,t,i){if(i.length>22)throw new Error("最大长度为22");const s=[...i,...new Array(22-i.length).fill(0)],r=255&i.reduce((e,t)=>e+t,0),a=(t>>4<<12)+(r>>4<<8)+((15&t)<<4)+(15&r),o=Array.from({length:11},(e,t)=>(s[2*t]<<8)+s[2*t+1]);return n.default.log("明文",c(e,4),c((t<<8)+r,4),o.map(e=>c(e,4))),[c(e,4),c((t<<8)+r,4),...u(o,a)].map(e=>`${e.slice(2)}${e.slice(0,2)}`)}t.encrypt=u,t.convertToServiceUuids=({len:e=null,data:i=null,index:n=0,mac:s})=>{const r=null==e?Math.round(18*Math.random())+1:e,a=null==i?Array.from({length:r},e=>Math.round(255*Math.random())):i,o=[147,r,...a],c=d(s,(()=>{const e=l;return l=l+1&255,e})(),o);return[...new Set(c)].length!==c.length?t.convertToServiceUuids({len:r,data:a,index:n++,mac:s}):c},t.convertToUuids=d,t.arrayBufferToWordArray=function(e){for(var t=[],i=new Uint8Array(e),n=0;n<i.length;n+=4){var r=i[n]<<24|i[n+1]<<16|i[n+2]<<8|i[n+3];t.push(r)}return s.lib.WordArray.create(t,i.length)}},function(e,t,i){var n;e.exports=(n=i(0),i(13),i(39),i(40),i(7),i(41),i(8),i(24),i(16),i(42),i(25),i(43),i(44),i(45),i(17),i(46),i(6),i(2),i(47),i(48),i(49),i(50),i(51),i(52),i(53),i(54),i(55),i(56),i(57),i(58),i(59),i(60),i(61),i(62),i(63),n)},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(18),r=i(15),a=i(5);t.default=(e,t,i=!0)=>n(void 0,void 0,void 0,(function*(){const n=Object.assign({},t),o={"Content-Type":"application/json","X-Gizwits-Application-Id":r.getGlobalData("appID")};i&&(o["X-Gizwits-User-token"]=r.getGlobalData("token")),n.header=Object.assign(Object.assign({},o),t.headers),delete n.headers;const c=r.getGlobalData("cloudServiceInfo").openAPIInfo,l=yield s.default("https://"+c+e,n);if(l.statusCode>=200&&l.statusCode<300)return{success:!0,data:l.data};let u={success:!1,err:{errorCode:a.default.GIZ_SDK_HTTP_REQUEST_FAILED.errorCode,errorMessage:""}};try{u={success:!1,err:{errorCode:l.data.error_code,errorMessage:l.data.error_message}}}catch(e){}return u}))},function(e,t,i){var n,s,r,a,o,c;e.exports=(c=i(0),s=(n=c).lib,r=s.Base,a=s.WordArray,(o=n.x64={}).Word=r.extend({init:function(e,t){this.high=e,this.low=t}}),o.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:8*e.length},toX32:function(){for(var e=this.words,t=e.length,i=[],n=0;n<t;n++){var s=e[n];i.push(s.high),i.push(s.low)}return a.create(i,this.sigBytes)},clone:function(){for(var e=r.clone.call(this),t=e.words=this.words.slice(0),i=t.length,n=0;n<i;n++)t[n]=t[n].clone();return e}}),c)},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(12);const r=new class{constructor(){this.data={},this.key="dataPointConfig",this.init=()=>n(this,void 0,void 0,(function*(){const e=(yield wx.getStorageSync(this.key))||"{}";let t={};try{t=JSON.parse(e)}catch(e){}this.data=t})),this.getConfigFile=e=>n(this,void 0,void 0,(function*(){var t;if(!this.data[e]){const i=`/app/datapoint?product_key=${e}`,n=yield s.default(`${i}`,{method:"GET"});if(!n.success||!(null===(t=n.data)||void 0===t?void 0:t.entities))return null;this.data[e]=n.data,wx.setStorageSync(this.key,JSON.stringify(this.data))}return this.data[e]})),this.getAttrItem=(e,t)=>n(this,void 0,void 0,(function*(){this.data[e]||(yield this.getConfigFile(e));for(let i in this.data[e].entities[0].attrs){const n=this.data[e].entities[0].attrs[i];if(n.name===t)return n}return null}))}};r.init(),t.default=r},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n={};t.setGlobalData=function(e,t){n[e]=t},t.getGlobalData=function(e){return n[e]}},function(e,t,i){var n;e.exports=(n=i(0),function(e){var t=n,i=t.lib,s=i.WordArray,r=i.Hasher,a=t.algo,o=[],c=[];!function(){function t(t){for(var i=e.sqrt(t),n=2;n<=i;n++)if(!(t%n))return!1;return!0}function i(e){return 4294967296*(e-(0|e))|0}for(var n=2,s=0;s<64;)t(n)&&(s<8&&(o[s]=i(e.pow(n,.5))),c[s]=i(e.pow(n,1/3)),s++),n++}();var l=[],u=a.SHA256=r.extend({_doReset:function(){this._hash=new s.init(o.slice(0))},_doProcessBlock:function(e,t){for(var i=this._hash.words,n=i[0],s=i[1],r=i[2],a=i[3],o=i[4],u=i[5],d=i[6],h=i[7],f=0;f<64;f++){if(f<16)l[f]=0|e[t+f];else{var p=l[f-15],v=(p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3,g=l[f-2],y=(g<<15|g>>>17)^(g<<13|g>>>19)^g>>>10;l[f]=v+l[f-7]+y+l[f-16]}var _=n&s^n&r^s&r,D=(n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22),m=h+((o<<26|o>>>6)^(o<<21|o>>>11)^(o<<7|o>>>25))+(o&u^~o&d)+c[f]+l[f];h=d,d=u,u=o,o=a+m|0,a=r,r=s,s=n,n=m+(D+_)|0}i[0]=i[0]+n|0,i[1]=i[1]+s|0,i[2]=i[2]+r|0,i[3]=i[3]+a|0,i[4]=i[4]+o|0,i[5]=i[5]+u|0,i[6]=i[6]+d|0,i[7]=i[7]+h|0},_doFinalize:function(){var t=this._data,i=t.words,n=8*this._nDataBytes,s=8*t.sigBytes;return i[s>>>5]|=128<<24-s%32,i[14+(s+64>>>9<<4)]=e.floor(n/4294967296),i[15+(s+64>>>9<<4)]=n,t.sigBytes=4*i.length,this._process(),this._hash},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=r._createHelper(u),t.HmacSHA256=r._createHmacHelper(u)}(Math),n.SHA256)},function(e,t,i){var n,s,r,a;e.exports=(n=i(0),r=(s=n).lib.Base,a=s.enc.Utf8,void(s.algo.HMAC=r.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=a.parse(t));var i=e.blockSize,n=4*i;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var s=this._oKey=t.clone(),r=this._iKey=t.clone(),o=s.words,c=r.words,l=0;l<i;l++)o[l]^=1549556828,c[l]^=909522486;s.sigBytes=r.sigBytes=n,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher,i=t.finalize(e);return t.reset(),t.finalize(this._oKey.clone().concat(i))}})))},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){return new Promise((i,n)=>{wx.request(Object.assign(Object.assign({url:e,timeout:3e3},t),{success:e=>{i(e)},fail:e=>{n(e)}}))})}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(4),r=i(9);function a(e,t){return new Promise((i,n)=>{wx.createBLEConnection({deviceId:e,timeout:t,success:e=>i(e),fail:e=>{-1===e.errCode?i(e):n(e)}})})}function o(e,t,i,n){return new Promise(s=>{wx.writeBLECharacteristicValue({deviceId:e,serviceId:t,characteristicId:i,value:n,complete:s})})}t.retryConnect=function(e,t=1e4){return n(this,void 0,void 0,(function*(){let i={success:!1};for(let n=0;n<5;n++)try{return console.debug("start createBLEConnection"),yield a(e,t)}catch(e){i=e,console.debug("createBLEConnection error retry"),yield r.default(1e3)}return i}))},t.openBluetoothAdapter=function(){return new Promise((e,t)=>{wx.openBluetoothAdapter({success:e,fail:t})})},t.closeBluetoothAdapter=function(){return new Promise((e,t)=>{wx.closeBluetoothAdapter({success:e,fail:t})})},t.getBluetoothAdapterState=function(){return new Promise((e,t)=>{wx.getBluetoothAdapterState({success:e,fail:t})})},t.startBluetoothDevicesDiscovery=function(e=!0){return new Promise((t,i)=>{wx.startBluetoothDevicesDiscovery({success:t,fail:i,allowDuplicatesKey:e,powerLevel:"high",interval:200})})},t.getBluetoothDevices=function(){return new Promise((e,t)=>{wx.getBluetoothDevices({success:({devices:t})=>e(t),fail:t})})},t.createBLEConnection=a,t.getBLEDeviceServices=function(e){return new Promise((t,i)=>{wx.getBLEDeviceServices({deviceId:e,success:({services:e})=>t(e),fail:i})})},t.getBLEDeviceCharacteristics=function(e,t){return new Promise((i,n)=>{wx.getBLEDeviceCharacteristics({deviceId:e,serviceId:t,success:({characteristics:e})=>i(e),fail:n})})},t.notifyBLECharacteristicValueChange=function(e,t,i,n=!0){return new Promise((s,r)=>{wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:t,characteristicId:i,state:n,success:s,fail:r})})},t.writeBLECharacteristicValue=o;const c=[];let l=!1;let u=0;t.unpackWriteBLECharacteristicValue=function(e,t,i,a){if(!a||0===a.byteLength)return Promise.reject(new Error("value is empty"));const d=a.byteLength;return Math.ceil(d/20),new Promise((h,f)=>{c.push({task:()=>n(this,void 0,void 0,(function*(){let n=0,c=d,l={errCode:0,errMsg:"ok"},u=0;for(;c>0;){yield r.default(30);const d=a.slice(n,n+20);if(n+=20,c-=20,l=yield o(e,t,i,d),s.default.log("unpackWriteBLECharacteristicValue",u+1,l),0!==l.errCode)break;u++}0!==l.errCode?f(l):h(l)})),resolve:h,reject:f}),function(){n(this,void 0,void 0,(function*(){if(!l&&0!==c.length){for(l=!0;c.length>0;){const e=c.shift();if(!e)continue;const t=Date.now()-u;if(t<500){const e=500-t;yield r.default(e)}try{yield e.task(),u=Date.now()}catch(t){e.reject(t)}}l=!1}}))}()})},t.downloadFile=function({url:e}){return n(this,void 0,void 0,(function*(){return new Promise((t,i)=>{wx.downloadFile({url:e,success(e){t(e)},fail(e){i(e)}})})}))}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(1),s=i(3);class r extends n.default{constructor(e){super(e)}}r.pack=(e,t)=>{const i=[],[n,r]=s.formatCodesFromStr(e),[a,o]=s.formatCodesFromStr(t),c=[0].concat([0,1],r,n,o,a);let l=c.length;for(;l>0;)i.push(l),l-=255;const u=[0,0,0,3].concat(i).concat(c),d=new ArrayBuffer(u.length),h=new Uint8Array(d);for(let e=0;e<d.byteLength;e++)h[e]=u[e];return h},t.default=r},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(9),r=i(5),a=i(33),o=i(4);t.default=class{constructor(e,t,i,c){this.ssid="",this.password="",this.specialProductKeys=[],this.disableSearchDevice=!1,this.specialProductKeySecrets=[],this.timeoutHandler=null,this.setDeviceOnboardingDeployRej=()=>{},this.cleanTimeout=()=>{this.disableSearchDevice=!0,this.timeoutHandler&&clearTimeout(this.timeoutHandler),this.timeoutHandler=null},this.stopDeviceOnboardingDeploy=()=>{this.setDeviceOnboardingDeployRej&&this.setDeviceOnboardingDeployRej({success:!1,err:r.default.GIZ_SDK_ONBOARDING_STOPPED}),this.cleanTimeout()},this.hasTimeoutHandler=e=>!!this.timeoutHandler&&(e&&e({success:!1,err:r.default.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING}),!0),this.handleTimeout=()=>{this.setDeviceOnboardingDeployRej&&this.setDeviceOnboardingDeployRej({success:!1,err:{errorCode:r.default.CONFIG_TIME_OUT,errorMessage:"time out"}}),this.timeoutHandler=null},this.searchDevice=({ssid:e,password:t})=>new Promise((i,c)=>{o.default.debug("GIZ_SDK: 开始大循环搜索设备");const l=()=>n(this,void 0,void 0,(function*(){var n;if(this.hasTimeoutHandler())try{const u=yield a.checkDeviceRegister({SSID:e,password:t,productKeys:this.specialProductKeys});if((null===(n=u.err)||void 0===n?void 0:n.errorCode)===r.default.GIZ_OPENAPI_TOKEN_INVALID.errorCode)return void c({success:!1,err:r.default.GIZ_OPENAPI_TOKEN_INVALID});u.err||0===u.data.length?(o.default.debug("GIZ_SDK: 大循环没有发现设备"),yield s.default(1500),!this.disableSearchDevice&&l()):(o.default.debug("GIZ_SDK: 大循环搜索到设备",u),i({success:!0,data:u.data}))}catch(e){yield s.default(3e3),!this.disableSearchDevice&&l()}}));l()}),this.initDeviceOnboardingDeploy=(e,t)=>{this.setDeviceOnboardingDeployRej=e,this.disableSearchDevice=!1},this.startTimeoutTimer=e=>{this.timeoutHandler=setTimeout(this.handleTimeout,1e3*e)},this.bindDevices=e=>(o.default.log("GIZ_SDK: start bind device"),new Promise((t,i)=>n(this,void 0,void 0,(function*(){const n=e.map(e=>{const t=this.specialProductKeys.findIndex(t=>e.productKey===t);if(-1===t)return;const i=this.specialProductKeySecrets[t];return a.bindMac({mac:e.mac,productKey:e.productKey,productSecret:i})});try{const s=yield Promise.all(n),a=e.filter((e,t)=>{const i=s[t];return i&&i.success});a.length>0?(o.default.log("GIZ_SDK: bind device success",a),t({success:!0,data:a})):(o.default.log("GIZ_SDK: bind device error",s),i({success:!1,data:e,err:r.default.GIZ_SDK_BIND_DEVICE_FAILED}))}catch(e){i(e)}})))),this.ssid=e,this.password=t,this.specialProductKeys=i,this.specialProductKeySecrets=c}}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__rest||function(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(e);s<n.length;s++)t.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(e,n[s])&&(i[n[s]]=e[n[s]])}return i};Object.defineProperty(t,"__esModule",{value:!0});const r=i(10),a=i(19),o=i(26),c=i(3),l=i(1),u=i(64),d=i(27),h=i(65),f=i(28),p=i(4),v=i(29),g=i(9),y=i(66),_=i(5),D=i(67),m=i(68),b=i(69),S=i(70),w=i(11),I=i(31),B=i(80),A=i(81),k=i(82);class C extends v.default{constructor({pks:e=[],bleHandleParams:t={serviceUUIDSuffix:"fe60",serviceUUIDSuffix2:"abf0",characteristicUUIDSuffix:"fe61"},offlineThreshold:i}){super(),this.connectedList=[],this.connectingDevId=null,this.pks=[],this.listenDevOfflineTimer=null,this.listenBluetoothDeviceFoundNoneTimer=null,this.MAX_BLE_SCAN_INVERTER=299999,this.startScanParams=null,this.isScanning=!1,this.boradcastDataCache={},this.baseServices=[],this.tmpBleData="",this.tmpDataNum=0,this.disableScanFlag=!1,this.peripheralServer=null,this.isActive=!0,this.otaSessionMap={},this.scanList=[],this.onBluetoothAdapterStateChange=e=>{p.default.debug("onBluetoothAdapterStateChange",e),e.available||(this.scanList=[],this.notifyDevices())},this.onAppShow=()=>{this.isActive=!0,this.scanList.map(e=>{e.ctime=Date.now()})},this.onAppHide=()=>{this.isActive=!1},this.listenDevOffline=e=>{this.listenDevOfflineTimer=setInterval(()=>{if(!this.isActive)return;const t=(new Date).getTime(),i=this.scanList.filter(i=>{const n=this.connectedList.find(e=>i.bleDeviceID==e.deviceId),s=this.connectingDevId===i.bleDeviceID;return!(!n&&!s)||("BLE_BROADCAST"===i.connectType?t-i.ctime<2*e:t-i.ctime<e)});if(i.length!==this.scanList.length){const e=this.scanList.filter(e=>!i.find(t=>r.isSameDevice(t,e)));p.default.warn("timestamp:",t,"\n","BLE devices offline:",e),this.scanList=i,this.notifyDevices()}},500)},this.openBluetoothAdapter=(e="central")=>new Promise((t,i)=>{wx.openBluetoothAdapter({mode:e,success:()=>{t({success:!0}),wx.onBLECharacteristicValueChange(this.handleOnBLECharacteristicValueChange)},fail:e=>{p.default.error("openBluetoothAdapter fail",new Error(JSON.stringify(e))),this.notifyError({errMsg:e.errMsg,errCode:-1}),i({success:!1,err:e})}})}),this.getProtocolBase=({device:e,hexString:t,curDeviceValue:i})=>{const n=c.hexStrint2byte(t);if("67a95f560e464453be079c5723a4a85c"===e.productKey||"0b58c73f12064eb897aa005cf43d6a1b"===e.productKey||"4b286229884f4711bcdbaefdfb5f76b9"===e.productKey){const e=new u.default(n);return{data:e,needWaitLen:e.len-i.byteLength}}const s=new l.default(n);return{data:s,needWaitLen:s.len-i.byteLength+4+Math.ceil(s.len.toString(2).length/8)}},this.handleOnBLECharacteristicValueChange=e=>n(this,void 0,void 0,(function*(){if(!e.value)return;const t=this.scanList.find(t=>t.bleDeviceID===e.deviceId);if(t){const i=r.ab2hex(e.value);try{const{needWaitLen:n}=this.getProtocolBase({device:t,hexString:i,curDeviceValue:e.value});this.tmpBleData=i,this.tmpDataNum=n}catch(t){this.tmpBleData&&(this.tmpBleData+=i,this.tmpDataNum-=e.value.byteLength)}if(this.tmpDataNum>0||!this.tmpBleData)return;this.notiDeviceDataToSdk(e,this.tmpBleData),this.tmpBleData="",this.tmpDataNum=0}else p.default.info("GIZ_SDK: 没有找到设备",e)})),this.notiDeviceDataToSdk=(e,t)=>{this.listenerMap.GizBleDeviceData&&this.listenerMap.GizBleDeviceData.map(i=>{i(e,t)})},this.notifyError=e=>{this.listenerMap.GizBleError&&this.listenerMap.GizBleError.map(t=>{t(e)})},this.notifyDevices=()=>{this.listenerMap.GizBleDeviceList&&this.listenerMap.GizBleDeviceList.map(e=>{e(this.scanList)})},this.listenConnection=()=>{wx.onBLEConnectionStateChange(e=>{if(!1===e.connected){const t=this.connectedList.findIndex(t=>t.deviceId===e.deviceId);-1!==t&&(this.connectedList.splice(t,1),this.notifyDevices())}})},this.init=()=>n(this,void 0,void 0,(function*(){const{platform:e}=wx.getSystemInfoSync();yield this.openBluetoothAdapter(),"ios"===e&&(yield this.openBluetoothAdapter("peripheral"));let t=!0;try{this.peripheralServer=(yield wx.createBLEPeripheralServer()).server,p.default.info("GIZ_SDK: 广播初始化成功",this.peripheralServer)}catch(e){p.default.error("GIZ_SDK: 广播初始化失败",new Error(JSON.stringify(e))),t=!1}if("android"===e&&!1===t)return{success:!1,message:"安卓设备:GIZ_SDK初始化蓝牙广播失败"};return yield this.getBluetoothAdapterState()})),this.checkPermission=()=>n(this,void 0,void 0,(function*(){if((yield wx.getSetting()).authSetting["scope.bluetooth"])return yield this.init();try{return yield wx.authorize({scope:"scope.bluetooth"}),yield this.init()}catch(e){p.default.log("授权失败",e),this.openBluetoothAdapter(),this.notifyError({errMsg:e.errMsg,errCode:-1})}})),this.getBluetoothAdapterState=()=>n(this,void 0,void 0,(function*(){p.default.log("getBluetoothAdapterState",yield wx.getBluetoothAdapterState());const e=yield wx.getBluetoothAdapterState(),{errMsg:t,available:i}=e,n=s(e,["errMsg","available"]);return{data:Object.assign({},n),err:r.wrapErrorInfo(t),success:i}})),this.getDeviceStatus=(e,t,i,s)=>n(this,void 0,void 0,(function*(){const n=yield h.default.pack(t,i,s);return n?yield this.write(e,r.numberArray2Uint8Array(n).buffer):{success:!1}})),this.updateDevice=e=>{const t=e.bleDeviceID,i=this.scanList.findIndex(e=>t==e.bleDeviceID);-1!==i&&(this.scanList[i]=e)},this.updateCtime=e=>{const t=e.deviceId,i=this.scanList.findIndex(e=>t==e.bleDeviceID);-1!==i&&(this.scanList[i].ctime=Date.now())},this.checkDeviceIsChange=(e,t)=>e.bleWorkStatus!==t.bleWorkStatus||e.name!==t.name||e.isBleOnline!==t.isBleOnline||e.isOnline!==t.isOnline,this.handleBluetoothDeviceFound=(e,t)=>{r.unionBy(e.devices,"deviceId").map(e=>{const{advertisData:i,deviceId:n,name:s,localName:a}=e,o=r.ab2hex(i);let c=null;try{c=r.parseBroadcastData(r.ab2numbers(i))}catch(e){}const l=this.scanList.find(e=>e.bleDeviceID===n);if(c&&148===c.cmd){const t=r.ab2hex(i);if(this.boradcastDataCache[n]&&this.boradcastDataCache[n]===t)return!1;if(!l)return!1;this.boradcastDataCache[n]=r.ab2hex(i);const s=f.padBoradcastData(c.data.map(e=>parseInt(e,16)));return this.updateCtime(e),void this.notiDeviceDataToSdk(e,s)}if(c&&25===c.cmd){this.pks.find(e=>e===c.data.join(""))&&(e.communicationType="BLE_BROADCAST")}if(l){const i=r.BTDevice2GDevice(e,this.pks);if(i.productKey&&i.mac){const e=this.checkDeviceIsChange(i,l);i.ctime=Date.now(),l.RSSI=i.RSSI,this.updateDevice(i),e&&t(this.scanList)}}else{if(this.pks.some(e=>o.includes(e))){const i=r.BTDevice2GDevice(e,this.pks);p.default.debug("insert ble device",i),i.productKey&&i.mac&&(this.scanList.push(i),t(this.scanList))}}})},this.listenBluetoothDeviceFoundNone=()=>{this.listenBluetoothDeviceFoundNoneTimer=setInterval(()=>{const e=(new Date).getTime();this.startScanParams&&this.startScanParams.lastStartScanTimestamp&&this.isScanning&&e-this.startScanParams.lastStartScanTimestamp>this.MAX_BLE_SCAN_INVERTER&&!this.disableScanFlag&&(this.stopScan(),this.startScanParams.lastStartScanTimestamp=e,p.default.warn("SDK RESTART SCAN BLE","\n","timestamp:",e),g.default(1e3).then(()=>{this.startScan(this.startScanParams.onScanDevice,this.startScanParams.delay,this.startScanParams.services||null)}))},3e3)},this.startScan=(e,t=5e3,i)=>n(this,void 0,void 0,(function*(){if(this.disableScanFlag)return{scanList:[]};if(!this.startScanParams){const n={onScanDevice:e,delay:t,services:i,lastStartScanTimestamp:(new Date).getTime()};this.startScanParams=n}return this.isScanning=!0,new Promise(s=>n(this,void 0,void 0,(function*(){wx.onBluetoothDeviceFound(t=>{this.handleBluetoothDeviceFound(t,e)}),p.default.debug("GIZ_SDK: start scan",t),yield wx.startBluetoothDevicesDiscovery({services:i||this.baseServices,powerLevel:"high",allowDuplicatesKey:!0,interval:200}),t>0&&setTimeout(()=>{this.stopScan(),s({scanList:this.scanList})},t)})))})),this.stopScan=()=>n(this,void 0,void 0,(function*(){try{return this.isScanning=!1,yield wx.stopBluetoothDevicesDiscovery()}catch(e){return e}})),this.disableScan=()=>n(this,void 0,void 0,(function*(){this.disableScanFlag=!0;const e=yield wx.stopBluetoothDevicesDiscovery();return yield g.default(200),e})),this.enableScan=()=>{this.disableScanFlag=!1},this.connectDevice=e=>n(this,void 0,void 0,(function*(){var t;try{this.connectingDevId=e;try{yield this.disableScan();const t=yield a.retryConnect(e);this.enableScan(),p.default.debug("connect res",t),p.default.debug("===蓝牙连接成功===",(new Date).getTime())}catch(e){if(p.default.error("GIZ_SDK: createBLEConnection error",new Error(JSON.stringify(e))),"createBLEConnection:fail:already connect"!==(null==e?void 0:e.errMsg))return this.notifyError(e),{success:!1,message:null==e?void 0:e.errMsg}}const i=yield wx.getBLEDeviceServices({deviceId:e}).catch(e=>this.notifyError(e)),n=null===(t=null==i?void 0:i.services.find(e=>e.isPrimary&&(e.uuid.toLowerCase().includes(this.serviceUUIDSuffix)||e.uuid.toLowerCase().includes(this.serviceUUIDSuffix2))))||void 0===t?void 0:t.uuid;if(!n)return{message:"can not find valid serviceId",success:!1};const s=null==i?void 0:i.services.find(e=>e.isPrimary&&e.uuid.toLowerCase().includes(this.serviceUUIDSuffix2)),c=yield wx.getBLEDeviceCharacteristics({deviceId:e,serviceId:n}).catch(e=>this.notifyError(e)),l=null==c?void 0:c.characteristics[0].uuid;if(this.connectedList.every(t=>t.deviceId!==e)&&this.connectedList.push({deviceId:e,serviceId:n,characteristicId:l}),yield wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:n,characteristicId:l,state:!0,type:"notification"}).catch(e=>this.notifyError(e)),s){this.write(e,r.numberArray2Uint8Array(o.default.pack()).buffer);const t=yield this.handleBindReq(e);if(p.default.log("handleBindReq",t),t.success){this.write(e,r.numberArray2Uint8Array(d.default.pack({passcode:t.data})).buffer);const i=yield this.handleLoginReq(e).catch(e=>this.notifyError(e));if(null==i?void 0:i.success)return{success:!0,message:"ok"}}return yield wx.closeBLEConnection({deviceId:e}),{success:!1,message:"ok"}}return{success:!0,message:"ok"}}finally{this.connectingDevId=null}})),this.handleWatchBleData=(e,t,i=3e3,s)=>n(this,void 0,void 0,(function*(){return new Promise(n=>{let r=!1,a=null,o=null;const c=e=>{r||(r=!0,a&&(clearTimeout(a),a=null),o&&(this.removeEventListener("GizBleDeviceData",o),o=null),s&&s.cancelHandlers.delete(l),n(e))},l=()=>{c({success:!1,err:_.default.GIZ_SDK_OTA_DEVICE_BUSY_IN_UPGRADE})};if(s){if(s.cancelled)return void l();s.cancelHandlers.add(l)}o=(i,n)=>{if(null==s?void 0:s.cancelled)return void l();if(e!==i.deviceId)return;const r=t(i,n);r&&c({success:!0,data:r})},this.addEventListener("GizBleDeviceData",o),a=setTimeout(()=>{c({success:!1,err:_.default.GIZ_SDK_DEVICE_NO_RESPONSE})},i)})})),this.handleBindReq=e=>new Promise(t=>{const i=(n,s)=>{if(n.deviceId!==e)return;p.default.log("监听蓝牙特征值发生变化");const r=new o.default(c.hexStrint2byte(s));this.removeEventListener("GizBleDeviceData",i),r.passcode?t({success:!0,data:r.passcode}):t({success:!1,data:""})};this.watchBleDevice(e,i)}),this.handleLoginReq=e=>new Promise(t=>{const i=(n,s)=>{if(n.deviceId!==e)return;p.default.log("设备回复LoginReq",s);const r=new d.default(c.hexStrint2byte(s));this.removeEventListener("GizBleDeviceData",i),!0===r.result?t({success:!0,data:r.did}):t({success:!1,data:""})};this.watchBleDevice(e,i)}),this.startUpgrade=({device:e,type:t,onEvent:i,onProgress:s,productKey:o})=>n(this,void 0,void 0,(function*(){i({code:"GizOTAEventPretreatment"});const n=yield this.checkUpdate({device:e,type:t});p.default.warn("检查设备是否有新固件",n);const u=e.bleDeviceID,d=this.createOtaSession(u),h=()=>({success:!1,err:_.default.GIZ_SDK_OTA_DEVICE_BUSY_IN_UPGRADE});try{if(!n.success)return n;const e=n.data.download_url,f=n.data.soft_ver;i({code:"GizOTAEventDownload"});let v="";try{v=(yield a.downloadFile({url:e})).tempFilePath}catch(e){return p.default.error("固件下载失败",e),{success:!1,err:_.default.GIZ_SDK_OTA_FIRMWARE_DOWNLOAD_FAILED}}if(p.default.warn("下载固件成功",v),d.cancelled)return p.default.warn("检测到 OTA 会话被抢占,停止继续处理"),h();i({code:"GizOTAEventTransmit"});const y=(e,t)=>{const i=c.hexStrint2byte(t);switch(new l.default(i).cmd){case"0042":return new m.default(i)}return null},D=(e,t)=>{const i=c.hexStrint2byte(t);switch(new l.default(i).cmd){case"0044":return new b.default(i)}return null},C=(e,t)=>{const i=c.hexStrint2byte(t);switch(new l.default(i).cmd){case"0052":return new S.default(i)}return null};if(p.default.warn("查询设备是否可以OTA"),d.cancelled)return h();const E=m.default.pack(t);if(yield this.write(u,r.numberArray2Uint8Array(E).buffer),d.cancelled)return h();const T=yield this.handleWatchBleData(u,y,3e3,d);if(p.default.warn("设备回复是否可以OTA",T),!T.success)return T;if(T.data.type!==t)return p.default.error(null,new Error("OTA类型不匹配")),{success:!1,err:_.default.GIZ_SDK_OTA_FIRMWARE_TYPE_NOT_MATCH};if(0!==T.data.state)return h();const P=wx.getFileSystemManager();let O=[];try{O=yield P.readFileSync(v,"hex",0)}catch(e){return p.default.error("读取固件失败",e),{success:!1,err:_.default.GIZ_SDK_OTA_FIRMWARE_DOWNLOAD_FAILED}}if(d.cancelled)return h();const L=O.match(/.{1,2}/g).map((function(e){return parseInt(e,16)})),x=r.arrayBufferToWordArray(L),M=w.MD5(x).toString(),K=I.crc32(L),H=b.default.pack(o,f,M,L.length,K);if(yield this.write(u,r.numberArray2Uint8Array(H).buffer),d.cancelled)return h();const R=yield this.handleWatchBleData(u,D,5e3,d);if(p.default.warn("设备回复ota 预请求",R),!R.success)return R;if(0!==R.data.state)return{success:!1};let N=0;if(R.data.processedLen>0){I.crc32(L.slice(0,R.data.processedLen)).toString(16)===R.data.processedCrc32?(N=R.data.processedLen,p.default.warn(`断点续传,从 ${N} 开始`)):(p.default.warn("从位置0开始OTA"),yield this.write(u,r.numberArray2Uint8Array(B.default.pack(0)).buffer),yield g.default(100))}const U=L.length,G=R.data.packageMaxLen;let j=Math.ceil(N/G),Z=0;for(;N<U;){if(d.cancelled)return p.default.warn("OTA 会话被新的请求打断,终止数据发送"),h();const e=L.slice(N,N+G),t=A.default.pack(e,j);if(yield this.write(u,r.numberArray2Uint8Array(t).buffer),d.cancelled)return p.default.warn("OTA 会话被新的请求打断,终止等待反馈"),h();const i=(e,t)=>{const i=c.hexStrint2byte(t);switch(new l.default(i).cmd){case"0048":{const e=new A.default(i);return e.packageNum===j?e:null}}return null},n=yield this.handleWatchBleData(u,i,5e3,d);let a=!1;if(!1===n.success){if(n.err===_.default.GIZ_SDK_OTA_DEVICE_BUSY_IN_UPGRADE)return n;a=!0}if(n.success&&0!==n.data.state&&4!==n.data.state&&(a=!0),a){if(Z+=1,p.default.warn(`发送OTA包失败,重试次数 ${Z}`,n),Z>3)return p.default.warn("发送OTA包失败次数超过限制"),{success:!1};continue}p.default.warn("设备接收ota子包成功",n),Z=0,N+=G,j+=1;let o=parseInt(`${j*G/U*100}`);if(o>100&&(o=100),s({firmwareSize:U,packageMaxLen:G,currentNumber:j,currentProgress:o}),yield g.default(100),d.cancelled)return p.default.warn("OTA 会话被新的请求打断,停止后续传输"),h();if(4===n.data.state){p.default.warn("设备请求等待OTA");const e=yield this.handleWatchBleData(u,C,6e4,d);if(p.default.warn("设备回复等待结果",e),!e.success)return e.err===_.default.GIZ_SDK_OTA_DEVICE_BUSY_IN_UPGRADE?e:{success:!1};if(1===e.data.state)return{success:!1}}}if(d.cancelled)return h();p.default.warn("发送完所有数据包,等待设备回复");const z=(e,t)=>{const i=c.hexStrint2byte(t);switch(new l.default(i).cmd){case"0050":return new k.default(i)}return null},W=yield this.handleWatchBleData(u,z,1e4,d);if(!W.success)return W;if(0===W.data.state){if(p.default.warn("设备回复收到固件,准备重启设备"),i({code:"GizOTAEventReboot"}),this.disConnectDevice(u),yield g.default(1e4),d.cancelled)return h();const e=yield this.connectDevice(u);if(console.log("connectRes",e),!e.success)return p.default.warn("设备重启后,无法连接"),{success:!1};const n=yield this.getDeviceInfo({deviceId:u});if(!n.success)return p.default.warn("获取设备版本号失败"),{success:!1};let s="";return s="MCU"===t?n.data.mcuSoftVersion:n.data.moduleSoftVersion,i({code:"GizOTAEventFinish"}),s===f?{success:!0}:(p.default.warn("设备上报版本号与更新的固件版本号不匹配,更新失败"),{success:!1})}return{success:!1}}finally{this.releaseOtaSession(u,d)}})),this.getDeviceInfo=({deviceId:e})=>n(this,void 0,void 0,(function*(){const t=y.default.pack();p.default.debug("DeviceInfo.pack",t),yield this.write(e,r.numberArray2Uint8Array(t).buffer);return yield this.handleWatchBleData(e,(e,t)=>{const i=c.hexStrint2byte(t);switch(new l.default(i).cmd){case"0014":try{const e=new y.default(i);return p.default.debug("parse DeviceInfo",e),e}catch(e){p.default.debug("parse DeviceInfo error",e)}}return null})})),this.checkUpdate=({device:e,type:t})=>n(this,void 0,void 0,(function*(){const i=yield this.getDeviceInfo({deviceId:e.bleDeviceID});if(i.success){let n="",s="";return"MCU"===t?(n=i.data.mcuSoftVersion,s=i.data.mcuHardVersion):(n=i.data.moduleSoftVersion,s=i.data.moduleHardVersion),yield D.checkUpdate({did:e.did,type:t,softVersion:n,hardVersion:s})}return{success:!1,err:i.err}})),this.watchBleDevice=(e,t)=>n(this,void 0,void 0,(function*(){const{serviceId:i,characteristicId:n,errMsg:s}=this.getTargetDevice(e);return s?{success:!1,message:s}:(yield wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:i,characteristicId:n,state:!0,type:"notification"}).catch(e=>this.notifyError(e)),p.default.log(`监听设备 ${e} 成功!`),this.addEventListener("GizBleDeviceData",t),{message:"ok",success:!0})})),this.writeBoradcast=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.scanList.find(t=>t.bleDeviceID===e);if(!i)return{success:!1,message:"not found device"};this.boradcastTimer&&clearTimeout(this.boradcastTimer);try{this.peripheralServer.stopAdvertising({});const e=r.convertToServiceUuids({mac:i.mac,index:0,data:t,len:t.length});return this.peripheralServer.startAdvertising({advertiseRequest:{connectable:!0,serviceUuids:e},powerLevel:"high",success:e=>{p.default.debug("GIZ_SDK: startAdvertising success",e)},fail:e=>{p.default.error("GIZ_SDK: startAdvertising error",new Error(JSON.stringify(e)))}}),p.default.debug("GIZ_SDK: start adv",e),this.boradcastTimer=setTimeout(()=>{this.peripheralServer.stopAdvertising({}),this.boradcastTimer=null},1e3),{success:!0}}catch(e){return p.default.log("GIZ_SDK:",e),clearTimeout(this.boradcastTimer),{success:!1,message:"send cmd error"}}})),this.write=(e,t)=>n(this,void 0,void 0,(function*(){p.default.warn("app => dev:",r.ab2hex(t),(new Date).getTime()),console.log("ble write",r.ab2hex(t));const i=this.getTargetDevice(e);if(i.serviceId&&i.characteristicId){return yield a.unpackWriteBLECharacteristicValue(e,i.serviceId,i.characteristicId,t)}return{success:!1,message:"send cmd error"}})),this.disConnectDevice=e=>n(this,void 0,void 0,(function*(){this.removeDevById(e);const{errMsg:t}=yield wx.closeBLEConnection({deviceId:e}),i=this.scanList.find(t=>t.bleDeviceID===e);return i&&(i.ctime=Date.now(),this.updateDevice(i)),"closeBLEConnection:ok"===t?{err:t,success:!0}:{err:t,success:!1}})),this.removeDevById=e=>{const t=this.connectedList.findIndex(t=>t.deviceId===e);-1!==t&&this.connectedList.splice(t,1)},this.getTargetDevice=e=>{const t=this.connectedList.find(t=>e===t.deviceId);return t||{errMsg:"Unable get this device,maybe you forgot to connect it."}},this.destory=()=>{this.listenDevOfflineTimer&&clearInterval(this.listenDevOfflineTimer),this.listenBluetoothDeviceFoundNoneTimer&&clearInterval(this.listenBluetoothDeviceFoundNoneTimer),wx.offAppShow(this.onAppShow),wx.offAppHide(this.onAppHide),wx.offBluetoothAdapterStateChange(this.onBluetoothAdapterStateChange)};const{serviceUUIDSuffix:v,serviceUUIDSuffix2:C}=t;this.serviceUUIDSuffix=v,this.serviceUUIDSuffix2=C,this.pks=e,this.listenDevOffline(null!=i?i:1e4),this.listenConnection(),this.listenBluetoothDeviceFoundNone(),wx.onAppShow(this.onAppShow),wx.onAppHide(this.onAppHide),wx.onBluetoothAdapterStateChange(this.onBluetoothAdapterStateChange)}createOtaSession(e){this.cancelOtaSession(e);const t={cancelled:!1,cancelHandlers:new Set};return this.otaSessionMap[e]=t,t}cancelOtaSession(e){const t=this.otaSessionMap[e];t&&(t.cancelled=!0,t.cancelHandlers.forEach(e=>e()),t.cancelHandlers.clear(),delete this.otaSessionMap[e])}releaseOtaSession(e,t){this.otaSessionMap[e]===t&&(t.cancelHandlers.clear(),delete this.otaSessionMap[e])}}t.BleHandle=C},function(e,t){var i;i=function(){return this}();try{i=i||new Function("return this")()}catch(e){"object"==typeof window&&(i=window)}e.exports=i},function(e,t,i){var n,s,r,a,o,c,l,u;e.exports=(u=i(0),s=(n=u).lib,r=s.WordArray,a=s.Hasher,o=n.algo,c=[],l=o.SHA1=a.extend({_doReset:function(){this._hash=new r.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(e,t){for(var i=this._hash.words,n=i[0],s=i[1],r=i[2],a=i[3],o=i[4],l=0;l<80;l++){if(l<16)c[l]=0|e[t+l];else{var u=c[l-3]^c[l-8]^c[l-14]^c[l-16];c[l]=u<<1|u>>>31}var d=(n<<5|n>>>27)+o+c[l];d+=l<20?1518500249+(s&r|~s&a):l<40?1859775393+(s^r^a):l<60?(s&r|s&a|r&a)-1894007588:(s^r^a)-899497514,o=a,a=r,r=s<<30|s>>>2,s=n,n=d}i[0]=i[0]+n|0,i[1]=i[1]+s|0,i[2]=i[2]+r|0,i[3]=i[3]+a|0,i[4]=i[4]+o|0},_doFinalize:function(){var e=this._data,t=e.words,i=8*this._nDataBytes,n=8*e.sigBytes;return t[n>>>5]|=128<<24-n%32,t[14+(n+64>>>9<<4)]=Math.floor(i/4294967296),t[15+(n+64>>>9<<4)]=i,e.sigBytes=4*t.length,this._process(),this._hash},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),n.SHA1=a._createHelper(l),n.HmacSHA1=a._createHmacHelper(l),u.SHA1)},function(e,t,i){var n;e.exports=(n=i(0),i(13),function(){var e=n,t=e.lib.Hasher,i=e.x64,s=i.Word,r=i.WordArray,a=e.algo;function o(){return s.create.apply(s,arguments)}var c=[o(1116352408,3609767458),o(1899447441,602891725),o(3049323471,3964484399),o(3921009573,2173295548),o(961987163,4081628472),o(1508970993,3053834265),o(2453635748,2937671579),o(2870763221,3664609560),o(3624381080,2734883394),o(310598401,1164996542),o(607225278,1323610764),o(1426881987,3590304994),o(1925078388,4068182383),o(2162078206,991336113),o(2614888103,633803317),o(3248222580,3479774868),o(3835390401,2666613458),o(4022224774,944711139),o(264347078,2341262773),o(604807628,2007800933),o(770255983,1495990901),o(1249150122,1856431235),o(1555081692,3175218132),o(1996064986,2198950837),o(2554220882,3999719339),o(2821834349,766784016),o(2952996808,2566594879),o(3210313671,3203337956),o(3336571891,1034457026),o(3584528711,2466948901),o(113926993,3758326383),o(338241895,168717936),o(666307205,1188179964),o(773529912,1546045734),o(1294757372,1522805485),o(1396182291,2643833823),o(1695183700,2343527390),o(1986661051,1014477480),o(2177026350,1206759142),o(2456956037,344077627),o(2730485921,1290863460),o(2820302411,3158454273),o(3259730800,3505952657),o(3345764771,106217008),o(3516065817,3606008344),o(3600352804,1432725776),o(4094571909,1467031594),o(275423344,851169720),o(430227734,3100823752),o(506948616,1363258195),o(659060556,3750685593),o(883997877,3785050280),o(958139571,3318307427),o(1322822218,3812723403),o(1537002063,2003034995),o(1747873779,3602036899),o(1955562222,1575990012),o(2024104815,1125592928),o(2227730452,2716904306),o(2361852424,442776044),o(2428436474,593698344),o(2756734187,3733110249),o(3204031479,2999351573),o(3329325298,3815920427),o(3391569614,3928383900),o(3515267271,566280711),o(3940187606,3454069534),o(4118630271,4000239992),o(116418474,1914138554),o(174292421,2731055270),o(289380356,3203993006),o(460393269,320620315),o(685471733,587496836),o(852142971,1086792851),o(1017036298,365543100),o(1126000580,2618297676),o(1288033470,3409855158),o(1501505948,4234509866),o(1607167915,987167468),o(1816402316,1246189591)],l=[];!function(){for(var e=0;e<80;e++)l[e]=o()}();var u=a.SHA512=t.extend({_doReset:function(){this._hash=new r.init([new s.init(1779033703,4089235720),new s.init(3144134277,2227873595),new s.init(1013904242,4271175723),new s.init(2773480762,1595750129),new s.init(1359893119,2917565137),new s.init(2600822924,725511199),new s.init(528734635,4215389547),new s.init(1541459225,327033209)])},_doProcessBlock:function(e,t){for(var i=this._hash.words,n=i[0],s=i[1],r=i[2],a=i[3],o=i[4],u=i[5],d=i[6],h=i[7],f=n.high,p=n.low,v=s.high,g=s.low,y=r.high,_=r.low,D=a.high,m=a.low,b=o.high,S=o.low,w=u.high,I=u.low,B=d.high,A=d.low,k=h.high,C=h.low,E=f,T=p,P=v,O=g,L=y,x=_,M=D,K=m,H=b,R=S,N=w,U=I,G=B,j=A,Z=k,z=C,W=0;W<80;W++){var F,V,Y=l[W];if(W<16)V=Y.high=0|e[t+2*W],F=Y.low=0|e[t+2*W+1];else{var $=l[W-15],X=$.high,J=$.low,q=(X>>>1|J<<31)^(X>>>8|J<<24)^X>>>7,Q=(J>>>1|X<<31)^(J>>>8|X<<24)^(J>>>7|X<<25),ee=l[W-2],te=ee.high,ie=ee.low,ne=(te>>>19|ie<<13)^(te<<3|ie>>>29)^te>>>6,se=(ie>>>19|te<<13)^(ie<<3|te>>>29)^(ie>>>6|te<<26),re=l[W-7],ae=re.high,oe=re.low,ce=l[W-16],le=ce.high,ue=ce.low;V=(V=(V=q+ae+((F=Q+oe)>>>0<Q>>>0?1:0))+ne+((F+=se)>>>0<se>>>0?1:0))+le+((F+=ue)>>>0<ue>>>0?1:0),Y.high=V,Y.low=F}var de,he=H&N^~H&G,fe=R&U^~R&j,pe=E&P^E&L^P&L,ve=T&O^T&x^O&x,ge=(E>>>28|T<<4)^(E<<30|T>>>2)^(E<<25|T>>>7),ye=(T>>>28|E<<4)^(T<<30|E>>>2)^(T<<25|E>>>7),_e=(H>>>14|R<<18)^(H>>>18|R<<14)^(H<<23|R>>>9),De=(R>>>14|H<<18)^(R>>>18|H<<14)^(R<<23|H>>>9),me=c[W],be=me.high,Se=me.low,we=Z+_e+((de=z+De)>>>0<z>>>0?1:0),Ie=ye+ve;Z=G,z=j,G=N,j=U,N=H,U=R,H=M+(we=(we=(we=we+he+((de+=fe)>>>0<fe>>>0?1:0))+be+((de+=Se)>>>0<Se>>>0?1:0))+V+((de+=F)>>>0<F>>>0?1:0))+((R=K+de|0)>>>0<K>>>0?1:0)|0,M=L,K=x,L=P,x=O,P=E,O=T,E=we+(ge+pe+(Ie>>>0<ye>>>0?1:0))+((T=de+Ie|0)>>>0<de>>>0?1:0)|0}p=n.low=p+T,n.high=f+E+(p>>>0<T>>>0?1:0),g=s.low=g+O,s.high=v+P+(g>>>0<O>>>0?1:0),_=r.low=_+x,r.high=y+L+(_>>>0<x>>>0?1:0),m=a.low=m+K,a.high=D+M+(m>>>0<K>>>0?1:0),S=o.low=S+R,o.high=b+H+(S>>>0<R>>>0?1:0),I=u.low=I+U,u.high=w+N+(I>>>0<U>>>0?1:0),A=d.low=A+j,d.high=B+G+(A>>>0<j>>>0?1:0),C=h.low=C+z,h.high=k+Z+(C>>>0<z>>>0?1:0)},_doFinalize:function(){var e=this._data,t=e.words,i=8*this._nDataBytes,n=8*e.sigBytes;return t[n>>>5]|=128<<24-n%32,t[30+(n+128>>>10<<5)]=Math.floor(i/4294967296),t[31+(n+128>>>10<<5)]=i,e.sigBytes=4*t.length,this._process(),this._hash.toX32()},clone:function(){var e=t.clone.call(this);return e._hash=this._hash.clone(),e},blockSize:32});e.SHA512=t._createHelper(u),e.HmacSHA512=t._createHmacHelper(u)}(),n.SHA512)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(1),s=i(3);class r extends n.default{constructor(e){super(e),this.passcode="";let t=0;const i=parseInt(s.arrayToString(this.content.slice(t,t+2)),16);t+=2;let n="";this.content.slice(t,t+i).map(e=>{n+=String.fromCharCode(e)}),this.passcode=n}}r.pack=()=>[0,0,0,3,3,0,0,6],t.default=r},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(1),s=i(3);class r extends n.default{constructor(e){super(e),this.result=!1,this.didLength=0,this.did="";let t=0;if(this.result=0===this.content[0],t++,1===this.flag[0]){this.didLength=parseInt(s.arrayToString(this.content.slice(t,t+2)),16),t+=2;let e="";this.content.slice(t,this.content.length).map(t=>{e+=String.fromCharCode(t)}),this.did=e}}}r.pack=({passcode:e})=>{let t=[0];const i=s.hexStrint2byte(s.fillString(e.length.toString(16),4)),n=s.string2Bytes(e),r=[0].concat([0,8]).concat(i).concat(n);return t=s.hexStrint2byte(r.length.toString(16)),[0,0,0,3].concat(t).concat(r)},t.default=r},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(14),r=i(3),a=e=>-1!==e.indexOf("uint")?"number":e,o=(e,t,i)=>{let n="";switch(e){case"bool":n=`${!0===t[i.name]?1:0}`;break;case"enum":{let e=t[i.name];"number"==typeof e&&(e=i.enum[e]);const s=i.enum.findIndex(t=>e===t),a=-1===s?0:s;n=r.fillString(a.toString(2),i.position.len);break}case"number":{let e=0;null!=t[i.name]&&(e=Math.round((t[i.name]-i.uint_spec.addition)/i.uint_spec.ratio)),n=r.fillString(e.toString(2),8*i.position.len);break}case"binary":{let e=t[i.name]||"";e instanceof Array&&(e=r.arrayToString(e));const s=r.fillString(e,2*i.position.len,!0);for(let e=0;e<s.length/2;e++){const t=2*e,i=s[t]+s[t+1];n+=r.fillString(parseInt(i,16).toString(2),8)}break}}const s=i.position.len*("byte"===i.position.unit?8:1)-n.length;if(s>0)for(let e=0;e<s;e++)n=`0${n}`;return`${n}`},c=(e,t,i)=>{switch(e){case"bool":return"1"===t;case"enum":return parseInt(t,2);case"binary":{const e=i.position.len;let n="";for(let e=0;e<t.length/8;e++){const i=8*e,s=t.substring(i,i+8);n+=r.fillString(parseInt(s,2).toString(16),2)}return r.fillString(n,2*e,!0)}case"number":return parseInt(t,2)/(1/i.uint_spec.ratio)+i.uint_spec.addition;default:return""}},l=({config:e,data:t,isAdaptiveDatapoint:i})=>{let n=e;const s=[0,0,0,3],c=[0],l=[0,147],d=[0,0,0,0];let h=[1],f="";const p=[];i||(n=n.filter(e=>"status_writable"===e.type)),n.map(e=>{void 0!==t[e.name]?(f=`1${f}`,p.push(e)):f=`0${f}`}),i&&(h=[17],n=p),f=r.fillString(f,8*Math.ceil(f.length/8));for(let e=0;e<f.length/8;e++)h.push(parseInt(f.substring(8*e,8*(e+1)),2));let v,g="";try{v=n[0]}catch(e){}n.map(e=>{"bool"===e.data_type||"enum"===e.data_type?(v.type!==e.type&&(h=h.concat(r.completeBlock(g)),g=""),g=((e,i)=>{const n=a(e.data_type);return i=o(n,t,e)+i})(e,g)):(g.length>0&&(h=h.concat(r.completeBlock(g)),g=""),h=((e,i)=>{const n=a(e.data_type),s=o(n,t,e);return i=i.concat(r.completeBlock(s))})(e,h)),v=e}),g.length>0&&(h=h.concat(r.completeBlock(g)),g="");const y=c.concat(l).concat(d).concat(h),_=u(y);return s.push(..._),{data:s.concat(y),raw:{header:[0,0,0,3],flag:c,len:_,headerCmd:l,sn:d,cmd:h}}};function u(e){const t=e.length.toString(2),i=[];for(let e=t.length;e>0;e-=7){const n=e-7,s=e;let r=t.substring(n,s);r=`${n>0?"1":"0"}${r}`,i.push(parseInt(r,2))}return i}function d(e,t){return e===t||"ALL"===e}function h({attrs:e,activeAttrs:t,flagString:i,cmdData:n,accumulate:s}){let r=0,a={},o=0;return["status_writable","status_readonly","alert","fault"].map(c=>{const l=e.filter(e=>d(c,e.type)).length,{cmd:u,cmdDataLength:h}=f({type:c,attrs:e.slice(o,o+l),activeAttrs:t,flagString:i.substring(o,o+l),cmdData:n.slice(r,n.length),accumulate:s});return r+=h,a=Object.assign(Object.assign({},a),u),o+=l,null}),a}function f({type:e,attrs:t,activeAttrs:i,cmdData:n,flagString:s,accumulate:o}){let l=0,u=0,h=0;return i.map(t=>{if(d(e,t.type)){const e=t.position.len*("bit"===t.position.unit?1:8);"bool"===t.data_type||"enum"===t.data_type?u+=e:h+=e}return null}),l=Math.ceil(h/8)+Math.ceil(u/8),{cmdDataLength:l,cmd:function({attrs:e,flagString:t,boolEnumLength:i,cmdData:n,accumulate:s}){const o={};let l=0;for(let u=0;u<t.length;u++)if(e[u]&&"1"===t[u]){const{data_type:t,position:{len:s}}=e[u];let d="";if("bool"===t||"enum"===t){let e="";n.slice(0,i).map(t=>(e+=r.fillString(t.toString(2),8),null));const t=e.length-l;d=e.substring(t-s,t),l+=s}else{const e=i,t=i+s;n.slice(e,t).map(e=>(d+=r.fillString(e.toString(2),8),null)),i+=s}const h=a(t);o[e[u].name]=c(h,d,e[u])}else if(s){const t=e[u]||{position:{len:0}};"byte"===t.position.unit?i+=t.position.len:l+=t.position.len}return o}({attrs:t,flagString:s,boolEnumLength:Math.ceil(u/8),cmdData:n,accumulate:o})}}t.getVariableLength=u;t.unpack=(e,t)=>n(void 0,void 0,void 0,(function*(){const i=yield s.default.getConfigFile(t);if(i){const n=function({config:e=[],data:t}){let i,n,s="";const a={header:r.arrayToString(t.slice(0,4)),flag:"",len:"",cmd:"",sn:"",action:"",payload:""},o=e;let c=r.checkHeader(t);if(!1===c)return;const l=t.slice(c,t.length),u=r.getProtocolLen(l);if(c+=u,a.len=r.arrayToString(l.slice(0,u)),c+=1,a.flag=r.arrayToString(t.slice(c-1,c)),c+=2,a.cmd=r.arrayToString(t.slice(c-2,c)),a.sn="",("0093"===a.cmd||"0094"===a.cmd)&&(c+=4,a.sn=r.arrayToString(t.slice(c-4,c)),"01"===a.flag)){c+=2,c+=parseInt(r.arrayToString(t.slice(c-2,c)),16)}c+=1,a.action=r.arrayToString(t.slice(c-1,c)),i=parseInt(a.action,16),a.payload=r.arrayToString(t.slice(c,t.length));const d=t.slice(c,t.length);let p=o;1===i&&(p=o.filter(e=>"status_writable"===e.type));const v=JSON.parse(JSON.stringify(p)),g=Math.ceil(p.length/8);let y=d.slice(0,g),_=d.slice(g,d.length);3!==i&&4!==i||(y=new Array(g).fill(255),_=d);let D="";y.map(e=>(D+=r.fillString(e.toString(2),8),null)),i>=17&&i<=20&&(p=p.filter((e,t)=>{const i=D.length-1-t;return"1"===D[i]})),"0090"===a.cmd||"0093"===a.cmd?(s="App 透传数据到 Dev",n="APP2DEV"):"0091"===a.cmd||"0094"===a.cmd?(s="Dev 收到控制命令后应答到 App",n="DEV2APP"):(s="非法数据",n="UNKNOW");let m={};switch(i){case 1:s="App 下发数据到 Dev",m=h({attrs:v,activeAttrs:p,flagString:D.split("").reverse().join(""),cmdData:_,accumulate:!0});break;case 2:return s="App 下发查询指令到 Dev",{kvData:null,rawData:a,message:s,messageType:n};case 3:s="Dev 回复查询指令到 App",m=h({attrs:v,activeAttrs:p,flagString:D.split("").reverse().join(""),cmdData:_,accumulate:!0});break;case 4:s="Dev 上报状态到 App",m=h({attrs:v,activeAttrs:p,flagString:D.split("").reverse().join(""),cmdData:_,accumulate:!0});break;case 5:return s="App 透传数据到 Dev",{kvData:null,rawData:a,message:s,messageType:n};case 6:return s="Dev 透传数据到 App",{kvData:null,rawData:a,message:s,messageType:n};case 7:return s="App 下发控制子设备",{kvData:null,rawData:a,message:s,messageType:n};case 8:return s="App 读取子设备数据",{kvData:null,rawData:a,message:s,messageType:n};case 9:return s="Dev 中控回复ACK",{kvData:null,rawData:a,message:s,messageType:n};case 10:return s="子设备上报状态到 App",{kvData:null,rawData:a,message:s,messageType:n};case 11:return s="App 下发添加子设备指令",{kvData:null,rawData:a,message:s,messageType:n};case 12:return s="App 下发删除子设备",{kvData:null,rawData:a,message:s,messageType:n};case 13:return s="App 获取中控子设备列表",{kvData:null,rawData:a,message:s,messageType:n};case 14:return s="中控响应字设备查询到 App",{kvData:null,rawData:a,message:s,messageType:n};case 15:return s="子设备列表变更通知到 App",{kvData:null,rawData:a,message:s,messageType:n};case 16:return s="Dev 子设备上下线状态变更通知",{kvData:null,rawData:a,message:s,messageType:n};case 17:s="App 下发变长数据到 Dev",m=f({type:"ALL",attrs:v,activeAttrs:p,flagString:D.split("").reverse().join(""),cmdData:_}).cmd;break;case 18:return s="App 下发变长查询到 Dev",{kvData:null,rawData:a,message:s,messageType:n};case 19:s="Dev 变长回复查询指令到 App",m=f({type:"ALL",attrs:v,activeAttrs:p,flagString:D.split("").reverse().join(""),cmdData:_}).cmd;break;case 20:s="Dev 变长上报状态到 App",m=f({type:"ALL",attrs:v,activeAttrs:p,flagString:D.split("").reverse().join(""),cmdData:_}).cmd;break;case 114:return s="App 向网关发送数据",{kvData:null,rawData:a,message:s,messageType:n};case 115:return s="Dev 网关上报数据到 App",{kvData:null,rawData:a,message:s,messageType:n};case 116:return s="App 通知网关删除子设备",{kvData:null,rawData:a,message:s,messageType:n};default:return{kvData:null,rawData:a,message:s,messageType:n}}return 0===o.length?{kvData:null,rawData:a,message:s,messageType:n}:{kvData:m,rawData:a,message:s,messageType:n}}({config:(yield i).entities[0].attrs,data:e});return n.kvData&&(n.kvData=yield p(null==n?void 0:n.kvData,t,"object")),n}return null}));t.pack=(e,t)=>n(void 0,void 0,void 0,(function*(){const i=yield s.default.getConfigFile(t);if(i){const t="var_len"===i.protocolType;return l({data:e,config:(yield i).entities[0].attrs,isAdaptiveDatapoint:t})}return null}));t.padBoradcastData=e=>{const t=[0].concat([0,147]).concat([0,0,0,0]).concat(e),i=u(t);return r.arrayToString([0,0,0,3].concat(i).concat(t))};t.formatEnum=(e,t,i)=>n(void 0,void 0,void 0,(function*(){for(let n in e){const r=yield s.default.getAttrItem(t,n);if(r&&"enum"===r.data_type){if("int"===i&&"string"==typeof e[n]){const t=r.enum.findIndex(t=>t===e[n]);e[n]=t||0}"string"===i&&"number"==typeof e[n]&&(e[n]=r.enum[e[n]])}}return e}));const p=(e,t,i)=>n(void 0,void 0,void 0,(function*(){for(let n in e){const a=yield s.default.getAttrItem(t,n);a&&"binary"===a.data_type&&("object"===i&&"string"==typeof e[n]&&(e[n]=r.hexStrint2byte(e[n])),"string"===i&&"object"==typeof e[n]&&(e[n]=r.arrayToString(e[n])))}return e}));t.formatBinary=p},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});t.default=class{constructor(){this.listenerMap={},this.addEventListener=(e,t)=>n(this,void 0,void 0,(function*(){return this.listenerMap[e]||(this.listenerMap[e]=[]),-1===this.listenerMap[e].indexOf(t)&&this.listenerMap[e].push(t),{success:!0}})),this.removeEventListener=(e,t)=>{if(this.listenerMap[e]){const i=this.listenerMap[e].indexOf(t);if(-1!==i)return this.listenerMap[e].splice(i,1),{success:!0}}return{success:!1}}}}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(14),r=i(3),a=e=>-1!==e.indexOf("uint")?"number":e,o=(e,t,i)=>{let n="";switch(e){case"bool":n=`${!0===t[i.name]?1:0}`;break;case"enum":{let e=t[i.name];"number"==typeof e&&(e=i.enum[e]);const s=i.enum.findIndex(t=>e===t),a=-1===s?0:s;n=r.fillString(a.toString(2),i.position.len);break}case"number":{let e=0;null!=t[i.name]&&(e=Math.round((t[i.name]-i.uint_spec.addition)/i.uint_spec.ratio)),n=r.fillString(e.toString(2),8*i.position.len);break}case"binary":{let e=t[i.name]||"";e instanceof Array&&(e=r.arrayToString(e));const s=r.fillString(e,2*i.position.len,!0);for(let e=0;e<s.length/2;e++){const t=2*e,i=s[t]+s[t+1];n+=r.fillString(parseInt(i,16).toString(2),8)}break}}const s=i.position.len*("byte"===i.position.unit?8:1)-n.length;if(s>0)for(let e=0;e<s;e++)n=`0${n}`;return`${n}`},c=(e,t,i)=>{switch(e){case"bool":return"1"===t;case"enum":return parseInt(t,2);case"binary":{const e=i.position.len;let n="";for(let e=0;e<t.length/8;e++){const i=8*e,s=t.substring(i,i+8);n+=r.fillString(parseInt(s,2).toString(16),2)}return r.fillString(n,2*e,!0)}case"number":return parseInt(t,2)/(1/i.uint_spec.ratio)+i.uint_spec.addition;default:return""}},l=({config:e,data:t,isAdaptiveDatapoint:i})=>{let n=e;const s=[0,0,0,3],c=[0],l=[0,147],d=[0,0,0,0];let h=[1],f="";const p=[];i||(n=n.filter(e=>"status_writable"===e.type)),n.map(e=>{void 0!==t[e.name]?(f=`1${f}`,p.push(e)):f=`0${f}`}),i&&(h=[17],n=p),f=r.fillString(f,8*Math.ceil(f.length/8));for(let e=0;e<f.length/8;e++)h.push(parseInt(f.substring(8*e,8*(e+1)),2));let v,g="";try{v=n[0]}catch(e){}n.map(e=>{"bool"===e.data_type||"enum"===e.data_type?(v.type!==e.type&&(h=h.concat(r.completeBlock(g)),g=""),g=((e,i)=>{const n=a(e.data_type);return i=o(n,t,e)+i})(e,g)):(g.length>0&&(h=h.concat(r.completeBlock(g)),g=""),h=((e,i)=>{const n=a(e.data_type),s=o(n,t,e);return i=i.concat(r.completeBlock(s))})(e,h)),v=e}),g.length>0&&(h=h.concat(r.completeBlock(g)),g="");const y=c.concat(l).concat(d).concat(h),_=u(y);return s.push(..._),{data:s.concat(y),raw:{header:[0,0,0,3],flag:c,len:_,headerCmd:l,sn:d,cmd:h}}};function u(e){const t=e.length.toString(2),i=[];for(let e=t.length;e>0;e-=7){const n=e-7,s=e;let r=t.substring(n,s);r=`${n>0?"1":"0"}${r}`,i.push(parseInt(r,2))}return i}function d(e,t){return e===t||"ALL"===e}function h({attrs:e,activeAttrs:t,flagString:i,cmdData:n,accumulate:s}){let r=0,a={},o=0;return["status_writable","status_readonly","alert","fault"].map(c=>{const l=e.filter(e=>d(c,e.type)).length,{cmd:u,cmdDataLength:h}=f({type:c,attrs:e.slice(o,o+l),activeAttrs:t,flagString:i.substring(o,o+l),cmdData:n.slice(r,n.length),accumulate:s});return r+=h,a=Object.assign(Object.assign({},a),u),o+=l,null}),a}function f({type:e,attrs:t,activeAttrs:i,cmdData:n,flagString:s,accumulate:o}){let l=0,u=0,h=0;return i.map(t=>{if(d(e,t.type)){const e=t.position.len*("bit"===t.position.unit?1:8);"bool"===t.data_type||"enum"===t.data_type?u+=e:h+=e}return null}),l=Math.ceil(h/8)+Math.ceil(u/8),{cmdDataLength:l,cmd:function({attrs:e,flagString:t,boolEnumLength:i,cmdData:n,accumulate:s}){const o={};let l=0;for(let u=0;u<t.length;u++)if(e[u]&&"1"===t[u]){const{data_type:t,position:{len:s}}=e[u];let d="";if("bool"===t||"enum"===t){let e="";n.slice(0,i).map(t=>(e+=r.fillString(t.toString(2),8),null));const t=e.length-l;d=e.substring(t-s,t),l+=s}else{const e=i,t=i+s;n.slice(e,t).map(e=>(d+=r.fillString(e.toString(2),8),null)),i+=s}const h=a(t);o[e[u].name]=c(h,d,e[u])}else if(s){const t=e[u]||{position:{len:0}};"byte"===t.position.unit?i+=t.position.len:l+=t.position.len}return o}({attrs:t,flagString:s,boolEnumLength:Math.ceil(u/8),cmdData:n,accumulate:o})}}t.getVariableLength=u;t.unpack=(e,t)=>n(void 0,void 0,void 0,(function*(){const i=yield s.default.getConfigFile(t);if(i){const n=function({config:e=[],data:t}){let i,n,s="";const a={header:r.arrayToString(t.slice(0,4)),flag:"",len:"",cmd:"",sn:"",action:"",payload:""},o=e;let c=r.checkHeader(t);if(!1===c)return;const l=t.slice(c,t.length),u=r.getProtocolLen(l);if(c+=u,a.len=r.arrayToString(l.slice(0,u)),c+=1,a.flag=r.arrayToString(t.slice(c-1,c)),c+=2,a.cmd=r.arrayToString(t.slice(c-2,c)),a.sn="",("0093"===a.cmd||"0094"===a.cmd)&&(c+=4,a.sn=r.arrayToString(t.slice(c-4,c)),"01"===a.flag)){c+=2,c+=parseInt(r.arrayToString(t.slice(c-2,c)),16)}c+=1,a.action=r.arrayToString(t.slice(c-1,c)),i=parseInt(a.action,16),a.payload=r.arrayToString(t.slice(c,t.length));const d=t.slice(c,t.length);let p=o;1===i&&(p=o.filter(e=>"status_writable"===e.type));const v=JSON.parse(JSON.stringify(p)),g=Math.ceil(p.length/8);let y=d.slice(0,g),_=d.slice(g,d.length);3!==i&&4!==i||(y=new Array(g).fill(255),_=d);let D="";y.map(e=>(D+=r.fillString(e.toString(2),8),null)),i>=17&&i<=20&&(p=p.filter((e,t)=>{const i=D.length-1-t;return"1"===D[i]})),"0090"===a.cmd||"0093"===a.cmd?(s="App 透传数据到 Dev",n="APP2DEV"):"0091"===a.cmd||"0094"===a.cmd?(s="Dev 收到控制命令后应答到 App",n="DEV2APP"):(s="非法数据",n="UNKNOW");let m={};switch(i){case 1:s="App 下发数据到 Dev",m=h({attrs:v,activeAttrs:p,flagString:D.split("").reverse().join(""),cmdData:_,accumulate:!0});break;case 2:return s="App 下发查询指令到 Dev",{kvData:null,rawData:a,message:s,messageType:n};case 3:s="Dev 回复查询指令到 App",m=h({attrs:v,activeAttrs:p,flagString:D.split("").reverse().join(""),cmdData:_,accumulate:!0});break;case 4:s="Dev 上报状态到 App",m=h({attrs:v,activeAttrs:p,flagString:D.split("").reverse().join(""),cmdData:_,accumulate:!0});break;case 5:return s="App 透传数据到 Dev",{kvData:null,rawData:a,message:s,messageType:n};case 6:return s="Dev 透传数据到 App",{kvData:null,rawData:a,message:s,messageType:n};case 7:return s="App 下发控制子设备",{kvData:null,rawData:a,message:s,messageType:n};case 8:return s="App 读取子设备数据",{kvData:null,rawData:a,message:s,messageType:n};case 9:return s="Dev 中控回复ACK",{kvData:null,rawData:a,message:s,messageType:n};case 10:return s="子设备上报状态到 App",{kvData:null,rawData:a,message:s,messageType:n};case 11:return s="App 下发添加子设备指令",{kvData:null,rawData:a,message:s,messageType:n};case 12:return s="App 下发删除子设备",{kvData:null,rawData:a,message:s,messageType:n};case 13:return s="App 获取中控子设备列表",{kvData:null,rawData:a,message:s,messageType:n};case 14:return s="中控响应字设备查询到 App",{kvData:null,rawData:a,message:s,messageType:n};case 15:return s="子设备列表变更通知到 App",{kvData:null,rawData:a,message:s,messageType:n};case 16:return s="Dev 子设备上下线状态变更通知",{kvData:null,rawData:a,message:s,messageType:n};case 17:s="App 下发变长数据到 Dev",m=f({type:"ALL",attrs:v,activeAttrs:p,flagString:D.split("").reverse().join(""),cmdData:_}).cmd;break;case 18:return s="App 下发变长查询到 Dev",{kvData:null,rawData:a,message:s,messageType:n};case 19:s="Dev 变长回复查询指令到 App",m=f({type:"ALL",attrs:v,activeAttrs:p,flagString:D.split("").reverse().join(""),cmdData:_}).cmd;break;case 20:s="Dev 变长上报状态到 App",m=f({type:"ALL",attrs:v,activeAttrs:p,flagString:D.split("").reverse().join(""),cmdData:_}).cmd;break;case 114:return s="App 向网关发送数据",{kvData:null,rawData:a,message:s,messageType:n};case 115:return s="Dev 网关上报数据到 App",{kvData:null,rawData:a,message:s,messageType:n};case 116:return s="App 通知网关删除子设备",{kvData:null,rawData:a,message:s,messageType:n};default:return{kvData:null,rawData:a,message:s,messageType:n}}return 0===o.length?{kvData:null,rawData:a,message:s,messageType:n}:{kvData:m,rawData:a,message:s,messageType:n}}({config:(yield i).entities[0].attrs,data:e});return n.kvData&&(n.kvData=yield p(null==n?void 0:n.kvData,t,"object")),n}return null}));t.pack=(e,t)=>n(void 0,void 0,void 0,(function*(){const i=yield s.default.getConfigFile(t);if(i){const t="var_len"===i.protocolType;return l({data:e,config:(yield i).entities[0].attrs,isAdaptiveDatapoint:t})}return null}));t.padBoradcastData=e=>{const t=[0].concat([0,147]).concat([0,0,0,0]).concat(e),i=u(t);return r.arrayToString([0,0,0,3].concat(i).concat(t))};t.formatEnum=(e,t,i)=>n(void 0,void 0,void 0,(function*(){for(let n in e){const r=yield s.default.getAttrItem(t,n);if(r&&"enum"===r.data_type){if("int"===i&&"string"==typeof e[n]){const t=r.enum.findIndex(t=>t===e[n]);e[n]=t||0}"string"===i&&"number"==typeof e[n]&&(e[n]=r.enum[e[n]])}}return e}));const p=(e,t,i)=>n(void 0,void 0,void 0,(function*(){for(let n in e){const a=yield s.default.getAttrItem(t,n);a&&"binary"===a.data_type&&("object"===i&&"string"==typeof e[n]&&(e[n]=r.hexStrint2byte(e[n])),"string"===i&&"object"==typeof e[n]&&(e[n]=r.arrayToString(e[n])))}return e}));t.formatBinary=p},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(71);t.crc16modbus=n.default;const s=i(78);t.crc32=s.default,t.default={crc16modbus:n.default,crc32:s.default}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(73);t.default=function(e,t){const i=(e,i)=>t(n.default(e),i)>>>0;return i.signed=(e,i)=>t(n.default(e),i),i.unsigned=i,i.model=e,i}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(12),r=i(85),a=i(86),o=i(11);class c{constructor(){this.pad=(e,t)=>{},this.unpad=e=>{const t=e.sigBytes;let i=0,n=1;const s=e.toString(o.enc.Utf8);for(;i+16<=t;)i+=16;for(let e=0;e<7;e++){const t=i-2*e;if(s.substring(t,t-2)!=s.substring(t-2,t-4)){i-=2*n;break}n++}e.sigBytes=i}}}t.getBindingList=()=>n(void 0,void 0,void 0,(function*(){const e=yield s.default("/app/bindings?show_disabled=0&limit=1000&skip=0",{method:"GET"});if(e.success){return{success:!0,data:e.data.devices.map(e=>({productKey:e.product_key,mac:e.mac,did:e.did,host:e.host,port_s:e.port_s,port:e.port,ws_port:e.ws_port,wss_port:e.wss_port,passcode:e.passcode,isBleOnline:!1,isLanOnline:!1,connectType:"NONE",name:e.dev_alias,isBind:!0,isOnline:e.is_online}))}}return{success:!1,err:e.err}})),t.bindMac=function({mac:e,productKey:t,productSecret:i,alias:r,beOwner:o}){return n(this,void 0,void 0,(function*(){const n={mac:e,product_key:t,dev_alias:r,set_owner:o},{Signature:c,timestamp:l}=a.psKeySign(i);return yield s.default("/app/bind_mac",{method:"POST",data:n,headers:{"X-Gizwits-Signature":c,"X-Gizwits-Timestamp":l}})}))},t.unbindDevice=function({devices:e}){return n(this,void 0,void 0,(function*(){return yield s.default("/app/bindings",{method:"DELETE",data:{devices:e.map(e=>({did:e.did}))}})}))},t.checkDeviceRegister=function({SSID:e,password:t,productKeys:i}){return n(this,void 0,void 0,(function*(){const n=r.default({SSID:e,password:t,pks:i});let a="";return n.map(e=>{a+=`${e},`}),a=a.substring(0,a.length-1),yield s.default(`/app/device_register?random_codes=${a}`,{method:"get"})}))},t.safeRegister=function({productKey:e,productSecret:t,mac:i,passcode:r,gwDid:a,isReset:c}){return n(this,void 0,void 0,(function*(){let n=`is_reset=${c?1:0}&mac=${i}&passcode=${r}`;a&&(n+=`&gw_did=${a}`);const u=o.enc.Hex.parse(t),d=o.enc.Hex.parse(""),h=o.enc.Utf8.parse(n),f=o.AES.encrypt(h,u,{iv:d,mode:o.mode.ECB,padding:o.pad.Pkcs7}).ciphertext.toString().toUpperCase(),p=yield s.default(`/dev/${e}/device`,{method:"POST",data:{data:f},headers:{"content-type":"application/x-www-form-urlencoded"}},!1);if(p.success){const e=l({productSecret:t,iv:d,data:p.data}),n=[];return e.find(e=>e.mac===i)||n.push({mac:i}),{success:!0,data:{successDevices:e,failedDevices:n}}}return{success:!1,err:p.err}}))};const l=({productSecret:e,data:t,iv:i})=>{const n=o.enc.Hex.parse(e),s=o.enc.Hex.parse(t);const r=o.AES.decrypt(o.enc.Base64.stringify(s),n,{iv:i,mode:o.mode.ECB,padding:new c}).toString(o.enc.Utf8),a=[];return r.split(",").map(e=>{const t=e.split("&"),i=t[0].replace("mac=",""),n=t[1].replace("did=","");a.push({mac:i,did:n})}),a};t.editBindInfo=function({name:e,remark:t,did:i}){return n(this,void 0,void 0,(function*(){const n={};return e&&(n.dev_alias=e),t&&(n.remark=t),yield s.default(`/app/bindings/${i}`,{method:"PUT",data:n},!0)}))}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),i(35);const n=i(36),s=i(5);t.errorCode=s.default;const r=i(22);t.BleHandle=r.BleHandle,t.default=n.default},function(e,t){},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(15),r=i(22),a=i(83),o=i(84),c=i(87),l=i(88),u=i(4),d=i(5),h=i(90),f=i(33),p=i(10),v=i(14),g=i(28),y=i(3),_=i(91),D=i(1),m=i(93),b=i(94),S=i(9),w=i(95),I=i(96),B=i(97);t.default=class{constructor({appID:e,appSecret:t,productInfo:i,cloudServiceInfo:r,token:a,uid:_,offlineThreshold:A}){this.version="3.6.6-kuka",this.listenerMap={},this.keepScanTimer=null,this._deviceList=[],this._bleDevices=[],this._lanDevices=[],this.productInfo=[],this.syncDataCallBack=null,this.syncTotalNum=0,this.syncCurrnetNum=0,this.syncDataTimoutTimer=null,this.SYNC_TIMEOUT=24e4,this.handleBleError=e=>{this.listenerMap.onBleHandleError&&this.listenerMap.onBleHandleError.map(t=>{t(e)})},this.handleBleDevices=e=>{this.bleDevices=e},this.handleLanDevices=e=>{this.lanDevices=e},this.handleLanDeviceData=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>t.mac===e);if(i){const e=yield g.unpack(y.hexStrint2byte(t),i.productKey);(null==e?void 0:e.kvData)&&this.listenerMap.GizDeviceAttrsNotifications&&this.listenerMap.GizDeviceAttrsNotifications.map(t=>{t({device:i,data:null==e?void 0:e.kvData})})}})),this.getBleProductProtocalType=e=>"67a95f560e464453be079c5723a4a85c"===e.productKey||"0b58c73f12064eb897aa005cf43d6a1b"===e.productKey||"4b286229884f4711bcdbaefdfb5f76b9"===e.productKey?"direct":"normal",this.handleBleDeviceData=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>t.bleDeviceID===e.deviceId);if(i){if("direct"===this.getBleProductProtocalType(i)){const e=y.hexStrint2byte(t);return void(this.listenerMap.onBleDeviceDataNotifications&&this.listenerMap.onBleDeviceDataNotifications.map(t=>{t({device:i,data:e})}))}const s=y.hexStrint2byte(t),r=new D.default(s);switch(u.default.warn("===收到蓝牙数据===",(new Date).getTime()),r.cmd){case"0093":case"0094":case"0090":case"0091":{if(console.debug("handleBleDeviceData",t,i),i.passcode){const e=this.productInfo.find(e=>e.productKey===i.productKey);if(e){const n=parseInt(`${Date.now()/1e3}`,10);b.uploadP0({device:i,data:[{raw:t,created_at:n}],productSecret:e.productSecret}).then(e=>{u.default.debug("设备上报数据:timestemp",new Date(1e3*n).toLocaleString(),e)})}}const e=yield g.unpack(y.hexStrint2byte(t),i.productKey);(null==e?void 0:e.kvData)&&this.listenerMap.GizDeviceAttrsNotifications&&this.listenerMap.GizDeviceAttrsNotifications.map(t=>{t({device:i,data:null==e?void 0:e.kvData})});break}case"0062":{const t=new I.default(s);u.default.debug("收到代理重置事件",t),1===t.status&&this.deviceSafetyApi({mac:i.mac,productKey:i.productKey,isReset:!0}).then(t=>n(this,void 0,void 0,(function*(){u.default.debug("代理重置结果",t),t.success&&t.data.successDevices.length>0&&(u.default.debug("重置成功,回写数据"),yield this.bleHandle.write(e.deviceId,p.numberArray2Uint8Array(B.default.pack(0)).buffer))})));break}case"0052":{const t=new m.RequestSync(s);if(u.default.debug("设备回复是否允许同步, state:",t.state),this.syncDataLengthCallback&&this.syncDataLengthCallback({success:0==t.state,data:t.len}),!this.syncDataCallBack)break;0===t.state?(this.syncCurrnetNum=0,this.syncTotalNum=t.len,this.syncDataCallBack({event:"SYNC_START",totalNum:this.syncTotalNum,currentNum:this.syncCurrnetNum}),u.default.debug("查询第一条离线数据"),yield this.bleHandle.write(e.deviceId,p.numberArray2Uint8Array(m.SyncPackage.pack(0)).buffer)):(u.default.debug("设备返回状态为1,同步失败"),this.syncDataCallBack({event:"SYNC_FAIL"}));break}case"0054":{if(!this.syncDataCallBack)break;u.default.debug("设备上报离线数据");const t=new m.SyncPackage(s),i=m.DeletePackage.pack(t.id);u.default.debug("设备上报离线数据:payload",t.payload);try{u.default.debug("设备上报离线数据:timestemp",new Date(1e3*t.timestemp).toLocaleString())}catch(e){}const n=this.productInfo.find(e=>e.productKey===this.syncDevice.productKey);if(n){const e=yield b.uploadP0({device:this.syncDevice,data:[{raw:y.arrayToString(t.payload),created_at:t.timestemp}],productSecret:n.productSecret});u.default.debug("上传离线数据结果",e)}this.syncCurrnetNum+=1,this.syncDataCallBack({event:"SYNC_PROGRESS",totalNum:this.syncTotalNum,currentNum:this.syncCurrnetNum}),u.default.debug("通知设备删除:",t.id),yield this.bleHandle.write(e.deviceId,p.numberArray2Uint8Array(i).buffer),yield S.default(100),t.id<this.syncTotalNum-1?(u.default.debug("查询新数据:",t.id+1),yield this.bleHandle.write(e.deviceId,p.numberArray2Uint8Array(m.SyncPackage.pack(t.id+1)).buffer)):(u.default.debug("send cancel sync to device"),this.bleHandle.write(e.deviceId,p.numberArray2Uint8Array(m.CancelSync.pack()).buffer),this.syncDataCallBack({event:"SYNC_END"}),this.cleanSyncDeviceData());break}case"0058":{if(!this.syncDataCallBack)break;const e=new m.CancelSync(s);u.default.debug("设备上报停止同步 state:",e.state),0===e.state?this.syncDataCallBack({event:"SYNC_END"}):this.syncDataCallBack({event:"SYNC_FAIL"}),this.cleanSyncDeviceData();break}}}})),this.handleSocketDeviceData=e=>n(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>t.did===e.did);if(t){if(e.attrs&&null!=e.attrs.is_online){const i=e.attrs.is_online;this.setDeviceMeta(t,"isOnline",i)}this.listenerMap.GizDeviceAttrsNotifications&&(e.attrs&&(e.attrs=yield g.formatEnum(e.attrs,t.productKey,"int")),this.listenerMap.GizDeviceAttrsNotifications.map(i=>{i(Object.assign({device:t},"attrs"in e?{data:e.attrs}:{raw:e.raw}))}))}})),this.handleSocketStatus=(e,t)=>{const i=this.allDevices.filter(t=>e.includes(t.did)&&"WAN"===t.connectType);u.default.log("handleSocketStatus",e,t),i.forEach(e=>{this.setDeviceMeta(e,"connectType",t?"WAN":"NONE")})},this.notiDeviceList=()=>{var e,t;null===(e=this.listenerMap.GizDeviceListNotifications)||void 0===e||e.map(e=>{e(this.allDevices)}),null===(t=this.listenerMap.onScanListChange)||void 0===t||t.map(e=>{e(this.bleScanDevice)})},this.initLan=()=>{try{this.lanHandle.init(),this.lanHandle.addEventListener("GizLanDeviceList",this.handleLanDevices),this.lanHandle.addEventListener("GizLanDeviceData",this.handleLanDeviceData)}catch(e){u.default.error("init lan error",e)}},this.startAutoScan=e=>{this.keepScanTimer?u.default.warn("startAutoScan already started"):(this.keepScanTimer=setInterval(()=>n(this,void 0,void 0,(function*(){this.bleHandle.startScan(e=>{this.bleDevices=e},-1,e)})),9e3),this.bleHandle.startScan(e=>{this.bleDevices=e},-1,e))},this.stopAutoScan=()=>{this.keepScanTimer&&clearInterval(this.keepScanTimer),this.keepScanTimer=null,this.bleHandle.stopScan()},this.setDeviceMeta=(e,t,i,n=!1)=>{const s=this.allDevices.find(t=>t.mac===e.mac);s&&0!==this.allDevices.length&&(e[t]!==i||n)&&(s[t]=i,this.notiDeviceList())},this.getVersion=()=>({success:!0,data:this.version}),this.initBle=()=>n(this,void 0,void 0,(function*(){const e=yield this.bleHandle.checkPermission();return e.success?(this.bleHandle.addEventListener("GizBleDeviceData",this.handleBleDeviceData),this.bleHandle.addEventListener("GizBleDeviceList",this.handleBleDevices),this.bleHandle.addEventListener("GizBleError",this.handleBleError),u.default.debug("init BLE succcess",e),{success:!0}):(u.default.error("init BLE Error",new Error(JSON.stringify(e))),{success:!1,err:d.default.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON})})),this.scanBleDevice=(e,t)=>n(this,void 0,void 0,(function*(){return this.bleHandle.scanList=[],{success:!0,data:(yield this.bleHandle.startScan(e=>{this.bleDevices=e},e,t)).scanList}})),this.write=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>p.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};if("NONE"!==i.connectType){const{data:e,raw:n}=yield g.pack(t,i.productKey);switch(i.connectType){case"BLE_BROADCAST":return yield this.bleHandle.writeBoradcast(i.bleDeviceID,n.cmd);case"BLE":return e?yield this.bleHandle.write(i.bleDeviceID,p.numberArray2Uint8Array(e).buffer):{success:!1};case"WAN":{const e=yield g.formatEnum(t,i.productKey,"string");return this.socketHandle.writeData(i,e)}case"LAN":return this.lanHandle.write(i,p.numberArray2Uint8Array(e).buffer)}}return{success:!1}})),this.writeRaw=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>p.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};if("NONE"!==i.connectType)switch(i.connectType){case"BLE_BROADCAST":return yield this.bleHandle.writeBoradcast(i.bleDeviceID,t);case"BLE":return t?yield this.bleHandle.write(i.bleDeviceID,p.numberArray2Uint8Array(t).buffer):{success:!1};case"WAN":return this.socketHandle.send(i.did,t);case"LAN":return this.lanHandle.write(i,p.numberArray2Uint8Array(t).buffer)}return{success:!1}})),this.setDeviceTimeStamp=e=>n(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>p.isSameDevice(t,e));if(!t)return{success:!1,message:"target is undefind"};const i=w.default.pack();switch(t.connectType){case"BLE":return this.bleHandle.write(e.bleDeviceID,p.numberArray2Uint8Array(i).buffer)}return{success:!1,message:"the connectType not support set timestamp"}})),this.syncDeviceData=(e,t=(()=>{}))=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>p.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};if(!i.isBind)return{success:!1,message:"Only the bound devices are supported"};if(this.syncDevice)return{success:!1,message:"Synchronizing"};switch(this.syncDevice=Object.assign({},i),i.connectType){case"BLE":{u.default.debug("start syncDeviceData",e),this.syncDataCallBack=t,this.syncDataTimoutTimer=setTimeout(()=>{this.syncDataCallBack({event:"SYNC_FAIL",message:"sync timeout"}),this.cleanSyncDeviceData()},this.SYNC_TIMEOUT);const i=m.RequestSync.pack();return u.default.debug("sent RequestSync data"),this.bleHandle.write(e.bleDeviceID,p.numberArray2Uint8Array(i).buffer)}}return{success:!1,message:"the connectType not support sync data"}})),this.queryNeedSyncDataLength=e=>n(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>p.isSameDevice(t,e));if(!t)return{success:!1,message:"target is undefind"};if(!t.isBind)return{success:!1,message:"Only the bound devices are supported"};switch(t.connectType){case"BLE":{const i=m.RequestSync.pack();return this.syncDevice=Object.assign({},t),u.default.debug("sent RequestSync data len"),this.bleHandle.write(e.bleDeviceID,p.numberArray2Uint8Array(i).buffer),new Promise(e=>{this.syncDataLengthCallback=e,setTimeout(()=>{try{e({success:!1,message:"timeout"})}catch(e){}},3e3)})}}return{success:!1,message:"the connectType not support sync data"}})),this.cancelSyncDeviceData=()=>n(this,void 0,void 0,(function*(){this.cleanSyncDeviceData()})),this.cleanSyncDeviceData=()=>{this.syncDataCallBack&&(this.syncDataCallBack({event:"SYNC_CANCEL"}),this.syncDataCallBack=null),this.syncCurrnetNum=0,this.syncTotalNum=0,this.syncDevice=null,this.syncDataTimoutTimer&&clearTimeout(this.syncDataTimoutTimer)},this.getProductConfig=e=>n(this,void 0,void 0,(function*(){const t=yield v.default.getConfigFile(e);return t?{success:!0,data:t}:{success:!1}})),this.stopScanBleDevice=()=>{this.bleHandle.stopScan()},this.login=e=>n(this,void 0,void 0,(function*(){var t,i;const n=yield h.AnonymousLogin({uid:e});return n.success&&(s.setGlobalData("token",null===(t=n.data)||void 0===t?void 0:t.token),s.setGlobalData("uid",null===(i=n.data)||void 0===i?void 0:i.uid),this.socketHandle.updateToken({token:n.data.token,uid:n.data.uid})),n})),this.getDeviceStatus=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>p.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};switch(i.connectType){case"BLE":return yield this.bleHandle.getDeviceStatus(i.bleDeviceID,i.productKey,i.rootDeviceId,t);case"WAN":return this.socketHandle.readStatus(i,t);default:return{success:!1,message:"Device connectType is unsupported"}}})),this.subscribe=(e,t,i=!0)=>n(this,void 0,void 0,(function*(){u.default.debug("subscribe device:",e);let i=this.allDevices.find(t=>p.isSameDevice(t,e));if(!i)return u.default.warn("Device Target Not Found"),u.default.warn("current devices ",this.allDevices),{success:!1,message:"device not found"};if("BLE_BROADCAST"===i.connectType)return{success:!0};const n=p.getFirstConnectType(i,t);switch("NONE"!==i.connectType&&i.connectType!==n&&(yield this.unSubscribe(i)),n){case"BLE":{const e=yield this.bleHandle.connectDevice(i.bleDeviceID);return e.success&&(this.setDeviceMeta(i,"connectType","BLE",!0),setTimeout(()=>{this.setDeviceTimeStamp(i)},250),setTimeout(()=>{this.getDeviceStatus(i)},500)),e}case"WAN":{const t=this.socketHandle.connectDevice(i);return t.success&&this.setDeviceMeta(e,"connectType","WAN",!0),t}case"LAN":{const t=yield this.lanHandle.connectDevice(i);return t.success&&this.setDeviceMeta(e,"connectType","LAN",!0),t}}return{success:!1}})),this.unSubscribe=e=>n(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>p.isSameDevice(t,e));switch(t.connectType){case"BLE":{const e=yield this.bleHandle.disConnectDevice(t.bleDeviceID);return e.success&&this.setDeviceMeta(t,"connectType","NONE",!0),e}case"WAN":{const e=this.socketHandle.disConnectDevice(t);return e.success&&this.setDeviceMeta(t,"connectType","NONE",!0),e}case"LAN":{const e=this.lanHandle.disConnectDevice(t);return e.success&&this.setDeviceMeta(t,"connectType","NONE",!0),e}}return{success:!1}})),this.bindRemoteDevice=({mac:e,productKey:t,alias:i,beOwner:s})=>n(this,void 0,void 0,(function*(){const n=p.getProductInfoThroughPK(t,this.productInfo);if(n){const r=yield f.bindMac({mac:e,productKey:t,productSecret:n.productSecret,alias:i,beOwner:s});return this.getBindingList(),r}return{success:!1,err:d.default.GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY}})),this.checkUpdate=({device:e,type:t})=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>p.isSameDevice(t,e));if(i){if(!i.did)return{success:!1,err:d.default.GIZ_OPENAPI_DEVICE_NOT_BOUND};switch(i.connectType){case"BLE":return this.bleHandle.checkUpdate({device:e,type:t});default:return{success:!1,err:d.default.GIZ_SDK_OTA_DEVICE_NOT_SUPPORT}}}return{success:!1,err:d.default.GIZ_SDK_DEVICE_NOT_SUBSCRIBED}})),this.getDeviceInfo=({device:e})=>n(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>p.isSameDevice(t,e));if(t){if(!t.did)return{success:!1,err:d.default.GIZ_OPENAPI_DEVICE_NOT_BOUND};switch(t.connectType){case"BLE":return this.bleHandle.getDeviceInfo({deviceId:e.bleDeviceID});default:return{success:!1,err:d.default.GIZ_SDK_OTA_DEVICE_NOT_SUPPORT}}}return{success:!1,err:d.default.GIZ_SDK_DEVICE_NOT_SUBSCRIBED}})),this.startUpgrade=({device:e,type:t,onProgress:i,onEvent:s})=>n(this,void 0,void 0,(function*(){const n=this.allDevices.find(t=>p.isSameDevice(t,e));if(n){if(!n.did)return{success:!1,err:d.default.GIZ_OPENAPI_DEVICE_NOT_BOUND};switch(n.connectType){case"BLE":return this.bleHandle.startUpgrade({device:e,type:t,productKey:e.productKey,onProgress:i,onEvent:s});default:return{success:!1,err:d.default.GIZ_SDK_OTA_DEVICE_NOT_SUPPORT}}}return{success:!1,err:d.default.GIZ_SDK_DEVICE_NOT_SUBSCRIBED}})),this.unbindDevice=({devices:e})=>n(this,void 0,void 0,(function*(){const t=yield f.unbindDevice({devices:e});return t.success&&this.getBindingList(),t})),this.deviceSafetyRegister=({mac:e,productKey:t})=>n(this,void 0,void 0,(function*(){return yield this.deviceSafetyApi({mac:e,productKey:t,isReset:!1})})),this.deviceSafetyUnbind=({mac:e,productKey:t})=>n(this,void 0,void 0,(function*(){return yield this.deviceSafetyApi({mac:e,productKey:t,isReset:!0})})),this.setDeviceOnboardingDeploy=({ssid:e,password:t,mode:i=0,timeout:s,isBind:r=!0,softAPSSIDPrefix:a,productKeys:h})=>n(this,void 0,void 0,(function*(){if(this.currentWifiConfigHandle)return{success:!1,err:d.default.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING};const n=(new Date).getTime();u.default.debug("GIZ_SDK: 配网开始时间:"+n);try{switch(i){case 0:{this.currentWifiConfigHandle=new o.default(e,t,this.specialProductKeys,this.specialProductKeySecrets);const i=yield this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:s,isBind:r,softAPSSIDPrefix:a});this.currentWifiConfigHandle=null;const c=(new Date).getTime();return u.default.debug("GIZ_SDK: 配网结束时间:"+c),u.default.debug("GIZ_SDK: 配网用时:"+(c-n)),i}case 3:{this.currentWifiConfigHandle=new c.default(e,t,this.specialProductKeys,this.specialProductKeySecrets,this.bleHandle);const i=yield this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:s,isBind:r,softAPSSIDPrefix:a});this.currentWifiConfigHandle=null;const o=(new Date).getTime();return u.default.debug("GIZ_SDK: 配网结束时间:"+o),u.default.debug("GIZ_SDK: 配网用时:"+(o-n)),i}case 10:{this.currentWifiConfigHandle=new l.default(e,t,this.specialProductKeys,this.specialProductKeySecrets,this.bleHandle);const i=yield this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:s,isBind:r,softAPSSIDPrefix:a,productKeys:h});this.currentWifiConfigHandle=null;const o=(new Date).getTime();return u.default.debug("GIZ_SDK: 配网结束时间:"+o),u.default.debug("GIZ_SDK: 配网用时:"+(o-n)),i}}}catch(e){return u.default.error("GIZ_SDK: setDeviceOnboardingDeploy",new Error(JSON.stringify(e))),e.err&&e.err.errorCode?e:{success:!1,err:d.default.GIZ_SDK_OTHERWISE}}finally{this.currentWifiConfigHandle=null}})),this.setDomain=e=>{const t=e&&e.openAPIInfo||"api.gizwits.com",i=e&&e.aepInfo||"https://gj-app.iotsdk.com/",n=Object.assign(Object.assign({},e||{}),{openAPIInfo:t,aepInfo:i});s.setGlobalData("cloudServiceInfo",n)},this.deviceSafetyApi=({mac:e,productKey:t,isReset:i})=>n(this,void 0,void 0,(function*(){const n=p.getProductInfoThroughPK(t,this.productInfo);return n?yield f.safeRegister({productKey:t,productSecret:n.productSecret,mac:e,isReset:i,passcode:"1234567890"}):{success:!1,err:d.default.GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY}})),this.getBindingList=()=>n(this,void 0,void 0,(function*(){const e=yield f.getBindingList();return this.deviceList=e.data||[],e})),this.getDevices=()=>n(this,void 0,void 0,(function*(){return yield this.getBindingList(),{success:!0,data:this.allDevices}})),this.stopDeviceOnboardingDeploy=()=>{this.currentWifiConfigHandle&&(this.currentWifiConfigHandle.stopDeviceOnboardingDeploy(),this.currentWifiConfigHandle=null)},this.setLogLevel=e=>u.default.setLogLevel(e),this.renameDevice=(e,t)=>n(this,void 0,void 0,(function*(){return t?e.isBind?yield f.editBindInfo({did:e.did,name:t}):{success:!1,message:"device not bind"}:{success:!1,message:"please input device name"}})),this.removeEventListener=(e,t)=>{if(this.listenerMap[e]){const i=this.listenerMap[e].indexOf(t);if(-1!==i)return this.listenerMap[e].splice(i,1),{success:!0}}return{success:!1}},this.addEventListener=(e,t)=>n(this,void 0,void 0,(function*(){return this.listenerMap[e]||(this.listenerMap[e]=[]),-1===this.listenerMap[e].indexOf(t)&&this.listenerMap[e].push(t),{success:!0}})),this.destory=()=>{this.bleHandle.destory(),this.lanHandle.destory(),this.socketHandle.destory(),this.keepScanTimer&&clearInterval(this.keepScanTimer),this.keepScanTimer=null},this.productInfo=i,s.setGlobalData("appID",e),s.setGlobalData("appSecret",t),s.setGlobalData("productInfo",i),s.setGlobalData("token",a),s.setGlobalData("uid",_),this.setDomain(r),this.offlineThreshold=A,u.default.warn(`init sdk success, current version: ${this.version}`),this.initLan()}get deviceList(){return this._deviceList}set deviceList(e){this._deviceList=e,this.notiDeviceList()}get bleDevices(){return this._bleDevices}set bleDevices(e){this._bleDevices=e,this.notiDeviceList()}get lanDevices(){return this._lanDevices}set lanDevices(e){this._lanDevices=e,this.notiDeviceList()}get allDevices(){let e=p.merageBleLocalDevices([...this.deviceList],this.bleDevices);e=p.merageLanLocalDevices(e,this.lanDevices),this.bleHandle.connectedList.map(t=>{const i=e.findIndex(e=>e.bleDeviceID===t.deviceId);-1!==i&&(e[i].connectType="BLE")});const t=this.socketHandle._connections;return Object.keys(t).forEach(i=>{const n=t[i];n&&n._subDids.forEach(t=>{const i=e.findIndex(e=>e.did===t);-1!==i&&(e[i].connectType="WAN")})}),this.lanHandle.connectedList.map(t=>{const i=e.findIndex(e=>e.mac===t.mac&&e.productKey===t.productKey);-1!==i&&(e[i].connectType="LAN")}),console.log("newDevices",e),e}get bleScanDevice(){return this.bleDevices.filter(e=>!0===e.isBleOnline)}get bleHandle(){return this._bleHandle||(this._bleHandle=new r.BleHandle({pks:this.specialProductKeys,offlineThreshold:this.offlineThreshold})),this._bleHandle}get lanHandle(){return this._lanHandle||(this._lanHandle=new _.LanHandle({pks:this.specialProductKeys})),this._lanHandle}get socketHandle(){return this._gizSocket||(this._gizSocket=new a.default({appID:s.getGlobalData("appID"),token:s.getGlobalData("token"),uid:s.getGlobalData("uid")}),this._gizSocket.subscribeDeviceStatus(this.handleSocketDeviceData),this._gizSocket.subscribeBindingChanged(this.getBindingList),this._gizSocket.subscribeSocketStatus(this.handleSocketStatus)),this._gizSocket}get specialProductKeys(){return this.productInfo.map(e=>{var t;return null!==(t=e.productKey)&&void 0!==t?t:""})}get specialProductKeySecrets(){return this.productInfo.map(e=>{var t;return null!==(t=e.productSecret)&&void 0!==t?t:""})}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(11),s=i(18);t.default=e=>{const t=wx.getSystemInfoSync(),i={exception:{values:[{type:"Error",value:e.stack,stacktrace:{},mechanism:{type:"generic",handled:!0}}]},level:"error",event_id:n.MD5(`${(new Date).getTime()}`).toString(),platform:"javascript",sdk:{},timestamp:(new Date).getTime()/1e3,environment:"production",contexts:{device:{},os:{name:t.platform,version:t.version},extra:{}},extra:{message:e.message}};var r={method:"POST",headers:{Connection:"keep-alive","User-Agent":"Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1 wechatdevtools/1.06.2206090 MicroMessenger/8.0.5 Language/zh_CN webview/","content-type":"application/json",Accept:"*/*","Sec-Fetch-Site":"cross-site","Sec-Fetch-Mode":"cors","Sec-Fetch-Dest":"empty",Referer:"https://servicewechat.com/wx6dc8e50cb68bc121/devtools/page-frame.html",Cookie:"__org="},data:JSON.stringify(i)};s.default("https://appmonitor.gizwits.com/api/21/store/?sentry_key=0b2de791abf548a1bedf0b0ebdd8ecc7&sentry_version=7",r)}},function(e,t){},function(e,t,i){var n;e.exports=(n=i(0),function(){if("function"==typeof ArrayBuffer){var e=n.lib.WordArray,t=e.init;(e.init=function(e){if(e instanceof ArrayBuffer&&(e=new Uint8Array(e)),(e instanceof Int8Array||"undefined"!=typeof Uint8ClampedArray&&e instanceof Uint8ClampedArray||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array)&&(e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),e instanceof Uint8Array){for(var i=e.byteLength,n=[],s=0;s<i;s++)n[s>>>2]|=e[s]<<24-s%4*8;t.call(this,n,i)}else t.apply(this,arguments)}).prototype=e}}(),n.lib.WordArray)},function(e,t,i){var n;e.exports=(n=i(0),function(){var e=n,t=e.lib.WordArray,i=e.enc;function s(e){return e<<8&4278255360|e>>>8&16711935}i.Utf16=i.Utf16BE={stringify:function(e){for(var t=e.words,i=e.sigBytes,n=[],s=0;s<i;s+=2){var r=t[s>>>2]>>>16-s%4*8&65535;n.push(String.fromCharCode(r))}return n.join("")},parse:function(e){for(var i=e.length,n=[],s=0;s<i;s++)n[s>>>1]|=e.charCodeAt(s)<<16-s%2*16;return t.create(n,2*i)}},i.Utf16LE={stringify:function(e){for(var t=e.words,i=e.sigBytes,n=[],r=0;r<i;r+=2){var a=s(t[r>>>2]>>>16-r%4*8&65535);n.push(String.fromCharCode(a))}return n.join("")},parse:function(e){for(var i=e.length,n=[],r=0;r<i;r++)n[r>>>1]|=s(e.charCodeAt(r)<<16-r%2*16);return t.create(n,2*i)}}}(),n.enc.Utf16)},function(e,t,i){var n,s,r;e.exports=(r=i(0),s=(n=r).lib.WordArray,n.enc.Base64url={stringify:function(e,t){void 0===t&&(t=!0);var i=e.words,n=e.sigBytes,s=t?this._safe_map:this._map;e.clamp();for(var r=[],a=0;a<n;a+=3)for(var o=(i[a>>>2]>>>24-a%4*8&255)<<16|(i[a+1>>>2]>>>24-(a+1)%4*8&255)<<8|i[a+2>>>2]>>>24-(a+2)%4*8&255,c=0;c<4&&a+.75*c<n;c++)r.push(s.charAt(o>>>6*(3-c)&63));var l=s.charAt(64);if(l)for(;r.length%4;)r.push(l);return r.join("")},parse:function(e,t){void 0===t&&(t=!0);var i=e.length,n=t?this._safe_map:this._map,r=this._reverseMap;if(!r){r=this._reverseMap=[];for(var a=0;a<n.length;a++)r[n.charCodeAt(a)]=a}var o=n.charAt(64);if(o){var c=e.indexOf(o);-1!==c&&(i=c)}return function(e,t,i){for(var n=[],r=0,a=0;a<t;a++)if(a%4){var o=i[e.charCodeAt(a-1)]<<a%4*2,c=i[e.charCodeAt(a)]>>>6-a%4*2,l=o|c;n[r>>>2]|=l<<24-r%4*8,r++}return s.create(n,r)}(e,i,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",_safe_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"},r.enc.Base64url)},function(e,t,i){var n,s,r,a,o,c;e.exports=(c=i(0),i(16),s=(n=c).lib.WordArray,r=n.algo,a=r.SHA256,o=r.SHA224=a.extend({_doReset:function(){this._hash=new s.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var e=a._doFinalize.call(this);return e.sigBytes-=4,e}}),n.SHA224=a._createHelper(o),n.HmacSHA224=a._createHmacHelper(o),c.SHA224)},function(e,t,i){var n,s,r,a,o,c,l,u;e.exports=(u=i(0),i(13),i(25),s=(n=u).x64,r=s.Word,a=s.WordArray,o=n.algo,c=o.SHA512,l=o.SHA384=c.extend({_doReset:function(){this._hash=new a.init([new r.init(3418070365,3238371032),new r.init(1654270250,914150663),new r.init(2438529370,812702999),new r.init(355462360,4144912697),new r.init(1731405415,4290775857),new r.init(2394180231,1750603025),new r.init(3675008525,1694076839),new r.init(1203062813,3204075428)])},_doFinalize:function(){var e=c._doFinalize.call(this);return e.sigBytes-=16,e}}),n.SHA384=c._createHelper(l),n.HmacSHA384=c._createHmacHelper(l),u.SHA384)},function(e,t,i){var n;e.exports=(n=i(0),i(13),function(e){var t=n,i=t.lib,s=i.WordArray,r=i.Hasher,a=t.x64.Word,o=t.algo,c=[],l=[],u=[];!function(){for(var e=1,t=0,i=0;i<24;i++){c[e+5*t]=(i+1)*(i+2)/2%64;var n=(2*e+3*t)%5;e=t%5,t=n}for(e=0;e<5;e++)for(t=0;t<5;t++)l[e+5*t]=t+(2*e+3*t)%5*5;for(var s=1,r=0;r<24;r++){for(var o=0,d=0,h=0;h<7;h++){if(1&s){var f=(1<<h)-1;f<32?d^=1<<f:o^=1<<f-32}128&s?s=s<<1^113:s<<=1}u[r]=a.create(o,d)}}();var d=[];!function(){for(var e=0;e<25;e++)d[e]=a.create()}();var h=o.SHA3=r.extend({cfg:r.cfg.extend({outputLength:512}),_doReset:function(){for(var e=this._state=[],t=0;t<25;t++)e[t]=new a.init;this.blockSize=(1600-2*this.cfg.outputLength)/32},_doProcessBlock:function(e,t){for(var i=this._state,n=this.blockSize/2,s=0;s<n;s++){var r=e[t+2*s],a=e[t+2*s+1];r=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),a=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),(C=i[s]).high^=a,C.low^=r}for(var o=0;o<24;o++){for(var h=0;h<5;h++){for(var f=0,p=0,v=0;v<5;v++)f^=(C=i[h+5*v]).high,p^=C.low;var g=d[h];g.high=f,g.low=p}for(h=0;h<5;h++){var y=d[(h+4)%5],_=d[(h+1)%5],D=_.high,m=_.low;for(f=y.high^(D<<1|m>>>31),p=y.low^(m<<1|D>>>31),v=0;v<5;v++)(C=i[h+5*v]).high^=f,C.low^=p}for(var b=1;b<25;b++){var S=(C=i[b]).high,w=C.low,I=c[b];I<32?(f=S<<I|w>>>32-I,p=w<<I|S>>>32-I):(f=w<<I-32|S>>>64-I,p=S<<I-32|w>>>64-I);var B=d[l[b]];B.high=f,B.low=p}var A=d[0],k=i[0];for(A.high=k.high,A.low=k.low,h=0;h<5;h++)for(v=0;v<5;v++){var C=i[b=h+5*v],E=d[b],T=d[(h+1)%5+5*v],P=d[(h+2)%5+5*v];C.high=E.high^~T.high&P.high,C.low=E.low^~T.low&P.low}C=i[0];var O=u[o];C.high^=O.high,C.low^=O.low}},_doFinalize:function(){var t=this._data,i=t.words,n=(this._nDataBytes,8*t.sigBytes),r=32*this.blockSize;i[n>>>5]|=1<<24-n%32,i[(e.ceil((n+1)/r)*r>>>5)-1]|=128,t.sigBytes=4*i.length,this._process();for(var a=this._state,o=this.cfg.outputLength/8,c=o/8,l=[],u=0;u<c;u++){var d=a[u],h=d.high,f=d.low;h=16711935&(h<<8|h>>>24)|4278255360&(h<<24|h>>>8),f=16711935&(f<<8|f>>>24)|4278255360&(f<<24|f>>>8),l.push(f),l.push(h)}return new s.init(l,o)},clone:function(){for(var e=r.clone.call(this),t=e._state=this._state.slice(0),i=0;i<25;i++)t[i]=t[i].clone();return e}});t.SHA3=r._createHelper(h),t.HmacSHA3=r._createHmacHelper(h)}(Math),n.SHA3)},function(e,t,i){var n;e.exports=(n=i(0),
|
|
1
|
+
module.exports=function(e){var t={};function i(n){if(t[n])return t[n].exports;var s=t[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,i),s.l=!0,s.exports}return i.m=e,i.c=t,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)i.d(n,s,function(t){return e[t]}.bind(null,s));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=34)}([function(e,t,i){(function(t){var n;e.exports=(n=n||function(e,n){var s;if("undefined"!=typeof window&&window.crypto&&(s=window.crypto),"undefined"!=typeof self&&self.crypto&&(s=self.crypto),"undefined"!=typeof globalThis&&globalThis.crypto&&(s=globalThis.crypto),!s&&"undefined"!=typeof window&&window.msCrypto&&(s=window.msCrypto),!s&&void 0!==t&&t.crypto&&(s=t.crypto),!s)try{s=i(38)}catch(e){}var r=function(){if(s){if("function"==typeof s.getRandomValues)try{return s.getRandomValues(new Uint32Array(1))[0]}catch(e){}if("function"==typeof s.randomBytes)try{return s.randomBytes(4).readInt32LE()}catch(e){}}throw new Error("Native crypto module could not be used to get secure random number.")},a=Object.create||function(){function e(){}return function(t){var i;return e.prototype=t,i=new e,e.prototype=null,i}}(),o={},c=o.lib={},l=c.Base={extend:function(e){var t=a(this);return e&&t.mixIn(e),t.hasOwnProperty("init")&&this.init!==t.init||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},u=c.WordArray=l.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||h).stringify(this)},concat:function(e){var t=this.words,i=e.words,n=this.sigBytes,s=e.sigBytes;if(this.clamp(),n%4)for(var r=0;r<s;r++){var a=i[r>>>2]>>>24-r%4*8&255;t[n+r>>>2]|=a<<24-(n+r)%4*8}else for(var o=0;o<s;o+=4)t[n+o>>>2]=i[o>>>2];return this.sigBytes+=s,this},clamp:function(){var t=this.words,i=this.sigBytes;t[i>>>2]&=4294967295<<32-i%4*8,t.length=e.ceil(i/4)},clone:function(){var e=l.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var t=[],i=0;i<e;i+=4)t.push(r());return new u.init(t,e)}}),d=o.enc={},h=d.Hex={stringify:function(e){for(var t=e.words,i=e.sigBytes,n=[],s=0;s<i;s++){var r=t[s>>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,i=[],n=0;n<t;n+=2)i[n>>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new u.init(i,t/2)}},f=d.Latin1={stringify:function(e){for(var t=e.words,i=e.sigBytes,n=[],s=0;s<i;s++){var r=t[s>>>2]>>>24-s%4*8&255;n.push(String.fromCharCode(r))}return n.join("")},parse:function(e){for(var t=e.length,i=[],n=0;n<t;n++)i[n>>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new u.init(i,t)}},p=d.Utf8={stringify:function(e){try{return decodeURIComponent(escape(f.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return f.parse(unescape(encodeURIComponent(e)))}},v=c.BufferedBlockAlgorithm=l.extend({reset:function(){this._data=new u.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=p.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var i,n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a),c=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,l=e.min(4*c,r);if(c){for(var d=0;d<c;d+=a)this._doProcessBlock(s,d);i=s.splice(0,c),n.sigBytes-=l}return new u.init(i,l)},clone:function(){var e=l.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0}),g=(c.Hasher=v.extend({cfg:l.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){v.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,i){return new e.init(i).finalize(t)}},_createHmacHelper:function(e){return function(t,i){return new g.HMAC.init(e,i).finalize(t)}}}),o.algo={});return o}(Math),n)}).call(this,i(23))},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(3);class s{constructor(e){this.header="",this.len=0,this.flag=[0],this.cmd="",this.content=[],this.formatP0=e=>{let t=n.checkHeader(e);if(!1===t)throw new Error("Header Error");this.header=n.arrayToString(e.slice(0,t));const i=e.slice(t,e.length),r=n.getProtocolLen(i);this.len=s.decodeLen(i.slice(0,r)),t+=r,this.flag=e.slice(t,t+1),t+=1,this.cmd=n.arrayToString(e.slice(t,t+2)),t+=2,this.content=e.slice(t,e.length)},e&&e.length>0&&this.formatP0(e)}}s.decodeLen=e=>{let t=1,i=0,n=0,s=0;do{n=e[s],i+=(127&n)*t,t*=128,s+=1}while(0!=(128&n));return i},t.default=s},function(e,t,i){var n,s,r,a,o,c,l,u,d,h,f,p,v,g,y,D,_,m,b;e.exports=(n=i(0),i(6),void(n.lib.Cipher||(s=n,r=s.lib,a=r.Base,o=r.WordArray,c=r.BufferedBlockAlgorithm,l=s.enc,l.Utf8,u=l.Base64,d=s.algo.EvpKDF,h=r.Cipher=c.extend({cfg:a.extend(),createEncryptor:function(e,t){return this.create(this._ENC_XFORM_MODE,e,t)},createDecryptor:function(e,t){return this.create(this._DEC_XFORM_MODE,e,t)},init:function(e,t,i){this.cfg=this.cfg.extend(i),this._xformMode=e,this._key=t,this.reset()},reset:function(){c.reset.call(this),this._doReset()},process:function(e){return this._append(e),this._process()},finalize:function(e){return e&&this._append(e),this._doFinalize()},keySize:4,ivSize:4,_ENC_XFORM_MODE:1,_DEC_XFORM_MODE:2,_createHelper:function(){function e(e){return"string"==typeof e?b:_}return function(t){return{encrypt:function(i,n,s){return e(n).encrypt(t,i,n,s)},decrypt:function(i,n,s){return e(n).decrypt(t,i,n,s)}}}}()}),r.StreamCipher=h.extend({_doFinalize:function(){return this._process(!0)},blockSize:1}),f=s.mode={},p=r.BlockCipherMode=a.extend({createEncryptor:function(e,t){return this.Encryptor.create(e,t)},createDecryptor:function(e,t){return this.Decryptor.create(e,t)},init:function(e,t){this._cipher=e,this._iv=t}}),v=f.CBC=function(){var e=p.extend();function t(e,t,i){var n,s=this._iv;s?(n=s,this._iv=void 0):n=this._prevBlock;for(var r=0;r<i;r++)e[t+r]^=n[r]}return e.Encryptor=e.extend({processBlock:function(e,i){var n=this._cipher,s=n.blockSize;t.call(this,e,i,s),n.encryptBlock(e,i),this._prevBlock=e.slice(i,i+s)}}),e.Decryptor=e.extend({processBlock:function(e,i){var n=this._cipher,s=n.blockSize,r=e.slice(i,i+s);n.decryptBlock(e,i),t.call(this,e,i,s),this._prevBlock=r}}),e}(),g=(s.pad={}).Pkcs7={pad:function(e,t){for(var i=4*t,n=i-e.sigBytes%i,s=n<<24|n<<16|n<<8|n,r=[],a=0;a<n;a+=4)r.push(s);var c=o.create(r,n);e.concat(c)},unpad:function(e){var t=255&e.words[e.sigBytes-1>>>2];e.sigBytes-=t}},r.BlockCipher=h.extend({cfg:h.cfg.extend({mode:v,padding:g}),reset:function(){var e;h.reset.call(this);var t=this.cfg,i=t.iv,n=t.mode;this._xformMode==this._ENC_XFORM_MODE?e=n.createEncryptor:(e=n.createDecryptor,this._minBufferSize=1),this._mode&&this._mode.__creator==e?this._mode.init(this,i&&i.words):(this._mode=e.call(n,this,i&&i.words),this._mode.__creator=e)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e,t=this.cfg.padding;return this._xformMode==this._ENC_XFORM_MODE?(t.pad(this._data,this.blockSize),e=this._process(!0)):(e=this._process(!0),t.unpad(e)),e},blockSize:4}),y=r.CipherParams=a.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),D=(s.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext,i=e.salt;return(i?o.create([1398893684,1701076831]).concat(i).concat(t):t).toString(u)},parse:function(e){var t,i=u.parse(e),n=i.words;return 1398893684==n[0]&&1701076831==n[1]&&(t=o.create(n.slice(2,4)),n.splice(0,4),i.sigBytes-=16),y.create({ciphertext:i,salt:t})}},_=r.SerializableCipher=a.extend({cfg:a.extend({format:D}),encrypt:function(e,t,i,n){n=this.cfg.extend(n);var s=e.createEncryptor(i,n),r=s.finalize(t),a=s.cfg;return y.create({ciphertext:r,key:i,iv:a.iv,algorithm:e,mode:a.mode,padding:a.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,i,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(i,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}}),m=(s.kdf={}).OpenSSL={execute:function(e,t,i,n,s){if(n||(n=o.random(8)),s)r=d.create({keySize:t+i,hasher:s}).compute(e,n);else var r=d.create({keySize:t+i}).compute(e,n);var a=o.create(r.words.slice(t),4*i);return r.sigBytes=4*t,y.create({key:r,iv:a,salt:n})}},b=r.PasswordBasedCipher=_.extend({cfg:_.cfg.extend({kdf:m}),encrypt:function(e,t,i,n){var s=(n=this.cfg.extend(n)).kdf.execute(i,e.keySize,e.ivSize,n.salt,n.hasher);n.iv=s.iv;var r=_.encrypt.call(this,e,t,s.key,n);return r.mixIn(s),r},decrypt:function(e,t,i,n){n=this.cfg.extend(n),t=this._parse(t,n.format);var s=n.kdf.execute(i,e.keySize,e.ivSize,t.salt,n.hasher);return n.iv=s.iv,_.decrypt.call(this,e,t,s.key,n)}}))))},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.checkHeader=e=>{let t=0;return 0===e[0]&&0===e[1]&&0===e[2]&&3===e[3]&&(t=4,4)},t.completeBlock=e=>{const t=n(e,8*Math.ceil(e.length/8)),i=[];for(let e=0;e<t.length;e+=8)i.push(parseInt(t.substring(e,e+8),2));return i};t.getProtocolLen=e=>{let t=0;for(;t<e.length&&"1"===n(e[t].toString(2),8)[0];t++);return t+1},t.arrayToString=function(e){let t="";return e.map(e=>(t+=n(e.toString(16),2),null)),t},t.arrayToASCII=function(e){let t="";return e.map(e=>(t+=String.fromCharCode(e),null)),t};const n=(e,t,i=!1)=>{const n=t-e.length,s=new Array(n).fill(0).join("");return i?e+=s:e=s+e,e};t.fillString=n;t.bytesToInt=e=>{let t=0;for(let i=0;i<e.length;i++)t=t<<8|e[i];return t};t.bytesToHexString=e=>Array.from(e,e=>("0"+e.toString(16)).slice(-2)).join("");t.string2Bytes=e=>{const t=[];for(let i=0;i<e.length;i++)t.push(e.charCodeAt(i));return t};t.hexStrint2byte=e=>{e.length%2!=0&&(e=`0${e}`);const t=Math.ceil(e.length/2),i=[];for(let n=0;n<t;n++){const t=2*n,s=t+2,r=e.substring(t,s);i.push(parseInt(r,16))}return i};const s=e=>{const t=encodeURI(e);return-1!==t.indexOf("%")&&"%"!==e?t.split("%").filter(e=>""!==e).map(e=>parseInt(e,16)):[t.charCodeAt(0)]};t.formatCode=s;t.formatCodesFromStr=e=>{const t=[0,0];let i=[];for(let n=0;n<e.length;n++){const r=s(e[n]);t[1]+=r.length,i=i.concat(r)}return[i,t]};t.arrayToUint8=e=>{const t=new ArrayBuffer(e.length),i=new Uint8Array(t);for(let n=0;n<t.byteLength;n++)i[n]=e[n];return i}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(5),s=i(37);t.default=new class{constructor(){this.logMap=[{id:"debug"},{id:"info"},{id:"warn"},{id:"error"}],this.console=console,this.debug=(...e)=>{this.console.debug(...e)},this.info=(...e)=>{this.console.info(...e)},this.log=(...e)=>{this.console.log(...e)},this.warn=(...e)=>{this.console.warn(...e)},this.error=(e,t)=>{this.console.error(e,t),s.default(t)},this.setLogLevel=e=>{const t=this.logMap.findIndex(t=>t.id===e);return-1!==t?(this.console=Object.assign({},console),this.logMap.map((e,i)=>{i<t&&(this.console[e.id]=()=>{})}),{success:!0,err:null}):{success:!1,err:n.default.GIZ_SDK_LOG_LEVEL_INVALID}}}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default={GIZ_OPENAPI_DEVICE_NOT_BOUND:{errorCode:9017,errorMessage:"not bind"},GIZ_SDK_HTTP_REQUEST_FAILED:{errorCode:8099,errorMessage:"网络请求失败"},GIZ_SDK_DEVICE_NO_RESPONSE:{errorCode:8030,errorMessage:"设备未响应"},GIZ_SDK_SDK_NOT_INITIALIZED:{errorCode:8300,errorMessage:"not init"},CONFIG_TIME_OUT:{errorCode:8023,errorMessage:"Config Timeout"},WECHAT_ERROR:{errorCode:1e4,errorMessage:"wechat error"},GIZ_SDK_ONBOARDING_STOPPED:{errorCode:8318,errorMessage:"配网中断"},GIZ_SDK_DEVICE_CONFIG_IS_RUNNING:{errorCode:8022,errorMessage:"配置正在进行中"},GIZ_OPENAPI_TOKEN_INVALID:{errorCode:9004,errorMessage:"token 失效"},GIZ_SDK_BIND_DEVICE_FAILED:{errorCode:8039,errorMessage:"设备绑定失败"},GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON:{errorCode:8281,errorMessage:"蓝牙未启用"},GIZ_SDK_OTHERWISE:{errorCode:8100,errorMessage:""},GIZ_SDK_DEVICE_NOT_SUBSCRIBED:{errorCode:8029,errorMessage:"设备还未订阅"},GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY:{errorCode:8250,errorMessage:"产品类型不在指定范围内"},GIZ_SDK_LOG_LEVEL_INVALID:{errorCode:8009,errorMessage:"产品类型不在指定范围内"},GIZ_SDK_OTA_DEVICE_NOT_SUPPORT:{errorCode:8360,errorMessage:"设备不支持手机OTA升级"},GIZ_SDK_OTA_DEVICE_BUSY_IN_UPGRADE:{errorCode:8354,errorMessage:"设备忙,固件正在升级"},GIZ_SDK_OTA_FIRMWARE_DOWNLOAD_FAILED:{errorCode:8353,errorMessage:"固件下载失败"},GIZ_SDK_OTA_FIRMWARE_TYPE_NOT_MATCH:{errorCode:8361,errorMessage:"蓝牙OTA设备返回的固件类型与当前要升级的固件类型不匹配"}}},function(e,t,i){var n,s,r,a,o,c,l,u;e.exports=(u=i(0),i(24),i(17),s=(n=u).lib,r=s.Base,a=s.WordArray,o=n.algo,c=o.MD5,l=o.EvpKDF=r.extend({cfg:r.extend({keySize:4,hasher:c,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var i,n=this.cfg,s=n.hasher.create(),r=a.create(),o=r.words,c=n.keySize,l=n.iterations;o.length<c;){i&&s.update(i),i=s.update(e).finalize(t),s.reset();for(var u=1;u<l;u++)i=s.finalize(i),s.reset();r.concat(i)}return r.sigBytes=4*c,r}}),n.EvpKDF=function(e,t,i){return l.create(i).compute(e,t)},u.EvpKDF)},function(e,t,i){var n,s,r;e.exports=(r=i(0),s=(n=r).lib.WordArray,n.enc.Base64={stringify:function(e){var t=e.words,i=e.sigBytes,n=this._map;e.clamp();for(var s=[],r=0;r<i;r+=3)for(var a=(t[r>>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;o<4&&r+.75*o<i;o++)s.push(n.charAt(a>>>6*(3-o)&63));var c=n.charAt(64);if(c)for(;s.length%4;)s.push(c);return s.join("")},parse:function(e){var t=e.length,i=this._map,n=this._reverseMap;if(!n){n=this._reverseMap=[];for(var r=0;r<i.length;r++)n[i.charCodeAt(r)]=r}var a=i.charAt(64);if(a){var o=e.indexOf(a);-1!==o&&(t=o)}return function(e,t,i){for(var n=[],r=0,a=0;a<t;a++)if(a%4){var o=i[e.charCodeAt(a-1)]<<a%4*2,c=i[e.charCodeAt(a)]>>>6-a%4*2,l=o|c;n[r>>>2]|=l<<24-r%4*8,r++}return s.create(n,r)}(e,t,n)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},r.enc.Base64)},function(e,t,i){var n;e.exports=(n=i(0),function(e){var t=n,i=t.lib,s=i.WordArray,r=i.Hasher,a=t.algo,o=[];!function(){for(var t=0;t<64;t++)o[t]=4294967296*e.abs(e.sin(t+1))|0}();var c=a.MD5=r.extend({_doReset:function(){this._hash=new s.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,t){for(var i=0;i<16;i++){var n=t+i,s=e[n];e[n]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8)}var r=this._hash.words,a=e[t+0],c=e[t+1],f=e[t+2],p=e[t+3],v=e[t+4],g=e[t+5],y=e[t+6],D=e[t+7],_=e[t+8],m=e[t+9],b=e[t+10],S=e[t+11],w=e[t+12],I=e[t+13],B=e[t+14],A=e[t+15],k=r[0],C=r[1],E=r[2],T=r[3];k=l(k,C,E,T,a,7,o[0]),T=l(T,k,C,E,c,12,o[1]),E=l(E,T,k,C,f,17,o[2]),C=l(C,E,T,k,p,22,o[3]),k=l(k,C,E,T,v,7,o[4]),T=l(T,k,C,E,g,12,o[5]),E=l(E,T,k,C,y,17,o[6]),C=l(C,E,T,k,D,22,o[7]),k=l(k,C,E,T,_,7,o[8]),T=l(T,k,C,E,m,12,o[9]),E=l(E,T,k,C,b,17,o[10]),C=l(C,E,T,k,S,22,o[11]),k=l(k,C,E,T,w,7,o[12]),T=l(T,k,C,E,I,12,o[13]),E=l(E,T,k,C,B,17,o[14]),k=u(k,C=l(C,E,T,k,A,22,o[15]),E,T,c,5,o[16]),T=u(T,k,C,E,y,9,o[17]),E=u(E,T,k,C,S,14,o[18]),C=u(C,E,T,k,a,20,o[19]),k=u(k,C,E,T,g,5,o[20]),T=u(T,k,C,E,b,9,o[21]),E=u(E,T,k,C,A,14,o[22]),C=u(C,E,T,k,v,20,o[23]),k=u(k,C,E,T,m,5,o[24]),T=u(T,k,C,E,B,9,o[25]),E=u(E,T,k,C,p,14,o[26]),C=u(C,E,T,k,_,20,o[27]),k=u(k,C,E,T,I,5,o[28]),T=u(T,k,C,E,f,9,o[29]),E=u(E,T,k,C,D,14,o[30]),k=d(k,C=u(C,E,T,k,w,20,o[31]),E,T,g,4,o[32]),T=d(T,k,C,E,_,11,o[33]),E=d(E,T,k,C,S,16,o[34]),C=d(C,E,T,k,B,23,o[35]),k=d(k,C,E,T,c,4,o[36]),T=d(T,k,C,E,v,11,o[37]),E=d(E,T,k,C,D,16,o[38]),C=d(C,E,T,k,b,23,o[39]),k=d(k,C,E,T,I,4,o[40]),T=d(T,k,C,E,a,11,o[41]),E=d(E,T,k,C,p,16,o[42]),C=d(C,E,T,k,y,23,o[43]),k=d(k,C,E,T,m,4,o[44]),T=d(T,k,C,E,w,11,o[45]),E=d(E,T,k,C,A,16,o[46]),k=h(k,C=d(C,E,T,k,f,23,o[47]),E,T,a,6,o[48]),T=h(T,k,C,E,D,10,o[49]),E=h(E,T,k,C,B,15,o[50]),C=h(C,E,T,k,g,21,o[51]),k=h(k,C,E,T,w,6,o[52]),T=h(T,k,C,E,p,10,o[53]),E=h(E,T,k,C,b,15,o[54]),C=h(C,E,T,k,c,21,o[55]),k=h(k,C,E,T,_,6,o[56]),T=h(T,k,C,E,A,10,o[57]),E=h(E,T,k,C,y,15,o[58]),C=h(C,E,T,k,I,21,o[59]),k=h(k,C,E,T,v,6,o[60]),T=h(T,k,C,E,S,10,o[61]),E=h(E,T,k,C,f,15,o[62]),C=h(C,E,T,k,m,21,o[63]),r[0]=r[0]+k|0,r[1]=r[1]+C|0,r[2]=r[2]+E|0,r[3]=r[3]+T|0},_doFinalize:function(){var t=this._data,i=t.words,n=8*this._nDataBytes,s=8*t.sigBytes;i[s>>>5]|=128<<24-s%32;var r=e.floor(n/4294967296),a=n;i[15+(s+64>>>9<<4)]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),i[14+(s+64>>>9<<4)]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),t.sigBytes=4*(i.length+1),this._process();for(var o=this._hash,c=o.words,l=0;l<4;l++){var u=c[l];c[l]=16711935&(u<<8|u>>>24)|4278255360&(u<<24|u>>>8)}return o},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});function l(e,t,i,n,s,r,a){var o=e+(t&i|~t&n)+s+a;return(o<<r|o>>>32-r)+t}function u(e,t,i,n,s,r,a){var o=e+(t&n|i&~n)+s+a;return(o<<r|o>>>32-r)+t}function d(e,t,i,n,s,r,a){var o=e+(t^i^n)+s+a;return(o<<r|o>>>32-r)+t}function h(e,t,i,n,s,r,a){var o=e+(i^(t|~n))+s+a;return(o<<r|o>>>32-r)+t}t.MD5=r._createHelper(c),t.HmacMD5=r._createHmacHelper(c)}(Math),n.MD5)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=e=>new Promise(t=>setTimeout(()=>t(),e))},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(4),s=i(0);function r(e){return Array.prototype.map.call(new Uint8Array(e),(function(e){return("00"+e.toString(16)).slice(-2)})).join("")}t.ab2hex=r,t.compareWXSDKVersion=function(e,t){const i=e.split("."),n=t.split("."),s=Math.max(e.length,t.length);for(;i.length<s;)i.push("0");for(;n.length<s;)n.push("0");for(let i=0;i<s;i++){const n=parseInt(e[i]),s=parseInt(t[i]);if(n>s)return 1;if(n<s)return-1}return 0},t.isError=e=>null!=e&&"symbol"==typeof e.errorCode,t.wrapErrorInfo=e=>({errorCode:e,errorMessage:e}),t.unionBy=(e,t)=>e.reduce((e,i)=>{const n=i[t];return e.some(e=>e[t]===n)||e.push(i),e},[]),t.isWXDevicesResult=function(e){return e.success&&"[object Array]"===Object.prototype.toString.call(e.bleDevices)},t.str2Buf=function(e){var t=e.length,i=new ArrayBuffer(t+2),n=new DataView(i);for(let i=0;i<t;i++)n.setUint8(i,parseInt(e[i],16));return i},t.numberArray2Uint8Array=e=>{const t=new ArrayBuffer(e.length),i=new Uint8Array(t);for(let n=0;n<t.byteLength;n++)i[n]=e[n];return i};function a(e){if(25!=(e=e.slice(0,25)).length)throw new Error("数据不合法");const t=`${c(e[0])}${c(e[1])}`;if(e[2]!==(255&e.slice(3).reduce((e,t)=>e+t,0)))throw new Error("校验和不合法");const i=c(e[3]),n=e.slice(5,5+e[4]).map(e=>c(e));return{mac:t,cmd:parseInt(i,16),data:n}}function o(e){return Array.prototype.map.call(new Uint8Array(e),(function(e){return e}))}function c(e,t=2){return`${new Array(t).fill(0).join("")}${e.toString(16)}`.slice(-t)}t.advertisData2PkAndMac=(e,t)=>e&&e.byteLength>=22&&e.byteLength<=24?Object.assign(Object.assign({},((e,t)=>{let i=e.slice(e.byteLength-16),n=e.slice(0,e.byteLength-16),s=r(i);if(t.find(e=>e===s)){const e=r(n);return{productKey:s,mac:e}}{i=e.slice(0,16),n=e.slice(16),s=r(i);const t=r(n);return{productKey:s,mac:t}}})(e,t)),{bleWorkStatus:1}):e&&e.byteLength>24?((e,t)=>{if(!e||0===e.byteLength)return{bleWorkStatus:0,mac:"",productKey:""};let i=0,n="",s="",a=1;const o=new Uint8Array(e);for(;!(i>e.byteLength-1);){const c=o[i];if(c<=0||!c)break;if(e.byteLength<c+i+1)break;const l=e.slice(i+1,i+c+1);if(c>=6&&c<=8&&(n=r(l),16==n.length&&(n=n.substring(0,15))),16==c){const e=r(l).toLowerCase();t.find(t=>t===e)&&(s=e)}1==c&&(a=new Uint8Array(l)[0]),i+=1+c}return{bleWorkStatus:a,mac:n,productKey:s}})(e,t):{mac:"",productKey:"",bleWorkStatus:1},t.isSameDevice=(e,t)=>e.mac.toLocaleLowerCase()===t.mac.toLocaleLowerCase()&&e.productKey===t.productKey,t.merageBleLocalDevices=(e,i)=>(e.map(e=>{e.isBleOnline=!1,e.bleWorkStatus=0}),i.map(i=>{const n=e.find(e=>t.isSameDevice(e,i));n?(n.isBleOnline=!0,n.bleDeviceID=i.bleDeviceID,n.connectType=i.connectType,n.bleWorkStatus=i.bleWorkStatus):e.push(i)}),e),t.merageLanLocalDevices=(e,i)=>(e.map(e=>{e.isLanOnline=!1}),i.map(i=>{const n=e.find(e=>t.isSameDevice(e,i));n?n.isLanOnline=!0:e.push(i)}),e),t.BTDevice2GDevice=(e,i)=>{let s={productKey:"",mac:"",bleWorkStatus:0},r={did:"",productKey:"",mac:"",bleWorkStatus:0,connectType:"NONE",isBleOnline:!0,isLanOnline:!1,isOnline:!1,name:e.name,isBind:!1,bleDeviceID:e.deviceId,ctime:(new Date).getTime(),RSSI:e.RSSI};switch(e.communicationType){case"BLE_BROADCAST":try{n.default.log("parse BLE_BROADCAST");const t=a(o(e.advertisData));s.productKey=t.data.join(""),s.mac=t.mac,r.connectType="BLE_BROADCAST"}catch(e){}break;default:s=t.advertisData2PkAndMac(e.advertisData,i)}return r=Object.assign(Object.assign({},r),s),r},t.getFirstConnectType=(e,t)=>{if(!t)return e.isLanOnline?"LAN":e.isBleOnline?"BLE":"WAN";if("WAN"===t)return"WAN";switch(t){case"BLE":return e.isBleOnline?"BLE":"NONE";case"LAN":return e.isLanOnline?"LAN":"NONE"}return"WAN"},t.getProductInfoThroughPK=(e,t)=>t.find(t=>t.productKey===e),t.mergeObject=(e,t)=>{for(let i in t)null!=t[i]&&""!==t[i]&&(e[i]=t[i]);return e},t.hex2ab=function(e){const t=[];for(let n=0;n<e.length;n+=2){var i=e.slice(n,n+2);t.push(parseInt(i,16))}return new Uint8Array(t)},t.parseBroadcastData=a,t.ab2numbers=o;let l=0;function u(e,t){let i=1,n=t;return e.map(e=>{const t=65535&(e^n);return n=i-t&65535,i<<=1,c(t,4)})}function d(e,t,i){if(i.length>22)throw new Error("最大长度为22");const s=[...i,...new Array(22-i.length).fill(0)],r=255&i.reduce((e,t)=>e+t,0),a=(t>>4<<12)+(r>>4<<8)+((15&t)<<4)+(15&r),o=Array.from({length:11},(e,t)=>(s[2*t]<<8)+s[2*t+1]);return n.default.log("明文",c(e,4),c((t<<8)+r,4),o.map(e=>c(e,4))),[c(e,4),c((t<<8)+r,4),...u(o,a)].map(e=>`${e.slice(2)}${e.slice(0,2)}`)}t.encrypt=u,t.convertToServiceUuids=({len:e=null,data:i=null,index:n=0,mac:s})=>{const r=null==e?Math.round(18*Math.random())+1:e,a=null==i?Array.from({length:r},e=>Math.round(255*Math.random())):i,o=[147,r,...a],c=d(s,(()=>{const e=l;return l=l+1&255,e})(),o);return[...new Set(c)].length!==c.length?t.convertToServiceUuids({len:r,data:a,index:n++,mac:s}):c},t.convertToUuids=d,t.arrayBufferToWordArray=function(e){for(var t=[],i=new Uint8Array(e),n=0;n<i.length;n+=4){var r=i[n]<<24|i[n+1]<<16|i[n+2]<<8|i[n+3];t.push(r)}return s.lib.WordArray.create(t,i.length)}},function(e,t,i){var n;e.exports=(n=i(0),i(13),i(39),i(40),i(7),i(41),i(8),i(24),i(16),i(42),i(25),i(43),i(44),i(45),i(17),i(46),i(6),i(2),i(47),i(48),i(49),i(50),i(51),i(52),i(53),i(54),i(55),i(56),i(57),i(58),i(59),i(60),i(61),i(62),i(63),n)},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(18),r=i(15),a=i(5);t.default=(e,t,i=!0)=>n(void 0,void 0,void 0,(function*(){const n=Object.assign({},t),o={"Content-Type":"application/json","X-Gizwits-Application-Id":r.getGlobalData("appID")};i&&(o["X-Gizwits-User-token"]=r.getGlobalData("token")),n.header=Object.assign(Object.assign({},o),t.headers),delete n.headers;const c=r.getGlobalData("cloudServiceInfo").openAPIInfo,l=yield s.default("https://"+c+e,n);if(l.statusCode>=200&&l.statusCode<300)return{success:!0,data:l.data};let u={success:!1,err:{errorCode:a.default.GIZ_SDK_HTTP_REQUEST_FAILED.errorCode,errorMessage:""}};try{u={success:!1,err:{errorCode:l.data.error_code,errorMessage:l.data.error_message}}}catch(e){}return u}))},function(e,t,i){var n,s,r,a,o,c;e.exports=(c=i(0),s=(n=c).lib,r=s.Base,a=s.WordArray,(o=n.x64={}).Word=r.extend({init:function(e,t){this.high=e,this.low=t}}),o.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:8*e.length},toX32:function(){for(var e=this.words,t=e.length,i=[],n=0;n<t;n++){var s=e[n];i.push(s.high),i.push(s.low)}return a.create(i,this.sigBytes)},clone:function(){for(var e=r.clone.call(this),t=e.words=this.words.slice(0),i=t.length,n=0;n<i;n++)t[n]=t[n].clone();return e}}),c)},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(12);const r=new class{constructor(){this.data={},this.key="dataPointConfig",this.init=()=>n(this,void 0,void 0,(function*(){const e=(yield wx.getStorageSync(this.key))||"{}";let t={};try{t=JSON.parse(e)}catch(e){}this.data=t})),this.getConfigFile=e=>n(this,void 0,void 0,(function*(){var t;if(!this.data[e]){const i=`/app/datapoint?product_key=${e}`,n=yield s.default(`${i}`,{method:"GET"});if(!n.success||!(null===(t=n.data)||void 0===t?void 0:t.entities))return null;this.data[e]=n.data,wx.setStorageSync(this.key,JSON.stringify(this.data))}return this.data[e]})),this.getAttrItem=(e,t)=>n(this,void 0,void 0,(function*(){this.data[e]||(yield this.getConfigFile(e));for(let i in this.data[e].entities[0].attrs){const n=this.data[e].entities[0].attrs[i];if(n.name===t)return n}return null}))}};r.init(),t.default=r},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n={};t.setGlobalData=function(e,t){n[e]=t},t.getGlobalData=function(e){return n[e]}},function(e,t,i){var n;e.exports=(n=i(0),function(e){var t=n,i=t.lib,s=i.WordArray,r=i.Hasher,a=t.algo,o=[],c=[];!function(){function t(t){for(var i=e.sqrt(t),n=2;n<=i;n++)if(!(t%n))return!1;return!0}function i(e){return 4294967296*(e-(0|e))|0}for(var n=2,s=0;s<64;)t(n)&&(s<8&&(o[s]=i(e.pow(n,.5))),c[s]=i(e.pow(n,1/3)),s++),n++}();var l=[],u=a.SHA256=r.extend({_doReset:function(){this._hash=new s.init(o.slice(0))},_doProcessBlock:function(e,t){for(var i=this._hash.words,n=i[0],s=i[1],r=i[2],a=i[3],o=i[4],u=i[5],d=i[6],h=i[7],f=0;f<64;f++){if(f<16)l[f]=0|e[t+f];else{var p=l[f-15],v=(p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3,g=l[f-2],y=(g<<15|g>>>17)^(g<<13|g>>>19)^g>>>10;l[f]=v+l[f-7]+y+l[f-16]}var D=n&s^n&r^s&r,_=(n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22),m=h+((o<<26|o>>>6)^(o<<21|o>>>11)^(o<<7|o>>>25))+(o&u^~o&d)+c[f]+l[f];h=d,d=u,u=o,o=a+m|0,a=r,r=s,s=n,n=m+(_+D)|0}i[0]=i[0]+n|0,i[1]=i[1]+s|0,i[2]=i[2]+r|0,i[3]=i[3]+a|0,i[4]=i[4]+o|0,i[5]=i[5]+u|0,i[6]=i[6]+d|0,i[7]=i[7]+h|0},_doFinalize:function(){var t=this._data,i=t.words,n=8*this._nDataBytes,s=8*t.sigBytes;return i[s>>>5]|=128<<24-s%32,i[14+(s+64>>>9<<4)]=e.floor(n/4294967296),i[15+(s+64>>>9<<4)]=n,t.sigBytes=4*i.length,this._process(),this._hash},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=r._createHelper(u),t.HmacSHA256=r._createHmacHelper(u)}(Math),n.SHA256)},function(e,t,i){var n,s,r,a;e.exports=(n=i(0),r=(s=n).lib.Base,a=s.enc.Utf8,void(s.algo.HMAC=r.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=a.parse(t));var i=e.blockSize,n=4*i;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var s=this._oKey=t.clone(),r=this._iKey=t.clone(),o=s.words,c=r.words,l=0;l<i;l++)o[l]^=1549556828,c[l]^=909522486;s.sigBytes=r.sigBytes=n,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher,i=t.finalize(e);return t.reset(),t.finalize(this._oKey.clone().concat(i))}})))},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){return new Promise((i,n)=>{wx.request(Object.assign(Object.assign({url:e,timeout:3e3},t),{success:e=>{i(e)},fail:e=>{n(e)}}))})}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(4),r=i(9);function a(e,t){return new Promise((i,n)=>{wx.createBLEConnection({deviceId:e,timeout:t,success:e=>i(e),fail:e=>{-1===e.errCode?i(e):n(e)}})})}function o(e,t,i,n){return new Promise(s=>{wx.writeBLECharacteristicValue({deviceId:e,serviceId:t,characteristicId:i,value:n,complete:s})})}t.retryConnect=function(e,t=1e4){return n(this,void 0,void 0,(function*(){let i={success:!1};for(let n=0;n<5;n++)try{return console.debug("start createBLEConnection"),yield a(e,t)}catch(e){i=e,console.debug("createBLEConnection error retry"),yield r.default(1e3)}return i}))},t.openBluetoothAdapter=function(){return new Promise((e,t)=>{wx.openBluetoothAdapter({success:e,fail:t})})},t.closeBluetoothAdapter=function(){return new Promise((e,t)=>{wx.closeBluetoothAdapter({success:e,fail:t})})},t.getBluetoothAdapterState=function(){return new Promise((e,t)=>{wx.getBluetoothAdapterState({success:e,fail:t})})},t.startBluetoothDevicesDiscovery=function(e=!0){return new Promise((t,i)=>{wx.startBluetoothDevicesDiscovery({success:t,fail:i,allowDuplicatesKey:e,powerLevel:"high",interval:200})})},t.getBluetoothDevices=function(){return new Promise((e,t)=>{wx.getBluetoothDevices({success:({devices:t})=>e(t),fail:t})})},t.createBLEConnection=a,t.getBLEDeviceServices=function(e){return new Promise((t,i)=>{wx.getBLEDeviceServices({deviceId:e,success:({services:e})=>t(e),fail:i})})},t.getBLEDeviceCharacteristics=function(e,t){return new Promise((i,n)=>{wx.getBLEDeviceCharacteristics({deviceId:e,serviceId:t,success:({characteristics:e})=>i(e),fail:n})})},t.notifyBLECharacteristicValueChange=function(e,t,i,n=!0){return new Promise((s,r)=>{wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:t,characteristicId:i,state:n,success:s,fail:r})})},t.writeBLECharacteristicValue=o;const c=[];let l=!1;let u=0;t.unpackWriteBLECharacteristicValue=function(e,t,i,a){if(!a||0===a.byteLength)throw new Error("value is empty");return new Promise((c,l)=>n(this,void 0,void 0,(function*(){let n,u=0,d=a.byteLength;for(;d>0;){yield r.default(30);const c=a.slice(u,u+20);if(u+=20,d-=20,n=yield o(e,t,i,c),s.default.log("unpackWriteBLECharacteristicValue",u/20,n),0!==n.errCode)break}0!==n.errCode?l(n):c(n)})))},t.unpackWriteBLECharacteristicValueWithQueue=function(e,t,i,a){if(!a||0===a.byteLength)return Promise.reject(new Error("value is empty"));const d=a.byteLength;return new Promise((h,f)=>{c.push({task:()=>n(this,void 0,void 0,(function*(){let n=0,c=d,l={errCode:0,errMsg:"ok"},u=0;for(;c>0;){yield r.default(30);const d=a.slice(n,n+20);if(n+=20,c-=20,l=yield o(e,t,i,d),s.default.log("unpackWriteBLECharacteristicValueWithQueue",u+1,l),0!==l.errCode)break;u++}0!==l.errCode?f(l):h(l)})),resolve:h,reject:f}),function(){n(this,void 0,void 0,(function*(){if(!l&&0!==c.length){for(l=!0;c.length>0;){const e=c.shift();if(!e)continue;const t=Date.now()-u;if(t<500){const e=500-t;yield r.default(e)}try{yield e.task(),u=Date.now()}catch(t){e.reject(t)}}l=!1}}))}()})},t.downloadFile=function({url:e}){return n(this,void 0,void 0,(function*(){return new Promise((t,i)=>{wx.downloadFile({url:e,success(e){t(e)},fail(e){i(e)}})})}))}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(1),s=i(3);class r extends n.default{constructor(e){super(e)}}r.pack=(e,t)=>{const i=[],[n,r]=s.formatCodesFromStr(e),[a,o]=s.formatCodesFromStr(t),c=[0].concat([0,1],r,n,o,a);let l=c.length;for(;l>0;)i.push(l),l-=255;const u=[0,0,0,3].concat(i).concat(c),d=new ArrayBuffer(u.length),h=new Uint8Array(d);for(let e=0;e<d.byteLength;e++)h[e]=u[e];return h},t.default=r},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(9),r=i(5),a=i(33),o=i(4);t.default=class{constructor(e,t,i,c){this.ssid="",this.password="",this.specialProductKeys=[],this.disableSearchDevice=!1,this.specialProductKeySecrets=[],this.timeoutHandler=null,this.setDeviceOnboardingDeployRej=()=>{},this.cleanTimeout=()=>{this.disableSearchDevice=!0,this.timeoutHandler&&clearTimeout(this.timeoutHandler),this.timeoutHandler=null},this.stopDeviceOnboardingDeploy=()=>{this.setDeviceOnboardingDeployRej&&this.setDeviceOnboardingDeployRej({success:!1,err:r.default.GIZ_SDK_ONBOARDING_STOPPED}),this.cleanTimeout()},this.hasTimeoutHandler=e=>!!this.timeoutHandler&&(e&&e({success:!1,err:r.default.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING}),!0),this.handleTimeout=()=>{this.setDeviceOnboardingDeployRej&&this.setDeviceOnboardingDeployRej({success:!1,err:{errorCode:r.default.CONFIG_TIME_OUT,errorMessage:"time out"}}),this.timeoutHandler=null},this.searchDevice=({ssid:e,password:t})=>new Promise((i,c)=>{o.default.debug("GIZ_SDK: 开始大循环搜索设备");const l=()=>n(this,void 0,void 0,(function*(){var n;if(this.hasTimeoutHandler())try{const u=yield a.checkDeviceRegister({SSID:e,password:t,productKeys:this.specialProductKeys});if((null===(n=u.err)||void 0===n?void 0:n.errorCode)===r.default.GIZ_OPENAPI_TOKEN_INVALID.errorCode)return void c({success:!1,err:r.default.GIZ_OPENAPI_TOKEN_INVALID});u.err||0===u.data.length?(o.default.debug("GIZ_SDK: 大循环没有发现设备"),yield s.default(1500),!this.disableSearchDevice&&l()):(o.default.debug("GIZ_SDK: 大循环搜索到设备",u),i({success:!0,data:u.data}))}catch(e){yield s.default(3e3),!this.disableSearchDevice&&l()}}));l()}),this.initDeviceOnboardingDeploy=(e,t)=>{this.setDeviceOnboardingDeployRej=e,this.disableSearchDevice=!1},this.startTimeoutTimer=e=>{this.timeoutHandler=setTimeout(this.handleTimeout,1e3*e)},this.bindDevices=e=>(o.default.log("GIZ_SDK: start bind device"),new Promise((t,i)=>n(this,void 0,void 0,(function*(){const n=e.map(e=>{const t=this.specialProductKeys.findIndex(t=>e.productKey===t);if(-1===t)return;const i=this.specialProductKeySecrets[t];return a.bindMac({mac:e.mac,productKey:e.productKey,productSecret:i})});try{const s=yield Promise.all(n),a=e.filter((e,t)=>{const i=s[t];return i&&i.success});a.length>0?(o.default.log("GIZ_SDK: bind device success",a),t({success:!0,data:a})):(o.default.log("GIZ_SDK: bind device error",s),i({success:!1,data:e,err:r.default.GIZ_SDK_BIND_DEVICE_FAILED}))}catch(e){i(e)}})))),this.ssid=e,this.password=t,this.specialProductKeys=i,this.specialProductKeySecrets=c}}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__rest||function(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(e);s<n.length;s++)t.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(e,n[s])&&(i[n[s]]=e[n[s]])}return i};Object.defineProperty(t,"__esModule",{value:!0});const r=i(10),a=i(19),o=i(26),c=i(3),l=i(1),u=i(64),d=i(27),h=i(65),f=i(28),p=i(4),v=i(29),g=i(9),y=i(66),D=i(5),_=i(67),m=i(68),b=i(69),S=i(70),w=i(11),I=i(31),B=i(80),A=i(81),k=i(82);class C extends v.default{constructor({pks:e=[],bleHandleParams:t={serviceUUIDSuffix:"fe60",serviceUUIDSuffix2:"abf0",characteristicUUIDSuffix:"fe61"},offlineThreshold:i}){super(),this.connectedList=[],this.connectingDevId=null,this.pks=[],this.listenDevOfflineTimer=null,this.listenBluetoothDeviceFoundNoneTimer=null,this.MAX_BLE_SCAN_INVERTER=299999,this.startScanParams=null,this.isScanning=!1,this.boradcastDataCache={},this.baseServices=[],this.tmpBleData="",this.tmpDataNum=0,this.disableScanFlag=!1,this.peripheralServer=null,this.isActive=!0,this.otaSessionMap={},this.scanList=[],this.onBluetoothAdapterStateChange=e=>{p.default.debug("onBluetoothAdapterStateChange",e),e.available||(this.scanList=[],this.notifyDevices())},this.onAppShow=()=>{this.isActive=!0,this.scanList.map(e=>{e.ctime=Date.now()})},this.onAppHide=()=>{this.isActive=!1},this.listenDevOffline=e=>{this.listenDevOfflineTimer=setInterval(()=>{if(!this.isActive)return;const t=(new Date).getTime(),i=this.scanList.filter(i=>{const n=this.connectedList.find(e=>i.bleDeviceID==e.deviceId),s=this.connectingDevId===i.bleDeviceID;return!(!n&&!s)||("BLE_BROADCAST"===i.connectType?t-i.ctime<2*e:t-i.ctime<e)});if(i.length!==this.scanList.length){const e=this.scanList.filter(e=>!i.find(t=>r.isSameDevice(t,e)));p.default.warn("timestamp:",t,"\n","BLE devices offline:",e),this.scanList=i,this.notifyDevices()}},500)},this.openBluetoothAdapter=(e="central")=>new Promise((t,i)=>{wx.openBluetoothAdapter({mode:e,success:()=>{t({success:!0}),wx.onBLECharacteristicValueChange(this.handleOnBLECharacteristicValueChange)},fail:e=>{p.default.error("openBluetoothAdapter fail",new Error(JSON.stringify(e))),this.notifyError({errMsg:e.errMsg,errCode:-1}),i({success:!1,err:e})}})}),this.getProtocolBase=({device:e,hexString:t,curDeviceValue:i})=>{const n=c.hexStrint2byte(t);if("67a95f560e464453be079c5723a4a85c"===e.productKey||"0b58c73f12064eb897aa005cf43d6a1b"===e.productKey||"4b286229884f4711bcdbaefdfb5f76b9"===e.productKey){const e=new u.default(n);return{data:e,needWaitLen:e.len-i.byteLength}}const s=new l.default(n);return{data:s,needWaitLen:s.len-i.byteLength+4+Math.ceil(s.len.toString(2).length/8)}},this.handleOnBLECharacteristicValueChange=e=>n(this,void 0,void 0,(function*(){if(!e.value)return;const t=this.scanList.find(t=>t.bleDeviceID===e.deviceId);if(t){const i=r.ab2hex(e.value);try{const{needWaitLen:n}=this.getProtocolBase({device:t,hexString:i,curDeviceValue:e.value});this.tmpBleData=i,this.tmpDataNum=n}catch(t){this.tmpBleData&&(this.tmpBleData+=i,this.tmpDataNum-=e.value.byteLength)}if(this.tmpDataNum>0||!this.tmpBleData)return;this.notiDeviceDataToSdk(e,this.tmpBleData),this.tmpBleData="",this.tmpDataNum=0}else p.default.info("GIZ_SDK: 没有找到设备",e)})),this.notiDeviceDataToSdk=(e,t)=>{this.listenerMap.GizBleDeviceData&&this.listenerMap.GizBleDeviceData.map(i=>{i(e,t)})},this.notifyError=e=>{this.listenerMap.GizBleError&&this.listenerMap.GizBleError.map(t=>{t(e)})},this.notifyDevices=()=>{this.listenerMap.GizBleDeviceList&&this.listenerMap.GizBleDeviceList.map(e=>{e(this.scanList)})},this.listenConnection=()=>{wx.onBLEConnectionStateChange(e=>{if(!1===e.connected){const t=this.connectedList.findIndex(t=>t.deviceId===e.deviceId);-1!==t&&(this.connectedList.splice(t,1),this.notifyDevices())}})},this.init=()=>n(this,void 0,void 0,(function*(){const{platform:e}=wx.getSystemInfoSync();yield this.openBluetoothAdapter(),"ios"===e&&(yield this.openBluetoothAdapter("peripheral"));let t=!0;try{this.peripheralServer=(yield wx.createBLEPeripheralServer()).server,p.default.info("GIZ_SDK: 广播初始化成功",this.peripheralServer)}catch(e){p.default.error("GIZ_SDK: 广播初始化失败",new Error(JSON.stringify(e))),t=!1}if("android"===e&&!1===t)return{success:!1,message:"安卓设备:GIZ_SDK初始化蓝牙广播失败"};return yield this.getBluetoothAdapterState()})),this.checkPermission=()=>n(this,void 0,void 0,(function*(){if((yield wx.getSetting()).authSetting["scope.bluetooth"])return yield this.init();try{return yield wx.authorize({scope:"scope.bluetooth"}),yield this.init()}catch(e){p.default.log("授权失败",e),this.openBluetoothAdapter(),this.notifyError({errMsg:e.errMsg,errCode:-1})}})),this.getBluetoothAdapterState=()=>n(this,void 0,void 0,(function*(){p.default.log("getBluetoothAdapterState",yield wx.getBluetoothAdapterState());const e=yield wx.getBluetoothAdapterState(),{errMsg:t,available:i}=e,n=s(e,["errMsg","available"]);return{data:Object.assign({},n),err:r.wrapErrorInfo(t),success:i}})),this.getDeviceStatus=(e,t,i,s)=>n(this,void 0,void 0,(function*(){const n=yield h.default.pack(t,i,s);return n?yield this.write(e,r.numberArray2Uint8Array(n).buffer):{success:!1}})),this.updateDevice=e=>{const t=e.bleDeviceID,i=this.scanList.findIndex(e=>t==e.bleDeviceID);-1!==i&&(this.scanList[i]=e)},this.updateCtime=e=>{const t=e.deviceId,i=this.scanList.findIndex(e=>t==e.bleDeviceID);-1!==i&&(this.scanList[i].ctime=Date.now())},this.checkDeviceIsChange=(e,t)=>e.bleWorkStatus!==t.bleWorkStatus||e.name!==t.name||e.isBleOnline!==t.isBleOnline||e.isOnline!==t.isOnline,this.handleBluetoothDeviceFound=(e,t)=>{r.unionBy(e.devices,"deviceId").map(e=>{const{advertisData:i,deviceId:n,name:s,localName:a}=e,o=r.ab2hex(i);let c=null;try{c=r.parseBroadcastData(r.ab2numbers(i))}catch(e){}const l=this.scanList.find(e=>e.bleDeviceID===n);if(c&&148===c.cmd){const t=r.ab2hex(i);if(this.boradcastDataCache[n]&&this.boradcastDataCache[n]===t)return!1;if(!l)return!1;this.boradcastDataCache[n]=r.ab2hex(i);const s=f.padBoradcastData(c.data.map(e=>parseInt(e,16)));return this.updateCtime(e),void this.notiDeviceDataToSdk(e,s)}if(c&&25===c.cmd){this.pks.find(e=>e===c.data.join(""))&&(e.communicationType="BLE_BROADCAST")}if(l){const i=r.BTDevice2GDevice(e,this.pks);if(i.productKey&&i.mac){const e=this.checkDeviceIsChange(i,l);i.ctime=Date.now(),l.RSSI=i.RSSI,this.updateDevice(i),e&&t(this.scanList)}}else{if(this.pks.some(e=>o.includes(e))){const i=r.BTDevice2GDevice(e,this.pks);p.default.debug("insert ble device",i),i.productKey&&i.mac&&(this.scanList.push(i),t(this.scanList))}}})},this.listenBluetoothDeviceFoundNone=()=>{this.listenBluetoothDeviceFoundNoneTimer=setInterval(()=>{const e=(new Date).getTime();this.startScanParams&&this.startScanParams.lastStartScanTimestamp&&this.isScanning&&e-this.startScanParams.lastStartScanTimestamp>this.MAX_BLE_SCAN_INVERTER&&!this.disableScanFlag&&(this.stopScan(),this.startScanParams.lastStartScanTimestamp=e,p.default.warn("SDK RESTART SCAN BLE","\n","timestamp:",e),g.default(1e3).then(()=>{this.startScan(this.startScanParams.onScanDevice,this.startScanParams.delay,this.startScanParams.services||null)}))},3e3)},this.startScan=(e,t=5e3,i)=>n(this,void 0,void 0,(function*(){if(this.disableScanFlag)return{scanList:[]};if(!this.startScanParams){const n={onScanDevice:e,delay:t,services:i,lastStartScanTimestamp:(new Date).getTime()};this.startScanParams=n}return this.isScanning=!0,new Promise(s=>n(this,void 0,void 0,(function*(){wx.onBluetoothDeviceFound(t=>{this.handleBluetoothDeviceFound(t,e)}),p.default.debug("GIZ_SDK: start scan",t),yield wx.startBluetoothDevicesDiscovery({services:i||this.baseServices,powerLevel:"high",allowDuplicatesKey:!0,interval:200}),t>0&&setTimeout(()=>{this.stopScan(),s({scanList:this.scanList})},t)})))})),this.stopScan=()=>n(this,void 0,void 0,(function*(){try{return this.isScanning=!1,yield wx.stopBluetoothDevicesDiscovery()}catch(e){return e}})),this.disableScan=()=>n(this,void 0,void 0,(function*(){this.disableScanFlag=!0;const e=yield wx.stopBluetoothDevicesDiscovery();return yield g.default(200),e})),this.enableScan=()=>{this.disableScanFlag=!1},this.connectDevice=e=>n(this,void 0,void 0,(function*(){var t;try{this.connectingDevId=e;try{yield this.disableScan();const t=yield a.retryConnect(e);this.enableScan(),p.default.debug("connect res",t),p.default.debug("===蓝牙连接成功===",(new Date).getTime())}catch(e){if(p.default.error("GIZ_SDK: createBLEConnection error",new Error(JSON.stringify(e))),"createBLEConnection:fail:already connect"!==(null==e?void 0:e.errMsg))return this.notifyError(e),{success:!1,message:null==e?void 0:e.errMsg}}const i=yield wx.getBLEDeviceServices({deviceId:e}).catch(e=>this.notifyError(e)),n=null===(t=null==i?void 0:i.services.find(e=>e.isPrimary&&(e.uuid.toLowerCase().includes(this.serviceUUIDSuffix)||e.uuid.toLowerCase().includes(this.serviceUUIDSuffix2))))||void 0===t?void 0:t.uuid;if(!n)return{message:"can not find valid serviceId",success:!1};const s=null==i?void 0:i.services.find(e=>e.isPrimary&&e.uuid.toLowerCase().includes(this.serviceUUIDSuffix2)),c=yield wx.getBLEDeviceCharacteristics({deviceId:e,serviceId:n}).catch(e=>this.notifyError(e)),l=null==c?void 0:c.characteristics[0].uuid;if(this.connectedList.every(t=>t.deviceId!==e)&&this.connectedList.push({deviceId:e,serviceId:n,characteristicId:l}),yield wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:n,characteristicId:l,state:!0,type:"notification"}).catch(e=>this.notifyError(e)),s){this.write(e,r.numberArray2Uint8Array(o.default.pack()).buffer);const t=yield this.handleBindReq(e);if(p.default.log("handleBindReq",t),t.success){this.write(e,r.numberArray2Uint8Array(d.default.pack({passcode:t.data})).buffer);const i=yield this.handleLoginReq(e).catch(e=>this.notifyError(e));if(null==i?void 0:i.success)return{success:!0,message:"ok"}}return yield wx.closeBLEConnection({deviceId:e}),{success:!1,message:"ok"}}return{success:!0,message:"ok"}}finally{this.connectingDevId=null}})),this.handleWatchBleData=(e,t,i=3e3,s)=>n(this,void 0,void 0,(function*(){return new Promise(n=>{let r=!1,a=null,o=null;const c=e=>{r||(r=!0,a&&(clearTimeout(a),a=null),o&&(this.removeEventListener("GizBleDeviceData",o),o=null),s&&s.cancelHandlers.delete(l),n(e))},l=()=>{c({success:!1,err:D.default.GIZ_SDK_OTA_DEVICE_BUSY_IN_UPGRADE})};if(s){if(s.cancelled)return void l();s.cancelHandlers.add(l)}o=(i,n)=>{if(null==s?void 0:s.cancelled)return void l();if(e!==i.deviceId)return;const r=t(i,n);r&&c({success:!0,data:r})},this.addEventListener("GizBleDeviceData",o),a=setTimeout(()=>{c({success:!1,err:D.default.GIZ_SDK_DEVICE_NO_RESPONSE})},i)})})),this.handleBindReq=e=>new Promise(t=>{const i=(n,s)=>{if(n.deviceId!==e)return;p.default.log("监听蓝牙特征值发生变化");const r=new o.default(c.hexStrint2byte(s));this.removeEventListener("GizBleDeviceData",i),r.passcode?t({success:!0,data:r.passcode}):t({success:!1,data:""})};this.watchBleDevice(e,i)}),this.handleLoginReq=e=>new Promise(t=>{const i=(n,s)=>{if(n.deviceId!==e)return;p.default.log("设备回复LoginReq",s);const r=new d.default(c.hexStrint2byte(s));this.removeEventListener("GizBleDeviceData",i),!0===r.result?t({success:!0,data:r.did}):t({success:!1,data:""})};this.watchBleDevice(e,i)}),this.startUpgrade=({device:e,type:t,onEvent:i,onProgress:s,productKey:o})=>n(this,void 0,void 0,(function*(){i({code:"GizOTAEventPretreatment"});const n=yield this.checkUpdate({device:e,type:t});p.default.warn("检查设备是否有新固件",n);const u=e.bleDeviceID,d=this.createOtaSession(u),h=()=>({success:!1,err:D.default.GIZ_SDK_OTA_DEVICE_BUSY_IN_UPGRADE});try{if(!n.success)return n;const e=n.data.download_url,f=n.data.soft_ver;i({code:"GizOTAEventDownload"});let v="";try{v=(yield a.downloadFile({url:e})).tempFilePath}catch(e){return p.default.error("固件下载失败",e),{success:!1,err:D.default.GIZ_SDK_OTA_FIRMWARE_DOWNLOAD_FAILED}}if(p.default.warn("下载固件成功",v),d.cancelled)return p.default.warn("检测到 OTA 会话被抢占,停止继续处理"),h();i({code:"GizOTAEventTransmit"});const y=(e,t)=>{const i=c.hexStrint2byte(t);switch(new l.default(i).cmd){case"0042":return new m.default(i)}return null},_=(e,t)=>{const i=c.hexStrint2byte(t);switch(new l.default(i).cmd){case"0044":return new b.default(i)}return null},C=(e,t)=>{const i=c.hexStrint2byte(t);switch(new l.default(i).cmd){case"0052":return new S.default(i)}return null};if(p.default.warn("查询设备是否可以OTA"),d.cancelled)return h();const E=m.default.pack(t);if(yield this.write(u,r.numberArray2Uint8Array(E).buffer),d.cancelled)return h();const T=yield this.handleWatchBleData(u,y,3e3,d);if(p.default.warn("设备回复是否可以OTA",T),!T.success)return T;if(T.data.type!==t)return p.default.error(null,new Error("OTA类型不匹配")),{success:!1,err:D.default.GIZ_SDK_OTA_FIRMWARE_TYPE_NOT_MATCH};if(0!==T.data.state)return h();const P=wx.getFileSystemManager();let O=[];try{O=yield P.readFileSync(v,"hex",0)}catch(e){return p.default.error("读取固件失败",e),{success:!1,err:D.default.GIZ_SDK_OTA_FIRMWARE_DOWNLOAD_FAILED}}if(d.cancelled)return h();const L=O.match(/.{1,2}/g).map((function(e){return parseInt(e,16)})),x=r.arrayBufferToWordArray(L),M=w.MD5(x).toString(),K=I.crc32(L),H=b.default.pack(o,f,M,L.length,K);if(yield this.write(u,r.numberArray2Uint8Array(H).buffer),d.cancelled)return h();const R=yield this.handleWatchBleData(u,_,5e3,d);if(p.default.warn("设备回复ota 预请求",R),!R.success)return R;if(0!==R.data.state)return{success:!1};let N=0;if(R.data.processedLen>0){I.crc32(L.slice(0,R.data.processedLen)).toString(16)===R.data.processedCrc32?(N=R.data.processedLen,p.default.warn(`断点续传,从 ${N} 开始`)):(p.default.warn("从位置0开始OTA"),yield this.write(u,r.numberArray2Uint8Array(B.default.pack(0)).buffer),yield g.default(100))}const U=L.length,G=R.data.packageMaxLen;let j=Math.ceil(N/G),Z=0;for(;N<U;){if(d.cancelled)return p.default.warn("OTA 会话被新的请求打断,终止数据发送"),h();const e=L.slice(N,N+G),t=A.default.pack(e,j);if(yield this.write(u,r.numberArray2Uint8Array(t).buffer),d.cancelled)return p.default.warn("OTA 会话被新的请求打断,终止等待反馈"),h();const i=(e,t)=>{const i=c.hexStrint2byte(t);switch(new l.default(i).cmd){case"0048":{const e=new A.default(i);return e.packageNum===j?e:null}}return null},n=yield this.handleWatchBleData(u,i,5e3,d);let a=!1;if(!1===n.success){if(n.err===D.default.GIZ_SDK_OTA_DEVICE_BUSY_IN_UPGRADE)return n;a=!0}if(n.success&&0!==n.data.state&&4!==n.data.state&&(a=!0),a){if(Z+=1,p.default.warn(`发送OTA包失败,重试次数 ${Z}`,n),Z>3)return p.default.warn("发送OTA包失败次数超过限制"),{success:!1};continue}p.default.warn("设备接收ota子包成功",n),Z=0,N+=G,j+=1;let o=parseInt(`${j*G/U*100}`);if(o>100&&(o=100),s({firmwareSize:U,packageMaxLen:G,currentNumber:j,currentProgress:o}),yield g.default(100),d.cancelled)return p.default.warn("OTA 会话被新的请求打断,停止后续传输"),h();if(4===n.data.state){p.default.warn("设备请求等待OTA");const e=yield this.handleWatchBleData(u,C,6e4,d);if(p.default.warn("设备回复等待结果",e),!e.success)return e.err===D.default.GIZ_SDK_OTA_DEVICE_BUSY_IN_UPGRADE?e:{success:!1};if(1===e.data.state)return{success:!1}}}if(d.cancelled)return h();p.default.warn("发送完所有数据包,等待设备回复");const z=(e,t)=>{const i=c.hexStrint2byte(t);switch(new l.default(i).cmd){case"0050":return new k.default(i)}return null},W=yield this.handleWatchBleData(u,z,1e4,d);if(!W.success)return W;if(0===W.data.state){if(p.default.warn("设备回复收到固件,准备重启设备"),i({code:"GizOTAEventReboot"}),this.disConnectDevice(u),yield g.default(1e4),d.cancelled)return h();const e=yield this.connectDevice(u);if(console.log("connectRes",e),!e.success)return p.default.warn("设备重启后,无法连接"),{success:!1};const n=yield this.getDeviceInfo({deviceId:u});if(!n.success)return p.default.warn("获取设备版本号失败"),{success:!1};let s="";return s="MCU"===t?n.data.mcuSoftVersion:n.data.moduleSoftVersion,i({code:"GizOTAEventFinish"}),s===f?{success:!0}:(p.default.warn("设备上报版本号与更新的固件版本号不匹配,更新失败"),{success:!1})}return{success:!1}}finally{this.releaseOtaSession(u,d)}})),this.getDeviceInfo=({deviceId:e})=>n(this,void 0,void 0,(function*(){const t=y.default.pack();p.default.debug("DeviceInfo.pack",t),yield this.write(e,r.numberArray2Uint8Array(t).buffer);return yield this.handleWatchBleData(e,(e,t)=>{const i=c.hexStrint2byte(t);switch(new l.default(i).cmd){case"0014":try{const e=new y.default(i);return p.default.debug("parse DeviceInfo",e),e}catch(e){p.default.debug("parse DeviceInfo error",e)}}return null})})),this.checkUpdate=({device:e,type:t})=>n(this,void 0,void 0,(function*(){const i=yield this.getDeviceInfo({deviceId:e.bleDeviceID});if(i.success){let n="",s="";return"MCU"===t?(n=i.data.mcuSoftVersion,s=i.data.mcuHardVersion):(n=i.data.moduleSoftVersion,s=i.data.moduleHardVersion),yield _.checkUpdate({did:e.did,type:t,softVersion:n,hardVersion:s})}return{success:!1,err:i.err}})),this.watchBleDevice=(e,t)=>n(this,void 0,void 0,(function*(){const{serviceId:i,characteristicId:n,errMsg:s}=this.getTargetDevice(e);return s?{success:!1,message:s}:(yield wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:i,characteristicId:n,state:!0,type:"notification"}).catch(e=>this.notifyError(e)),p.default.log(`监听设备 ${e} 成功!`),this.addEventListener("GizBleDeviceData",t),{message:"ok",success:!0})})),this.writeBoradcast=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.scanList.find(t=>t.bleDeviceID===e);if(!i)return{success:!1,message:"not found device"};this.boradcastTimer&&clearTimeout(this.boradcastTimer);try{this.peripheralServer.stopAdvertising({});const e=r.convertToServiceUuids({mac:i.mac,index:0,data:t,len:t.length});return this.peripheralServer.startAdvertising({advertiseRequest:{connectable:!0,serviceUuids:e},powerLevel:"high",success:e=>{p.default.debug("GIZ_SDK: startAdvertising success",e)},fail:e=>{p.default.error("GIZ_SDK: startAdvertising error",new Error(JSON.stringify(e)))}}),p.default.debug("GIZ_SDK: start adv",e),this.boradcastTimer=setTimeout(()=>{this.peripheralServer.stopAdvertising({}),this.boradcastTimer=null},1e3),{success:!0}}catch(e){return p.default.log("GIZ_SDK:",e),clearTimeout(this.boradcastTimer),{success:!1,message:"send cmd error"}}})),this.write=(e,t)=>n(this,void 0,void 0,(function*(){p.default.warn("app => dev:",r.ab2hex(t),(new Date).getTime()),console.log("ble write",r.ab2hex(t));const i=this.getTargetDevice(e);if(i.serviceId&&i.characteristicId){return yield a.unpackWriteBLECharacteristicValue(e,i.serviceId,i.characteristicId,t)}return{success:!1,message:"send cmd error"}})),this.writeWithQueue=(e,t)=>n(this,void 0,void 0,(function*(){p.default.warn("app => dev (with queue):",r.ab2hex(t),(new Date).getTime()),console.log("ble write with queue",r.ab2hex(t));const i=this.getTargetDevice(e);if(i.serviceId&&i.characteristicId){return yield a.unpackWriteBLECharacteristicValueWithQueue(e,i.serviceId,i.characteristicId,t)}return{success:!1,message:"send cmd error"}})),this.disConnectDevice=e=>n(this,void 0,void 0,(function*(){this.removeDevById(e);const{errMsg:t}=yield wx.closeBLEConnection({deviceId:e}),i=this.scanList.find(t=>t.bleDeviceID===e);return i&&(i.ctime=Date.now(),this.updateDevice(i)),"closeBLEConnection:ok"===t?{err:t,success:!0}:{err:t,success:!1}})),this.removeDevById=e=>{const t=this.connectedList.findIndex(t=>t.deviceId===e);-1!==t&&this.connectedList.splice(t,1)},this.getTargetDevice=e=>{const t=this.connectedList.find(t=>e===t.deviceId);return t||{errMsg:"Unable get this device,maybe you forgot to connect it."}},this.destory=()=>{this.listenDevOfflineTimer&&clearInterval(this.listenDevOfflineTimer),this.listenBluetoothDeviceFoundNoneTimer&&clearInterval(this.listenBluetoothDeviceFoundNoneTimer),wx.offAppShow(this.onAppShow),wx.offAppHide(this.onAppHide),wx.offBluetoothAdapterStateChange(this.onBluetoothAdapterStateChange)};const{serviceUUIDSuffix:v,serviceUUIDSuffix2:C}=t;this.serviceUUIDSuffix=v,this.serviceUUIDSuffix2=C,this.pks=e,this.listenDevOffline(null!=i?i:1e4),this.listenConnection(),this.listenBluetoothDeviceFoundNone(),wx.onAppShow(this.onAppShow),wx.onAppHide(this.onAppHide),wx.onBluetoothAdapterStateChange(this.onBluetoothAdapterStateChange)}createOtaSession(e){this.cancelOtaSession(e);const t={cancelled:!1,cancelHandlers:new Set};return this.otaSessionMap[e]=t,t}cancelOtaSession(e){const t=this.otaSessionMap[e];t&&(t.cancelled=!0,t.cancelHandlers.forEach(e=>e()),t.cancelHandlers.clear(),delete this.otaSessionMap[e])}releaseOtaSession(e,t){this.otaSessionMap[e]===t&&(t.cancelHandlers.clear(),delete this.otaSessionMap[e])}}t.BleHandle=C},function(e,t){var i;i=function(){return this}();try{i=i||new Function("return this")()}catch(e){"object"==typeof window&&(i=window)}e.exports=i},function(e,t,i){var n,s,r,a,o,c,l,u;e.exports=(u=i(0),s=(n=u).lib,r=s.WordArray,a=s.Hasher,o=n.algo,c=[],l=o.SHA1=a.extend({_doReset:function(){this._hash=new r.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(e,t){for(var i=this._hash.words,n=i[0],s=i[1],r=i[2],a=i[3],o=i[4],l=0;l<80;l++){if(l<16)c[l]=0|e[t+l];else{var u=c[l-3]^c[l-8]^c[l-14]^c[l-16];c[l]=u<<1|u>>>31}var d=(n<<5|n>>>27)+o+c[l];d+=l<20?1518500249+(s&r|~s&a):l<40?1859775393+(s^r^a):l<60?(s&r|s&a|r&a)-1894007588:(s^r^a)-899497514,o=a,a=r,r=s<<30|s>>>2,s=n,n=d}i[0]=i[0]+n|0,i[1]=i[1]+s|0,i[2]=i[2]+r|0,i[3]=i[3]+a|0,i[4]=i[4]+o|0},_doFinalize:function(){var e=this._data,t=e.words,i=8*this._nDataBytes,n=8*e.sigBytes;return t[n>>>5]|=128<<24-n%32,t[14+(n+64>>>9<<4)]=Math.floor(i/4294967296),t[15+(n+64>>>9<<4)]=i,e.sigBytes=4*t.length,this._process(),this._hash},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),n.SHA1=a._createHelper(l),n.HmacSHA1=a._createHmacHelper(l),u.SHA1)},function(e,t,i){var n;e.exports=(n=i(0),i(13),function(){var e=n,t=e.lib.Hasher,i=e.x64,s=i.Word,r=i.WordArray,a=e.algo;function o(){return s.create.apply(s,arguments)}var c=[o(1116352408,3609767458),o(1899447441,602891725),o(3049323471,3964484399),o(3921009573,2173295548),o(961987163,4081628472),o(1508970993,3053834265),o(2453635748,2937671579),o(2870763221,3664609560),o(3624381080,2734883394),o(310598401,1164996542),o(607225278,1323610764),o(1426881987,3590304994),o(1925078388,4068182383),o(2162078206,991336113),o(2614888103,633803317),o(3248222580,3479774868),o(3835390401,2666613458),o(4022224774,944711139),o(264347078,2341262773),o(604807628,2007800933),o(770255983,1495990901),o(1249150122,1856431235),o(1555081692,3175218132),o(1996064986,2198950837),o(2554220882,3999719339),o(2821834349,766784016),o(2952996808,2566594879),o(3210313671,3203337956),o(3336571891,1034457026),o(3584528711,2466948901),o(113926993,3758326383),o(338241895,168717936),o(666307205,1188179964),o(773529912,1546045734),o(1294757372,1522805485),o(1396182291,2643833823),o(1695183700,2343527390),o(1986661051,1014477480),o(2177026350,1206759142),o(2456956037,344077627),o(2730485921,1290863460),o(2820302411,3158454273),o(3259730800,3505952657),o(3345764771,106217008),o(3516065817,3606008344),o(3600352804,1432725776),o(4094571909,1467031594),o(275423344,851169720),o(430227734,3100823752),o(506948616,1363258195),o(659060556,3750685593),o(883997877,3785050280),o(958139571,3318307427),o(1322822218,3812723403),o(1537002063,2003034995),o(1747873779,3602036899),o(1955562222,1575990012),o(2024104815,1125592928),o(2227730452,2716904306),o(2361852424,442776044),o(2428436474,593698344),o(2756734187,3733110249),o(3204031479,2999351573),o(3329325298,3815920427),o(3391569614,3928383900),o(3515267271,566280711),o(3940187606,3454069534),o(4118630271,4000239992),o(116418474,1914138554),o(174292421,2731055270),o(289380356,3203993006),o(460393269,320620315),o(685471733,587496836),o(852142971,1086792851),o(1017036298,365543100),o(1126000580,2618297676),o(1288033470,3409855158),o(1501505948,4234509866),o(1607167915,987167468),o(1816402316,1246189591)],l=[];!function(){for(var e=0;e<80;e++)l[e]=o()}();var u=a.SHA512=t.extend({_doReset:function(){this._hash=new r.init([new s.init(1779033703,4089235720),new s.init(3144134277,2227873595),new s.init(1013904242,4271175723),new s.init(2773480762,1595750129),new s.init(1359893119,2917565137),new s.init(2600822924,725511199),new s.init(528734635,4215389547),new s.init(1541459225,327033209)])},_doProcessBlock:function(e,t){for(var i=this._hash.words,n=i[0],s=i[1],r=i[2],a=i[3],o=i[4],u=i[5],d=i[6],h=i[7],f=n.high,p=n.low,v=s.high,g=s.low,y=r.high,D=r.low,_=a.high,m=a.low,b=o.high,S=o.low,w=u.high,I=u.low,B=d.high,A=d.low,k=h.high,C=h.low,E=f,T=p,P=v,O=g,L=y,x=D,M=_,K=m,H=b,R=S,N=w,U=I,G=B,j=A,Z=k,z=C,W=0;W<80;W++){var F,V,Y=l[W];if(W<16)V=Y.high=0|e[t+2*W],F=Y.low=0|e[t+2*W+1];else{var $=l[W-15],X=$.high,J=$.low,q=(X>>>1|J<<31)^(X>>>8|J<<24)^X>>>7,Q=(J>>>1|X<<31)^(J>>>8|X<<24)^(J>>>7|X<<25),ee=l[W-2],te=ee.high,ie=ee.low,ne=(te>>>19|ie<<13)^(te<<3|ie>>>29)^te>>>6,se=(ie>>>19|te<<13)^(ie<<3|te>>>29)^(ie>>>6|te<<26),re=l[W-7],ae=re.high,oe=re.low,ce=l[W-16],le=ce.high,ue=ce.low;V=(V=(V=q+ae+((F=Q+oe)>>>0<Q>>>0?1:0))+ne+((F+=se)>>>0<se>>>0?1:0))+le+((F+=ue)>>>0<ue>>>0?1:0),Y.high=V,Y.low=F}var de,he=H&N^~H&G,fe=R&U^~R&j,pe=E&P^E&L^P&L,ve=T&O^T&x^O&x,ge=(E>>>28|T<<4)^(E<<30|T>>>2)^(E<<25|T>>>7),ye=(T>>>28|E<<4)^(T<<30|E>>>2)^(T<<25|E>>>7),De=(H>>>14|R<<18)^(H>>>18|R<<14)^(H<<23|R>>>9),_e=(R>>>14|H<<18)^(R>>>18|H<<14)^(R<<23|H>>>9),me=c[W],be=me.high,Se=me.low,we=Z+De+((de=z+_e)>>>0<z>>>0?1:0),Ie=ye+ve;Z=G,z=j,G=N,j=U,N=H,U=R,H=M+(we=(we=(we=we+he+((de+=fe)>>>0<fe>>>0?1:0))+be+((de+=Se)>>>0<Se>>>0?1:0))+V+((de+=F)>>>0<F>>>0?1:0))+((R=K+de|0)>>>0<K>>>0?1:0)|0,M=L,K=x,L=P,x=O,P=E,O=T,E=we+(ge+pe+(Ie>>>0<ye>>>0?1:0))+((T=de+Ie|0)>>>0<de>>>0?1:0)|0}p=n.low=p+T,n.high=f+E+(p>>>0<T>>>0?1:0),g=s.low=g+O,s.high=v+P+(g>>>0<O>>>0?1:0),D=r.low=D+x,r.high=y+L+(D>>>0<x>>>0?1:0),m=a.low=m+K,a.high=_+M+(m>>>0<K>>>0?1:0),S=o.low=S+R,o.high=b+H+(S>>>0<R>>>0?1:0),I=u.low=I+U,u.high=w+N+(I>>>0<U>>>0?1:0),A=d.low=A+j,d.high=B+G+(A>>>0<j>>>0?1:0),C=h.low=C+z,h.high=k+Z+(C>>>0<z>>>0?1:0)},_doFinalize:function(){var e=this._data,t=e.words,i=8*this._nDataBytes,n=8*e.sigBytes;return t[n>>>5]|=128<<24-n%32,t[30+(n+128>>>10<<5)]=Math.floor(i/4294967296),t[31+(n+128>>>10<<5)]=i,e.sigBytes=4*t.length,this._process(),this._hash.toX32()},clone:function(){var e=t.clone.call(this);return e._hash=this._hash.clone(),e},blockSize:32});e.SHA512=t._createHelper(u),e.HmacSHA512=t._createHmacHelper(u)}(),n.SHA512)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(1),s=i(3);class r extends n.default{constructor(e){super(e),this.passcode="";let t=0;const i=parseInt(s.arrayToString(this.content.slice(t,t+2)),16);t+=2;let n="";this.content.slice(t,t+i).map(e=>{n+=String.fromCharCode(e)}),this.passcode=n}}r.pack=()=>[0,0,0,3,3,0,0,6],t.default=r},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(1),s=i(3);class r extends n.default{constructor(e){super(e),this.result=!1,this.didLength=0,this.did="";let t=0;if(this.result=0===this.content[0],t++,1===this.flag[0]){this.didLength=parseInt(s.arrayToString(this.content.slice(t,t+2)),16),t+=2;let e="";this.content.slice(t,this.content.length).map(t=>{e+=String.fromCharCode(t)}),this.did=e}}}r.pack=({passcode:e})=>{let t=[0];const i=s.hexStrint2byte(s.fillString(e.length.toString(16),4)),n=s.string2Bytes(e),r=[0].concat([0,8]).concat(i).concat(n);return t=s.hexStrint2byte(r.length.toString(16)),[0,0,0,3].concat(t).concat(r)},t.default=r},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(14),r=i(3),a=e=>-1!==e.indexOf("uint")?"number":e,o=(e,t,i)=>{let n="";switch(e){case"bool":n=`${!0===t[i.name]?1:0}`;break;case"enum":{let e=t[i.name];"number"==typeof e&&(e=i.enum[e]);const s=i.enum.findIndex(t=>e===t),a=-1===s?0:s;n=r.fillString(a.toString(2),i.position.len);break}case"number":{let e=0;null!=t[i.name]&&(e=Math.round((t[i.name]-i.uint_spec.addition)/i.uint_spec.ratio)),n=r.fillString(e.toString(2),8*i.position.len);break}case"binary":{let e=t[i.name]||"";e instanceof Array&&(e=r.arrayToString(e));const s=r.fillString(e,2*i.position.len,!0);for(let e=0;e<s.length/2;e++){const t=2*e,i=s[t]+s[t+1];n+=r.fillString(parseInt(i,16).toString(2),8)}break}}const s=i.position.len*("byte"===i.position.unit?8:1)-n.length;if(s>0)for(let e=0;e<s;e++)n=`0${n}`;return`${n}`},c=(e,t,i)=>{switch(e){case"bool":return"1"===t;case"enum":return parseInt(t,2);case"binary":{const e=i.position.len;let n="";for(let e=0;e<t.length/8;e++){const i=8*e,s=t.substring(i,i+8);n+=r.fillString(parseInt(s,2).toString(16),2)}return r.fillString(n,2*e,!0)}case"number":return parseInt(t,2)/(1/i.uint_spec.ratio)+i.uint_spec.addition;default:return""}},l=({config:e,data:t,isAdaptiveDatapoint:i})=>{let n=e;const s=[0,0,0,3],c=[0],l=[0,147],d=[0,0,0,0];let h=[1],f="";const p=[];i||(n=n.filter(e=>"status_writable"===e.type)),n.map(e=>{void 0!==t[e.name]?(f=`1${f}`,p.push(e)):f=`0${f}`}),i&&(h=[17],n=p),f=r.fillString(f,8*Math.ceil(f.length/8));for(let e=0;e<f.length/8;e++)h.push(parseInt(f.substring(8*e,8*(e+1)),2));let v,g="";try{v=n[0]}catch(e){}n.map(e=>{"bool"===e.data_type||"enum"===e.data_type?(v.type!==e.type&&(h=h.concat(r.completeBlock(g)),g=""),g=((e,i)=>{const n=a(e.data_type);return i=o(n,t,e)+i})(e,g)):(g.length>0&&(h=h.concat(r.completeBlock(g)),g=""),h=((e,i)=>{const n=a(e.data_type),s=o(n,t,e);return i=i.concat(r.completeBlock(s))})(e,h)),v=e}),g.length>0&&(h=h.concat(r.completeBlock(g)),g="");const y=c.concat(l).concat(d).concat(h),D=u(y);return s.push(...D),{data:s.concat(y),raw:{header:[0,0,0,3],flag:c,len:D,headerCmd:l,sn:d,cmd:h}}};function u(e){const t=e.length.toString(2),i=[];for(let e=t.length;e>0;e-=7){const n=e-7,s=e;let r=t.substring(n,s);r=`${n>0?"1":"0"}${r}`,i.push(parseInt(r,2))}return i}function d(e,t){return e===t||"ALL"===e}function h({attrs:e,activeAttrs:t,flagString:i,cmdData:n,accumulate:s}){let r=0,a={},o=0;return["status_writable","status_readonly","alert","fault"].map(c=>{const l=e.filter(e=>d(c,e.type)).length,{cmd:u,cmdDataLength:h}=f({type:c,attrs:e.slice(o,o+l),activeAttrs:t,flagString:i.substring(o,o+l),cmdData:n.slice(r,n.length),accumulate:s});return r+=h,a=Object.assign(Object.assign({},a),u),o+=l,null}),a}function f({type:e,attrs:t,activeAttrs:i,cmdData:n,flagString:s,accumulate:o}){let l=0,u=0,h=0;return i.map(t=>{if(d(e,t.type)){const e=t.position.len*("bit"===t.position.unit?1:8);"bool"===t.data_type||"enum"===t.data_type?u+=e:h+=e}return null}),l=Math.ceil(h/8)+Math.ceil(u/8),{cmdDataLength:l,cmd:function({attrs:e,flagString:t,boolEnumLength:i,cmdData:n,accumulate:s}){const o={};let l=0;for(let u=0;u<t.length;u++)if(e[u]&&"1"===t[u]){const{data_type:t,position:{len:s}}=e[u];let d="";if("bool"===t||"enum"===t){let e="";n.slice(0,i).map(t=>(e+=r.fillString(t.toString(2),8),null));const t=e.length-l;d=e.substring(t-s,t),l+=s}else{const e=i,t=i+s;n.slice(e,t).map(e=>(d+=r.fillString(e.toString(2),8),null)),i+=s}const h=a(t);o[e[u].name]=c(h,d,e[u])}else if(s){const t=e[u]||{position:{len:0}};"byte"===t.position.unit?i+=t.position.len:l+=t.position.len}return o}({attrs:t,flagString:s,boolEnumLength:Math.ceil(u/8),cmdData:n,accumulate:o})}}t.getVariableLength=u;t.unpack=(e,t)=>n(void 0,void 0,void 0,(function*(){const i=yield s.default.getConfigFile(t);if(i){const n=function({config:e=[],data:t}){let i,n,s="";const a={header:r.arrayToString(t.slice(0,4)),flag:"",len:"",cmd:"",sn:"",action:"",payload:""},o=e;let c=r.checkHeader(t);if(!1===c)return;const l=t.slice(c,t.length),u=r.getProtocolLen(l);if(c+=u,a.len=r.arrayToString(l.slice(0,u)),c+=1,a.flag=r.arrayToString(t.slice(c-1,c)),c+=2,a.cmd=r.arrayToString(t.slice(c-2,c)),a.sn="",("0093"===a.cmd||"0094"===a.cmd)&&(c+=4,a.sn=r.arrayToString(t.slice(c-4,c)),"01"===a.flag)){c+=2,c+=parseInt(r.arrayToString(t.slice(c-2,c)),16)}c+=1,a.action=r.arrayToString(t.slice(c-1,c)),i=parseInt(a.action,16),a.payload=r.arrayToString(t.slice(c,t.length));const d=t.slice(c,t.length);let p=o;1===i&&(p=o.filter(e=>"status_writable"===e.type));const v=JSON.parse(JSON.stringify(p)),g=Math.ceil(p.length/8);let y=d.slice(0,g),D=d.slice(g,d.length);3!==i&&4!==i||(y=new Array(g).fill(255),D=d);let _="";y.map(e=>(_+=r.fillString(e.toString(2),8),null)),i>=17&&i<=20&&(p=p.filter((e,t)=>{const i=_.length-1-t;return"1"===_[i]})),"0090"===a.cmd||"0093"===a.cmd?(s="App 透传数据到 Dev",n="APP2DEV"):"0091"===a.cmd||"0094"===a.cmd?(s="Dev 收到控制命令后应答到 App",n="DEV2APP"):(s="非法数据",n="UNKNOW");let m={};switch(i){case 1:s="App 下发数据到 Dev",m=h({attrs:v,activeAttrs:p,flagString:_.split("").reverse().join(""),cmdData:D,accumulate:!0});break;case 2:return s="App 下发查询指令到 Dev",{kvData:null,rawData:a,message:s,messageType:n};case 3:s="Dev 回复查询指令到 App",m=h({attrs:v,activeAttrs:p,flagString:_.split("").reverse().join(""),cmdData:D,accumulate:!0});break;case 4:s="Dev 上报状态到 App",m=h({attrs:v,activeAttrs:p,flagString:_.split("").reverse().join(""),cmdData:D,accumulate:!0});break;case 5:return s="App 透传数据到 Dev",{kvData:null,rawData:a,message:s,messageType:n};case 6:return s="Dev 透传数据到 App",{kvData:null,rawData:a,message:s,messageType:n};case 7:return s="App 下发控制子设备",{kvData:null,rawData:a,message:s,messageType:n};case 8:return s="App 读取子设备数据",{kvData:null,rawData:a,message:s,messageType:n};case 9:return s="Dev 中控回复ACK",{kvData:null,rawData:a,message:s,messageType:n};case 10:return s="子设备上报状态到 App",{kvData:null,rawData:a,message:s,messageType:n};case 11:return s="App 下发添加子设备指令",{kvData:null,rawData:a,message:s,messageType:n};case 12:return s="App 下发删除子设备",{kvData:null,rawData:a,message:s,messageType:n};case 13:return s="App 获取中控子设备列表",{kvData:null,rawData:a,message:s,messageType:n};case 14:return s="中控响应字设备查询到 App",{kvData:null,rawData:a,message:s,messageType:n};case 15:return s="子设备列表变更通知到 App",{kvData:null,rawData:a,message:s,messageType:n};case 16:return s="Dev 子设备上下线状态变更通知",{kvData:null,rawData:a,message:s,messageType:n};case 17:s="App 下发变长数据到 Dev",m=f({type:"ALL",attrs:v,activeAttrs:p,flagString:_.split("").reverse().join(""),cmdData:D}).cmd;break;case 18:return s="App 下发变长查询到 Dev",{kvData:null,rawData:a,message:s,messageType:n};case 19:s="Dev 变长回复查询指令到 App",m=f({type:"ALL",attrs:v,activeAttrs:p,flagString:_.split("").reverse().join(""),cmdData:D}).cmd;break;case 20:s="Dev 变长上报状态到 App",m=f({type:"ALL",attrs:v,activeAttrs:p,flagString:_.split("").reverse().join(""),cmdData:D}).cmd;break;case 114:return s="App 向网关发送数据",{kvData:null,rawData:a,message:s,messageType:n};case 115:return s="Dev 网关上报数据到 App",{kvData:null,rawData:a,message:s,messageType:n};case 116:return s="App 通知网关删除子设备",{kvData:null,rawData:a,message:s,messageType:n};default:return{kvData:null,rawData:a,message:s,messageType:n}}return 0===o.length?{kvData:null,rawData:a,message:s,messageType:n}:{kvData:m,rawData:a,message:s,messageType:n}}({config:(yield i).entities[0].attrs,data:e});return n.kvData&&(n.kvData=yield p(null==n?void 0:n.kvData,t,"object")),n}return null}));t.pack=(e,t)=>n(void 0,void 0,void 0,(function*(){const i=yield s.default.getConfigFile(t);if(i){const t="var_len"===i.protocolType;return l({data:e,config:(yield i).entities[0].attrs,isAdaptiveDatapoint:t})}return null}));t.padBoradcastData=e=>{const t=[0].concat([0,147]).concat([0,0,0,0]).concat(e),i=u(t);return r.arrayToString([0,0,0,3].concat(i).concat(t))};t.formatEnum=(e,t,i)=>n(void 0,void 0,void 0,(function*(){for(let n in e){const r=yield s.default.getAttrItem(t,n);if(r&&"enum"===r.data_type){if("int"===i&&"string"==typeof e[n]){const t=r.enum.findIndex(t=>t===e[n]);e[n]=t||0}"string"===i&&"number"==typeof e[n]&&(e[n]=r.enum[e[n]])}}return e}));const p=(e,t,i)=>n(void 0,void 0,void 0,(function*(){for(let n in e){const a=yield s.default.getAttrItem(t,n);a&&"binary"===a.data_type&&("object"===i&&"string"==typeof e[n]&&(e[n]=r.hexStrint2byte(e[n])),"string"===i&&"object"==typeof e[n]&&(e[n]=r.arrayToString(e[n])))}return e}));t.formatBinary=p},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});t.default=class{constructor(){this.listenerMap={},this.addEventListener=(e,t)=>n(this,void 0,void 0,(function*(){return this.listenerMap[e]||(this.listenerMap[e]=[]),-1===this.listenerMap[e].indexOf(t)&&this.listenerMap[e].push(t),{success:!0}})),this.removeEventListener=(e,t)=>{if(this.listenerMap[e]){const i=this.listenerMap[e].indexOf(t);if(-1!==i)return this.listenerMap[e].splice(i,1),{success:!0}}return{success:!1}}}}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(14),r=i(3),a=e=>-1!==e.indexOf("uint")?"number":e,o=(e,t,i)=>{let n="";switch(e){case"bool":n=`${!0===t[i.name]?1:0}`;break;case"enum":{let e=t[i.name];"number"==typeof e&&(e=i.enum[e]);const s=i.enum.findIndex(t=>e===t),a=-1===s?0:s;n=r.fillString(a.toString(2),i.position.len);break}case"number":{let e=0;null!=t[i.name]&&(e=Math.round((t[i.name]-i.uint_spec.addition)/i.uint_spec.ratio)),n=r.fillString(e.toString(2),8*i.position.len);break}case"binary":{let e=t[i.name]||"";e instanceof Array&&(e=r.arrayToString(e));const s=r.fillString(e,2*i.position.len,!0);for(let e=0;e<s.length/2;e++){const t=2*e,i=s[t]+s[t+1];n+=r.fillString(parseInt(i,16).toString(2),8)}break}}const s=i.position.len*("byte"===i.position.unit?8:1)-n.length;if(s>0)for(let e=0;e<s;e++)n=`0${n}`;return`${n}`},c=(e,t,i)=>{switch(e){case"bool":return"1"===t;case"enum":return parseInt(t,2);case"binary":{const e=i.position.len;let n="";for(let e=0;e<t.length/8;e++){const i=8*e,s=t.substring(i,i+8);n+=r.fillString(parseInt(s,2).toString(16),2)}return r.fillString(n,2*e,!0)}case"number":return parseInt(t,2)/(1/i.uint_spec.ratio)+i.uint_spec.addition;default:return""}},l=({config:e,data:t,isAdaptiveDatapoint:i})=>{let n=e;const s=[0,0,0,3],c=[0],l=[0,147],d=[0,0,0,0];let h=[1],f="";const p=[];i||(n=n.filter(e=>"status_writable"===e.type)),n.map(e=>{void 0!==t[e.name]?(f=`1${f}`,p.push(e)):f=`0${f}`}),i&&(h=[17],n=p),f=r.fillString(f,8*Math.ceil(f.length/8));for(let e=0;e<f.length/8;e++)h.push(parseInt(f.substring(8*e,8*(e+1)),2));let v,g="";try{v=n[0]}catch(e){}n.map(e=>{"bool"===e.data_type||"enum"===e.data_type?(v.type!==e.type&&(h=h.concat(r.completeBlock(g)),g=""),g=((e,i)=>{const n=a(e.data_type);return i=o(n,t,e)+i})(e,g)):(g.length>0&&(h=h.concat(r.completeBlock(g)),g=""),h=((e,i)=>{const n=a(e.data_type),s=o(n,t,e);return i=i.concat(r.completeBlock(s))})(e,h)),v=e}),g.length>0&&(h=h.concat(r.completeBlock(g)),g="");const y=c.concat(l).concat(d).concat(h),D=u(y);return s.push(...D),{data:s.concat(y),raw:{header:[0,0,0,3],flag:c,len:D,headerCmd:l,sn:d,cmd:h}}};function u(e){const t=e.length.toString(2),i=[];for(let e=t.length;e>0;e-=7){const n=e-7,s=e;let r=t.substring(n,s);r=`${n>0?"1":"0"}${r}`,i.push(parseInt(r,2))}return i}function d(e,t){return e===t||"ALL"===e}function h({attrs:e,activeAttrs:t,flagString:i,cmdData:n,accumulate:s}){let r=0,a={},o=0;return["status_writable","status_readonly","alert","fault"].map(c=>{const l=e.filter(e=>d(c,e.type)).length,{cmd:u,cmdDataLength:h}=f({type:c,attrs:e.slice(o,o+l),activeAttrs:t,flagString:i.substring(o,o+l),cmdData:n.slice(r,n.length),accumulate:s});return r+=h,a=Object.assign(Object.assign({},a),u),o+=l,null}),a}function f({type:e,attrs:t,activeAttrs:i,cmdData:n,flagString:s,accumulate:o}){let l=0,u=0,h=0;return i.map(t=>{if(d(e,t.type)){const e=t.position.len*("bit"===t.position.unit?1:8);"bool"===t.data_type||"enum"===t.data_type?u+=e:h+=e}return null}),l=Math.ceil(h/8)+Math.ceil(u/8),{cmdDataLength:l,cmd:function({attrs:e,flagString:t,boolEnumLength:i,cmdData:n,accumulate:s}){const o={};let l=0;for(let u=0;u<t.length;u++)if(e[u]&&"1"===t[u]){const{data_type:t,position:{len:s}}=e[u];let d="";if("bool"===t||"enum"===t){let e="";n.slice(0,i).map(t=>(e+=r.fillString(t.toString(2),8),null));const t=e.length-l;d=e.substring(t-s,t),l+=s}else{const e=i,t=i+s;n.slice(e,t).map(e=>(d+=r.fillString(e.toString(2),8),null)),i+=s}const h=a(t);o[e[u].name]=c(h,d,e[u])}else if(s){const t=e[u]||{position:{len:0}};"byte"===t.position.unit?i+=t.position.len:l+=t.position.len}return o}({attrs:t,flagString:s,boolEnumLength:Math.ceil(u/8),cmdData:n,accumulate:o})}}t.getVariableLength=u;t.unpack=(e,t)=>n(void 0,void 0,void 0,(function*(){const i=yield s.default.getConfigFile(t);if(i){const n=function({config:e=[],data:t}){let i,n,s="";const a={header:r.arrayToString(t.slice(0,4)),flag:"",len:"",cmd:"",sn:"",action:"",payload:""},o=e;let c=r.checkHeader(t);if(!1===c)return;const l=t.slice(c,t.length),u=r.getProtocolLen(l);if(c+=u,a.len=r.arrayToString(l.slice(0,u)),c+=1,a.flag=r.arrayToString(t.slice(c-1,c)),c+=2,a.cmd=r.arrayToString(t.slice(c-2,c)),a.sn="",("0093"===a.cmd||"0094"===a.cmd)&&(c+=4,a.sn=r.arrayToString(t.slice(c-4,c)),"01"===a.flag)){c+=2,c+=parseInt(r.arrayToString(t.slice(c-2,c)),16)}c+=1,a.action=r.arrayToString(t.slice(c-1,c)),i=parseInt(a.action,16),a.payload=r.arrayToString(t.slice(c,t.length));const d=t.slice(c,t.length);let p=o;1===i&&(p=o.filter(e=>"status_writable"===e.type));const v=JSON.parse(JSON.stringify(p)),g=Math.ceil(p.length/8);let y=d.slice(0,g),D=d.slice(g,d.length);3!==i&&4!==i||(y=new Array(g).fill(255),D=d);let _="";y.map(e=>(_+=r.fillString(e.toString(2),8),null)),i>=17&&i<=20&&(p=p.filter((e,t)=>{const i=_.length-1-t;return"1"===_[i]})),"0090"===a.cmd||"0093"===a.cmd?(s="App 透传数据到 Dev",n="APP2DEV"):"0091"===a.cmd||"0094"===a.cmd?(s="Dev 收到控制命令后应答到 App",n="DEV2APP"):(s="非法数据",n="UNKNOW");let m={};switch(i){case 1:s="App 下发数据到 Dev",m=h({attrs:v,activeAttrs:p,flagString:_.split("").reverse().join(""),cmdData:D,accumulate:!0});break;case 2:return s="App 下发查询指令到 Dev",{kvData:null,rawData:a,message:s,messageType:n};case 3:s="Dev 回复查询指令到 App",m=h({attrs:v,activeAttrs:p,flagString:_.split("").reverse().join(""),cmdData:D,accumulate:!0});break;case 4:s="Dev 上报状态到 App",m=h({attrs:v,activeAttrs:p,flagString:_.split("").reverse().join(""),cmdData:D,accumulate:!0});break;case 5:return s="App 透传数据到 Dev",{kvData:null,rawData:a,message:s,messageType:n};case 6:return s="Dev 透传数据到 App",{kvData:null,rawData:a,message:s,messageType:n};case 7:return s="App 下发控制子设备",{kvData:null,rawData:a,message:s,messageType:n};case 8:return s="App 读取子设备数据",{kvData:null,rawData:a,message:s,messageType:n};case 9:return s="Dev 中控回复ACK",{kvData:null,rawData:a,message:s,messageType:n};case 10:return s="子设备上报状态到 App",{kvData:null,rawData:a,message:s,messageType:n};case 11:return s="App 下发添加子设备指令",{kvData:null,rawData:a,message:s,messageType:n};case 12:return s="App 下发删除子设备",{kvData:null,rawData:a,message:s,messageType:n};case 13:return s="App 获取中控子设备列表",{kvData:null,rawData:a,message:s,messageType:n};case 14:return s="中控响应字设备查询到 App",{kvData:null,rawData:a,message:s,messageType:n};case 15:return s="子设备列表变更通知到 App",{kvData:null,rawData:a,message:s,messageType:n};case 16:return s="Dev 子设备上下线状态变更通知",{kvData:null,rawData:a,message:s,messageType:n};case 17:s="App 下发变长数据到 Dev",m=f({type:"ALL",attrs:v,activeAttrs:p,flagString:_.split("").reverse().join(""),cmdData:D}).cmd;break;case 18:return s="App 下发变长查询到 Dev",{kvData:null,rawData:a,message:s,messageType:n};case 19:s="Dev 变长回复查询指令到 App",m=f({type:"ALL",attrs:v,activeAttrs:p,flagString:_.split("").reverse().join(""),cmdData:D}).cmd;break;case 20:s="Dev 变长上报状态到 App",m=f({type:"ALL",attrs:v,activeAttrs:p,flagString:_.split("").reverse().join(""),cmdData:D}).cmd;break;case 114:return s="App 向网关发送数据",{kvData:null,rawData:a,message:s,messageType:n};case 115:return s="Dev 网关上报数据到 App",{kvData:null,rawData:a,message:s,messageType:n};case 116:return s="App 通知网关删除子设备",{kvData:null,rawData:a,message:s,messageType:n};default:return{kvData:null,rawData:a,message:s,messageType:n}}return 0===o.length?{kvData:null,rawData:a,message:s,messageType:n}:{kvData:m,rawData:a,message:s,messageType:n}}({config:(yield i).entities[0].attrs,data:e});return n.kvData&&(n.kvData=yield p(null==n?void 0:n.kvData,t,"object")),n}return null}));t.pack=(e,t)=>n(void 0,void 0,void 0,(function*(){const i=yield s.default.getConfigFile(t);if(i){const t="var_len"===i.protocolType;return l({data:e,config:(yield i).entities[0].attrs,isAdaptiveDatapoint:t})}return null}));t.padBoradcastData=e=>{const t=[0].concat([0,147]).concat([0,0,0,0]).concat(e),i=u(t);return r.arrayToString([0,0,0,3].concat(i).concat(t))};t.formatEnum=(e,t,i)=>n(void 0,void 0,void 0,(function*(){for(let n in e){const r=yield s.default.getAttrItem(t,n);if(r&&"enum"===r.data_type){if("int"===i&&"string"==typeof e[n]){const t=r.enum.findIndex(t=>t===e[n]);e[n]=t||0}"string"===i&&"number"==typeof e[n]&&(e[n]=r.enum[e[n]])}}return e}));const p=(e,t,i)=>n(void 0,void 0,void 0,(function*(){for(let n in e){const a=yield s.default.getAttrItem(t,n);a&&"binary"===a.data_type&&("object"===i&&"string"==typeof e[n]&&(e[n]=r.hexStrint2byte(e[n])),"string"===i&&"object"==typeof e[n]&&(e[n]=r.arrayToString(e[n])))}return e}));t.formatBinary=p},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(71);t.crc16modbus=n.default;const s=i(78);t.crc32=s.default,t.default={crc16modbus:n.default,crc32:s.default}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(73);t.default=function(e,t){const i=(e,i)=>t(n.default(e),i)>>>0;return i.signed=(e,i)=>t(n.default(e),i),i.unsigned=i,i.model=e,i}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(12),r=i(85),a=i(86),o=i(11);class c{constructor(){this.pad=(e,t)=>{},this.unpad=e=>{const t=e.sigBytes;let i=0,n=1;const s=e.toString(o.enc.Utf8);for(;i+16<=t;)i+=16;for(let e=0;e<7;e++){const t=i-2*e;if(s.substring(t,t-2)!=s.substring(t-2,t-4)){i-=2*n;break}n++}e.sigBytes=i}}}t.getBindingList=()=>n(void 0,void 0,void 0,(function*(){const e=yield s.default("/app/bindings?show_disabled=0&limit=1000&skip=0",{method:"GET"});if(e.success){return{success:!0,data:e.data.devices.map(e=>({productKey:e.product_key,mac:e.mac,did:e.did,host:e.host,port_s:e.port_s,port:e.port,ws_port:e.ws_port,wss_port:e.wss_port,passcode:e.passcode,isBleOnline:!1,isLanOnline:!1,connectType:"NONE",name:e.dev_alias,isBind:!0,isOnline:e.is_online}))}}return{success:!1,err:e.err}})),t.bindMac=function({mac:e,productKey:t,productSecret:i,alias:r,beOwner:o}){return n(this,void 0,void 0,(function*(){const n={mac:e,product_key:t,dev_alias:r,set_owner:o},{Signature:c,timestamp:l}=a.psKeySign(i);return yield s.default("/app/bind_mac",{method:"POST",data:n,headers:{"X-Gizwits-Signature":c,"X-Gizwits-Timestamp":l}})}))},t.unbindDevice=function({devices:e}){return n(this,void 0,void 0,(function*(){return yield s.default("/app/bindings",{method:"DELETE",data:{devices:e.map(e=>({did:e.did}))}})}))},t.checkDeviceRegister=function({SSID:e,password:t,productKeys:i}){return n(this,void 0,void 0,(function*(){const n=r.default({SSID:e,password:t,pks:i});let a="";return n.map(e=>{a+=`${e},`}),a=a.substring(0,a.length-1),yield s.default(`/app/device_register?random_codes=${a}`,{method:"get"})}))},t.safeRegister=function({productKey:e,productSecret:t,mac:i,passcode:r,gwDid:a,isReset:c}){return n(this,void 0,void 0,(function*(){let n=`is_reset=${c?1:0}&mac=${i}&passcode=${r}`;a&&(n+=`&gw_did=${a}`);const u=o.enc.Hex.parse(t),d=o.enc.Hex.parse(""),h=o.enc.Utf8.parse(n),f=o.AES.encrypt(h,u,{iv:d,mode:o.mode.ECB,padding:o.pad.Pkcs7}).ciphertext.toString().toUpperCase(),p=yield s.default(`/dev/${e}/device`,{method:"POST",data:{data:f},headers:{"content-type":"application/x-www-form-urlencoded"}},!1);if(p.success){const e=l({productSecret:t,iv:d,data:p.data}),n=[];return e.find(e=>e.mac===i)||n.push({mac:i}),{success:!0,data:{successDevices:e,failedDevices:n}}}return{success:!1,err:p.err}}))};const l=({productSecret:e,data:t,iv:i})=>{const n=o.enc.Hex.parse(e),s=o.enc.Hex.parse(t);const r=o.AES.decrypt(o.enc.Base64.stringify(s),n,{iv:i,mode:o.mode.ECB,padding:new c}).toString(o.enc.Utf8),a=[];return r.split(",").map(e=>{const t=e.split("&"),i=t[0].replace("mac=",""),n=t[1].replace("did=","");a.push({mac:i,did:n})}),a};t.editBindInfo=function({name:e,remark:t,did:i}){return n(this,void 0,void 0,(function*(){const n={};return e&&(n.dev_alias=e),t&&(n.remark=t),yield s.default(`/app/bindings/${i}`,{method:"PUT",data:n},!0)}))}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),i(35);const n=i(36),s=i(5);t.errorCode=s.default;const r=i(22);t.BleHandle=r.BleHandle,t.default=n.default},function(e,t){},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(15),r=i(22),a=i(83),o=i(84),c=i(87),l=i(88),u=i(4),d=i(5),h=i(90),f=i(33),p=i(10),v=i(14),g=i(28),y=i(3),D=i(91),_=i(1),m=i(93),b=i(94),S=i(9),w=i(95),I=i(96),B=i(97);t.default=class{constructor({appID:e,appSecret:t,productInfo:i,cloudServiceInfo:r,token:a,uid:D,offlineThreshold:A}){this.version="3.6.6-kuka",this.listenerMap={},this.keepScanTimer=null,this._deviceList=[],this._bleDevices=[],this._lanDevices=[],this.productInfo=[],this.syncDataCallBack=null,this.syncTotalNum=0,this.syncCurrnetNum=0,this.syncDataTimoutTimer=null,this.SYNC_TIMEOUT=24e4,this.handleBleError=e=>{this.listenerMap.onBleHandleError&&this.listenerMap.onBleHandleError.map(t=>{t(e)})},this.handleBleDevices=e=>{this.bleDevices=e},this.handleLanDevices=e=>{this.lanDevices=e},this.handleLanDeviceData=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>t.mac===e);if(i){const e=yield g.unpack(y.hexStrint2byte(t),i.productKey);(null==e?void 0:e.kvData)&&this.listenerMap.GizDeviceAttrsNotifications&&this.listenerMap.GizDeviceAttrsNotifications.map(t=>{t({device:i,data:null==e?void 0:e.kvData})})}})),this.getBleProductProtocalType=e=>"67a95f560e464453be079c5723a4a85c"===e.productKey||"0b58c73f12064eb897aa005cf43d6a1b"===e.productKey||"4b286229884f4711bcdbaefdfb5f76b9"===e.productKey?"direct":"normal",this.handleBleDeviceData=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>t.bleDeviceID===e.deviceId);if(i){if("direct"===this.getBleProductProtocalType(i)){const e=y.hexStrint2byte(t);return void(this.listenerMap.onBleDeviceDataNotifications&&this.listenerMap.onBleDeviceDataNotifications.map(t=>{t({device:i,data:e})}))}const s=y.hexStrint2byte(t),r=new _.default(s);switch(u.default.warn("===收到蓝牙数据===",(new Date).getTime()),r.cmd){case"0093":case"0094":case"0090":case"0091":{if(console.debug("handleBleDeviceData",t,i),i.passcode){const e=this.productInfo.find(e=>e.productKey===i.productKey);if(e){const n=parseInt(`${Date.now()/1e3}`,10);b.uploadP0({device:i,data:[{raw:t,created_at:n}],productSecret:e.productSecret}).then(e=>{u.default.debug("设备上报数据:timestemp",new Date(1e3*n).toLocaleString(),e)})}}const e=yield g.unpack(y.hexStrint2byte(t),i.productKey);(null==e?void 0:e.kvData)&&this.listenerMap.GizDeviceAttrsNotifications&&this.listenerMap.GizDeviceAttrsNotifications.map(t=>{t({device:i,data:null==e?void 0:e.kvData})});break}case"0062":{const t=new I.default(s);u.default.debug("收到代理重置事件",t),1===t.status&&this.deviceSafetyApi({mac:i.mac,productKey:i.productKey,isReset:!0}).then(t=>n(this,void 0,void 0,(function*(){u.default.debug("代理重置结果",t),t.success&&t.data.successDevices.length>0&&(u.default.debug("重置成功,回写数据"),yield this.bleHandle.write(e.deviceId,p.numberArray2Uint8Array(B.default.pack(0)).buffer))})));break}case"0052":{const t=new m.RequestSync(s);if(u.default.debug("设备回复是否允许同步, state:",t.state),this.syncDataLengthCallback&&this.syncDataLengthCallback({success:0==t.state,data:t.len}),!this.syncDataCallBack)break;0===t.state?(this.syncCurrnetNum=0,this.syncTotalNum=t.len,this.syncDataCallBack({event:"SYNC_START",totalNum:this.syncTotalNum,currentNum:this.syncCurrnetNum}),u.default.debug("查询第一条离线数据"),yield this.bleHandle.write(e.deviceId,p.numberArray2Uint8Array(m.SyncPackage.pack(0)).buffer)):(u.default.debug("设备返回状态为1,同步失败"),this.syncDataCallBack({event:"SYNC_FAIL"}));break}case"0054":{if(!this.syncDataCallBack)break;u.default.debug("设备上报离线数据");const t=new m.SyncPackage(s),i=m.DeletePackage.pack(t.id);u.default.debug("设备上报离线数据:payload",t.payload);try{u.default.debug("设备上报离线数据:timestemp",new Date(1e3*t.timestemp).toLocaleString())}catch(e){}const n=this.productInfo.find(e=>e.productKey===this.syncDevice.productKey);if(n){const e=yield b.uploadP0({device:this.syncDevice,data:[{raw:y.arrayToString(t.payload),created_at:t.timestemp}],productSecret:n.productSecret});u.default.debug("上传离线数据结果",e)}this.syncCurrnetNum+=1,this.syncDataCallBack({event:"SYNC_PROGRESS",totalNum:this.syncTotalNum,currentNum:this.syncCurrnetNum}),u.default.debug("通知设备删除:",t.id),yield this.bleHandle.write(e.deviceId,p.numberArray2Uint8Array(i).buffer),yield S.default(100),t.id<this.syncTotalNum-1?(u.default.debug("查询新数据:",t.id+1),yield this.bleHandle.write(e.deviceId,p.numberArray2Uint8Array(m.SyncPackage.pack(t.id+1)).buffer)):(u.default.debug("send cancel sync to device"),this.bleHandle.write(e.deviceId,p.numberArray2Uint8Array(m.CancelSync.pack()).buffer),this.syncDataCallBack({event:"SYNC_END"}),this.cleanSyncDeviceData());break}case"0058":{if(!this.syncDataCallBack)break;const e=new m.CancelSync(s);u.default.debug("设备上报停止同步 state:",e.state),0===e.state?this.syncDataCallBack({event:"SYNC_END"}):this.syncDataCallBack({event:"SYNC_FAIL"}),this.cleanSyncDeviceData();break}}}})),this.handleSocketDeviceData=e=>n(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>t.did===e.did);if(t){if(e.attrs&&null!=e.attrs.is_online){const i=e.attrs.is_online;this.setDeviceMeta(t,"isOnline",i)}this.listenerMap.GizDeviceAttrsNotifications&&(e.attrs&&(e.attrs=yield g.formatEnum(e.attrs,t.productKey,"int")),this.listenerMap.GizDeviceAttrsNotifications.map(i=>{i(Object.assign({device:t},"attrs"in e?{data:e.attrs}:{raw:e.raw}))}))}})),this.handleSocketStatus=(e,t)=>{const i=this.allDevices.filter(t=>e.includes(t.did)&&"WAN"===t.connectType);u.default.log("handleSocketStatus",e,t),i.forEach(e=>{this.setDeviceMeta(e,"connectType",t?"WAN":"NONE")})},this.notiDeviceList=()=>{var e,t;null===(e=this.listenerMap.GizDeviceListNotifications)||void 0===e||e.map(e=>{e(this.allDevices)}),null===(t=this.listenerMap.onScanListChange)||void 0===t||t.map(e=>{e(this.bleScanDevice)})},this.initLan=()=>{try{this.lanHandle.init(),this.lanHandle.addEventListener("GizLanDeviceList",this.handleLanDevices),this.lanHandle.addEventListener("GizLanDeviceData",this.handleLanDeviceData)}catch(e){u.default.error("init lan error",e)}},this.startAutoScan=e=>{this.keepScanTimer?u.default.warn("startAutoScan already started"):(this.keepScanTimer=setInterval(()=>n(this,void 0,void 0,(function*(){this.bleHandle.startScan(e=>{this.bleDevices=e},-1,e)})),9e3),this.bleHandle.startScan(e=>{this.bleDevices=e},-1,e))},this.stopAutoScan=()=>{this.keepScanTimer&&clearInterval(this.keepScanTimer),this.keepScanTimer=null,this.bleHandle.stopScan()},this.setDeviceMeta=(e,t,i,n=!1)=>{const s=this.allDevices.find(t=>t.mac===e.mac);s&&0!==this.allDevices.length&&(e[t]!==i||n)&&(s[t]=i,this.notiDeviceList())},this.getVersion=()=>({success:!0,data:this.version}),this.initBle=()=>n(this,void 0,void 0,(function*(){const e=yield this.bleHandle.checkPermission();return e.success?(this.bleHandle.addEventListener("GizBleDeviceData",this.handleBleDeviceData),this.bleHandle.addEventListener("GizBleDeviceList",this.handleBleDevices),this.bleHandle.addEventListener("GizBleError",this.handleBleError),u.default.debug("init BLE succcess",e),{success:!0}):(u.default.error("init BLE Error",new Error(JSON.stringify(e))),{success:!1,err:d.default.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON})})),this.scanBleDevice=(e,t)=>n(this,void 0,void 0,(function*(){return this.bleHandle.scanList=[],{success:!0,data:(yield this.bleHandle.startScan(e=>{this.bleDevices=e},e,t)).scanList}})),this.write=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>p.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};if("NONE"!==i.connectType){const{data:e,raw:n}=yield g.pack(t,i.productKey);switch(i.connectType){case"BLE_BROADCAST":return yield this.bleHandle.writeBoradcast(i.bleDeviceID,n.cmd);case"BLE":return e?yield this.bleHandle.write(i.bleDeviceID,p.numberArray2Uint8Array(e).buffer):{success:!1};case"WAN":{const e=yield g.formatEnum(t,i.productKey,"string");return this.socketHandle.writeData(i,e)}case"LAN":return this.lanHandle.write(i,p.numberArray2Uint8Array(e).buffer)}}return{success:!1}})),this.writeWithQueue=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>p.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};if("NONE"!==i.connectType){const{data:e,raw:n}=yield g.pack(t,i.productKey);switch(i.connectType){case"BLE_BROADCAST":return yield this.bleHandle.writeBoradcast(i.bleDeviceID,n.cmd);case"BLE":return e?yield this.bleHandle.writeWithQueue(i.bleDeviceID,p.numberArray2Uint8Array(e).buffer):{success:!1};case"WAN":{const e=yield g.formatEnum(t,i.productKey,"string");return this.socketHandle.writeData(i,e)}case"LAN":return this.lanHandle.write(i,p.numberArray2Uint8Array(e).buffer)}}return{success:!1}})),this.writeRaw=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>p.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};if("NONE"!==i.connectType)switch(i.connectType){case"BLE_BROADCAST":return yield this.bleHandle.writeBoradcast(i.bleDeviceID,t);case"BLE":return t?yield this.bleHandle.write(i.bleDeviceID,p.numberArray2Uint8Array(t).buffer):{success:!1};case"WAN":return this.socketHandle.send(i.did,t);case"LAN":return this.lanHandle.write(i,p.numberArray2Uint8Array(t).buffer)}return{success:!1}})),this.setDeviceTimeStamp=e=>n(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>p.isSameDevice(t,e));if(!t)return{success:!1,message:"target is undefind"};const i=w.default.pack();switch(t.connectType){case"BLE":return this.bleHandle.write(e.bleDeviceID,p.numberArray2Uint8Array(i).buffer)}return{success:!1,message:"the connectType not support set timestamp"}})),this.syncDeviceData=(e,t=(()=>{}))=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>p.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};if(!i.isBind)return{success:!1,message:"Only the bound devices are supported"};if(this.syncDevice)return{success:!1,message:"Synchronizing"};switch(this.syncDevice=Object.assign({},i),i.connectType){case"BLE":{u.default.debug("start syncDeviceData",e),this.syncDataCallBack=t,this.syncDataTimoutTimer=setTimeout(()=>{this.syncDataCallBack({event:"SYNC_FAIL",message:"sync timeout"}),this.cleanSyncDeviceData()},this.SYNC_TIMEOUT);const i=m.RequestSync.pack();return u.default.debug("sent RequestSync data"),this.bleHandle.write(e.bleDeviceID,p.numberArray2Uint8Array(i).buffer)}}return{success:!1,message:"the connectType not support sync data"}})),this.queryNeedSyncDataLength=e=>n(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>p.isSameDevice(t,e));if(!t)return{success:!1,message:"target is undefind"};if(!t.isBind)return{success:!1,message:"Only the bound devices are supported"};switch(t.connectType){case"BLE":{const i=m.RequestSync.pack();return this.syncDevice=Object.assign({},t),u.default.debug("sent RequestSync data len"),this.bleHandle.write(e.bleDeviceID,p.numberArray2Uint8Array(i).buffer),new Promise(e=>{this.syncDataLengthCallback=e,setTimeout(()=>{try{e({success:!1,message:"timeout"})}catch(e){}},3e3)})}}return{success:!1,message:"the connectType not support sync data"}})),this.cancelSyncDeviceData=()=>n(this,void 0,void 0,(function*(){this.cleanSyncDeviceData()})),this.cleanSyncDeviceData=()=>{this.syncDataCallBack&&(this.syncDataCallBack({event:"SYNC_CANCEL"}),this.syncDataCallBack=null),this.syncCurrnetNum=0,this.syncTotalNum=0,this.syncDevice=null,this.syncDataTimoutTimer&&clearTimeout(this.syncDataTimoutTimer)},this.getProductConfig=e=>n(this,void 0,void 0,(function*(){const t=yield v.default.getConfigFile(e);return t?{success:!0,data:t}:{success:!1}})),this.stopScanBleDevice=()=>{this.bleHandle.stopScan()},this.login=e=>n(this,void 0,void 0,(function*(){var t,i;const n=yield h.AnonymousLogin({uid:e});return n.success&&(s.setGlobalData("token",null===(t=n.data)||void 0===t?void 0:t.token),s.setGlobalData("uid",null===(i=n.data)||void 0===i?void 0:i.uid),this.socketHandle.updateToken({token:n.data.token,uid:n.data.uid})),n})),this.getDeviceStatus=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>p.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};switch(i.connectType){case"BLE":return yield this.bleHandle.getDeviceStatus(i.bleDeviceID,i.productKey,i.rootDeviceId,t);case"WAN":return this.socketHandle.readStatus(i,t);default:return{success:!1,message:"Device connectType is unsupported"}}})),this.subscribe=(e,t,i=!0)=>n(this,void 0,void 0,(function*(){u.default.debug("subscribe device:",e);let i=this.allDevices.find(t=>p.isSameDevice(t,e));if(!i)return u.default.warn("Device Target Not Found"),u.default.warn("current devices ",this.allDevices),{success:!1,message:"device not found"};if("BLE_BROADCAST"===i.connectType)return{success:!0};const n=p.getFirstConnectType(i,t);switch("NONE"!==i.connectType&&i.connectType!==n&&(yield this.unSubscribe(i)),n){case"BLE":{const e=yield this.bleHandle.connectDevice(i.bleDeviceID);return e.success&&(this.setDeviceMeta(i,"connectType","BLE",!0),setTimeout(()=>{this.setDeviceTimeStamp(i)},250),setTimeout(()=>{this.getDeviceStatus(i)},500)),e}case"WAN":{const t=this.socketHandle.connectDevice(i);return t.success&&this.setDeviceMeta(e,"connectType","WAN",!0),t}case"LAN":{const t=yield this.lanHandle.connectDevice(i);return t.success&&this.setDeviceMeta(e,"connectType","LAN",!0),t}}return{success:!1}})),this.unSubscribe=e=>n(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>p.isSameDevice(t,e));switch(t.connectType){case"BLE":{const e=yield this.bleHandle.disConnectDevice(t.bleDeviceID);return e.success&&this.setDeviceMeta(t,"connectType","NONE",!0),e}case"WAN":{const e=this.socketHandle.disConnectDevice(t);return e.success&&this.setDeviceMeta(t,"connectType","NONE",!0),e}case"LAN":{const e=this.lanHandle.disConnectDevice(t);return e.success&&this.setDeviceMeta(t,"connectType","NONE",!0),e}}return{success:!1}})),this.bindRemoteDevice=({mac:e,productKey:t,alias:i,beOwner:s})=>n(this,void 0,void 0,(function*(){const n=p.getProductInfoThroughPK(t,this.productInfo);if(n){const r=yield f.bindMac({mac:e,productKey:t,productSecret:n.productSecret,alias:i,beOwner:s});return this.getBindingList(),r}return{success:!1,err:d.default.GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY}})),this.checkUpdate=({device:e,type:t})=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>p.isSameDevice(t,e));if(i){if(!i.did)return{success:!1,err:d.default.GIZ_OPENAPI_DEVICE_NOT_BOUND};switch(i.connectType){case"BLE":return this.bleHandle.checkUpdate({device:e,type:t});default:return{success:!1,err:d.default.GIZ_SDK_OTA_DEVICE_NOT_SUPPORT}}}return{success:!1,err:d.default.GIZ_SDK_DEVICE_NOT_SUBSCRIBED}})),this.getDeviceInfo=({device:e})=>n(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>p.isSameDevice(t,e));if(t){if(!t.did)return{success:!1,err:d.default.GIZ_OPENAPI_DEVICE_NOT_BOUND};switch(t.connectType){case"BLE":return this.bleHandle.getDeviceInfo({deviceId:e.bleDeviceID});default:return{success:!1,err:d.default.GIZ_SDK_OTA_DEVICE_NOT_SUPPORT}}}return{success:!1,err:d.default.GIZ_SDK_DEVICE_NOT_SUBSCRIBED}})),this.startUpgrade=({device:e,type:t,onProgress:i,onEvent:s})=>n(this,void 0,void 0,(function*(){const n=this.allDevices.find(t=>p.isSameDevice(t,e));if(n){if(!n.did)return{success:!1,err:d.default.GIZ_OPENAPI_DEVICE_NOT_BOUND};switch(n.connectType){case"BLE":return this.bleHandle.startUpgrade({device:e,type:t,productKey:e.productKey,onProgress:i,onEvent:s});default:return{success:!1,err:d.default.GIZ_SDK_OTA_DEVICE_NOT_SUPPORT}}}return{success:!1,err:d.default.GIZ_SDK_DEVICE_NOT_SUBSCRIBED}})),this.unbindDevice=({devices:e})=>n(this,void 0,void 0,(function*(){const t=yield f.unbindDevice({devices:e});return t.success&&this.getBindingList(),t})),this.deviceSafetyRegister=({mac:e,productKey:t})=>n(this,void 0,void 0,(function*(){return yield this.deviceSafetyApi({mac:e,productKey:t,isReset:!1})})),this.deviceSafetyUnbind=({mac:e,productKey:t})=>n(this,void 0,void 0,(function*(){return yield this.deviceSafetyApi({mac:e,productKey:t,isReset:!0})})),this.setDeviceOnboardingDeploy=({ssid:e,password:t,mode:i=0,timeout:s,isBind:r=!0,softAPSSIDPrefix:a,productKeys:h})=>n(this,void 0,void 0,(function*(){if(this.currentWifiConfigHandle)return{success:!1,err:d.default.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING};const n=(new Date).getTime();u.default.debug("GIZ_SDK: 配网开始时间:"+n);try{switch(i){case 0:{this.currentWifiConfigHandle=new o.default(e,t,this.specialProductKeys,this.specialProductKeySecrets);const i=yield this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:s,isBind:r,softAPSSIDPrefix:a});this.currentWifiConfigHandle=null;const c=(new Date).getTime();return u.default.debug("GIZ_SDK: 配网结束时间:"+c),u.default.debug("GIZ_SDK: 配网用时:"+(c-n)),i}case 3:{this.currentWifiConfigHandle=new c.default(e,t,this.specialProductKeys,this.specialProductKeySecrets,this.bleHandle);const i=yield this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:s,isBind:r,softAPSSIDPrefix:a});this.currentWifiConfigHandle=null;const o=(new Date).getTime();return u.default.debug("GIZ_SDK: 配网结束时间:"+o),u.default.debug("GIZ_SDK: 配网用时:"+(o-n)),i}case 10:{this.currentWifiConfigHandle=new l.default(e,t,this.specialProductKeys,this.specialProductKeySecrets,this.bleHandle);const i=yield this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:s,isBind:r,softAPSSIDPrefix:a,productKeys:h});this.currentWifiConfigHandle=null;const o=(new Date).getTime();return u.default.debug("GIZ_SDK: 配网结束时间:"+o),u.default.debug("GIZ_SDK: 配网用时:"+(o-n)),i}}}catch(e){return u.default.error("GIZ_SDK: setDeviceOnboardingDeploy",new Error(JSON.stringify(e))),e.err&&e.err.errorCode?e:{success:!1,err:d.default.GIZ_SDK_OTHERWISE}}finally{this.currentWifiConfigHandle=null}})),this.setDomain=e=>{const t=e&&e.openAPIInfo||"api.gizwits.com",i=e&&e.aepInfo||"https://gj-app.iotsdk.com/",n=Object.assign(Object.assign({},e||{}),{openAPIInfo:t,aepInfo:i});s.setGlobalData("cloudServiceInfo",n)},this.deviceSafetyApi=({mac:e,productKey:t,isReset:i})=>n(this,void 0,void 0,(function*(){const n=p.getProductInfoThroughPK(t,this.productInfo);return n?yield f.safeRegister({productKey:t,productSecret:n.productSecret,mac:e,isReset:i,passcode:"1234567890"}):{success:!1,err:d.default.GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY}})),this.getBindingList=()=>n(this,void 0,void 0,(function*(){const e=yield f.getBindingList();return this.deviceList=e.data||[],e})),this.getDevices=()=>n(this,void 0,void 0,(function*(){return yield this.getBindingList(),{success:!0,data:this.allDevices}})),this.stopDeviceOnboardingDeploy=()=>{this.currentWifiConfigHandle&&(this.currentWifiConfigHandle.stopDeviceOnboardingDeploy(),this.currentWifiConfigHandle=null)},this.setLogLevel=e=>u.default.setLogLevel(e),this.renameDevice=(e,t)=>n(this,void 0,void 0,(function*(){return t?e.isBind?yield f.editBindInfo({did:e.did,name:t}):{success:!1,message:"device not bind"}:{success:!1,message:"please input device name"}})),this.removeEventListener=(e,t)=>{if(this.listenerMap[e]){const i=this.listenerMap[e].indexOf(t);if(-1!==i)return this.listenerMap[e].splice(i,1),{success:!0}}return{success:!1}},this.addEventListener=(e,t)=>n(this,void 0,void 0,(function*(){return this.listenerMap[e]||(this.listenerMap[e]=[]),-1===this.listenerMap[e].indexOf(t)&&this.listenerMap[e].push(t),{success:!0}})),this.destory=()=>{this.bleHandle.destory(),this.lanHandle.destory(),this.socketHandle.destory(),this.keepScanTimer&&clearInterval(this.keepScanTimer),this.keepScanTimer=null},this.productInfo=i,s.setGlobalData("appID",e),s.setGlobalData("appSecret",t),s.setGlobalData("productInfo",i),s.setGlobalData("token",a),s.setGlobalData("uid",D),this.setDomain(r),this.offlineThreshold=A,u.default.warn(`init sdk success, current version: ${this.version}`),this.initLan()}get deviceList(){return this._deviceList}set deviceList(e){this._deviceList=e,this.notiDeviceList()}get bleDevices(){return this._bleDevices}set bleDevices(e){this._bleDevices=e,this.notiDeviceList()}get lanDevices(){return this._lanDevices}set lanDevices(e){this._lanDevices=e,this.notiDeviceList()}get allDevices(){let e=p.merageBleLocalDevices([...this.deviceList],this.bleDevices);e=p.merageLanLocalDevices(e,this.lanDevices),this.bleHandle.connectedList.map(t=>{const i=e.findIndex(e=>e.bleDeviceID===t.deviceId);-1!==i&&(e[i].connectType="BLE")});const t=this.socketHandle._connections;return Object.keys(t).forEach(i=>{const n=t[i];n&&n._subDids.forEach(t=>{const i=e.findIndex(e=>e.did===t);-1!==i&&(e[i].connectType="WAN")})}),this.lanHandle.connectedList.map(t=>{const i=e.findIndex(e=>e.mac===t.mac&&e.productKey===t.productKey);-1!==i&&(e[i].connectType="LAN")}),console.log("newDevices",e),e}get bleScanDevice(){return this.bleDevices.filter(e=>!0===e.isBleOnline)}get bleHandle(){return this._bleHandle||(this._bleHandle=new r.BleHandle({pks:this.specialProductKeys,offlineThreshold:this.offlineThreshold})),this._bleHandle}get lanHandle(){return this._lanHandle||(this._lanHandle=new D.LanHandle({pks:this.specialProductKeys})),this._lanHandle}get socketHandle(){return this._gizSocket||(this._gizSocket=new a.default({appID:s.getGlobalData("appID"),token:s.getGlobalData("token"),uid:s.getGlobalData("uid")}),this._gizSocket.subscribeDeviceStatus(this.handleSocketDeviceData),this._gizSocket.subscribeBindingChanged(this.getBindingList),this._gizSocket.subscribeSocketStatus(this.handleSocketStatus)),this._gizSocket}get specialProductKeys(){return this.productInfo.map(e=>{var t;return null!==(t=e.productKey)&&void 0!==t?t:""})}get specialProductKeySecrets(){return this.productInfo.map(e=>{var t;return null!==(t=e.productSecret)&&void 0!==t?t:""})}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(11),s=i(18);t.default=e=>{const t=wx.getSystemInfoSync(),i={exception:{values:[{type:"Error",value:e.stack,stacktrace:{},mechanism:{type:"generic",handled:!0}}]},level:"error",event_id:n.MD5(`${(new Date).getTime()}`).toString(),platform:"javascript",sdk:{},timestamp:(new Date).getTime()/1e3,environment:"production",contexts:{device:{},os:{name:t.platform,version:t.version},extra:{}},extra:{message:e.message}};var r={method:"POST",headers:{Connection:"keep-alive","User-Agent":"Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1 wechatdevtools/1.06.2206090 MicroMessenger/8.0.5 Language/zh_CN webview/","content-type":"application/json",Accept:"*/*","Sec-Fetch-Site":"cross-site","Sec-Fetch-Mode":"cors","Sec-Fetch-Dest":"empty",Referer:"https://servicewechat.com/wx6dc8e50cb68bc121/devtools/page-frame.html",Cookie:"__org="},data:JSON.stringify(i)};s.default("https://appmonitor.gizwits.com/api/21/store/?sentry_key=0b2de791abf548a1bedf0b0ebdd8ecc7&sentry_version=7",r)}},function(e,t){},function(e,t,i){var n;e.exports=(n=i(0),function(){if("function"==typeof ArrayBuffer){var e=n.lib.WordArray,t=e.init;(e.init=function(e){if(e instanceof ArrayBuffer&&(e=new Uint8Array(e)),(e instanceof Int8Array||"undefined"!=typeof Uint8ClampedArray&&e instanceof Uint8ClampedArray||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array)&&(e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),e instanceof Uint8Array){for(var i=e.byteLength,n=[],s=0;s<i;s++)n[s>>>2]|=e[s]<<24-s%4*8;t.call(this,n,i)}else t.apply(this,arguments)}).prototype=e}}(),n.lib.WordArray)},function(e,t,i){var n;e.exports=(n=i(0),function(){var e=n,t=e.lib.WordArray,i=e.enc;function s(e){return e<<8&4278255360|e>>>8&16711935}i.Utf16=i.Utf16BE={stringify:function(e){for(var t=e.words,i=e.sigBytes,n=[],s=0;s<i;s+=2){var r=t[s>>>2]>>>16-s%4*8&65535;n.push(String.fromCharCode(r))}return n.join("")},parse:function(e){for(var i=e.length,n=[],s=0;s<i;s++)n[s>>>1]|=e.charCodeAt(s)<<16-s%2*16;return t.create(n,2*i)}},i.Utf16LE={stringify:function(e){for(var t=e.words,i=e.sigBytes,n=[],r=0;r<i;r+=2){var a=s(t[r>>>2]>>>16-r%4*8&65535);n.push(String.fromCharCode(a))}return n.join("")},parse:function(e){for(var i=e.length,n=[],r=0;r<i;r++)n[r>>>1]|=s(e.charCodeAt(r)<<16-r%2*16);return t.create(n,2*i)}}}(),n.enc.Utf16)},function(e,t,i){var n,s,r;e.exports=(r=i(0),s=(n=r).lib.WordArray,n.enc.Base64url={stringify:function(e,t){void 0===t&&(t=!0);var i=e.words,n=e.sigBytes,s=t?this._safe_map:this._map;e.clamp();for(var r=[],a=0;a<n;a+=3)for(var o=(i[a>>>2]>>>24-a%4*8&255)<<16|(i[a+1>>>2]>>>24-(a+1)%4*8&255)<<8|i[a+2>>>2]>>>24-(a+2)%4*8&255,c=0;c<4&&a+.75*c<n;c++)r.push(s.charAt(o>>>6*(3-c)&63));var l=s.charAt(64);if(l)for(;r.length%4;)r.push(l);return r.join("")},parse:function(e,t){void 0===t&&(t=!0);var i=e.length,n=t?this._safe_map:this._map,r=this._reverseMap;if(!r){r=this._reverseMap=[];for(var a=0;a<n.length;a++)r[n.charCodeAt(a)]=a}var o=n.charAt(64);if(o){var c=e.indexOf(o);-1!==c&&(i=c)}return function(e,t,i){for(var n=[],r=0,a=0;a<t;a++)if(a%4){var o=i[e.charCodeAt(a-1)]<<a%4*2,c=i[e.charCodeAt(a)]>>>6-a%4*2,l=o|c;n[r>>>2]|=l<<24-r%4*8,r++}return s.create(n,r)}(e,i,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",_safe_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"},r.enc.Base64url)},function(e,t,i){var n,s,r,a,o,c;e.exports=(c=i(0),i(16),s=(n=c).lib.WordArray,r=n.algo,a=r.SHA256,o=r.SHA224=a.extend({_doReset:function(){this._hash=new s.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var e=a._doFinalize.call(this);return e.sigBytes-=4,e}}),n.SHA224=a._createHelper(o),n.HmacSHA224=a._createHmacHelper(o),c.SHA224)},function(e,t,i){var n,s,r,a,o,c,l,u;e.exports=(u=i(0),i(13),i(25),s=(n=u).x64,r=s.Word,a=s.WordArray,o=n.algo,c=o.SHA512,l=o.SHA384=c.extend({_doReset:function(){this._hash=new a.init([new r.init(3418070365,3238371032),new r.init(1654270250,914150663),new r.init(2438529370,812702999),new r.init(355462360,4144912697),new r.init(1731405415,4290775857),new r.init(2394180231,1750603025),new r.init(3675008525,1694076839),new r.init(1203062813,3204075428)])},_doFinalize:function(){var e=c._doFinalize.call(this);return e.sigBytes-=16,e}}),n.SHA384=c._createHelper(l),n.HmacSHA384=c._createHmacHelper(l),u.SHA384)},function(e,t,i){var n;e.exports=(n=i(0),i(13),function(e){var t=n,i=t.lib,s=i.WordArray,r=i.Hasher,a=t.x64.Word,o=t.algo,c=[],l=[],u=[];!function(){for(var e=1,t=0,i=0;i<24;i++){c[e+5*t]=(i+1)*(i+2)/2%64;var n=(2*e+3*t)%5;e=t%5,t=n}for(e=0;e<5;e++)for(t=0;t<5;t++)l[e+5*t]=t+(2*e+3*t)%5*5;for(var s=1,r=0;r<24;r++){for(var o=0,d=0,h=0;h<7;h++){if(1&s){var f=(1<<h)-1;f<32?d^=1<<f:o^=1<<f-32}128&s?s=s<<1^113:s<<=1}u[r]=a.create(o,d)}}();var d=[];!function(){for(var e=0;e<25;e++)d[e]=a.create()}();var h=o.SHA3=r.extend({cfg:r.cfg.extend({outputLength:512}),_doReset:function(){for(var e=this._state=[],t=0;t<25;t++)e[t]=new a.init;this.blockSize=(1600-2*this.cfg.outputLength)/32},_doProcessBlock:function(e,t){for(var i=this._state,n=this.blockSize/2,s=0;s<n;s++){var r=e[t+2*s],a=e[t+2*s+1];r=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),a=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),(C=i[s]).high^=a,C.low^=r}for(var o=0;o<24;o++){for(var h=0;h<5;h++){for(var f=0,p=0,v=0;v<5;v++)f^=(C=i[h+5*v]).high,p^=C.low;var g=d[h];g.high=f,g.low=p}for(h=0;h<5;h++){var y=d[(h+4)%5],D=d[(h+1)%5],_=D.high,m=D.low;for(f=y.high^(_<<1|m>>>31),p=y.low^(m<<1|_>>>31),v=0;v<5;v++)(C=i[h+5*v]).high^=f,C.low^=p}for(var b=1;b<25;b++){var S=(C=i[b]).high,w=C.low,I=c[b];I<32?(f=S<<I|w>>>32-I,p=w<<I|S>>>32-I):(f=w<<I-32|S>>>64-I,p=S<<I-32|w>>>64-I);var B=d[l[b]];B.high=f,B.low=p}var A=d[0],k=i[0];for(A.high=k.high,A.low=k.low,h=0;h<5;h++)for(v=0;v<5;v++){var C=i[b=h+5*v],E=d[b],T=d[(h+1)%5+5*v],P=d[(h+2)%5+5*v];C.high=E.high^~T.high&P.high,C.low=E.low^~T.low&P.low}C=i[0];var O=u[o];C.high^=O.high,C.low^=O.low}},_doFinalize:function(){var t=this._data,i=t.words,n=(this._nDataBytes,8*t.sigBytes),r=32*this.blockSize;i[n>>>5]|=1<<24-n%32,i[(e.ceil((n+1)/r)*r>>>5)-1]|=128,t.sigBytes=4*i.length,this._process();for(var a=this._state,o=this.cfg.outputLength/8,c=o/8,l=[],u=0;u<c;u++){var d=a[u],h=d.high,f=d.low;h=16711935&(h<<8|h>>>24)|4278255360&(h<<24|h>>>8),f=16711935&(f<<8|f>>>24)|4278255360&(f<<24|f>>>8),l.push(f),l.push(h)}return new s.init(l,o)},clone:function(){for(var e=r.clone.call(this),t=e._state=this._state.slice(0),i=0;i<25;i++)t[i]=t[i].clone();return e}});t.SHA3=r._createHelper(h),t.HmacSHA3=r._createHmacHelper(h)}(Math),n.SHA3)},function(e,t,i){var n;e.exports=(n=i(0),
|
|
2
2
|
/** @preserve
|
|
3
3
|
(c) 2012 by Cédric Mesnil. All rights reserved.
|
|
4
4
|
|
|
@@ -9,17 +9,17 @@ module.exports=function(e){var t={};function i(n){if(t[n])return t[n].exports;va
|
|
|
9
9
|
|
|
10
10
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
11
11
|
*/
|
|
12
|
-
function(e){var t=n,i=t.lib,s=i.WordArray,r=i.Hasher,a=t.algo,o=s.create([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13]),c=s.create([5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11]),l=s.create([11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6]),u=s.create([8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]),d=s.create([0,1518500249,1859775393,2400959708,2840853838]),h=s.create([1352829926,1548603684,1836072691,2053994217,0]),f=a.RIPEMD160=r.extend({_doReset:function(){this._hash=s.create([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(e,t){for(var i=0;i<16;i++){var n=t+i,s=e[n];e[n]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8)}var r,a,f,m,b,S,w,I,B,A,k,C=this._hash.words,E=d.words,T=h.words,P=o.words,O=c.words,L=l.words,x=u.words;for(S=r=C[0],w=a=C[1],I=f=C[2],B=m=C[3],A=b=C[4],i=0;i<80;i+=1)k=r+e[t+P[i]]|0,k+=i<16?p(a,f,m)+E[0]:i<32?v(a,f,m)+E[1]:i<48?g(a,f,m)+E[2]:i<64?y(a,f,m)+E[3]:
|
|
12
|
+
function(e){var t=n,i=t.lib,s=i.WordArray,r=i.Hasher,a=t.algo,o=s.create([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13]),c=s.create([5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11]),l=s.create([11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6]),u=s.create([8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]),d=s.create([0,1518500249,1859775393,2400959708,2840853838]),h=s.create([1352829926,1548603684,1836072691,2053994217,0]),f=a.RIPEMD160=r.extend({_doReset:function(){this._hash=s.create([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(e,t){for(var i=0;i<16;i++){var n=t+i,s=e[n];e[n]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8)}var r,a,f,m,b,S,w,I,B,A,k,C=this._hash.words,E=d.words,T=h.words,P=o.words,O=c.words,L=l.words,x=u.words;for(S=r=C[0],w=a=C[1],I=f=C[2],B=m=C[3],A=b=C[4],i=0;i<80;i+=1)k=r+e[t+P[i]]|0,k+=i<16?p(a,f,m)+E[0]:i<32?v(a,f,m)+E[1]:i<48?g(a,f,m)+E[2]:i<64?y(a,f,m)+E[3]:D(a,f,m)+E[4],k=(k=_(k|=0,L[i]))+b|0,r=b,b=m,m=_(f,10),f=a,a=k,k=S+e[t+O[i]]|0,k+=i<16?D(w,I,B)+T[0]:i<32?y(w,I,B)+T[1]:i<48?g(w,I,B)+T[2]:i<64?v(w,I,B)+T[3]:p(w,I,B)+T[4],k=(k=_(k|=0,x[i]))+A|0,S=A,A=B,B=_(I,10),I=w,w=k;k=C[1]+f+B|0,C[1]=C[2]+m+A|0,C[2]=C[3]+b+S|0,C[3]=C[4]+r+w|0,C[4]=C[0]+a+I|0,C[0]=k},_doFinalize:function(){var e=this._data,t=e.words,i=8*this._nDataBytes,n=8*e.sigBytes;t[n>>>5]|=128<<24-n%32,t[14+(n+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),e.sigBytes=4*(t.length+1),this._process();for(var s=this._hash,r=s.words,a=0;a<5;a++){var o=r[a];r[a]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}return s},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});function p(e,t,i){return e^t^i}function v(e,t,i){return e&t|~e&i}function g(e,t,i){return(e|~t)^i}function y(e,t,i){return e&i|t&~i}function D(e,t,i){return e^(t|~i)}function _(e,t){return e<<t|e>>>32-t}t.RIPEMD160=r._createHelper(f),t.HmacRIPEMD160=r._createHmacHelper(f)}(Math),n.RIPEMD160)},function(e,t,i){var n,s,r,a,o,c,l,u,d;e.exports=(d=i(0),i(16),i(17),s=(n=d).lib,r=s.Base,a=s.WordArray,o=n.algo,c=o.SHA256,l=o.HMAC,u=o.PBKDF2=r.extend({cfg:r.extend({keySize:4,hasher:c,iterations:25e4}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var i=this.cfg,n=l.create(i.hasher,e),s=a.create(),r=a.create([1]),o=s.words,c=r.words,u=i.keySize,d=i.iterations;o.length<u;){var h=n.update(t).finalize(r);n.reset();for(var f=h.words,p=f.length,v=h,g=1;g<d;g++){v=n.finalize(v),n.reset();for(var y=v.words,D=0;D<p;D++)f[D]^=y[D]}s.concat(h),c[0]++}return s.sigBytes=4*u,s}}),n.PBKDF2=function(e,t,i){return u.create(i).compute(e,t)},d.PBKDF2)},function(e,t,i){var n;e.exports=(n=i(0),i(2),n.mode.CFB=function(){var e=n.lib.BlockCipherMode.extend();function t(e,t,i,n){var s,r=this._iv;r?(s=r.slice(0),this._iv=void 0):s=this._prevBlock,n.encryptBlock(s,0);for(var a=0;a<i;a++)e[t+a]^=s[a]}return e.Encryptor=e.extend({processBlock:function(e,i){var n=this._cipher,s=n.blockSize;t.call(this,e,i,s,n),this._prevBlock=e.slice(i,i+s)}}),e.Decryptor=e.extend({processBlock:function(e,i){var n=this._cipher,s=n.blockSize,r=e.slice(i,i+s);t.call(this,e,i,s,n),this._prevBlock=r}}),e}(),n.mode.CFB)},function(e,t,i){var n,s,r;e.exports=(r=i(0),i(2),r.mode.CTR=(n=r.lib.BlockCipherMode.extend(),s=n.Encryptor=n.extend({processBlock:function(e,t){var i=this._cipher,n=i.blockSize,s=this._iv,r=this._counter;s&&(r=this._counter=s.slice(0),this._iv=void 0);var a=r.slice(0);i.encryptBlock(a,0),r[n-1]=r[n-1]+1|0;for(var o=0;o<n;o++)e[t+o]^=a[o]}}),n.Decryptor=s,n),r.mode.CTR)},function(e,t,i){var n;e.exports=(n=i(0),i(2),
|
|
13
13
|
/** @preserve
|
|
14
14
|
* Counter block mode compatible with Dr Brian Gladman fileenc.c
|
|
15
15
|
* derived from CryptoJS.mode.CTR
|
|
16
16
|
* Jan Hruby jhruby.web@gmail.com
|
|
17
17
|
*/
|
|
18
|
-
n.mode.CTRGladman=function(){var e=n.lib.BlockCipherMode.extend();function t(e){if(255==(e>>24&255)){var t=e>>16&255,i=e>>8&255,n=255&e;255===t?(t=0,255===i?(i=0,255===n?n=0:++n):++i):++t,e=0,e+=t<<16,e+=i<<8,e+=n}else e+=1<<24;return e}var i=e.Encryptor=e.extend({processBlock:function(e,i){var n=this._cipher,s=n.blockSize,r=this._iv,a=this._counter;r&&(a=this._counter=r.slice(0),this._iv=void 0),function(e){0===(e[0]=t(e[0]))&&(e[1]=t(e[1]))}(a);var o=a.slice(0);n.encryptBlock(o,0);for(var c=0;c<s;c++)e[i+c]^=o[c]}});return e.Decryptor=i,e}(),n.mode.CTRGladman)},function(e,t,i){var n,s,r;e.exports=(r=i(0),i(2),r.mode.OFB=(n=r.lib.BlockCipherMode.extend(),s=n.Encryptor=n.extend({processBlock:function(e,t){var i=this._cipher,n=i.blockSize,s=this._iv,r=this._keystream;s&&(r=this._keystream=s.slice(0),this._iv=void 0),i.encryptBlock(r,0);for(var a=0;a<n;a++)e[t+a]^=r[a]}}),n.Decryptor=s,n),r.mode.OFB)},function(e,t,i){var n,s;e.exports=(s=i(0),i(2),s.mode.ECB=((n=s.lib.BlockCipherMode.extend()).Encryptor=n.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),n.Decryptor=n.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),n),s.mode.ECB)},function(e,t,i){var n;e.exports=(n=i(0),i(2),n.pad.AnsiX923={pad:function(e,t){var i=e.sigBytes,n=4*t,s=n-i%n,r=i+s-1;e.clamp(),e.words[r>>>2]|=s<<24-r%4*8,e.sigBytes+=s},unpad:function(e){var t=255&e.words[e.sigBytes-1>>>2];e.sigBytes-=t}},n.pad.Ansix923)},function(e,t,i){var n;e.exports=(n=i(0),i(2),n.pad.Iso10126={pad:function(e,t){var i=4*t,s=i-e.sigBytes%i;e.concat(n.lib.WordArray.random(s-1)).concat(n.lib.WordArray.create([s<<24],1))},unpad:function(e){var t=255&e.words[e.sigBytes-1>>>2];e.sigBytes-=t}},n.pad.Iso10126)},function(e,t,i){var n;e.exports=(n=i(0),i(2),n.pad.Iso97971={pad:function(e,t){e.concat(n.lib.WordArray.create([2147483648],1)),n.pad.ZeroPadding.pad(e,t)},unpad:function(e){n.pad.ZeroPadding.unpad(e),e.sigBytes--}},n.pad.Iso97971)},function(e,t,i){var n;e.exports=(n=i(0),i(2),n.pad.ZeroPadding={pad:function(e,t){var i=4*t;e.clamp(),e.sigBytes+=i-(e.sigBytes%i||i)},unpad:function(e){var t=e.words,i=e.sigBytes-1;for(i=e.sigBytes-1;i>=0;i--)if(t[i>>>2]>>>24-i%4*8&255){e.sigBytes=i+1;break}}},n.pad.ZeroPadding)},function(e,t,i){var n;e.exports=(n=i(0),i(2),n.pad.NoPadding={pad:function(){},unpad:function(){}},n.pad.NoPadding)},function(e,t,i){var n,s,r,a;e.exports=(a=i(0),i(2),s=(n=a).lib.CipherParams,r=n.enc.Hex,n.format.Hex={stringify:function(e){return e.ciphertext.toString(r)},parse:function(e){var t=r.parse(e);return s.create({ciphertext:t})}},a.format.Hex)},function(e,t,i){var n;e.exports=(n=i(0),i(7),i(8),i(6),i(2),function(){var e=n,t=e.lib.BlockCipher,i=e.algo,s=[],r=[],a=[],o=[],c=[],l=[],u=[],d=[],h=[],f=[];!function(){for(var e=[],t=0;t<256;t++)e[t]=t<128?t<<1:t<<1^283;var i=0,n=0;for(t=0;t<256;t++){var p=n^n<<1^n<<2^n<<3^n<<4;p=p>>>8^255&p^99,s[i]=p,r[p]=i;var v=e[i],g=e[v],y=e[g],_=257*e[p]^16843008*p;a[i]=_<<24|_>>>8,o[i]=_<<16|_>>>16,c[i]=_<<8|_>>>24,l[i]=_,_=16843009*y^65537*g^257*v^16843008*i,u[p]=_<<24|_>>>8,d[p]=_<<16|_>>>16,h[p]=_<<8|_>>>24,f[p]=_,i?(i=v^e[e[e[y^v]]],n^=e[e[n]]):i=n=1}}();var p=[0,1,2,4,8,16,32,64,128,27,54],v=i.AES=t.extend({_doReset:function(){if(!this._nRounds||this._keyPriorReset!==this._key){for(var e=this._keyPriorReset=this._key,t=e.words,i=e.sigBytes/4,n=4*((this._nRounds=i+6)+1),r=this._keySchedule=[],a=0;a<n;a++)a<i?r[a]=t[a]:(l=r[a-1],a%i?i>6&&a%i==4&&(l=s[l>>>24]<<24|s[l>>>16&255]<<16|s[l>>>8&255]<<8|s[255&l]):(l=s[(l=l<<8|l>>>24)>>>24]<<24|s[l>>>16&255]<<16|s[l>>>8&255]<<8|s[255&l],l^=p[a/i|0]<<24),r[a]=r[a-i]^l);for(var o=this._invKeySchedule=[],c=0;c<n;c++){if(a=n-c,c%4)var l=r[a];else l=r[a-4];o[c]=c<4||a<=4?l:u[s[l>>>24]]^d[s[l>>>16&255]]^h[s[l>>>8&255]]^f[s[255&l]]}}},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,a,o,c,l,s)},decryptBlock:function(e,t){var i=e[t+1];e[t+1]=e[t+3],e[t+3]=i,this._doCryptBlock(e,t,this._invKeySchedule,u,d,h,f,r),i=e[t+1],e[t+1]=e[t+3],e[t+3]=i},_doCryptBlock:function(e,t,i,n,s,r,a,o){for(var c=this._nRounds,l=e[t]^i[0],u=e[t+1]^i[1],d=e[t+2]^i[2],h=e[t+3]^i[3],f=4,p=1;p<c;p++){var v=n[l>>>24]^s[u>>>16&255]^r[d>>>8&255]^a[255&h]^i[f++],g=n[u>>>24]^s[d>>>16&255]^r[h>>>8&255]^a[255&l]^i[f++],y=n[d>>>24]^s[h>>>16&255]^r[l>>>8&255]^a[255&u]^i[f++],_=n[h>>>24]^s[l>>>16&255]^r[u>>>8&255]^a[255&d]^i[f++];l=v,u=g,d=y,h=_}v=(o[l>>>24]<<24|o[u>>>16&255]<<16|o[d>>>8&255]<<8|o[255&h])^i[f++],g=(o[u>>>24]<<24|o[d>>>16&255]<<16|o[h>>>8&255]<<8|o[255&l])^i[f++],y=(o[d>>>24]<<24|o[h>>>16&255]<<16|o[l>>>8&255]<<8|o[255&u])^i[f++],_=(o[h>>>24]<<24|o[l>>>16&255]<<16|o[u>>>8&255]<<8|o[255&d])^i[f++],e[t]=v,e[t+1]=g,e[t+2]=y,e[t+3]=_},keySize:8});e.AES=t._createHelper(v)}(),n.AES)},function(e,t,i){var n;e.exports=(n=i(0),i(7),i(8),i(6),i(2),function(){var e=n,t=e.lib,i=t.WordArray,s=t.BlockCipher,r=e.algo,a=[57,49,41,33,25,17,9,1,58,50,42,34,26,18,10,2,59,51,43,35,27,19,11,3,60,52,44,36,63,55,47,39,31,23,15,7,62,54,46,38,30,22,14,6,61,53,45,37,29,21,13,5,28,20,12,4],o=[14,17,11,24,1,5,3,28,15,6,21,10,23,19,12,4,26,8,16,7,27,20,13,2,41,52,31,37,47,55,30,40,51,45,33,48,44,49,39,56,34,53,46,42,50,36,29,32],c=[1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28],l=[{0:8421888,268435456:32768,536870912:8421378,805306368:2,1073741824:512,1342177280:8421890,1610612736:8389122,1879048192:8388608,2147483648:514,2415919104:8389120,2684354560:33280,2952790016:8421376,3221225472:32770,3489660928:8388610,3758096384:0,4026531840:33282,134217728:0,402653184:8421890,671088640:33282,939524096:32768,1207959552:8421888,1476395008:512,1744830464:8421378,2013265920:2,2281701376:8389120,2550136832:33280,2818572288:8421376,3087007744:8389122,3355443200:8388610,3623878656:32770,3892314112:514,4160749568:8388608,1:32768,268435457:2,536870913:8421888,805306369:8388608,1073741825:8421378,1342177281:33280,1610612737:512,1879048193:8389122,2147483649:8421890,2415919105:8421376,2684354561:8388610,2952790017:33282,3221225473:514,3489660929:8389120,3758096385:32770,4026531841:0,134217729:8421890,402653185:8421376,671088641:8388608,939524097:512,1207959553:32768,1476395009:8388610,1744830465:2,2013265921:33282,2281701377:32770,2550136833:8389122,2818572289:514,3087007745:8421888,3355443201:8389120,3623878657:0,3892314113:33280,4160749569:8421378},{0:1074282512,16777216:16384,33554432:524288,50331648:1074266128,67108864:1073741840,83886080:1074282496,100663296:1073758208,117440512:16,134217728:540672,150994944:1073758224,167772160:1073741824,184549376:540688,201326592:524304,218103808:0,234881024:16400,251658240:1074266112,8388608:1073758208,25165824:540688,41943040:16,58720256:1073758224,75497472:1074282512,92274688:1073741824,109051904:524288,125829120:1074266128,142606336:524304,159383552:0,176160768:16384,192937984:1074266112,209715200:1073741840,226492416:540672,243269632:1074282496,260046848:16400,268435456:0,285212672:1074266128,301989888:1073758224,318767104:1074282496,335544320:1074266112,352321536:16,369098752:540688,385875968:16384,402653184:16400,419430400:524288,436207616:524304,452984832:1073741840,469762048:540672,486539264:1073758208,503316480:1073741824,520093696:1074282512,276824064:540688,293601280:524288,310378496:1074266112,327155712:16384,343932928:1073758208,360710144:1074282512,377487360:16,394264576:1073741824,411041792:1074282496,427819008:1073741840,444596224:1073758224,461373440:524304,478150656:0,494927872:16400,511705088:1074266128,528482304:540672},{0:260,1048576:0,2097152:67109120,3145728:65796,4194304:65540,5242880:67108868,6291456:67174660,7340032:67174400,8388608:67108864,9437184:67174656,10485760:65792,11534336:67174404,12582912:67109124,13631488:65536,14680064:4,15728640:256,524288:67174656,1572864:67174404,2621440:0,3670016:67109120,4718592:67108868,5767168:65536,6815744:65540,7864320:260,8912896:4,9961472:256,11010048:67174400,12058624:65796,13107200:65792,14155776:67109124,15204352:67174660,16252928:67108864,16777216:67174656,17825792:65540,18874368:65536,19922944:67109120,20971520:256,22020096:67174660,23068672:67108868,24117248:0,25165824:67109124,26214400:67108864,27262976:4,28311552:65792,29360128:67174400,30408704:260,31457280:65796,32505856:67174404,17301504:67108864,18350080:260,19398656:67174656,20447232:0,21495808:65540,22544384:67109120,23592960:256,24641536:67174404,25690112:65536,26738688:67174660,27787264:65796,28835840:67108868,29884416:67109124,30932992:67174400,31981568:4,33030144:65792},{0:2151682048,65536:2147487808,131072:4198464,196608:2151677952,262144:0,327680:4198400,393216:2147483712,458752:4194368,524288:2147483648,589824:4194304,655360:64,720896:2147487744,786432:2151678016,851968:4160,917504:4096,983040:2151682112,32768:2147487808,98304:64,163840:2151678016,229376:2147487744,294912:4198400,360448:2151682112,425984:0,491520:2151677952,557056:4096,622592:2151682048,688128:4194304,753664:4160,819200:2147483648,884736:4194368,950272:4198464,1015808:2147483712,1048576:4194368,1114112:4198400,1179648:2147483712,1245184:0,1310720:4160,1376256:2151678016,1441792:2151682048,1507328:2147487808,1572864:2151682112,1638400:2147483648,1703936:2151677952,1769472:4198464,1835008:2147487744,1900544:4194304,1966080:64,2031616:4096,1081344:2151677952,1146880:2151682112,1212416:0,1277952:4198400,1343488:4194368,1409024:2147483648,1474560:2147487808,1540096:64,1605632:2147483712,1671168:4096,1736704:2147487744,1802240:2151678016,1867776:4160,1933312:2151682048,1998848:4194304,2064384:4198464},{0:128,4096:17039360,8192:262144,12288:536870912,16384:537133184,20480:16777344,24576:553648256,28672:262272,32768:16777216,36864:537133056,40960:536871040,45056:553910400,49152:553910272,53248:0,57344:17039488,61440:553648128,2048:17039488,6144:553648256,10240:128,14336:17039360,18432:262144,22528:537133184,26624:553910272,30720:536870912,34816:537133056,38912:0,43008:553910400,47104:16777344,51200:536871040,55296:553648128,59392:16777216,63488:262272,65536:262144,69632:128,73728:536870912,77824:553648256,81920:16777344,86016:553910272,90112:537133184,94208:16777216,98304:553910400,102400:553648128,106496:17039360,110592:537133056,114688:262272,118784:536871040,122880:0,126976:17039488,67584:553648256,71680:16777216,75776:17039360,79872:537133184,83968:536870912,88064:17039488,92160:128,96256:553910272,100352:262272,104448:553910400,108544:0,112640:553648128,116736:16777344,120832:262144,124928:537133056,129024:536871040},{0:268435464,256:8192,512:270532608,768:270540808,1024:268443648,1280:2097152,1536:2097160,1792:268435456,2048:0,2304:268443656,2560:2105344,2816:8,3072:270532616,3328:2105352,3584:8200,3840:270540800,128:270532608,384:270540808,640:8,896:2097152,1152:2105352,1408:268435464,1664:268443648,1920:8200,2176:2097160,2432:8192,2688:268443656,2944:270532616,3200:0,3456:270540800,3712:2105344,3968:268435456,4096:268443648,4352:270532616,4608:270540808,4864:8200,5120:2097152,5376:268435456,5632:268435464,5888:2105344,6144:2105352,6400:0,6656:8,6912:270532608,7168:8192,7424:268443656,7680:270540800,7936:2097160,4224:8,4480:2105344,4736:2097152,4992:268435464,5248:268443648,5504:8200,5760:270540808,6016:270532608,6272:270540800,6528:270532616,6784:8192,7040:2105352,7296:2097160,7552:0,7808:268435456,8064:268443656},{0:1048576,16:33555457,32:1024,48:1049601,64:34604033,80:0,96:1,112:34603009,128:33555456,144:1048577,160:33554433,176:34604032,192:34603008,208:1025,224:1049600,240:33554432,8:34603009,24:0,40:33555457,56:34604032,72:1048576,88:33554433,104:33554432,120:1025,136:1049601,152:33555456,168:34603008,184:1048577,200:1024,216:34604033,232:1,248:1049600,256:33554432,272:1048576,288:33555457,304:34603009,320:1048577,336:33555456,352:34604032,368:1049601,384:1025,400:34604033,416:1049600,432:1,448:0,464:34603008,480:33554433,496:1024,264:1049600,280:33555457,296:34603009,312:1,328:33554432,344:1048576,360:1025,376:34604032,392:33554433,408:34603008,424:0,440:34604033,456:1049601,472:1024,488:33555456,504:1048577},{0:134219808,1:131072,2:134217728,3:32,4:131104,5:134350880,6:134350848,7:2048,8:134348800,9:134219776,10:133120,11:134348832,12:2080,13:0,14:134217760,15:133152,2147483648:2048,2147483649:134350880,2147483650:134219808,2147483651:134217728,2147483652:134348800,2147483653:133120,2147483654:133152,2147483655:32,2147483656:134217760,2147483657:2080,2147483658:131104,2147483659:134350848,2147483660:0,2147483661:134348832,2147483662:134219776,2147483663:131072,16:133152,17:134350848,18:32,19:2048,20:134219776,21:134217760,22:134348832,23:131072,24:0,25:131104,26:134348800,27:134219808,28:134350880,29:133120,30:2080,31:134217728,2147483664:131072,2147483665:2048,2147483666:134348832,2147483667:133152,2147483668:32,2147483669:134348800,2147483670:134217728,2147483671:134219808,2147483672:134350880,2147483673:134217760,2147483674:134219776,2147483675:0,2147483676:133120,2147483677:2080,2147483678:131104,2147483679:134350848}],u=[4160749569,528482304,33030144,2064384,129024,8064,504,2147483679],d=r.DES=s.extend({_doReset:function(){for(var e=this._key.words,t=[],i=0;i<56;i++){var n=a[i]-1;t[i]=e[n>>>5]>>>31-n%32&1}for(var s=this._subKeys=[],r=0;r<16;r++){var l=s[r]=[],u=c[r];for(i=0;i<24;i++)l[i/6|0]|=t[(o[i]-1+u)%28]<<31-i%6,l[4+(i/6|0)]|=t[28+(o[i+24]-1+u)%28]<<31-i%6;for(l[0]=l[0]<<1|l[0]>>>31,i=1;i<7;i++)l[i]=l[i]>>>4*(i-1)+3;l[7]=l[7]<<5|l[7]>>>27}var d=this._invSubKeys=[];for(i=0;i<16;i++)d[i]=s[15-i]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._subKeys)},decryptBlock:function(e,t){this._doCryptBlock(e,t,this._invSubKeys)},_doCryptBlock:function(e,t,i){this._lBlock=e[t],this._rBlock=e[t+1],h.call(this,4,252645135),h.call(this,16,65535),f.call(this,2,858993459),f.call(this,8,16711935),h.call(this,1,1431655765);for(var n=0;n<16;n++){for(var s=i[n],r=this._lBlock,a=this._rBlock,o=0,c=0;c<8;c++)o|=l[c][((a^s[c])&u[c])>>>0];this._lBlock=a,this._rBlock=r^o}var d=this._lBlock;this._lBlock=this._rBlock,this._rBlock=d,h.call(this,1,1431655765),f.call(this,8,16711935),f.call(this,2,858993459),h.call(this,16,65535),h.call(this,4,252645135),e[t]=this._lBlock,e[t+1]=this._rBlock},keySize:2,ivSize:2,blockSize:2});function h(e,t){var i=(this._lBlock>>>e^this._rBlock)&t;this._rBlock^=i,this._lBlock^=i<<e}function f(e,t){var i=(this._rBlock>>>e^this._lBlock)&t;this._lBlock^=i,this._rBlock^=i<<e}e.DES=s._createHelper(d);var p=r.TripleDES=s.extend({_doReset:function(){var e=this._key.words;if(2!==e.length&&4!==e.length&&e.length<6)throw new Error("Invalid key length - 3DES requires the key length to be 64, 128, 192 or >192.");var t=e.slice(0,2),n=e.length<4?e.slice(0,2):e.slice(2,4),s=e.length<6?e.slice(0,2):e.slice(4,6);this._des1=d.createEncryptor(i.create(t)),this._des2=d.createEncryptor(i.create(n)),this._des3=d.createEncryptor(i.create(s))},encryptBlock:function(e,t){this._des1.encryptBlock(e,t),this._des2.decryptBlock(e,t),this._des3.encryptBlock(e,t)},decryptBlock:function(e,t){this._des3.decryptBlock(e,t),this._des2.encryptBlock(e,t),this._des1.decryptBlock(e,t)},keySize:6,ivSize:2,blockSize:2});e.TripleDES=s._createHelper(p)}(),n.TripleDES)},function(e,t,i){var n;e.exports=(n=i(0),i(7),i(8),i(6),i(2),function(){var e=n,t=e.lib.StreamCipher,i=e.algo,s=i.RC4=t.extend({_doReset:function(){for(var e=this._key,t=e.words,i=e.sigBytes,n=this._S=[],s=0;s<256;s++)n[s]=s;s=0;for(var r=0;s<256;s++){var a=s%i,o=t[a>>>2]>>>24-a%4*8&255;r=(r+n[s]+o)%256;var c=n[s];n[s]=n[r],n[r]=c}this._i=this._j=0},_doProcessBlock:function(e,t){e[t]^=r.call(this)},keySize:8,ivSize:0});function r(){for(var e=this._S,t=this._i,i=this._j,n=0,s=0;s<4;s++){i=(i+e[t=(t+1)%256])%256;var r=e[t];e[t]=e[i],e[i]=r,n|=e[(e[t]+e[i])%256]<<24-8*s}return this._i=t,this._j=i,n}e.RC4=t._createHelper(s);var a=i.RC4Drop=s.extend({cfg:s.cfg.extend({drop:192}),_doReset:function(){s._doReset.call(this);for(var e=this.cfg.drop;e>0;e--)r.call(this)}});e.RC4Drop=t._createHelper(a)}(),n.RC4)},function(e,t,i){var n;e.exports=(n=i(0),i(7),i(8),i(6),i(2),function(){var e=n,t=e.lib.StreamCipher,i=e.algo,s=[],r=[],a=[],o=i.Rabbit=t.extend({_doReset:function(){for(var e=this._key.words,t=this.cfg.iv,i=0;i<4;i++)e[i]=16711935&(e[i]<<8|e[i]>>>24)|4278255360&(e[i]<<24|e[i]>>>8);var n=this._X=[e[0],e[3]<<16|e[2]>>>16,e[1],e[0]<<16|e[3]>>>16,e[2],e[1]<<16|e[0]>>>16,e[3],e[2]<<16|e[1]>>>16],s=this._C=[e[2]<<16|e[2]>>>16,4294901760&e[0]|65535&e[1],e[3]<<16|e[3]>>>16,4294901760&e[1]|65535&e[2],e[0]<<16|e[0]>>>16,4294901760&e[2]|65535&e[3],e[1]<<16|e[1]>>>16,4294901760&e[3]|65535&e[0]];for(this._b=0,i=0;i<4;i++)c.call(this);for(i=0;i<8;i++)s[i]^=n[i+4&7];if(t){var r=t.words,a=r[0],o=r[1],l=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),u=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8),d=l>>>16|4294901760&u,h=u<<16|65535&l;for(s[0]^=l,s[1]^=d,s[2]^=u,s[3]^=h,s[4]^=l,s[5]^=d,s[6]^=u,s[7]^=h,i=0;i<4;i++)c.call(this)}},_doProcessBlock:function(e,t){var i=this._X;c.call(this),s[0]=i[0]^i[5]>>>16^i[3]<<16,s[1]=i[2]^i[7]>>>16^i[5]<<16,s[2]=i[4]^i[1]>>>16^i[7]<<16,s[3]=i[6]^i[3]>>>16^i[1]<<16;for(var n=0;n<4;n++)s[n]=16711935&(s[n]<<8|s[n]>>>24)|4278255360&(s[n]<<24|s[n]>>>8),e[t+n]^=s[n]},blockSize:4,ivSize:2});function c(){for(var e=this._X,t=this._C,i=0;i<8;i++)r[i]=t[i];for(t[0]=t[0]+1295307597+this._b|0,t[1]=t[1]+3545052371+(t[0]>>>0<r[0]>>>0?1:0)|0,t[2]=t[2]+886263092+(t[1]>>>0<r[1]>>>0?1:0)|0,t[3]=t[3]+1295307597+(t[2]>>>0<r[2]>>>0?1:0)|0,t[4]=t[4]+3545052371+(t[3]>>>0<r[3]>>>0?1:0)|0,t[5]=t[5]+886263092+(t[4]>>>0<r[4]>>>0?1:0)|0,t[6]=t[6]+1295307597+(t[5]>>>0<r[5]>>>0?1:0)|0,t[7]=t[7]+3545052371+(t[6]>>>0<r[6]>>>0?1:0)|0,this._b=t[7]>>>0<r[7]>>>0?1:0,i=0;i<8;i++){var n=e[i]+t[i],s=65535&n,o=n>>>16,c=((s*s>>>17)+s*o>>>15)+o*o,l=((4294901760&n)*n|0)+((65535&n)*n|0);a[i]=c^l}e[0]=a[0]+(a[7]<<16|a[7]>>>16)+(a[6]<<16|a[6]>>>16)|0,e[1]=a[1]+(a[0]<<8|a[0]>>>24)+a[7]|0,e[2]=a[2]+(a[1]<<16|a[1]>>>16)+(a[0]<<16|a[0]>>>16)|0,e[3]=a[3]+(a[2]<<8|a[2]>>>24)+a[1]|0,e[4]=a[4]+(a[3]<<16|a[3]>>>16)+(a[2]<<16|a[2]>>>16)|0,e[5]=a[5]+(a[4]<<8|a[4]>>>24)+a[3]|0,e[6]=a[6]+(a[5]<<16|a[5]>>>16)+(a[4]<<16|a[4]>>>16)|0,e[7]=a[7]+(a[6]<<8|a[6]>>>24)+a[5]|0}e.Rabbit=t._createHelper(o)}(),n.Rabbit)},function(e,t,i){var n;e.exports=(n=i(0),i(7),i(8),i(6),i(2),function(){var e=n,t=e.lib.StreamCipher,i=e.algo,s=[],r=[],a=[],o=i.RabbitLegacy=t.extend({_doReset:function(){var e=this._key.words,t=this.cfg.iv,i=this._X=[e[0],e[3]<<16|e[2]>>>16,e[1],e[0]<<16|e[3]>>>16,e[2],e[1]<<16|e[0]>>>16,e[3],e[2]<<16|e[1]>>>16],n=this._C=[e[2]<<16|e[2]>>>16,4294901760&e[0]|65535&e[1],e[3]<<16|e[3]>>>16,4294901760&e[1]|65535&e[2],e[0]<<16|e[0]>>>16,4294901760&e[2]|65535&e[3],e[1]<<16|e[1]>>>16,4294901760&e[3]|65535&e[0]];this._b=0;for(var s=0;s<4;s++)c.call(this);for(s=0;s<8;s++)n[s]^=i[s+4&7];if(t){var r=t.words,a=r[0],o=r[1],l=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),u=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8),d=l>>>16|4294901760&u,h=u<<16|65535&l;for(n[0]^=l,n[1]^=d,n[2]^=u,n[3]^=h,n[4]^=l,n[5]^=d,n[6]^=u,n[7]^=h,s=0;s<4;s++)c.call(this)}},_doProcessBlock:function(e,t){var i=this._X;c.call(this),s[0]=i[0]^i[5]>>>16^i[3]<<16,s[1]=i[2]^i[7]>>>16^i[5]<<16,s[2]=i[4]^i[1]>>>16^i[7]<<16,s[3]=i[6]^i[3]>>>16^i[1]<<16;for(var n=0;n<4;n++)s[n]=16711935&(s[n]<<8|s[n]>>>24)|4278255360&(s[n]<<24|s[n]>>>8),e[t+n]^=s[n]},blockSize:4,ivSize:2});function c(){for(var e=this._X,t=this._C,i=0;i<8;i++)r[i]=t[i];for(t[0]=t[0]+1295307597+this._b|0,t[1]=t[1]+3545052371+(t[0]>>>0<r[0]>>>0?1:0)|0,t[2]=t[2]+886263092+(t[1]>>>0<r[1]>>>0?1:0)|0,t[3]=t[3]+1295307597+(t[2]>>>0<r[2]>>>0?1:0)|0,t[4]=t[4]+3545052371+(t[3]>>>0<r[3]>>>0?1:0)|0,t[5]=t[5]+886263092+(t[4]>>>0<r[4]>>>0?1:0)|0,t[6]=t[6]+1295307597+(t[5]>>>0<r[5]>>>0?1:0)|0,t[7]=t[7]+3545052371+(t[6]>>>0<r[6]>>>0?1:0)|0,this._b=t[7]>>>0<r[7]>>>0?1:0,i=0;i<8;i++){var n=e[i]+t[i],s=65535&n,o=n>>>16,c=((s*s>>>17)+s*o>>>15)+o*o,l=((4294901760&n)*n|0)+((65535&n)*n|0);a[i]=c^l}e[0]=a[0]+(a[7]<<16|a[7]>>>16)+(a[6]<<16|a[6]>>>16)|0,e[1]=a[1]+(a[0]<<8|a[0]>>>24)+a[7]|0,e[2]=a[2]+(a[1]<<16|a[1]>>>16)+(a[0]<<16|a[0]>>>16)|0,e[3]=a[3]+(a[2]<<8|a[2]>>>24)+a[1]|0,e[4]=a[4]+(a[3]<<16|a[3]>>>16)+(a[2]<<16|a[2]>>>16)|0,e[5]=a[5]+(a[4]<<8|a[4]>>>24)+a[3]|0,e[6]=a[6]+(a[5]<<16|a[5]>>>16)+(a[4]<<16|a[4]>>>16)|0,e[7]=a[7]+(a[6]<<8|a[6]>>>24)+a[5]|0}e.RabbitLegacy=t._createHelper(o)}(),n.RabbitLegacy)},function(e,t,i){var n;e.exports=(n=i(0),i(7),i(8),i(6),i(2),function(){var e=n,t=e.lib.BlockCipher,i=e.algo;const s=16,r=[608135816,2242054355,320440878,57701188,2752067618,698298832,137296536,3964562569,1160258022,953160567,3193202383,887688300,3232508343,3380367581,1065670069,3041331479,2450970073,2306472731],a=[[3509652390,2564797868,805139163,3491422135,3101798381,1780907670,3128725573,4046225305,614570311,3012652279,134345442,2240740374,1667834072,1901547113,2757295779,4103290238,227898511,1921955416,1904987480,2182433518,2069144605,3260701109,2620446009,720527379,3318853667,677414384,3393288472,3101374703,2390351024,1614419982,1822297739,2954791486,3608508353,3174124327,2024746970,1432378464,3864339955,2857741204,1464375394,1676153920,1439316330,715854006,3033291828,289532110,2706671279,2087905683,3018724369,1668267050,732546397,1947742710,3462151702,2609353502,2950085171,1814351708,2050118529,680887927,999245976,1800124847,3300911131,1713906067,1641548236,4213287313,1216130144,1575780402,4018429277,3917837745,3693486850,3949271944,596196993,3549867205,258830323,2213823033,772490370,2760122372,1774776394,2652871518,566650946,4142492826,1728879713,2882767088,1783734482,3629395816,2517608232,2874225571,1861159788,326777828,3124490320,2130389656,2716951837,967770486,1724537150,2185432712,2364442137,1164943284,2105845187,998989502,3765401048,2244026483,1075463327,1455516326,1322494562,910128902,469688178,1117454909,936433444,3490320968,3675253459,1240580251,122909385,2157517691,634681816,4142456567,3825094682,3061402683,2540495037,79693498,3249098678,1084186820,1583128258,426386531,1761308591,1047286709,322548459,995290223,1845252383,2603652396,3431023940,2942221577,3202600964,3727903485,1712269319,422464435,3234572375,1170764815,3523960633,3117677531,1434042557,442511882,3600875718,1076654713,1738483198,4213154764,2393238008,3677496056,1014306527,4251020053,793779912,2902807211,842905082,4246964064,1395751752,1040244610,2656851899,3396308128,445077038,3742853595,3577915638,679411651,2892444358,2354009459,1767581616,3150600392,3791627101,3102740896,284835224,4246832056,1258075500,768725851,2589189241,3069724005,3532540348,1274779536,3789419226,2764799539,1660621633,3471099624,4011903706,913787905,3497959166,737222580,2514213453,2928710040,3937242737,1804850592,3499020752,2949064160,2386320175,2390070455,2415321851,4061277028,2290661394,2416832540,1336762016,1754252060,3520065937,3014181293,791618072,3188594551,3933548030,2332172193,3852520463,3043980520,413987798,3465142937,3030929376,4245938359,2093235073,3534596313,375366246,2157278981,2479649556,555357303,3870105701,2008414854,3344188149,4221384143,3956125452,2067696032,3594591187,2921233993,2428461,544322398,577241275,1471733935,610547355,4027169054,1432588573,1507829418,2025931657,3646575487,545086370,48609733,2200306550,1653985193,298326376,1316178497,3007786442,2064951626,458293330,2589141269,3591329599,3164325604,727753846,2179363840,146436021,1461446943,4069977195,705550613,3059967265,3887724982,4281599278,3313849956,1404054877,2845806497,146425753,1854211946],[1266315497,3048417604,3681880366,3289982499,290971e4,1235738493,2632868024,2414719590,3970600049,1771706367,1449415276,3266420449,422970021,1963543593,2690192192,3826793022,1062508698,1531092325,1804592342,2583117782,2714934279,4024971509,1294809318,4028980673,1289560198,2221992742,1669523910,35572830,157838143,1052438473,1016535060,1802137761,1753167236,1386275462,3080475397,2857371447,1040679964,2145300060,2390574316,1461121720,2956646967,4031777805,4028374788,33600511,2920084762,1018524850,629373528,3691585981,3515945977,2091462646,2486323059,586499841,988145025,935516892,3367335476,2599673255,2839830854,265290510,3972581182,2759138881,3795373465,1005194799,847297441,406762289,1314163512,1332590856,1866599683,4127851711,750260880,613907577,1450815602,3165620655,3734664991,3650291728,3012275730,3704569646,1427272223,778793252,1343938022,2676280711,2052605720,1946737175,3164576444,3914038668,3967478842,3682934266,1661551462,3294938066,4011595847,840292616,3712170807,616741398,312560963,711312465,1351876610,322626781,1910503582,271666773,2175563734,1594956187,70604529,3617834859,1007753275,1495573769,4069517037,2549218298,2663038764,504708206,2263041392,3941167025,2249088522,1514023603,1998579484,1312622330,694541497,2582060303,2151582166,1382467621,776784248,2618340202,3323268794,2497899128,2784771155,503983604,4076293799,907881277,423175695,432175456,1378068232,4145222326,3954048622,3938656102,3820766613,2793130115,2977904593,26017576,3274890735,3194772133,1700274565,1756076034,4006520079,3677328699,720338349,1533947780,354530856,688349552,3973924725,1637815568,332179504,3949051286,53804574,2852348879,3044236432,1282449977,3583942155,3416972820,4006381244,1617046695,2628476075,3002303598,1686838959,431878346,2686675385,1700445008,1080580658,1009431731,832498133,3223435511,2605976345,2271191193,2516031870,1648197032,4164389018,2548247927,300782431,375919233,238389289,3353747414,2531188641,2019080857,1475708069,455242339,2609103871,448939670,3451063019,1395535956,2413381860,1841049896,1491858159,885456874,4264095073,4001119347,1565136089,3898914787,1108368660,540939232,1173283510,2745871338,3681308437,4207628240,3343053890,4016749493,1699691293,1103962373,3625875870,2256883143,3830138730,1031889488,3479347698,1535977030,4236805024,3251091107,2132092099,1774941330,1199868427,1452454533,157007616,2904115357,342012276,595725824,1480756522,206960106,497939518,591360097,863170706,2375253569,3596610801,1814182875,2094937945,3421402208,1082520231,3463918190,2785509508,435703966,3908032597,1641649973,2842273706,3305899714,1510255612,2148256476,2655287854,3276092548,4258621189,236887753,3681803219,274041037,1734335097,3815195456,3317970021,1899903192,1026095262,4050517792,356393447,2410691914,3873677099,3682840055],[3913112168,2491498743,4132185628,2489919796,1091903735,1979897079,3170134830,3567386728,3557303409,857797738,1136121015,1342202287,507115054,2535736646,337727348,3213592640,1301675037,2528481711,1895095763,1721773893,3216771564,62756741,2142006736,835421444,2531993523,1442658625,3659876326,2882144922,676362277,1392781812,170690266,3921047035,1759253602,3611846912,1745797284,664899054,1329594018,3901205900,3045908486,2062866102,2865634940,3543621612,3464012697,1080764994,553557557,3656615353,3996768171,991055499,499776247,1265440854,648242737,3940784050,980351604,3713745714,1749149687,3396870395,4211799374,3640570775,1161844396,3125318951,1431517754,545492359,4268468663,3499529547,1437099964,2702547544,3433638243,2581715763,2787789398,1060185593,1593081372,2418618748,4260947970,69676912,2159744348,86519011,2512459080,3838209314,1220612927,3339683548,133810670,1090789135,1078426020,1569222167,845107691,3583754449,4072456591,1091646820,628848692,1613405280,3757631651,526609435,236106946,48312990,2942717905,3402727701,1797494240,859738849,992217954,4005476642,2243076622,3870952857,3732016268,765654824,3490871365,2511836413,1685915746,3888969200,1414112111,2273134842,3281911079,4080962846,172450625,2569994100,980381355,4109958455,2819808352,2716589560,2568741196,3681446669,3329971472,1835478071,660984891,3704678404,4045999559,3422617507,3040415634,1762651403,1719377915,3470491036,2693910283,3642056355,3138596744,1364962596,2073328063,1983633131,926494387,3423689081,2150032023,4096667949,1749200295,3328846651,309677260,2016342300,1779581495,3079819751,111262694,1274766160,443224088,298511866,1025883608,3806446537,1145181785,168956806,3641502830,3584813610,1689216846,3666258015,3200248200,1692713982,2646376535,4042768518,1618508792,1610833997,3523052358,4130873264,2001055236,3610705100,2202168115,4028541809,2961195399,1006657119,2006996926,3186142756,1430667929,3210227297,1314452623,4074634658,4101304120,2273951170,1399257539,3367210612,3027628629,1190975929,2062231137,2333990788,2221543033,2438960610,1181637006,548689776,2362791313,3372408396,3104550113,3145860560,296247880,1970579870,3078560182,3769228297,1714227617,3291629107,3898220290,166772364,1251581989,493813264,448347421,195405023,2709975567,677966185,3703036547,1463355134,2715995803,1338867538,1343315457,2802222074,2684532164,233230375,2599980071,2000651841,3277868038,1638401717,4028070440,3237316320,6314154,819756386,300326615,590932579,1405279636,3267499572,3150704214,2428286686,3959192993,3461946742,1862657033,1266418056,963775037,2089974820,2263052895,1917689273,448879540,3550394620,3981727096,150775221,3627908307,1303187396,508620638,2975983352,2726630617,1817252668,1876281319,1457606340,908771278,3720792119,3617206836,2455994898,1729034894,1080033504],[976866871,3556439503,2881648439,1522871579,1555064734,1336096578,3548522304,2579274686,3574697629,3205460757,3593280638,3338716283,3079412587,564236357,2993598910,1781952180,1464380207,3163844217,3332601554,1699332808,1393555694,1183702653,3581086237,1288719814,691649499,2847557200,2895455976,3193889540,2717570544,1781354906,1676643554,2592534050,3230253752,1126444790,2770207658,2633158820,2210423226,2615765581,2414155088,3127139286,673620729,2805611233,1269405062,4015350505,3341807571,4149409754,1057255273,2012875353,2162469141,2276492801,2601117357,993977747,3918593370,2654263191,753973209,36408145,2530585658,25011837,3520020182,2088578344,530523599,2918365339,1524020338,1518925132,3760827505,3759777254,1202760957,3985898139,3906192525,674977740,4174734889,2031300136,2019492241,3983892565,4153806404,3822280332,352677332,2297720250,60907813,90501309,3286998549,1016092578,2535922412,2839152426,457141659,509813237,4120667899,652014361,1966332200,2975202805,55981186,2327461051,676427537,3255491064,2882294119,3433927263,1307055953,942726286,933058658,2468411793,3933900994,4215176142,1361170020,2001714738,2830558078,3274259782,1222529897,1679025792,2729314320,3714953764,1770335741,151462246,3013232138,1682292957,1483529935,471910574,1539241949,458788160,3436315007,1807016891,3718408830,978976581,1043663428,3165965781,1927990952,4200891579,2372276910,3208408903,3533431907,1412390302,2931980059,4132332400,1947078029,3881505623,4168226417,2941484381,1077988104,1320477388,886195818,18198404,3786409e3,2509781533,112762804,3463356488,1866414978,891333506,18488651,661792760,1628790961,3885187036,3141171499,876946877,2693282273,1372485963,791857591,2686433993,3759982718,3167212022,3472953795,2716379847,445679433,3561995674,3504004811,3574258232,54117162,3331405415,2381918588,3769707343,4154350007,1140177722,4074052095,668550556,3214352940,367459370,261225585,2610173221,4209349473,3468074219,3265815641,314222801,3066103646,3808782860,282218597,3406013506,3773591054,379116347,1285071038,846784868,2669647154,3771962079,3550491691,2305946142,453669953,1268987020,3317592352,3279303384,3744833421,2610507566,3859509063,266596637,3847019092,517658769,3462560207,3443424879,370717030,4247526661,2224018117,4143653529,4112773975,2788324899,2477274417,1456262402,2901442914,1517677493,1846949527,2295493580,3734397586,2176403920,1280348187,1908823572,3871786941,846861322,1172426758,3287448474,3383383037,1655181056,3139813346,901632758,1897031941,2986607138,3066810236,3447102507,1393639104,373351379,950779232,625454576,3124240540,4148612726,2007998917,544563296,2244738638,2330496472,2058025392,1291430526,424198748,50039436,29584100,3605783033,2429876329,2791104160,1057563949,3255363231,3075367218,3463963227,1469046755,985887462]];var o={pbox:[],sbox:[]};function c(e,t){let i=t>>24&255,n=t>>16&255,s=t>>8&255,r=255&t,a=e.sbox[0][i]+e.sbox[1][n];return a^=e.sbox[2][s],a+=e.sbox[3][r],a}function l(e,t,i){let n,r=t,a=i;for(let t=0;t<s;++t)r^=e.pbox[t],a=c(e,r)^a,n=r,r=a,a=n;return n=r,r=a,a=n,a^=e.pbox[s],r^=e.pbox[17],{left:r,right:a}}var u=i.Blowfish=t.extend({_doReset:function(){if(this._keyPriorReset!==this._key){var e=this._keyPriorReset=this._key,t=e.words,i=e.sigBytes/4;!function(e,t,i){for(let t=0;t<4;t++){e.sbox[t]=[];for(let i=0;i<256;i++)e.sbox[t][i]=a[t][i]}let n=0;for(let s=0;s<18;s++)e.pbox[s]=r[s]^t[n],n++,n>=i&&(n=0);let s=0,o=0,c=0;for(let t=0;t<18;t+=2)c=l(e,s,o),s=c.left,o=c.right,e.pbox[t]=s,e.pbox[t+1]=o;for(let t=0;t<4;t++)for(let i=0;i<256;i+=2)c=l(e,s,o),s=c.left,o=c.right,e.sbox[t][i]=s,e.sbox[t][i+1]=o}(o,t,i)}},encryptBlock:function(e,t){var i=l(o,e[t],e[t+1]);e[t]=i.left,e[t+1]=i.right},decryptBlock:function(e,t){var i=function(e,t,i){let n,s=t,r=i;for(let t=17;t>1;--t)s^=e.pbox[t],r=c(e,s)^r,n=s,s=r,r=n;return n=s,s=r,r=n,r^=e.pbox[1],s^=e.pbox[0],{left:s,right:r}}(o,e[t],e[t+1]);e[t]=i.left,e[t+1]=i.right},blockSize:2,keySize:4,ivSize:2});e.Blowfish=t._createHelper(u)}(),n.Blowfish)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=class{constructor(e){this.header="",this.len=0,this.flag=[0],this.cmd="",this.content=[],this.formatP0=e=>{let t=(e=>{let t=0;return 170===e[0]&&16===e[1]&&(t=2,2)})(e);if(!1===t)throw new Error("Header Error");const i=e.slice(t,e.length);this.len=i[0]},e&&e.length>0&&this.formatP0(e)}}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(14),r=i(1),a=i(3);class o extends r.default{}o.pack=(e,t,i)=>n(void 0,void 0,void 0,(function*(){const n=yield s.default.getConfigFile(e);if(n){const e="var_len"===n.protocolType,s=[0,0,0,3],r=[0];let o=[0];const c=[0,147];let l=[0,0,0,0],u=[2];if(t){o=[1];const e=a.fillString(t.length.toString(16),4),i=a.hexStrint2byte(e),n=a.string2Bytes(t);l=l.concat(i).concat(n)}if(e){u=[18];let e="";if(i){const t=i.reduce((e,t)=>Object.assign(Object.assign({},e),{[t]:1}),{});n.entities[0].attrs.map(i=>{e=t[i.name]?`1${e}`:`0${e}`})}else n.entities[0].attrs.map(()=>{e=`1${e}`});e=a.fillString(e,8*Math.ceil(e.length/8)),u=u.concat(a.hexStrint2byte(BigInt(`0b${e}`).toString(16)))}const d=o.concat(c).concat(l).concat(u);return r[0]=d.length,s.concat(r).concat(d)}return null})),t.default=o},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(1),s=i(3);class r extends n.default{constructor(e){super(e),this.moduleSoftVersion="",this.moduleHardVersion="",this.mcuSoftVersion="",this.mcuHardVersion="",this.businessVersion="";let t=0;this.moduleHardVersion=s.arrayToASCII(this.content.slice(t,t+8)),t+=8,this.moduleSoftVersion=s.arrayToASCII(this.content.slice(t,t+8)),t+=8,this.mcuHardVersion=s.arrayToASCII(this.content.slice(t,t+8)),t+=8,this.mcuSoftVersion=s.arrayToASCII(this.content.slice(t,t+8)),t+=8,this.businessVersion=s.arrayToASCII(this.content.slice(t,t+8)),t+=8}}r.pack=()=>[0,0,0,3,3,0,0,19],t.default=r},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(12);t.checkUpdate=function({did:e,type:t,hardVersion:i,softVersion:r}){return n(this,void 0,void 0,(function*(){const n="MCU"==t?"2":"1";return s.default(`/app/ota/v4.1/update_and_check/${e}`,{data:{type:n,hard_version:i,soft_version:r,https:"1"},method:"POST"},!0)}))}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(1);class s extends n.default{constructor(e){super(e),this.type="MCU",this.state=0,this.version=0;let t=0;this.type=1===this.content[t]?"MODULE":"MCU",t+=1,this.state=this.content[t],t+=1,this.version=this.content[t]}}s.pack=e=>[0,0,0,3,4,0,0,65,"MCU"===e?2:1],t.default=s},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(30),s=i(1),r=i(3);class a extends s.default{constructor(e){super(e),this.state=0,this.processedLen=0,this.processedCrc32="",this.packageMaxLen=20;let t=0;this.state=this.content[t],t+=1,this.processedLen=r.bytesToInt(this.content.slice(t,t+4)),t+=4,this.processedCrc32=r.bytesToHexString(this.content.slice(t,t+4)),t+=4,this.packageMaxLen=r.bytesToInt(this.content.slice(t,t+2))}}a.pack=(e,t,i,s,a)=>{const o=r.string2Bytes(e),c=e.length,l=r.string2Bytes(r.fillString(t,8)),u=r.hexStrint2byte(i),d=r.hexStrint2byte(r.fillString(a.toString(16),8)),h=r.hexStrint2byte(r.fillString(s.toString(16),8));let f=[0];f=f.concat([0,67],[c],o,l,u,h,d);const p=n.getVariableLength(f);return[0,0,0,3].concat(p,f)},t.default=a},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(1);class s extends n.default{constructor(e){super(e),this.state=0,this.state=this.content[0]}}s.pack=e=>[0,0,0,3],t.default=s},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(72),s=i(32);t.default=s.default("crc-16-modbus",n.default)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});let n=[0,49345,49537,320,49921,960,640,49729,50689,1728,1920,51009,1280,50625,50305,1088,52225,3264,3456,52545,3840,53185,52865,3648,2560,51905,52097,2880,51457,2496,2176,51265,55297,6336,6528,55617,6912,56257,55937,6720,7680,57025,57217,8e3,56577,7616,7296,56385,5120,54465,54657,5440,55041,6080,5760,54849,53761,4800,4992,54081,4352,53697,53377,4160,61441,12480,12672,61761,13056,62401,62081,12864,13824,63169,63361,14144,62721,13760,13440,62529,15360,64705,64897,15680,65281,16320,16e3,65089,64001,15040,15232,64321,14592,63937,63617,14400,10240,59585,59777,10560,60161,11200,10880,59969,60929,11968,12160,61249,11520,60865,60545,11328,58369,9408,9600,58689,9984,59329,59009,9792,8704,58049,58241,9024,57601,8640,8320,57409,40961,24768,24960,41281,25344,41921,41601,25152,26112,42689,42881,26432,42241,26048,25728,42049,27648,44225,44417,27968,44801,28608,28288,44609,43521,27328,27520,43841,26880,43457,43137,26688,30720,47297,47489,31040,47873,31680,31360,47681,48641,32448,32640,48961,32e3,48577,48257,31808,46081,29888,30080,46401,30464,47041,46721,30272,29184,45761,45953,29504,45313,29120,28800,45121,20480,37057,37249,20800,37633,21440,21120,37441,38401,22208,22400,38721,21760,38337,38017,21568,39937,23744,23936,40257,24320,40897,40577,24128,23040,39617,39809,23360,39169,22976,22656,38977,34817,18624,18816,35137,19200,35777,35457,19008,19968,36545,36737,20288,36097,19904,19584,35905,17408,33985,34177,17728,34561,18368,18048,34369,33281,17088,17280,33601,16640,33217,32897,16448];"undefined"!=typeof Int32Array&&(n=new Int32Array(n));t.default=(e,t)=>{let i=void 0!==t?~~t:65535;for(let t=0;t<e.length;t++)i=65535&(n[255&(i^e[t])]^i>>8);return i}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(74);t.default=(e,t)=>n.Buffer.from(e,t)},function(e,t,i){"use strict";(function(e){
|
|
18
|
+
n.mode.CTRGladman=function(){var e=n.lib.BlockCipherMode.extend();function t(e){if(255==(e>>24&255)){var t=e>>16&255,i=e>>8&255,n=255&e;255===t?(t=0,255===i?(i=0,255===n?n=0:++n):++i):++t,e=0,e+=t<<16,e+=i<<8,e+=n}else e+=1<<24;return e}var i=e.Encryptor=e.extend({processBlock:function(e,i){var n=this._cipher,s=n.blockSize,r=this._iv,a=this._counter;r&&(a=this._counter=r.slice(0),this._iv=void 0),function(e){0===(e[0]=t(e[0]))&&(e[1]=t(e[1]))}(a);var o=a.slice(0);n.encryptBlock(o,0);for(var c=0;c<s;c++)e[i+c]^=o[c]}});return e.Decryptor=i,e}(),n.mode.CTRGladman)},function(e,t,i){var n,s,r;e.exports=(r=i(0),i(2),r.mode.OFB=(n=r.lib.BlockCipherMode.extend(),s=n.Encryptor=n.extend({processBlock:function(e,t){var i=this._cipher,n=i.blockSize,s=this._iv,r=this._keystream;s&&(r=this._keystream=s.slice(0),this._iv=void 0),i.encryptBlock(r,0);for(var a=0;a<n;a++)e[t+a]^=r[a]}}),n.Decryptor=s,n),r.mode.OFB)},function(e,t,i){var n,s;e.exports=(s=i(0),i(2),s.mode.ECB=((n=s.lib.BlockCipherMode.extend()).Encryptor=n.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),n.Decryptor=n.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),n),s.mode.ECB)},function(e,t,i){var n;e.exports=(n=i(0),i(2),n.pad.AnsiX923={pad:function(e,t){var i=e.sigBytes,n=4*t,s=n-i%n,r=i+s-1;e.clamp(),e.words[r>>>2]|=s<<24-r%4*8,e.sigBytes+=s},unpad:function(e){var t=255&e.words[e.sigBytes-1>>>2];e.sigBytes-=t}},n.pad.Ansix923)},function(e,t,i){var n;e.exports=(n=i(0),i(2),n.pad.Iso10126={pad:function(e,t){var i=4*t,s=i-e.sigBytes%i;e.concat(n.lib.WordArray.random(s-1)).concat(n.lib.WordArray.create([s<<24],1))},unpad:function(e){var t=255&e.words[e.sigBytes-1>>>2];e.sigBytes-=t}},n.pad.Iso10126)},function(e,t,i){var n;e.exports=(n=i(0),i(2),n.pad.Iso97971={pad:function(e,t){e.concat(n.lib.WordArray.create([2147483648],1)),n.pad.ZeroPadding.pad(e,t)},unpad:function(e){n.pad.ZeroPadding.unpad(e),e.sigBytes--}},n.pad.Iso97971)},function(e,t,i){var n;e.exports=(n=i(0),i(2),n.pad.ZeroPadding={pad:function(e,t){var i=4*t;e.clamp(),e.sigBytes+=i-(e.sigBytes%i||i)},unpad:function(e){var t=e.words,i=e.sigBytes-1;for(i=e.sigBytes-1;i>=0;i--)if(t[i>>>2]>>>24-i%4*8&255){e.sigBytes=i+1;break}}},n.pad.ZeroPadding)},function(e,t,i){var n;e.exports=(n=i(0),i(2),n.pad.NoPadding={pad:function(){},unpad:function(){}},n.pad.NoPadding)},function(e,t,i){var n,s,r,a;e.exports=(a=i(0),i(2),s=(n=a).lib.CipherParams,r=n.enc.Hex,n.format.Hex={stringify:function(e){return e.ciphertext.toString(r)},parse:function(e){var t=r.parse(e);return s.create({ciphertext:t})}},a.format.Hex)},function(e,t,i){var n;e.exports=(n=i(0),i(7),i(8),i(6),i(2),function(){var e=n,t=e.lib.BlockCipher,i=e.algo,s=[],r=[],a=[],o=[],c=[],l=[],u=[],d=[],h=[],f=[];!function(){for(var e=[],t=0;t<256;t++)e[t]=t<128?t<<1:t<<1^283;var i=0,n=0;for(t=0;t<256;t++){var p=n^n<<1^n<<2^n<<3^n<<4;p=p>>>8^255&p^99,s[i]=p,r[p]=i;var v=e[i],g=e[v],y=e[g],D=257*e[p]^16843008*p;a[i]=D<<24|D>>>8,o[i]=D<<16|D>>>16,c[i]=D<<8|D>>>24,l[i]=D,D=16843009*y^65537*g^257*v^16843008*i,u[p]=D<<24|D>>>8,d[p]=D<<16|D>>>16,h[p]=D<<8|D>>>24,f[p]=D,i?(i=v^e[e[e[y^v]]],n^=e[e[n]]):i=n=1}}();var p=[0,1,2,4,8,16,32,64,128,27,54],v=i.AES=t.extend({_doReset:function(){if(!this._nRounds||this._keyPriorReset!==this._key){for(var e=this._keyPriorReset=this._key,t=e.words,i=e.sigBytes/4,n=4*((this._nRounds=i+6)+1),r=this._keySchedule=[],a=0;a<n;a++)a<i?r[a]=t[a]:(l=r[a-1],a%i?i>6&&a%i==4&&(l=s[l>>>24]<<24|s[l>>>16&255]<<16|s[l>>>8&255]<<8|s[255&l]):(l=s[(l=l<<8|l>>>24)>>>24]<<24|s[l>>>16&255]<<16|s[l>>>8&255]<<8|s[255&l],l^=p[a/i|0]<<24),r[a]=r[a-i]^l);for(var o=this._invKeySchedule=[],c=0;c<n;c++){if(a=n-c,c%4)var l=r[a];else l=r[a-4];o[c]=c<4||a<=4?l:u[s[l>>>24]]^d[s[l>>>16&255]]^h[s[l>>>8&255]]^f[s[255&l]]}}},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,a,o,c,l,s)},decryptBlock:function(e,t){var i=e[t+1];e[t+1]=e[t+3],e[t+3]=i,this._doCryptBlock(e,t,this._invKeySchedule,u,d,h,f,r),i=e[t+1],e[t+1]=e[t+3],e[t+3]=i},_doCryptBlock:function(e,t,i,n,s,r,a,o){for(var c=this._nRounds,l=e[t]^i[0],u=e[t+1]^i[1],d=e[t+2]^i[2],h=e[t+3]^i[3],f=4,p=1;p<c;p++){var v=n[l>>>24]^s[u>>>16&255]^r[d>>>8&255]^a[255&h]^i[f++],g=n[u>>>24]^s[d>>>16&255]^r[h>>>8&255]^a[255&l]^i[f++],y=n[d>>>24]^s[h>>>16&255]^r[l>>>8&255]^a[255&u]^i[f++],D=n[h>>>24]^s[l>>>16&255]^r[u>>>8&255]^a[255&d]^i[f++];l=v,u=g,d=y,h=D}v=(o[l>>>24]<<24|o[u>>>16&255]<<16|o[d>>>8&255]<<8|o[255&h])^i[f++],g=(o[u>>>24]<<24|o[d>>>16&255]<<16|o[h>>>8&255]<<8|o[255&l])^i[f++],y=(o[d>>>24]<<24|o[h>>>16&255]<<16|o[l>>>8&255]<<8|o[255&u])^i[f++],D=(o[h>>>24]<<24|o[l>>>16&255]<<16|o[u>>>8&255]<<8|o[255&d])^i[f++],e[t]=v,e[t+1]=g,e[t+2]=y,e[t+3]=D},keySize:8});e.AES=t._createHelper(v)}(),n.AES)},function(e,t,i){var n;e.exports=(n=i(0),i(7),i(8),i(6),i(2),function(){var e=n,t=e.lib,i=t.WordArray,s=t.BlockCipher,r=e.algo,a=[57,49,41,33,25,17,9,1,58,50,42,34,26,18,10,2,59,51,43,35,27,19,11,3,60,52,44,36,63,55,47,39,31,23,15,7,62,54,46,38,30,22,14,6,61,53,45,37,29,21,13,5,28,20,12,4],o=[14,17,11,24,1,5,3,28,15,6,21,10,23,19,12,4,26,8,16,7,27,20,13,2,41,52,31,37,47,55,30,40,51,45,33,48,44,49,39,56,34,53,46,42,50,36,29,32],c=[1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28],l=[{0:8421888,268435456:32768,536870912:8421378,805306368:2,1073741824:512,1342177280:8421890,1610612736:8389122,1879048192:8388608,2147483648:514,2415919104:8389120,2684354560:33280,2952790016:8421376,3221225472:32770,3489660928:8388610,3758096384:0,4026531840:33282,134217728:0,402653184:8421890,671088640:33282,939524096:32768,1207959552:8421888,1476395008:512,1744830464:8421378,2013265920:2,2281701376:8389120,2550136832:33280,2818572288:8421376,3087007744:8389122,3355443200:8388610,3623878656:32770,3892314112:514,4160749568:8388608,1:32768,268435457:2,536870913:8421888,805306369:8388608,1073741825:8421378,1342177281:33280,1610612737:512,1879048193:8389122,2147483649:8421890,2415919105:8421376,2684354561:8388610,2952790017:33282,3221225473:514,3489660929:8389120,3758096385:32770,4026531841:0,134217729:8421890,402653185:8421376,671088641:8388608,939524097:512,1207959553:32768,1476395009:8388610,1744830465:2,2013265921:33282,2281701377:32770,2550136833:8389122,2818572289:514,3087007745:8421888,3355443201:8389120,3623878657:0,3892314113:33280,4160749569:8421378},{0:1074282512,16777216:16384,33554432:524288,50331648:1074266128,67108864:1073741840,83886080:1074282496,100663296:1073758208,117440512:16,134217728:540672,150994944:1073758224,167772160:1073741824,184549376:540688,201326592:524304,218103808:0,234881024:16400,251658240:1074266112,8388608:1073758208,25165824:540688,41943040:16,58720256:1073758224,75497472:1074282512,92274688:1073741824,109051904:524288,125829120:1074266128,142606336:524304,159383552:0,176160768:16384,192937984:1074266112,209715200:1073741840,226492416:540672,243269632:1074282496,260046848:16400,268435456:0,285212672:1074266128,301989888:1073758224,318767104:1074282496,335544320:1074266112,352321536:16,369098752:540688,385875968:16384,402653184:16400,419430400:524288,436207616:524304,452984832:1073741840,469762048:540672,486539264:1073758208,503316480:1073741824,520093696:1074282512,276824064:540688,293601280:524288,310378496:1074266112,327155712:16384,343932928:1073758208,360710144:1074282512,377487360:16,394264576:1073741824,411041792:1074282496,427819008:1073741840,444596224:1073758224,461373440:524304,478150656:0,494927872:16400,511705088:1074266128,528482304:540672},{0:260,1048576:0,2097152:67109120,3145728:65796,4194304:65540,5242880:67108868,6291456:67174660,7340032:67174400,8388608:67108864,9437184:67174656,10485760:65792,11534336:67174404,12582912:67109124,13631488:65536,14680064:4,15728640:256,524288:67174656,1572864:67174404,2621440:0,3670016:67109120,4718592:67108868,5767168:65536,6815744:65540,7864320:260,8912896:4,9961472:256,11010048:67174400,12058624:65796,13107200:65792,14155776:67109124,15204352:67174660,16252928:67108864,16777216:67174656,17825792:65540,18874368:65536,19922944:67109120,20971520:256,22020096:67174660,23068672:67108868,24117248:0,25165824:67109124,26214400:67108864,27262976:4,28311552:65792,29360128:67174400,30408704:260,31457280:65796,32505856:67174404,17301504:67108864,18350080:260,19398656:67174656,20447232:0,21495808:65540,22544384:67109120,23592960:256,24641536:67174404,25690112:65536,26738688:67174660,27787264:65796,28835840:67108868,29884416:67109124,30932992:67174400,31981568:4,33030144:65792},{0:2151682048,65536:2147487808,131072:4198464,196608:2151677952,262144:0,327680:4198400,393216:2147483712,458752:4194368,524288:2147483648,589824:4194304,655360:64,720896:2147487744,786432:2151678016,851968:4160,917504:4096,983040:2151682112,32768:2147487808,98304:64,163840:2151678016,229376:2147487744,294912:4198400,360448:2151682112,425984:0,491520:2151677952,557056:4096,622592:2151682048,688128:4194304,753664:4160,819200:2147483648,884736:4194368,950272:4198464,1015808:2147483712,1048576:4194368,1114112:4198400,1179648:2147483712,1245184:0,1310720:4160,1376256:2151678016,1441792:2151682048,1507328:2147487808,1572864:2151682112,1638400:2147483648,1703936:2151677952,1769472:4198464,1835008:2147487744,1900544:4194304,1966080:64,2031616:4096,1081344:2151677952,1146880:2151682112,1212416:0,1277952:4198400,1343488:4194368,1409024:2147483648,1474560:2147487808,1540096:64,1605632:2147483712,1671168:4096,1736704:2147487744,1802240:2151678016,1867776:4160,1933312:2151682048,1998848:4194304,2064384:4198464},{0:128,4096:17039360,8192:262144,12288:536870912,16384:537133184,20480:16777344,24576:553648256,28672:262272,32768:16777216,36864:537133056,40960:536871040,45056:553910400,49152:553910272,53248:0,57344:17039488,61440:553648128,2048:17039488,6144:553648256,10240:128,14336:17039360,18432:262144,22528:537133184,26624:553910272,30720:536870912,34816:537133056,38912:0,43008:553910400,47104:16777344,51200:536871040,55296:553648128,59392:16777216,63488:262272,65536:262144,69632:128,73728:536870912,77824:553648256,81920:16777344,86016:553910272,90112:537133184,94208:16777216,98304:553910400,102400:553648128,106496:17039360,110592:537133056,114688:262272,118784:536871040,122880:0,126976:17039488,67584:553648256,71680:16777216,75776:17039360,79872:537133184,83968:536870912,88064:17039488,92160:128,96256:553910272,100352:262272,104448:553910400,108544:0,112640:553648128,116736:16777344,120832:262144,124928:537133056,129024:536871040},{0:268435464,256:8192,512:270532608,768:270540808,1024:268443648,1280:2097152,1536:2097160,1792:268435456,2048:0,2304:268443656,2560:2105344,2816:8,3072:270532616,3328:2105352,3584:8200,3840:270540800,128:270532608,384:270540808,640:8,896:2097152,1152:2105352,1408:268435464,1664:268443648,1920:8200,2176:2097160,2432:8192,2688:268443656,2944:270532616,3200:0,3456:270540800,3712:2105344,3968:268435456,4096:268443648,4352:270532616,4608:270540808,4864:8200,5120:2097152,5376:268435456,5632:268435464,5888:2105344,6144:2105352,6400:0,6656:8,6912:270532608,7168:8192,7424:268443656,7680:270540800,7936:2097160,4224:8,4480:2105344,4736:2097152,4992:268435464,5248:268443648,5504:8200,5760:270540808,6016:270532608,6272:270540800,6528:270532616,6784:8192,7040:2105352,7296:2097160,7552:0,7808:268435456,8064:268443656},{0:1048576,16:33555457,32:1024,48:1049601,64:34604033,80:0,96:1,112:34603009,128:33555456,144:1048577,160:33554433,176:34604032,192:34603008,208:1025,224:1049600,240:33554432,8:34603009,24:0,40:33555457,56:34604032,72:1048576,88:33554433,104:33554432,120:1025,136:1049601,152:33555456,168:34603008,184:1048577,200:1024,216:34604033,232:1,248:1049600,256:33554432,272:1048576,288:33555457,304:34603009,320:1048577,336:33555456,352:34604032,368:1049601,384:1025,400:34604033,416:1049600,432:1,448:0,464:34603008,480:33554433,496:1024,264:1049600,280:33555457,296:34603009,312:1,328:33554432,344:1048576,360:1025,376:34604032,392:33554433,408:34603008,424:0,440:34604033,456:1049601,472:1024,488:33555456,504:1048577},{0:134219808,1:131072,2:134217728,3:32,4:131104,5:134350880,6:134350848,7:2048,8:134348800,9:134219776,10:133120,11:134348832,12:2080,13:0,14:134217760,15:133152,2147483648:2048,2147483649:134350880,2147483650:134219808,2147483651:134217728,2147483652:134348800,2147483653:133120,2147483654:133152,2147483655:32,2147483656:134217760,2147483657:2080,2147483658:131104,2147483659:134350848,2147483660:0,2147483661:134348832,2147483662:134219776,2147483663:131072,16:133152,17:134350848,18:32,19:2048,20:134219776,21:134217760,22:134348832,23:131072,24:0,25:131104,26:134348800,27:134219808,28:134350880,29:133120,30:2080,31:134217728,2147483664:131072,2147483665:2048,2147483666:134348832,2147483667:133152,2147483668:32,2147483669:134348800,2147483670:134217728,2147483671:134219808,2147483672:134350880,2147483673:134217760,2147483674:134219776,2147483675:0,2147483676:133120,2147483677:2080,2147483678:131104,2147483679:134350848}],u=[4160749569,528482304,33030144,2064384,129024,8064,504,2147483679],d=r.DES=s.extend({_doReset:function(){for(var e=this._key.words,t=[],i=0;i<56;i++){var n=a[i]-1;t[i]=e[n>>>5]>>>31-n%32&1}for(var s=this._subKeys=[],r=0;r<16;r++){var l=s[r]=[],u=c[r];for(i=0;i<24;i++)l[i/6|0]|=t[(o[i]-1+u)%28]<<31-i%6,l[4+(i/6|0)]|=t[28+(o[i+24]-1+u)%28]<<31-i%6;for(l[0]=l[0]<<1|l[0]>>>31,i=1;i<7;i++)l[i]=l[i]>>>4*(i-1)+3;l[7]=l[7]<<5|l[7]>>>27}var d=this._invSubKeys=[];for(i=0;i<16;i++)d[i]=s[15-i]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._subKeys)},decryptBlock:function(e,t){this._doCryptBlock(e,t,this._invSubKeys)},_doCryptBlock:function(e,t,i){this._lBlock=e[t],this._rBlock=e[t+1],h.call(this,4,252645135),h.call(this,16,65535),f.call(this,2,858993459),f.call(this,8,16711935),h.call(this,1,1431655765);for(var n=0;n<16;n++){for(var s=i[n],r=this._lBlock,a=this._rBlock,o=0,c=0;c<8;c++)o|=l[c][((a^s[c])&u[c])>>>0];this._lBlock=a,this._rBlock=r^o}var d=this._lBlock;this._lBlock=this._rBlock,this._rBlock=d,h.call(this,1,1431655765),f.call(this,8,16711935),f.call(this,2,858993459),h.call(this,16,65535),h.call(this,4,252645135),e[t]=this._lBlock,e[t+1]=this._rBlock},keySize:2,ivSize:2,blockSize:2});function h(e,t){var i=(this._lBlock>>>e^this._rBlock)&t;this._rBlock^=i,this._lBlock^=i<<e}function f(e,t){var i=(this._rBlock>>>e^this._lBlock)&t;this._lBlock^=i,this._rBlock^=i<<e}e.DES=s._createHelper(d);var p=r.TripleDES=s.extend({_doReset:function(){var e=this._key.words;if(2!==e.length&&4!==e.length&&e.length<6)throw new Error("Invalid key length - 3DES requires the key length to be 64, 128, 192 or >192.");var t=e.slice(0,2),n=e.length<4?e.slice(0,2):e.slice(2,4),s=e.length<6?e.slice(0,2):e.slice(4,6);this._des1=d.createEncryptor(i.create(t)),this._des2=d.createEncryptor(i.create(n)),this._des3=d.createEncryptor(i.create(s))},encryptBlock:function(e,t){this._des1.encryptBlock(e,t),this._des2.decryptBlock(e,t),this._des3.encryptBlock(e,t)},decryptBlock:function(e,t){this._des3.decryptBlock(e,t),this._des2.encryptBlock(e,t),this._des1.decryptBlock(e,t)},keySize:6,ivSize:2,blockSize:2});e.TripleDES=s._createHelper(p)}(),n.TripleDES)},function(e,t,i){var n;e.exports=(n=i(0),i(7),i(8),i(6),i(2),function(){var e=n,t=e.lib.StreamCipher,i=e.algo,s=i.RC4=t.extend({_doReset:function(){for(var e=this._key,t=e.words,i=e.sigBytes,n=this._S=[],s=0;s<256;s++)n[s]=s;s=0;for(var r=0;s<256;s++){var a=s%i,o=t[a>>>2]>>>24-a%4*8&255;r=(r+n[s]+o)%256;var c=n[s];n[s]=n[r],n[r]=c}this._i=this._j=0},_doProcessBlock:function(e,t){e[t]^=r.call(this)},keySize:8,ivSize:0});function r(){for(var e=this._S,t=this._i,i=this._j,n=0,s=0;s<4;s++){i=(i+e[t=(t+1)%256])%256;var r=e[t];e[t]=e[i],e[i]=r,n|=e[(e[t]+e[i])%256]<<24-8*s}return this._i=t,this._j=i,n}e.RC4=t._createHelper(s);var a=i.RC4Drop=s.extend({cfg:s.cfg.extend({drop:192}),_doReset:function(){s._doReset.call(this);for(var e=this.cfg.drop;e>0;e--)r.call(this)}});e.RC4Drop=t._createHelper(a)}(),n.RC4)},function(e,t,i){var n;e.exports=(n=i(0),i(7),i(8),i(6),i(2),function(){var e=n,t=e.lib.StreamCipher,i=e.algo,s=[],r=[],a=[],o=i.Rabbit=t.extend({_doReset:function(){for(var e=this._key.words,t=this.cfg.iv,i=0;i<4;i++)e[i]=16711935&(e[i]<<8|e[i]>>>24)|4278255360&(e[i]<<24|e[i]>>>8);var n=this._X=[e[0],e[3]<<16|e[2]>>>16,e[1],e[0]<<16|e[3]>>>16,e[2],e[1]<<16|e[0]>>>16,e[3],e[2]<<16|e[1]>>>16],s=this._C=[e[2]<<16|e[2]>>>16,4294901760&e[0]|65535&e[1],e[3]<<16|e[3]>>>16,4294901760&e[1]|65535&e[2],e[0]<<16|e[0]>>>16,4294901760&e[2]|65535&e[3],e[1]<<16|e[1]>>>16,4294901760&e[3]|65535&e[0]];for(this._b=0,i=0;i<4;i++)c.call(this);for(i=0;i<8;i++)s[i]^=n[i+4&7];if(t){var r=t.words,a=r[0],o=r[1],l=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),u=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8),d=l>>>16|4294901760&u,h=u<<16|65535&l;for(s[0]^=l,s[1]^=d,s[2]^=u,s[3]^=h,s[4]^=l,s[5]^=d,s[6]^=u,s[7]^=h,i=0;i<4;i++)c.call(this)}},_doProcessBlock:function(e,t){var i=this._X;c.call(this),s[0]=i[0]^i[5]>>>16^i[3]<<16,s[1]=i[2]^i[7]>>>16^i[5]<<16,s[2]=i[4]^i[1]>>>16^i[7]<<16,s[3]=i[6]^i[3]>>>16^i[1]<<16;for(var n=0;n<4;n++)s[n]=16711935&(s[n]<<8|s[n]>>>24)|4278255360&(s[n]<<24|s[n]>>>8),e[t+n]^=s[n]},blockSize:4,ivSize:2});function c(){for(var e=this._X,t=this._C,i=0;i<8;i++)r[i]=t[i];for(t[0]=t[0]+1295307597+this._b|0,t[1]=t[1]+3545052371+(t[0]>>>0<r[0]>>>0?1:0)|0,t[2]=t[2]+886263092+(t[1]>>>0<r[1]>>>0?1:0)|0,t[3]=t[3]+1295307597+(t[2]>>>0<r[2]>>>0?1:0)|0,t[4]=t[4]+3545052371+(t[3]>>>0<r[3]>>>0?1:0)|0,t[5]=t[5]+886263092+(t[4]>>>0<r[4]>>>0?1:0)|0,t[6]=t[6]+1295307597+(t[5]>>>0<r[5]>>>0?1:0)|0,t[7]=t[7]+3545052371+(t[6]>>>0<r[6]>>>0?1:0)|0,this._b=t[7]>>>0<r[7]>>>0?1:0,i=0;i<8;i++){var n=e[i]+t[i],s=65535&n,o=n>>>16,c=((s*s>>>17)+s*o>>>15)+o*o,l=((4294901760&n)*n|0)+((65535&n)*n|0);a[i]=c^l}e[0]=a[0]+(a[7]<<16|a[7]>>>16)+(a[6]<<16|a[6]>>>16)|0,e[1]=a[1]+(a[0]<<8|a[0]>>>24)+a[7]|0,e[2]=a[2]+(a[1]<<16|a[1]>>>16)+(a[0]<<16|a[0]>>>16)|0,e[3]=a[3]+(a[2]<<8|a[2]>>>24)+a[1]|0,e[4]=a[4]+(a[3]<<16|a[3]>>>16)+(a[2]<<16|a[2]>>>16)|0,e[5]=a[5]+(a[4]<<8|a[4]>>>24)+a[3]|0,e[6]=a[6]+(a[5]<<16|a[5]>>>16)+(a[4]<<16|a[4]>>>16)|0,e[7]=a[7]+(a[6]<<8|a[6]>>>24)+a[5]|0}e.Rabbit=t._createHelper(o)}(),n.Rabbit)},function(e,t,i){var n;e.exports=(n=i(0),i(7),i(8),i(6),i(2),function(){var e=n,t=e.lib.StreamCipher,i=e.algo,s=[],r=[],a=[],o=i.RabbitLegacy=t.extend({_doReset:function(){var e=this._key.words,t=this.cfg.iv,i=this._X=[e[0],e[3]<<16|e[2]>>>16,e[1],e[0]<<16|e[3]>>>16,e[2],e[1]<<16|e[0]>>>16,e[3],e[2]<<16|e[1]>>>16],n=this._C=[e[2]<<16|e[2]>>>16,4294901760&e[0]|65535&e[1],e[3]<<16|e[3]>>>16,4294901760&e[1]|65535&e[2],e[0]<<16|e[0]>>>16,4294901760&e[2]|65535&e[3],e[1]<<16|e[1]>>>16,4294901760&e[3]|65535&e[0]];this._b=0;for(var s=0;s<4;s++)c.call(this);for(s=0;s<8;s++)n[s]^=i[s+4&7];if(t){var r=t.words,a=r[0],o=r[1],l=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),u=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8),d=l>>>16|4294901760&u,h=u<<16|65535&l;for(n[0]^=l,n[1]^=d,n[2]^=u,n[3]^=h,n[4]^=l,n[5]^=d,n[6]^=u,n[7]^=h,s=0;s<4;s++)c.call(this)}},_doProcessBlock:function(e,t){var i=this._X;c.call(this),s[0]=i[0]^i[5]>>>16^i[3]<<16,s[1]=i[2]^i[7]>>>16^i[5]<<16,s[2]=i[4]^i[1]>>>16^i[7]<<16,s[3]=i[6]^i[3]>>>16^i[1]<<16;for(var n=0;n<4;n++)s[n]=16711935&(s[n]<<8|s[n]>>>24)|4278255360&(s[n]<<24|s[n]>>>8),e[t+n]^=s[n]},blockSize:4,ivSize:2});function c(){for(var e=this._X,t=this._C,i=0;i<8;i++)r[i]=t[i];for(t[0]=t[0]+1295307597+this._b|0,t[1]=t[1]+3545052371+(t[0]>>>0<r[0]>>>0?1:0)|0,t[2]=t[2]+886263092+(t[1]>>>0<r[1]>>>0?1:0)|0,t[3]=t[3]+1295307597+(t[2]>>>0<r[2]>>>0?1:0)|0,t[4]=t[4]+3545052371+(t[3]>>>0<r[3]>>>0?1:0)|0,t[5]=t[5]+886263092+(t[4]>>>0<r[4]>>>0?1:0)|0,t[6]=t[6]+1295307597+(t[5]>>>0<r[5]>>>0?1:0)|0,t[7]=t[7]+3545052371+(t[6]>>>0<r[6]>>>0?1:0)|0,this._b=t[7]>>>0<r[7]>>>0?1:0,i=0;i<8;i++){var n=e[i]+t[i],s=65535&n,o=n>>>16,c=((s*s>>>17)+s*o>>>15)+o*o,l=((4294901760&n)*n|0)+((65535&n)*n|0);a[i]=c^l}e[0]=a[0]+(a[7]<<16|a[7]>>>16)+(a[6]<<16|a[6]>>>16)|0,e[1]=a[1]+(a[0]<<8|a[0]>>>24)+a[7]|0,e[2]=a[2]+(a[1]<<16|a[1]>>>16)+(a[0]<<16|a[0]>>>16)|0,e[3]=a[3]+(a[2]<<8|a[2]>>>24)+a[1]|0,e[4]=a[4]+(a[3]<<16|a[3]>>>16)+(a[2]<<16|a[2]>>>16)|0,e[5]=a[5]+(a[4]<<8|a[4]>>>24)+a[3]|0,e[6]=a[6]+(a[5]<<16|a[5]>>>16)+(a[4]<<16|a[4]>>>16)|0,e[7]=a[7]+(a[6]<<8|a[6]>>>24)+a[5]|0}e.RabbitLegacy=t._createHelper(o)}(),n.RabbitLegacy)},function(e,t,i){var n;e.exports=(n=i(0),i(7),i(8),i(6),i(2),function(){var e=n,t=e.lib.BlockCipher,i=e.algo;const s=16,r=[608135816,2242054355,320440878,57701188,2752067618,698298832,137296536,3964562569,1160258022,953160567,3193202383,887688300,3232508343,3380367581,1065670069,3041331479,2450970073,2306472731],a=[[3509652390,2564797868,805139163,3491422135,3101798381,1780907670,3128725573,4046225305,614570311,3012652279,134345442,2240740374,1667834072,1901547113,2757295779,4103290238,227898511,1921955416,1904987480,2182433518,2069144605,3260701109,2620446009,720527379,3318853667,677414384,3393288472,3101374703,2390351024,1614419982,1822297739,2954791486,3608508353,3174124327,2024746970,1432378464,3864339955,2857741204,1464375394,1676153920,1439316330,715854006,3033291828,289532110,2706671279,2087905683,3018724369,1668267050,732546397,1947742710,3462151702,2609353502,2950085171,1814351708,2050118529,680887927,999245976,1800124847,3300911131,1713906067,1641548236,4213287313,1216130144,1575780402,4018429277,3917837745,3693486850,3949271944,596196993,3549867205,258830323,2213823033,772490370,2760122372,1774776394,2652871518,566650946,4142492826,1728879713,2882767088,1783734482,3629395816,2517608232,2874225571,1861159788,326777828,3124490320,2130389656,2716951837,967770486,1724537150,2185432712,2364442137,1164943284,2105845187,998989502,3765401048,2244026483,1075463327,1455516326,1322494562,910128902,469688178,1117454909,936433444,3490320968,3675253459,1240580251,122909385,2157517691,634681816,4142456567,3825094682,3061402683,2540495037,79693498,3249098678,1084186820,1583128258,426386531,1761308591,1047286709,322548459,995290223,1845252383,2603652396,3431023940,2942221577,3202600964,3727903485,1712269319,422464435,3234572375,1170764815,3523960633,3117677531,1434042557,442511882,3600875718,1076654713,1738483198,4213154764,2393238008,3677496056,1014306527,4251020053,793779912,2902807211,842905082,4246964064,1395751752,1040244610,2656851899,3396308128,445077038,3742853595,3577915638,679411651,2892444358,2354009459,1767581616,3150600392,3791627101,3102740896,284835224,4246832056,1258075500,768725851,2589189241,3069724005,3532540348,1274779536,3789419226,2764799539,1660621633,3471099624,4011903706,913787905,3497959166,737222580,2514213453,2928710040,3937242737,1804850592,3499020752,2949064160,2386320175,2390070455,2415321851,4061277028,2290661394,2416832540,1336762016,1754252060,3520065937,3014181293,791618072,3188594551,3933548030,2332172193,3852520463,3043980520,413987798,3465142937,3030929376,4245938359,2093235073,3534596313,375366246,2157278981,2479649556,555357303,3870105701,2008414854,3344188149,4221384143,3956125452,2067696032,3594591187,2921233993,2428461,544322398,577241275,1471733935,610547355,4027169054,1432588573,1507829418,2025931657,3646575487,545086370,48609733,2200306550,1653985193,298326376,1316178497,3007786442,2064951626,458293330,2589141269,3591329599,3164325604,727753846,2179363840,146436021,1461446943,4069977195,705550613,3059967265,3887724982,4281599278,3313849956,1404054877,2845806497,146425753,1854211946],[1266315497,3048417604,3681880366,3289982499,290971e4,1235738493,2632868024,2414719590,3970600049,1771706367,1449415276,3266420449,422970021,1963543593,2690192192,3826793022,1062508698,1531092325,1804592342,2583117782,2714934279,4024971509,1294809318,4028980673,1289560198,2221992742,1669523910,35572830,157838143,1052438473,1016535060,1802137761,1753167236,1386275462,3080475397,2857371447,1040679964,2145300060,2390574316,1461121720,2956646967,4031777805,4028374788,33600511,2920084762,1018524850,629373528,3691585981,3515945977,2091462646,2486323059,586499841,988145025,935516892,3367335476,2599673255,2839830854,265290510,3972581182,2759138881,3795373465,1005194799,847297441,406762289,1314163512,1332590856,1866599683,4127851711,750260880,613907577,1450815602,3165620655,3734664991,3650291728,3012275730,3704569646,1427272223,778793252,1343938022,2676280711,2052605720,1946737175,3164576444,3914038668,3967478842,3682934266,1661551462,3294938066,4011595847,840292616,3712170807,616741398,312560963,711312465,1351876610,322626781,1910503582,271666773,2175563734,1594956187,70604529,3617834859,1007753275,1495573769,4069517037,2549218298,2663038764,504708206,2263041392,3941167025,2249088522,1514023603,1998579484,1312622330,694541497,2582060303,2151582166,1382467621,776784248,2618340202,3323268794,2497899128,2784771155,503983604,4076293799,907881277,423175695,432175456,1378068232,4145222326,3954048622,3938656102,3820766613,2793130115,2977904593,26017576,3274890735,3194772133,1700274565,1756076034,4006520079,3677328699,720338349,1533947780,354530856,688349552,3973924725,1637815568,332179504,3949051286,53804574,2852348879,3044236432,1282449977,3583942155,3416972820,4006381244,1617046695,2628476075,3002303598,1686838959,431878346,2686675385,1700445008,1080580658,1009431731,832498133,3223435511,2605976345,2271191193,2516031870,1648197032,4164389018,2548247927,300782431,375919233,238389289,3353747414,2531188641,2019080857,1475708069,455242339,2609103871,448939670,3451063019,1395535956,2413381860,1841049896,1491858159,885456874,4264095073,4001119347,1565136089,3898914787,1108368660,540939232,1173283510,2745871338,3681308437,4207628240,3343053890,4016749493,1699691293,1103962373,3625875870,2256883143,3830138730,1031889488,3479347698,1535977030,4236805024,3251091107,2132092099,1774941330,1199868427,1452454533,157007616,2904115357,342012276,595725824,1480756522,206960106,497939518,591360097,863170706,2375253569,3596610801,1814182875,2094937945,3421402208,1082520231,3463918190,2785509508,435703966,3908032597,1641649973,2842273706,3305899714,1510255612,2148256476,2655287854,3276092548,4258621189,236887753,3681803219,274041037,1734335097,3815195456,3317970021,1899903192,1026095262,4050517792,356393447,2410691914,3873677099,3682840055],[3913112168,2491498743,4132185628,2489919796,1091903735,1979897079,3170134830,3567386728,3557303409,857797738,1136121015,1342202287,507115054,2535736646,337727348,3213592640,1301675037,2528481711,1895095763,1721773893,3216771564,62756741,2142006736,835421444,2531993523,1442658625,3659876326,2882144922,676362277,1392781812,170690266,3921047035,1759253602,3611846912,1745797284,664899054,1329594018,3901205900,3045908486,2062866102,2865634940,3543621612,3464012697,1080764994,553557557,3656615353,3996768171,991055499,499776247,1265440854,648242737,3940784050,980351604,3713745714,1749149687,3396870395,4211799374,3640570775,1161844396,3125318951,1431517754,545492359,4268468663,3499529547,1437099964,2702547544,3433638243,2581715763,2787789398,1060185593,1593081372,2418618748,4260947970,69676912,2159744348,86519011,2512459080,3838209314,1220612927,3339683548,133810670,1090789135,1078426020,1569222167,845107691,3583754449,4072456591,1091646820,628848692,1613405280,3757631651,526609435,236106946,48312990,2942717905,3402727701,1797494240,859738849,992217954,4005476642,2243076622,3870952857,3732016268,765654824,3490871365,2511836413,1685915746,3888969200,1414112111,2273134842,3281911079,4080962846,172450625,2569994100,980381355,4109958455,2819808352,2716589560,2568741196,3681446669,3329971472,1835478071,660984891,3704678404,4045999559,3422617507,3040415634,1762651403,1719377915,3470491036,2693910283,3642056355,3138596744,1364962596,2073328063,1983633131,926494387,3423689081,2150032023,4096667949,1749200295,3328846651,309677260,2016342300,1779581495,3079819751,111262694,1274766160,443224088,298511866,1025883608,3806446537,1145181785,168956806,3641502830,3584813610,1689216846,3666258015,3200248200,1692713982,2646376535,4042768518,1618508792,1610833997,3523052358,4130873264,2001055236,3610705100,2202168115,4028541809,2961195399,1006657119,2006996926,3186142756,1430667929,3210227297,1314452623,4074634658,4101304120,2273951170,1399257539,3367210612,3027628629,1190975929,2062231137,2333990788,2221543033,2438960610,1181637006,548689776,2362791313,3372408396,3104550113,3145860560,296247880,1970579870,3078560182,3769228297,1714227617,3291629107,3898220290,166772364,1251581989,493813264,448347421,195405023,2709975567,677966185,3703036547,1463355134,2715995803,1338867538,1343315457,2802222074,2684532164,233230375,2599980071,2000651841,3277868038,1638401717,4028070440,3237316320,6314154,819756386,300326615,590932579,1405279636,3267499572,3150704214,2428286686,3959192993,3461946742,1862657033,1266418056,963775037,2089974820,2263052895,1917689273,448879540,3550394620,3981727096,150775221,3627908307,1303187396,508620638,2975983352,2726630617,1817252668,1876281319,1457606340,908771278,3720792119,3617206836,2455994898,1729034894,1080033504],[976866871,3556439503,2881648439,1522871579,1555064734,1336096578,3548522304,2579274686,3574697629,3205460757,3593280638,3338716283,3079412587,564236357,2993598910,1781952180,1464380207,3163844217,3332601554,1699332808,1393555694,1183702653,3581086237,1288719814,691649499,2847557200,2895455976,3193889540,2717570544,1781354906,1676643554,2592534050,3230253752,1126444790,2770207658,2633158820,2210423226,2615765581,2414155088,3127139286,673620729,2805611233,1269405062,4015350505,3341807571,4149409754,1057255273,2012875353,2162469141,2276492801,2601117357,993977747,3918593370,2654263191,753973209,36408145,2530585658,25011837,3520020182,2088578344,530523599,2918365339,1524020338,1518925132,3760827505,3759777254,1202760957,3985898139,3906192525,674977740,4174734889,2031300136,2019492241,3983892565,4153806404,3822280332,352677332,2297720250,60907813,90501309,3286998549,1016092578,2535922412,2839152426,457141659,509813237,4120667899,652014361,1966332200,2975202805,55981186,2327461051,676427537,3255491064,2882294119,3433927263,1307055953,942726286,933058658,2468411793,3933900994,4215176142,1361170020,2001714738,2830558078,3274259782,1222529897,1679025792,2729314320,3714953764,1770335741,151462246,3013232138,1682292957,1483529935,471910574,1539241949,458788160,3436315007,1807016891,3718408830,978976581,1043663428,3165965781,1927990952,4200891579,2372276910,3208408903,3533431907,1412390302,2931980059,4132332400,1947078029,3881505623,4168226417,2941484381,1077988104,1320477388,886195818,18198404,3786409e3,2509781533,112762804,3463356488,1866414978,891333506,18488651,661792760,1628790961,3885187036,3141171499,876946877,2693282273,1372485963,791857591,2686433993,3759982718,3167212022,3472953795,2716379847,445679433,3561995674,3504004811,3574258232,54117162,3331405415,2381918588,3769707343,4154350007,1140177722,4074052095,668550556,3214352940,367459370,261225585,2610173221,4209349473,3468074219,3265815641,314222801,3066103646,3808782860,282218597,3406013506,3773591054,379116347,1285071038,846784868,2669647154,3771962079,3550491691,2305946142,453669953,1268987020,3317592352,3279303384,3744833421,2610507566,3859509063,266596637,3847019092,517658769,3462560207,3443424879,370717030,4247526661,2224018117,4143653529,4112773975,2788324899,2477274417,1456262402,2901442914,1517677493,1846949527,2295493580,3734397586,2176403920,1280348187,1908823572,3871786941,846861322,1172426758,3287448474,3383383037,1655181056,3139813346,901632758,1897031941,2986607138,3066810236,3447102507,1393639104,373351379,950779232,625454576,3124240540,4148612726,2007998917,544563296,2244738638,2330496472,2058025392,1291430526,424198748,50039436,29584100,3605783033,2429876329,2791104160,1057563949,3255363231,3075367218,3463963227,1469046755,985887462]];var o={pbox:[],sbox:[]};function c(e,t){let i=t>>24&255,n=t>>16&255,s=t>>8&255,r=255&t,a=e.sbox[0][i]+e.sbox[1][n];return a^=e.sbox[2][s],a+=e.sbox[3][r],a}function l(e,t,i){let n,r=t,a=i;for(let t=0;t<s;++t)r^=e.pbox[t],a=c(e,r)^a,n=r,r=a,a=n;return n=r,r=a,a=n,a^=e.pbox[s],r^=e.pbox[17],{left:r,right:a}}var u=i.Blowfish=t.extend({_doReset:function(){if(this._keyPriorReset!==this._key){var e=this._keyPriorReset=this._key,t=e.words,i=e.sigBytes/4;!function(e,t,i){for(let t=0;t<4;t++){e.sbox[t]=[];for(let i=0;i<256;i++)e.sbox[t][i]=a[t][i]}let n=0;for(let s=0;s<18;s++)e.pbox[s]=r[s]^t[n],n++,n>=i&&(n=0);let s=0,o=0,c=0;for(let t=0;t<18;t+=2)c=l(e,s,o),s=c.left,o=c.right,e.pbox[t]=s,e.pbox[t+1]=o;for(let t=0;t<4;t++)for(let i=0;i<256;i+=2)c=l(e,s,o),s=c.left,o=c.right,e.sbox[t][i]=s,e.sbox[t][i+1]=o}(o,t,i)}},encryptBlock:function(e,t){var i=l(o,e[t],e[t+1]);e[t]=i.left,e[t+1]=i.right},decryptBlock:function(e,t){var i=function(e,t,i){let n,s=t,r=i;for(let t=17;t>1;--t)s^=e.pbox[t],r=c(e,s)^r,n=s,s=r,r=n;return n=s,s=r,r=n,r^=e.pbox[1],s^=e.pbox[0],{left:s,right:r}}(o,e[t],e[t+1]);e[t]=i.left,e[t+1]=i.right},blockSize:2,keySize:4,ivSize:2});e.Blowfish=t._createHelper(u)}(),n.Blowfish)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=class{constructor(e){this.header="",this.len=0,this.flag=[0],this.cmd="",this.content=[],this.formatP0=e=>{let t=(e=>{let t=0;return 170===e[0]&&16===e[1]&&(t=2,2)})(e);if(!1===t)throw new Error("Header Error");const i=e.slice(t,e.length);this.len=i[0]},e&&e.length>0&&this.formatP0(e)}}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(14),r=i(1),a=i(3);class o extends r.default{}o.pack=(e,t,i)=>n(void 0,void 0,void 0,(function*(){const n=yield s.default.getConfigFile(e);if(n){const e="var_len"===n.protocolType,s=[0,0,0,3],r=[0];let o=[0];const c=[0,147];let l=[0,0,0,0],u=[2];if(t){o=[1];const e=a.fillString(t.length.toString(16),4),i=a.hexStrint2byte(e),n=a.string2Bytes(t);l=l.concat(i).concat(n)}if(e){u=[18];let e="";if(i){const t=i.reduce((e,t)=>Object.assign(Object.assign({},e),{[t]:1}),{});n.entities[0].attrs.map(i=>{e=t[i.name]?`1${e}`:`0${e}`})}else n.entities[0].attrs.map(()=>{e=`1${e}`});e=a.fillString(e,8*Math.ceil(e.length/8)),u=u.concat(a.hexStrint2byte(BigInt(`0b${e}`).toString(16)))}const d=o.concat(c).concat(l).concat(u);return r[0]=d.length,s.concat(r).concat(d)}return null})),t.default=o},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(1),s=i(3);class r extends n.default{constructor(e){super(e),this.moduleSoftVersion="",this.moduleHardVersion="",this.mcuSoftVersion="",this.mcuHardVersion="",this.businessVersion="";let t=0;this.moduleHardVersion=s.arrayToASCII(this.content.slice(t,t+8)),t+=8,this.moduleSoftVersion=s.arrayToASCII(this.content.slice(t,t+8)),t+=8,this.mcuHardVersion=s.arrayToASCII(this.content.slice(t,t+8)),t+=8,this.mcuSoftVersion=s.arrayToASCII(this.content.slice(t,t+8)),t+=8,this.businessVersion=s.arrayToASCII(this.content.slice(t,t+8)),t+=8}}r.pack=()=>[0,0,0,3,3,0,0,19],t.default=r},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(12);t.checkUpdate=function({did:e,type:t,hardVersion:i,softVersion:r}){return n(this,void 0,void 0,(function*(){const n="MCU"==t?"2":"1";return s.default(`/app/ota/v4.1/update_and_check/${e}`,{data:{type:n,hard_version:i,soft_version:r,https:"1"},method:"POST"},!0)}))}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(1);class s extends n.default{constructor(e){super(e),this.type="MCU",this.state=0,this.version=0;let t=0;this.type=1===this.content[t]?"MODULE":"MCU",t+=1,this.state=this.content[t],t+=1,this.version=this.content[t]}}s.pack=e=>[0,0,0,3,4,0,0,65,"MCU"===e?2:1],t.default=s},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(30),s=i(1),r=i(3);class a extends s.default{constructor(e){super(e),this.state=0,this.processedLen=0,this.processedCrc32="",this.packageMaxLen=20;let t=0;this.state=this.content[t],t+=1,this.processedLen=r.bytesToInt(this.content.slice(t,t+4)),t+=4,this.processedCrc32=r.bytesToHexString(this.content.slice(t,t+4)),t+=4,this.packageMaxLen=r.bytesToInt(this.content.slice(t,t+2))}}a.pack=(e,t,i,s,a)=>{const o=r.string2Bytes(e),c=e.length,l=r.string2Bytes(r.fillString(t,8)),u=r.hexStrint2byte(i),d=r.hexStrint2byte(r.fillString(a.toString(16),8)),h=r.hexStrint2byte(r.fillString(s.toString(16),8));let f=[0];f=f.concat([0,67],[c],o,l,u,h,d);const p=n.getVariableLength(f);return[0,0,0,3].concat(p,f)},t.default=a},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(1);class s extends n.default{constructor(e){super(e),this.state=0,this.state=this.content[0]}}s.pack=e=>[0,0,0,3],t.default=s},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(72),s=i(32);t.default=s.default("crc-16-modbus",n.default)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});let n=[0,49345,49537,320,49921,960,640,49729,50689,1728,1920,51009,1280,50625,50305,1088,52225,3264,3456,52545,3840,53185,52865,3648,2560,51905,52097,2880,51457,2496,2176,51265,55297,6336,6528,55617,6912,56257,55937,6720,7680,57025,57217,8e3,56577,7616,7296,56385,5120,54465,54657,5440,55041,6080,5760,54849,53761,4800,4992,54081,4352,53697,53377,4160,61441,12480,12672,61761,13056,62401,62081,12864,13824,63169,63361,14144,62721,13760,13440,62529,15360,64705,64897,15680,65281,16320,16e3,65089,64001,15040,15232,64321,14592,63937,63617,14400,10240,59585,59777,10560,60161,11200,10880,59969,60929,11968,12160,61249,11520,60865,60545,11328,58369,9408,9600,58689,9984,59329,59009,9792,8704,58049,58241,9024,57601,8640,8320,57409,40961,24768,24960,41281,25344,41921,41601,25152,26112,42689,42881,26432,42241,26048,25728,42049,27648,44225,44417,27968,44801,28608,28288,44609,43521,27328,27520,43841,26880,43457,43137,26688,30720,47297,47489,31040,47873,31680,31360,47681,48641,32448,32640,48961,32e3,48577,48257,31808,46081,29888,30080,46401,30464,47041,46721,30272,29184,45761,45953,29504,45313,29120,28800,45121,20480,37057,37249,20800,37633,21440,21120,37441,38401,22208,22400,38721,21760,38337,38017,21568,39937,23744,23936,40257,24320,40897,40577,24128,23040,39617,39809,23360,39169,22976,22656,38977,34817,18624,18816,35137,19200,35777,35457,19008,19968,36545,36737,20288,36097,19904,19584,35905,17408,33985,34177,17728,34561,18368,18048,34369,33281,17088,17280,33601,16640,33217,32897,16448];"undefined"!=typeof Int32Array&&(n=new Int32Array(n));t.default=(e,t)=>{let i=void 0!==t?~~t:65535;for(let t=0;t<e.length;t++)i=65535&(n[255&(i^e[t])]^i>>8);return i}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(74);t.default=(e,t)=>n.Buffer.from(e,t)},function(e,t,i){"use strict";(function(e){
|
|
19
19
|
/*!
|
|
20
20
|
* The buffer module from node.js, for the browser.
|
|
21
21
|
*
|
|
22
22
|
* @author Feross Aboukhadijeh <http://feross.org>
|
|
23
23
|
* @license MIT
|
|
24
24
|
*/
|
|
25
|
-
var n=i(75),s=i(76),r=i(77);function a(){return c.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function o(e,t){if(a()<t)throw new RangeError("Invalid typed array length");return c.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=c.prototype:(null===e&&(e=new c(t)),e.length=t),e}function c(e,t,i){if(!(c.TYPED_ARRAY_SUPPORT||this instanceof c))return new c(e,t,i);if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return d(this,e)}return l(this,e,t,i)}function l(e,t,i,n){if("number"==typeof t)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer?function(e,t,i,n){if(t.byteLength,i<0||t.byteLength<i)throw new RangeError("'offset' is out of bounds");if(t.byteLength<i+(n||0))throw new RangeError("'length' is out of bounds");t=void 0===i&&void 0===n?new Uint8Array(t):void 0===n?new Uint8Array(t,i):new Uint8Array(t,i,n);c.TYPED_ARRAY_SUPPORT?(e=t).__proto__=c.prototype:e=h(e,t);return e}(e,t,i,n):"string"==typeof t?function(e,t,i){"string"==typeof i&&""!==i||(i="utf8");if(!c.isEncoding(i))throw new TypeError('"encoding" must be a valid string encoding');var n=0|p(t,i),s=(e=o(e,n)).write(t,i);s!==n&&(e=e.slice(0,s));return e}(e,t,i):function(e,t){if(c.isBuffer(t)){var i=0|f(t.length);return 0===(e=o(e,i)).length||t.copy(e,0,0,i),e}if(t){if("undefined"!=typeof ArrayBuffer&&t.buffer instanceof ArrayBuffer||"length"in t)return"number"!=typeof t.length||(n=t.length)!=n?o(e,0):h(e,t);if("Buffer"===t.type&&r(t.data))return h(e,t.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function u(e){if("number"!=typeof e)throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function d(e,t){if(u(t),e=o(e,t<0?0:0|f(t)),!c.TYPED_ARRAY_SUPPORT)for(var i=0;i<t;++i)e[i]=0;return e}function h(e,t){var i=t.length<0?0:0|f(t.length);e=o(e,i);for(var n=0;n<i;n+=1)e[n]=255&t[n];return e}function f(e){if(e>=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|e}function p(e,t){if(c.isBuffer(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var i=e.length;if(0===i)return 0;for(var n=!1;;)switch(t){case"ascii":case"latin1":case"binary":return i;case"utf8":case"utf-8":case void 0:return U(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*i;case"hex":return i>>>1;case"base64":return G(e).length;default:if(n)return U(e).length;t=(""+t).toLowerCase(),n=!0}}function v(e,t,i){var n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return"";if((i>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return E(this,t,i);case"utf8":case"utf-8":return A(this,t,i);case"ascii":return k(this,t,i);case"latin1":case"binary":return C(this,t,i);case"base64":return B(this,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,t,i);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function g(e,t,i){var n=e[t];e[t]=e[i],e[i]=n}function y(e,t,i,n,s){if(0===e.length)return-1;if("string"==typeof i?(n=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),i=+i,isNaN(i)&&(i=s?0:e.length-1),i<0&&(i=e.length+i),i>=e.length){if(s)return-1;i=e.length-1}else if(i<0){if(!s)return-1;i=0}if("string"==typeof t&&(t=c.from(t,n)),c.isBuffer(t))return 0===t.length?-1:_(e,t,i,n,s);if("number"==typeof t)return t&=255,c.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?s?Uint8Array.prototype.indexOf.call(e,t,i):Uint8Array.prototype.lastIndexOf.call(e,t,i):_(e,[t],i,n,s);throw new TypeError("val must be string, number or Buffer")}function _(e,t,i,n,s){var r,a=1,o=e.length,c=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;a=2,o/=2,c/=2,i/=2}function l(e,t){return 1===a?e[t]:e.readUInt16BE(t*a)}if(s){var u=-1;for(r=i;r<o;r++)if(l(e,r)===l(t,-1===u?0:r-u)){if(-1===u&&(u=r),r-u+1===c)return u*a}else-1!==u&&(r-=r-u),u=-1}else for(i+c>o&&(i=o-c),r=i;r>=0;r--){for(var d=!0,h=0;h<c;h++)if(l(e,r+h)!==l(t,h)){d=!1;break}if(d)return r}return-1}function D(e,t,i,n){i=Number(i)||0;var s=e.length-i;n?(n=Number(n))>s&&(n=s):n=s;var r=t.length;if(r%2!=0)throw new TypeError("Invalid hex string");n>r/2&&(n=r/2);for(var a=0;a<n;++a){var o=parseInt(t.substr(2*a,2),16);if(isNaN(o))return a;e[i+a]=o}return a}function m(e,t,i,n){return j(U(t,e.length-i),e,i,n)}function b(e,t,i,n){return j(function(e){for(var t=[],i=0;i<e.length;++i)t.push(255&e.charCodeAt(i));return t}(t),e,i,n)}function S(e,t,i,n){return b(e,t,i,n)}function w(e,t,i,n){return j(G(t),e,i,n)}function I(e,t,i,n){return j(function(e,t){for(var i,n,s,r=[],a=0;a<e.length&&!((t-=2)<0);++a)i=e.charCodeAt(a),n=i>>8,s=i%256,r.push(s),r.push(n);return r}(t,e.length-i),e,i,n)}function B(e,t,i){return 0===t&&i===e.length?n.fromByteArray(e):n.fromByteArray(e.slice(t,i))}function A(e,t,i){i=Math.min(e.length,i);for(var n=[],s=t;s<i;){var r,a,o,c,l=e[s],u=null,d=l>239?4:l>223?3:l>191?2:1;if(s+d<=i)switch(d){case 1:l<128&&(u=l);break;case 2:128==(192&(r=e[s+1]))&&(c=(31&l)<<6|63&r)>127&&(u=c);break;case 3:r=e[s+1],a=e[s+2],128==(192&r)&&128==(192&a)&&(c=(15&l)<<12|(63&r)<<6|63&a)>2047&&(c<55296||c>57343)&&(u=c);break;case 4:r=e[s+1],a=e[s+2],o=e[s+3],128==(192&r)&&128==(192&a)&&128==(192&o)&&(c=(15&l)<<18|(63&r)<<12|(63&a)<<6|63&o)>65535&&c<1114112&&(u=c)}null===u?(u=65533,d=1):u>65535&&(u-=65536,n.push(u>>>10&1023|55296),u=56320|1023&u),n.push(u),s+=d}return function(e){var t=e.length;if(t<=4096)return String.fromCharCode.apply(String,e);var i="",n=0;for(;n<t;)i+=String.fromCharCode.apply(String,e.slice(n,n+=4096));return i}(n)}t.Buffer=c,t.SlowBuffer=function(e){+e!=e&&(e=0);return c.alloc(+e)},t.INSPECT_MAX_BYTES=50,c.TYPED_ARRAY_SUPPORT=void 0!==e.TYPED_ARRAY_SUPPORT?e.TYPED_ARRAY_SUPPORT:function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()&&"function"==typeof e.subarray&&0===e.subarray(1,1).byteLength}catch(e){return!1}}(),t.kMaxLength=a(),c.poolSize=8192,c._augment=function(e){return e.__proto__=c.prototype,e},c.from=function(e,t,i){return l(null,e,t,i)},c.TYPED_ARRAY_SUPPORT&&(c.prototype.__proto__=Uint8Array.prototype,c.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&c[Symbol.species]===c&&Object.defineProperty(c,Symbol.species,{value:null,configurable:!0})),c.alloc=function(e,t,i){return function(e,t,i,n){return u(t),t<=0?o(e,t):void 0!==i?"string"==typeof n?o(e,t).fill(i,n):o(e,t).fill(i):o(e,t)}(null,e,t,i)},c.allocUnsafe=function(e){return d(null,e)},c.allocUnsafeSlow=function(e){return d(null,e)},c.isBuffer=function(e){return!(null==e||!e._isBuffer)},c.compare=function(e,t){if(!c.isBuffer(e)||!c.isBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var i=e.length,n=t.length,s=0,r=Math.min(i,n);s<r;++s)if(e[s]!==t[s]){i=e[s],n=t[s];break}return i<n?-1:n<i?1:0},c.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},c.concat=function(e,t){if(!r(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return c.alloc(0);var i;if(void 0===t)for(t=0,i=0;i<e.length;++i)t+=e[i].length;var n=c.allocUnsafe(t),s=0;for(i=0;i<e.length;++i){var a=e[i];if(!c.isBuffer(a))throw new TypeError('"list" argument must be an Array of Buffers');a.copy(n,s),s+=a.length}return n},c.byteLength=p,c.prototype._isBuffer=!0,c.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)g(this,t,t+1);return this},c.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)g(this,t,t+3),g(this,t+1,t+2);return this},c.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)g(this,t,t+7),g(this,t+1,t+6),g(this,t+2,t+5),g(this,t+3,t+4);return this},c.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?A(this,0,e):v.apply(this,arguments)},c.prototype.equals=function(e){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===c.compare(this,e)},c.prototype.inspect=function(){var e="",i=t.INSPECT_MAX_BYTES;return this.length>0&&(e=this.toString("hex",0,i).match(/.{2}/g).join(" "),this.length>i&&(e+=" ... ")),"<Buffer "+e+">"},c.prototype.compare=function(e,t,i,n,s){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===i&&(i=e?e.length:0),void 0===n&&(n=0),void 0===s&&(s=this.length),t<0||i>e.length||n<0||s>this.length)throw new RangeError("out of range index");if(n>=s&&t>=i)return 0;if(n>=s)return-1;if(t>=i)return 1;if(this===e)return 0;for(var r=(s>>>=0)-(n>>>=0),a=(i>>>=0)-(t>>>=0),o=Math.min(r,a),l=this.slice(n,s),u=e.slice(t,i),d=0;d<o;++d)if(l[d]!==u[d]){r=l[d],a=u[d];break}return r<a?-1:a<r?1:0},c.prototype.includes=function(e,t,i){return-1!==this.indexOf(e,t,i)},c.prototype.indexOf=function(e,t,i){return y(this,e,t,i,!0)},c.prototype.lastIndexOf=function(e,t,i){return y(this,e,t,i,!1)},c.prototype.write=function(e,t,i,n){if(void 0===t)n="utf8",i=this.length,t=0;else if(void 0===i&&"string"==typeof t)n=t,i=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t|=0,isFinite(i)?(i|=0,void 0===n&&(n="utf8")):(n=i,i=void 0)}var s=this.length-t;if((void 0===i||i>s)&&(i=s),e.length>0&&(i<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var r=!1;;)switch(n){case"hex":return D(this,e,t,i);case"utf8":case"utf-8":return m(this,e,t,i);case"ascii":return b(this,e,t,i);case"latin1":case"binary":return S(this,e,t,i);case"base64":return w(this,e,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return I(this,e,t,i);default:if(r)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),r=!0}},c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function k(e,t,i){var n="";i=Math.min(e.length,i);for(var s=t;s<i;++s)n+=String.fromCharCode(127&e[s]);return n}function C(e,t,i){var n="";i=Math.min(e.length,i);for(var s=t;s<i;++s)n+=String.fromCharCode(e[s]);return n}function E(e,t,i){var n=e.length;(!t||t<0)&&(t=0),(!i||i<0||i>n)&&(i=n);for(var s="",r=t;r<i;++r)s+=N(e[r]);return s}function T(e,t,i){for(var n=e.slice(t,i),s="",r=0;r<n.length;r+=2)s+=String.fromCharCode(n[r]+256*n[r+1]);return s}function P(e,t,i){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>i)throw new RangeError("Trying to access beyond buffer length")}function O(e,t,i,n,s,r){if(!c.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>s||t<r)throw new RangeError('"value" argument is out of bounds');if(i+n>e.length)throw new RangeError("Index out of range")}function L(e,t,i,n){t<0&&(t=65535+t+1);for(var s=0,r=Math.min(e.length-i,2);s<r;++s)e[i+s]=(t&255<<8*(n?s:1-s))>>>8*(n?s:1-s)}function x(e,t,i,n){t<0&&(t=4294967295+t+1);for(var s=0,r=Math.min(e.length-i,4);s<r;++s)e[i+s]=t>>>8*(n?s:3-s)&255}function M(e,t,i,n,s,r){if(i+n>e.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function K(e,t,i,n,r){return r||M(e,0,i,4),s.write(e,t,i,n,23,4),i+4}function H(e,t,i,n,r){return r||M(e,0,i,8),s.write(e,t,i,n,52,8),i+8}c.prototype.slice=function(e,t){var i,n=this.length;if((e=~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),(t=void 0===t?n:~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),t<e&&(t=e),c.TYPED_ARRAY_SUPPORT)(i=this.subarray(e,t)).__proto__=c.prototype;else{var s=t-e;i=new c(s,void 0);for(var r=0;r<s;++r)i[r]=this[r+e]}return i},c.prototype.readUIntLE=function(e,t,i){e|=0,t|=0,i||P(e,t,this.length);for(var n=this[e],s=1,r=0;++r<t&&(s*=256);)n+=this[e+r]*s;return n},c.prototype.readUIntBE=function(e,t,i){e|=0,t|=0,i||P(e,t,this.length);for(var n=this[e+--t],s=1;t>0&&(s*=256);)n+=this[e+--t]*s;return n},c.prototype.readUInt8=function(e,t){return t||P(e,1,this.length),this[e]},c.prototype.readUInt16LE=function(e,t){return t||P(e,2,this.length),this[e]|this[e+1]<<8},c.prototype.readUInt16BE=function(e,t){return t||P(e,2,this.length),this[e]<<8|this[e+1]},c.prototype.readUInt32LE=function(e,t){return t||P(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},c.prototype.readUInt32BE=function(e,t){return t||P(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},c.prototype.readIntLE=function(e,t,i){e|=0,t|=0,i||P(e,t,this.length);for(var n=this[e],s=1,r=0;++r<t&&(s*=256);)n+=this[e+r]*s;return n>=(s*=128)&&(n-=Math.pow(2,8*t)),n},c.prototype.readIntBE=function(e,t,i){e|=0,t|=0,i||P(e,t,this.length);for(var n=t,s=1,r=this[e+--n];n>0&&(s*=256);)r+=this[e+--n]*s;return r>=(s*=128)&&(r-=Math.pow(2,8*t)),r},c.prototype.readInt8=function(e,t){return t||P(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},c.prototype.readInt16LE=function(e,t){t||P(e,2,this.length);var i=this[e]|this[e+1]<<8;return 32768&i?4294901760|i:i},c.prototype.readInt16BE=function(e,t){t||P(e,2,this.length);var i=this[e+1]|this[e]<<8;return 32768&i?4294901760|i:i},c.prototype.readInt32LE=function(e,t){return t||P(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},c.prototype.readInt32BE=function(e,t){return t||P(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},c.prototype.readFloatLE=function(e,t){return t||P(e,4,this.length),s.read(this,e,!0,23,4)},c.prototype.readFloatBE=function(e,t){return t||P(e,4,this.length),s.read(this,e,!1,23,4)},c.prototype.readDoubleLE=function(e,t){return t||P(e,8,this.length),s.read(this,e,!0,52,8)},c.prototype.readDoubleBE=function(e,t){return t||P(e,8,this.length),s.read(this,e,!1,52,8)},c.prototype.writeUIntLE=function(e,t,i,n){(e=+e,t|=0,i|=0,n)||O(this,e,t,i,Math.pow(2,8*i)-1,0);var s=1,r=0;for(this[t]=255&e;++r<i&&(s*=256);)this[t+r]=e/s&255;return t+i},c.prototype.writeUIntBE=function(e,t,i,n){(e=+e,t|=0,i|=0,n)||O(this,e,t,i,Math.pow(2,8*i)-1,0);var s=i-1,r=1;for(this[t+s]=255&e;--s>=0&&(r*=256);)this[t+s]=e/r&255;return t+i},c.prototype.writeUInt8=function(e,t,i){return e=+e,t|=0,i||O(this,e,t,1,255,0),c.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},c.prototype.writeUInt16LE=function(e,t,i){return e=+e,t|=0,i||O(this,e,t,2,65535,0),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):L(this,e,t,!0),t+2},c.prototype.writeUInt16BE=function(e,t,i){return e=+e,t|=0,i||O(this,e,t,2,65535,0),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):L(this,e,t,!1),t+2},c.prototype.writeUInt32LE=function(e,t,i){return e=+e,t|=0,i||O(this,e,t,4,4294967295,0),c.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):x(this,e,t,!0),t+4},c.prototype.writeUInt32BE=function(e,t,i){return e=+e,t|=0,i||O(this,e,t,4,4294967295,0),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):x(this,e,t,!1),t+4},c.prototype.writeIntLE=function(e,t,i,n){if(e=+e,t|=0,!n){var s=Math.pow(2,8*i-1);O(this,e,t,i,s-1,-s)}var r=0,a=1,o=0;for(this[t]=255&e;++r<i&&(a*=256);)e<0&&0===o&&0!==this[t+r-1]&&(o=1),this[t+r]=(e/a>>0)-o&255;return t+i},c.prototype.writeIntBE=function(e,t,i,n){if(e=+e,t|=0,!n){var s=Math.pow(2,8*i-1);O(this,e,t,i,s-1,-s)}var r=i-1,a=1,o=0;for(this[t+r]=255&e;--r>=0&&(a*=256);)e<0&&0===o&&0!==this[t+r+1]&&(o=1),this[t+r]=(e/a>>0)-o&255;return t+i},c.prototype.writeInt8=function(e,t,i){return e=+e,t|=0,i||O(this,e,t,1,127,-128),c.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},c.prototype.writeInt16LE=function(e,t,i){return e=+e,t|=0,i||O(this,e,t,2,32767,-32768),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):L(this,e,t,!0),t+2},c.prototype.writeInt16BE=function(e,t,i){return e=+e,t|=0,i||O(this,e,t,2,32767,-32768),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):L(this,e,t,!1),t+2},c.prototype.writeInt32LE=function(e,t,i){return e=+e,t|=0,i||O(this,e,t,4,2147483647,-2147483648),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):x(this,e,t,!0),t+4},c.prototype.writeInt32BE=function(e,t,i){return e=+e,t|=0,i||O(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):x(this,e,t,!1),t+4},c.prototype.writeFloatLE=function(e,t,i){return K(this,e,t,!0,i)},c.prototype.writeFloatBE=function(e,t,i){return K(this,e,t,!1,i)},c.prototype.writeDoubleLE=function(e,t,i){return H(this,e,t,!0,i)},c.prototype.writeDoubleBE=function(e,t,i){return H(this,e,t,!1,i)},c.prototype.copy=function(e,t,i,n){if(i||(i=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<i&&(n=i),n===i)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(i<0||i>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-i&&(n=e.length-t+i);var s,r=n-i;if(this===e&&i<t&&t<n)for(s=r-1;s>=0;--s)e[s+t]=this[s+i];else if(r<1e3||!c.TYPED_ARRAY_SUPPORT)for(s=0;s<r;++s)e[s+t]=this[s+i];else Uint8Array.prototype.set.call(e,this.subarray(i,i+r),t);return r},c.prototype.fill=function(e,t,i,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=0,i=this.length):"string"==typeof i&&(n=i,i=this.length),1===e.length){var s=e.charCodeAt(0);s<256&&(e=s)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!c.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<i)throw new RangeError("Out of range index");if(i<=t)return this;var r;if(t>>>=0,i=void 0===i?this.length:i>>>0,e||(e=0),"number"==typeof e)for(r=t;r<i;++r)this[r]=e;else{var a=c.isBuffer(e)?e:U(new c(e,n).toString()),o=a.length;for(r=0;r<i-t;++r)this[r+t]=a[r%o]}return this};var R=/[^+\/0-9A-Za-z-_]/g;function N(e){return e<16?"0"+e.toString(16):e.toString(16)}function U(e,t){var i;t=t||1/0;for(var n=e.length,s=null,r=[],a=0;a<n;++a){if((i=e.charCodeAt(a))>55295&&i<57344){if(!s){if(i>56319){(t-=3)>-1&&r.push(239,191,189);continue}if(a+1===n){(t-=3)>-1&&r.push(239,191,189);continue}s=i;continue}if(i<56320){(t-=3)>-1&&r.push(239,191,189),s=i;continue}i=65536+(s-55296<<10|i-56320)}else s&&(t-=3)>-1&&r.push(239,191,189);if(s=null,i<128){if((t-=1)<0)break;r.push(i)}else if(i<2048){if((t-=2)<0)break;r.push(i>>6|192,63&i|128)}else if(i<65536){if((t-=3)<0)break;r.push(i>>12|224,i>>6&63|128,63&i|128)}else{if(!(i<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;r.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128)}}return r}function G(e){return n.toByteArray(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(R,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function j(e,t,i,n){for(var s=0;s<n&&!(s+i>=t.length||s>=e.length);++s)t[s+i]=e[s];return s}}).call(this,i(23))},function(e,t,i){"use strict";t.byteLength=function(e){var t=l(e),i=t[0],n=t[1];return 3*(i+n)/4-n},t.toByteArray=function(e){var t,i,n=l(e),a=n[0],o=n[1],c=new r(function(e,t,i){return 3*(t+i)/4-i}(0,a,o)),u=0,d=o>0?a-4:a;for(i=0;i<d;i+=4)t=s[e.charCodeAt(i)]<<18|s[e.charCodeAt(i+1)]<<12|s[e.charCodeAt(i+2)]<<6|s[e.charCodeAt(i+3)],c[u++]=t>>16&255,c[u++]=t>>8&255,c[u++]=255&t;2===o&&(t=s[e.charCodeAt(i)]<<2|s[e.charCodeAt(i+1)]>>4,c[u++]=255&t);1===o&&(t=s[e.charCodeAt(i)]<<10|s[e.charCodeAt(i+1)]<<4|s[e.charCodeAt(i+2)]>>2,c[u++]=t>>8&255,c[u++]=255&t);return c},t.fromByteArray=function(e){for(var t,i=e.length,s=i%3,r=[],a=0,o=i-s;a<o;a+=16383)r.push(u(e,a,a+16383>o?o:a+16383));1===s?(t=e[i-1],r.push(n[t>>2]+n[t<<4&63]+"==")):2===s&&(t=(e[i-2]<<8)+e[i-1],r.push(n[t>>10]+n[t>>4&63]+n[t<<2&63]+"="));return r.join("")};for(var n=[],s=[],r="undefined"!=typeof Uint8Array?Uint8Array:Array,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0,c=a.length;o<c;++o)n[o]=a[o],s[a.charCodeAt(o)]=o;function l(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var i=e.indexOf("=");return-1===i&&(i=t),[i,i===t?0:4-i%4]}function u(e,t,i){for(var s,r,a=[],o=t;o<i;o+=3)s=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(255&e[o+2]),a.push(n[(r=s)>>18&63]+n[r>>12&63]+n[r>>6&63]+n[63&r]);return a.join("")}s["-".charCodeAt(0)]=62,s["_".charCodeAt(0)]=63},function(e,t){t.read=function(e,t,i,n,s){var r,a,o=8*s-n-1,c=(1<<o)-1,l=c>>1,u=-7,d=i?s-1:0,h=i?-1:1,f=e[t+d];for(d+=h,r=f&(1<<-u)-1,f>>=-u,u+=o;u>0;r=256*r+e[t+d],d+=h,u-=8);for(a=r&(1<<-u)-1,r>>=-u,u+=n;u>0;a=256*a+e[t+d],d+=h,u-=8);if(0===r)r=1-l;else{if(r===c)return a?NaN:1/0*(f?-1:1);a+=Math.pow(2,n),r-=l}return(f?-1:1)*a*Math.pow(2,r-n)},t.write=function(e,t,i,n,s,r){var a,o,c,l=8*r-s-1,u=(1<<l)-1,d=u>>1,h=23===s?Math.pow(2,-24)-Math.pow(2,-77):0,f=n?0:r-1,p=n?1:-1,v=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(o=isNaN(t)?1:0,a=u):(a=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-a))<1&&(a--,c*=2),(t+=a+d>=1?h/c:h*Math.pow(2,1-d))*c>=2&&(a++,c/=2),a+d>=u?(o=0,a=u):a+d>=1?(o=(t*c-1)*Math.pow(2,s),a+=d):(o=t*Math.pow(2,d-1)*Math.pow(2,s),a=0));s>=8;e[i+f]=255&o,f+=p,o/=256,s-=8);for(a=a<<s|o,l+=s;l>0;e[i+f]=255&a,f+=p,a/=256,l-=8);e[i+f-p]|=128*v}},function(e,t){var i={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==i.call(e)}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(79),s=i(32);t.default=s.default("crc-32",n.default)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});let n=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117];"undefined"!=typeof Int32Array&&(n=new Int32Array(n));t.default=(e,t)=>{let i=0===t?0:-1^~~t;for(let t=0;t<e.length;t++)i=n[255&(i^e[t])]^i>>>8;return-1^i}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(1),s=i(3);class r extends n.default{constructor(e){super(e)}}r.pack=e=>[0,0,0,3,7,0,0,69,...s.hexStrint2byte(s.fillString(e.toString(16),8))],t.default=r},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(31),s=i(30),r=i(1),a=i(3);class o extends r.default{constructor(e){super(e),this.packageNum=0,this.state=0;let t=0;this.packageNum=a.bytesToInt(this.content.slice(t,t+2)),t+=2,this.state=this.content[t]}}o.pack=(e,t)=>{const i=a.hexStrint2byte(a.fillString(t.toString(16),4)),r=a.hexStrint2byte(a.fillString(e.length.toString(16),4)),o=a.fillString(n.crc16modbus(new Uint8Array(e)).toString(16),4),c=a.hexStrint2byte(o);let l=[0];l=l.concat([0,71],i,r,c,e);const u=s.getVariableLength(l);return[0,0,0,3].concat(u,l)},t.default=o},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(1);class s extends n.default{constructor(e){super(e),this.state=0;this.state=this.content[0]}}s.pack=e=>[0,0,0,3,4,0,0,80,e],t.default=s},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(5),r=i(4),a=i(12),o=i(10);t.default=class{constructor({appID:e,token:t,uid:i,limitSocketNum:r=!0}){this._bindingDevices=null,this._connections={},this.updateToken=({token:e,uid:t})=>{this.token=e,this.uid=t},this._getDevice=e=>{if(null===this._bindingDevices)return s.default.GIZ_SDK_SDK_NOT_INITIALIZED;const t=this._bindingDevices[e];return null==t?s.default.GIZ_OPENAPI_DEVICE_NOT_BOUND:t},this._getConnect=e=>{const t=this._getWebsocketConnInfo(e);return this._connections[t]},this._getDeviceAndConnect=e=>{const t=this._getDevice(e);if(o.isError(t))return t;const i=this._getConnect(t);return null==i?s.default.GIZ_SDK_DEVICE_NOT_SUBSCRIBED:[t,i]},this.connectDevice=e=>{const t=this._getWebsocketConnInfo(e);let i=this._connections[t];if(null==i){const e=Object.keys(this._connections).length;if(0!==this._maxSocketNum&&e>=this._maxSocketNum)return{success:!1,errorCode:s.default.MAX_CONNECT};i=new c({appID:this.appID,token:this.token,uid:this.uid,wsInfo:t,onDeviceStatusChanged:this._handleDeviceStatusChanged,onBindingChanged:this._handleBindingChanged,onSocketStatusChanged:this._handleSocketStatusChanged}),this._connections[t]=i}return i._addSubDid(e.did),null==i._websocket?i._connectWS():i.ready&&i._subDevices([e.did]),{success:!0}},this.disConnectDevice=e=>{const t=this._getWebsocketConnInfo(e);let i=this._connections[t];return i&&i._unSubDevices([e.did]),{success:!0}},this.connect=e=>{const t=this._getDevice(e);if(o.isError(t))return t;const i=this.connectDevice(t);return i.success?null:i.errorCode},this.send=(e,t)=>{const i=this._getDeviceAndConnect(e);return o.isError(i)?i:i[1]._send({cmd:"c2s_raw",data:{did:e,raw:t}})},this.writeData=(e,t)=>{const i=this._getConnect(e);return null!=i?i._send({cmd:"c2s_write",data:{did:e.did,attrs:t}}):{success:!1}},this.write=(e,t)=>{const i=this._getDeviceAndConnect(e);return o.isError(i)?i:i[1]._send({cmd:"c2s_write",data:{did:e,attrs:t}})},this.readStatus=(e,t)=>{const i=this._getConnect(e),n=null!=i;return n&&i._send({cmd:"c2s_read",data:{did:e.did,names:t}}),{success:n}},this.read=(e,t)=>{const i=this._getDeviceAndConnect(e);return o.isError(i)?i:i[1]._send({cmd:"c2s_read",data:{did:e,names:t}})},this.destory=()=>{Object.values(this._connections).forEach(e=>e.destory())},this.subscribeDeviceStatus=e=>{this._onDeviceStatusChanged=e},this.subscribeBindingChanged=e=>{this._onBindingChanged=e},this.subscribeSocketStatus=e=>{this._onSocketStatusChanged=e},this._handleDeviceStatusChanged=e=>{this._onDeviceStatusChanged&&this._onDeviceStatusChanged(e)},this._handleBindingChanged=()=>{this._onBindingChanged&&this._onBindingChanged()},this._handleSocketStatusChanged=(...e)=>{this._onSocketStatusChanged&&this._onSocketStatusChanged(...e)},this._getBindingList=(e=20,t=0,i=[])=>n(this,void 0,void 0,(function*(){const n=`/app/bindings?show_disabled=0&limit=${e}&skip=${t}`,{err:s,data:r}=yield a.default(`${n}`,{method:"GET"});if(s)return{err:s};const o=[...i,...(null==r?void 0:r.devices)||[]];return r&&r.devices.length===e?yield this._getBindingList(e,e+t,o):o})),this._getWebsocketConnInfo=e=>e.host?`wss://wx${e.host}`:"wss://wxstage.gizwits.com",this.appID=e,this.token=t,this.uid=i;const l=wx.getSystemInfoSync().SDKVersion;this._maxSocketNum=r?-1===o.compareWXSDKVersion(l||"1.0.0","1.7.0")?1:5:0}init(){var e,t;return n(this,void 0,void 0,(function*(){try{const i=yield this._getBindingList();return(null===(e=i.err)||void 0===e?void 0:e.errorCode)?{errorCode:null===(t=i.err)||void 0===t?void 0:t.errorCode,errorMessage:"getting binding list failed"}:(this._bindingDevices=i.reduce((e,t)=>Object.assign(Object.assign({},e),{[t.did]:t}),{}),null)}catch(e){return s.default.GIZ_SDK_OTHERWISE}}))}};class c{constructor({appID:e,token:t,uid:i,wsInfo:s,onDeviceStatusChanged:a,onBindingChanged:o,onSocketStatusChanged:c}){this.ready=!1,this.commType="attrs_v4",this._heartbeatInterval=60,this._keepaliveTime=180,this._loginIntveral=5e3,this.autoSubscribe=!1,this._websocket=null,this._loginFailedTimes=0,this._subDids=new Set,this._socketRespHandleMap={},this._waitSends=[],this.destory=()=>{this._heartbeatTimerId&&clearInterval(this._heartbeatTimerId),this._checkConnectTimerId&&clearInterval(this._checkConnectTimerId),this.close()},this._networkChange=e=>n(this,void 0,void 0,(function*(){r.default.log("network change",e)})),this._appShow=()=>n(this,void 0,void 0,(function*(){r.default.log("app show")})),this._addSubDid=e=>{this._subDids.add(e)},this._removeSubDid=e=>{this._subDids.delete(e)},this._connectWS=()=>{r.default.log("GIZ_SDK: start connect ws"),this._websocket=wx.connectSocket({url:this._wsUrl,fail:e=>{r.default.error("GIZ_SDK: connectSocket error",new Error(JSON.stringify(e)))}}),this._websocket.onClose(this.handleClose),this._websocket.onOpen(this.handleOpen),this._websocket.onError(this.handleError),this._websocket.onMessage(this.handleMessage),this._checkConnectTimerId||(this._checkConnectTimerId=setInterval(()=>{this._websocket||this._connectWS()},1e3))},this._subDevices=e=>{const t={cmd:"subscribe_req",data:e.map(e=>({did:e}))};this._send(t)},this._unSubDevices=e=>{e.map(e=>this._removeSubDid(e))},this._send=(e,t=!1)=>(r.default.log("GIZ_SDK: Socket send",e,t),new Promise(i=>{this._websocket?t||this.ready?this._websocket&&(t||this.ready)&&this._websocket.send({data:JSON.stringify(e),complete:e=>{r.default.log("GIZ_SDK: socket send res",e),r.default.log("resres",e);let t=!1;"sendSocketMessage:ok"===e.errMsg&&(t=!0),i({success:t,message:e.errMsg})},fail:e=>{r.default.error("GIZ_SDK: Socket send error",new Error(JSON.stringify(e))),i({success:!1,message:e.errMsg})}}):i({success:!1,message:"Socket not ready"}):i({success:!1,message:"Socket not init"})})),this.close=()=>{this.ready=!1,this._heartbeatTimerId&&clearInterval(this._heartbeatTimerId),this._websocket&&(this._websocket.close({}),this._websocket=null),this._handleSocketStatusChanged(!1)},this.handleClose=e=>{r.default.error("GIZ_SDK: socket close",new Error(JSON.stringify(e))),this.close(),this._stopPing()},this.handleOpen=()=>{r.default.log(" socket open"),this._login()},this.handleMessage=({data:e})=>{r.default.log("GIZ_SDK: message",e);const t=JSON.parse(e),i=this._socketRespHandleMap[t.cmd];i&&i(t.data)},this.handleError=e=>{r.default.error("GIZ_SDK: socket error",new Error(JSON.stringify(e))),this.close(),this._stopPing()},this._login=()=>{const e={cmd:"login_req",data:{appid:this.appID,uid:this.uid,token:this.token,p0_type:this.commType,heartbeat_interval:this._keepaliveTime,auto_subscribe:this.autoSubscribe}};this._send(e,!0)},this._tryLoginAgain=()=>{this._loginFailedTimes+=1,setTimeout(()=>{this._login()},this._loginFailedTimes*this._loginIntveral)},this._startPing=()=>{this._heartbeatTimerId=setInterval(()=>{this._send({cmd:"ping"})},1e3*this._heartbeatInterval)},this._stopPing=()=>{this._heartbeatTimerId&&clearInterval(this._heartbeatTimerId)},this.pongResp=()=>{},this._loginResp=e=>{1==e.success?(this._loginFailedTimes=0,this.ready=!0,this._startPing(),this._subDevices([...this._subDids]),this._handleSocketStatusChanged(!0),this._consumeWaitSends()):this._loginFailedTimes<3?(r.default.log("GIZ_SDK: Login failed, will try again, please wait..."),this._tryLoginAgain()):(r.default.error("GIZ_SDK: Login failed",new Error("m2m socket login failed")),this.close())},this._consumeWaitSends=()=>{let e=this._waitSends.pop();for(;e;)this._send(e),e=this._waitSends.pop()},this._handleSocketStatusChanged=e=>{this._onSocketStatusChanged&&this._onSocketStatusChanged([...this._subDids],e)},this._subscribeResp=e=>{r.default.log("GIZ_SDK: subscribe_res",e),e&&e.success&&e.success.forEach(e=>this._send({cmd:"c2s_read",data:{did:e.did}})),r.default.debug("GIZ_SDK: subscribe_res",e)},this._onlineResp=e=>{this._isSub(e.did)&&this._onDeviceStatusChanged&&this._onDeviceStatusChanged({did:e.did,attrs:Object.assign({is_online:e.online},e)})},this._rawChangedResp=e=>{this._isSub(e.did)&&this._onDeviceStatusChanged&&this._onDeviceStatusChanged(e)},this._statusChangedResp=e=>{this._isSub(e.did)&&this._onDeviceStatusChanged&&this._onDeviceStatusChanged(e)},this._isSub=e=>this._subDids.has(e),this._invalidMsgResp=e=>{1003===e.error_code&&this._login(),r.default.error("GIZ_SDK: s2c_invalid_msg",new Error(JSON.stringify(e)))},this._bindingChangedResp=e=>{!e.bind&&e.did&&this._removeSubDid(e.did),this._onBindingChanged&&this._onBindingChanged()},this.appID=e,this.token=t,this.uid=i,this._wsUrl=`${s}/ws/app/v1`,this._heartbeatTimerId=void 0,this._loginFailedTimes=0,this._onDeviceStatusChanged=a,this._onBindingChanged=o,this._onSocketStatusChanged=c,this._socketRespHandleMap={pong:this.pongResp,login_res:this._loginResp,subscribe_res:this._subscribeResp,s2c_online_status:this._onlineResp,s2c_raw:this._rawChangedResp,s2c_noti:this._statusChangedResp,s2c_invalid_msg:this._invalidMsgResp,s2c_binding_changed:this._bindingChangedResp},wx.onNetworkStatusChange(this._networkChange),wx.onAppShow(this._appShow)}}t.Connection=c},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(5),r=i(4),a=i(20),o=i(21);class c extends o.default{constructor(){super(...arguments),this.disableSendUDP=!1,this.sendMessageInterval=null,this.UDPSocketHandler=null,this.destroy=()=>{this.cleanTimeout(),this.sendMessageInterval&&clearInterval(this.sendMessageInterval),this.sendMessageInterval=null,this.UDPSocketHandler&&(this.UDPSocketHandler.offError(),this.UDPSocketHandler.offMessage(),this.UDPSocketHandler.close())},this.configDevice=({ssid:e,password:t,softAPSSIDPrefix:i})=>new Promise((o,c)=>{r.default.debug("GIZ_SDK: start config device");let l=!1,u=0;const d=a.default.pack(e,t);this.UDPSocketHandler=wx.createUDPSocket(),this.UDPSocketHandler.bind(),this.disableSendUDP=!1;const h=()=>{try{!this.disableSendUDP&&this.UDPSocketHandler.send({address:"10.10.100.254",port:12414,message:d,offset:0,length:d.byteLength})}catch(e){}};this.sendMessageInterval=setInterval(()=>{h()},2e3),this.UDPSocketHandler.onError(e=>{u+=1,u>2&&(this.destroy(),c({success:!1,err:{errorCode:s.default.WECHAT_ERROR.errorCode,errorMessage:e.errMsg}}))});const f=()=>n(this,void 0,void 0,(function*(){if(!l){this.UDPSocketHandler.offMessage(),this.UDPSocketHandler.offError(),this.sendMessageInterval&&clearInterval(this.sendMessageInterval),this.disableSendUDP=!0,l=!0;try{const i=yield this.searchDevice({ssid:e,password:t});o(i)}catch(e){c(e)}}}));this.UDPSocketHandler.onMessage(e=>{f()}),wx.onNetworkStatusChange(()=>n(this,void 0,void 0,(function*(){!l&&wx.getConnectedWifi({success:e=>n(this,void 0,void 0,(function*(){-1===e.wifi.SSID.indexOf(i)&&f()}))})})))}),this.setDeviceOnboardingDeploy=({timeout:e,isBind:t=!0,softAPSSIDPrefix:i})=>{const s=this.ssid,r=this.password;return new Promise((a,o)=>n(this,void 0,void 0,(function*(){this.destroy(),this.initDeviceOnboardingDeploy(a,o),this.startTimeoutTimer(e);try{const e=((yield this.configDevice({ssid:s,password:r,softAPSSIDPrefix:i})).data||[]).map(e=>({mac:e.mac,productKey:e.product_key,did:e.did,name:"",isBind:!1,connectType:"NONE",isBleOnline:!1,isLanOnline:!1,isOnline:!1}));if(t)try{a(yield this.bindDevices(e))}catch(e){o(e)}else a({success:!0,data:e})}catch(e){o(e)}finally{this.destroy()}})))}}}t.default=c},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(11),s=({SSID:e,password:t,pk:i})=>{let s=n.MD5(e+t).toString();s=n.enc.Hex.parse(s);let r=n.enc.Utf8.parse(i),a=n.AES.encrypt(r,s,{iv:s,mode:n.mode.ECB,padding:n.pad.ZeroPadding});return n.MD5(a.ciphertext).toString()};t.default=({SSID:e,password:t,pks:i})=>{const n=[];return i.map(i=>{const r=s({SSID:e,password:t,pk:i});n.push(r)}),n}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(11);t.psKeySign=e=>{const t=Math.round((new Date).getTime()/1e3),i=e+t;return{Signature:n.MD5(i).toString(),timestamp:t}}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(5),r=i(10),a=i(19),o=i(9),c=i(21),l=i(20),u=i(4);function d({bleDeviceId:e,arrayBuffer:t,serviceUUIDSuffix:i="fe60",characteristicUUIDSuffix:s="fe61",bleHandle:o}){let c=null,l=null;const d=()=>null===l&&(c&&clearInterval(c),!0);return new Promise((h,f)=>n(this,void 0,void 0,(function*(){try{u.default.debug("GIZ_SDK: ssid info: ",t),l=setTimeout(()=>{c&&clearInterval(c),l=null,h(!1)},5e3),u.default.debug("GIZ_SDK: createBLEConnection start: ",e),yield o.disableScan();const n=yield a.retryConnect(e,1e4);o.enableScan(),u.default.debug("GIZ_SDK: createBLEConnection end, res:",n);const f=yield a.getBLEDeviceServices(e);u.default.debug("GIZ_SDK: getBLEDeviceServices end, res:",f);const p=f.find(e=>e.uuid.split("-")[0].toLowerCase().endsWith(i));if(!p)return u.default.debug("GIZ_SDK: get ble device services fail",e,f),void h(!1);const v=yield a.getBLEDeviceCharacteristics(e,p.uuid);u.default.debug("GIZ_SDK: getBLEDeviceCharacteristics end, res:",v);const g=v.find(e=>e.uuid.split("-")[0].toLowerCase().endsWith(s));if(!g)return u.default.debug("GIZ_SDK: get ble device characteristics fail",e,v),void h(!1);if(!g.properties.notify&&!g.properties.indicate)return u.default.debug("GIZ_SDK: the ble device characteristic not support notify or indicate",e,g),void h(!1);u.default.debug("GIZ_SDK: check characteristic and service success"),yield a.notifyBLECharacteristicValueChange(e,p.uuid,g.uuid);const y=e=>{const t=r.ab2hex(e.value);u.default.debug("GIZ_SDK: 收到设备返回ack",t),"0000000303000002"===t&&(o.removeEventListener("GizBleDeviceData",y),h(!0))};if(o.addEventListener("GizBleDeviceData",y),u.default.debug("GIZ_SDK: on notifyBLECharacteristicValueChange success"),d())return;yield a.unpackWriteBLECharacteristicValue(e,p.uuid,g.uuid,t),c=setInterval(()=>{d()||a.unpackWriteBLECharacteristicValue(e,p.uuid,g.uuid,t)},2e3),u.default.debug("GIZ_SDK: unpackWriteBLECharacteristicValue end")}catch(e){f(!1),u.default.debug("GIZ_SDK: sendBLEConfigCmd error",e)}}))).catch(e=>{u.default.debug("GIZ_SDK: sendBLEConfigCmd error",e)}).finally(()=>{l&&clearTimeout(l),c&&clearInterval(c),wx.closeBLEConnection({deviceId:e})})}t.sendBLEConfigCmd=d;class h extends c.default{constructor(e,t,i,c,h){super(e,t,i,c),this.destroy=()=>{this.cleanTimeout()},this.isValidBleDevice=(e,t)=>{if(!e||!e.advertisData)return!1;const{productKey:i,mac:n}=r.advertisData2PkAndMac(e.advertisData,this.specialProductKeys);return!!this.specialProductKeys.includes(i)&&(u.default.debug(`GIZ_SDK: isValidBleDevice mac: ${n} pk: ${i} name: ${e.name}`),u.default.debug(`GIZ_SDK: softAPSSIDPrefix: ${t} ismatch : ${e.name&&e.name.startsWith(t)}`),!t||e.name&&e.name.startsWith(t))},this.enableBluetoothDevicesDescovery=()=>n(this,void 0,void 0,(function*(){return(yield a.getBluetoothAdapterState()).available?(yield a.startBluetoothDevicesDiscovery(),{success:!0}):{success:!1,err:{errorCode:s.default.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON.errorCode,errorMessage:"蓝牙状态不可用"}}})),this.enableAndGetBluetoothDevices=e=>n(this,void 0,void 0,(function*(){const t=yield this.enableBluetoothDevicesDescovery();if(!t.success)return t;u.default.debug("GIZ_SDK: start enableAndGetBluetoothDevices");const i=(yield a.getBluetoothDevices()).filter(t=>this.isValidBleDevice(t,e));return u.default.debug("GIZ_SDK: getBluetoothDevices success",i),{success:!0,bleDevices:i}})),this.setDeviceOnboardingDeploy=({timeout:e,isBind:t=!0,softAPSSIDPrefix:i})=>new Promise((s,r)=>n(this,void 0,void 0,(function*(){const n=this.ssid,a=this.password;this.destroy(),this.initDeviceOnboardingDeploy(s,r),this.startTimeoutTimer(e);try{const r=((yield this.configBLEDevice({ssid:n,password:a,timeout:1e3*e,softAPSSIDPrefix:i})).data||[]).map(e=>({mac:e.mac,productKey:e.product_key,did:e.did,name:"",isBind:!1,connectType:"NONE",isBleOnline:!1,isLanOnline:!1,isOnline:!1}));s(t?yield this.bindDevices(r):{success:!0,data:r})}catch(e){s({success:!1,data:e})}finally{this.destroy()}}))),this.configBLEDevice=({ssid:e,password:t,softAPSSIDPrefix:i})=>new Promise((c,h)=>n(this,void 0,void 0,(function*(){u.default.debug("GIZ_SDK: start config ble device");const f=yield this.enableAndGetBluetoothDevices(i).catch(e=>({success:!1,err:{errorCode:s.default.WECHAT_ERROR.errorCode,errorMessage:JSON.stringify(e)}}));if(!r.isWXDevicesResult(f))return h(f);const{bleDevices:p}=f;u.default.debug("GIZ_SDK: enableAndGetBluetoothDevices success, target devices: ",p);const v=({devices:e})=>n(this,void 0,void 0,(function*(){this.hasTimeoutHandler()?Array.prototype.push.apply(p,e.filter(e=>this.isValidBleDevice(e,i))):wx.offBluetoothDeviceFound(v)}));wx.onBluetoothDeviceFound(v);const g=l.default.pack(e,t),y=()=>n(this,void 0,void 0,(function*(){if(u.default.debug("GIZ_SDK: startConfigDevice"),!this.hasTimeoutHandler())return;const e=p.shift();if(e&&u.default.debug("GIZ_SDK: startConfigDevice, target device: ",e),!(e&&(yield d({bleDeviceId:e.deviceId,arrayBuffer:g.buffer,bleHandle:this.bleHandle}))))return yield o.default(500),yield a.startBluetoothDevicesDiscovery(),void(yield y());u.default.debug("GIZ_SDK: offBluetoothDeviceFound ready search device"),wx.offBluetoothDeviceFound(v)}));try{this.searchDevice({ssid:e,password:t}).then(e=>{c(e)})}catch(e){h(e),u.default.error("GIZ_SDK: searchDevice error",new Error(JSON.stringify(e)))}yield y()}))),this.bleHandle=h}}t.default=h},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(5),r=i(10),a=i(19),o=i(9),c=i(21),l=i(20),u=i(4),d=i(89),h={a57a49b9b265421ca337219cd66a6701:"icgsfwJZDFX","67a95f560e464453be079c5723a4a85c":"icgshOaLCG5","0b58c73f12064eb897aa005cf43d6a1b":"icgs4Yuoa16","5a64ca1f742942edacd09a17e3c4a7f2":"icgsbR0xeRj",a83ce02518944076aa3a4e949acc71a2:"icgsBZbJtsl","4b286229884f4711bcdbaefdfb5f76b9":"icgs0cyLT3e","8c71d805031a41f2870aa9cd8680d579":"icgsobrRgsz",b7a77f535a774c1592a6146b03e14a7d:"icgsQMsZFS9",aff644f2b33c47fe8a557473a29ef7c1:"icgsiBVdr5P",ccfeacd9296f47f7ad3598cc5e4d0843:"icgs4eOiCOU","7c735620d8fa48329ce2d6af68abd41b":"icgsb2Y7InK",a7bca53587744b00bb76da2a7ed66e00:"icgst4qDGSv",fe1c263c41ea481ca70789783c8488ee:"icgst8DYtI6","1ff67b6ef3394024b15e38f2d0b511b9":"icgs8Cv3lIH","7f240f94172446988e8f3febdd722e04":"icgsoHk7c19","21732bba93b64203b24ea1e8b71f30e3":"icgsUEJjCU0",b038229fed814ac2b07383e281047a0a:"icgsrp4M0QN","5816516a5f6a4a628c3df602e769ced3":"icgsioLXjiC"};function f({bleDeviceId:e,arrayBuffer:t,serviceUUIDSuffix:i="fe60",characteristicUUIDSuffix:s="fe61",bleHandle:o}){let c=null,l=null;const d=()=>null===l&&(c&&clearInterval(c),!0);return new Promise((h,f)=>n(this,void 0,void 0,(function*(){try{u.default.debug("GIZ_SDK: ssid info: ",t),l=setTimeout(()=>{c&&clearInterval(c),l=null,h(!1)},5e3),u.default.debug("GIZ_SDK: createBLEConnection start: ",e),yield o.disableScan();const n=yield a.retryConnect(e,1e4);o.enableScan(),u.default.debug("GIZ_SDK: createBLEConnection end, res:",n),u.default.debug("GIZ_SDK: getBLEDeviceServices start, res:",i);const f=yield a.getBLEDeviceServices(e);u.default.debug("GIZ_SDK: getBLEDeviceServices end, res:",f);const p=f.find(e=>e.uuid.split("-")[0].toLowerCase().endsWith(i)||e.uuid.split("-")[0].toLowerCase().endsWith("abf0"));if(!p)return u.default.debug("GIZ_SDK: get ble device services fail",e,f),void h(!1);const v=yield a.getBLEDeviceCharacteristics(e,p.uuid);u.default.debug("GIZ_SDK: getBLEDeviceCharacteristics end, res:",v);const g=v.find(e=>e.uuid.split("-")[0].toLowerCase().endsWith(s)||e.uuid.split("-")[0].toLowerCase().endsWith("abf7"));if(!g)return u.default.debug("GIZ_SDK: get ble device characteristics fail",e,v),void h(!1);if(!g.properties.notify&&!g.properties.indicate)return u.default.debug("GIZ_SDK: the ble device characteristic not support notify or indicate",e,g),void h(!1);u.default.debug("GIZ_SDK: check characteristic and service success"),yield a.notifyBLECharacteristicValueChange(e,p.uuid,g.uuid);const y=e=>{const t=r.ab2hex(e.value);u.default.debug("GIZ_SDK: 收到设备返回ack",t),"0000000303000002"===t&&(o.removeEventListener("GizBleDeviceData",y),h(!0))};if(o.addEventListener("GizBleDeviceData",y),u.default.debug("GIZ_SDK: on notifyBLECharacteristicValueChange success"),d())return;yield a.unpackWriteBLECharacteristicValue(e,p.uuid,g.uuid,t),c=setInterval(()=>{d()||a.unpackWriteBLECharacteristicValue(e,p.uuid,g.uuid,t)},2e3),u.default.debug("GIZ_SDK: unpackWriteBLECharacteristicValue end")}catch(e){f(!1),u.default.debug("GIZ_SDK: sendBLEConfigCmd error",e)}}))).catch(e=>{u.default.debug("GIZ_SDK: sendBLEConfigCmd error",e)}).finally(()=>{l&&clearTimeout(l),c&&clearInterval(c),wx.closeBLEConnection({deviceId:e})})}t.sendBLEConfigCmd=f;class p extends c.default{constructor(e,t,i,c,p){super(e,t,i,c),this.lastestOnlineTimeMap={},this.destroy=()=>{this.cleanTimeout()},this.isValidBleDevice=(e,t,i)=>{if(!e||!e.advertisData)return!1;const{productKey:n,mac:s,bleWorkStatus:a}=r.advertisData2PkAndMac(e.advertisData,this.specialProductKeys);return 0!==a&&(!!this.specialProductKeys.includes(n)&&(!(i&&i.length>0&&!i.includes(n))&&(u.default.debug(`GIZ_SDK: isValidBleDevice mac: ${s} pk: ${n} name: ${e.name}`),u.default.debug(`GIZ_SDK: softAPSSIDPrefix: ${t} ismatch : ${e.name&&e.name.startsWith(t)}`),!t||e.name&&e.name.startsWith(t))))},this.enableBluetoothDevicesDescovery=()=>n(this,void 0,void 0,(function*(){return(yield a.getBluetoothAdapterState()).available?(yield a.startBluetoothDevicesDiscovery(),{success:!0}):{success:!1,err:{errorCode:s.default.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON.errorCode,errorMessage:"蓝牙状态不可用"}}})),this.enableAndGetBluetoothDevices=(e,t)=>n(this,void 0,void 0,(function*(){const i=yield this.enableBluetoothDevicesDescovery();if(!i.success)return i;u.default.debug("GIZ_SDK: start enableAndGetBluetoothDevices");const n=(yield a.getBluetoothDevices()).filter(i=>this.isValidBleDevice(i,e,t));u.default.debug("GIZ_SDK: getBluetoothDevices success",n);const s=[];return n.forEach(e=>{e&&e.advertisData&&s.push(Object.assign({},e))}),{success:!0,bleDevices:s}})),this.setDeviceOnboardingDeploy=({timeout:e,isBind:t=!0,softAPSSIDPrefix:i,productKeys:s})=>new Promise((r,a)=>n(this,void 0,void 0,(function*(){const n=this.ssid,o=this.password;this.destroy(),this.initDeviceOnboardingDeploy(r,a),this.startTimeoutTimer(e);try{const a=[(yield this.configBLEDevice({ssid:n,password:o,timeout:1e3*e,softAPSSIDPrefix:i,productKeys:s})).data];r(t?yield this.bindDevices(a):{success:!0,data:a})}catch(e){r({success:!1,data:e})}finally{this.destroy()}}))),this.getDeviceLastestOnlineTime=({productKey:e,mac:t})=>n(this,void 0,void 0,(function*(){let i=h[e];i||(i=e),u.default.debug("GIZ_SDK: getDeviceLastestOnlineTime",i,t,e);const n=yield d.default(`app/device/deviceInfo/${i}/${(null!=t?t:"").toLocaleLowerCase()}`,{method:"post"});return u.default.debug("GIZ_SDK: 请求结果",n),n})),this.verifyDeviceOnline=({productKey:e,mac:t})=>new Promise((i,s)=>{u.default.debug("GIZ_SDK: 开始确认设备上线");const r=()=>n(this,void 0,void 0,(function*(){var n,s;if(this.hasTimeoutHandler())try{yield o.default(2e3);const a=yield this.getDeviceLastestOnlineTime({productKey:e,mac:t});u.default.debug("GIZ_SDK: 确认到设备是否在线",null===(s=null===(n=a.data)||void 0===n?void 0:n.data)||void 0===s?void 0:s.onlineStatus),a.success&&a.data&&a.data.data&&1==a.data.data.onlineStatus?(u.default.debug("GIZ_SDK: 确认到设备是在线的",a),i({success:!0,data:a.data})):(u.default.debug("GIZ_SDK: 未确认到设备是在线"),yield o.default(1500),!this.disableSearchDevice&&r())}catch(e){yield o.default(3e3),!this.disableSearchDevice&&r()}}));r()}),this.configBLEDevice=({ssid:e,password:t,softAPSSIDPrefix:i,productKeys:c})=>new Promise((d,h)=>n(this,void 0,void 0,(function*(){u.default.debug("GIZ_SDK: start config ble device");const p=yield this.enableAndGetBluetoothDevices(i,c).catch(e=>({success:!1,err:{errorCode:s.default.WECHAT_ERROR.errorCode,errorMessage:JSON.stringify(e)}}));if(!r.isWXDevicesResult(p))return h(p);const{bleDevices:v}=p;u.default.debug("GIZ_SDK: enableAndGetBluetoothDevices success, target devices: ",v);const g=({devices:e})=>n(this,void 0,void 0,(function*(){this.hasTimeoutHandler()?Array.prototype.push.apply(v,e.filter(e=>this.isValidBleDevice(e,i,c))):wx.offBluetoothDeviceFound(g)}));wx.onBluetoothDeviceFound(g);const y=l.default.pack(e,t),_=v.shift(),D=e=>n(this,void 0,void 0,(function*(){if(u.default.debug("GIZ_SDK: startConfigDevice"),!this.hasTimeoutHandler())return;if(e&&u.default.debug("GIZ_SDK: startConfigDevice, target device: ",e),!(e&&(yield f({bleDeviceId:e.deviceId,arrayBuffer:y.buffer,bleHandle:this.bleHandle}))))return yield o.default(500),yield a.startBluetoothDevicesDiscovery(),void(yield D(e));u.default.debug("GIZ_SDK: offBluetoothDeviceFound ready search device"),wx.offBluetoothDeviceFound(g)})),{productKey:m,mac:b}=r.advertisData2PkAndMac((null!=_?_:{}).advertisData,this.specialProductKeys);D(_);try{yield o.default(5e3),this.verifyDeviceOnline({productKey:m,mac:b}).then(e=>{d(Object.assign(Object.assign({},e),{data:Object.assign(Object.assign({},e.data.data),{productKey:m})}))})}catch(e){h(e),u.default.error("GIZ_SDK: searchDevice error",new Error(JSON.stringify(e)))}}))),this.bleHandle=p}}t.default=p},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(18),r=i(15),a=i(5),o=i(4);t.default=(e,t,i=!0)=>n(void 0,void 0,void 0,(function*(){const n=Object.assign({},t),c={"Content-Type":"application/json","X-Gizwits-Application-Id":r.getGlobalData("appID")};i&&(c.Authorization=r.getGlobalData("token")),n.header=Object.assign(Object.assign({},c),t.headers),delete n.headers;const l=r.getGlobalData("cloudServiceInfo").aepInfo;o.default.debug("aepApiRequest",l+e);const u=yield s.default(l+e,n);if(u.statusCode>=200&&u.statusCode<300)return{success:!0,data:u.data};let d={success:!1,err:{errorCode:a.default.GIZ_SDK_HTTP_REQUEST_FAILED.errorCode,errorMessage:""}};try{d={success:!1,err:{errorCode:u.data.error_code,errorMessage:u.data.error_message}}}catch(e){}return d}))},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(12);t.AnonymousLogin=function({uid:e}){return n(this,void 0,void 0,(function*(){return s.default("/app/users",{data:{phone_id:e},method:"POST"},!1)}))}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(4),r=i(26),a=i(92),o=i(27),c=i(1),l=i(3),u=i(9),d=i(10),h=i(29);class f extends h.default{constructor({pks:e}){super(),this.connectedList=[],this.pks=[],this.scanList=[],this.deviceUDPPort=12414,this.appUDPPort=2415,this.offlineThreshold=2e4,this.isActive=!0,this.listenDevOfflineTimer=null,this.init=()=>{this.UDPSocket&&(this.UDPSocket=wx.createUDPSocket(),this.UDPSocket.bind(),this.UDPSocket.onMessage(this.onMessage),this.UDPSocket.onError(this.onError),s.default.info("Start UDP Discover"),this.startDiscover(),this.listenDevOffline(this.offlineThreshold),wx.onAppShow(this.onAppShow),wx.onAppHide(this.onAppHide))},this.onAppShow=()=>{this.isActive=!0,this.scanList.map(e=>{e.ctime=Date.now()})},this.onAppHide=()=>{this.isActive=!1},this.listenDevOffline=e=>{this.listenDevOfflineTimer=setInterval(()=>{if(!this.isActive)return;const t=(new Date).getTime(),i=this.scanList.filter(i=>t-i.ctime<e);i.length!==this.scanList.length&&(s.default.debug("remove lan device"),this.scanList=i,this.notifyDevices())},500)},this.notifyDevices=()=>{this.listenerMap.GizLanDeviceList&&this.listenerMap.GizLanDeviceList.map(e=>{e(this.scanList)})},this.notifyDeviceData=(e,t)=>{this.listenerMap.GizLanDeviceData&&this.listenerMap.GizLanDeviceData.map(i=>{i(e,t)})},this.isSameDevice=(e,t)=>e.mac===t.mac&&e.productKey===t.productKey,this.disConnectDevice=e=>{const t=this.connectedList.findIndex(t=>t.productKey===e.productKey&&t.mac===e.mac);try{return-1!==t&&(this.connectedList[t].socketHandle.destory(),this.connectedList.splice(t,1)),{success:!0}}catch(e){return{success:!1,err:e}}},this.onData=(e,t)=>{this.notifyDeviceData(e,t)},this.connectDevice=e=>n(this,void 0,void 0,(function*(){const t=this.scanList.find(t=>this.isSameDevice(e,t));if(!t)return{success:!1};if(this.connectedList.find(t=>this.isSameDevice(e,t)))return{success:!0};{const e=new p({ip:t.ip,mac:t.mac,productKey:t.productKey,onClose:this.onDeviceClose,onData:this.onData}),i=yield e.connect();return i.success?this.connectedList.push({mac:t.mac,productKey:t.productKey,socketHandle:e}):e.destory(),i}})),this.onError=e=>{s.default.warn("Discover Error",e)},this.isMatchPk=e=>0===this.pks.length||this.pks.includes(e),this.onMessage=e=>{const t=d.ab2numbers(e.message),i=new a.default(t);""!==i.mac&&this.isMatchPk(i.productKey)&&this.updateDevice(i,e.remoteInfo.address)},this.onDeviceClose=({productKey:e,mac:t})=>{const i=this.connectedList.findIndex(i=>i.productKey===e&&i.mac===t);-1!==i&&this.connectedList.splice(i,1)},this.write=(e,t)=>n(this,void 0,void 0,(function*(){s.default.debug("send data to device",e,t,this.connectedList);const i=this.connectedList.findIndex(t=>this.isSameDevice(t,e));if(-1!==i){return this.connectedList[i].socketHandle.write(t)}return{success:!1,message:"device not sub"}})),this.updateDevice=(e,t)=>{const i=this.scanList.find(t=>t.mac===e.mac);if(i)i.ctime=Date.now();else{const i={mac:e.mac,ip:t,productKey:e.productKey,did:e.did,expandData:e,name:"",isBind:!1,connectType:"NONE",isOnline:!1,isLanOnline:!0,isBleOnline:!1,ctime:Date.now()};this.scanList.push(i),this.notifyDevices()}},this.sendBoradCast=()=>{this.UDPSocket&&(this.UDPSocket.send({address:"255.255.255.255",message:a.default.pack(),port:this.deviceUDPPort}),s.default.debug("Send UDP Discover"))},this.startDiscover=()=>{this.sendBoradCast(),this.boradcastTimer=setInterval(()=>{this.sendBoradCast()},5e3)},this.destory=()=>{this.boradcastTimer&&clearInterval(this.boradcastTimer),this.UDPSocket&&this.UDPSocket.close(),this.listenDevOfflineTimer&&clearInterval(this.listenDevOfflineTimer),wx.offAppShow(this.onAppShow),wx.offAppHide(this.onAppHide)},this.pks=e}}t.LanHandle=f;class p{constructor({ip:e,onClose:t,mac:i,productKey:a,onData:h}){this.deviceTCPPort=12416,this.ip="",this.productKey="",this.mac="",this.tcpHandler=null,this.onData=(e,t)=>{},this.onCloseListener=({mac:e,productKey:t})=>{},this.connect=()=>n(this,void 0,void 0,(function*(){return new Promise(e=>n(this,void 0,void 0,(function*(){const t=()=>{const e=r.default.pack();this.tcpHandler.write(l.arrayToUint8(e)),s.default.debug("connect success try login")},i=t=>{e({success:!0,err:t})},n=t=>{switch(new c.default(d.ab2numbers(t.message)).cmd){case"0007":{const e=new r.default(d.ab2numbers(t.message)),i=o.default.pack({passcode:e.passcode});this.tcpHandler.write(l.arrayToUint8(i));break}case"0009":new o.default(d.ab2numbers(t.message)).result?(e({success:!0}),this.initListener()):e({success:!1})}};try{this.tcpHandler=wx.createTCPSocket(),this.tcpHandler.onConnect(t),this.tcpHandler.onError(i),this.tcpHandler.onMessage(n),this.tcpHandler.connect({address:this.ip,port:this.deviceTCPPort,timeout:2}),yield u.default(4e3),e({success:!1,err:null})}catch(t){s.default.error("connect lan error",t),e({success:!1,err:null})}finally{this.tcpHandler.offConnect(t),this.tcpHandler.offError(i),this.tcpHandler.offMessage(n)}})))})),this.write=e=>(this.tcpHandler.write(e),{success:!0}),this.onMessage=e=>{try{const t=d.ab2hex(e.message),i=new c.default(l.hexStrint2byte(t));s.default.debug("on tcp message",i),this.onData(this.mac,t)}catch(e){}},this.onError=()=>{},this.onClose=()=>{this.onCloseListener({productKey:this.productKey,mac:this.mac})},this.initListener=()=>{this.tcpHandler.onError(this.onError),this.tcpHandler.onMessage(this.onMessage),this.tcpHandler.onClose(this.onClose)},this.destory=()=>{this.tcpHandler&&this.tcpHandler.close(),this.tcpHandler.offError(this.onError),this.tcpHandler.offMessage(this.onMessage),this.tcpHandler.offClose(this.onClose)},this.ip=e,this.mac=i,this.productKey=a,this.onData=h,this.onCloseListener=t}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(4),s=i(1),r=i(3);class a extends s.default{constructor(e){super(e),this.did="",this.mac="",this.productKey="",this.deviceType=0,this.apiUrl="",this.protocolVersion="",this.mcuVersion="",this.moduleVersion="",this.parseEndChat=(e,t)=>{let i="";const n=this.content.slice(e,this.content.length);for(let t in n){const s=n[t];if(e+=1,0===s)break;i+=String.fromCharCode(s)}return this[t]=i,e},this.baseParse=(e,t,i="ASCII")=>{const n=parseInt(r.arrayToString(this.content.slice(e,e+2)),16);e+=2;let s="";return this.content.slice(e,e+n).map(e=>{if("ASCII"===i)s+=String.fromCharCode(e);else{const t=e.toString(16);s+=r.fillString(t,2)}}),this[t]=s,e+n};let t=0;try{t=this.baseParse(t,"did"),t=this.baseParse(t,"mac","HEX"),t=this.baseParse(t,"moduleVersion"),t=this.baseParse(t,"productKey"),t+=8,t=this.parseEndChat(t,"apiUrl"),t=this.parseEndChat(t,"protocolVersion"),this.mcuVersion="",this.content.slice(t,this.content.length).map(e=>{this.mcuVersion+=String.fromCharCode(e)})}catch(e){n.default.warn("Parse DiscoverUDP error",e)}}}a.pack=()=>{const e=[0,0,0,3,3,0,0,3],t=new ArrayBuffer(e.length),i=new Uint8Array(t);for(let n=0;n<t.byteLength;n++)i[n]=e[n];return i},t.default=a},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(1),s=i(3);class r extends n.default{constructor(e){super(e),this.state=0,this.len=0;let t=0;this.len=parseInt(s.arrayToString(this.content.slice(t,t+2)),16),t+=2,this.state=this.content[t]}}t.RequestSync=r,r.pack=()=>[0,0,0,3,3,0,0,81];class a extends n.default{constructor(e){super(e),this.id=0,this.timestemp=0,this.payloadLen=0,this.payload=[];let t=0;this.id=parseInt(s.arrayToString(this.content.slice(t,t+2)),16),t+=2,this.timestemp=parseInt(s.arrayToString(this.content.slice(t,t+5)),16),t+=5,this.payloadLen=parseInt(s.arrayToString(this.content.slice(t,t+2)),16),t+=2,this.payload=this.content.slice(t,this.content.length)}}t.SyncPackage=a,a.pack=e=>{let t=e.toString(2);return t=s.fillString(t,16),[0,0,0,3,5].concat([0,0,83]).concat(s.completeBlock(t))};class o extends n.default{}t.DeletePackage=o,o.pack=e=>{let t=e.toString(2);return t=s.fillString(t,16),[0,0,0,3,5].concat([0,0,85]).concat(s.completeBlock(t))};class c extends n.default{constructor(e){super(e),this.state=0,this.state=this.content[0]}}t.CancelSync=c,c.pack=()=>[0,0,0,3,3,0,0,87]},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(12),r=i(11);t.uploadP0=function({device:e,data:t,productSecret:i}){return n(this,void 0,void 0,(function*(){const n=`/v2/products/${e.productKey}/devices/offline-data`;let a=e.passcode;const o=r.enc.Hex.parse(i),c=r.enc.Hex.parse(""),l=r.enc.Utf8.parse(a);return a=r.AES.encrypt(l,o,{iv:c,mode:r.mode.ECB,padding:r.pad.Pkcs7}).ciphertext.toString().toUpperCase(),s.default(n,{data:{data:t,encoding:"hex"},method:"POST",headers:{"X-Gizwits-Device-Id":e.did,"X-Gizwits-Device-passcode":a}},!1)}))}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(1),s=i(3);class r extends n.default{}r.pack=()=>{const e=parseInt(`${Date.now()/1e3}`,10),t=s.fillString(e.toString(2),40);return[0,0,0,3,8,0,0,89].concat(s.completeBlock(t))},t.default=r},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(1);class s extends n.default{constructor(e){super(e),this.status=0,this.status=this.content[0]}}s.pack=()=>[0,0,0,3,3,0,0,97],t.default=s},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(1);class s extends n.default{constructor(){super(...arguments),this.status=0}}s.pack=e=>[0,0,0,3,3,0,0,99,e],t.default=s}]);
|
|
25
|
+
var n=i(75),s=i(76),r=i(77);function a(){return c.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function o(e,t){if(a()<t)throw new RangeError("Invalid typed array length");return c.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=c.prototype:(null===e&&(e=new c(t)),e.length=t),e}function c(e,t,i){if(!(c.TYPED_ARRAY_SUPPORT||this instanceof c))return new c(e,t,i);if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return d(this,e)}return l(this,e,t,i)}function l(e,t,i,n){if("number"==typeof t)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer?function(e,t,i,n){if(t.byteLength,i<0||t.byteLength<i)throw new RangeError("'offset' is out of bounds");if(t.byteLength<i+(n||0))throw new RangeError("'length' is out of bounds");t=void 0===i&&void 0===n?new Uint8Array(t):void 0===n?new Uint8Array(t,i):new Uint8Array(t,i,n);c.TYPED_ARRAY_SUPPORT?(e=t).__proto__=c.prototype:e=h(e,t);return e}(e,t,i,n):"string"==typeof t?function(e,t,i){"string"==typeof i&&""!==i||(i="utf8");if(!c.isEncoding(i))throw new TypeError('"encoding" must be a valid string encoding');var n=0|p(t,i),s=(e=o(e,n)).write(t,i);s!==n&&(e=e.slice(0,s));return e}(e,t,i):function(e,t){if(c.isBuffer(t)){var i=0|f(t.length);return 0===(e=o(e,i)).length||t.copy(e,0,0,i),e}if(t){if("undefined"!=typeof ArrayBuffer&&t.buffer instanceof ArrayBuffer||"length"in t)return"number"!=typeof t.length||(n=t.length)!=n?o(e,0):h(e,t);if("Buffer"===t.type&&r(t.data))return h(e,t.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function u(e){if("number"!=typeof e)throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function d(e,t){if(u(t),e=o(e,t<0?0:0|f(t)),!c.TYPED_ARRAY_SUPPORT)for(var i=0;i<t;++i)e[i]=0;return e}function h(e,t){var i=t.length<0?0:0|f(t.length);e=o(e,i);for(var n=0;n<i;n+=1)e[n]=255&t[n];return e}function f(e){if(e>=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|e}function p(e,t){if(c.isBuffer(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var i=e.length;if(0===i)return 0;for(var n=!1;;)switch(t){case"ascii":case"latin1":case"binary":return i;case"utf8":case"utf-8":case void 0:return U(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*i;case"hex":return i>>>1;case"base64":return G(e).length;default:if(n)return U(e).length;t=(""+t).toLowerCase(),n=!0}}function v(e,t,i){var n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return"";if((i>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return E(this,t,i);case"utf8":case"utf-8":return A(this,t,i);case"ascii":return k(this,t,i);case"latin1":case"binary":return C(this,t,i);case"base64":return B(this,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,t,i);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function g(e,t,i){var n=e[t];e[t]=e[i],e[i]=n}function y(e,t,i,n,s){if(0===e.length)return-1;if("string"==typeof i?(n=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),i=+i,isNaN(i)&&(i=s?0:e.length-1),i<0&&(i=e.length+i),i>=e.length){if(s)return-1;i=e.length-1}else if(i<0){if(!s)return-1;i=0}if("string"==typeof t&&(t=c.from(t,n)),c.isBuffer(t))return 0===t.length?-1:D(e,t,i,n,s);if("number"==typeof t)return t&=255,c.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?s?Uint8Array.prototype.indexOf.call(e,t,i):Uint8Array.prototype.lastIndexOf.call(e,t,i):D(e,[t],i,n,s);throw new TypeError("val must be string, number or Buffer")}function D(e,t,i,n,s){var r,a=1,o=e.length,c=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;a=2,o/=2,c/=2,i/=2}function l(e,t){return 1===a?e[t]:e.readUInt16BE(t*a)}if(s){var u=-1;for(r=i;r<o;r++)if(l(e,r)===l(t,-1===u?0:r-u)){if(-1===u&&(u=r),r-u+1===c)return u*a}else-1!==u&&(r-=r-u),u=-1}else for(i+c>o&&(i=o-c),r=i;r>=0;r--){for(var d=!0,h=0;h<c;h++)if(l(e,r+h)!==l(t,h)){d=!1;break}if(d)return r}return-1}function _(e,t,i,n){i=Number(i)||0;var s=e.length-i;n?(n=Number(n))>s&&(n=s):n=s;var r=t.length;if(r%2!=0)throw new TypeError("Invalid hex string");n>r/2&&(n=r/2);for(var a=0;a<n;++a){var o=parseInt(t.substr(2*a,2),16);if(isNaN(o))return a;e[i+a]=o}return a}function m(e,t,i,n){return j(U(t,e.length-i),e,i,n)}function b(e,t,i,n){return j(function(e){for(var t=[],i=0;i<e.length;++i)t.push(255&e.charCodeAt(i));return t}(t),e,i,n)}function S(e,t,i,n){return b(e,t,i,n)}function w(e,t,i,n){return j(G(t),e,i,n)}function I(e,t,i,n){return j(function(e,t){for(var i,n,s,r=[],a=0;a<e.length&&!((t-=2)<0);++a)i=e.charCodeAt(a),n=i>>8,s=i%256,r.push(s),r.push(n);return r}(t,e.length-i),e,i,n)}function B(e,t,i){return 0===t&&i===e.length?n.fromByteArray(e):n.fromByteArray(e.slice(t,i))}function A(e,t,i){i=Math.min(e.length,i);for(var n=[],s=t;s<i;){var r,a,o,c,l=e[s],u=null,d=l>239?4:l>223?3:l>191?2:1;if(s+d<=i)switch(d){case 1:l<128&&(u=l);break;case 2:128==(192&(r=e[s+1]))&&(c=(31&l)<<6|63&r)>127&&(u=c);break;case 3:r=e[s+1],a=e[s+2],128==(192&r)&&128==(192&a)&&(c=(15&l)<<12|(63&r)<<6|63&a)>2047&&(c<55296||c>57343)&&(u=c);break;case 4:r=e[s+1],a=e[s+2],o=e[s+3],128==(192&r)&&128==(192&a)&&128==(192&o)&&(c=(15&l)<<18|(63&r)<<12|(63&a)<<6|63&o)>65535&&c<1114112&&(u=c)}null===u?(u=65533,d=1):u>65535&&(u-=65536,n.push(u>>>10&1023|55296),u=56320|1023&u),n.push(u),s+=d}return function(e){var t=e.length;if(t<=4096)return String.fromCharCode.apply(String,e);var i="",n=0;for(;n<t;)i+=String.fromCharCode.apply(String,e.slice(n,n+=4096));return i}(n)}t.Buffer=c,t.SlowBuffer=function(e){+e!=e&&(e=0);return c.alloc(+e)},t.INSPECT_MAX_BYTES=50,c.TYPED_ARRAY_SUPPORT=void 0!==e.TYPED_ARRAY_SUPPORT?e.TYPED_ARRAY_SUPPORT:function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()&&"function"==typeof e.subarray&&0===e.subarray(1,1).byteLength}catch(e){return!1}}(),t.kMaxLength=a(),c.poolSize=8192,c._augment=function(e){return e.__proto__=c.prototype,e},c.from=function(e,t,i){return l(null,e,t,i)},c.TYPED_ARRAY_SUPPORT&&(c.prototype.__proto__=Uint8Array.prototype,c.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&c[Symbol.species]===c&&Object.defineProperty(c,Symbol.species,{value:null,configurable:!0})),c.alloc=function(e,t,i){return function(e,t,i,n){return u(t),t<=0?o(e,t):void 0!==i?"string"==typeof n?o(e,t).fill(i,n):o(e,t).fill(i):o(e,t)}(null,e,t,i)},c.allocUnsafe=function(e){return d(null,e)},c.allocUnsafeSlow=function(e){return d(null,e)},c.isBuffer=function(e){return!(null==e||!e._isBuffer)},c.compare=function(e,t){if(!c.isBuffer(e)||!c.isBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var i=e.length,n=t.length,s=0,r=Math.min(i,n);s<r;++s)if(e[s]!==t[s]){i=e[s],n=t[s];break}return i<n?-1:n<i?1:0},c.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},c.concat=function(e,t){if(!r(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return c.alloc(0);var i;if(void 0===t)for(t=0,i=0;i<e.length;++i)t+=e[i].length;var n=c.allocUnsafe(t),s=0;for(i=0;i<e.length;++i){var a=e[i];if(!c.isBuffer(a))throw new TypeError('"list" argument must be an Array of Buffers');a.copy(n,s),s+=a.length}return n},c.byteLength=p,c.prototype._isBuffer=!0,c.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)g(this,t,t+1);return this},c.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)g(this,t,t+3),g(this,t+1,t+2);return this},c.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)g(this,t,t+7),g(this,t+1,t+6),g(this,t+2,t+5),g(this,t+3,t+4);return this},c.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?A(this,0,e):v.apply(this,arguments)},c.prototype.equals=function(e){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===c.compare(this,e)},c.prototype.inspect=function(){var e="",i=t.INSPECT_MAX_BYTES;return this.length>0&&(e=this.toString("hex",0,i).match(/.{2}/g).join(" "),this.length>i&&(e+=" ... ")),"<Buffer "+e+">"},c.prototype.compare=function(e,t,i,n,s){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===i&&(i=e?e.length:0),void 0===n&&(n=0),void 0===s&&(s=this.length),t<0||i>e.length||n<0||s>this.length)throw new RangeError("out of range index");if(n>=s&&t>=i)return 0;if(n>=s)return-1;if(t>=i)return 1;if(this===e)return 0;for(var r=(s>>>=0)-(n>>>=0),a=(i>>>=0)-(t>>>=0),o=Math.min(r,a),l=this.slice(n,s),u=e.slice(t,i),d=0;d<o;++d)if(l[d]!==u[d]){r=l[d],a=u[d];break}return r<a?-1:a<r?1:0},c.prototype.includes=function(e,t,i){return-1!==this.indexOf(e,t,i)},c.prototype.indexOf=function(e,t,i){return y(this,e,t,i,!0)},c.prototype.lastIndexOf=function(e,t,i){return y(this,e,t,i,!1)},c.prototype.write=function(e,t,i,n){if(void 0===t)n="utf8",i=this.length,t=0;else if(void 0===i&&"string"==typeof t)n=t,i=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t|=0,isFinite(i)?(i|=0,void 0===n&&(n="utf8")):(n=i,i=void 0)}var s=this.length-t;if((void 0===i||i>s)&&(i=s),e.length>0&&(i<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var r=!1;;)switch(n){case"hex":return _(this,e,t,i);case"utf8":case"utf-8":return m(this,e,t,i);case"ascii":return b(this,e,t,i);case"latin1":case"binary":return S(this,e,t,i);case"base64":return w(this,e,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return I(this,e,t,i);default:if(r)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),r=!0}},c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function k(e,t,i){var n="";i=Math.min(e.length,i);for(var s=t;s<i;++s)n+=String.fromCharCode(127&e[s]);return n}function C(e,t,i){var n="";i=Math.min(e.length,i);for(var s=t;s<i;++s)n+=String.fromCharCode(e[s]);return n}function E(e,t,i){var n=e.length;(!t||t<0)&&(t=0),(!i||i<0||i>n)&&(i=n);for(var s="",r=t;r<i;++r)s+=N(e[r]);return s}function T(e,t,i){for(var n=e.slice(t,i),s="",r=0;r<n.length;r+=2)s+=String.fromCharCode(n[r]+256*n[r+1]);return s}function P(e,t,i){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>i)throw new RangeError("Trying to access beyond buffer length")}function O(e,t,i,n,s,r){if(!c.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>s||t<r)throw new RangeError('"value" argument is out of bounds');if(i+n>e.length)throw new RangeError("Index out of range")}function L(e,t,i,n){t<0&&(t=65535+t+1);for(var s=0,r=Math.min(e.length-i,2);s<r;++s)e[i+s]=(t&255<<8*(n?s:1-s))>>>8*(n?s:1-s)}function x(e,t,i,n){t<0&&(t=4294967295+t+1);for(var s=0,r=Math.min(e.length-i,4);s<r;++s)e[i+s]=t>>>8*(n?s:3-s)&255}function M(e,t,i,n,s,r){if(i+n>e.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function K(e,t,i,n,r){return r||M(e,0,i,4),s.write(e,t,i,n,23,4),i+4}function H(e,t,i,n,r){return r||M(e,0,i,8),s.write(e,t,i,n,52,8),i+8}c.prototype.slice=function(e,t){var i,n=this.length;if((e=~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),(t=void 0===t?n:~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),t<e&&(t=e),c.TYPED_ARRAY_SUPPORT)(i=this.subarray(e,t)).__proto__=c.prototype;else{var s=t-e;i=new c(s,void 0);for(var r=0;r<s;++r)i[r]=this[r+e]}return i},c.prototype.readUIntLE=function(e,t,i){e|=0,t|=0,i||P(e,t,this.length);for(var n=this[e],s=1,r=0;++r<t&&(s*=256);)n+=this[e+r]*s;return n},c.prototype.readUIntBE=function(e,t,i){e|=0,t|=0,i||P(e,t,this.length);for(var n=this[e+--t],s=1;t>0&&(s*=256);)n+=this[e+--t]*s;return n},c.prototype.readUInt8=function(e,t){return t||P(e,1,this.length),this[e]},c.prototype.readUInt16LE=function(e,t){return t||P(e,2,this.length),this[e]|this[e+1]<<8},c.prototype.readUInt16BE=function(e,t){return t||P(e,2,this.length),this[e]<<8|this[e+1]},c.prototype.readUInt32LE=function(e,t){return t||P(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},c.prototype.readUInt32BE=function(e,t){return t||P(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},c.prototype.readIntLE=function(e,t,i){e|=0,t|=0,i||P(e,t,this.length);for(var n=this[e],s=1,r=0;++r<t&&(s*=256);)n+=this[e+r]*s;return n>=(s*=128)&&(n-=Math.pow(2,8*t)),n},c.prototype.readIntBE=function(e,t,i){e|=0,t|=0,i||P(e,t,this.length);for(var n=t,s=1,r=this[e+--n];n>0&&(s*=256);)r+=this[e+--n]*s;return r>=(s*=128)&&(r-=Math.pow(2,8*t)),r},c.prototype.readInt8=function(e,t){return t||P(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},c.prototype.readInt16LE=function(e,t){t||P(e,2,this.length);var i=this[e]|this[e+1]<<8;return 32768&i?4294901760|i:i},c.prototype.readInt16BE=function(e,t){t||P(e,2,this.length);var i=this[e+1]|this[e]<<8;return 32768&i?4294901760|i:i},c.prototype.readInt32LE=function(e,t){return t||P(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},c.prototype.readInt32BE=function(e,t){return t||P(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},c.prototype.readFloatLE=function(e,t){return t||P(e,4,this.length),s.read(this,e,!0,23,4)},c.prototype.readFloatBE=function(e,t){return t||P(e,4,this.length),s.read(this,e,!1,23,4)},c.prototype.readDoubleLE=function(e,t){return t||P(e,8,this.length),s.read(this,e,!0,52,8)},c.prototype.readDoubleBE=function(e,t){return t||P(e,8,this.length),s.read(this,e,!1,52,8)},c.prototype.writeUIntLE=function(e,t,i,n){(e=+e,t|=0,i|=0,n)||O(this,e,t,i,Math.pow(2,8*i)-1,0);var s=1,r=0;for(this[t]=255&e;++r<i&&(s*=256);)this[t+r]=e/s&255;return t+i},c.prototype.writeUIntBE=function(e,t,i,n){(e=+e,t|=0,i|=0,n)||O(this,e,t,i,Math.pow(2,8*i)-1,0);var s=i-1,r=1;for(this[t+s]=255&e;--s>=0&&(r*=256);)this[t+s]=e/r&255;return t+i},c.prototype.writeUInt8=function(e,t,i){return e=+e,t|=0,i||O(this,e,t,1,255,0),c.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},c.prototype.writeUInt16LE=function(e,t,i){return e=+e,t|=0,i||O(this,e,t,2,65535,0),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):L(this,e,t,!0),t+2},c.prototype.writeUInt16BE=function(e,t,i){return e=+e,t|=0,i||O(this,e,t,2,65535,0),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):L(this,e,t,!1),t+2},c.prototype.writeUInt32LE=function(e,t,i){return e=+e,t|=0,i||O(this,e,t,4,4294967295,0),c.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):x(this,e,t,!0),t+4},c.prototype.writeUInt32BE=function(e,t,i){return e=+e,t|=0,i||O(this,e,t,4,4294967295,0),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):x(this,e,t,!1),t+4},c.prototype.writeIntLE=function(e,t,i,n){if(e=+e,t|=0,!n){var s=Math.pow(2,8*i-1);O(this,e,t,i,s-1,-s)}var r=0,a=1,o=0;for(this[t]=255&e;++r<i&&(a*=256);)e<0&&0===o&&0!==this[t+r-1]&&(o=1),this[t+r]=(e/a>>0)-o&255;return t+i},c.prototype.writeIntBE=function(e,t,i,n){if(e=+e,t|=0,!n){var s=Math.pow(2,8*i-1);O(this,e,t,i,s-1,-s)}var r=i-1,a=1,o=0;for(this[t+r]=255&e;--r>=0&&(a*=256);)e<0&&0===o&&0!==this[t+r+1]&&(o=1),this[t+r]=(e/a>>0)-o&255;return t+i},c.prototype.writeInt8=function(e,t,i){return e=+e,t|=0,i||O(this,e,t,1,127,-128),c.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},c.prototype.writeInt16LE=function(e,t,i){return e=+e,t|=0,i||O(this,e,t,2,32767,-32768),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):L(this,e,t,!0),t+2},c.prototype.writeInt16BE=function(e,t,i){return e=+e,t|=0,i||O(this,e,t,2,32767,-32768),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):L(this,e,t,!1),t+2},c.prototype.writeInt32LE=function(e,t,i){return e=+e,t|=0,i||O(this,e,t,4,2147483647,-2147483648),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):x(this,e,t,!0),t+4},c.prototype.writeInt32BE=function(e,t,i){return e=+e,t|=0,i||O(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):x(this,e,t,!1),t+4},c.prototype.writeFloatLE=function(e,t,i){return K(this,e,t,!0,i)},c.prototype.writeFloatBE=function(e,t,i){return K(this,e,t,!1,i)},c.prototype.writeDoubleLE=function(e,t,i){return H(this,e,t,!0,i)},c.prototype.writeDoubleBE=function(e,t,i){return H(this,e,t,!1,i)},c.prototype.copy=function(e,t,i,n){if(i||(i=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<i&&(n=i),n===i)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(i<0||i>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-i&&(n=e.length-t+i);var s,r=n-i;if(this===e&&i<t&&t<n)for(s=r-1;s>=0;--s)e[s+t]=this[s+i];else if(r<1e3||!c.TYPED_ARRAY_SUPPORT)for(s=0;s<r;++s)e[s+t]=this[s+i];else Uint8Array.prototype.set.call(e,this.subarray(i,i+r),t);return r},c.prototype.fill=function(e,t,i,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=0,i=this.length):"string"==typeof i&&(n=i,i=this.length),1===e.length){var s=e.charCodeAt(0);s<256&&(e=s)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!c.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<i)throw new RangeError("Out of range index");if(i<=t)return this;var r;if(t>>>=0,i=void 0===i?this.length:i>>>0,e||(e=0),"number"==typeof e)for(r=t;r<i;++r)this[r]=e;else{var a=c.isBuffer(e)?e:U(new c(e,n).toString()),o=a.length;for(r=0;r<i-t;++r)this[r+t]=a[r%o]}return this};var R=/[^+\/0-9A-Za-z-_]/g;function N(e){return e<16?"0"+e.toString(16):e.toString(16)}function U(e,t){var i;t=t||1/0;for(var n=e.length,s=null,r=[],a=0;a<n;++a){if((i=e.charCodeAt(a))>55295&&i<57344){if(!s){if(i>56319){(t-=3)>-1&&r.push(239,191,189);continue}if(a+1===n){(t-=3)>-1&&r.push(239,191,189);continue}s=i;continue}if(i<56320){(t-=3)>-1&&r.push(239,191,189),s=i;continue}i=65536+(s-55296<<10|i-56320)}else s&&(t-=3)>-1&&r.push(239,191,189);if(s=null,i<128){if((t-=1)<0)break;r.push(i)}else if(i<2048){if((t-=2)<0)break;r.push(i>>6|192,63&i|128)}else if(i<65536){if((t-=3)<0)break;r.push(i>>12|224,i>>6&63|128,63&i|128)}else{if(!(i<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;r.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128)}}return r}function G(e){return n.toByteArray(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(R,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function j(e,t,i,n){for(var s=0;s<n&&!(s+i>=t.length||s>=e.length);++s)t[s+i]=e[s];return s}}).call(this,i(23))},function(e,t,i){"use strict";t.byteLength=function(e){var t=l(e),i=t[0],n=t[1];return 3*(i+n)/4-n},t.toByteArray=function(e){var t,i,n=l(e),a=n[0],o=n[1],c=new r(function(e,t,i){return 3*(t+i)/4-i}(0,a,o)),u=0,d=o>0?a-4:a;for(i=0;i<d;i+=4)t=s[e.charCodeAt(i)]<<18|s[e.charCodeAt(i+1)]<<12|s[e.charCodeAt(i+2)]<<6|s[e.charCodeAt(i+3)],c[u++]=t>>16&255,c[u++]=t>>8&255,c[u++]=255&t;2===o&&(t=s[e.charCodeAt(i)]<<2|s[e.charCodeAt(i+1)]>>4,c[u++]=255&t);1===o&&(t=s[e.charCodeAt(i)]<<10|s[e.charCodeAt(i+1)]<<4|s[e.charCodeAt(i+2)]>>2,c[u++]=t>>8&255,c[u++]=255&t);return c},t.fromByteArray=function(e){for(var t,i=e.length,s=i%3,r=[],a=0,o=i-s;a<o;a+=16383)r.push(u(e,a,a+16383>o?o:a+16383));1===s?(t=e[i-1],r.push(n[t>>2]+n[t<<4&63]+"==")):2===s&&(t=(e[i-2]<<8)+e[i-1],r.push(n[t>>10]+n[t>>4&63]+n[t<<2&63]+"="));return r.join("")};for(var n=[],s=[],r="undefined"!=typeof Uint8Array?Uint8Array:Array,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0,c=a.length;o<c;++o)n[o]=a[o],s[a.charCodeAt(o)]=o;function l(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var i=e.indexOf("=");return-1===i&&(i=t),[i,i===t?0:4-i%4]}function u(e,t,i){for(var s,r,a=[],o=t;o<i;o+=3)s=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(255&e[o+2]),a.push(n[(r=s)>>18&63]+n[r>>12&63]+n[r>>6&63]+n[63&r]);return a.join("")}s["-".charCodeAt(0)]=62,s["_".charCodeAt(0)]=63},function(e,t){t.read=function(e,t,i,n,s){var r,a,o=8*s-n-1,c=(1<<o)-1,l=c>>1,u=-7,d=i?s-1:0,h=i?-1:1,f=e[t+d];for(d+=h,r=f&(1<<-u)-1,f>>=-u,u+=o;u>0;r=256*r+e[t+d],d+=h,u-=8);for(a=r&(1<<-u)-1,r>>=-u,u+=n;u>0;a=256*a+e[t+d],d+=h,u-=8);if(0===r)r=1-l;else{if(r===c)return a?NaN:1/0*(f?-1:1);a+=Math.pow(2,n),r-=l}return(f?-1:1)*a*Math.pow(2,r-n)},t.write=function(e,t,i,n,s,r){var a,o,c,l=8*r-s-1,u=(1<<l)-1,d=u>>1,h=23===s?Math.pow(2,-24)-Math.pow(2,-77):0,f=n?0:r-1,p=n?1:-1,v=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(o=isNaN(t)?1:0,a=u):(a=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-a))<1&&(a--,c*=2),(t+=a+d>=1?h/c:h*Math.pow(2,1-d))*c>=2&&(a++,c/=2),a+d>=u?(o=0,a=u):a+d>=1?(o=(t*c-1)*Math.pow(2,s),a+=d):(o=t*Math.pow(2,d-1)*Math.pow(2,s),a=0));s>=8;e[i+f]=255&o,f+=p,o/=256,s-=8);for(a=a<<s|o,l+=s;l>0;e[i+f]=255&a,f+=p,a/=256,l-=8);e[i+f-p]|=128*v}},function(e,t){var i={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==i.call(e)}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(79),s=i(32);t.default=s.default("crc-32",n.default)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});let n=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117];"undefined"!=typeof Int32Array&&(n=new Int32Array(n));t.default=(e,t)=>{let i=0===t?0:-1^~~t;for(let t=0;t<e.length;t++)i=n[255&(i^e[t])]^i>>>8;return-1^i}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(1),s=i(3);class r extends n.default{constructor(e){super(e)}}r.pack=e=>[0,0,0,3,7,0,0,69,...s.hexStrint2byte(s.fillString(e.toString(16),8))],t.default=r},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(31),s=i(30),r=i(1),a=i(3);class o extends r.default{constructor(e){super(e),this.packageNum=0,this.state=0;let t=0;this.packageNum=a.bytesToInt(this.content.slice(t,t+2)),t+=2,this.state=this.content[t]}}o.pack=(e,t)=>{const i=a.hexStrint2byte(a.fillString(t.toString(16),4)),r=a.hexStrint2byte(a.fillString(e.length.toString(16),4)),o=a.fillString(n.crc16modbus(new Uint8Array(e)).toString(16),4),c=a.hexStrint2byte(o);let l=[0];l=l.concat([0,71],i,r,c,e);const u=s.getVariableLength(l);return[0,0,0,3].concat(u,l)},t.default=o},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(1);class s extends n.default{constructor(e){super(e),this.state=0;this.state=this.content[0]}}s.pack=e=>[0,0,0,3,4,0,0,80,e],t.default=s},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(5),r=i(4),a=i(12),o=i(10);t.default=class{constructor({appID:e,token:t,uid:i,limitSocketNum:r=!0}){this._bindingDevices=null,this._connections={},this.updateToken=({token:e,uid:t})=>{this.token=e,this.uid=t},this._getDevice=e=>{if(null===this._bindingDevices)return s.default.GIZ_SDK_SDK_NOT_INITIALIZED;const t=this._bindingDevices[e];return null==t?s.default.GIZ_OPENAPI_DEVICE_NOT_BOUND:t},this._getConnect=e=>{const t=this._getWebsocketConnInfo(e);return this._connections[t]},this._getDeviceAndConnect=e=>{const t=this._getDevice(e);if(o.isError(t))return t;const i=this._getConnect(t);return null==i?s.default.GIZ_SDK_DEVICE_NOT_SUBSCRIBED:[t,i]},this.connectDevice=e=>{const t=this._getWebsocketConnInfo(e);let i=this._connections[t];if(null==i){const e=Object.keys(this._connections).length;if(0!==this._maxSocketNum&&e>=this._maxSocketNum)return{success:!1,errorCode:s.default.MAX_CONNECT};i=new c({appID:this.appID,token:this.token,uid:this.uid,wsInfo:t,onDeviceStatusChanged:this._handleDeviceStatusChanged,onBindingChanged:this._handleBindingChanged,onSocketStatusChanged:this._handleSocketStatusChanged}),this._connections[t]=i}return i._addSubDid(e.did),null==i._websocket?i._connectWS():i.ready&&i._subDevices([e.did]),{success:!0}},this.disConnectDevice=e=>{const t=this._getWebsocketConnInfo(e);let i=this._connections[t];return i&&i._unSubDevices([e.did]),{success:!0}},this.connect=e=>{const t=this._getDevice(e);if(o.isError(t))return t;const i=this.connectDevice(t);return i.success?null:i.errorCode},this.send=(e,t)=>{const i=this._getDeviceAndConnect(e);return o.isError(i)?i:i[1]._send({cmd:"c2s_raw",data:{did:e,raw:t}})},this.writeData=(e,t)=>{const i=this._getConnect(e);return null!=i?i._send({cmd:"c2s_write",data:{did:e.did,attrs:t}}):{success:!1}},this.write=(e,t)=>{const i=this._getDeviceAndConnect(e);return o.isError(i)?i:i[1]._send({cmd:"c2s_write",data:{did:e,attrs:t}})},this.readStatus=(e,t)=>{const i=this._getConnect(e),n=null!=i;return n&&i._send({cmd:"c2s_read",data:{did:e.did,names:t}}),{success:n}},this.read=(e,t)=>{const i=this._getDeviceAndConnect(e);return o.isError(i)?i:i[1]._send({cmd:"c2s_read",data:{did:e,names:t}})},this.destory=()=>{Object.values(this._connections).forEach(e=>e.destory())},this.subscribeDeviceStatus=e=>{this._onDeviceStatusChanged=e},this.subscribeBindingChanged=e=>{this._onBindingChanged=e},this.subscribeSocketStatus=e=>{this._onSocketStatusChanged=e},this._handleDeviceStatusChanged=e=>{this._onDeviceStatusChanged&&this._onDeviceStatusChanged(e)},this._handleBindingChanged=()=>{this._onBindingChanged&&this._onBindingChanged()},this._handleSocketStatusChanged=(...e)=>{this._onSocketStatusChanged&&this._onSocketStatusChanged(...e)},this._getBindingList=(e=20,t=0,i=[])=>n(this,void 0,void 0,(function*(){const n=`/app/bindings?show_disabled=0&limit=${e}&skip=${t}`,{err:s,data:r}=yield a.default(`${n}`,{method:"GET"});if(s)return{err:s};const o=[...i,...(null==r?void 0:r.devices)||[]];return r&&r.devices.length===e?yield this._getBindingList(e,e+t,o):o})),this._getWebsocketConnInfo=e=>e.host?`wss://wx${e.host}`:"wss://wxstage.gizwits.com",this.appID=e,this.token=t,this.uid=i;const l=wx.getSystemInfoSync().SDKVersion;this._maxSocketNum=r?-1===o.compareWXSDKVersion(l||"1.0.0","1.7.0")?1:5:0}init(){var e,t;return n(this,void 0,void 0,(function*(){try{const i=yield this._getBindingList();return(null===(e=i.err)||void 0===e?void 0:e.errorCode)?{errorCode:null===(t=i.err)||void 0===t?void 0:t.errorCode,errorMessage:"getting binding list failed"}:(this._bindingDevices=i.reduce((e,t)=>Object.assign(Object.assign({},e),{[t.did]:t}),{}),null)}catch(e){return s.default.GIZ_SDK_OTHERWISE}}))}};class c{constructor({appID:e,token:t,uid:i,wsInfo:s,onDeviceStatusChanged:a,onBindingChanged:o,onSocketStatusChanged:c}){this.ready=!1,this.commType="attrs_v4",this._heartbeatInterval=60,this._keepaliveTime=180,this._loginIntveral=5e3,this.autoSubscribe=!1,this._websocket=null,this._loginFailedTimes=0,this._subDids=new Set,this._socketRespHandleMap={},this._waitSends=[],this.destory=()=>{this._heartbeatTimerId&&clearInterval(this._heartbeatTimerId),this._checkConnectTimerId&&clearInterval(this._checkConnectTimerId),this.close()},this._networkChange=e=>n(this,void 0,void 0,(function*(){r.default.log("network change",e)})),this._appShow=()=>n(this,void 0,void 0,(function*(){r.default.log("app show")})),this._addSubDid=e=>{this._subDids.add(e)},this._removeSubDid=e=>{this._subDids.delete(e)},this._connectWS=()=>{r.default.log("GIZ_SDK: start connect ws"),this._websocket=wx.connectSocket({url:this._wsUrl,fail:e=>{r.default.error("GIZ_SDK: connectSocket error",new Error(JSON.stringify(e)))}}),this._websocket.onClose(this.handleClose),this._websocket.onOpen(this.handleOpen),this._websocket.onError(this.handleError),this._websocket.onMessage(this.handleMessage),this._checkConnectTimerId||(this._checkConnectTimerId=setInterval(()=>{this._websocket||this._connectWS()},1e3))},this._subDevices=e=>{const t={cmd:"subscribe_req",data:e.map(e=>({did:e}))};this._send(t)},this._unSubDevices=e=>{e.map(e=>this._removeSubDid(e))},this._send=(e,t=!1)=>(r.default.log("GIZ_SDK: Socket send",e,t),new Promise(i=>{this._websocket?t||this.ready?this._websocket&&(t||this.ready)&&this._websocket.send({data:JSON.stringify(e),complete:e=>{r.default.log("GIZ_SDK: socket send res",e),r.default.log("resres",e);let t=!1;"sendSocketMessage:ok"===e.errMsg&&(t=!0),i({success:t,message:e.errMsg})},fail:e=>{r.default.error("GIZ_SDK: Socket send error",new Error(JSON.stringify(e))),i({success:!1,message:e.errMsg})}}):i({success:!1,message:"Socket not ready"}):i({success:!1,message:"Socket not init"})})),this.close=()=>{this.ready=!1,this._heartbeatTimerId&&clearInterval(this._heartbeatTimerId),this._websocket&&(this._websocket.close({}),this._websocket=null),this._handleSocketStatusChanged(!1)},this.handleClose=e=>{r.default.error("GIZ_SDK: socket close",new Error(JSON.stringify(e))),this.close(),this._stopPing()},this.handleOpen=()=>{r.default.log(" socket open"),this._login()},this.handleMessage=({data:e})=>{r.default.log("GIZ_SDK: message",e);const t=JSON.parse(e),i=this._socketRespHandleMap[t.cmd];i&&i(t.data)},this.handleError=e=>{r.default.error("GIZ_SDK: socket error",new Error(JSON.stringify(e))),this.close(),this._stopPing()},this._login=()=>{const e={cmd:"login_req",data:{appid:this.appID,uid:this.uid,token:this.token,p0_type:this.commType,heartbeat_interval:this._keepaliveTime,auto_subscribe:this.autoSubscribe}};this._send(e,!0)},this._tryLoginAgain=()=>{this._loginFailedTimes+=1,setTimeout(()=>{this._login()},this._loginFailedTimes*this._loginIntveral)},this._startPing=()=>{this._heartbeatTimerId=setInterval(()=>{this._send({cmd:"ping"})},1e3*this._heartbeatInterval)},this._stopPing=()=>{this._heartbeatTimerId&&clearInterval(this._heartbeatTimerId)},this.pongResp=()=>{},this._loginResp=e=>{1==e.success?(this._loginFailedTimes=0,this.ready=!0,this._startPing(),this._subDevices([...this._subDids]),this._handleSocketStatusChanged(!0),this._consumeWaitSends()):this._loginFailedTimes<3?(r.default.log("GIZ_SDK: Login failed, will try again, please wait..."),this._tryLoginAgain()):(r.default.error("GIZ_SDK: Login failed",new Error("m2m socket login failed")),this.close())},this._consumeWaitSends=()=>{let e=this._waitSends.pop();for(;e;)this._send(e),e=this._waitSends.pop()},this._handleSocketStatusChanged=e=>{this._onSocketStatusChanged&&this._onSocketStatusChanged([...this._subDids],e)},this._subscribeResp=e=>{r.default.log("GIZ_SDK: subscribe_res",e),e&&e.success&&e.success.forEach(e=>this._send({cmd:"c2s_read",data:{did:e.did}})),r.default.debug("GIZ_SDK: subscribe_res",e)},this._onlineResp=e=>{this._isSub(e.did)&&this._onDeviceStatusChanged&&this._onDeviceStatusChanged({did:e.did,attrs:Object.assign({is_online:e.online},e)})},this._rawChangedResp=e=>{this._isSub(e.did)&&this._onDeviceStatusChanged&&this._onDeviceStatusChanged(e)},this._statusChangedResp=e=>{this._isSub(e.did)&&this._onDeviceStatusChanged&&this._onDeviceStatusChanged(e)},this._isSub=e=>this._subDids.has(e),this._invalidMsgResp=e=>{1003===e.error_code&&this._login(),r.default.error("GIZ_SDK: s2c_invalid_msg",new Error(JSON.stringify(e)))},this._bindingChangedResp=e=>{!e.bind&&e.did&&this._removeSubDid(e.did),this._onBindingChanged&&this._onBindingChanged()},this.appID=e,this.token=t,this.uid=i,this._wsUrl=`${s}/ws/app/v1`,this._heartbeatTimerId=void 0,this._loginFailedTimes=0,this._onDeviceStatusChanged=a,this._onBindingChanged=o,this._onSocketStatusChanged=c,this._socketRespHandleMap={pong:this.pongResp,login_res:this._loginResp,subscribe_res:this._subscribeResp,s2c_online_status:this._onlineResp,s2c_raw:this._rawChangedResp,s2c_noti:this._statusChangedResp,s2c_invalid_msg:this._invalidMsgResp,s2c_binding_changed:this._bindingChangedResp},wx.onNetworkStatusChange(this._networkChange),wx.onAppShow(this._appShow)}}t.Connection=c},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(5),r=i(4),a=i(20),o=i(21);class c extends o.default{constructor(){super(...arguments),this.disableSendUDP=!1,this.sendMessageInterval=null,this.UDPSocketHandler=null,this.destroy=()=>{this.cleanTimeout(),this.sendMessageInterval&&clearInterval(this.sendMessageInterval),this.sendMessageInterval=null,this.UDPSocketHandler&&(this.UDPSocketHandler.offError(),this.UDPSocketHandler.offMessage(),this.UDPSocketHandler.close())},this.configDevice=({ssid:e,password:t,softAPSSIDPrefix:i})=>new Promise((o,c)=>{r.default.debug("GIZ_SDK: start config device");let l=!1,u=0;const d=a.default.pack(e,t);this.UDPSocketHandler=wx.createUDPSocket(),this.UDPSocketHandler.bind(),this.disableSendUDP=!1;const h=()=>{try{!this.disableSendUDP&&this.UDPSocketHandler.send({address:"10.10.100.254",port:12414,message:d,offset:0,length:d.byteLength})}catch(e){}};this.sendMessageInterval=setInterval(()=>{h()},2e3),this.UDPSocketHandler.onError(e=>{u+=1,u>2&&(this.destroy(),c({success:!1,err:{errorCode:s.default.WECHAT_ERROR.errorCode,errorMessage:e.errMsg}}))});const f=()=>n(this,void 0,void 0,(function*(){if(!l){this.UDPSocketHandler.offMessage(),this.UDPSocketHandler.offError(),this.sendMessageInterval&&clearInterval(this.sendMessageInterval),this.disableSendUDP=!0,l=!0;try{const i=yield this.searchDevice({ssid:e,password:t});o(i)}catch(e){c(e)}}}));this.UDPSocketHandler.onMessage(e=>{f()}),wx.onNetworkStatusChange(()=>n(this,void 0,void 0,(function*(){!l&&wx.getConnectedWifi({success:e=>n(this,void 0,void 0,(function*(){-1===e.wifi.SSID.indexOf(i)&&f()}))})})))}),this.setDeviceOnboardingDeploy=({timeout:e,isBind:t=!0,softAPSSIDPrefix:i})=>{const s=this.ssid,r=this.password;return new Promise((a,o)=>n(this,void 0,void 0,(function*(){this.destroy(),this.initDeviceOnboardingDeploy(a,o),this.startTimeoutTimer(e);try{const e=((yield this.configDevice({ssid:s,password:r,softAPSSIDPrefix:i})).data||[]).map(e=>({mac:e.mac,productKey:e.product_key,did:e.did,name:"",isBind:!1,connectType:"NONE",isBleOnline:!1,isLanOnline:!1,isOnline:!1}));if(t)try{a(yield this.bindDevices(e))}catch(e){o(e)}else a({success:!0,data:e})}catch(e){o(e)}finally{this.destroy()}})))}}}t.default=c},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(11),s=({SSID:e,password:t,pk:i})=>{let s=n.MD5(e+t).toString();s=n.enc.Hex.parse(s);let r=n.enc.Utf8.parse(i),a=n.AES.encrypt(r,s,{iv:s,mode:n.mode.ECB,padding:n.pad.ZeroPadding});return n.MD5(a.ciphertext).toString()};t.default=({SSID:e,password:t,pks:i})=>{const n=[];return i.map(i=>{const r=s({SSID:e,password:t,pk:i});n.push(r)}),n}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(11);t.psKeySign=e=>{const t=Math.round((new Date).getTime()/1e3),i=e+t;return{Signature:n.MD5(i).toString(),timestamp:t}}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(5),r=i(10),a=i(19),o=i(9),c=i(21),l=i(20),u=i(4);function d({bleDeviceId:e,arrayBuffer:t,serviceUUIDSuffix:i="fe60",characteristicUUIDSuffix:s="fe61",bleHandle:o}){let c=null,l=null;const d=()=>null===l&&(c&&clearInterval(c),!0);return new Promise((h,f)=>n(this,void 0,void 0,(function*(){try{u.default.debug("GIZ_SDK: ssid info: ",t),l=setTimeout(()=>{c&&clearInterval(c),l=null,h(!1)},5e3),u.default.debug("GIZ_SDK: createBLEConnection start: ",e),yield o.disableScan();const n=yield a.retryConnect(e,1e4);o.enableScan(),u.default.debug("GIZ_SDK: createBLEConnection end, res:",n);const f=yield a.getBLEDeviceServices(e);u.default.debug("GIZ_SDK: getBLEDeviceServices end, res:",f);const p=f.find(e=>e.uuid.split("-")[0].toLowerCase().endsWith(i));if(!p)return u.default.debug("GIZ_SDK: get ble device services fail",e,f),void h(!1);const v=yield a.getBLEDeviceCharacteristics(e,p.uuid);u.default.debug("GIZ_SDK: getBLEDeviceCharacteristics end, res:",v);const g=v.find(e=>e.uuid.split("-")[0].toLowerCase().endsWith(s));if(!g)return u.default.debug("GIZ_SDK: get ble device characteristics fail",e,v),void h(!1);if(!g.properties.notify&&!g.properties.indicate)return u.default.debug("GIZ_SDK: the ble device characteristic not support notify or indicate",e,g),void h(!1);u.default.debug("GIZ_SDK: check characteristic and service success"),yield a.notifyBLECharacteristicValueChange(e,p.uuid,g.uuid);const y=e=>{const t=r.ab2hex(e.value);u.default.debug("GIZ_SDK: 收到设备返回ack",t),"0000000303000002"===t&&(o.removeEventListener("GizBleDeviceData",y),h(!0))};if(o.addEventListener("GizBleDeviceData",y),u.default.debug("GIZ_SDK: on notifyBLECharacteristicValueChange success"),d())return;yield a.unpackWriteBLECharacteristicValue(e,p.uuid,g.uuid,t),c=setInterval(()=>{d()||a.unpackWriteBLECharacteristicValue(e,p.uuid,g.uuid,t)},2e3),u.default.debug("GIZ_SDK: unpackWriteBLECharacteristicValue end")}catch(e){f(!1),u.default.debug("GIZ_SDK: sendBLEConfigCmd error",e)}}))).catch(e=>{u.default.debug("GIZ_SDK: sendBLEConfigCmd error",e)}).finally(()=>{l&&clearTimeout(l),c&&clearInterval(c),wx.closeBLEConnection({deviceId:e})})}t.sendBLEConfigCmd=d;class h extends c.default{constructor(e,t,i,c,h){super(e,t,i,c),this.destroy=()=>{this.cleanTimeout()},this.isValidBleDevice=(e,t)=>{if(!e||!e.advertisData)return!1;const{productKey:i,mac:n}=r.advertisData2PkAndMac(e.advertisData,this.specialProductKeys);return!!this.specialProductKeys.includes(i)&&(u.default.debug(`GIZ_SDK: isValidBleDevice mac: ${n} pk: ${i} name: ${e.name}`),u.default.debug(`GIZ_SDK: softAPSSIDPrefix: ${t} ismatch : ${e.name&&e.name.startsWith(t)}`),!t||e.name&&e.name.startsWith(t))},this.enableBluetoothDevicesDescovery=()=>n(this,void 0,void 0,(function*(){return(yield a.getBluetoothAdapterState()).available?(yield a.startBluetoothDevicesDiscovery(),{success:!0}):{success:!1,err:{errorCode:s.default.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON.errorCode,errorMessage:"蓝牙状态不可用"}}})),this.enableAndGetBluetoothDevices=e=>n(this,void 0,void 0,(function*(){const t=yield this.enableBluetoothDevicesDescovery();if(!t.success)return t;u.default.debug("GIZ_SDK: start enableAndGetBluetoothDevices");const i=(yield a.getBluetoothDevices()).filter(t=>this.isValidBleDevice(t,e));return u.default.debug("GIZ_SDK: getBluetoothDevices success",i),{success:!0,bleDevices:i}})),this.setDeviceOnboardingDeploy=({timeout:e,isBind:t=!0,softAPSSIDPrefix:i})=>new Promise((s,r)=>n(this,void 0,void 0,(function*(){const n=this.ssid,a=this.password;this.destroy(),this.initDeviceOnboardingDeploy(s,r),this.startTimeoutTimer(e);try{const r=((yield this.configBLEDevice({ssid:n,password:a,timeout:1e3*e,softAPSSIDPrefix:i})).data||[]).map(e=>({mac:e.mac,productKey:e.product_key,did:e.did,name:"",isBind:!1,connectType:"NONE",isBleOnline:!1,isLanOnline:!1,isOnline:!1}));s(t?yield this.bindDevices(r):{success:!0,data:r})}catch(e){s({success:!1,data:e})}finally{this.destroy()}}))),this.configBLEDevice=({ssid:e,password:t,softAPSSIDPrefix:i})=>new Promise((c,h)=>n(this,void 0,void 0,(function*(){u.default.debug("GIZ_SDK: start config ble device");const f=yield this.enableAndGetBluetoothDevices(i).catch(e=>({success:!1,err:{errorCode:s.default.WECHAT_ERROR.errorCode,errorMessage:JSON.stringify(e)}}));if(!r.isWXDevicesResult(f))return h(f);const{bleDevices:p}=f;u.default.debug("GIZ_SDK: enableAndGetBluetoothDevices success, target devices: ",p);const v=({devices:e})=>n(this,void 0,void 0,(function*(){this.hasTimeoutHandler()?Array.prototype.push.apply(p,e.filter(e=>this.isValidBleDevice(e,i))):wx.offBluetoothDeviceFound(v)}));wx.onBluetoothDeviceFound(v);const g=l.default.pack(e,t),y=()=>n(this,void 0,void 0,(function*(){if(u.default.debug("GIZ_SDK: startConfigDevice"),!this.hasTimeoutHandler())return;const e=p.shift();if(e&&u.default.debug("GIZ_SDK: startConfigDevice, target device: ",e),!(e&&(yield d({bleDeviceId:e.deviceId,arrayBuffer:g.buffer,bleHandle:this.bleHandle}))))return yield o.default(500),yield a.startBluetoothDevicesDiscovery(),void(yield y());u.default.debug("GIZ_SDK: offBluetoothDeviceFound ready search device"),wx.offBluetoothDeviceFound(v)}));try{this.searchDevice({ssid:e,password:t}).then(e=>{c(e)})}catch(e){h(e),u.default.error("GIZ_SDK: searchDevice error",new Error(JSON.stringify(e)))}yield y()}))),this.bleHandle=h}}t.default=h},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(5),r=i(10),a=i(19),o=i(9),c=i(21),l=i(20),u=i(4),d=i(89),h={a57a49b9b265421ca337219cd66a6701:"icgsfwJZDFX","67a95f560e464453be079c5723a4a85c":"icgshOaLCG5","0b58c73f12064eb897aa005cf43d6a1b":"icgs4Yuoa16","5a64ca1f742942edacd09a17e3c4a7f2":"icgsbR0xeRj",a83ce02518944076aa3a4e949acc71a2:"icgsBZbJtsl","4b286229884f4711bcdbaefdfb5f76b9":"icgs0cyLT3e","8c71d805031a41f2870aa9cd8680d579":"icgsobrRgsz",b7a77f535a774c1592a6146b03e14a7d:"icgsQMsZFS9",aff644f2b33c47fe8a557473a29ef7c1:"icgsiBVdr5P",ccfeacd9296f47f7ad3598cc5e4d0843:"icgs4eOiCOU","7c735620d8fa48329ce2d6af68abd41b":"icgsb2Y7InK",a7bca53587744b00bb76da2a7ed66e00:"icgst4qDGSv",fe1c263c41ea481ca70789783c8488ee:"icgst8DYtI6","1ff67b6ef3394024b15e38f2d0b511b9":"icgs8Cv3lIH","7f240f94172446988e8f3febdd722e04":"icgsoHk7c19","21732bba93b64203b24ea1e8b71f30e3":"icgsUEJjCU0",b038229fed814ac2b07383e281047a0a:"icgsrp4M0QN","5816516a5f6a4a628c3df602e769ced3":"icgsioLXjiC"};function f({bleDeviceId:e,arrayBuffer:t,serviceUUIDSuffix:i="fe60",characteristicUUIDSuffix:s="fe61",bleHandle:o}){let c=null,l=null;const d=()=>null===l&&(c&&clearInterval(c),!0);return new Promise((h,f)=>n(this,void 0,void 0,(function*(){try{u.default.debug("GIZ_SDK: ssid info: ",t),l=setTimeout(()=>{c&&clearInterval(c),l=null,h(!1)},5e3),u.default.debug("GIZ_SDK: createBLEConnection start: ",e),yield o.disableScan();const n=yield a.retryConnect(e,1e4);o.enableScan(),u.default.debug("GIZ_SDK: createBLEConnection end, res:",n),u.default.debug("GIZ_SDK: getBLEDeviceServices start, res:",i);const f=yield a.getBLEDeviceServices(e);u.default.debug("GIZ_SDK: getBLEDeviceServices end, res:",f);const p=f.find(e=>e.uuid.split("-")[0].toLowerCase().endsWith(i)||e.uuid.split("-")[0].toLowerCase().endsWith("abf0"));if(!p)return u.default.debug("GIZ_SDK: get ble device services fail",e,f),void h(!1);const v=yield a.getBLEDeviceCharacteristics(e,p.uuid);u.default.debug("GIZ_SDK: getBLEDeviceCharacteristics end, res:",v);const g=v.find(e=>e.uuid.split("-")[0].toLowerCase().endsWith(s)||e.uuid.split("-")[0].toLowerCase().endsWith("abf7"));if(!g)return u.default.debug("GIZ_SDK: get ble device characteristics fail",e,v),void h(!1);if(!g.properties.notify&&!g.properties.indicate)return u.default.debug("GIZ_SDK: the ble device characteristic not support notify or indicate",e,g),void h(!1);u.default.debug("GIZ_SDK: check characteristic and service success"),yield a.notifyBLECharacteristicValueChange(e,p.uuid,g.uuid);const y=e=>{const t=r.ab2hex(e.value);u.default.debug("GIZ_SDK: 收到设备返回ack",t),"0000000303000002"===t&&(o.removeEventListener("GizBleDeviceData",y),h(!0))};if(o.addEventListener("GizBleDeviceData",y),u.default.debug("GIZ_SDK: on notifyBLECharacteristicValueChange success"),d())return;yield a.unpackWriteBLECharacteristicValue(e,p.uuid,g.uuid,t),c=setInterval(()=>{d()||a.unpackWriteBLECharacteristicValue(e,p.uuid,g.uuid,t)},2e3),u.default.debug("GIZ_SDK: unpackWriteBLECharacteristicValue end")}catch(e){f(!1),u.default.debug("GIZ_SDK: sendBLEConfigCmd error",e)}}))).catch(e=>{u.default.debug("GIZ_SDK: sendBLEConfigCmd error",e)}).finally(()=>{l&&clearTimeout(l),c&&clearInterval(c),wx.closeBLEConnection({deviceId:e})})}t.sendBLEConfigCmd=f;class p extends c.default{constructor(e,t,i,c,p){super(e,t,i,c),this.lastestOnlineTimeMap={},this.destroy=()=>{this.cleanTimeout()},this.isValidBleDevice=(e,t,i)=>{if(!e||!e.advertisData)return!1;const{productKey:n,mac:s,bleWorkStatus:a}=r.advertisData2PkAndMac(e.advertisData,this.specialProductKeys);return 0!==a&&(!!this.specialProductKeys.includes(n)&&(!(i&&i.length>0&&!i.includes(n))&&(u.default.debug(`GIZ_SDK: isValidBleDevice mac: ${s} pk: ${n} name: ${e.name}`),u.default.debug(`GIZ_SDK: softAPSSIDPrefix: ${t} ismatch : ${e.name&&e.name.startsWith(t)}`),!t||e.name&&e.name.startsWith(t))))},this.enableBluetoothDevicesDescovery=()=>n(this,void 0,void 0,(function*(){return(yield a.getBluetoothAdapterState()).available?(yield a.startBluetoothDevicesDiscovery(),{success:!0}):{success:!1,err:{errorCode:s.default.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON.errorCode,errorMessage:"蓝牙状态不可用"}}})),this.enableAndGetBluetoothDevices=(e,t)=>n(this,void 0,void 0,(function*(){const i=yield this.enableBluetoothDevicesDescovery();if(!i.success)return i;u.default.debug("GIZ_SDK: start enableAndGetBluetoothDevices");const n=(yield a.getBluetoothDevices()).filter(i=>this.isValidBleDevice(i,e,t));u.default.debug("GIZ_SDK: getBluetoothDevices success",n);const s=[];return n.forEach(e=>{e&&e.advertisData&&s.push(Object.assign({},e))}),{success:!0,bleDevices:s}})),this.setDeviceOnboardingDeploy=({timeout:e,isBind:t=!0,softAPSSIDPrefix:i,productKeys:s})=>new Promise((r,a)=>n(this,void 0,void 0,(function*(){const n=this.ssid,o=this.password;this.destroy(),this.initDeviceOnboardingDeploy(r,a),this.startTimeoutTimer(e);try{const a=[(yield this.configBLEDevice({ssid:n,password:o,timeout:1e3*e,softAPSSIDPrefix:i,productKeys:s})).data];r(t?yield this.bindDevices(a):{success:!0,data:a})}catch(e){r({success:!1,data:e})}finally{this.destroy()}}))),this.getDeviceLastestOnlineTime=({productKey:e,mac:t})=>n(this,void 0,void 0,(function*(){let i=h[e];i||(i=e),u.default.debug("GIZ_SDK: getDeviceLastestOnlineTime",i,t,e);const n=yield d.default(`app/device/deviceInfo/${i}/${(null!=t?t:"").toLocaleLowerCase()}`,{method:"post"});return u.default.debug("GIZ_SDK: 请求结果",n),n})),this.verifyDeviceOnline=({productKey:e,mac:t})=>new Promise((i,s)=>{u.default.debug("GIZ_SDK: 开始确认设备上线");const r=()=>n(this,void 0,void 0,(function*(){var n,s;if(this.hasTimeoutHandler())try{yield o.default(2e3);const a=yield this.getDeviceLastestOnlineTime({productKey:e,mac:t});u.default.debug("GIZ_SDK: 确认到设备是否在线",null===(s=null===(n=a.data)||void 0===n?void 0:n.data)||void 0===s?void 0:s.onlineStatus),a.success&&a.data&&a.data.data&&1==a.data.data.onlineStatus?(u.default.debug("GIZ_SDK: 确认到设备是在线的",a),i({success:!0,data:a.data})):(u.default.debug("GIZ_SDK: 未确认到设备是在线"),yield o.default(1500),!this.disableSearchDevice&&r())}catch(e){yield o.default(3e3),!this.disableSearchDevice&&r()}}));r()}),this.configBLEDevice=({ssid:e,password:t,softAPSSIDPrefix:i,productKeys:c})=>new Promise((d,h)=>n(this,void 0,void 0,(function*(){u.default.debug("GIZ_SDK: start config ble device");const p=yield this.enableAndGetBluetoothDevices(i,c).catch(e=>({success:!1,err:{errorCode:s.default.WECHAT_ERROR.errorCode,errorMessage:JSON.stringify(e)}}));if(!r.isWXDevicesResult(p))return h(p);const{bleDevices:v}=p;u.default.debug("GIZ_SDK: enableAndGetBluetoothDevices success, target devices: ",v);const g=({devices:e})=>n(this,void 0,void 0,(function*(){this.hasTimeoutHandler()?Array.prototype.push.apply(v,e.filter(e=>this.isValidBleDevice(e,i,c))):wx.offBluetoothDeviceFound(g)}));wx.onBluetoothDeviceFound(g);const y=l.default.pack(e,t),D=v.shift(),_=e=>n(this,void 0,void 0,(function*(){if(u.default.debug("GIZ_SDK: startConfigDevice"),!this.hasTimeoutHandler())return;if(e&&u.default.debug("GIZ_SDK: startConfigDevice, target device: ",e),!(e&&(yield f({bleDeviceId:e.deviceId,arrayBuffer:y.buffer,bleHandle:this.bleHandle}))))return yield o.default(500),yield a.startBluetoothDevicesDiscovery(),void(yield _(e));u.default.debug("GIZ_SDK: offBluetoothDeviceFound ready search device"),wx.offBluetoothDeviceFound(g)})),{productKey:m,mac:b}=r.advertisData2PkAndMac((null!=D?D:{}).advertisData,this.specialProductKeys);_(D);try{yield o.default(5e3),this.verifyDeviceOnline({productKey:m,mac:b}).then(e=>{d(Object.assign(Object.assign({},e),{data:Object.assign(Object.assign({},e.data.data),{productKey:m})}))})}catch(e){h(e),u.default.error("GIZ_SDK: searchDevice error",new Error(JSON.stringify(e)))}}))),this.bleHandle=p}}t.default=p},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(18),r=i(15),a=i(5),o=i(4);t.default=(e,t,i=!0)=>n(void 0,void 0,void 0,(function*(){const n=Object.assign({},t),c={"Content-Type":"application/json","X-Gizwits-Application-Id":r.getGlobalData("appID")};i&&(c.Authorization=r.getGlobalData("token")),n.header=Object.assign(Object.assign({},c),t.headers),delete n.headers;const l=r.getGlobalData("cloudServiceInfo").aepInfo;o.default.debug("aepApiRequest",l+e);const u=yield s.default(l+e,n);if(u.statusCode>=200&&u.statusCode<300)return{success:!0,data:u.data};let d={success:!1,err:{errorCode:a.default.GIZ_SDK_HTTP_REQUEST_FAILED.errorCode,errorMessage:""}};try{d={success:!1,err:{errorCode:u.data.error_code,errorMessage:u.data.error_message}}}catch(e){}return d}))},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(12);t.AnonymousLogin=function({uid:e}){return n(this,void 0,void 0,(function*(){return s.default("/app/users",{data:{phone_id:e},method:"POST"},!1)}))}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(4),r=i(26),a=i(92),o=i(27),c=i(1),l=i(3),u=i(9),d=i(10),h=i(29);class f extends h.default{constructor({pks:e}){super(),this.connectedList=[],this.pks=[],this.scanList=[],this.deviceUDPPort=12414,this.appUDPPort=2415,this.offlineThreshold=2e4,this.isActive=!0,this.listenDevOfflineTimer=null,this.init=()=>{this.UDPSocket&&(this.UDPSocket=wx.createUDPSocket(),this.UDPSocket.bind(),this.UDPSocket.onMessage(this.onMessage),this.UDPSocket.onError(this.onError),s.default.info("Start UDP Discover"),this.startDiscover(),this.listenDevOffline(this.offlineThreshold),wx.onAppShow(this.onAppShow),wx.onAppHide(this.onAppHide))},this.onAppShow=()=>{this.isActive=!0,this.scanList.map(e=>{e.ctime=Date.now()})},this.onAppHide=()=>{this.isActive=!1},this.listenDevOffline=e=>{this.listenDevOfflineTimer=setInterval(()=>{if(!this.isActive)return;const t=(new Date).getTime(),i=this.scanList.filter(i=>t-i.ctime<e);i.length!==this.scanList.length&&(s.default.debug("remove lan device"),this.scanList=i,this.notifyDevices())},500)},this.notifyDevices=()=>{this.listenerMap.GizLanDeviceList&&this.listenerMap.GizLanDeviceList.map(e=>{e(this.scanList)})},this.notifyDeviceData=(e,t)=>{this.listenerMap.GizLanDeviceData&&this.listenerMap.GizLanDeviceData.map(i=>{i(e,t)})},this.isSameDevice=(e,t)=>e.mac===t.mac&&e.productKey===t.productKey,this.disConnectDevice=e=>{const t=this.connectedList.findIndex(t=>t.productKey===e.productKey&&t.mac===e.mac);try{return-1!==t&&(this.connectedList[t].socketHandle.destory(),this.connectedList.splice(t,1)),{success:!0}}catch(e){return{success:!1,err:e}}},this.onData=(e,t)=>{this.notifyDeviceData(e,t)},this.connectDevice=e=>n(this,void 0,void 0,(function*(){const t=this.scanList.find(t=>this.isSameDevice(e,t));if(!t)return{success:!1};if(this.connectedList.find(t=>this.isSameDevice(e,t)))return{success:!0};{const e=new p({ip:t.ip,mac:t.mac,productKey:t.productKey,onClose:this.onDeviceClose,onData:this.onData}),i=yield e.connect();return i.success?this.connectedList.push({mac:t.mac,productKey:t.productKey,socketHandle:e}):e.destory(),i}})),this.onError=e=>{s.default.warn("Discover Error",e)},this.isMatchPk=e=>0===this.pks.length||this.pks.includes(e),this.onMessage=e=>{const t=d.ab2numbers(e.message),i=new a.default(t);""!==i.mac&&this.isMatchPk(i.productKey)&&this.updateDevice(i,e.remoteInfo.address)},this.onDeviceClose=({productKey:e,mac:t})=>{const i=this.connectedList.findIndex(i=>i.productKey===e&&i.mac===t);-1!==i&&this.connectedList.splice(i,1)},this.write=(e,t)=>n(this,void 0,void 0,(function*(){s.default.debug("send data to device",e,t,this.connectedList);const i=this.connectedList.findIndex(t=>this.isSameDevice(t,e));if(-1!==i){return this.connectedList[i].socketHandle.write(t)}return{success:!1,message:"device not sub"}})),this.updateDevice=(e,t)=>{const i=this.scanList.find(t=>t.mac===e.mac);if(i)i.ctime=Date.now();else{const i={mac:e.mac,ip:t,productKey:e.productKey,did:e.did,expandData:e,name:"",isBind:!1,connectType:"NONE",isOnline:!1,isLanOnline:!0,isBleOnline:!1,ctime:Date.now()};this.scanList.push(i),this.notifyDevices()}},this.sendBoradCast=()=>{this.UDPSocket&&(this.UDPSocket.send({address:"255.255.255.255",message:a.default.pack(),port:this.deviceUDPPort}),s.default.debug("Send UDP Discover"))},this.startDiscover=()=>{this.sendBoradCast(),this.boradcastTimer=setInterval(()=>{this.sendBoradCast()},5e3)},this.destory=()=>{this.boradcastTimer&&clearInterval(this.boradcastTimer),this.UDPSocket&&this.UDPSocket.close(),this.listenDevOfflineTimer&&clearInterval(this.listenDevOfflineTimer),wx.offAppShow(this.onAppShow),wx.offAppHide(this.onAppHide)},this.pks=e}}t.LanHandle=f;class p{constructor({ip:e,onClose:t,mac:i,productKey:a,onData:h}){this.deviceTCPPort=12416,this.ip="",this.productKey="",this.mac="",this.tcpHandler=null,this.onData=(e,t)=>{},this.onCloseListener=({mac:e,productKey:t})=>{},this.connect=()=>n(this,void 0,void 0,(function*(){return new Promise(e=>n(this,void 0,void 0,(function*(){const t=()=>{const e=r.default.pack();this.tcpHandler.write(l.arrayToUint8(e)),s.default.debug("connect success try login")},i=t=>{e({success:!0,err:t})},n=t=>{switch(new c.default(d.ab2numbers(t.message)).cmd){case"0007":{const e=new r.default(d.ab2numbers(t.message)),i=o.default.pack({passcode:e.passcode});this.tcpHandler.write(l.arrayToUint8(i));break}case"0009":new o.default(d.ab2numbers(t.message)).result?(e({success:!0}),this.initListener()):e({success:!1})}};try{this.tcpHandler=wx.createTCPSocket(),this.tcpHandler.onConnect(t),this.tcpHandler.onError(i),this.tcpHandler.onMessage(n),this.tcpHandler.connect({address:this.ip,port:this.deviceTCPPort,timeout:2}),yield u.default(4e3),e({success:!1,err:null})}catch(t){s.default.error("connect lan error",t),e({success:!1,err:null})}finally{this.tcpHandler.offConnect(t),this.tcpHandler.offError(i),this.tcpHandler.offMessage(n)}})))})),this.write=e=>(this.tcpHandler.write(e),{success:!0}),this.onMessage=e=>{try{const t=d.ab2hex(e.message),i=new c.default(l.hexStrint2byte(t));s.default.debug("on tcp message",i),this.onData(this.mac,t)}catch(e){}},this.onError=()=>{},this.onClose=()=>{this.onCloseListener({productKey:this.productKey,mac:this.mac})},this.initListener=()=>{this.tcpHandler.onError(this.onError),this.tcpHandler.onMessage(this.onMessage),this.tcpHandler.onClose(this.onClose)},this.destory=()=>{this.tcpHandler&&this.tcpHandler.close(),this.tcpHandler.offError(this.onError),this.tcpHandler.offMessage(this.onMessage),this.tcpHandler.offClose(this.onClose)},this.ip=e,this.mac=i,this.productKey=a,this.onData=h,this.onCloseListener=t}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(4),s=i(1),r=i(3);class a extends s.default{constructor(e){super(e),this.did="",this.mac="",this.productKey="",this.deviceType=0,this.apiUrl="",this.protocolVersion="",this.mcuVersion="",this.moduleVersion="",this.parseEndChat=(e,t)=>{let i="";const n=this.content.slice(e,this.content.length);for(let t in n){const s=n[t];if(e+=1,0===s)break;i+=String.fromCharCode(s)}return this[t]=i,e},this.baseParse=(e,t,i="ASCII")=>{const n=parseInt(r.arrayToString(this.content.slice(e,e+2)),16);e+=2;let s="";return this.content.slice(e,e+n).map(e=>{if("ASCII"===i)s+=String.fromCharCode(e);else{const t=e.toString(16);s+=r.fillString(t,2)}}),this[t]=s,e+n};let t=0;try{t=this.baseParse(t,"did"),t=this.baseParse(t,"mac","HEX"),t=this.baseParse(t,"moduleVersion"),t=this.baseParse(t,"productKey"),t+=8,t=this.parseEndChat(t,"apiUrl"),t=this.parseEndChat(t,"protocolVersion"),this.mcuVersion="",this.content.slice(t,this.content.length).map(e=>{this.mcuVersion+=String.fromCharCode(e)})}catch(e){n.default.warn("Parse DiscoverUDP error",e)}}}a.pack=()=>{const e=[0,0,0,3,3,0,0,3],t=new ArrayBuffer(e.length),i=new Uint8Array(t);for(let n=0;n<t.byteLength;n++)i[n]=e[n];return i},t.default=a},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(1),s=i(3);class r extends n.default{constructor(e){super(e),this.state=0,this.len=0;let t=0;this.len=parseInt(s.arrayToString(this.content.slice(t,t+2)),16),t+=2,this.state=this.content[t]}}t.RequestSync=r,r.pack=()=>[0,0,0,3,3,0,0,81];class a extends n.default{constructor(e){super(e),this.id=0,this.timestemp=0,this.payloadLen=0,this.payload=[];let t=0;this.id=parseInt(s.arrayToString(this.content.slice(t,t+2)),16),t+=2,this.timestemp=parseInt(s.arrayToString(this.content.slice(t,t+5)),16),t+=5,this.payloadLen=parseInt(s.arrayToString(this.content.slice(t,t+2)),16),t+=2,this.payload=this.content.slice(t,this.content.length)}}t.SyncPackage=a,a.pack=e=>{let t=e.toString(2);return t=s.fillString(t,16),[0,0,0,3,5].concat([0,0,83]).concat(s.completeBlock(t))};class o extends n.default{}t.DeletePackage=o,o.pack=e=>{let t=e.toString(2);return t=s.fillString(t,16),[0,0,0,3,5].concat([0,0,85]).concat(s.completeBlock(t))};class c extends n.default{constructor(e){super(e),this.state=0,this.state=this.content[0]}}t.CancelSync=c,c.pack=()=>[0,0,0,3,3,0,0,87]},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(12),r=i(11);t.uploadP0=function({device:e,data:t,productSecret:i}){return n(this,void 0,void 0,(function*(){const n=`/v2/products/${e.productKey}/devices/offline-data`;let a=e.passcode;const o=r.enc.Hex.parse(i),c=r.enc.Hex.parse(""),l=r.enc.Utf8.parse(a);return a=r.AES.encrypt(l,o,{iv:c,mode:r.mode.ECB,padding:r.pad.Pkcs7}).ciphertext.toString().toUpperCase(),s.default(n,{data:{data:t,encoding:"hex"},method:"POST",headers:{"X-Gizwits-Device-Id":e.did,"X-Gizwits-Device-passcode":a}},!1)}))}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(1),s=i(3);class r extends n.default{}r.pack=()=>{const e=parseInt(`${Date.now()/1e3}`,10),t=s.fillString(e.toString(2),40);return[0,0,0,3,8,0,0,89].concat(s.completeBlock(t))},t.default=r},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(1);class s extends n.default{constructor(e){super(e),this.status=0,this.status=this.content[0]}}s.pack=()=>[0,0,0,3,3,0,0,97],t.default=s},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(1);class s extends n.default{constructor(){super(...arguments),this.status=0}}s.pack=e=>[0,0,0,3,3,0,0,99,e],t.default=s}]);
|