mini_program_gizwits_sdk 3.6.27-socketResend → 3.6.28
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 +1 -1
- package/package.json +1 -1
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=36)}([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(41)}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.")},o=Object.create||function(){function e(){}return function(t){var i;return e.prototype=t,i=new e,e.prototype=null,i}}(),a={},c=a.lib={},u=c.Base={extend:function(e){var t=o(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)}},l=c.WordArray=u.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 o=i[r>>>2]>>>24-r%4*8&255;t[n+r>>>2]|=o<<24-(n+r)%4*8}else for(var a=0;a<s;a+=4)t[n+a>>>2]=i[a>>>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=u.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 l.init(t,e)}}),d=a.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 l.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 l.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=u.extend({reset:function(){this._data=new l.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,o=this.blockSize,a=r/(4*o),c=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,u=e.min(4*c,r);if(c){for(var d=0;d<c;d+=o)this._doProcessBlock(s,d);i=s.splice(0,c),n.sigBytes-=u}return new l.init(i,u)},clone:function(){var e=u.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0}),g=(c.Hasher=v.extend({cfg:u.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)}}}),a.algo={});return a}(Math),n)}).call(this,i(17))},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.sn=[0,0,0,0],this.content=[],this.formatP0=e=>{let t=(0,n.checkHeader)(e);if(!1===t)throw new Error("Header Error");this.header=(0,n.arrayToString)(e.slice(0,t));const i=e.slice(t,e.length),r=(0,n.getProtocolLen)(i);this.len=s.decodeLen(i.slice(0,r)),t+=r,this.flag=e.slice(t,t+1),t+=1,this.cmd=(0,n.arrayToString)(e.slice(t,t+2)),t+=2,"0093"===this.cmd||"0094"===this.cmd?(this.sn=e.slice(t,4),t+=4,this.content=e.slice(t,e.length)):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,o,a,c,u,l,d,h,f,p,v,g,y,_,m,D,b;e.exports=(n=i(0),i(6),void(n.lib.Cipher||(s=n,r=s.lib,o=r.Base,a=r.WordArray,c=r.BufferedBlockAlgorithm,u=s.enc,u.Utf8,l=u.Base64,d=s.algo.EvpKDF,h=r.Cipher=c.extend({cfg:o.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:m}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=o.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=[],o=0;o<n;o+=4)r.push(s);var c=a.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=o.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?a.create([1398893684,1701076831]).concat(i).concat(t):t).toString(l)},parse:function(e){var t,i=l.parse(e),n=i.words;return 1398893684==n[0]&&1701076831==n[1]&&(t=a.create(n.slice(2,4)),n.splice(0,4),i.sigBytes-=16),y.create({ciphertext:i,salt:t})}},m=r.SerializableCipher=o.extend({cfg:o.extend({format:_}),encrypt:function(e,t,i,n){n=this.cfg.extend(n);var s=e.createEncryptor(i,n),r=s.finalize(t),o=s.cfg;return y.create({ciphertext:r,key:i,iv:o.iv,algorithm:e,mode:o.mode,padding:o.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}}),D=(s.kdf={}).OpenSSL={execute:function(e,t,i,n,s){if(n||(n=a.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 o=a.create(r.words.slice(t),4*i);return r.sigBytes=4*t,y.create({key:r,iv:o,salt:n})}},b=r.PasswordBasedCipher=m.extend({cfg:m.cfg.extend({kdf:D}),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=m.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,m.decrypt.call(this,e,t,s.key,n)}}))))},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.bytesToHexString=t.bytesToInt=t.arrayToUint8=t.formatCode=t.formatCodesFromStr=t.hexStrint2byte=t.string2Bytes=t.fillString=t.arrayToString=t.getProtocolLen=t.checkHeader=t.arrayToASCII=t.completeBlock=void 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";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=n(i(5)),r=n(i(40));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),(0,r.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:s.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,o,a,c,u,l;e.exports=(l=i(0),i(24),i(19),s=(n=l).lib,r=s.Base,o=s.WordArray,a=n.algo,c=a.MD5,u=a.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=o.create(),a=r.words,c=n.keySize,u=n.iterations;a.length<c;){i&&s.update(i),i=s.update(e).finalize(t),s.reset();for(var l=1;l<u;l++)i=s.finalize(i),s.reset();r.concat(i)}return r.sigBytes=4*c,r}}),n.EvpKDF=function(e,t,i){return u.create(i).compute(e,t)},l.EvpKDF)},function(e,t,i){"use strict";(function(e){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function o(e){try{c(n.next(e))}catch(e){r(e)}}function a(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(o,a)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.statisticRequest=void 0;const r=s(i(5)),o=i(14),a=s(i(26));t.statisticRequest=function(t,i,s=!0){return n(this,void 0,void 0,(function*(){try{const n=i.body.appInfo.appID,r=Object.assign(Object.assign({},i),{data:i.body}),c={"Content-Type":"application/json","X-Gizwits-Application-Id":n};s&&(c["X-Gizwits-User-token"]=e.token),r.headers=Object.assign(Object.assign({},c),i.headers);const u=`https://${(0,o.getGlobalData)("cloudServiceInfo").openAPIInfo}/`;console.log("===statisticRequest===",u+t,r);const l=yield(0,a.default)(u+t,r);return(null==l?void 0:l.statusCode)>=200&&(null==l?void 0:l.statusCode)<300?{success:!0,data:null==l?void 0:l.data}:{success:!1,err:{errorCode:(null==l?void 0:l.data).error_code,errorMessage:(null==l?void 0:l.data).error_message}}}catch(e){return{success:!1}}}))},t.default=(e,t,i=!0)=>n(void 0,void 0,void 0,(function*(){const n=Object.assign({},t),s={"Content-Type":"application/json","X-Gizwits-Application-Id":(0,o.getGlobalData)("appID")};i&&(s["X-Gizwits-User-token"]=(0,o.getGlobalData)("token")),n.header=Object.assign(Object.assign({},s),t.headers),delete n.headers;const c=(0,o.getGlobalData)("cloudServiceInfo").openAPIInfo,u=yield(0,a.default)("https://"+c+e,n);if(u.statusCode>=200&&u.statusCode<300)return{success:!0,data:u.data};let l={success:!1,err:{errorCode:r.default.GIZ_SDK_HTTP_REQUEST_FAILED.errorCode,errorMessage:""}};try{l={success:!1,err:{errorCode:u.data.error_code,errorMessage:u.data.error_message}}}catch(e){}return l}))}).call(this,i(17))},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 o=(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,a=0;a<4&&r+.75*a<i;a++)s.push(n.charAt(o>>>6*(3-a)&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 o=i.charAt(64);if(o){var a=e.indexOf(o);-1!==a&&(t=a)}return function(e,t,i){for(var n=[],r=0,o=0;o<t;o++)if(o%4){var a=i[e.charCodeAt(o-1)]<<o%4*2,c=i[e.charCodeAt(o)]>>>6-o%4*2,u=a|c;n[r>>>2]|=u<<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,o=t.algo,a=[];!function(){for(var t=0;t<64;t++)a[t]=4294967296*e.abs(e.sin(t+1))|0}();var c=o.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,o=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],m=e[t+8],D=e[t+9],b=e[t+10],S=e[t+11],w=e[t+12],I=e[t+13],C=e[t+14],B=e[t+15],A=r[0],E=r[1],k=r[2],T=r[3];A=u(A,E,k,T,o,7,a[0]),T=u(T,A,E,k,c,12,a[1]),k=u(k,T,A,E,f,17,a[2]),E=u(E,k,T,A,p,22,a[3]),A=u(A,E,k,T,v,7,a[4]),T=u(T,A,E,k,g,12,a[5]),k=u(k,T,A,E,y,17,a[6]),E=u(E,k,T,A,_,22,a[7]),A=u(A,E,k,T,m,7,a[8]),T=u(T,A,E,k,D,12,a[9]),k=u(k,T,A,E,b,17,a[10]),E=u(E,k,T,A,S,22,a[11]),A=u(A,E,k,T,w,7,a[12]),T=u(T,A,E,k,I,12,a[13]),k=u(k,T,A,E,C,17,a[14]),A=l(A,E=u(E,k,T,A,B,22,a[15]),k,T,c,5,a[16]),T=l(T,A,E,k,y,9,a[17]),k=l(k,T,A,E,S,14,a[18]),E=l(E,k,T,A,o,20,a[19]),A=l(A,E,k,T,g,5,a[20]),T=l(T,A,E,k,b,9,a[21]),k=l(k,T,A,E,B,14,a[22]),E=l(E,k,T,A,v,20,a[23]),A=l(A,E,k,T,D,5,a[24]),T=l(T,A,E,k,C,9,a[25]),k=l(k,T,A,E,p,14,a[26]),E=l(E,k,T,A,m,20,a[27]),A=l(A,E,k,T,I,5,a[28]),T=l(T,A,E,k,f,9,a[29]),k=l(k,T,A,E,_,14,a[30]),A=d(A,E=l(E,k,T,A,w,20,a[31]),k,T,g,4,a[32]),T=d(T,A,E,k,m,11,a[33]),k=d(k,T,A,E,S,16,a[34]),E=d(E,k,T,A,C,23,a[35]),A=d(A,E,k,T,c,4,a[36]),T=d(T,A,E,k,v,11,a[37]),k=d(k,T,A,E,_,16,a[38]),E=d(E,k,T,A,b,23,a[39]),A=d(A,E,k,T,I,4,a[40]),T=d(T,A,E,k,o,11,a[41]),k=d(k,T,A,E,p,16,a[42]),E=d(E,k,T,A,y,23,a[43]),A=d(A,E,k,T,D,4,a[44]),T=d(T,A,E,k,w,11,a[45]),k=d(k,T,A,E,B,16,a[46]),A=h(A,E=d(E,k,T,A,f,23,a[47]),k,T,o,6,a[48]),T=h(T,A,E,k,_,10,a[49]),k=h(k,T,A,E,C,15,a[50]),E=h(E,k,T,A,g,21,a[51]),A=h(A,E,k,T,w,6,a[52]),T=h(T,A,E,k,p,10,a[53]),k=h(k,T,A,E,b,15,a[54]),E=h(E,k,T,A,c,21,a[55]),A=h(A,E,k,T,m,6,a[56]),T=h(T,A,E,k,B,10,a[57]),k=h(k,T,A,E,y,15,a[58]),E=h(E,k,T,A,I,21,a[59]),A=h(A,E,k,T,v,6,a[60]),T=h(T,A,E,k,S,10,a[61]),k=h(k,T,A,E,f,15,a[62]),E=h(E,k,T,A,D,21,a[63]),r[0]=r[0]+A|0,r[1]=r[1]+E|0,r[2]=r[2]+k|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),o=n;i[15+(s+64>>>9<<4)]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),i[14+(s+64>>>9<<4)]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8),t.sigBytes=4*(i.length+1),this._process();for(var a=this._hash,c=a.words,u=0;u<4;u++){var l=c[u];c[u]=16711935&(l<<8|l>>>24)|4278255360&(l<<24|l>>>8)}return a},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});function u(e,t,i,n,s,r,o){var a=e+(t&i|~t&n)+s+o;return(a<<r|a>>>32-r)+t}function l(e,t,i,n,s,r,o){var a=e+(t&n|i&~n)+s+o;return(a<<r|a>>>32-r)+t}function d(e,t,i,n,s,r,o){var a=e+(t^i^n)+s+o;return(a<<r|a>>>32-r)+t}function h(e,t,i,n,s,r,o){var a=e+(i^(t|~n))+s+o;return(a<<r|a>>>32-r)+t}t.MD5=r._createHelper(c),t.HmacMD5=r._createHmacHelper(c)}(Math),n.MD5)},function(e,t,i){var n;e.exports=(n=i(0),i(15),i(42),i(43),i(8),i(44),i(9),i(24),i(18),i(45),i(25),i(46),i(47),i(48),i(19),i(49),i(6),i(2),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),i(64),i(65),i(66),n)},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";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.createUUID32=t.arrayBufferToWordArray=t.convertToUuids=t.convertToServiceUuids=t.encrypt=t.ab2numbers=t.parseBroadcastData=t.hex2ab=t.hex2numbers=t.mergeObject=t.getProductInfoThroughPK=t.getFirstConnectType=t.splitIntoChunks=t.BTDevice2GDevice=t.merageLanLocalDevices=t.merageBleLocalDevices=t.getDeviceId=t.isSameDevice=t.advertisData2PkAndMac=t.numberArray2Uint8Array=t.str2Buf=t.isWXDevicesResult=t.unionBy=t.wrapErrorInfo=t.isError=t.compareWXSDKVersion=t.ab2hex=void 0;const s=i(0),r=n(i(4));function o(e){return Array.prototype.map.call(new Uint8Array(e),(function(e){return("00"+e.toString(16)).slice(-2)})).join("")}t.ab2hex=o,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};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=o(i);if(t.find(e=>e===s)){const e=o(n);return{productKey:s,mac:e}}{i=e.slice(0,16),n=e.slice(16),s=o(i);const t=o(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="",r=1;const a=new Uint8Array(e);for(;!(i>e.byteLength-1);){const c=a[i];if(c<=0||!c)break;if(e.byteLength<c+i+1)break;const u=e.slice(i+1,i+c+1);if(c>=6&&c<=8&&(n=o(u),16==n.length&&(n=n.substring(0,15))),16==c){const e=o(u).toLowerCase();t.find(t=>t===e)&&(s=e)}if(1==c){const e=o(u);r="1"===parseInt(e,16).toString(2).split("").pop()?1:0}i+=1+c}return{bleWorkStatus:r,mac:n,productKey:s}})(e,t):{mac:"",productKey:"",bleWorkStatus:1};t.isSameDevice=(e,t)=>e.mac===t.mac&&e.productKey===t.productKey;t.getDeviceId=e=>`${e.mac}${e.productKey}`;t.merageBleLocalDevices=(e,i)=>(e.map(e=>{e.isBleOnline=!1,e.bleWorkStatus=0}),i.map(i=>{const n=e.find(e=>(0,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=>(0,t.isSameDevice)(e,i));n?n.isLanOnline=!0:e.push(i)}),e);t.BTDevice2GDevice=(e,i)=>{let n={productKey:"",mac:"",bleWorkStatus:0},s={did:"",productKey:"",mac:"",bleWorkStatus:0,connectType:"NONE",isBleOnline:!0,isLanOnline:!1,isOnline:!1,name:e.localName,localName:e.localName,isBind:!1,bleDeviceID:e.deviceId,ctime:(new Date).getTime()};switch(e.communicationType){case"BLE_BROADCAST":try{r.default.log("parse BLE_BROADCAST");const t=c(u(e.advertisData));n.productKey=t.data.join(""),n.mac=t.mac,s.connectType="BLE_BROADCAST"}catch(e){}break;default:n=(0,t.advertisData2PkAndMac)(e.advertisData,i)}return s=Object.assign(Object.assign({},s),n),s};t.splitIntoChunks=(e,t)=>{const i=[];for(let n=0;n<e.length;n+=t)i.push(e.slice(n,n+t));return i};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);function a(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 t}function c(e){if(25!=(e=e.slice(0,25)).length)throw new Error("数据不合法");const t=`${l(e[0])}${l(e[1])}`;if(e[2]!==(255&e.slice(3).reduce((e,t)=>e+t,0)))throw new Error("校验和不合法");const i=l(e[3]),n=e.slice(5,5+e[4]).map(e=>l(e));return{mac:t,cmd:parseInt(i,16),data:n}}function u(e){return Array.prototype.map.call(new Uint8Array(e),(function(e){return e}))}function l(e,t=2){return`${new Array(t).fill(0).join("")}${e.toString(16)}`.slice(-t)}t.mergeObject=(e,t)=>{for(let i in t)null!=t[i]&&""!==t[i]&&(e[i]=t[i]);return e},t.hex2numbers=a,t.hex2ab=function(e){return new Uint8Array(a(e))},t.parseBroadcastData=c,t.ab2numbers=u;let d=0;function h(e,t){let i=1,n=t;return e.map(e=>{const t=65535&(e^n);return n=i-t&65535,i<<=1,l(t,4)})}t.encrypt=h;function f(e,t,i){if(i.length>22)throw new Error("最大长度为22");const n=[...i,...new Array(22-i.length).fill(0)],s=255&i.reduce((e,t)=>e+t,0),o=(t>>4<<12)+(s>>4<<8)+((15&t)<<4)+(15&s),a=Array.from({length:11},(e,t)=>(n[2*t]<<8)+n[2*t+1]);return r.default.log("明文",l(e,4),l((t<<8)+s,4),a.map(e=>l(e,4))),[l(e,4),l((t<<8)+s,4),...h(a,o)].map(e=>`${e.slice(2)}${e.slice(0,2)}`)}t.convertToServiceUuids=({len:e=null,data:i=null,index:n=0,mac:s,cmd:r=147})=>{if(i&&i.length>20)throw new Error("data 最大 20");const o=null==e?Math.round(18*Math.random())+1:e,a=null==i?Array.from({length:o},e=>Math.round(255*Math.random())):i,c=[r,o,...a],u=f(s,(()=>{const e=d;return d=d+1&255,e})(),c);return[...new Set(u)].length!==u.length?(0,t.convertToServiceUuids)({len:o,data:a,index:n++,mac:s}):u},t.convertToUuids=f,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)},t.createUUID32=function(){let e=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){let i=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==t?i:3&i|8).toString(16)}))}},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 o(e){try{c(n.next(e))}catch(e){r(e)}}function a(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(o,a)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.formatBinary=t.formatEnum=t.padBoradcastData=t.unpack=t.pack=t.getVariableLength=void 0;const r=s(i(20)),o=i(3),a=e=>-1!==e.indexOf("uint")?"number":e,c=(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),r=-1===s?0:s;n=(0,o.fillString)(r.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=(0,o.fillString)(e.toString(2),8*i.position.len);break}case"binary":{let e=t[i.name]||"";e instanceof Array&&(e=(0,o.arrayToString)(e));const s=(0,o.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+=(0,o.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}`},u=(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+=(0,o.fillString)(parseInt(s,2).toString(16),2)}return(0,o.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],r=[0],u=[0,147],l=[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=(0,o.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((0,o.completeBlock)(g)),g=""),g=((e,i)=>{const n=a(e.data_type);return i=c(n,t,e)+i})(e,g)):(g.length>0&&(h=h.concat((0,o.completeBlock)(g)),g=""),h=((e,i)=>{const n=a(e.data_type),s=c(n,t,e);return i=i.concat((0,o.completeBlock)(s)),console.log("handleOther",s,i),i})(e,h)),v=e}),g.length>0&&(h=h.concat((0,o.completeBlock)(g)),g="");const y=r.concat(u).concat(l).concat(h),_=d(y);return s.push(..._),{data:s.concat(y),raw:{header:[0,0,0,3],flag:r,len:_,headerCmd:u,sn:l,cmd:h}}};function d(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 h(e,t){return e===t||"ALL"===e}function f({attrs:e,activeAttrs:t,flagString:i,cmdData:n,accumulate:s}){let r=0,o={},a=0;return["status_writable","status_readonly","alert","fault"].map(c=>{const u=e.filter(e=>h(c,e.type)).length,{cmd:l,cmdDataLength:d}=p({type:c,attrs:e.slice(a,a+u),activeAttrs:t,flagString:i.substring(a,a+u),cmdData:n.slice(r,n.length),accumulate:s});return r+=d,o=Object.assign(Object.assign({},o),l),a+=u,null}),o}function p({type:e,attrs:t,activeAttrs:i,cmdData:n,flagString:s,accumulate:r}){let c=0,l=0,d=0;return i.map(t=>{if(h(e,t.type)){const e=t.position.len*("bit"===t.position.unit?1:8);"bool"===t.data_type||"enum"===t.data_type?l+=e:d+=e}return null}),c=Math.ceil(d/8)+Math.ceil(l/8),{cmdDataLength:c,cmd:function({attrs:e,flagString:t,boolEnumLength:i,cmdData:n,accumulate:s}){const r={};let c=0;for(let l=0;l<t.length;l++)if(e[l]&&"1"===t[l]){const{data_type:t,position:{len:s}}=e[l];let d="";if("bool"===t||"enum"===t){let e="";n.slice(0,i).map(t=>(e+=(0,o.fillString)(t.toString(2),8),null));const t=e.length-c;d=e.substring(t-s,t),c+=s}else{const e=i,t=i+s;n.slice(e,t).map(e=>(d+=(0,o.fillString)(e.toString(2),8),null)),i+=s}const h=a(t);r[e[l].name]=u(h,d,e[l])}else if(s){const t=e[l]||{position:{len:0}};"byte"===t.position.unit?i+=t.position.len:c+=t.position.len}return r}({attrs:t,flagString:s,boolEnumLength:Math.ceil(l/8),cmdData:n,accumulate:r})}}t.getVariableLength=d;t.unpack=(e,t)=>n(void 0,void 0,void 0,(function*(){const i=yield r.default.getConfigFile(t);if(i){const n=function({config:e=[],data:t}){let i,n,s="";const r={header:(0,o.arrayToString)(t.slice(0,4)),flag:"",len:"",cmd:"",sn:"",action:"",payload:""},a=e;let c=(0,o.checkHeader)(t);if(!1===c)return;const u=t.slice(c,t.length),l=(0,o.getProtocolLen)(u);if(c+=l,r.len=(0,o.arrayToString)(u.slice(0,l)),c+=1,r.flag=(0,o.arrayToString)(t.slice(c-1,c)),c+=2,r.cmd=(0,o.arrayToString)(t.slice(c-2,c)),r.sn="",("0093"===r.cmd||"0094"===r.cmd)&&(c+=4,r.sn=(0,o.arrayToString)(t.slice(c-4,c)),"01"===r.flag)){c+=2,c+=parseInt((0,o.arrayToString)(t.slice(c-2,c)),16)}c+=1,r.action=(0,o.arrayToString)(t.slice(c-1,c)),i=parseInt(r.action,16),r.payload=(0,o.arrayToString)(t.slice(c,t.length));const d=t.slice(c,t.length);let h=a;1===i&&(h=a.filter(e=>"status_writable"===e.type));const v=JSON.parse(JSON.stringify(h)),g=Math.ceil(h.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 m="";y.map(e=>(m+=(0,o.fillString)(e.toString(2),8),null)),i>=17&&i<=20&&(h=h.filter((e,t)=>{const i=m.length-1-t;return"1"===m[i]})),"0090"===r.cmd||"0093"===r.cmd?(s="App 透传数据到 Dev",n="APP2DEV"):"0091"===r.cmd||"0094"===r.cmd?(s="Dev 收到控制命令后应答到 App",n="DEV2APP"):(s="非法数据",n="UNKNOW");let D={};switch(i){case 1:s="App 下发数据到 Dev",D=f({attrs:v,activeAttrs:h,flagString:m.split("").reverse().join(""),cmdData:_,accumulate:!0});break;case 2:return s="App 下发查询指令到 Dev",{kvData:null,rawData:r,message:s,messageType:n};case 3:s="Dev 回复查询指令到 App",D=f({attrs:v,activeAttrs:h,flagString:m.split("").reverse().join(""),cmdData:_,accumulate:!0});break;case 4:s="Dev 上报状态到 App",D=f({attrs:v,activeAttrs:h,flagString:m.split("").reverse().join(""),cmdData:_,accumulate:!0});break;case 5:return s="App 透传数据到 Dev",{kvData:null,rawData:r,message:s,messageType:n};case 6:return s="Dev 透传数据到 App",{kvData:null,rawData:r,message:s,messageType:n};case 7:return s="App 下发控制子设备",{kvData:null,rawData:r,message:s,messageType:n};case 8:return s="App 读取子设备数据",{kvData:null,rawData:r,message:s,messageType:n};case 9:return s="Dev 中控回复ACK",{kvData:null,rawData:r,message:s,messageType:n};case 10:return s="子设备上报状态到 App",{kvData:null,rawData:r,message:s,messageType:n};case 11:return s="App 下发添加子设备指令",{kvData:null,rawData:r,message:s,messageType:n};case 12:return s="App 下发删除子设备",{kvData:null,rawData:r,message:s,messageType:n};case 13:return s="App 获取中控子设备列表",{kvData:null,rawData:r,message:s,messageType:n};case 14:return s="中控响应字设备查询到 App",{kvData:null,rawData:r,message:s,messageType:n};case 15:return s="子设备列表变更通知到 App",{kvData:null,rawData:r,message:s,messageType:n};case 16:return s="Dev 子设备上下线状态变更通知",{kvData:null,rawData:r,message:s,messageType:n};case 17:s="App 下发变长数据到 Dev",D=p({type:"ALL",attrs:v,activeAttrs:h,flagString:m.split("").reverse().join(""),cmdData:_}).cmd;break;case 18:return s="App 下发变长查询到 Dev",{kvData:null,rawData:r,message:s,messageType:n};case 19:s="Dev 变长回复查询指令到 App",D=p({type:"ALL",attrs:v,activeAttrs:h,flagString:m.split("").reverse().join(""),cmdData:_}).cmd;break;case 20:s="Dev 变长上报状态到 App",D=p({type:"ALL",attrs:v,activeAttrs:h,flagString:m.split("").reverse().join(""),cmdData:_}).cmd;break;case 114:return s="App 向网关发送数据",{kvData:null,rawData:r,message:s,messageType:n};case 115:return s="Dev 网关上报数据到 App",{kvData:null,rawData:r,message:s,messageType:n};case 116:return s="App 通知网关删除子设备",{kvData:null,rawData:r,message:s,messageType:n};default:return{kvData:null,rawData:r,message:s,messageType:n}}return 0===a.length?{kvData:null,rawData:r,message:s,messageType:n}:{kvData:D,rawData:r,message:s,messageType:n}}({config:(yield i).entities[0].attrs,data:e});return n.kvData&&(n.kvData=yield v(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 r.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=d(t);return(0,o.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 s=yield r.default.getAttrItem(t,n);if(s&&"enum"===s.data_type){if("int"===i&&"string"==typeof e[n]){const t=s.enum.findIndex(t=>t===e[n]);e[n]=t||0}"string"===i&&"number"==typeof e[n]&&(e[n]=s.enum[e[n]])}}return e}));const v=(e,t,i)=>n(void 0,void 0,void 0,(function*(){for(let n in e){const s=yield r.default.getAttrItem(t,n);s&&"binary"===s.data_type&&("object"===i&&"string"==typeof e[n]&&(e[n]=(0,o.hexStrint2byte)(e[n])),"string"===i&&"object"==typeof e[n]&&(e[n]=(0,o.arrayToString)(e[n])))}return e}));t.formatBinary=v},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getGlobalData=t.setGlobalData=void 0;const n={};t.setGlobalData=function(e,t){n[e]=t},t.getGlobalData=function(e){return n[e]}},function(e,t,i){var n,s,r,o,a,c;e.exports=(c=i(0),s=(n=c).lib,r=s.Base,o=s.WordArray,(a=n.x64={}).Word=r.extend({init:function(e,t){this.high=e,this.low=t}}),a.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 o.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){e.exports=JSON.parse('{"name":"mini_program_gizwits_sdk","version":"3.6.27-socketResend","description":"更新类型","main":"./dist/index.js","scripts":{"test":"node_modules/mocha/bin/_mocha -r ts-node/register tests/**/*.spec.ts -file ./tests/setup-wx.js -timeout 60s","testBle":"node_modules/mocha/bin/_mocha -r ts-node/register tests/utils/randomCode.spec.ts -file ./tests/setup-wx.js -timeout 60s","build":"rm -rf ./dist && webpack","release":"npm run build && release-it","cover":"istanbul cover node_modules/mocha/bin/_mocha -- -r ts-node/register tests/**/*.spec.ts -file ./tests/setup-wx.js -timeout 60s","coveralls":"npm run cover -- --report lcovonly && cat ./coverage/lcov.info | coveralls"},"repository":{"type":"git","url":"git+https://github.com/gizwits/mini_program_gizwits_sdk.git"},"keywords":["gizwits","miniprogram","sdk"],"devDependencies":{"@babel/plugin-transform-modules-commonjs":"^7.12.1","@release-it/conventional-changelog":"^2.0.0","@types/chai":"^4.2.11","@types/crypto-js":"^4.0.2","@types/mocha":"^7.0.2","@types/node":"^12.12.14","@types/sinon":"^10.0.6","chai":"^4.2.0","coveralls":"^3.0.11","istanbul":"^1.1.0-alpha.1","miniprogram-api-typings":"^3.9.0","mocha":"^7.1.1","release-it":"^14.2.2","sinon":"^9.2.4","ts-loader":"^6.2.2","ts-node":"^8.8.1","typescript":"^4.9.5","uglifyjs-webpack-plugin":"^2.2.0","webpack":"^4.42.1","webpack-bundle-analyzer":"^4.5.0","webpack-cli":"^3.3.11"},"author":"gizwits","license":"ISC","bugs":{"url":"https://github.com/gizwits/mini_program_gizwits_sdk/issues"},"homepage":"https://github.com/gizwits/mini_program_gizwits_sdk#readme","dependencies":{"crypto-js":"^4.1.1"}}')},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;e.exports=(n=i(0),function(e){var t=n,i=t.lib,s=i.WordArray,r=i.Hasher,o=t.algo,a=[],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&&(a[s]=i(e.pow(n,.5))),c[s]=i(e.pow(n,1/3)),s++),n++}();var u=[],l=o.SHA256=r.extend({_doReset:function(){this._hash=new s.init(a.slice(0))},_doProcessBlock:function(e,t){for(var i=this._hash.words,n=i[0],s=i[1],r=i[2],o=i[3],a=i[4],l=i[5],d=i[6],h=i[7],f=0;f<64;f++){if(f<16)u[f]=0|e[t+f];else{var p=u[f-15],v=(p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3,g=u[f-2],y=(g<<15|g>>>17)^(g<<13|g>>>19)^g>>>10;u[f]=v+u[f-7]+y+u[f-16]}var _=n&s^n&r^s&r,m=(n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22),D=h+((a<<26|a>>>6)^(a<<21|a>>>11)^(a<<7|a>>>25))+(a&l^~a&d)+c[f]+u[f];h=d,d=l,l=a,a=o+D|0,o=r,r=s,s=n,n=D+(m+_)|0}i[0]=i[0]+n|0,i[1]=i[1]+s|0,i[2]=i[2]+r|0,i[3]=i[3]+o|0,i[4]=i[4]+a|0,i[5]=i[5]+l|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(l),t.HmacSHA256=r._createHmacHelper(l)}(Math),n.SHA256)},function(e,t,i){var n,s,r,o;e.exports=(n=i(0),r=(s=n).lib.Base,o=s.enc.Utf8,void(s.algo.HMAC=r.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=o.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(),a=s.words,c=r.words,u=0;u<i;u++)a[u]^=1549556828,c[u]^=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";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function o(e){try{c(n.next(e))}catch(e){r(e)}}function a(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(o,a)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(7));const o=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.getConfigFileMap={},this.getConfigFile=e=>{if(!this.data[e]){if(this.getConfigFileMap[e])return this.getConfigFileMap[e];const t=new Promise(t=>n(this,void 0,void 0,(function*(){var i;const n=`/app/datapoint?product_key=${e}`,s=yield(0,r.default)(`${n}`,{method:"GET"});s.success&&(null===(i=s.data)||void 0===i?void 0:i.entities)?(this.data[e]=s.data,t(this.data[e]),wx.setStorageSync(this.key,JSON.stringify(this.data))):t(null),this.getConfigFileMap[e]=null})));return this.getConfigFileMap[e]=t,t}return Promise.resolve(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}))}};o.init(),t.default=o},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 o(e){try{c(n.next(e))}catch(e){r(e)}}function a(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(o,a)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.controlDevice=t.editBindInfo=t.safeRegister=t.checkDeviceRegister=t.unbindDevice=t.bindMac=t.getBindingList=void 0;const r=i(10),o=s(i(7)),a=s(i(89)),c=i(90),u=s(i(4));class l{constructor(){this.pad=(e,t)=>{},this.unpad=e=>{const t=e.sigBytes;let i=0,n=1;const s=e.toString(r.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(0,o.default)("/app/bindings?show_disabled=0&limit=1000&skip=0",{method:"GET"});if(e.success){return{success:!0,data:e.data.devices.map(e=>Object.assign(Object.assign({},e),{productKey:e.product_key,mac:e.mac,did:e.did,host:e.host,localName:"",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:s,beOwner:r}){return n(this,void 0,void 0,(function*(){const n={mac:e,product_key:t,dev_alias:s,set_owner:r},{Signature:a,timestamp:u}=(0,c.psKeySign)(i);return yield(0,o.default)("/app/bind_mac",{method:"POST",data:n,headers:{"X-Gizwits-Signature":a,"X-Gizwits-Timestamp":u}})}))},t.unbindDevice=function({devices:e}){return n(this,void 0,void 0,(function*(){return yield(0,o.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=(0,a.default)({SSID:e,password:t,pks:i});let s="";return n.map(e=>{s+=`${e},`}),s=s.substring(0,s.length-1),yield(0,o.default)(`/app/device_register?random_codes=${s}`,{method:"get"})}))},t.safeRegister=function({productKey:e,productSecret:t,mac:i,passcode:s,gwDid:a,isReset:c}){return n(this,void 0,void 0,(function*(){let n=`is_reset=${c?1:0}&mac=${i}&passcode=${s}`;a&&(n+=`&gw_did=${a}`);const u=r.enc.Hex.parse(t),l=r.enc.Hex.parse(""),h=r.enc.Utf8.parse(n),f=r.AES.encrypt(h,u,{iv:l,mode:r.mode.ECB,padding:r.pad.Pkcs7}).ciphertext.toString().toUpperCase(),p=yield(0,o.default)(`/dev/${e}/device`,{method:"POST",data:{data:f},headers:{"content-type":"application/x-www-form-urlencoded"}},!1);if(p.success){const e=d({productSecret:t,iv:l,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 d=({productSecret:e,data:t,iv:i})=>{const n=r.enc.Hex.parse(e),s=r.enc.Hex.parse(t);const o=r.AES.decrypt(r.enc.Base64.stringify(s),n,{iv:i,mode:r.mode.ECB,padding:new l}).toString(r.enc.Utf8),a=[];return o.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(0,o.default)(`/app/bindings/${i}`,{method:"PUT",data:n},!0)}))},t.controlDevice=function(e){return n(this,void 0,void 0,(function*(){const{did:t,raw:i,attrs:n}=e,s={};i&&(s.raw=i),n&&(s.attrs=n);const r=yield(0,o.default)(`/app/control/${t}`,{method:"POST",data:s},!0);return u.default.log("GIZ_SDK: ControlDevice",e,r),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 o(e){try{c(n.next(e))}catch(e){r(e)}}function a(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(o,a)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(11)),o=s(i(5)),a=i(21),c=s(i(4)),u=s(i(23));t.default=class{constructor(e,t,i,s,l){this.ssid="",this.bssid="",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&&(u.default.cancel(),this.setDeviceOnboardingDeployRej({success:!1,err:o.default.GIZ_SDK_ONBOARDING_STOPPED})),this.cleanTimeout()},this.appendExtendData=e=>{const t=-(new Date).getTimezoneOffset()/60;let i=Math.floor(t),n=0,s="",r=t-i;return s=i>=0&&i<=9?String.fromCharCode("0".charCodeAt(0)+i):i>9?String.fromCharCode(i-10+"A".charCodeAt(0)):String.fromCharCode(-i-1+"a".charCodeAt(0)),r<0&&(r=-r),n=r>=0&&r<.25?0:r>=.25&&r<.5?1:r>=.5&&r<.75?2:3,e+"\00"+s+n+"309"},this.hasTimeoutHandler=e=>!!this.timeoutHandler&&(e&&e({success:!1,err:o.default.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING}),!0),this.handleTimeout=()=>{if(this.setDeviceOnboardingDeployRej){const e={errorCode:o.default.CONFIG_TIME_OUT,errorMessage:"time out"};this.setDeviceOnboardingDeployRej({success:!1,err:{errorCode:o.default.CONFIG_TIME_OUT,errorMessage:"time out"}}),u.default.appendEvent({name:"WIFI_CONFIG_FAIL",message:JSON.stringify({error:e})})}this.timeoutHandler=null},this.searchDevice=({ssid:e,password:t})=>new Promise((i,s)=>{u.default.appendEvent({name:"START_SEARCH_RANDOM_CODE",message:""}),c.default.debug("GIZ_SDK: 开始大循环搜索设备");const l=()=>n(this,void 0,void 0,(function*(){var n,d;if(this.hasTimeoutHandler())try{const h=yield(0,a.checkDeviceRegister)({SSID:e,password:t,productKeys:this.specialProductKeys});if((null===(n=h.err)||void 0===n?void 0:n.errorCode)===o.default.GIZ_OPENAPI_TOKEN_INVALID.errorCode)return void s({success:!1,err:o.default.GIZ_OPENAPI_TOKEN_INVALID});h.err||0===h.data.length?(yield(0,r.default)(250),!this.disableSearchDevice&&l()):(null===(d=this.eventCallBack)||void 0===d||d.call(this,{event:"GIZ_CONFIG_SUCCESS"}),u.default.appendEvent({name:"START_SEARCH_RANDOM_CODE_SUCCESS",message:JSON.stringify(h)}),c.default.debug("GIZ_SDK: 大循环搜索到设备",h),i({success:!0,data:h.data}))}catch(e){yield(0,r.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=>(c.default.log("GIZ_SDK: start bind device"),u.default.appendEvent({name:"START_BIND_DEVICE",message:""}),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(0,a.bindMac)({mac:e.mac,productKey:e.productKey,productSecret:i})});try{const s=yield Promise.all(n),r=e.filter((e,t)=>{const i=s[t];return i&&i.success});if(r.length>0)c.default.log("GIZ_SDK: bind device success",r),u.default.appendEvent({name:"BIND_DEVICE_SUCCESS",message:JSON.stringify(r)}),t({success:!0,data:r});else{c.default.log("GIZ_SDK: bind device error",s);const t={success:!1,data:e,err:o.default.GIZ_SDK_BIND_DEVICE_FAILED};u.default.appendEvent({name:"BIND_DEVICE_FAIL",message:JSON.stringify(t)}),i(t)}}catch(e){i(e)}})))),this.ssid=e,this.bssid=t,this.password=i,this.specialProductKeys=s,this.specialProductKeySecrets=l}}},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 o(e){try{c(n.next(e))}catch(e){r(e)}}function a(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(o,a)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(16),r=i(14),o=i(12),a=i(7);t.default=new class{constructor(){this.isSuccess=!1,this.productKey="",this.logs=[],this.init=e=>{this.clean(),this.productKey=e.productKey,this.ssid=e.ssid,this.mode=e.mode,this.isBind=e.isBind,this.timeout=e.timeout},this.getEnv=()=>{try{wx.getSystemInfoAsync({success:e=>{const t={wxSdkVersion:e.SDKVersion,gizwitsSdkVersion:s.version,appID:(0,r.getGlobalData)("appID"),bluetoothEnabled:e.bluetoothEnabled,locationEnabled:e.locationEnabled,wifiEnabled:e.wifiEnabled},i={brand:e.brand,model:e.model,pixelRatio:e.pixelRatio,systemVersion:e.system,platform:e.platform};this.mobileInfo=i,this.appInfo=t}})}catch(e){console.error(e)}},this.updateProductKey=e=>{this.productKey=e},this.appendEvent=e=>{try{this.logs.push(Object.assign(Object.assign({},e),{timestamp:Math.floor((new Date).getTime()/1e3)})),"WIFI_CONFIG_SUCCESS"===e.name&&(this.isSuccess=!0),"WIFI_CONFIG_SUCCESS"!==e.name&&"WIFI_CONFIG_FAIL"!==e.name||this.report()}catch(e){console.error(e)}},this.report=()=>n(this,void 0,void 0,(function*(){try{if(!this.productKey)return;if(0===this.logs.length)return;if(this.logs[0]&&"START_WIFI_CONFIG"!==this.logs[0].name)return;const e=new Date,t=(0,o.createUUID32)(),i=this.mobileInfo,n=this.appInfo,s={ssid:this.ssid,mode:this.mode,timeout:this.timeout,isBind:this.isBind},c={origin:"MINI-WX",mobileInfo:i,userInfo:{uid:(0,r.getGlobalData)("uid")},appInfo:n,eventID:t,eventType:"ConfigNetWorkDetail",monitorTarget:s,eventDetail:{success:this.isSuccess,processDetails:this.logs},time:e,timeStamp:Math.floor(e.getTime()/1e3)};if(console.debug("report data",c),this.productKey){const e=yield(0,a.statisticRequest)(`v2/products/${this.productKey}/devices/dist-net`,{method:"POST",body:c});e.success?console.debug("===已成功上报结束配网事件==="):console.error("===上报结束配网事件失败===",e)}this.clean()}catch(e){console.error(e)}})),this.cancel=()=>n(this,void 0,void 0,(function*(){return this.isSuccess=!1,this.appendEvent({name:"WIFI_CONFIG_CANCEL",message:""}),yield this.report()})),this.clean=()=>{this.logs=[],this.isSuccess=!1},this.getEnv()}}},function(e,t,i){var n,s,r,o,a,c,u,l;e.exports=(l=i(0),s=(n=l).lib,r=s.WordArray,o=s.Hasher,a=n.algo,c=[],u=a.SHA1=o.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],o=i[3],a=i[4],u=0;u<80;u++){if(u<16)c[u]=0|e[t+u];else{var l=c[u-3]^c[u-8]^c[u-14]^c[u-16];c[u]=l<<1|l>>>31}var d=(n<<5|n>>>27)+a+c[u];d+=u<20?1518500249+(s&r|~s&o):u<40?1859775393+(s^r^o):u<60?(s&r|s&o|r&o)-1894007588:(s^r^o)-899497514,a=o,o=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]+o|0,i[4]=i[4]+a|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=o.clone.call(this);return e._hash=this._hash.clone(),e}}),n.SHA1=o._createHelper(u),n.HmacSHA1=o._createHmacHelper(u),l.SHA1)},function(e,t,i){var n;e.exports=(n=i(0),i(15),function(){var e=n,t=e.lib.Hasher,i=e.x64,s=i.Word,r=i.WordArray,o=e.algo;function a(){return s.create.apply(s,arguments)}var c=[a(1116352408,3609767458),a(1899447441,602891725),a(3049323471,3964484399),a(3921009573,2173295548),a(961987163,4081628472),a(1508970993,3053834265),a(2453635748,2937671579),a(2870763221,3664609560),a(3624381080,2734883394),a(310598401,1164996542),a(607225278,1323610764),a(1426881987,3590304994),a(1925078388,4068182383),a(2162078206,991336113),a(2614888103,633803317),a(3248222580,3479774868),a(3835390401,2666613458),a(4022224774,944711139),a(264347078,2341262773),a(604807628,2007800933),a(770255983,1495990901),a(1249150122,1856431235),a(1555081692,3175218132),a(1996064986,2198950837),a(2554220882,3999719339),a(2821834349,766784016),a(2952996808,2566594879),a(3210313671,3203337956),a(3336571891,1034457026),a(3584528711,2466948901),a(113926993,3758326383),a(338241895,168717936),a(666307205,1188179964),a(773529912,1546045734),a(1294757372,1522805485),a(1396182291,2643833823),a(1695183700,2343527390),a(1986661051,1014477480),a(2177026350,1206759142),a(2456956037,344077627),a(2730485921,1290863460),a(2820302411,3158454273),a(3259730800,3505952657),a(3345764771,106217008),a(3516065817,3606008344),a(3600352804,1432725776),a(4094571909,1467031594),a(275423344,851169720),a(430227734,3100823752),a(506948616,1363258195),a(659060556,3750685593),a(883997877,3785050280),a(958139571,3318307427),a(1322822218,3812723403),a(1537002063,2003034995),a(1747873779,3602036899),a(1955562222,1575990012),a(2024104815,1125592928),a(2227730452,2716904306),a(2361852424,442776044),a(2428436474,593698344),a(2756734187,3733110249),a(3204031479,2999351573),a(3329325298,3815920427),a(3391569614,3928383900),a(3515267271,566280711),a(3940187606,3454069534),a(4118630271,4000239992),a(116418474,1914138554),a(174292421,2731055270),a(289380356,3203993006),a(460393269,320620315),a(685471733,587496836),a(852142971,1086792851),a(1017036298,365543100),a(1126000580,2618297676),a(1288033470,3409855158),a(1501505948,4234509866),a(1607167915,987167468),a(1816402316,1246189591)],u=[];!function(){for(var e=0;e<80;e++)u[e]=a()}();var l=o.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],o=i[3],a=i[4],l=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,m=o.high,D=o.low,b=a.high,S=a.low,w=l.high,I=l.low,C=d.high,B=d.low,A=h.high,E=h.low,k=f,T=p,O=v,x=g,P=y,L=_,M=m,N=D,R=b,H=S,U=w,K=I,G=C,F=B,j=A,z=E,W=0;W<80;W++){var V,Z,Y=u[W];if(W<16)Z=Y.high=0|e[t+2*W],V=Y.low=0|e[t+2*W+1];else{var $=u[W-15],J=$.high,X=$.low,q=(J>>>1|X<<31)^(J>>>8|X<<24)^J>>>7,Q=(X>>>1|J<<31)^(X>>>8|J<<24)^(X>>>7|J<<25),ee=u[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=u[W-7],oe=re.high,ae=re.low,ce=u[W-16],ue=ce.high,le=ce.low;Z=(Z=(Z=q+oe+((V=Q+ae)>>>0<Q>>>0?1:0))+ne+((V+=se)>>>0<se>>>0?1:0))+ue+((V+=le)>>>0<le>>>0?1:0),Y.high=Z,Y.low=V}var de,he=R&U^~R&G,fe=H&K^~H&F,pe=k&O^k&P^O&P,ve=T&x^T&L^x&L,ge=(k>>>28|T<<4)^(k<<30|T>>>2)^(k<<25|T>>>7),ye=(T>>>28|k<<4)^(T<<30|k>>>2)^(T<<25|k>>>7),_e=(R>>>14|H<<18)^(R>>>18|H<<14)^(R<<23|H>>>9),me=(H>>>14|R<<18)^(H>>>18|R<<14)^(H<<23|R>>>9),De=c[W],be=De.high,Se=De.low,we=j+_e+((de=z+me)>>>0<z>>>0?1:0),Ie=ye+ve;j=G,z=F,G=U,F=K,U=R,K=H,R=M+(we=(we=(we=we+he+((de+=fe)>>>0<fe>>>0?1:0))+be+((de+=Se)>>>0<Se>>>0?1:0))+Z+((de+=V)>>>0<V>>>0?1:0))+((H=N+de|0)>>>0<N>>>0?1:0)|0,M=P,N=L,P=O,L=x,O=k,x=T,k=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+k+(p>>>0<T>>>0?1:0),g=s.low=g+x,s.high=v+O+(g>>>0<x>>>0?1:0),_=r.low=_+L,r.high=y+P+(_>>>0<L>>>0?1:0),D=o.low=D+N,o.high=m+M+(D>>>0<N>>>0?1:0),S=a.low=S+H,a.high=b+R+(S>>>0<H>>>0?1:0),I=l.low=I+K,l.high=w+U+(I>>>0<K>>>0?1:0),B=d.low=B+F,d.high=C+G+(B>>>0<F>>>0?1:0),E=h.low=E+z,h.high=A+j+(E>>>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(l),e.HmacSHA512=t._createHmacHelper(l)}(),n.SHA512)},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.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=n(i(1)),r=i(3);class o extends s.default{constructor(e){super(e),this.passcode="";let t=0;const i=parseInt((0,r.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}}o.pack=()=>[0,0,0,3,3,0,0,6],t.default=o},function(e,t,i){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=n(i(1)),r=i(3);class o extends s.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((0,r.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}}}o.pack=({passcode:e})=>{let t=[0];const i=(0,r.hexStrint2byte)((0,r.fillString)(e.length.toString(16),4)),n=(0,r.string2Bytes)(e),s=[0].concat([0,8]).concat(i).concat(n);return t=(0,r.hexStrint2byte)(s.length.toString(16)),[0,0,0,3].concat(t).concat(s)},t.default=o},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 o(e){try{c(n.next(e))}catch(e){r(e)}}function a(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(o,a)}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.__decorate||function(e,t,i,n){var s,r=arguments.length,o=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,n);else for(var a=e.length-1;a>=0;a--)(s=e[a])&&(o=(r<3?s(o):r>3?s(t,i,o):s(t,i))||o);return r>3&&o&&Object.defineProperty(t,i,o),o},s=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function o(e){try{c(n.next(e))}catch(e){r(e)}}function a(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(o,a)}c((n=n.apply(e,t||[])).next())}))},r=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},o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.BleHandle=void 0;const a=o(i(4)),c=o(i(27)),u=i(13),l=o(i(31)),d=o(i(28)),h=o(i(1)),f=i(3),p=i(70),v=o(i(11)),g=i(10),y=i(32),_=i(12),m=i(34),D=o(i(29)),b=i(80),S=o(i(5)),w=o(i(81)),I=o(i(82)),C=o(i(83)),B=o(i(84)),A=o(i(85)),E=o(i(86)),k=o(i(87));function T(e){return function(t,i,n){const{value:s}=n;n.value=function(...t){return s.apply(this,t).then(i=>{var{_failureType_:n}=i,s=r(i,["_failureType_"]);return(0,p.reportEvent)({device:t[0],eventID:this.__event_id__,eventType:e,success:s.success}),Object.assign(Object.assign({},s),{_failureType_:e})})}}}class O extends D.default{set offlineThreshold(e){this._offlineThreshold=e}get offlineThreshold(){return this._offlineThreshold||1e4}constructor({pks:e=[],bleHandleParams:t={serviceUUIDSuffix:"abf0",characteristicUUIDSuffix:"abf7"},offlineThreshold:i}){super(),this.connectedList=[],this.connectingDevId=null,this.pks=[],this.listenDevOfflineTimer=null,this.methodQueue=Promise.resolve(),this.boradcastDataCache={},this.validBoradcastCmd=[152,154,25,148],this.baseServices=["ABF8","ABF0","F0AB","F8AB"],this.tmpBleData="",this.tmpDataNum=0,this.disableScanFlag=!1,this.peripheralServer=null,this.isActive=!0,this.isInitSuccess=!1,this.isRunInit=!1,this._offlineThreshold=null,this.scanList=[],this.onBluetoothAdapterStateChange=e=>{a.default.debug("onBluetoothAdapterStateChange",e,this.isRunInit,this.isInitSuccess),e.available?this.isRunInit&&!1===this.isInitSuccess&&this.init():(this.scanList=[],this.notifyDevices())},this.onAppShow=()=>{this.isActive=!0,this.scanList.map(e=>{e.ctime=Date.now()})},this.onAppHide=()=>{this.isActive=!1},this.listenDevOffline=()=>{this.listenDevOfflineTimer=setInterval(()=>{if(!this.isActive)return;const e=(new Date).getTime(),t=this.scanList.filter(t=>{const i=this.connectedList.find(e=>t.bleDeviceID==e.deviceId),n=this.connectingDevId===t.bleDeviceID;return!(!i&&!n)||("BLE_BROADCAST"===t.connectType?e-t.ctime<2*this.offlineThreshold:e-t.ctime<this.offlineThreshold)});t.length!==this.scanList.length&&(this.scanList=t,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=>{a.default.error("openBluetoothAdapter fail",new Error(JSON.stringify(e))),this.notifyError({errMsg:e.errMsg,errCode:-1}),i({success:!1,err:e})}})}),this.handleOnBLECharacteristicValueChange=e=>s(this,void 0,void 0,(function*(){if(!e.value)return;const t=(0,_.ab2hex)(e.value);try{const i=new h.default((0,f.hexStrint2byte)(t));this.tmpBleData=t,this.tmpDataNum=i.len-e.value.byteLength+4+Math.ceil(i.len.toString(2).length/8)}catch(i){this.tmpBleData&&(this.tmpBleData+=t,this.tmpDataNum-=e.value.byteLength)}this.tmpDataNum>0||!this.tmpBleData||(this.notiDeviceDataToSdk(e,this.tmpBleData),this.tmpBleData="",this.tmpDataNum=0)})),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=()=>s(this,void 0,void 0,(function*(){this.isRunInit=!0;const{platform:e}=wx.getSystemInfoSync();yield this.openBluetoothAdapter(),"ios"===e&&(yield this.openBluetoothAdapter("peripheral"));let t=!0;try{this.peripheralServer=(yield wx.createBLEPeripheralServer()).server,a.default.info("GIZ_SDK: 广播初始化成功",this.peripheralServer)}catch(e){a.default.error("GIZ_SDK: 广播初始化失败",new Error(JSON.stringify(e))),t=!1}if("android"===e&&!1===t)return{success:!1,message:"Android: GIZ_SDK初始化蓝牙广播失败"};const i=yield this.getBluetoothAdapterState();return this.isInitSuccess=!0,wx.onBluetoothDeviceFound(e=>{this.handleBluetoothDeviceFound(e)}),i})),this.checkPermission=()=>s(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){return a.default.log("授权失败",e),this.openBluetoothAdapter(),this.notifyError({errMsg:e.errMsg,errCode:-1}),{success:!1}}})),this.getBluetoothAdapterState=()=>s(this,void 0,void 0,(function*(){a.default.log("getBluetoothAdapterState",yield wx.getBluetoothAdapterState());const e=yield wx.getBluetoothAdapterState(),{errMsg:t,available:i}=e,n=r(e,["errMsg","available"]);return{data:Object.assign({},n),err:(0,_.wrapErrorInfo)(t),success:i}})),this.getDeviceStatus=(e,t,i,n)=>s(this,void 0,void 0,(function*(){const s=yield l.default.pack(t,i,n);return s?yield this.write(e,(0,_.numberArray2Uint8Array)(s).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=>{(0,_.unionBy)(e.devices,"deviceId").map(e=>{const{advertisData:t,deviceId:i,name:n,localName:s}=e,r=(0,_.ab2hex)(t);let o=null;try{o=(0,_.parseBroadcastData)((0,_.ab2numbers)(t))}catch(e){}const a=this.scanList.find(e=>e.bleDeviceID===i);if(o&&148===o.cmd){const n=(0,_.ab2hex)(t);if(this.boradcastDataCache[i]&&this.boradcastDataCache[i]===n)return!1;if(!a)return!1;this.boradcastDataCache[i]=(0,_.ab2hex)(t);const s=(0,u.padBoradcastData)(o.data.map(e=>parseInt(e,16)));return this.updateCtime(e),void this.notiDeviceDataToSdk(e,s)}if(o&&25===o.cmd){this.pks.find(e=>e===o.data.join(""))&&(e.communicationType="BLE_BROADCAST")}if(o&&this.validBoradcastCmd.includes(o.cmd)&&this.notiBoardCastData(e,o),a){const t=(0,_.BTDevice2GDevice)(e,this.pks);if(t.productKey&&t.mac){const e=this.checkDeviceIsChange(t,a);t.ctime=Date.now(),this.updateDevice(t),e&&this.notifyDevices()}}else{if(this.pks.some(e=>r.includes(e))){const t=(0,_.BTDevice2GDevice)(e,this.pks);t.productKey&&t.mac&&(this.scanList.push(t),this.notifyDevices())}}})},this.startScan=(e=5e3,t)=>s(this,void 0,void 0,(function*(){return this.disableScanFlag?{scanList:[]}:new Promise(i=>s(this,void 0,void 0,(function*(){a.default.debug("GIZ_SDK: start scan",e),yield wx.startBluetoothDevicesDiscovery({services:t||this.baseServices,powerLevel:"high",allowDuplicatesKey:!0,interval:200}),e>0&&setTimeout(()=>{this.stopScan(),i({scanList:this.scanList})},e)})))})),this.stopScan=()=>s(this,void 0,void 0,(function*(){try{return yield wx.stopBluetoothDevicesDiscovery()}catch(e){return e}})),this.disableScan=()=>s(this,void 0,void 0,(function*(){this.disableScanFlag=!0;const e=yield wx.stopBluetoothDevicesDiscovery();return yield(0,v.default)(200),e})),this.enableScan=()=>{this.disableScanFlag=!1},this.connectDevice=e=>s(this,void 0,void 0,(function*(){try{return this.connectingDevId=e.bleDeviceID,yield this._connectDevice(e)}finally{this.connectingDevId=null}})),this.handleWatchBleData=(e,t,i=3e3)=>s(this,void 0,void 0,(function*(){return new Promise(n=>{let s=(i,r)=>{if(e!==i.deviceId)return;const o=t(i,r);o&&(n({success:!0,data:o}),this.removeEventListener("GizBleDeviceData",s))};this.addEventListener("GizBleDeviceData",s),setTimeout(()=>{s&&(this.removeEventListener("GizBleDeviceData",s),n({success:!1,err:S.default.GIZ_SDK_DEVICE_NO_RESPONSE}))},i)})})),this.handleBindReq=e=>new Promise(t=>{const i=setTimeout(()=>{a.default.debug("绑定协议执行超时"),t({success:!1,data:""})},5e3),n=(s,r)=>{if(s.deviceId!==e)return;i&&clearTimeout(i),a.default.log("监听蓝牙特征值发生变化");const o=new c.default((0,f.hexStrint2byte)(r));this.removeEventListener("GizBleDeviceData",n),o.passcode?t({success:!0,data:o.passcode}):t({success:!1,data:""})};this.watchBleDevice(e,n)}),this.handleLoginReq=e=>new Promise(t=>{const i=setTimeout(()=>{a.default.debug("登录协议执行超时"),t({success:!1,data:""})},5e3),n=(s,r)=>{if(s.deviceId!==e)return;i&&clearTimeout(i),a.default.log("设备回复LoginReq",r);const o=new d.default((0,f.hexStrint2byte)(r));this.removeEventListener("GizBleDeviceData",n),!0===o.result?t({success:!0,data:o.did}):t({success:!1,data:""})};this.watchBleDevice(e,n)}),this.startUpgrade=({device:e,type:t,onEvent:i,onProgress:n,productKey:r})=>s(this,void 0,void 0,(function*(){i({code:"GizOTAEventPretreatment"});const s=yield this.checkUpdate({device:e,type:t});a.default.debug("检查设备是否有新固件",s);const o=e.bleDeviceID;if(s.success){const c=s.data.download_url,u=s.data.soft_ver;i({code:"GizOTAEventDownload"});let l="";try{l=(yield(0,m.downloadFile)({url:c})).tempFilePath}catch(e){return a.default.error("固件下载失败",e),{success:!1,err:S.default.GIZ_SDK_OTA_FIRMWARE_DOWNLOAD_FAILED}}a.default.debug("下载固件成功",l),i({code:"GizOTAEventTransmit"});const d=(e,t)=>{const i=(0,f.hexStrint2byte)(t);switch(new h.default(i).cmd){case"0042":return new I.default(i)}return null},p=(e,t)=>{const i=(0,f.hexStrint2byte)(t);switch(new h.default(i).cmd){case"0044":return new C.default(i)}return null},D=(e,t)=>{const i=(0,f.hexStrint2byte)(t);switch(new h.default(i).cmd){case"0052":return new E.default(i)}return null};a.default.debug("查询设备是否可以OTA");const b=I.default.pack(t);yield this.write(o,(0,_.numberArray2Uint8Array)(b).buffer);const w=yield this.handleWatchBleData(o,d);if(a.default.debug("设备回复是否可以OTA",w),w.success&&w.data.type!==t)return a.default.error(null,new Error("OTA类型不匹配")),{success:!1,err:S.default.GIZ_SDK_OTA_FIRMWARE_TYPE_NOT_MATCH};if(w.success&&0===w.data.state){const s=wx.getFileSystemManager();let c=[];try{c=yield s.readFileSync(l,"hex",0)}catch(e){return a.default.error("读取固件失败",e),{success:!1,err:S.default.GIZ_SDK_OTA_FIRMWARE_DOWNLOAD_FAILED}}const d=c.match(/.{1,2}/g).map((function(e){return parseInt(e,16)})),m=(0,_.arrayBufferToWordArray)(d),b=(0,g.MD5)(m).toString(),w=(0,y.crc32)(d),I=C.default.pack(r,u,b,d.length,w);yield this.write(o,(0,_.numberArray2Uint8Array)(I).buffer);const E=yield this.handleWatchBleData(o,p,5e3);if(a.default.debug("设备回复ota 预请求",E),E.success&&0===E.data.state){let s=0;if(E.data.processedLen>0){(0,y.crc32)(d.slice(0,E.data.processedLen)).toString(16)===E.data.processedCrc32?(s=E.data.processedLen,a.default.debug(`断点续传,从 ${s} 开始`)):(a.default.debug("从位置0开始OTA"),yield this.write(o,(0,_.numberArray2Uint8Array)(B.default.pack(0)).buffer),yield(0,v.default)(100))}const r=d.length,c=E.data.packageMaxLen;let l=Math.ceil(s/c),p=0;for(;s<r;){const e=d.slice(s,s+c),t=A.default.pack(e,l);yield this.write(o,(0,_.numberArray2Uint8Array)(t).buffer);const i=(e,t)=>{const i=(0,f.hexStrint2byte)(t);switch(new h.default(i).cmd){case"0048":{const e=new A.default(i);return e.packageNum===l?e:null}}return null},u=yield this.handleWatchBleData(o,i,5e3);let g=!1;if(!1===u.success&&(g=!0),u.success&&0!==u.data.state&&4!==u.data.state&&(g=!0),g){if(p+=1,a.default.debug(`发送OTA包失败,重试次数 ${p}`,u),p>3)return a.default.debug("发送OTA包失败次数超过限制"),{success:!1};continue}a.default.debug("设备接收ota子包成功",u),p=0,s+=c,l+=1;let y=parseInt(`${l*c/r*100}`);if(y>100&&(y=100),n({firmwareSize:r,packageMaxLen:c,currentNumber:l,currentProgress:y}),yield(0,v.default)(100),4===u.data.state){a.default.debug("设备请求等待OTA");const e=yield this.handleWatchBleData(o,D,6e4);if(a.default.debug("设备回复等待结果",e),1===e.data.state)return{success:!1}}}a.default.debug("发送完所有数据包,等待设备回复");const g=(e,t)=>{const i=(0,f.hexStrint2byte)(t);switch(new h.default(i).cmd){case"0050":return new k.default(i)}return null},m=yield this.handleWatchBleData(o,g,1e4);if(m.success&&0===m.data.state){a.default.debug("设备回复收到固件,准备重启设备"),i({code:"GizOTAEventReboot"}),this.disConnectDevice(o),yield(0,v.default)(1e4);const n=yield this.connectDevice(e);if(console.log("connectRes",n),!n.success)return a.default.debug("设备重启后,无法连接"),{success:!1};const s=yield this.getDeviceInfo({deviceId:o});if(!s.success)return a.default.debug("获取设备版本号失败"),{success:!1};let r="";return r="MCU"===t?s.data.mcuSoftVersion:s.data.moduleSoftVersion,i({code:"GizOTAEventFinish"}),r===u?{success:!0}:(a.default.debug("设备上报版本号与更新的固件版本号不匹配,更新失败"),{success:!1})}return{success:!1}}return{success:!1}}return{success:!1,err:S.default.GIZ_SDK_OTA_DEVICE_BUSY_IN_UPGRADE}}return s})),this.getDeviceInfo=({deviceId:e})=>s(this,void 0,void 0,(function*(){const t=w.default.pack();a.default.debug("DeviceInfo.pack",t),yield this.write(e,(0,_.numberArray2Uint8Array)(t).buffer);return yield this.handleWatchBleData(e,(e,t)=>{const i=(0,f.hexStrint2byte)(t);switch(new h.default(i).cmd){case"0014":try{const e=new w.default(i);return a.default.debug("parse DeviceInfo",e),e}catch(e){a.default.debug("parse DeviceInfo error",e)}}return null})})),this.checkUpdate=({device:e,type:t})=>s(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(0,b.checkUpdate)({did:e.did,type:t,softVersion:n,hardVersion:s})}return{success:!1,err:i.err}})),this.watchBleDevice=(e,t)=>s(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)),a.default.log(`监听设备 ${e} 成功!`),this.addEventListener("GizBleDeviceData",t),{message:"ok",success:!0})})),this.sendAdv=(e,t=1e3)=>s(this,void 0,void 0,(function*(){try{return this.peripheralServer.stopAdvertising({}),this.peripheralServer.startAdvertising({advertiseRequest:{connectable:!0,serviceUuids:e},powerLevel:"high",success:e=>{a.default.debug("GIZ_SDK: startAdvertising success",e)},fail:e=>{a.default.error("GIZ_SDK: startAdvertising error",new Error(JSON.stringify(e)))}}),a.default.debug("GIZ_SDK: start adv",e),yield(0,v.default)(t),this.peripheralServer.stopAdvertising({}),{success:!0}}catch(e){return a.default.log("GIZ_SDK:",e),{success:!1,message:"send cmd error"}}})),this.writeBigDataTimeoutHandle=null,this.writeBigData=(e,t)=>s(this,void 0,void 0,(function*(){return new Promise((i,n)=>s(this,void 0,void 0,(function*(){if(this.writeBigDataTimeoutHandle)return void i({success:!1,message:"send big data already"});const n=this.scanList.find(t=>t.bleDeviceID===e);if(!n)return{success:!1,message:"not found device"};let s=-1;const r=(0,_.splitIntoChunks)(t,19);r.map((e,t)=>{r[t].unshift(t)});const o=(0,_.convertToServiceUuids)({mac:n.mac,index:0,data:[r.length],len:1,cmd:151}),c=r.map(e=>(0,_.convertToServiceUuids)({mac:n.mac,index:0,data:e,len:e.length,cmd:153})),u=(t,i)=>{if(console.log("boardCastData",t.deviceId,e),t.deviceId==e)switch(i.cmd){case 154:{const e=i.data[0];parseInt(e,16)===s?(s+=1,a.default.debug("设备回复收到数据包",e)):a.default.debug("数据包序号不匹配",e,s);break}case 152:s=0,a.default.debug("设备回复引导,开始发送数据")}};this.addBoardCastDataListener(u);let l=!0;for(this.writeBigDataTimeoutHandle=setTimeout(()=>{a.default.debug("发送大数据超时"),i({success:!1,message:"write big data timeout"}),this.removeBoardCastDataListener(u),this.writeBigDataTimeoutHandle=null,l=!1},2e4);s<r.length&&l;){if(!this.writeBigDataTimeoutHandle)return;if(-1==s)a.default.debug("发送引导包",o),yield this.sendAdv(o);else{const e=c[s];a.default.debug("发送数据包",e),e&&(yield this.sendAdv(e))}}this.removeBoardCastDataListener(u),l&&(this.writeBigDataTimeoutHandle&&(clearTimeout(this.writeBigDataTimeoutHandle),this.writeBigDataTimeoutHandle=null),i({success:!0,message:"write big data success"}))})))})),this.writeBoradcast=(e,t)=>s(this,void 0,void 0,(function*(){const i=this.scanList.find(t=>t.bleDeviceID===e);if(!i)return{success:!1,message:"not found device"};const n=(0,_.convertToServiceUuids)({mac:i.mac,index:0,data:t,len:t.length,cmd:147});return this.sendAdv(n)})),this.write=(e,t)=>s(this,void 0,void 0,(function*(){return this.methodQueue=this.methodQueue.then(()=>s(this,void 0,void 0,(function*(){a.default.log("app => dev:",(0,_.ab2hex)(t));const i=this.getTargetDevice(e);if(i.serviceId&&i.characteristicId){const n=yield(0,m.unpackWriteBLECharacteristicValue)(e,i.serviceId,i.characteristicId,t);return 0==n.errCode?{success:!0,message:n.errMsg}:{success:!1,message:n.errMsg}}return{success:!1,message:"send cmd error"}}))),this.methodQueue})),this.disConnectDevice=e=>s(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.boardCastDataListenerCallbacks=[],this.notiBoardCastData=(e,t)=>{this.boardCastDataListenerCallbacks.forEach(i=>{i(e,t)})},this.addBoardCastDataListener=e=>{this.boardCastDataListenerCallbacks.push(e)},this.removeBoardCastDataListener=e=>{this.boardCastDataListenerCallbacks=this.boardCastDataListenerCallbacks.filter(t=>t!==e)},this.destory=()=>{this.listenDevOfflineTimer&&clearInterval(this.listenDevOfflineTimer),wx.offAppShow(this.onAppShow),wx.offAppHide(this.onAppHide),wx.offBluetoothAdapterStateChange(this.onBluetoothAdapterStateChange)};const{serviceUUIDSuffix:n}=t;this.serviceUUIDSuffix=n,this.pks=e,this.offlineThreshold=i,this.listenDevOffline(),this.listenConnection(),wx.onAppShow(this.onAppShow),wx.onAppHide(this.onAppHide),wx.onBluetoothAdapterStateChange(this.onBluetoothAdapterStateChange)}connectDeviceBle(e){var t,i,n;return s(this,void 0,void 0,(function*(){yield this.disableScan();const s=yield(0,m.retryConnect)(e.bleDeviceID);if(this.enableScan(),a.default.debug("connect res",s),!s.success&&(a.default.error("GIZ_SDK: createBLEConnection error",new Error(JSON.stringify(s.error))),"createBLEConnection:fail:already connect"!==(null===(t=s.error)||void 0===t?void 0:t.errMsg)))return this.notifyError(s.error),{success:!1,message:null===(i=s.error)||void 0===i?void 0:i.errMsg};const r=yield wx.getBLEDeviceServices({deviceId:e.bleDeviceID}).catch(e=>this.notifyError(e)),o=null===(n=null==r?void 0:r.services.find(e=>e.isPrimary&&e.uuid.toLowerCase().includes(this.serviceUUIDSuffix)))||void 0===n?void 0:n.uuid;if(!o)return{message:"can not find valid serviceId",success:!1};const c=yield wx.getBLEDeviceCharacteristics({deviceId:e.bleDeviceID,serviceId:o}).catch(e=>this.notifyError(e));return{success:!0,data:{serviceId:o,characteristicId:null==c?void 0:c.characteristics[0].uuid}}}))}connectDeviceBindRequest(e){return s(this,void 0,void 0,(function*(){this.write(e.bleDeviceID,(0,_.numberArray2Uint8Array)(c.default.pack()).buffer);const t=yield this.handleBindReq(e.bleDeviceID);return a.default.log("handleBindReq",t),t.success||(yield wx.closeBLEConnection({deviceId:e.bleDeviceID})),t}))}connectDeviceLoginRequest(e,t){return s(this,void 0,void 0,(function*(){this.write(e.bleDeviceID,(0,_.numberArray2Uint8Array)(d.default.pack({passcode:t})).buffer);const i=yield this.handleLoginReq(e.bleDeviceID).catch(e=>this.notifyError(e));return{success:!!(null==i?void 0:i.success),message:"ok"}}))}_connectDevice(e){return s(this,void 0,void 0,(function*(){const t=yield this.connectDeviceBle(e);if(!t.success)return t;const{serviceId:i,characteristicId:n}=t.data;this.connectedList.every(t=>t.deviceId!==e.bleDeviceID)&&this.connectedList.push({deviceId:e.bleDeviceID,serviceId:i,characteristicId:n}),yield wx.notifyBLECharacteristicValueChange({deviceId:e.bleDeviceID,serviceId:i,characteristicId:n,state:!0,type:"notification"}).catch(e=>this.notifyError(e));const s=yield this.connectDeviceBindRequest(e);return s.success?yield this.connectDeviceLoginRequest(e,s.data):s}))}}n([T("BleDeviceConnectEnd")],O.prototype,"connectDeviceBle",null),n([T("BleDeviceConnectBind")],O.prototype,"connectDeviceBindRequest",null),n([T("BleDeviceConnectLogin")],O.prototype,"connectDeviceLoginRequest",null),n([function(e,t,i){const{value:n}=i;i.value=function(...e){const t=Object.create(this);return t.__event_id__=function(){let e=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){let i=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==t?i:3&i|8).toString(16)}))}(),(0,p.reportEvent)({device:e[0],eventID:t.__event_id__,eventType:"BleDeviceConnectStart",success:!0}),n.apply(t,e).then(i=>{var{_failureType_:n}=i,s=r(i,["_failureType_"]);return(0,p.reportEvent)(Object.assign({device:e[0],eventID:t.__event_id__,eventType:"BleDeviceConnectFinish",success:s.success},s.success?{}:{failureType:n})),s})}}],O.prototype,"_connectDevice",null),t.BleHandle=O},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 o(e){try{c(n.next(e))}catch(e){r(e)}}function a(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(o,a)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(20)),o=s(i(1)),a=i(3);class c extends o.default{}c.pack=(e,t,i)=>n(void 0,void 0,void 0,(function*(){const n=yield r.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 u=[0,0,0,0],l=[2];if(t){o=[1];const e=(0,a.fillString)(t.length.toString(16),4),i=(0,a.hexStrint2byte)(e),n=(0,a.string2Bytes)(t);u=u.concat(i).concat(n)}if(e){l=[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=(0,a.fillString)(e,8*Math.ceil(e.length/8)),l=l.concat((0,a.hexStrint2byte)(parseInt(e,2).toString(16)))}const d=o.concat(c).concat(u).concat(l);return r[0]=d.length,s.concat(r).concat(d)}return null})),t.default=c},function(e,t,i){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.crc32=t.crc16modbus=void 0;const s=n(i(71));t.crc16modbus=s.default;const r=n(i(78));t.crc32=r.default,t.default={crc16modbus:s.default,crc32:r.default}},function(e,t,i){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=n(i(73));t.default=function(e,t){const i=(e,i)=>t((0,s.default)(e),i)>>>0;return i.signed=(e,i)=>t((0,s.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 o(e){try{c(n.next(e))}catch(e){r(e)}}function a(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(o,a)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.setMtu=t.downloadFile=t.unpackWriteBLECharacteristicValue=t.writeBLECharacteristicValue=t.notifyBLECharacteristicValueChange=t.getBLEDeviceCharacteristics=t.getBLEDeviceServices=t.createBLEConnection=t.getBluetoothDevices=t.startBluetoothDevicesDiscovery=t.getBluetoothAdapterState=t.closeBluetoothAdapter=t.openBluetoothAdapter=t.retryConnect=void 0;const r=s(i(11));function o(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 a(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=3e3){return n(this,void 0,void 0,(function*(){let i={success:!1,error:null};for(let n=0;n<5;n++)try{return console.debug("start createBLEConnection"),{success:yield o(e,t),error:null}}catch(e){i={success:!1,error:e},console.debug("createBLEConnection error retry"),yield(0,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=o,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=a,t.unpackWriteBLECharacteristicValue=function(e,t,i,s,o=20){if(!s||0===s.byteLength)throw new Error("value is empty");return new Promise((c,u)=>n(this,void 0,void 0,(function*(){let n,l=0,d=s.byteLength;for(;d>0;){yield(0,r.default)(10);const c=s.slice(l,l+o);if(l+=o,d-=o,n=yield a(e,t,i,c),0!==n.errCode)break}0!==n.errCode?u(n):c(n)})))},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)}})})}))},t.setMtu=function(e,t){return n(this,void 0,void 0,(function*(){return new Promise(i=>{wx.setBLEMTU({mtu:e,deviceId:t,success:e=>{i(e.mtu)},fail:()=>{i(20)}})})}))}},function(e,t,i){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=n(i(1)),r=i(3);class o extends s.default{constructor(e){super(e)}}o.pack=(e,t)=>{const i=[],[n,s]=(0,r.formatCodesFromStr)(e),[o,a]=(0,r.formatCodesFromStr)(t),c=[0].concat([0,1],s,n,a,o);let u=c.length;for(;u>0;)i.push(u),u-=255;const l=[0,0,0,3].concat(i).concat(c),d=new ArrayBuffer(l.length),h=new Uint8Array(d);for(let e=0;e<d.byteLength;e++)h[e]=l[e];return h},t.default=o},function(e,t,i){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var s=Object.getOwnPropertyDescriptor(t,i);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,s)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),s=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||n(t,e,i)},r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.BleHandle=t.errorCode=void 0,i(37);const o=r(i(38)),a=r(i(5));t.errorCode=a.default;const c=i(30);Object.defineProperty(t,"BleHandle",{enumerable:!0,get:function(){return c.BleHandle}}),t.default=o.default,s(i(105),t)},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 o(e){try{c(n.next(e))}catch(e){r(e)}}function a(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(o,a)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=i(14),o=s(i(16)),a=i(39),c=s(i(20)),u=i(13),l=s(i(68)),d=i(69),h=s(i(1)),f=i(3),p=i(30),v=s(i(88)),g=s(i(91)),y=s(i(92)),_=s(i(4)),m=s(i(5)),D=i(21),b=i(93),S=i(94),w=s(i(11)),I=i(12),C=s(i(95)),B=s(i(96)),A=s(i(97)),E=s(i(31)),k=o.default.version;class T{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=(0,I.merageBleLocalDevices)([...this.deviceList],this.bleDevices);e=(0,I.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")}),e}get bleScanDevice(){return this.bleDevices.filter(e=>!0===e.isBleOnline)}constructor(e){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.init=({appID:e,appSecret:t,productInfo:i,cloudServiceInfo:n,token:s,uid:o,offlineThreshold:a})=>{this.productInfo=i,(0,r.setGlobalData)("appID",e),(0,r.setGlobalData)("appSecret",t),(0,r.setGlobalData)("productInfo",i),(0,r.setGlobalData)("token",s),(0,r.setGlobalData)("uid",o),this.setDomain(n),this.offlineThreshold=a,_.default.debug(`init sdk success, current version: ${T.getVersion().data}`),this.initLan()},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(0,u.unpack)((0,f.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.handleBleDeviceData=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>t.bleDeviceID===e.deviceId);if(i){const s=(0,f.hexStrint2byte)(t);switch(new h.default(s).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);(0,S.uploadP0)({device:i,data:[{raw:t,created_at:n}],productSecret:e.productSecret}).then(e=>{_.default.debug("设备上报数据:timestemp",new Date(1e3*n).toLocaleString(),e)})}}const e=yield(0,u.unpack)((0,f.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 g.default(s);_.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*(){_.default.debug("代理重置结果",t),t.success&&t.data.successDevices.length>0&&(_.default.debug("重置成功,回写数据"),yield this.bleHandle.write(e.deviceId,(0,I.numberArray2Uint8Array)(y.default.pack(0)).buffer))})));break}case"0064":break;case"0072":{const t=new d.RequestSync(s);if(_.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}),_.default.debug("查询第一条离线数据"),yield this.bleHandle.write(e.deviceId,(0,I.numberArray2Uint8Array)(d.SyncPackage.pack(0)).buffer)):(_.default.debug("设备返回状态为1,同步失败"),this.syncDataCallBack({event:"SYNC_FAIL"}));break}case"0074":{if(!this.syncDataCallBack)break;_.default.debug("设备上报离线数据");const t=new d.SyncPackage(s),i=d.DeletePackage.pack(t.id);_.default.debug("设备上报离线数据:payload",t.payload);try{_.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(0,S.uploadP0)({device:this.syncDevice,data:[{raw:(0,f.arrayToString)(t.payload),created_at:t.timestemp}],productSecret:n.productSecret});_.default.debug("上传离线数据结果",e)}this.syncCurrnetNum+=1,this.syncDataCallBack({event:"SYNC_PROGRESS",totalNum:this.syncTotalNum,currentNum:this.syncCurrnetNum}),_.default.debug("通知设备删除:",t.id),yield this.bleHandle.write(e.deviceId,(0,I.numberArray2Uint8Array)(i).buffer),yield(0,w.default)(100),t.id<this.syncTotalNum-1?(_.default.debug("查询新数据:",t.id+1),yield this.bleHandle.write(e.deviceId,(0,I.numberArray2Uint8Array)(d.SyncPackage.pack(t.id+1)).buffer)):(_.default.debug("send cancel sync to device"),this.bleHandle.write(e.deviceId,(0,I.numberArray2Uint8Array)(d.CancelSync.pack()).buffer),this.syncDataCallBack({event:"SYNC_END"}),this.cleanSyncDeviceData());break}case"0078":{if(!this.syncDataCallBack)break;const e=new d.CancelSync(s);_.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(0,u.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);_.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){_.default.error("init lan error",e)}},this.startAutoScan=e=>{this.keepScanTimer?_.default.debug("startAutoScan fail. keepScanTimer is init"):(this.keepScanTimer=setInterval(()=>n(this,void 0,void 0,(function*(){this.bleHandle.startScan(-1,e)})),9e3),this.bleHandle.startScan(-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.setDevicesMeta=(e,t,i,n=!1)=>{let s=!1;const r=e.map(e=>this.allDevices.find(t=>t.mac===e.mac));for(let e=0;e<r.length;e++){const o=r[e];o&&(o[t]!==i||n)&&(o[t]=i,s=!0)}s&&this.notiDeviceList()},this.initBle=()=>n(this,void 0,void 0,(function*(){try{this.bleHandle.addEventListener("GizBleDeviceData",this.handleBleDeviceData),this.bleHandle.addEventListener("GizBleDeviceList",this.handleBleDevices),this.bleHandle.addEventListener("GizBleError",this.handleBleError);const e=yield this.bleHandle.checkPermission();if(!e.success)return _.default.error("init BLE Error",new Error(JSON.stringify(e))),{success:!1,err:m.default.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON};_.default.debug("init BLE succcess",e)}catch(e){return _.default.error("init BLE error",e),{success:!1,err:m.default.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON}}return{success:!0}})),this.scanBleDevice=(e,t)=>n(this,void 0,void 0,(function*(){return this.bleHandle.scanList=[],{success:!0,data:(yield this.bleHandle.startScan(e,t)).scanList}})),this.writeBigData=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>(0,I.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.writeBigData(i.bleDeviceID,t)}return{success:!1,message:"the connectType not support write big data"}})),this.write=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>(0,I.isSameDevice)(t,e));if(!i)return{success:!1,message:"target is undefind"};if("NONE"!==i.connectType){const{data:e,raw:n}=yield(0,u.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,(0,I.numberArray2Uint8Array)(e).buffer):{success:!1};case"WAN":{const e=yield(0,u.formatEnum)(t,i.productKey,"string");return this.socketHandle.writeData(i,e)}case"LAN":return this.lanHandle.write(i,(0,I.numberArray2Uint8Array)(e).buffer)}}return{success:!1}})),this.writeRaw=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>(0,I.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,(0,I.numberArray2Uint8Array)(t).buffer):{success:!1};case"WAN":return this.socketHandle.send(i,t);case"LAN":return this.lanHandle.write(i,(0,I.numberArray2Uint8Array)(t).buffer)}return{success:!1}})),this.setDeviceTimeStamp=e=>n(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>(0,I.isSameDevice)(t,e));if(!t)return{success:!1,message:"target is undefind"};const i=l.default.pack();switch(t.connectType){case"BLE":return this.bleHandle.write(e.bleDeviceID,(0,I.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=>(0,I.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":{_.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=d.RequestSync.pack();return _.default.debug("sent RequestSync data"),this.bleHandle.write(e.bleDeviceID,(0,I.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=>(0,I.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=d.RequestSync.pack();return this.syncDevice=Object.assign({},t),_.default.debug("sent RequestSync data len"),this.bleHandle.write(e.bleDeviceID,(0,I.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 c.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(0,b.AnonymousLogin)({uid:e});return n.success&&((0,r.setGlobalData)("token",null===(t=n.data)||void 0===t?void 0:t.token),(0,r.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=>(0,I.isSameDevice)(t,e));if(!i)return{success:!1,message:"target is undefind"};switch(i.connectType){case"BLE_BROADCAST":{const e=yield E.default.pack(i.productKey,null,t),n=new h.default(e);return yield this.bleHandle.writeBoradcast(i.bleDeviceID,n.content)}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*(){_.default.debug("subscribe device:",e);let i=this.allDevices.find(t=>(0,I.isSameDevice)(t,e));if(!i)return _.default.warn("Device Target Not Found"),_.default.warn("current devices ",this.allDevices),{success:!1,message:"device not found"};if("BLE_BROADCAST"===i.connectType)return{success:!0,message:""};const n=(0,I.getFirstConnectType)(i,t);switch("NONE"!==i.connectType&&i.connectType!==n&&(yield this.unSubscribe(i)),n){case"BLE":{const e=yield this.bleHandle.connectDevice(i);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,message:""}})),this.batchSubscribe=(e,t)=>n(this,void 0,void 0,(function*(){var i,n,s;_.default.debug("subscribe devices =>",e);const r=this.allDevices.reduce((e,t)=>Object.assign(Object.assign({},e),{[(0,I.getDeviceId)(t)]:t}),{}),o=e.filter(e=>r[(0,I.getDeviceId)(e)]);if(0===o.length)return _.default.warn("Device Target Not Found"),_.default.warn("current devices ",this.allDevices),{success:!1,message:"device not found"};const a=o.reduce((e,i)=>{const n="BLE_BROADCAST"===i.connectType?"BLE_BROADCAST":(0,I.getFirstConnectType)(i,t);return e[n]||(e[n]=[]),e[n].push(i),e},{}),c=Object.keys(a);if(1===c.length&&"BLE_BROADCAST"===c[0])return{success:!0,message:""};if((null!==(i=a.BLE)&&void 0!==i?i:[]).length>0||(null!==(n=a.LAN)&&void 0!==n?n:[]).length>0)return{success:!1,message:"BLE and LAN can not subscribe together"};const u=null!==(s=a.WAN)&&void 0!==s?s:[];if(0===u.length)return{success:!1,message:"no WAN device"};const l=u.filter(e=>"NONE"!==e.connectType&&"WAN"!==e.connectType);l.length>0&&(yield this.batchWanUnSubscribe(l));const d=this.socketHandle.connectDevices(u);return d.success&&this.setDevicesMeta(u,"connectType","WAN",!0),d})),this.batchWanUnSubscribe=e=>n(this,void 0,void 0,(function*(){const t=yield this.socketHandle.disConnectDevices(e);return t.success&&this.setDevicesMeta(e,"connectType","NONE",!0),t})),this.unSubscribe=e=>n(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>(0,I.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=(0,I.getProductInfoThroughPK)(t,this.productInfo);if(n){const r=yield(0,D.bindMac)({mac:e,productKey:t,productSecret:n.productSecret,alias:i,beOwner:s});return this.getBindingList(),r}return{success:!1,err:m.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=>(0,I.isSameDevice)(t,e));if(i){if(!i.did)return{success:!1,err:m.default.GIZ_OPENAPI_DEVICE_NOT_BOUND};switch(i.connectType){case"BLE":return this.bleHandle.checkUpdate({device:e,type:t});default:return{success:!1,err:m.default.GIZ_SDK_OTA_DEVICE_NOT_SUPPORT}}}return{success:!1,err:m.default.GIZ_SDK_DEVICE_NOT_SUBSCRIBED}})),this.getDeviceInfo=({device:e})=>n(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>(0,I.isSameDevice)(t,e));if(t){if(!t.did)return{success:!1,err:m.default.GIZ_OPENAPI_DEVICE_NOT_BOUND};switch(t.connectType){case"BLE":return this.bleHandle.getDeviceInfo({deviceId:e.bleDeviceID});default:return{success:!1,err:m.default.GIZ_SDK_OTA_DEVICE_NOT_SUPPORT}}}return{success:!1,err:m.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=>(0,I.isSameDevice)(t,e));if(n){if(!n.did)return{success:!1,err:m.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:m.default.GIZ_SDK_OTA_DEVICE_NOT_SUPPORT}}}return{success:!1,err:m.default.GIZ_SDK_DEVICE_NOT_SUBSCRIBED}})),this.unbindDevice=({devices:e})=>n(this,void 0,void 0,(function*(){const t=yield(0,D.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,bssid:t="",password:i,mode:s=0,timeout:o,productKey:a,isBind:c=!0,softAPSSIDPrefix:u,eventCallBack:l})=>n(this,void 0,void 0,(function*(){if(this.currentWifiConfigHandle)return{success:!1,err:m.default.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING};const n=(new Date).getTime();_.default.debug("GIZ_SDK: 配网开始时间:"+n,s);try{switch(s){case 0:{this.currentWifiConfigHandle=new C.default(e,t,i,this.specialProductKeys,this.specialProductKeySecrets);const s=yield this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:o,isBind:c,productKey:a,softAPSSIDPrefix:u,eventCallBack:l});this.currentWifiConfigHandle=null;const r=(new Date).getTime();return _.default.debug("GIZ_SDK: 配网结束时间:"+r),_.default.debug("GIZ_SDK: 配网用时:"+(r-n)),s}case 3:{this.currentWifiConfigHandle=new B.default(e,t,i,this.specialProductKeys,this.specialProductKeySecrets,this.bleHandle);const s=yield this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:o,isBind:c,productKey:a,softAPSSIDPrefix:u,eventCallBack:l});this.currentWifiConfigHandle=null;const r=(new Date).getTime();return _.default.debug("GIZ_SDK: 配网结束时间:"+r),_.default.debug("GIZ_SDK: 配网用时:"+(r-n)),s}case 5:{const s=yield wx.getSystemInfoSync();if(console.log("sysInfosysInfo",s),"android"!==s.platform)return{success:!1,message:"只支持安卓"};const a=(0,r.getGlobalData)("cloudServiceInfo");console.log("cloudServiceInfo",a),this.currentWifiConfigHandle=new A.default(e,t,i,this.specialProductKeys,this.specialProductKeySecrets,(null==a?void 0:a.openAPIInfo)||"api.gizwits.com");const d=yield this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:o,isBind:c,softAPSSIDPrefix:u,eventCallBack:l});this.currentWifiConfigHandle=null;const h=(new Date).getTime();return _.default.debug("GIZ_SDK: 配网结束时间:"+h),_.default.debug("GIZ_SDK: 配网用时:"+(h-n)),d}}}catch(e){return _.default.error("GIZ_SDK: setDeviceOnboardingDeploy",e),e.err&&e.err.errorCode?e:{success:!1,err:m.default.GIZ_SDK_OTHERWISE}}finally{this.currentWifiConfigHandle=null}})),this.setDomain=e=>{const t=e&&e.openAPIInfo||"api.gizwits.com",i=Object.assign(Object.assign({},e||{}),{openAPIInfo:t});(0,r.setGlobalData)("cloudServiceInfo",i)},this.deviceSafetyApi=({mac:e,productKey:t,isReset:i})=>n(this,void 0,void 0,(function*(){const n=(0,I.getProductInfoThroughPK)(t,this.productInfo);return n?yield(0,D.safeRegister)({productKey:t,productSecret:n.productSecret,mac:e,isReset:i,passcode:"1234567890"}):{success:!1,err:m.default.GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY}})),this.getBindingList=()=>n(this,void 0,void 0,(function*(){const e=yield(0,D.getBindingList)();return this.deviceList=e.data||[],this.notiDeviceList(),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=>_.default.setLogLevel(e),this.renameDevice=(e,t)=>n(this,void 0,void 0,(function*(){return t?e.isBind?yield(0,D.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.init(e)}get bleHandle(){return this._bleHandle||(this._bleHandle=new p.BleHandle({pks:this.specialProductKeys,offlineThreshold:this.offlineThreshold})),this._bleHandle}get lanHandle(){return this._lanHandle||(this._lanHandle=new a.LanHandle({pks:this.specialProductKeys})),this._lanHandle}get socketHandle(){return this._gizSocket||(this._gizSocket=new v.default({appID:(0,r.getGlobalData)("appID"),token:(0,r.getGlobalData)("token"),uid:(0,r.getGlobalData)("uid")}),this._gizSocket.subscribeDeviceStatus(this.handleSocketDeviceData),this._gizSocket.subscribeBindingChanged(this.getBindingList),this._gizSocket.subscribeSocketStatus(this.handleSocketStatus)),this._gizSocket}reInit(e){this.init(e),this.lanHandle.pks=this.specialProductKeys,this.bleHandle.pks=this.specialProductKeys,this.bleHandle.offlineThreshold=e.offlineThreshold;const{appID:t,token:i,cloudServiceInfo:n={openAPIInfo:""}}=e,s=n&&n.openAPIInfo||"api.gizwits.com";t===(0,r.getGlobalData)("appID")&&i===(0,r.getGlobalData)("token")&&s===(0,r.getGlobalData)("cloudServiceInfo").openAPIInfo||(this.socketHandle.destory(),this._gizSocket=null,this.socketHandle,this.getBindingList())}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:""})}}T.getVersion=()=>({success:!0,data:k}),t.default=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 o(e){try{c(n.next(e))}catch(e){r(e)}}function a(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(o,a)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.TCPHandler=t.LanHandle=void 0;const r=s(i(4)),o=s(i(27)),a=s(i(67)),c=s(i(28)),u=s(i(1)),l=i(3),d=s(i(11)),h=i(12),f=s(i(29));class p extends f.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),r.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&&(r.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 v({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=>{r.default.warn("Discover Error",e)},this.isMatchPk=e=>0===this.pks.length||this.pks.includes(e),this.onMessage=e=>{const t=(0,h.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*(){r.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,localName:"",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}),r.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=p;class v{constructor({ip:e,onClose:t,mac:i,productKey:s,onData:a}){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=o.default.pack();this.tcpHandler.write((0,l.arrayToUint8)(e)),r.default.debug("connect success try login")},i=t=>{e({success:!0,err:t})},n=t=>{switch(new u.default((0,h.ab2numbers)(t.message)).cmd){case"0007":{const e=new o.default((0,h.ab2numbers)(t.message)),i=c.default.pack({passcode:e.passcode});this.tcpHandler.write((0,l.arrayToUint8)(i));break}case"0009":new c.default((0,h.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(0,d.default)(4e3),e({success:!1,err:null})}catch(t){r.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=(0,h.ab2hex)(e.message),i=new u.default((0,l.hexStrint2byte)(t));r.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=s,this.onData=a,this.onCloseListener=t}}t.TCPHandler=v},function(e,t,i){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=i(10),r=n(i(26));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:(0,s.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 n={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)};(0,r.default)("https://appmonitor.gizwits.com/api/21/store/?sentry_key=0b2de791abf548a1bedf0b0ebdd8ecc7&sentry_version=7",n)}},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 o=s(t[r>>>2]>>>16-r%4*8&65535);n.push(String.fromCharCode(o))}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=[],o=0;o<n;o+=3)for(var a=(i[o>>>2]>>>24-o%4*8&255)<<16|(i[o+1>>>2]>>>24-(o+1)%4*8&255)<<8|i[o+2>>>2]>>>24-(o+2)%4*8&255,c=0;c<4&&o+.75*c<n;c++)r.push(s.charAt(a>>>6*(3-c)&63));var u=s.charAt(64);if(u)for(;r.length%4;)r.push(u);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 o=0;o<n.length;o++)r[n.charCodeAt(o)]=o}var a=n.charAt(64);if(a){var c=e.indexOf(a);-1!==c&&(i=c)}return function(e,t,i){for(var n=[],r=0,o=0;o<t;o++)if(o%4){var a=i[e.charCodeAt(o-1)]<<o%4*2,c=i[e.charCodeAt(o)]>>>6-o%4*2,u=a|c;n[r>>>2]|=u<<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,o,a,c;e.exports=(c=i(0),i(18),s=(n=c).lib.WordArray,r=n.algo,o=r.SHA256,a=r.SHA224=o.extend({_doReset:function(){this._hash=new s.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var e=o._doFinalize.call(this);return e.sigBytes-=4,e}}),n.SHA224=o._createHelper(a),n.HmacSHA224=o._createHmacHelper(a),c.SHA224)},function(e,t,i){var n,s,r,o,a,c,u,l;e.exports=(l=i(0),i(15),i(25),s=(n=l).x64,r=s.Word,o=s.WordArray,a=n.algo,c=a.SHA512,u=a.SHA384=c.extend({_doReset:function(){this._hash=new o.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(u),n.HmacSHA384=c._createHmacHelper(u),l.SHA384)},function(e,t,i){var n;e.exports=(n=i(0),i(15),function(e){var t=n,i=t.lib,s=i.WordArray,r=i.Hasher,o=t.x64.Word,a=t.algo,c=[],u=[],l=[];!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++)u[e+5*t]=t+(2*e+3*t)%5*5;for(var s=1,r=0;r<24;r++){for(var a=0,d=0,h=0;h<7;h++){if(1&s){var f=(1<<h)-1;f<32?d^=1<<f:a^=1<<f-32}128&s?s=s<<1^113:s<<=1}l[r]=o.create(a,d)}}();var d=[];!function(){for(var e=0;e<25;e++)d[e]=o.create()}();var h=a.SHA3=r.extend({cfg:r.cfg.extend({outputLength:512}),_doReset:function(){for(var e=this._state=[],t=0;t<25;t++)e[t]=new o.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],o=e[t+2*s+1];r=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),o=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8),(E=i[s]).high^=o,E.low^=r}for(var a=0;a<24;a++){for(var h=0;h<5;h++){for(var f=0,p=0,v=0;v<5;v++)f^=(E=i[h+5*v]).high,p^=E.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],m=_.high,D=_.low;for(f=y.high^(m<<1|D>>>31),p=y.low^(D<<1|m>>>31),v=0;v<5;v++)(E=i[h+5*v]).high^=f,E.low^=p}for(var b=1;b<25;b++){var S=(E=i[b]).high,w=E.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 C=d[u[b]];C.high=f,C.low=p}var B=d[0],A=i[0];for(B.high=A.high,B.low=A.low,h=0;h<5;h++)for(v=0;v<5;v++){var E=i[b=h+5*v],k=d[b],T=d[(h+1)%5+5*v],O=d[(h+2)%5+5*v];E.high=k.high^~T.high&O.high,E.low=k.low^~T.low&O.low}E=i[0];var x=l[a];E.high^=x.high,E.low^=x.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 o=this._state,a=this.cfg.outputLength/8,c=a/8,u=[],l=0;l<c;l++){var d=o[l],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),u.push(f),u.push(h)}return new s.init(u,a)},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=36)}([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(41)}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.")},o=Object.create||function(){function e(){}return function(t){var i;return e.prototype=t,i=new e,e.prototype=null,i}}(),a={},c=a.lib={},u=c.Base={extend:function(e){var t=o(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)}},l=c.WordArray=u.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 o=i[r>>>2]>>>24-r%4*8&255;t[n+r>>>2]|=o<<24-(n+r)%4*8}else for(var a=0;a<s;a+=4)t[n+a>>>2]=i[a>>>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=u.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 l.init(t,e)}}),d=a.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 l.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 l.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=u.extend({reset:function(){this._data=new l.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,o=this.blockSize,a=r/(4*o),c=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,u=e.min(4*c,r);if(c){for(var d=0;d<c;d+=o)this._doProcessBlock(s,d);i=s.splice(0,c),n.sigBytes-=u}return new l.init(i,u)},clone:function(){var e=u.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0}),g=(c.Hasher=v.extend({cfg:u.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)}}}),a.algo={});return a}(Math),n)}).call(this,i(17))},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.sn=[0,0,0,0],this.content=[],this.formatP0=e=>{let t=(0,n.checkHeader)(e);if(!1===t)throw new Error("Header Error");this.header=(0,n.arrayToString)(e.slice(0,t));const i=e.slice(t,e.length),r=(0,n.getProtocolLen)(i);this.len=s.decodeLen(i.slice(0,r)),t+=r,this.flag=e.slice(t,t+1),t+=1,this.cmd=(0,n.arrayToString)(e.slice(t,t+2)),t+=2,"0093"===this.cmd||"0094"===this.cmd?(this.sn=e.slice(t,4),t+=4,this.content=e.slice(t,e.length)):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,o,a,c,u,l,d,h,f,p,v,g,y,_,m,D,b;e.exports=(n=i(0),i(6),void(n.lib.Cipher||(s=n,r=s.lib,o=r.Base,a=r.WordArray,c=r.BufferedBlockAlgorithm,u=s.enc,u.Utf8,l=u.Base64,d=s.algo.EvpKDF,h=r.Cipher=c.extend({cfg:o.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:m}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=o.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=[],o=0;o<n;o+=4)r.push(s);var c=a.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=o.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?a.create([1398893684,1701076831]).concat(i).concat(t):t).toString(l)},parse:function(e){var t,i=l.parse(e),n=i.words;return 1398893684==n[0]&&1701076831==n[1]&&(t=a.create(n.slice(2,4)),n.splice(0,4),i.sigBytes-=16),y.create({ciphertext:i,salt:t})}},m=r.SerializableCipher=o.extend({cfg:o.extend({format:_}),encrypt:function(e,t,i,n){n=this.cfg.extend(n);var s=e.createEncryptor(i,n),r=s.finalize(t),o=s.cfg;return y.create({ciphertext:r,key:i,iv:o.iv,algorithm:e,mode:o.mode,padding:o.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}}),D=(s.kdf={}).OpenSSL={execute:function(e,t,i,n,s){if(n||(n=a.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 o=a.create(r.words.slice(t),4*i);return r.sigBytes=4*t,y.create({key:r,iv:o,salt:n})}},b=r.PasswordBasedCipher=m.extend({cfg:m.cfg.extend({kdf:D}),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=m.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,m.decrypt.call(this,e,t,s.key,n)}}))))},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.bytesToHexString=t.bytesToInt=t.arrayToUint8=t.formatCode=t.formatCodesFromStr=t.hexStrint2byte=t.string2Bytes=t.fillString=t.arrayToString=t.getProtocolLen=t.checkHeader=t.arrayToASCII=t.completeBlock=void 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";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=n(i(5)),r=n(i(40));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),(0,r.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:s.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,o,a,c,u,l;e.exports=(l=i(0),i(24),i(19),s=(n=l).lib,r=s.Base,o=s.WordArray,a=n.algo,c=a.MD5,u=a.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=o.create(),a=r.words,c=n.keySize,u=n.iterations;a.length<c;){i&&s.update(i),i=s.update(e).finalize(t),s.reset();for(var l=1;l<u;l++)i=s.finalize(i),s.reset();r.concat(i)}return r.sigBytes=4*c,r}}),n.EvpKDF=function(e,t,i){return u.create(i).compute(e,t)},l.EvpKDF)},function(e,t,i){"use strict";(function(e){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function o(e){try{c(n.next(e))}catch(e){r(e)}}function a(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(o,a)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.statisticRequest=void 0;const r=s(i(5)),o=i(14),a=s(i(26));t.statisticRequest=function(t,i,s=!0){return n(this,void 0,void 0,(function*(){try{const n=i.body.appInfo.appID,r=Object.assign(Object.assign({},i),{data:i.body}),c={"Content-Type":"application/json","X-Gizwits-Application-Id":n};s&&(c["X-Gizwits-User-token"]=e.token),r.headers=Object.assign(Object.assign({},c),i.headers);const u=`https://${(0,o.getGlobalData)("cloudServiceInfo").openAPIInfo}/`;console.log("===statisticRequest===",u+t,r);const l=yield(0,a.default)(u+t,r);return(null==l?void 0:l.statusCode)>=200&&(null==l?void 0:l.statusCode)<300?{success:!0,data:null==l?void 0:l.data}:{success:!1,err:{errorCode:(null==l?void 0:l.data).error_code,errorMessage:(null==l?void 0:l.data).error_message}}}catch(e){return{success:!1}}}))},t.default=(e,t,i=!0)=>n(void 0,void 0,void 0,(function*(){const n=Object.assign({},t),s={"Content-Type":"application/json","X-Gizwits-Application-Id":(0,o.getGlobalData)("appID")};i&&(s["X-Gizwits-User-token"]=(0,o.getGlobalData)("token")),n.header=Object.assign(Object.assign({},s),t.headers),delete n.headers;const c=(0,o.getGlobalData)("cloudServiceInfo").openAPIInfo,u=yield(0,a.default)("https://"+c+e,n);if(u.statusCode>=200&&u.statusCode<300)return{success:!0,data:u.data};let l={success:!1,err:{errorCode:r.default.GIZ_SDK_HTTP_REQUEST_FAILED.errorCode,errorMessage:""}};try{l={success:!1,err:{errorCode:u.data.error_code,errorMessage:u.data.error_message}}}catch(e){}return l}))}).call(this,i(17))},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 o=(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,a=0;a<4&&r+.75*a<i;a++)s.push(n.charAt(o>>>6*(3-a)&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 o=i.charAt(64);if(o){var a=e.indexOf(o);-1!==a&&(t=a)}return function(e,t,i){for(var n=[],r=0,o=0;o<t;o++)if(o%4){var a=i[e.charCodeAt(o-1)]<<o%4*2,c=i[e.charCodeAt(o)]>>>6-o%4*2,u=a|c;n[r>>>2]|=u<<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,o=t.algo,a=[];!function(){for(var t=0;t<64;t++)a[t]=4294967296*e.abs(e.sin(t+1))|0}();var c=o.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,o=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],m=e[t+8],D=e[t+9],b=e[t+10],S=e[t+11],w=e[t+12],I=e[t+13],C=e[t+14],B=e[t+15],A=r[0],E=r[1],k=r[2],T=r[3];A=u(A,E,k,T,o,7,a[0]),T=u(T,A,E,k,c,12,a[1]),k=u(k,T,A,E,f,17,a[2]),E=u(E,k,T,A,p,22,a[3]),A=u(A,E,k,T,v,7,a[4]),T=u(T,A,E,k,g,12,a[5]),k=u(k,T,A,E,y,17,a[6]),E=u(E,k,T,A,_,22,a[7]),A=u(A,E,k,T,m,7,a[8]),T=u(T,A,E,k,D,12,a[9]),k=u(k,T,A,E,b,17,a[10]),E=u(E,k,T,A,S,22,a[11]),A=u(A,E,k,T,w,7,a[12]),T=u(T,A,E,k,I,12,a[13]),k=u(k,T,A,E,C,17,a[14]),A=l(A,E=u(E,k,T,A,B,22,a[15]),k,T,c,5,a[16]),T=l(T,A,E,k,y,9,a[17]),k=l(k,T,A,E,S,14,a[18]),E=l(E,k,T,A,o,20,a[19]),A=l(A,E,k,T,g,5,a[20]),T=l(T,A,E,k,b,9,a[21]),k=l(k,T,A,E,B,14,a[22]),E=l(E,k,T,A,v,20,a[23]),A=l(A,E,k,T,D,5,a[24]),T=l(T,A,E,k,C,9,a[25]),k=l(k,T,A,E,p,14,a[26]),E=l(E,k,T,A,m,20,a[27]),A=l(A,E,k,T,I,5,a[28]),T=l(T,A,E,k,f,9,a[29]),k=l(k,T,A,E,_,14,a[30]),A=d(A,E=l(E,k,T,A,w,20,a[31]),k,T,g,4,a[32]),T=d(T,A,E,k,m,11,a[33]),k=d(k,T,A,E,S,16,a[34]),E=d(E,k,T,A,C,23,a[35]),A=d(A,E,k,T,c,4,a[36]),T=d(T,A,E,k,v,11,a[37]),k=d(k,T,A,E,_,16,a[38]),E=d(E,k,T,A,b,23,a[39]),A=d(A,E,k,T,I,4,a[40]),T=d(T,A,E,k,o,11,a[41]),k=d(k,T,A,E,p,16,a[42]),E=d(E,k,T,A,y,23,a[43]),A=d(A,E,k,T,D,4,a[44]),T=d(T,A,E,k,w,11,a[45]),k=d(k,T,A,E,B,16,a[46]),A=h(A,E=d(E,k,T,A,f,23,a[47]),k,T,o,6,a[48]),T=h(T,A,E,k,_,10,a[49]),k=h(k,T,A,E,C,15,a[50]),E=h(E,k,T,A,g,21,a[51]),A=h(A,E,k,T,w,6,a[52]),T=h(T,A,E,k,p,10,a[53]),k=h(k,T,A,E,b,15,a[54]),E=h(E,k,T,A,c,21,a[55]),A=h(A,E,k,T,m,6,a[56]),T=h(T,A,E,k,B,10,a[57]),k=h(k,T,A,E,y,15,a[58]),E=h(E,k,T,A,I,21,a[59]),A=h(A,E,k,T,v,6,a[60]),T=h(T,A,E,k,S,10,a[61]),k=h(k,T,A,E,f,15,a[62]),E=h(E,k,T,A,D,21,a[63]),r[0]=r[0]+A|0,r[1]=r[1]+E|0,r[2]=r[2]+k|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),o=n;i[15+(s+64>>>9<<4)]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),i[14+(s+64>>>9<<4)]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8),t.sigBytes=4*(i.length+1),this._process();for(var a=this._hash,c=a.words,u=0;u<4;u++){var l=c[u];c[u]=16711935&(l<<8|l>>>24)|4278255360&(l<<24|l>>>8)}return a},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});function u(e,t,i,n,s,r,o){var a=e+(t&i|~t&n)+s+o;return(a<<r|a>>>32-r)+t}function l(e,t,i,n,s,r,o){var a=e+(t&n|i&~n)+s+o;return(a<<r|a>>>32-r)+t}function d(e,t,i,n,s,r,o){var a=e+(t^i^n)+s+o;return(a<<r|a>>>32-r)+t}function h(e,t,i,n,s,r,o){var a=e+(i^(t|~n))+s+o;return(a<<r|a>>>32-r)+t}t.MD5=r._createHelper(c),t.HmacMD5=r._createHmacHelper(c)}(Math),n.MD5)},function(e,t,i){var n;e.exports=(n=i(0),i(15),i(42),i(43),i(8),i(44),i(9),i(24),i(18),i(45),i(25),i(46),i(47),i(48),i(19),i(49),i(6),i(2),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),i(64),i(65),i(66),n)},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";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.createUUID32=t.arrayBufferToWordArray=t.convertToUuids=t.convertToServiceUuids=t.encrypt=t.ab2numbers=t.parseBroadcastData=t.hex2ab=t.hex2numbers=t.mergeObject=t.getProductInfoThroughPK=t.getFirstConnectType=t.splitIntoChunks=t.BTDevice2GDevice=t.merageLanLocalDevices=t.merageBleLocalDevices=t.getDeviceId=t.isSameDevice=t.advertisData2PkAndMac=t.numberArray2Uint8Array=t.str2Buf=t.isWXDevicesResult=t.unionBy=t.wrapErrorInfo=t.isError=t.compareWXSDKVersion=t.ab2hex=void 0;const s=i(0),r=n(i(4));function o(e){return Array.prototype.map.call(new Uint8Array(e),(function(e){return("00"+e.toString(16)).slice(-2)})).join("")}t.ab2hex=o,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};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=o(i);if(t.find(e=>e===s)){const e=o(n);return{productKey:s,mac:e}}{i=e.slice(0,16),n=e.slice(16),s=o(i);const t=o(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="",r=1;const a=new Uint8Array(e);for(;!(i>e.byteLength-1);){const c=a[i];if(c<=0||!c)break;if(e.byteLength<c+i+1)break;const u=e.slice(i+1,i+c+1);if(c>=6&&c<=8&&(n=o(u),16==n.length&&(n=n.substring(0,15))),16==c){const e=o(u).toLowerCase();t.find(t=>t===e)&&(s=e)}if(1==c){const e=o(u);r="1"===parseInt(e,16).toString(2).split("").pop()?1:0}i+=1+c}return{bleWorkStatus:r,mac:n,productKey:s}})(e,t):{mac:"",productKey:"",bleWorkStatus:1};t.isSameDevice=(e,t)=>e.mac===t.mac&&e.productKey===t.productKey;t.getDeviceId=e=>`${e.mac}${e.productKey}`;t.merageBleLocalDevices=(e,i)=>(e.map(e=>{e.isBleOnline=!1,e.bleWorkStatus=0}),i.map(i=>{const n=e.find(e=>(0,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=>(0,t.isSameDevice)(e,i));n?n.isLanOnline=!0:e.push(i)}),e);t.BTDevice2GDevice=(e,i)=>{let n={productKey:"",mac:"",bleWorkStatus:0},s={did:"",productKey:"",mac:"",bleWorkStatus:0,connectType:"NONE",isBleOnline:!0,isLanOnline:!1,isOnline:!1,name:e.localName,localName:e.localName,isBind:!1,bleDeviceID:e.deviceId,ctime:(new Date).getTime()};switch(e.communicationType){case"BLE_BROADCAST":try{r.default.log("parse BLE_BROADCAST");const t=c(u(e.advertisData));n.productKey=t.data.join(""),n.mac=t.mac,s.connectType="BLE_BROADCAST"}catch(e){}break;default:n=(0,t.advertisData2PkAndMac)(e.advertisData,i)}return s=Object.assign(Object.assign({},s),n),s};t.splitIntoChunks=(e,t)=>{const i=[];for(let n=0;n<e.length;n+=t)i.push(e.slice(n,n+t));return i};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);function a(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 t}function c(e){if(25!=(e=e.slice(0,25)).length)throw new Error("数据不合法");const t=`${l(e[0])}${l(e[1])}`;if(e[2]!==(255&e.slice(3).reduce((e,t)=>e+t,0)))throw new Error("校验和不合法");const i=l(e[3]),n=e.slice(5,5+e[4]).map(e=>l(e));return{mac:t,cmd:parseInt(i,16),data:n}}function u(e){return Array.prototype.map.call(new Uint8Array(e),(function(e){return e}))}function l(e,t=2){return`${new Array(t).fill(0).join("")}${e.toString(16)}`.slice(-t)}t.mergeObject=(e,t)=>{for(let i in t)null!=t[i]&&""!==t[i]&&(e[i]=t[i]);return e},t.hex2numbers=a,t.hex2ab=function(e){return new Uint8Array(a(e))},t.parseBroadcastData=c,t.ab2numbers=u;let d=0;function h(e,t){let i=1,n=t;return e.map(e=>{const t=65535&(e^n);return n=i-t&65535,i<<=1,l(t,4)})}t.encrypt=h;function f(e,t,i){if(i.length>22)throw new Error("最大长度为22");const n=[...i,...new Array(22-i.length).fill(0)],s=255&i.reduce((e,t)=>e+t,0),o=(t>>4<<12)+(s>>4<<8)+((15&t)<<4)+(15&s),a=Array.from({length:11},(e,t)=>(n[2*t]<<8)+n[2*t+1]);return r.default.log("明文",l(e,4),l((t<<8)+s,4),a.map(e=>l(e,4))),[l(e,4),l((t<<8)+s,4),...h(a,o)].map(e=>`${e.slice(2)}${e.slice(0,2)}`)}t.convertToServiceUuids=({len:e=null,data:i=null,index:n=0,mac:s,cmd:r=147})=>{if(i&&i.length>20)throw new Error("data 最大 20");const o=null==e?Math.round(18*Math.random())+1:e,a=null==i?Array.from({length:o},e=>Math.round(255*Math.random())):i,c=[r,o,...a],u=f(s,(()=>{const e=d;return d=d+1&255,e})(),c);return[...new Set(u)].length!==u.length?(0,t.convertToServiceUuids)({len:o,data:a,index:n++,mac:s}):u},t.convertToUuids=f,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)},t.createUUID32=function(){let e=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){let i=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==t?i:3&i|8).toString(16)}))}},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 o(e){try{c(n.next(e))}catch(e){r(e)}}function a(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(o,a)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.formatBinary=t.formatEnum=t.padBoradcastData=t.unpack=t.pack=t.getVariableLength=void 0;const r=s(i(20)),o=i(3),a=e=>-1!==e.indexOf("uint")?"number":e,c=(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),r=-1===s?0:s;n=(0,o.fillString)(r.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=(0,o.fillString)(e.toString(2),8*i.position.len);break}case"binary":{let e=t[i.name]||"";e instanceof Array&&(e=(0,o.arrayToString)(e));const s=(0,o.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+=(0,o.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}`},u=(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+=(0,o.fillString)(parseInt(s,2).toString(16),2)}return(0,o.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],r=[0],u=[0,147],l=[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=(0,o.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((0,o.completeBlock)(g)),g=""),g=((e,i)=>{const n=a(e.data_type);return i=c(n,t,e)+i})(e,g)):(g.length>0&&(h=h.concat((0,o.completeBlock)(g)),g=""),h=((e,i)=>{const n=a(e.data_type),s=c(n,t,e);return i=i.concat((0,o.completeBlock)(s)),console.log("handleOther",s,i),i})(e,h)),v=e}),g.length>0&&(h=h.concat((0,o.completeBlock)(g)),g="");const y=r.concat(u).concat(l).concat(h),_=d(y);return s.push(..._),{data:s.concat(y),raw:{header:[0,0,0,3],flag:r,len:_,headerCmd:u,sn:l,cmd:h}}};function d(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 h(e,t){return e===t||"ALL"===e}function f({attrs:e,activeAttrs:t,flagString:i,cmdData:n,accumulate:s}){let r=0,o={},a=0;return["status_writable","status_readonly","alert","fault"].map(c=>{const u=e.filter(e=>h(c,e.type)).length,{cmd:l,cmdDataLength:d}=p({type:c,attrs:e.slice(a,a+u),activeAttrs:t,flagString:i.substring(a,a+u),cmdData:n.slice(r,n.length),accumulate:s});return r+=d,o=Object.assign(Object.assign({},o),l),a+=u,null}),o}function p({type:e,attrs:t,activeAttrs:i,cmdData:n,flagString:s,accumulate:r}){let c=0,l=0,d=0;return i.map(t=>{if(h(e,t.type)){const e=t.position.len*("bit"===t.position.unit?1:8);"bool"===t.data_type||"enum"===t.data_type?l+=e:d+=e}return null}),c=Math.ceil(d/8)+Math.ceil(l/8),{cmdDataLength:c,cmd:function({attrs:e,flagString:t,boolEnumLength:i,cmdData:n,accumulate:s}){const r={};let c=0;for(let l=0;l<t.length;l++)if(e[l]&&"1"===t[l]){const{data_type:t,position:{len:s}}=e[l];let d="";if("bool"===t||"enum"===t){let e="";n.slice(0,i).map(t=>(e+=(0,o.fillString)(t.toString(2),8),null));const t=e.length-c;d=e.substring(t-s,t),c+=s}else{const e=i,t=i+s;n.slice(e,t).map(e=>(d+=(0,o.fillString)(e.toString(2),8),null)),i+=s}const h=a(t);r[e[l].name]=u(h,d,e[l])}else if(s){const t=e[l]||{position:{len:0}};"byte"===t.position.unit?i+=t.position.len:c+=t.position.len}return r}({attrs:t,flagString:s,boolEnumLength:Math.ceil(l/8),cmdData:n,accumulate:r})}}t.getVariableLength=d;t.unpack=(e,t)=>n(void 0,void 0,void 0,(function*(){const i=yield r.default.getConfigFile(t);if(i){const n=function({config:e=[],data:t}){let i,n,s="";const r={header:(0,o.arrayToString)(t.slice(0,4)),flag:"",len:"",cmd:"",sn:"",action:"",payload:""},a=e;let c=(0,o.checkHeader)(t);if(!1===c)return;const u=t.slice(c,t.length),l=(0,o.getProtocolLen)(u);if(c+=l,r.len=(0,o.arrayToString)(u.slice(0,l)),c+=1,r.flag=(0,o.arrayToString)(t.slice(c-1,c)),c+=2,r.cmd=(0,o.arrayToString)(t.slice(c-2,c)),r.sn="",("0093"===r.cmd||"0094"===r.cmd)&&(c+=4,r.sn=(0,o.arrayToString)(t.slice(c-4,c)),"01"===r.flag)){c+=2,c+=parseInt((0,o.arrayToString)(t.slice(c-2,c)),16)}c+=1,r.action=(0,o.arrayToString)(t.slice(c-1,c)),i=parseInt(r.action,16),r.payload=(0,o.arrayToString)(t.slice(c,t.length));const d=t.slice(c,t.length);let h=a;1===i&&(h=a.filter(e=>"status_writable"===e.type));const v=JSON.parse(JSON.stringify(h)),g=Math.ceil(h.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 m="";y.map(e=>(m+=(0,o.fillString)(e.toString(2),8),null)),i>=17&&i<=20&&(h=h.filter((e,t)=>{const i=m.length-1-t;return"1"===m[i]})),"0090"===r.cmd||"0093"===r.cmd?(s="App 透传数据到 Dev",n="APP2DEV"):"0091"===r.cmd||"0094"===r.cmd?(s="Dev 收到控制命令后应答到 App",n="DEV2APP"):(s="非法数据",n="UNKNOW");let D={};switch(i){case 1:s="App 下发数据到 Dev",D=f({attrs:v,activeAttrs:h,flagString:m.split("").reverse().join(""),cmdData:_,accumulate:!0});break;case 2:return s="App 下发查询指令到 Dev",{kvData:null,rawData:r,message:s,messageType:n};case 3:s="Dev 回复查询指令到 App",D=f({attrs:v,activeAttrs:h,flagString:m.split("").reverse().join(""),cmdData:_,accumulate:!0});break;case 4:s="Dev 上报状态到 App",D=f({attrs:v,activeAttrs:h,flagString:m.split("").reverse().join(""),cmdData:_,accumulate:!0});break;case 5:return s="App 透传数据到 Dev",{kvData:null,rawData:r,message:s,messageType:n};case 6:return s="Dev 透传数据到 App",{kvData:null,rawData:r,message:s,messageType:n};case 7:return s="App 下发控制子设备",{kvData:null,rawData:r,message:s,messageType:n};case 8:return s="App 读取子设备数据",{kvData:null,rawData:r,message:s,messageType:n};case 9:return s="Dev 中控回复ACK",{kvData:null,rawData:r,message:s,messageType:n};case 10:return s="子设备上报状态到 App",{kvData:null,rawData:r,message:s,messageType:n};case 11:return s="App 下发添加子设备指令",{kvData:null,rawData:r,message:s,messageType:n};case 12:return s="App 下发删除子设备",{kvData:null,rawData:r,message:s,messageType:n};case 13:return s="App 获取中控子设备列表",{kvData:null,rawData:r,message:s,messageType:n};case 14:return s="中控响应字设备查询到 App",{kvData:null,rawData:r,message:s,messageType:n};case 15:return s="子设备列表变更通知到 App",{kvData:null,rawData:r,message:s,messageType:n};case 16:return s="Dev 子设备上下线状态变更通知",{kvData:null,rawData:r,message:s,messageType:n};case 17:s="App 下发变长数据到 Dev",D=p({type:"ALL",attrs:v,activeAttrs:h,flagString:m.split("").reverse().join(""),cmdData:_}).cmd;break;case 18:return s="App 下发变长查询到 Dev",{kvData:null,rawData:r,message:s,messageType:n};case 19:s="Dev 变长回复查询指令到 App",D=p({type:"ALL",attrs:v,activeAttrs:h,flagString:m.split("").reverse().join(""),cmdData:_}).cmd;break;case 20:s="Dev 变长上报状态到 App",D=p({type:"ALL",attrs:v,activeAttrs:h,flagString:m.split("").reverse().join(""),cmdData:_}).cmd;break;case 114:return s="App 向网关发送数据",{kvData:null,rawData:r,message:s,messageType:n};case 115:return s="Dev 网关上报数据到 App",{kvData:null,rawData:r,message:s,messageType:n};case 116:return s="App 通知网关删除子设备",{kvData:null,rawData:r,message:s,messageType:n};default:return{kvData:null,rawData:r,message:s,messageType:n}}return 0===a.length?{kvData:null,rawData:r,message:s,messageType:n}:{kvData:D,rawData:r,message:s,messageType:n}}({config:(yield i).entities[0].attrs,data:e});return n.kvData&&(n.kvData=yield v(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 r.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=d(t);return(0,o.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 s=yield r.default.getAttrItem(t,n);if(s&&"enum"===s.data_type){if("int"===i&&"string"==typeof e[n]){const t=s.enum.findIndex(t=>t===e[n]);e[n]=t||0}"string"===i&&"number"==typeof e[n]&&(e[n]=s.enum[e[n]])}}return e}));const v=(e,t,i)=>n(void 0,void 0,void 0,(function*(){for(let n in e){const s=yield r.default.getAttrItem(t,n);s&&"binary"===s.data_type&&("object"===i&&"string"==typeof e[n]&&(e[n]=(0,o.hexStrint2byte)(e[n])),"string"===i&&"object"==typeof e[n]&&(e[n]=(0,o.arrayToString)(e[n])))}return e}));t.formatBinary=v},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getGlobalData=t.setGlobalData=void 0;const n={};t.setGlobalData=function(e,t){n[e]=t},t.getGlobalData=function(e){return n[e]}},function(e,t,i){var n,s,r,o,a,c;e.exports=(c=i(0),s=(n=c).lib,r=s.Base,o=s.WordArray,(a=n.x64={}).Word=r.extend({init:function(e,t){this.high=e,this.low=t}}),a.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 o.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){e.exports=JSON.parse('{"name":"mini_program_gizwits_sdk","version":"3.6.28","description":"更新类型","main":"./dist/index.js","scripts":{"test":"node_modules/mocha/bin/_mocha -r ts-node/register tests/**/*.spec.ts -file ./tests/setup-wx.js -timeout 60s","testBle":"node_modules/mocha/bin/_mocha -r ts-node/register tests/utils/randomCode.spec.ts -file ./tests/setup-wx.js -timeout 60s","build":"rm -rf ./dist && webpack","release":"npm run build && release-it","cover":"istanbul cover node_modules/mocha/bin/_mocha -- -r ts-node/register tests/**/*.spec.ts -file ./tests/setup-wx.js -timeout 60s","coveralls":"npm run cover -- --report lcovonly && cat ./coverage/lcov.info | coveralls"},"repository":{"type":"git","url":"git+https://github.com/gizwits/mini_program_gizwits_sdk.git"},"keywords":["gizwits","miniprogram","sdk"],"devDependencies":{"@babel/plugin-transform-modules-commonjs":"^7.12.1","@release-it/conventional-changelog":"^2.0.0","@types/chai":"^4.2.11","@types/crypto-js":"^4.0.2","@types/mocha":"^7.0.2","@types/node":"^12.12.14","@types/sinon":"^10.0.6","chai":"^4.2.0","coveralls":"^3.0.11","istanbul":"^1.1.0-alpha.1","miniprogram-api-typings":"^3.9.0","mocha":"^7.1.1","release-it":"^14.2.2","sinon":"^9.2.4","ts-loader":"^6.2.2","ts-node":"^8.8.1","typescript":"^4.9.5","uglifyjs-webpack-plugin":"^2.2.0","webpack":"^4.42.1","webpack-bundle-analyzer":"^4.5.0","webpack-cli":"^3.3.11"},"author":"gizwits","license":"ISC","bugs":{"url":"https://github.com/gizwits/mini_program_gizwits_sdk/issues"},"homepage":"https://github.com/gizwits/mini_program_gizwits_sdk#readme","dependencies":{"crypto-js":"^4.1.1"}}')},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;e.exports=(n=i(0),function(e){var t=n,i=t.lib,s=i.WordArray,r=i.Hasher,o=t.algo,a=[],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&&(a[s]=i(e.pow(n,.5))),c[s]=i(e.pow(n,1/3)),s++),n++}();var u=[],l=o.SHA256=r.extend({_doReset:function(){this._hash=new s.init(a.slice(0))},_doProcessBlock:function(e,t){for(var i=this._hash.words,n=i[0],s=i[1],r=i[2],o=i[3],a=i[4],l=i[5],d=i[6],h=i[7],f=0;f<64;f++){if(f<16)u[f]=0|e[t+f];else{var p=u[f-15],v=(p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3,g=u[f-2],y=(g<<15|g>>>17)^(g<<13|g>>>19)^g>>>10;u[f]=v+u[f-7]+y+u[f-16]}var _=n&s^n&r^s&r,m=(n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22),D=h+((a<<26|a>>>6)^(a<<21|a>>>11)^(a<<7|a>>>25))+(a&l^~a&d)+c[f]+u[f];h=d,d=l,l=a,a=o+D|0,o=r,r=s,s=n,n=D+(m+_)|0}i[0]=i[0]+n|0,i[1]=i[1]+s|0,i[2]=i[2]+r|0,i[3]=i[3]+o|0,i[4]=i[4]+a|0,i[5]=i[5]+l|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(l),t.HmacSHA256=r._createHmacHelper(l)}(Math),n.SHA256)},function(e,t,i){var n,s,r,o;e.exports=(n=i(0),r=(s=n).lib.Base,o=s.enc.Utf8,void(s.algo.HMAC=r.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=o.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(),a=s.words,c=r.words,u=0;u<i;u++)a[u]^=1549556828,c[u]^=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";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function o(e){try{c(n.next(e))}catch(e){r(e)}}function a(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(o,a)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(7));const o=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.getConfigFileMap={},this.getConfigFile=e=>{if(!this.data[e]){if(this.getConfigFileMap[e])return this.getConfigFileMap[e];const t=new Promise(t=>n(this,void 0,void 0,(function*(){var i;const n=`/app/datapoint?product_key=${e}`,s=yield(0,r.default)(`${n}`,{method:"GET"});s.success&&(null===(i=s.data)||void 0===i?void 0:i.entities)?(this.data[e]=s.data,t(this.data[e]),wx.setStorageSync(this.key,JSON.stringify(this.data))):t(null),this.getConfigFileMap[e]=null})));return this.getConfigFileMap[e]=t,t}return Promise.resolve(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}))}};o.init(),t.default=o},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 o(e){try{c(n.next(e))}catch(e){r(e)}}function a(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(o,a)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.controlDevice=t.editBindInfo=t.safeRegister=t.checkDeviceRegister=t.unbindDevice=t.bindMac=t.getBindingList=void 0;const r=i(10),o=s(i(7)),a=s(i(89)),c=i(90),u=s(i(4));class l{constructor(){this.pad=(e,t)=>{},this.unpad=e=>{const t=e.sigBytes;let i=0,n=1;const s=e.toString(r.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(0,o.default)("/app/bindings?show_disabled=0&limit=1000&skip=0",{method:"GET"});if(e.success){return{success:!0,data:e.data.devices.map(e=>Object.assign(Object.assign({},e),{productKey:e.product_key,mac:e.mac,did:e.did,host:e.host,localName:"",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:s,beOwner:r}){return n(this,void 0,void 0,(function*(){const n={mac:e,product_key:t,dev_alias:s,set_owner:r},{Signature:a,timestamp:u}=(0,c.psKeySign)(i);return yield(0,o.default)("/app/bind_mac",{method:"POST",data:n,headers:{"X-Gizwits-Signature":a,"X-Gizwits-Timestamp":u}})}))},t.unbindDevice=function({devices:e}){return n(this,void 0,void 0,(function*(){return yield(0,o.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=(0,a.default)({SSID:e,password:t,pks:i});let s="";return n.map(e=>{s+=`${e},`}),s=s.substring(0,s.length-1),yield(0,o.default)(`/app/device_register?random_codes=${s}`,{method:"get"})}))},t.safeRegister=function({productKey:e,productSecret:t,mac:i,passcode:s,gwDid:a,isReset:c}){return n(this,void 0,void 0,(function*(){let n=`is_reset=${c?1:0}&mac=${i}&passcode=${s}`;a&&(n+=`&gw_did=${a}`);const u=r.enc.Hex.parse(t),l=r.enc.Hex.parse(""),h=r.enc.Utf8.parse(n),f=r.AES.encrypt(h,u,{iv:l,mode:r.mode.ECB,padding:r.pad.Pkcs7}).ciphertext.toString().toUpperCase(),p=yield(0,o.default)(`/dev/${e}/device`,{method:"POST",data:{data:f},headers:{"content-type":"application/x-www-form-urlencoded"}},!1);if(p.success){const e=d({productSecret:t,iv:l,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 d=({productSecret:e,data:t,iv:i})=>{const n=r.enc.Hex.parse(e),s=r.enc.Hex.parse(t);const o=r.AES.decrypt(r.enc.Base64.stringify(s),n,{iv:i,mode:r.mode.ECB,padding:new l}).toString(r.enc.Utf8),a=[];return o.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(0,o.default)(`/app/bindings/${i}`,{method:"PUT",data:n},!0)}))},t.controlDevice=function(e){return n(this,void 0,void 0,(function*(){const{did:t,raw:i,attrs:n}=e,s={};i&&(s.raw=i),n&&(s.attrs=n);const r=yield(0,o.default)(`/app/control/${t}`,{method:"POST",data:s},!0);return u.default.log("GIZ_SDK: ControlDevice",e,r),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 o(e){try{c(n.next(e))}catch(e){r(e)}}function a(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(o,a)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(11)),o=s(i(5)),a=i(21),c=s(i(4)),u=s(i(23));t.default=class{constructor(e,t,i,s,l){this.ssid="",this.bssid="",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&&(u.default.cancel(),this.setDeviceOnboardingDeployRej({success:!1,err:o.default.GIZ_SDK_ONBOARDING_STOPPED})),this.cleanTimeout()},this.appendExtendData=e=>{const t=-(new Date).getTimezoneOffset()/60;let i=Math.floor(t),n=0,s="",r=t-i;return s=i>=0&&i<=9?String.fromCharCode("0".charCodeAt(0)+i):i>9?String.fromCharCode(i-10+"A".charCodeAt(0)):String.fromCharCode(-i-1+"a".charCodeAt(0)),r<0&&(r=-r),n=r>=0&&r<.25?0:r>=.25&&r<.5?1:r>=.5&&r<.75?2:3,e+"\00"+s+n+"309"},this.hasTimeoutHandler=e=>!!this.timeoutHandler&&(e&&e({success:!1,err:o.default.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING}),!0),this.handleTimeout=()=>{if(this.setDeviceOnboardingDeployRej){const e={errorCode:o.default.CONFIG_TIME_OUT,errorMessage:"time out"};this.setDeviceOnboardingDeployRej({success:!1,err:{errorCode:o.default.CONFIG_TIME_OUT,errorMessage:"time out"}}),u.default.appendEvent({name:"WIFI_CONFIG_FAIL",message:JSON.stringify({error:e})})}this.timeoutHandler=null},this.searchDevice=({ssid:e,password:t})=>new Promise((i,s)=>{u.default.appendEvent({name:"START_SEARCH_RANDOM_CODE",message:""}),c.default.debug("GIZ_SDK: 开始大循环搜索设备");const l=()=>n(this,void 0,void 0,(function*(){var n,d;if(this.hasTimeoutHandler())try{const h=yield(0,a.checkDeviceRegister)({SSID:e,password:t,productKeys:this.specialProductKeys});if((null===(n=h.err)||void 0===n?void 0:n.errorCode)===o.default.GIZ_OPENAPI_TOKEN_INVALID.errorCode)return void s({success:!1,err:o.default.GIZ_OPENAPI_TOKEN_INVALID});h.err||0===h.data.length?(yield(0,r.default)(250),!this.disableSearchDevice&&l()):(null===(d=this.eventCallBack)||void 0===d||d.call(this,{event:"GIZ_CONFIG_SUCCESS"}),u.default.appendEvent({name:"START_SEARCH_RANDOM_CODE_SUCCESS",message:JSON.stringify(h)}),c.default.debug("GIZ_SDK: 大循环搜索到设备",h),i({success:!0,data:h.data}))}catch(e){yield(0,r.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=>(c.default.log("GIZ_SDK: start bind device"),u.default.appendEvent({name:"START_BIND_DEVICE",message:""}),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(0,a.bindMac)({mac:e.mac,productKey:e.productKey,productSecret:i})});try{const s=yield Promise.all(n),r=e.filter((e,t)=>{const i=s[t];return i&&i.success});if(r.length>0)c.default.log("GIZ_SDK: bind device success",r),u.default.appendEvent({name:"BIND_DEVICE_SUCCESS",message:JSON.stringify(r)}),t({success:!0,data:r});else{c.default.log("GIZ_SDK: bind device error",s);const t={success:!1,data:e,err:o.default.GIZ_SDK_BIND_DEVICE_FAILED};u.default.appendEvent({name:"BIND_DEVICE_FAIL",message:JSON.stringify(t)}),i(t)}}catch(e){i(e)}})))),this.ssid=e,this.bssid=t,this.password=i,this.specialProductKeys=s,this.specialProductKeySecrets=l}}},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 o(e){try{c(n.next(e))}catch(e){r(e)}}function a(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(o,a)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(16),r=i(14),o=i(12),a=i(7);t.default=new class{constructor(){this.isSuccess=!1,this.productKey="",this.logs=[],this.init=e=>{this.clean(),this.productKey=e.productKey,this.ssid=e.ssid,this.mode=e.mode,this.isBind=e.isBind,this.timeout=e.timeout},this.getEnv=()=>{try{wx.getSystemInfoAsync({success:e=>{const t={wxSdkVersion:e.SDKVersion,gizwitsSdkVersion:s.version,appID:(0,r.getGlobalData)("appID"),bluetoothEnabled:e.bluetoothEnabled,locationEnabled:e.locationEnabled,wifiEnabled:e.wifiEnabled},i={brand:e.brand,model:e.model,pixelRatio:e.pixelRatio,systemVersion:e.system,platform:e.platform};this.mobileInfo=i,this.appInfo=t}})}catch(e){console.error(e)}},this.updateProductKey=e=>{this.productKey=e},this.appendEvent=e=>{try{this.logs.push(Object.assign(Object.assign({},e),{timestamp:Math.floor((new Date).getTime()/1e3)})),"WIFI_CONFIG_SUCCESS"===e.name&&(this.isSuccess=!0),"WIFI_CONFIG_SUCCESS"!==e.name&&"WIFI_CONFIG_FAIL"!==e.name||this.report()}catch(e){console.error(e)}},this.report=()=>n(this,void 0,void 0,(function*(){try{if(!this.productKey)return;if(0===this.logs.length)return;if(this.logs[0]&&"START_WIFI_CONFIG"!==this.logs[0].name)return;const e=new Date,t=(0,o.createUUID32)(),i=this.mobileInfo,n=this.appInfo,s={ssid:this.ssid,mode:this.mode,timeout:this.timeout,isBind:this.isBind},c={origin:"MINI-WX",mobileInfo:i,userInfo:{uid:(0,r.getGlobalData)("uid")},appInfo:n,eventID:t,eventType:"ConfigNetWorkDetail",monitorTarget:s,eventDetail:{success:this.isSuccess,processDetails:this.logs},time:e,timeStamp:Math.floor(e.getTime()/1e3)};if(console.debug("report data",c),this.productKey){const e=yield(0,a.statisticRequest)(`v2/products/${this.productKey}/devices/dist-net`,{method:"POST",body:c});e.success?console.debug("===已成功上报结束配网事件==="):console.error("===上报结束配网事件失败===",e)}this.clean()}catch(e){console.error(e)}})),this.cancel=()=>n(this,void 0,void 0,(function*(){return this.isSuccess=!1,this.appendEvent({name:"WIFI_CONFIG_CANCEL",message:""}),yield this.report()})),this.clean=()=>{this.logs=[],this.isSuccess=!1},this.getEnv()}}},function(e,t,i){var n,s,r,o,a,c,u,l;e.exports=(l=i(0),s=(n=l).lib,r=s.WordArray,o=s.Hasher,a=n.algo,c=[],u=a.SHA1=o.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],o=i[3],a=i[4],u=0;u<80;u++){if(u<16)c[u]=0|e[t+u];else{var l=c[u-3]^c[u-8]^c[u-14]^c[u-16];c[u]=l<<1|l>>>31}var d=(n<<5|n>>>27)+a+c[u];d+=u<20?1518500249+(s&r|~s&o):u<40?1859775393+(s^r^o):u<60?(s&r|s&o|r&o)-1894007588:(s^r^o)-899497514,a=o,o=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]+o|0,i[4]=i[4]+a|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=o.clone.call(this);return e._hash=this._hash.clone(),e}}),n.SHA1=o._createHelper(u),n.HmacSHA1=o._createHmacHelper(u),l.SHA1)},function(e,t,i){var n;e.exports=(n=i(0),i(15),function(){var e=n,t=e.lib.Hasher,i=e.x64,s=i.Word,r=i.WordArray,o=e.algo;function a(){return s.create.apply(s,arguments)}var c=[a(1116352408,3609767458),a(1899447441,602891725),a(3049323471,3964484399),a(3921009573,2173295548),a(961987163,4081628472),a(1508970993,3053834265),a(2453635748,2937671579),a(2870763221,3664609560),a(3624381080,2734883394),a(310598401,1164996542),a(607225278,1323610764),a(1426881987,3590304994),a(1925078388,4068182383),a(2162078206,991336113),a(2614888103,633803317),a(3248222580,3479774868),a(3835390401,2666613458),a(4022224774,944711139),a(264347078,2341262773),a(604807628,2007800933),a(770255983,1495990901),a(1249150122,1856431235),a(1555081692,3175218132),a(1996064986,2198950837),a(2554220882,3999719339),a(2821834349,766784016),a(2952996808,2566594879),a(3210313671,3203337956),a(3336571891,1034457026),a(3584528711,2466948901),a(113926993,3758326383),a(338241895,168717936),a(666307205,1188179964),a(773529912,1546045734),a(1294757372,1522805485),a(1396182291,2643833823),a(1695183700,2343527390),a(1986661051,1014477480),a(2177026350,1206759142),a(2456956037,344077627),a(2730485921,1290863460),a(2820302411,3158454273),a(3259730800,3505952657),a(3345764771,106217008),a(3516065817,3606008344),a(3600352804,1432725776),a(4094571909,1467031594),a(275423344,851169720),a(430227734,3100823752),a(506948616,1363258195),a(659060556,3750685593),a(883997877,3785050280),a(958139571,3318307427),a(1322822218,3812723403),a(1537002063,2003034995),a(1747873779,3602036899),a(1955562222,1575990012),a(2024104815,1125592928),a(2227730452,2716904306),a(2361852424,442776044),a(2428436474,593698344),a(2756734187,3733110249),a(3204031479,2999351573),a(3329325298,3815920427),a(3391569614,3928383900),a(3515267271,566280711),a(3940187606,3454069534),a(4118630271,4000239992),a(116418474,1914138554),a(174292421,2731055270),a(289380356,3203993006),a(460393269,320620315),a(685471733,587496836),a(852142971,1086792851),a(1017036298,365543100),a(1126000580,2618297676),a(1288033470,3409855158),a(1501505948,4234509866),a(1607167915,987167468),a(1816402316,1246189591)],u=[];!function(){for(var e=0;e<80;e++)u[e]=a()}();var l=o.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],o=i[3],a=i[4],l=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,m=o.high,D=o.low,b=a.high,S=a.low,w=l.high,I=l.low,C=d.high,B=d.low,A=h.high,E=h.low,k=f,T=p,O=v,x=g,P=y,L=_,M=m,N=D,R=b,H=S,U=w,K=I,G=C,F=B,j=A,z=E,W=0;W<80;W++){var V,Z,Y=u[W];if(W<16)Z=Y.high=0|e[t+2*W],V=Y.low=0|e[t+2*W+1];else{var $=u[W-15],J=$.high,X=$.low,q=(J>>>1|X<<31)^(J>>>8|X<<24)^J>>>7,Q=(X>>>1|J<<31)^(X>>>8|J<<24)^(X>>>7|J<<25),ee=u[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=u[W-7],oe=re.high,ae=re.low,ce=u[W-16],ue=ce.high,le=ce.low;Z=(Z=(Z=q+oe+((V=Q+ae)>>>0<Q>>>0?1:0))+ne+((V+=se)>>>0<se>>>0?1:0))+ue+((V+=le)>>>0<le>>>0?1:0),Y.high=Z,Y.low=V}var de,he=R&U^~R&G,fe=H&K^~H&F,pe=k&O^k&P^O&P,ve=T&x^T&L^x&L,ge=(k>>>28|T<<4)^(k<<30|T>>>2)^(k<<25|T>>>7),ye=(T>>>28|k<<4)^(T<<30|k>>>2)^(T<<25|k>>>7),_e=(R>>>14|H<<18)^(R>>>18|H<<14)^(R<<23|H>>>9),me=(H>>>14|R<<18)^(H>>>18|R<<14)^(H<<23|R>>>9),De=c[W],be=De.high,Se=De.low,we=j+_e+((de=z+me)>>>0<z>>>0?1:0),Ie=ye+ve;j=G,z=F,G=U,F=K,U=R,K=H,R=M+(we=(we=(we=we+he+((de+=fe)>>>0<fe>>>0?1:0))+be+((de+=Se)>>>0<Se>>>0?1:0))+Z+((de+=V)>>>0<V>>>0?1:0))+((H=N+de|0)>>>0<N>>>0?1:0)|0,M=P,N=L,P=O,L=x,O=k,x=T,k=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+k+(p>>>0<T>>>0?1:0),g=s.low=g+x,s.high=v+O+(g>>>0<x>>>0?1:0),_=r.low=_+L,r.high=y+P+(_>>>0<L>>>0?1:0),D=o.low=D+N,o.high=m+M+(D>>>0<N>>>0?1:0),S=a.low=S+H,a.high=b+R+(S>>>0<H>>>0?1:0),I=l.low=I+K,l.high=w+U+(I>>>0<K>>>0?1:0),B=d.low=B+F,d.high=C+G+(B>>>0<F>>>0?1:0),E=h.low=E+z,h.high=A+j+(E>>>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(l),e.HmacSHA512=t._createHmacHelper(l)}(),n.SHA512)},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.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=n(i(1)),r=i(3);class o extends s.default{constructor(e){super(e),this.passcode="";let t=0;const i=parseInt((0,r.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}}o.pack=()=>[0,0,0,3,3,0,0,6],t.default=o},function(e,t,i){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=n(i(1)),r=i(3);class o extends s.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((0,r.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}}}o.pack=({passcode:e})=>{let t=[0];const i=(0,r.hexStrint2byte)((0,r.fillString)(e.length.toString(16),4)),n=(0,r.string2Bytes)(e),s=[0].concat([0,8]).concat(i).concat(n);return t=(0,r.hexStrint2byte)(s.length.toString(16)),[0,0,0,3].concat(t).concat(s)},t.default=o},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 o(e){try{c(n.next(e))}catch(e){r(e)}}function a(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(o,a)}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.__decorate||function(e,t,i,n){var s,r=arguments.length,o=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,n);else for(var a=e.length-1;a>=0;a--)(s=e[a])&&(o=(r<3?s(o):r>3?s(t,i,o):s(t,i))||o);return r>3&&o&&Object.defineProperty(t,i,o),o},s=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function o(e){try{c(n.next(e))}catch(e){r(e)}}function a(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(o,a)}c((n=n.apply(e,t||[])).next())}))},r=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},o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.BleHandle=void 0;const a=o(i(4)),c=o(i(27)),u=i(13),l=o(i(31)),d=o(i(28)),h=o(i(1)),f=i(3),p=i(70),v=o(i(11)),g=i(10),y=i(32),_=i(12),m=i(34),D=o(i(29)),b=i(80),S=o(i(5)),w=o(i(81)),I=o(i(82)),C=o(i(83)),B=o(i(84)),A=o(i(85)),E=o(i(86)),k=o(i(87));function T(e){return function(t,i,n){const{value:s}=n;n.value=function(...t){return s.apply(this,t).then(i=>{var{_failureType_:n}=i,s=r(i,["_failureType_"]);return(0,p.reportEvent)({device:t[0],eventID:this.__event_id__,eventType:e,success:s.success}),Object.assign(Object.assign({},s),{_failureType_:e})})}}}class O extends D.default{set offlineThreshold(e){this._offlineThreshold=e}get offlineThreshold(){return this._offlineThreshold||1e4}constructor({pks:e=[],bleHandleParams:t={serviceUUIDSuffix:"abf0",characteristicUUIDSuffix:"abf7"},offlineThreshold:i}){super(),this.connectedList=[],this.connectingDevId=null,this.pks=[],this.listenDevOfflineTimer=null,this.methodQueue=Promise.resolve(),this.boradcastDataCache={},this.validBoradcastCmd=[152,154,25,148],this.baseServices=["ABF8","ABF0","F0AB","F8AB"],this.tmpBleData="",this.tmpDataNum=0,this.disableScanFlag=!1,this.peripheralServer=null,this.isActive=!0,this.isInitSuccess=!1,this.isRunInit=!1,this._offlineThreshold=null,this.scanList=[],this.onBluetoothAdapterStateChange=e=>{a.default.debug("onBluetoothAdapterStateChange",e,this.isRunInit,this.isInitSuccess),e.available?this.isRunInit&&!1===this.isInitSuccess&&this.init():(this.scanList=[],this.notifyDevices())},this.onAppShow=()=>{this.isActive=!0,this.scanList.map(e=>{e.ctime=Date.now()})},this.onAppHide=()=>{this.isActive=!1},this.listenDevOffline=()=>{this.listenDevOfflineTimer=setInterval(()=>{if(!this.isActive)return;const e=(new Date).getTime(),t=this.scanList.filter(t=>{const i=this.connectedList.find(e=>t.bleDeviceID==e.deviceId),n=this.connectingDevId===t.bleDeviceID;return!(!i&&!n)||("BLE_BROADCAST"===t.connectType?e-t.ctime<2*this.offlineThreshold:e-t.ctime<this.offlineThreshold)});t.length!==this.scanList.length&&(this.scanList=t,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=>{a.default.error("openBluetoothAdapter fail",new Error(JSON.stringify(e))),this.notifyError({errMsg:e.errMsg,errCode:-1}),i({success:!1,err:e})}})}),this.handleOnBLECharacteristicValueChange=e=>s(this,void 0,void 0,(function*(){if(!e.value)return;const t=(0,_.ab2hex)(e.value);try{const i=new h.default((0,f.hexStrint2byte)(t));this.tmpBleData=t,this.tmpDataNum=i.len-e.value.byteLength+4+Math.ceil(i.len.toString(2).length/8)}catch(i){this.tmpBleData&&(this.tmpBleData+=t,this.tmpDataNum-=e.value.byteLength)}this.tmpDataNum>0||!this.tmpBleData||(this.notiDeviceDataToSdk(e,this.tmpBleData),this.tmpBleData="",this.tmpDataNum=0)})),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=()=>s(this,void 0,void 0,(function*(){this.isRunInit=!0;const{platform:e}=wx.getSystemInfoSync();yield this.openBluetoothAdapter(),"ios"===e&&(yield this.openBluetoothAdapter("peripheral"));let t=!0;try{this.peripheralServer=(yield wx.createBLEPeripheralServer()).server,a.default.info("GIZ_SDK: 广播初始化成功",this.peripheralServer)}catch(e){a.default.error("GIZ_SDK: 广播初始化失败",new Error(JSON.stringify(e))),t=!1}if("android"===e&&!1===t)return{success:!1,message:"Android: GIZ_SDK初始化蓝牙广播失败"};const i=yield this.getBluetoothAdapterState();return this.isInitSuccess=!0,wx.onBluetoothDeviceFound(e=>{this.handleBluetoothDeviceFound(e)}),i})),this.checkPermission=()=>s(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){return a.default.log("授权失败",e),this.openBluetoothAdapter(),this.notifyError({errMsg:e.errMsg,errCode:-1}),{success:!1}}})),this.getBluetoothAdapterState=()=>s(this,void 0,void 0,(function*(){a.default.log("getBluetoothAdapterState",yield wx.getBluetoothAdapterState());const e=yield wx.getBluetoothAdapterState(),{errMsg:t,available:i}=e,n=r(e,["errMsg","available"]);return{data:Object.assign({},n),err:(0,_.wrapErrorInfo)(t),success:i}})),this.getDeviceStatus=(e,t,i,n)=>s(this,void 0,void 0,(function*(){const s=yield l.default.pack(t,i,n);return s?yield this.write(e,(0,_.numberArray2Uint8Array)(s).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=>{(0,_.unionBy)(e.devices,"deviceId").map(e=>{const{advertisData:t,deviceId:i,name:n,localName:s}=e,r=(0,_.ab2hex)(t);let o=null;try{o=(0,_.parseBroadcastData)((0,_.ab2numbers)(t))}catch(e){}const a=this.scanList.find(e=>e.bleDeviceID===i);if(o&&148===o.cmd){const n=(0,_.ab2hex)(t);if(this.boradcastDataCache[i]&&this.boradcastDataCache[i]===n)return!1;if(!a)return!1;this.boradcastDataCache[i]=(0,_.ab2hex)(t);const s=(0,u.padBoradcastData)(o.data.map(e=>parseInt(e,16)));return this.updateCtime(e),void this.notiDeviceDataToSdk(e,s)}if(o&&25===o.cmd){this.pks.find(e=>e===o.data.join(""))&&(e.communicationType="BLE_BROADCAST")}if(o&&this.validBoradcastCmd.includes(o.cmd)&&this.notiBoardCastData(e,o),a){const t=(0,_.BTDevice2GDevice)(e,this.pks);if(t.productKey&&t.mac){const e=this.checkDeviceIsChange(t,a);t.ctime=Date.now(),this.updateDevice(t),e&&this.notifyDevices()}}else{if(this.pks.some(e=>r.includes(e))){const t=(0,_.BTDevice2GDevice)(e,this.pks);t.productKey&&t.mac&&(this.scanList.push(t),this.notifyDevices())}}})},this.startScan=(e=5e3,t)=>s(this,void 0,void 0,(function*(){return this.disableScanFlag?{scanList:[]}:new Promise(i=>s(this,void 0,void 0,(function*(){a.default.debug("GIZ_SDK: start scan",e),yield wx.startBluetoothDevicesDiscovery({services:t||this.baseServices,powerLevel:"high",allowDuplicatesKey:!0,interval:200}),e>0&&setTimeout(()=>{this.stopScan(),i({scanList:this.scanList})},e)})))})),this.stopScan=()=>s(this,void 0,void 0,(function*(){try{return yield wx.stopBluetoothDevicesDiscovery()}catch(e){return e}})),this.disableScan=()=>s(this,void 0,void 0,(function*(){this.disableScanFlag=!0;const e=yield wx.stopBluetoothDevicesDiscovery();return yield(0,v.default)(200),e})),this.enableScan=()=>{this.disableScanFlag=!1},this.connectDevice=e=>s(this,void 0,void 0,(function*(){try{return this.connectingDevId=e.bleDeviceID,yield this._connectDevice(e)}finally{this.connectingDevId=null}})),this.handleWatchBleData=(e,t,i=3e3)=>s(this,void 0,void 0,(function*(){return new Promise(n=>{let s=(i,r)=>{if(e!==i.deviceId)return;const o=t(i,r);o&&(n({success:!0,data:o}),this.removeEventListener("GizBleDeviceData",s))};this.addEventListener("GizBleDeviceData",s),setTimeout(()=>{s&&(this.removeEventListener("GizBleDeviceData",s),n({success:!1,err:S.default.GIZ_SDK_DEVICE_NO_RESPONSE}))},i)})})),this.handleBindReq=e=>new Promise(t=>{const i=setTimeout(()=>{a.default.debug("绑定协议执行超时"),t({success:!1,data:""})},5e3),n=(s,r)=>{if(s.deviceId!==e)return;i&&clearTimeout(i),a.default.log("监听蓝牙特征值发生变化");const o=new c.default((0,f.hexStrint2byte)(r));this.removeEventListener("GizBleDeviceData",n),o.passcode?t({success:!0,data:o.passcode}):t({success:!1,data:""})};this.watchBleDevice(e,n)}),this.handleLoginReq=e=>new Promise(t=>{const i=setTimeout(()=>{a.default.debug("登录协议执行超时"),t({success:!1,data:""})},5e3),n=(s,r)=>{if(s.deviceId!==e)return;i&&clearTimeout(i),a.default.log("设备回复LoginReq",r);const o=new d.default((0,f.hexStrint2byte)(r));this.removeEventListener("GizBleDeviceData",n),!0===o.result?t({success:!0,data:o.did}):t({success:!1,data:""})};this.watchBleDevice(e,n)}),this.startUpgrade=({device:e,type:t,onEvent:i,onProgress:n,productKey:r})=>s(this,void 0,void 0,(function*(){i({code:"GizOTAEventPretreatment"});const s=yield this.checkUpdate({device:e,type:t});a.default.debug("检查设备是否有新固件",s);const o=e.bleDeviceID;if(s.success){const c=s.data.download_url,u=s.data.soft_ver;i({code:"GizOTAEventDownload"});let l="";try{l=(yield(0,m.downloadFile)({url:c})).tempFilePath}catch(e){return a.default.error("固件下载失败",e),{success:!1,err:S.default.GIZ_SDK_OTA_FIRMWARE_DOWNLOAD_FAILED}}a.default.debug("下载固件成功",l),i({code:"GizOTAEventTransmit"});const d=(e,t)=>{const i=(0,f.hexStrint2byte)(t);switch(new h.default(i).cmd){case"0042":return new I.default(i)}return null},p=(e,t)=>{const i=(0,f.hexStrint2byte)(t);switch(new h.default(i).cmd){case"0044":return new C.default(i)}return null},D=(e,t)=>{const i=(0,f.hexStrint2byte)(t);switch(new h.default(i).cmd){case"0052":return new E.default(i)}return null};a.default.debug("查询设备是否可以OTA");const b=I.default.pack(t);yield this.write(o,(0,_.numberArray2Uint8Array)(b).buffer);const w=yield this.handleWatchBleData(o,d);if(a.default.debug("设备回复是否可以OTA",w),w.success&&w.data.type!==t)return a.default.error(null,new Error("OTA类型不匹配")),{success:!1,err:S.default.GIZ_SDK_OTA_FIRMWARE_TYPE_NOT_MATCH};if(w.success&&0===w.data.state){const s=wx.getFileSystemManager();let c=[];try{c=yield s.readFileSync(l,"hex",0)}catch(e){return a.default.error("读取固件失败",e),{success:!1,err:S.default.GIZ_SDK_OTA_FIRMWARE_DOWNLOAD_FAILED}}const d=c.match(/.{1,2}/g).map((function(e){return parseInt(e,16)})),m=(0,_.arrayBufferToWordArray)(d),b=(0,g.MD5)(m).toString(),w=(0,y.crc32)(d),I=C.default.pack(r,u,b,d.length,w);yield this.write(o,(0,_.numberArray2Uint8Array)(I).buffer);const E=yield this.handleWatchBleData(o,p,5e3);if(a.default.debug("设备回复ota 预请求",E),E.success&&0===E.data.state){let s=0;if(E.data.processedLen>0){(0,y.crc32)(d.slice(0,E.data.processedLen)).toString(16)===E.data.processedCrc32?(s=E.data.processedLen,a.default.debug(`断点续传,从 ${s} 开始`)):(a.default.debug("从位置0开始OTA"),yield this.write(o,(0,_.numberArray2Uint8Array)(B.default.pack(0)).buffer),yield(0,v.default)(100))}const r=d.length,c=E.data.packageMaxLen;let l=Math.ceil(s/c),p=0;for(;s<r;){const e=d.slice(s,s+c),t=A.default.pack(e,l);yield this.write(o,(0,_.numberArray2Uint8Array)(t).buffer);const i=(e,t)=>{const i=(0,f.hexStrint2byte)(t);switch(new h.default(i).cmd){case"0048":{const e=new A.default(i);return e.packageNum===l?e:null}}return null},u=yield this.handleWatchBleData(o,i,5e3);let g=!1;if(!1===u.success&&(g=!0),u.success&&0!==u.data.state&&4!==u.data.state&&(g=!0),g){if(p+=1,a.default.debug(`发送OTA包失败,重试次数 ${p}`,u),p>3)return a.default.debug("发送OTA包失败次数超过限制"),{success:!1};continue}a.default.debug("设备接收ota子包成功",u),p=0,s+=c,l+=1;let y=parseInt(`${l*c/r*100}`);if(y>100&&(y=100),n({firmwareSize:r,packageMaxLen:c,currentNumber:l,currentProgress:y}),yield(0,v.default)(100),4===u.data.state){a.default.debug("设备请求等待OTA");const e=yield this.handleWatchBleData(o,D,6e4);if(a.default.debug("设备回复等待结果",e),1===e.data.state)return{success:!1}}}a.default.debug("发送完所有数据包,等待设备回复");const g=(e,t)=>{const i=(0,f.hexStrint2byte)(t);switch(new h.default(i).cmd){case"0050":return new k.default(i)}return null},m=yield this.handleWatchBleData(o,g,1e4);if(m.success&&0===m.data.state){a.default.debug("设备回复收到固件,准备重启设备"),i({code:"GizOTAEventReboot"}),this.disConnectDevice(o),yield(0,v.default)(1e4);const n=yield this.connectDevice(e);if(console.log("connectRes",n),!n.success)return a.default.debug("设备重启后,无法连接"),{success:!1};const s=yield this.getDeviceInfo({deviceId:o});if(!s.success)return a.default.debug("获取设备版本号失败"),{success:!1};let r="";return r="MCU"===t?s.data.mcuSoftVersion:s.data.moduleSoftVersion,i({code:"GizOTAEventFinish"}),r===u?{success:!0}:(a.default.debug("设备上报版本号与更新的固件版本号不匹配,更新失败"),{success:!1})}return{success:!1}}return{success:!1}}return{success:!1,err:S.default.GIZ_SDK_OTA_DEVICE_BUSY_IN_UPGRADE}}return s})),this.getDeviceInfo=({deviceId:e})=>s(this,void 0,void 0,(function*(){const t=w.default.pack();a.default.debug("DeviceInfo.pack",t),yield this.write(e,(0,_.numberArray2Uint8Array)(t).buffer);return yield this.handleWatchBleData(e,(e,t)=>{const i=(0,f.hexStrint2byte)(t);switch(new h.default(i).cmd){case"0014":try{const e=new w.default(i);return a.default.debug("parse DeviceInfo",e),e}catch(e){a.default.debug("parse DeviceInfo error",e)}}return null})})),this.checkUpdate=({device:e,type:t})=>s(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(0,b.checkUpdate)({did:e.did,type:t,softVersion:n,hardVersion:s})}return{success:!1,err:i.err}})),this.watchBleDevice=(e,t)=>s(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)),a.default.log(`监听设备 ${e} 成功!`),this.addEventListener("GizBleDeviceData",t),{message:"ok",success:!0})})),this.sendAdv=(e,t=1e3)=>s(this,void 0,void 0,(function*(){try{return this.peripheralServer.stopAdvertising({}),this.peripheralServer.startAdvertising({advertiseRequest:{connectable:!0,serviceUuids:e},powerLevel:"high",success:e=>{a.default.debug("GIZ_SDK: startAdvertising success",e)},fail:e=>{a.default.error("GIZ_SDK: startAdvertising error",new Error(JSON.stringify(e)))}}),a.default.debug("GIZ_SDK: start adv",e),yield(0,v.default)(t),this.peripheralServer.stopAdvertising({}),{success:!0}}catch(e){return a.default.log("GIZ_SDK:",e),{success:!1,message:"send cmd error"}}})),this.writeBigDataTimeoutHandle=null,this.writeBigData=(e,t)=>s(this,void 0,void 0,(function*(){return new Promise((i,n)=>s(this,void 0,void 0,(function*(){if(this.writeBigDataTimeoutHandle)return void i({success:!1,message:"send big data already"});const n=this.scanList.find(t=>t.bleDeviceID===e);if(!n)return{success:!1,message:"not found device"};let s=-1;const r=(0,_.splitIntoChunks)(t,19);r.map((e,t)=>{r[t].unshift(t)});const o=(0,_.convertToServiceUuids)({mac:n.mac,index:0,data:[r.length],len:1,cmd:151}),c=r.map(e=>(0,_.convertToServiceUuids)({mac:n.mac,index:0,data:e,len:e.length,cmd:153})),u=(t,i)=>{if(console.log("boardCastData",t.deviceId,e),t.deviceId==e)switch(i.cmd){case 154:{const e=i.data[0];parseInt(e,16)===s?(s+=1,a.default.debug("设备回复收到数据包",e)):a.default.debug("数据包序号不匹配",e,s);break}case 152:s=0,a.default.debug("设备回复引导,开始发送数据")}};this.addBoardCastDataListener(u);let l=!0;for(this.writeBigDataTimeoutHandle=setTimeout(()=>{a.default.debug("发送大数据超时"),i({success:!1,message:"write big data timeout"}),this.removeBoardCastDataListener(u),this.writeBigDataTimeoutHandle=null,l=!1},2e4);s<r.length&&l;){if(!this.writeBigDataTimeoutHandle)return;if(-1==s)a.default.debug("发送引导包",o),yield this.sendAdv(o);else{const e=c[s];a.default.debug("发送数据包",e),e&&(yield this.sendAdv(e))}}this.removeBoardCastDataListener(u),l&&(this.writeBigDataTimeoutHandle&&(clearTimeout(this.writeBigDataTimeoutHandle),this.writeBigDataTimeoutHandle=null),i({success:!0,message:"write big data success"}))})))})),this.writeBoradcast=(e,t)=>s(this,void 0,void 0,(function*(){const i=this.scanList.find(t=>t.bleDeviceID===e);if(!i)return{success:!1,message:"not found device"};const n=(0,_.convertToServiceUuids)({mac:i.mac,index:0,data:t,len:t.length,cmd:147});return this.sendAdv(n)})),this.write=(e,t)=>s(this,void 0,void 0,(function*(){return this.methodQueue=this.methodQueue.then(()=>s(this,void 0,void 0,(function*(){a.default.log("app => dev:",(0,_.ab2hex)(t));const i=this.getTargetDevice(e);if(i.serviceId&&i.characteristicId){const n=yield(0,m.unpackWriteBLECharacteristicValue)(e,i.serviceId,i.characteristicId,t);return 0==n.errCode?{success:!0,message:n.errMsg}:{success:!1,message:n.errMsg}}return{success:!1,message:"send cmd error"}}))),this.methodQueue})),this.disConnectDevice=e=>s(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.boardCastDataListenerCallbacks=[],this.notiBoardCastData=(e,t)=>{this.boardCastDataListenerCallbacks.forEach(i=>{i(e,t)})},this.addBoardCastDataListener=e=>{this.boardCastDataListenerCallbacks.push(e)},this.removeBoardCastDataListener=e=>{this.boardCastDataListenerCallbacks=this.boardCastDataListenerCallbacks.filter(t=>t!==e)},this.destory=()=>{this.listenDevOfflineTimer&&clearInterval(this.listenDevOfflineTimer),wx.offAppShow(this.onAppShow),wx.offAppHide(this.onAppHide),wx.offBluetoothAdapterStateChange(this.onBluetoothAdapterStateChange)};const{serviceUUIDSuffix:n}=t;this.serviceUUIDSuffix=n,this.pks=e,this.offlineThreshold=i,this.listenDevOffline(),this.listenConnection(),wx.onAppShow(this.onAppShow),wx.onAppHide(this.onAppHide),wx.onBluetoothAdapterStateChange(this.onBluetoothAdapterStateChange)}connectDeviceBle(e){var t,i,n;return s(this,void 0,void 0,(function*(){yield this.disableScan();const s=yield(0,m.retryConnect)(e.bleDeviceID);if(this.enableScan(),a.default.debug("connect res",s),!s.success&&(a.default.error("GIZ_SDK: createBLEConnection error",new Error(JSON.stringify(s.error))),"createBLEConnection:fail:already connect"!==(null===(t=s.error)||void 0===t?void 0:t.errMsg)))return this.notifyError(s.error),{success:!1,message:null===(i=s.error)||void 0===i?void 0:i.errMsg};const r=yield wx.getBLEDeviceServices({deviceId:e.bleDeviceID}).catch(e=>this.notifyError(e)),o=null===(n=null==r?void 0:r.services.find(e=>e.isPrimary&&e.uuid.toLowerCase().includes(this.serviceUUIDSuffix)))||void 0===n?void 0:n.uuid;if(!o)return{message:"can not find valid serviceId",success:!1};const c=yield wx.getBLEDeviceCharacteristics({deviceId:e.bleDeviceID,serviceId:o}).catch(e=>this.notifyError(e));return{success:!0,data:{serviceId:o,characteristicId:null==c?void 0:c.characteristics[0].uuid}}}))}connectDeviceBindRequest(e){return s(this,void 0,void 0,(function*(){this.write(e.bleDeviceID,(0,_.numberArray2Uint8Array)(c.default.pack()).buffer);const t=yield this.handleBindReq(e.bleDeviceID);return a.default.log("handleBindReq",t),t.success||(yield wx.closeBLEConnection({deviceId:e.bleDeviceID})),t}))}connectDeviceLoginRequest(e,t){return s(this,void 0,void 0,(function*(){this.write(e.bleDeviceID,(0,_.numberArray2Uint8Array)(d.default.pack({passcode:t})).buffer);const i=yield this.handleLoginReq(e.bleDeviceID).catch(e=>this.notifyError(e));return{success:!!(null==i?void 0:i.success),message:"ok"}}))}_connectDevice(e){return s(this,void 0,void 0,(function*(){const t=yield this.connectDeviceBle(e);if(!t.success)return t;const{serviceId:i,characteristicId:n}=t.data;this.connectedList.every(t=>t.deviceId!==e.bleDeviceID)&&this.connectedList.push({deviceId:e.bleDeviceID,serviceId:i,characteristicId:n}),yield wx.notifyBLECharacteristicValueChange({deviceId:e.bleDeviceID,serviceId:i,characteristicId:n,state:!0,type:"notification"}).catch(e=>this.notifyError(e));const s=yield this.connectDeviceBindRequest(e);return s.success?yield this.connectDeviceLoginRequest(e,s.data):s}))}}n([T("BleDeviceConnectEnd")],O.prototype,"connectDeviceBle",null),n([T("BleDeviceConnectBind")],O.prototype,"connectDeviceBindRequest",null),n([T("BleDeviceConnectLogin")],O.prototype,"connectDeviceLoginRequest",null),n([function(e,t,i){const{value:n}=i;i.value=function(...e){const t=Object.create(this);return t.__event_id__=function(){let e=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){let i=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==t?i:3&i|8).toString(16)}))}(),(0,p.reportEvent)({device:e[0],eventID:t.__event_id__,eventType:"BleDeviceConnectStart",success:!0}),n.apply(t,e).then(i=>{var{_failureType_:n}=i,s=r(i,["_failureType_"]);return(0,p.reportEvent)(Object.assign({device:e[0],eventID:t.__event_id__,eventType:"BleDeviceConnectFinish",success:s.success},s.success?{}:{failureType:n})),s})}}],O.prototype,"_connectDevice",null),t.BleHandle=O},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 o(e){try{c(n.next(e))}catch(e){r(e)}}function a(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(o,a)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(20)),o=s(i(1)),a=i(3);class c extends o.default{}c.pack=(e,t,i)=>n(void 0,void 0,void 0,(function*(){const n=yield r.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 u=[0,0,0,0],l=[2];if(t){o=[1];const e=(0,a.fillString)(t.length.toString(16),4),i=(0,a.hexStrint2byte)(e),n=(0,a.string2Bytes)(t);u=u.concat(i).concat(n)}if(e){l=[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=(0,a.fillString)(e,8*Math.ceil(e.length/8)),l=l.concat((0,a.hexStrint2byte)(parseInt(e,2).toString(16)))}const d=o.concat(c).concat(u).concat(l);return r[0]=d.length,s.concat(r).concat(d)}return null})),t.default=c},function(e,t,i){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.crc32=t.crc16modbus=void 0;const s=n(i(71));t.crc16modbus=s.default;const r=n(i(78));t.crc32=r.default,t.default={crc16modbus:s.default,crc32:r.default}},function(e,t,i){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=n(i(73));t.default=function(e,t){const i=(e,i)=>t((0,s.default)(e),i)>>>0;return i.signed=(e,i)=>t((0,s.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 o(e){try{c(n.next(e))}catch(e){r(e)}}function a(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(o,a)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.setMtu=t.downloadFile=t.unpackWriteBLECharacteristicValue=t.writeBLECharacteristicValue=t.notifyBLECharacteristicValueChange=t.getBLEDeviceCharacteristics=t.getBLEDeviceServices=t.createBLEConnection=t.getBluetoothDevices=t.startBluetoothDevicesDiscovery=t.getBluetoothAdapterState=t.closeBluetoothAdapter=t.openBluetoothAdapter=t.retryConnect=void 0;const r=s(i(11));function o(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 a(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=3e3){return n(this,void 0,void 0,(function*(){let i={success:!1,error:null};for(let n=0;n<5;n++)try{return console.debug("start createBLEConnection"),{success:yield o(e,t),error:null}}catch(e){i={success:!1,error:e},console.debug("createBLEConnection error retry"),yield(0,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=o,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=a,t.unpackWriteBLECharacteristicValue=function(e,t,i,s,o=20){if(!s||0===s.byteLength)throw new Error("value is empty");return new Promise((c,u)=>n(this,void 0,void 0,(function*(){let n,l=0,d=s.byteLength;for(;d>0;){yield(0,r.default)(10);const c=s.slice(l,l+o);if(l+=o,d-=o,n=yield a(e,t,i,c),0!==n.errCode)break}0!==n.errCode?u(n):c(n)})))},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)}})})}))},t.setMtu=function(e,t){return n(this,void 0,void 0,(function*(){return new Promise(i=>{wx.setBLEMTU({mtu:e,deviceId:t,success:e=>{i(e.mtu)},fail:()=>{i(20)}})})}))}},function(e,t,i){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=n(i(1)),r=i(3);class o extends s.default{constructor(e){super(e)}}o.pack=(e,t)=>{const i=[],[n,s]=(0,r.formatCodesFromStr)(e),[o,a]=(0,r.formatCodesFromStr)(t),c=[0].concat([0,1],s,n,a,o);let u=c.length;for(;u>0;)i.push(u),u-=255;const l=[0,0,0,3].concat(i).concat(c),d=new ArrayBuffer(l.length),h=new Uint8Array(d);for(let e=0;e<d.byteLength;e++)h[e]=l[e];return h},t.default=o},function(e,t,i){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var s=Object.getOwnPropertyDescriptor(t,i);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,s)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),s=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||n(t,e,i)},r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.BleHandle=t.errorCode=void 0,i(37);const o=r(i(38)),a=r(i(5));t.errorCode=a.default;const c=i(30);Object.defineProperty(t,"BleHandle",{enumerable:!0,get:function(){return c.BleHandle}}),t.default=o.default,s(i(105),t)},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 o(e){try{c(n.next(e))}catch(e){r(e)}}function a(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(o,a)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=i(14),o=s(i(16)),a=i(39),c=s(i(20)),u=i(13),l=s(i(68)),d=i(69),h=s(i(1)),f=i(3),p=i(30),v=s(i(88)),g=s(i(91)),y=s(i(92)),_=s(i(4)),m=s(i(5)),D=i(21),b=i(93),S=i(94),w=s(i(11)),I=i(12),C=s(i(95)),B=s(i(96)),A=s(i(97)),E=s(i(31)),k=o.default.version;class T{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=(0,I.merageBleLocalDevices)([...this.deviceList],this.bleDevices);e=(0,I.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")}),e}get bleScanDevice(){return this.bleDevices.filter(e=>!0===e.isBleOnline)}constructor(e){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.init=({appID:e,appSecret:t,productInfo:i,cloudServiceInfo:n,token:s,uid:o,offlineThreshold:a})=>{this.productInfo=i,(0,r.setGlobalData)("appID",e),(0,r.setGlobalData)("appSecret",t),(0,r.setGlobalData)("productInfo",i),(0,r.setGlobalData)("token",s),(0,r.setGlobalData)("uid",o),this.setDomain(n),this.offlineThreshold=a,_.default.debug(`init sdk success, current version: ${T.getVersion().data}`),this.initLan()},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(0,u.unpack)((0,f.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.handleBleDeviceData=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>t.bleDeviceID===e.deviceId);if(i){const s=(0,f.hexStrint2byte)(t);switch(new h.default(s).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);(0,S.uploadP0)({device:i,data:[{raw:t,created_at:n}],productSecret:e.productSecret}).then(e=>{_.default.debug("设备上报数据:timestemp",new Date(1e3*n).toLocaleString(),e)})}}const e=yield(0,u.unpack)((0,f.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 g.default(s);_.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*(){_.default.debug("代理重置结果",t),t.success&&t.data.successDevices.length>0&&(_.default.debug("重置成功,回写数据"),yield this.bleHandle.write(e.deviceId,(0,I.numberArray2Uint8Array)(y.default.pack(0)).buffer))})));break}case"0064":break;case"0072":{const t=new d.RequestSync(s);if(_.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}),_.default.debug("查询第一条离线数据"),yield this.bleHandle.write(e.deviceId,(0,I.numberArray2Uint8Array)(d.SyncPackage.pack(0)).buffer)):(_.default.debug("设备返回状态为1,同步失败"),this.syncDataCallBack({event:"SYNC_FAIL"}));break}case"0074":{if(!this.syncDataCallBack)break;_.default.debug("设备上报离线数据");const t=new d.SyncPackage(s),i=d.DeletePackage.pack(t.id);_.default.debug("设备上报离线数据:payload",t.payload);try{_.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(0,S.uploadP0)({device:this.syncDevice,data:[{raw:(0,f.arrayToString)(t.payload),created_at:t.timestemp}],productSecret:n.productSecret});_.default.debug("上传离线数据结果",e)}this.syncCurrnetNum+=1,this.syncDataCallBack({event:"SYNC_PROGRESS",totalNum:this.syncTotalNum,currentNum:this.syncCurrnetNum}),_.default.debug("通知设备删除:",t.id),yield this.bleHandle.write(e.deviceId,(0,I.numberArray2Uint8Array)(i).buffer),yield(0,w.default)(100),t.id<this.syncTotalNum-1?(_.default.debug("查询新数据:",t.id+1),yield this.bleHandle.write(e.deviceId,(0,I.numberArray2Uint8Array)(d.SyncPackage.pack(t.id+1)).buffer)):(_.default.debug("send cancel sync to device"),this.bleHandle.write(e.deviceId,(0,I.numberArray2Uint8Array)(d.CancelSync.pack()).buffer),this.syncDataCallBack({event:"SYNC_END"}),this.cleanSyncDeviceData());break}case"0078":{if(!this.syncDataCallBack)break;const e=new d.CancelSync(s);_.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(0,u.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);_.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){_.default.error("init lan error",e)}},this.startAutoScan=e=>{this.keepScanTimer?_.default.debug("startAutoScan fail. keepScanTimer is init"):(this.keepScanTimer=setInterval(()=>n(this,void 0,void 0,(function*(){this.bleHandle.startScan(-1,e)})),9e3),this.bleHandle.startScan(-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.setDevicesMeta=(e,t,i,n=!1)=>{let s=!1;const r=e.map(e=>this.allDevices.find(t=>t.mac===e.mac));for(let e=0;e<r.length;e++){const o=r[e];o&&(o[t]!==i||n)&&(o[t]=i,s=!0)}s&&this.notiDeviceList()},this.initBle=()=>n(this,void 0,void 0,(function*(){try{this.bleHandle.addEventListener("GizBleDeviceData",this.handleBleDeviceData),this.bleHandle.addEventListener("GizBleDeviceList",this.handleBleDevices),this.bleHandle.addEventListener("GizBleError",this.handleBleError);const e=yield this.bleHandle.checkPermission();if(!e.success)return _.default.error("init BLE Error",new Error(JSON.stringify(e))),{success:!1,err:m.default.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON};_.default.debug("init BLE succcess",e)}catch(e){return _.default.error("init BLE error",e),{success:!1,err:m.default.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON}}return{success:!0}})),this.scanBleDevice=(e,t)=>n(this,void 0,void 0,(function*(){return this.bleHandle.scanList=[],{success:!0,data:(yield this.bleHandle.startScan(e,t)).scanList}})),this.writeBigData=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>(0,I.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.writeBigData(i.bleDeviceID,t)}return{success:!1,message:"the connectType not support write big data"}})),this.write=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>(0,I.isSameDevice)(t,e));if(!i)return{success:!1,message:"target is undefind"};if("NONE"!==i.connectType){const{data:e,raw:n}=yield(0,u.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,(0,I.numberArray2Uint8Array)(e).buffer):{success:!1};case"WAN":{const e=yield(0,u.formatEnum)(t,i.productKey,"string");return this.socketHandle.writeData(i,e)}case"LAN":return this.lanHandle.write(i,(0,I.numberArray2Uint8Array)(e).buffer)}}return{success:!1}})),this.writeRaw=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>(0,I.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,(0,I.numberArray2Uint8Array)(t).buffer):{success:!1};case"WAN":return this.socketHandle.send(i,t);case"LAN":return this.lanHandle.write(i,(0,I.numberArray2Uint8Array)(t).buffer)}return{success:!1}})),this.setDeviceTimeStamp=e=>n(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>(0,I.isSameDevice)(t,e));if(!t)return{success:!1,message:"target is undefind"};const i=l.default.pack();switch(t.connectType){case"BLE":return this.bleHandle.write(e.bleDeviceID,(0,I.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=>(0,I.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":{_.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=d.RequestSync.pack();return _.default.debug("sent RequestSync data"),this.bleHandle.write(e.bleDeviceID,(0,I.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=>(0,I.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=d.RequestSync.pack();return this.syncDevice=Object.assign({},t),_.default.debug("sent RequestSync data len"),this.bleHandle.write(e.bleDeviceID,(0,I.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 c.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(0,b.AnonymousLogin)({uid:e});return n.success&&((0,r.setGlobalData)("token",null===(t=n.data)||void 0===t?void 0:t.token),(0,r.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=>(0,I.isSameDevice)(t,e));if(!i)return{success:!1,message:"target is undefind"};switch(i.connectType){case"BLE_BROADCAST":{const e=yield E.default.pack(i.productKey,null,t),n=new h.default(e);return yield this.bleHandle.writeBoradcast(i.bleDeviceID,n.content)}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*(){_.default.debug("subscribe device:",e);let i=this.allDevices.find(t=>(0,I.isSameDevice)(t,e));if(!i)return _.default.warn("Device Target Not Found"),_.default.warn("current devices ",this.allDevices),{success:!1,message:"device not found"};if("BLE_BROADCAST"===i.connectType)return{success:!0,message:""};const n=(0,I.getFirstConnectType)(i,t);switch("NONE"!==i.connectType&&i.connectType!==n&&(yield this.unSubscribe(i)),n){case"BLE":{const e=yield this.bleHandle.connectDevice(i);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,message:""}})),this.batchSubscribe=(e,t)=>n(this,void 0,void 0,(function*(){var i,n,s;_.default.debug("subscribe devices =>",e);const r=this.allDevices.reduce((e,t)=>Object.assign(Object.assign({},e),{[(0,I.getDeviceId)(t)]:t}),{}),o=e.filter(e=>r[(0,I.getDeviceId)(e)]);if(0===o.length)return _.default.warn("Device Target Not Found"),_.default.warn("current devices ",this.allDevices),{success:!1,message:"device not found"};const a=o.reduce((e,i)=>{const n="BLE_BROADCAST"===i.connectType?"BLE_BROADCAST":(0,I.getFirstConnectType)(i,t);return e[n]||(e[n]=[]),e[n].push(i),e},{}),c=Object.keys(a);if(1===c.length&&"BLE_BROADCAST"===c[0])return{success:!0,message:""};if((null!==(i=a.BLE)&&void 0!==i?i:[]).length>0||(null!==(n=a.LAN)&&void 0!==n?n:[]).length>0)return{success:!1,message:"BLE and LAN can not subscribe together"};const u=null!==(s=a.WAN)&&void 0!==s?s:[];if(0===u.length)return{success:!1,message:"no WAN device"};const l=u.filter(e=>"NONE"!==e.connectType&&"WAN"!==e.connectType);l.length>0&&(yield this.batchWanUnSubscribe(l));const d=this.socketHandle.connectDevices(u);return d.success&&this.setDevicesMeta(u,"connectType","WAN",!0),d})),this.batchWanUnSubscribe=e=>n(this,void 0,void 0,(function*(){const t=yield this.socketHandle.disConnectDevices(e);return t.success&&this.setDevicesMeta(e,"connectType","NONE",!0),t})),this.unSubscribe=e=>n(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>(0,I.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=(0,I.getProductInfoThroughPK)(t,this.productInfo);if(n){const r=yield(0,D.bindMac)({mac:e,productKey:t,productSecret:n.productSecret,alias:i,beOwner:s});return this.getBindingList(),r}return{success:!1,err:m.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=>(0,I.isSameDevice)(t,e));if(i){if(!i.did)return{success:!1,err:m.default.GIZ_OPENAPI_DEVICE_NOT_BOUND};switch(i.connectType){case"BLE":return this.bleHandle.checkUpdate({device:e,type:t});default:return{success:!1,err:m.default.GIZ_SDK_OTA_DEVICE_NOT_SUPPORT}}}return{success:!1,err:m.default.GIZ_SDK_DEVICE_NOT_SUBSCRIBED}})),this.getDeviceInfo=({device:e})=>n(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>(0,I.isSameDevice)(t,e));if(t){if(!t.did)return{success:!1,err:m.default.GIZ_OPENAPI_DEVICE_NOT_BOUND};switch(t.connectType){case"BLE":return this.bleHandle.getDeviceInfo({deviceId:e.bleDeviceID});default:return{success:!1,err:m.default.GIZ_SDK_OTA_DEVICE_NOT_SUPPORT}}}return{success:!1,err:m.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=>(0,I.isSameDevice)(t,e));if(n){if(!n.did)return{success:!1,err:m.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:m.default.GIZ_SDK_OTA_DEVICE_NOT_SUPPORT}}}return{success:!1,err:m.default.GIZ_SDK_DEVICE_NOT_SUBSCRIBED}})),this.unbindDevice=({devices:e})=>n(this,void 0,void 0,(function*(){const t=yield(0,D.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,bssid:t="",password:i,mode:s=0,timeout:o,productKey:a,isBind:c=!0,softAPSSIDPrefix:u,eventCallBack:l})=>n(this,void 0,void 0,(function*(){if(this.currentWifiConfigHandle)return{success:!1,err:m.default.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING};const n=(new Date).getTime();_.default.debug("GIZ_SDK: 配网开始时间:"+n,s);try{switch(s){case 0:{this.currentWifiConfigHandle=new C.default(e,t,i,this.specialProductKeys,this.specialProductKeySecrets);const s=yield this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:o,isBind:c,productKey:a,softAPSSIDPrefix:u,eventCallBack:l});this.currentWifiConfigHandle=null;const r=(new Date).getTime();return _.default.debug("GIZ_SDK: 配网结束时间:"+r),_.default.debug("GIZ_SDK: 配网用时:"+(r-n)),s}case 3:{this.currentWifiConfigHandle=new B.default(e,t,i,this.specialProductKeys,this.specialProductKeySecrets,this.bleHandle);const s=yield this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:o,isBind:c,productKey:a,softAPSSIDPrefix:u,eventCallBack:l});this.currentWifiConfigHandle=null;const r=(new Date).getTime();return _.default.debug("GIZ_SDK: 配网结束时间:"+r),_.default.debug("GIZ_SDK: 配网用时:"+(r-n)),s}case 5:{const s=yield wx.getSystemInfoSync();if(console.log("sysInfosysInfo",s),"android"!==s.platform)return{success:!1,message:"只支持安卓"};const a=(0,r.getGlobalData)("cloudServiceInfo");console.log("cloudServiceInfo",a),this.currentWifiConfigHandle=new A.default(e,t,i,this.specialProductKeys,this.specialProductKeySecrets,(null==a?void 0:a.openAPIInfo)||"api.gizwits.com");const d=yield this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:o,isBind:c,softAPSSIDPrefix:u,eventCallBack:l});this.currentWifiConfigHandle=null;const h=(new Date).getTime();return _.default.debug("GIZ_SDK: 配网结束时间:"+h),_.default.debug("GIZ_SDK: 配网用时:"+(h-n)),d}}}catch(e){return _.default.error("GIZ_SDK: setDeviceOnboardingDeploy",e),e.err&&e.err.errorCode?e:{success:!1,err:m.default.GIZ_SDK_OTHERWISE}}finally{this.currentWifiConfigHandle=null}})),this.setDomain=e=>{const t=e&&e.openAPIInfo||"api.gizwits.com",i=Object.assign(Object.assign({},e||{}),{openAPIInfo:t});(0,r.setGlobalData)("cloudServiceInfo",i)},this.deviceSafetyApi=({mac:e,productKey:t,isReset:i})=>n(this,void 0,void 0,(function*(){const n=(0,I.getProductInfoThroughPK)(t,this.productInfo);return n?yield(0,D.safeRegister)({productKey:t,productSecret:n.productSecret,mac:e,isReset:i,passcode:"1234567890"}):{success:!1,err:m.default.GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY}})),this.getBindingList=()=>n(this,void 0,void 0,(function*(){const e=yield(0,D.getBindingList)();return this.deviceList=e.data||[],this.notiDeviceList(),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=>_.default.setLogLevel(e),this.renameDevice=(e,t)=>n(this,void 0,void 0,(function*(){return t?e.isBind?yield(0,D.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.init(e)}get bleHandle(){return this._bleHandle||(this._bleHandle=new p.BleHandle({pks:this.specialProductKeys,offlineThreshold:this.offlineThreshold})),this._bleHandle}get lanHandle(){return this._lanHandle||(this._lanHandle=new a.LanHandle({pks:this.specialProductKeys})),this._lanHandle}get socketHandle(){return this._gizSocket||(this._gizSocket=new v.default({appID:(0,r.getGlobalData)("appID"),token:(0,r.getGlobalData)("token"),uid:(0,r.getGlobalData)("uid")}),this._gizSocket.subscribeDeviceStatus(this.handleSocketDeviceData),this._gizSocket.subscribeBindingChanged(this.getBindingList),this._gizSocket.subscribeSocketStatus(this.handleSocketStatus)),this._gizSocket}reInit(e){this.init(e),this.lanHandle.pks=this.specialProductKeys,this.bleHandle.pks=this.specialProductKeys,this.bleHandle.offlineThreshold=e.offlineThreshold;const{appID:t,token:i,cloudServiceInfo:n={openAPIInfo:""}}=e,s=n&&n.openAPIInfo||"api.gizwits.com";t===(0,r.getGlobalData)("appID")&&i===(0,r.getGlobalData)("token")&&s===(0,r.getGlobalData)("cloudServiceInfo").openAPIInfo||(this.socketHandle.destory(),this._gizSocket=null,this.socketHandle,this.getBindingList())}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:""})}}T.getVersion=()=>({success:!0,data:k}),t.default=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 o(e){try{c(n.next(e))}catch(e){r(e)}}function a(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(o,a)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.TCPHandler=t.LanHandle=void 0;const r=s(i(4)),o=s(i(27)),a=s(i(67)),c=s(i(28)),u=s(i(1)),l=i(3),d=s(i(11)),h=i(12),f=s(i(29));class p extends f.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),r.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&&(r.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 v({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=>{r.default.warn("Discover Error",e)},this.isMatchPk=e=>0===this.pks.length||this.pks.includes(e),this.onMessage=e=>{const t=(0,h.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*(){r.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,localName:"",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}),r.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=p;class v{constructor({ip:e,onClose:t,mac:i,productKey:s,onData:a}){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=o.default.pack();this.tcpHandler.write((0,l.arrayToUint8)(e)),r.default.debug("connect success try login")},i=t=>{e({success:!0,err:t})},n=t=>{switch(new u.default((0,h.ab2numbers)(t.message)).cmd){case"0007":{const e=new o.default((0,h.ab2numbers)(t.message)),i=c.default.pack({passcode:e.passcode});this.tcpHandler.write((0,l.arrayToUint8)(i));break}case"0009":new c.default((0,h.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(0,d.default)(4e3),e({success:!1,err:null})}catch(t){r.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=(0,h.ab2hex)(e.message),i=new u.default((0,l.hexStrint2byte)(t));r.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=s,this.onData=a,this.onCloseListener=t}}t.TCPHandler=v},function(e,t,i){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=i(10),r=n(i(26));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:(0,s.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 n={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)};(0,r.default)("https://appmonitor.gizwits.com/api/21/store/?sentry_key=0b2de791abf548a1bedf0b0ebdd8ecc7&sentry_version=7",n)}},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 o=s(t[r>>>2]>>>16-r%4*8&65535);n.push(String.fromCharCode(o))}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=[],o=0;o<n;o+=3)for(var a=(i[o>>>2]>>>24-o%4*8&255)<<16|(i[o+1>>>2]>>>24-(o+1)%4*8&255)<<8|i[o+2>>>2]>>>24-(o+2)%4*8&255,c=0;c<4&&o+.75*c<n;c++)r.push(s.charAt(a>>>6*(3-c)&63));var u=s.charAt(64);if(u)for(;r.length%4;)r.push(u);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 o=0;o<n.length;o++)r[n.charCodeAt(o)]=o}var a=n.charAt(64);if(a){var c=e.indexOf(a);-1!==c&&(i=c)}return function(e,t,i){for(var n=[],r=0,o=0;o<t;o++)if(o%4){var a=i[e.charCodeAt(o-1)]<<o%4*2,c=i[e.charCodeAt(o)]>>>6-o%4*2,u=a|c;n[r>>>2]|=u<<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,o,a,c;e.exports=(c=i(0),i(18),s=(n=c).lib.WordArray,r=n.algo,o=r.SHA256,a=r.SHA224=o.extend({_doReset:function(){this._hash=new s.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var e=o._doFinalize.call(this);return e.sigBytes-=4,e}}),n.SHA224=o._createHelper(a),n.HmacSHA224=o._createHmacHelper(a),c.SHA224)},function(e,t,i){var n,s,r,o,a,c,u,l;e.exports=(l=i(0),i(15),i(25),s=(n=l).x64,r=s.Word,o=s.WordArray,a=n.algo,c=a.SHA512,u=a.SHA384=c.extend({_doReset:function(){this._hash=new o.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(u),n.HmacSHA384=c._createHmacHelper(u),l.SHA384)},function(e,t,i){var n;e.exports=(n=i(0),i(15),function(e){var t=n,i=t.lib,s=i.WordArray,r=i.Hasher,o=t.x64.Word,a=t.algo,c=[],u=[],l=[];!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++)u[e+5*t]=t+(2*e+3*t)%5*5;for(var s=1,r=0;r<24;r++){for(var a=0,d=0,h=0;h<7;h++){if(1&s){var f=(1<<h)-1;f<32?d^=1<<f:a^=1<<f-32}128&s?s=s<<1^113:s<<=1}l[r]=o.create(a,d)}}();var d=[];!function(){for(var e=0;e<25;e++)d[e]=o.create()}();var h=a.SHA3=r.extend({cfg:r.cfg.extend({outputLength:512}),_doReset:function(){for(var e=this._state=[],t=0;t<25;t++)e[t]=new o.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],o=e[t+2*s+1];r=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),o=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8),(E=i[s]).high^=o,E.low^=r}for(var a=0;a<24;a++){for(var h=0;h<5;h++){for(var f=0,p=0,v=0;v<5;v++)f^=(E=i[h+5*v]).high,p^=E.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],m=_.high,D=_.low;for(f=y.high^(m<<1|D>>>31),p=y.low^(D<<1|m>>>31),v=0;v<5;v++)(E=i[h+5*v]).high^=f,E.low^=p}for(var b=1;b<25;b++){var S=(E=i[b]).high,w=E.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 C=d[u[b]];C.high=f,C.low=p}var B=d[0],A=i[0];for(B.high=A.high,B.low=A.low,h=0;h<5;h++)for(v=0;v<5;v++){var E=i[b=h+5*v],k=d[b],T=d[(h+1)%5+5*v],O=d[(h+2)%5+5*v];E.high=k.high^~T.high&O.high,E.low=k.low^~T.low&O.low}E=i[0];var x=l[a];E.high^=x.high,E.low^=x.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 o=this._state,a=this.cfg.outputLength/8,c=a/8,u=[],l=0;l<c;l++){var d=o[l],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),u.push(f),u.push(h)}return new s.init(u,a)},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
|
|