mini_program_gizwits_sdk 3.4.0-beta.0 → 3.4.0-beta.2

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 CHANGED
@@ -1,8 +1,8 @@
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=31)}([function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(1);class s{constructor(e){this.header="",this.len=0,this.flag=[0],this.cmd="",this.content=[],this.formatP0=e=>{let t=n.checkHeader(e);if(!1===t)throw new Error("Header Error");this.header=n.arrayToString(e.slice(0,t));const i=e.slice(t,e.length),r=n.getProtocolLen(i);this.len=s.decodeLen(i.slice(0,r)),t+=r,this.flag=e.slice(t,t+1),t+=1,this.cmd=n.arrayToString(e.slice(t,t+2)),t+=2,this.content=e.slice(t,e.length)},e&&e.length>0&&this.formatP0(e)}}s.decodeLen=e=>{let t=1,i=0,n=0,s=0;do{n=e[s],i+=(127&n)*t,t*=128,s+=1}while(0!=(128&n));return i},t.default=s},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.checkHeader=e=>{let t=0;return 0===e[0]&&0===e[1]&&0===e[2]&&3===e[3]&&(t=4,4)},t.completeBlock=e=>{const t=n(e,8*Math.ceil(e.length/8)),i=[];for(let e=0;e<t.length;e+=8)i.push(parseInt(t.substring(e,e+8),2));return i};t.getProtocolLen=e=>{let t=0;for(;t<e.length&&"1"===n(e[t].toString(2),8)[0];t++);return t+1},t.arrayToString=function(e){let t="";return e.map(e=>(t+=n(e.toString(16),2),null)),t},t.arrayToASCII=function(e){let t="";return e.map(e=>(t+=String.fromCharCode(e),null)),t};const n=(e,t,i=!1)=>{const n=t-e.length,s=new Array(n).fill(0).join("");return i?e+=s:e=s+e,e};t.fillString=n;t.string2Bytes=e=>{const t=[];for(let i=0;i<e.length;i++)t.push(e.charCodeAt(i));return t};t.hexStrint2byte=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){(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(34)}catch(e){}var r=function(){if(s){if("function"==typeof s.getRandomValues)try{return s.getRandomValues(new Uint32Array(1))[0]}catch(e){}if("function"==typeof s.randomBytes)try{return s.randomBytes(4).readInt32LE()}catch(e){}}throw new Error("Native crypto module could not be used to get secure random number.")},a=Object.create||function(){function e(){}return function(t){var i;return e.prototype=t,i=new e,e.prototype=null,i}}(),o={},c=o.lib={},u=c.Base={extend:function(e){var t=a(this);return e&&t.mixIn(e),t.hasOwnProperty("init")&&this.init!==t.init||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},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 a=i[r>>>2]>>>24-r%4*8&255;t[n+r>>>2]|=a<<24-(n+r)%4*8}else for(var o=0;o<s;o+=4)t[n+o>>>2]=i[o>>>2];return this.sigBytes+=s,this},clamp:function(){var t=this.words,i=this.sigBytes;t[i>>>2]&=4294967295<<32-i%4*8,t.length=e.ceil(i/4)},clone:function(){var e=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=o.enc={},h=d.Hex={stringify:function(e){for(var t=e.words,i=e.sigBytes,n=[],s=0;s<i;s++){var r=t[s>>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,i=[],n=0;n<t;n+=2)i[n>>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new 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,a=this.blockSize,o=r/(4*a),c=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,u=e.min(4*c,r);if(c){for(var d=0;d<c;d+=a)this._doProcessBlock(s,d);i=s.splice(0,c),n.sigBytes-=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)}}}),o.algo={});return o}(Math),n)}).call(this,i(18))},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(4)),r=n(i(38));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),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){"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.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(19)),a=i(16),o=s(i(4));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":a.getGlobalData("appID")};i&&(s["X-Gizwits-User-token"]=a.getGlobalData("token")),n.header=Object.assign(Object.assign({},s),t.headers),delete n.headers;const c=a.getGlobalData("cloudServiceInfo").openAPIInfo,u=yield r.default("https://"+c+e,n);if(u.statusCode>=200&&u.statusCode<300)return{success:!0,data:u.data};let l={success:!1,err:{errorCode:o.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}))},function(e,t,i){var n;e.exports=(n=i(2),function(e){var t=n,i=t.lib,s=i.WordArray,r=i.Hasher,a=t.algo,o=[];!function(){for(var t=0;t<64;t++)o[t]=4294967296*e.abs(e.sin(t+1))|0}();var c=a.MD5=r.extend({_doReset:function(){this._hash=new s.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,t){for(var i=0;i<16;i++){var n=t+i,s=e[n];e[n]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8)}var r=this._hash.words,a=e[t+0],c=e[t+1],f=e[t+2],p=e[t+3],v=e[t+4],g=e[t+5],y=e[t+6],_=e[t+7],m=e[t+8],D=e[t+9],b=e[t+10],S=e[t+11],w=e[t+12],I=e[t+13],A=e[t+14],B=e[t+15],k=r[0],E=r[1],C=r[2],T=r[3];k=u(k,E,C,T,a,7,o[0]),T=u(T,k,E,C,c,12,o[1]),C=u(C,T,k,E,f,17,o[2]),E=u(E,C,T,k,p,22,o[3]),k=u(k,E,C,T,v,7,o[4]),T=u(T,k,E,C,g,12,o[5]),C=u(C,T,k,E,y,17,o[6]),E=u(E,C,T,k,_,22,o[7]),k=u(k,E,C,T,m,7,o[8]),T=u(T,k,E,C,D,12,o[9]),C=u(C,T,k,E,b,17,o[10]),E=u(E,C,T,k,S,22,o[11]),k=u(k,E,C,T,w,7,o[12]),T=u(T,k,E,C,I,12,o[13]),C=u(C,T,k,E,A,17,o[14]),k=l(k,E=u(E,C,T,k,B,22,o[15]),C,T,c,5,o[16]),T=l(T,k,E,C,y,9,o[17]),C=l(C,T,k,E,S,14,o[18]),E=l(E,C,T,k,a,20,o[19]),k=l(k,E,C,T,g,5,o[20]),T=l(T,k,E,C,b,9,o[21]),C=l(C,T,k,E,B,14,o[22]),E=l(E,C,T,k,v,20,o[23]),k=l(k,E,C,T,D,5,o[24]),T=l(T,k,E,C,A,9,o[25]),C=l(C,T,k,E,p,14,o[26]),E=l(E,C,T,k,m,20,o[27]),k=l(k,E,C,T,I,5,o[28]),T=l(T,k,E,C,f,9,o[29]),C=l(C,T,k,E,_,14,o[30]),k=d(k,E=l(E,C,T,k,w,20,o[31]),C,T,g,4,o[32]),T=d(T,k,E,C,m,11,o[33]),C=d(C,T,k,E,S,16,o[34]),E=d(E,C,T,k,A,23,o[35]),k=d(k,E,C,T,c,4,o[36]),T=d(T,k,E,C,v,11,o[37]),C=d(C,T,k,E,_,16,o[38]),E=d(E,C,T,k,b,23,o[39]),k=d(k,E,C,T,I,4,o[40]),T=d(T,k,E,C,a,11,o[41]),C=d(C,T,k,E,p,16,o[42]),E=d(E,C,T,k,y,23,o[43]),k=d(k,E,C,T,D,4,o[44]),T=d(T,k,E,C,w,11,o[45]),C=d(C,T,k,E,B,16,o[46]),k=h(k,E=d(E,C,T,k,f,23,o[47]),C,T,a,6,o[48]),T=h(T,k,E,C,_,10,o[49]),C=h(C,T,k,E,A,15,o[50]),E=h(E,C,T,k,g,21,o[51]),k=h(k,E,C,T,w,6,o[52]),T=h(T,k,E,C,p,10,o[53]),C=h(C,T,k,E,b,15,o[54]),E=h(E,C,T,k,c,21,o[55]),k=h(k,E,C,T,m,6,o[56]),T=h(T,k,E,C,B,10,o[57]),C=h(C,T,k,E,y,15,o[58]),E=h(E,C,T,k,I,21,o[59]),k=h(k,E,C,T,v,6,o[60]),T=h(T,k,E,C,S,10,o[61]),C=h(C,T,k,E,f,15,o[62]),E=h(E,C,T,k,D,21,o[63]),r[0]=r[0]+k|0,r[1]=r[1]+E|0,r[2]=r[2]+C|0,r[3]=r[3]+T|0},_doFinalize:function(){var t=this._data,i=t.words,n=8*this._nDataBytes,s=8*t.sigBytes;i[s>>>5]|=128<<24-s%32;var r=e.floor(n/4294967296),a=n;i[15+(s+64>>>9<<4)]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),i[14+(s+64>>>9<<4)]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),t.sigBytes=4*(i.length+1),this._process();for(var o=this._hash,c=o.words,u=0;u<4;u++){var l=c[u];c[u]=16711935&(l<<8|l>>>24)|4278255360&(l<<24|l>>>8)}return o},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});function u(e,t,i,n,s,r,a){var o=e+(t&i|~t&n)+s+a;return(o<<r|o>>>32-r)+t}function l(e,t,i,n,s,r,a){var o=e+(t&n|i&~n)+s+a;return(o<<r|o>>>32-r)+t}function d(e,t,i,n,s,r,a){var o=e+(t^i^n)+s+a;return(o<<r|o>>>32-r)+t}function h(e,t,i,n,s,r,a){var o=e+(i^(t|~n))+s+a;return(o<<r|o>>>32-r)+t}t.MD5=r._createHelper(c),t.HmacMD5=r._createHmacHelper(c)}(Math),n.MD5)},function(e,t,i){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=i(2),r=n(i(3));function a(e){return Array.prototype.map.call(new Uint8Array(e),(function(e){return("00"+e.toString(16)).slice(-2)})).join("")}t.ab2hex=a,t.compareWXSDKVersion=function(e,t){const i=e.split("."),n=t.split("."),s=Math.max(e.length,t.length);for(;i.length<s;)i.push("0");for(;n.length<s;)n.push("0");for(let i=0;i<s;i++){const n=parseInt(e[i]),s=parseInt(t[i]);if(n>s)return 1;if(n<s)return-1}return 0},t.isError=e=>null!=e&&"symbol"==typeof e.errorCode,t.wrapErrorInfo=e=>({errorCode:e,errorMessage:e}),t.unionBy=(e,t)=>e.reduce((e,i)=>{const n=i[t];return e.some(e=>e[t]===n)||e.push(i),e},[]),t.isWXDevicesResult=function(e){return e.success&&"[object Array]"===Object.prototype.toString.call(e.bleDevices)},t.str2Buf=function(e){var t=e.length,i=new ArrayBuffer(t+2),n=new DataView(i);for(let i=0;i<t;i++)n.setUint8(i,parseInt(e[i],16));return i},t.numberArray2Uint8Array=e=>{const t=new ArrayBuffer(e.length),i=new Uint8Array(t);for(let n=0;n<t.byteLength;n++)i[n]=e[n];return i};function o(e){if(25!=(e=e.slice(0,25)).length)throw new Error("数据不合法");const t=`${u(e[0])}${u(e[1])}`;if(e[2]!==(255&e.slice(3).reduce((e,t)=>e+t,0)))throw new Error("校验和不合法");const i=u(e[3]),n=e.slice(5,5+e[4]).map(e=>u(e));return{mac:t,cmd:parseInt(i,16),data:n}}function c(e){return Array.prototype.map.call(new Uint8Array(e),(function(e){return e}))}function u(e,t=2){return`${new Array(t).fill(0).join("")}${e.toString(16)}`.slice(-t)}t.advertisData2PkAndMac=(e,t)=>e&&e.byteLength>=22&&e.byteLength<=24?Object.assign(Object.assign({},((e,t)=>{let i=e.slice(e.byteLength-16),n=e.slice(0,e.byteLength-16),s=a(i);if(t.find(e=>e===s)){const e=a(n);return{productKey:s,mac:e}}{i=e.slice(0,16),n=e.slice(16),s=a(i);const t=a(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 o=new Uint8Array(e);for(;!(i>e.byteLength-1);){const c=o[i];if(c<=0||!c)break;if(e.byteLength<c+i+1)break;const u=e.slice(i+1,i+c+1);if(c>=6&&c<=8&&(n=a(u),16==n.length&&(n=n.substring(0,15))),16==c){const e=a(u).toLowerCase();t.find(t=>t===e)&&(s=e)}1==c&&(r=new Uint8Array(u)[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.merageBleLocalDevices=(e,i)=>(e.map(e=>{e.isBleOnline=!1,e.bleWorkStatus=0}),i.map(i=>{const n=e.find(e=>t.isSameDevice(e,i));n?(n.isBleOnline=!0,n.bleDeviceID=i.bleDeviceID,n.connectType=i.connectType,n.bleWorkStatus=i.bleWorkStatus):e.push(i)}),e),t.merageLanLocalDevices=(e,i)=>(e.map(e=>{e.isLanOnline=!1}),i.map(i=>{const n=e.find(e=>t.isSameDevice(e,i));n?n.isLanOnline=!0:e.push(i)}),e),t.BTDevice2GDevice=(e,i)=>{let n={productKey:"",mac:"",bleWorkStatus:0},s={did:"",productKey:"",mac:"",bleWorkStatus:0,connectType:"NONE",isBleOnline:!0,isLanOnline:!1,isOnline:!1,name:e.name,isBind:!1,bleDeviceID:e.deviceId,ctime:(new Date).getTime()};switch(e.communicationType){case"BLE_BROADCAST":try{r.default.log("parse BLE_BROADCAST");const t=o(c(e.advertisData));n.productKey=t.data.join(""),n.mac=t.mac,s.connectType="BLE_BROADCAST"}catch(e){}break;default:n=t.advertisData2PkAndMac(e.advertisData,i)}return s=Object.assign(Object.assign({},s),n),s},t.getFirstConnectType=(e,t)=>{if(!t)return e.isLanOnline?"LAN":e.isBleOnline?"BLE":"WAN";if("WAN"===t)return"WAN";switch(t){case"BLE":return e.isBleOnline?"BLE":"NONE";case"LAN":return e.isLanOnline?"LAN":"NONE"}return"WAN"},t.getProductInfoThroughPK=(e,t)=>t.find(t=>t.productKey===e),t.mergeObject=(e,t)=>{for(let i in t)null!=t[i]&&""!==t[i]&&(e[i]=t[i]);return e},t.hex2ab=function(e){const t=[];for(let n=0;n<e.length;n+=2){var i=e.slice(n,n+2);t.push(parseInt(i,16))}return new Uint8Array(t)},t.parseBroadcastData=o,t.ab2numbers=c;let l=0;function d(e,t){let i=1,n=t;return e.map(e=>{const t=65535&(e^n);return n=i-t&65535,i<<=1,u(t,4)})}function h(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),a=(t>>4<<12)+(s>>4<<8)+((15&t)<<4)+(15&s),o=Array.from({length:11},(e,t)=>(n[2*t]<<8)+n[2*t+1]);return r.default.log("明文",u(e,4),u((t<<8)+s,4),o.map(e=>u(e,4))),[u(e,4),u((t<<8)+s,4),...d(o,a)].map(e=>`${e.slice(2)}${e.slice(0,2)}`)}t.encrypt=d,t.convertToServiceUuids=({len:e=null,data:i=null,index:n=0,mac:s})=>{const r=null==e?Math.round(18*Math.random())+1:e,a=null==i?Array.from({length:r},e=>Math.round(255*Math.random())):i,o=[147,r,...a],c=h(s,(()=>{const e=l;return l=l+1&255,e})(),o);return[...new Set(c)].length!==c.length?t.convertToServiceUuids({len:r,data:a,index:n++,mac:s}):c},t.convertToUuids=h,t.arrayBufferToWordArray=function(e){for(var t=[],i=new Uint8Array(e),n=0;n<i.length;n+=4){var r=i[n]<<24|i[n+1]<<16|i[n+2]<<8|i[n+3];t.push(r)}return s.lib.WordArray.create(t,i.length)}},function(e,t,i){var n,s,r,a,o,c,u,l,d,h,f,p,v,g,y,_,m,D,b;e.exports=(n=i(2),i(27),void(n.lib.Cipher||(s=n,r=s.lib,a=r.Base,o=r.WordArray,c=r.BufferedBlockAlgorithm,u=s.enc,u.Utf8,l=u.Base64,d=s.algo.EvpKDF,h=r.Cipher=c.extend({cfg:a.extend(),createEncryptor:function(e,t){return this.create(this._ENC_XFORM_MODE,e,t)},createDecryptor:function(e,t){return this.create(this._DEC_XFORM_MODE,e,t)},init:function(e,t,i){this.cfg=this.cfg.extend(i),this._xformMode=e,this._key=t,this.reset()},reset:function(){c.reset.call(this),this._doReset()},process:function(e){return this._append(e),this._process()},finalize:function(e){return e&&this._append(e),this._doFinalize()},keySize:4,ivSize:4,_ENC_XFORM_MODE:1,_DEC_XFORM_MODE:2,_createHelper:function(){function e(e){return"string"==typeof e?b: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=a.extend({createEncryptor:function(e,t){return this.Encryptor.create(e,t)},createDecryptor:function(e,t){return this.Decryptor.create(e,t)},init:function(e,t){this._cipher=e,this._iv=t}}),v=f.CBC=function(){var e=p.extend();function t(e,t,i){var n,s=this._iv;s?(n=s,this._iv=void 0):n=this._prevBlock;for(var r=0;r<i;r++)e[t+r]^=n[r]}return e.Encryptor=e.extend({processBlock:function(e,i){var n=this._cipher,s=n.blockSize;t.call(this,e,i,s),n.encryptBlock(e,i),this._prevBlock=e.slice(i,i+s)}}),e.Decryptor=e.extend({processBlock:function(e,i){var n=this._cipher,s=n.blockSize,r=e.slice(i,i+s);n.decryptBlock(e,i),t.call(this,e,i,s),this._prevBlock=r}}),e}(),g=(s.pad={}).Pkcs7={pad:function(e,t){for(var i=4*t,n=i-e.sigBytes%i,s=n<<24|n<<16|n<<8|n,r=[],a=0;a<n;a+=4)r.push(s);var c=o.create(r,n);e.concat(c)},unpad:function(e){var t=255&e.words[e.sigBytes-1>>>2];e.sigBytes-=t}},r.BlockCipher=h.extend({cfg:h.cfg.extend({mode:v,padding:g}),reset:function(){var e;h.reset.call(this);var t=this.cfg,i=t.iv,n=t.mode;this._xformMode==this._ENC_XFORM_MODE?e=n.createEncryptor:(e=n.createDecryptor,this._minBufferSize=1),this._mode&&this._mode.__creator==e?this._mode.init(this,i&&i.words):(this._mode=e.call(n,this,i&&i.words),this._mode.__creator=e)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e,t=this.cfg.padding;return this._xformMode==this._ENC_XFORM_MODE?(t.pad(this._data,this.blockSize),e=this._process(!0)):(e=this._process(!0),t.unpad(e)),e},blockSize:4}),y=r.CipherParams=a.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),_=(s.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext,i=e.salt;return(i?o.create([1398893684,1701076831]).concat(i).concat(t):t).toString(l)},parse:function(e){var t,i=l.parse(e),n=i.words;return 1398893684==n[0]&&1701076831==n[1]&&(t=o.create(n.slice(2,4)),n.splice(0,4),i.sigBytes-=16),y.create({ciphertext:i,salt:t})}},m=r.SerializableCipher=a.extend({cfg:a.extend({format:_}),encrypt:function(e,t,i,n){n=this.cfg.extend(n);var s=e.createEncryptor(i,n),r=s.finalize(t),a=s.cfg;return y.create({ciphertext:r,key:i,iv:a.iv,algorithm:e,mode:a.mode,padding:a.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,i,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(i,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}}),D=(s.kdf={}).OpenSSL={execute:function(e,t,i,n){n||(n=o.random(8));var s=d.create({keySize:t+i}).compute(e,n),r=o.create(s.words.slice(t),4*i);return s.sigBytes=4*t,y.create({key:s,iv:r,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.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);return n.iv=s.iv,m.decrypt.call(this,e,t,s.key,n)}}))))},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(6));const a=new class{constructor(){this.data={},this.key="dataPointConfig",this.init=()=>n(this,void 0,void 0,(function*(){const e=(yield wx.getStorageSync(this.key))||"{}";let t={};try{t=JSON.parse(e)}catch(e){}this.data=t})),this.getConfigFile=e=>n(this,void 0,void 0,(function*(){var t;if(!this.data[e]){const i=`/app/datapoint?product_key=${e}`,n=yield r.default(`${i}`,{method:"GET"});if(!n.success||!(null===(t=n.data)||void 0===t?void 0:t.entities))return null;this.data[e]=n.data,wx.setStorageSync(this.key,JSON.stringify(this.data))}return this.data[e]})),this.getAttrItem=(e,t)=>n(this,void 0,void 0,(function*(){this.data[e]||(yield this.getConfigFile(e));for(let i in this.data[e].entities[0].attrs){const n=this.data[e].entities[0].attrs[i];if(n.name===t)return n}return null}))}};a.init(),t.default=a},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(10)),a=i(1),o=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=a.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=a.fillString(e.toString(2),8*i.position.len);break}case"binary":{let e=t[i.name]||"";e instanceof Array&&(e=a.arrayToString(e));const s=a.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+=a.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+=a.fillString(parseInt(s,2).toString(16),2)}return a.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=a.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(a.completeBlock(g)),g=""),g=((e,i)=>{const n=o(e.data_type);return i=c(n,t,e)+i})(e,g)):(g.length>0&&(h=h.concat(a.completeBlock(g)),g=""),h=((e,i)=>{const n=o(e.data_type),s=c(n,t,e);return i=i.concat(a.completeBlock(s))})(e,h)),v=e}),g.length>0&&(h=h.concat(a.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,a={},o=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(o,o+u),activeAttrs:t,flagString:i.substring(o,o+u),cmdData:n.slice(r,n.length),accumulate:s});return r+=d,a=Object.assign(Object.assign({},a),l),o+=u,null}),a}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+=a.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+=a.fillString(e.toString(2),8),null)),i+=s}const h=o(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:a.arrayToString(t.slice(0,4)),flag:"",len:"",cmd:"",sn:"",action:"",payload:""},o=e;let c=a.checkHeader(t);if(!1===c)return;const u=t.slice(c,t.length),l=a.getProtocolLen(u);if(c+=l,r.len=a.arrayToString(u.slice(0,l)),c+=1,r.flag=a.arrayToString(t.slice(c-1,c)),c+=2,r.cmd=a.arrayToString(t.slice(c-2,c)),r.sn="",("0093"===r.cmd||"0094"===r.cmd)&&(c+=4,r.sn=a.arrayToString(t.slice(c-4,c)),"01"===r.flag)){c+=2,c+=parseInt(a.arrayToString(t.slice(c-2,c)),16)}c+=1,r.action=a.arrayToString(t.slice(c-1,c)),i=parseInt(r.action,16),r.payload=a.arrayToString(t.slice(c,t.length));const d=t.slice(c,t.length);let h=o;1===i&&(h=o.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+=a.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===o.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 a.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]=a.hexStrint2byte(e[n])),"string"===i&&"object"==typeof e[n]&&(e[n]=a.arrayToString(e[n])))}return e}));t.formatBinary=v},function(e,t,i){var n,s;e.exports=(s=i(2),i(9),s.mode.ECB=((n=s.lib.BlockCipherMode.extend()).Encryptor=n.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),n.Decryptor=n.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),n),s.mode.ECB)},function(e,t,i){var n;e.exports=(n=i(2),i(29),i(7),i(27),i(9),function(){var e=n,t=e.lib.BlockCipher,i=e.algo,s=[],r=[],a=[],o=[],c=[],u=[],l=[],d=[],h=[],f=[];!function(){for(var e=[],t=0;t<256;t++)e[t]=t<128?t<<1:t<<1^283;var i=0,n=0;for(t=0;t<256;t++){var p=n^n<<1^n<<2^n<<3^n<<4;p=p>>>8^255&p^99,s[i]=p,r[p]=i;var v=e[i],g=e[v],y=e[g],_=257*e[p]^16843008*p;a[i]=_<<24|_>>>8,o[i]=_<<16|_>>>16,c[i]=_<<8|_>>>24,u[i]=_,_=16843009*y^65537*g^257*v^16843008*i,l[p]=_<<24|_>>>8,d[p]=_<<16|_>>>16,h[p]=_<<8|_>>>24,f[p]=_,i?(i=v^e[e[e[y^v]]],n^=e[e[n]]):i=n=1}}();var p=[0,1,2,4,8,16,32,64,128,27,54],v=i.AES=t.extend({_doReset:function(){if(!this._nRounds||this._keyPriorReset!==this._key){for(var e=this._keyPriorReset=this._key,t=e.words,i=e.sigBytes/4,n=4*((this._nRounds=i+6)+1),r=this._keySchedule=[],a=0;a<n;a++)a<i?r[a]=t[a]:(u=r[a-1],a%i?i>6&&a%i==4&&(u=s[u>>>24]<<24|s[u>>>16&255]<<16|s[u>>>8&255]<<8|s[255&u]):(u=s[(u=u<<8|u>>>24)>>>24]<<24|s[u>>>16&255]<<16|s[u>>>8&255]<<8|s[255&u],u^=p[a/i|0]<<24),r[a]=r[a-i]^u);for(var o=this._invKeySchedule=[],c=0;c<n;c++){if(a=n-c,c%4)var u=r[a];else u=r[a-4];o[c]=c<4||a<=4?u:l[s[u>>>24]]^d[s[u>>>16&255]]^h[s[u>>>8&255]]^f[s[255&u]]}}},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,a,o,c,u,s)},decryptBlock:function(e,t){var i=e[t+1];e[t+1]=e[t+3],e[t+3]=i,this._doCryptBlock(e,t,this._invKeySchedule,l,d,h,f,r),i=e[t+1],e[t+1]=e[t+3],e[t+3]=i},_doCryptBlock:function(e,t,i,n,s,r,a,o){for(var c=this._nRounds,u=e[t]^i[0],l=e[t+1]^i[1],d=e[t+2]^i[2],h=e[t+3]^i[3],f=4,p=1;p<c;p++){var v=n[u>>>24]^s[l>>>16&255]^r[d>>>8&255]^a[255&h]^i[f++],g=n[l>>>24]^s[d>>>16&255]^r[h>>>8&255]^a[255&u]^i[f++],y=n[d>>>24]^s[h>>>16&255]^r[u>>>8&255]^a[255&l]^i[f++],_=n[h>>>24]^s[u>>>16&255]^r[l>>>8&255]^a[255&d]^i[f++];u=v,l=g,d=y,h=_}v=(o[u>>>24]<<24|o[l>>>16&255]<<16|o[d>>>8&255]<<8|o[255&h])^i[f++],g=(o[l>>>24]<<24|o[d>>>16&255]<<16|o[h>>>8&255]<<8|o[255&u])^i[f++],y=(o[d>>>24]<<24|o[h>>>16&255]<<16|o[u>>>8&255]<<8|o[255&l])^i[f++],_=(o[h>>>24]<<24|o[u>>>16&255]<<16|o[l>>>8&255]<<8|o[255&d])^i[f++],e[t]=v,e[t+1]=g,e[t+2]=y,e[t+3]=_},keySize:8});e.AES=t._createHelper(v)}(),n.AES)},function(e,t,i){var n;e.exports=(n=i(2),n.enc.Utf8)},function(e,t,i){var n;e.exports=(n=i(2),n.enc.Hex)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n={};t.setGlobalData=function(e,t){n[e]=t},t.getGlobalData=function(e){return n[e]}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__rest||function(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(e);s<n.length;s++)t.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(e,n[s])&&(i[n[s]]=e[n[s]])}return i},r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=r(i(7)),o=r(i(61)),c=i(8),u=i(20),l=r(i(21)),d=i(1),h=r(i(0)),f=r(i(22)),p=r(i(39)),v=i(11),g=r(i(3)),y=r(i(23)),_=r(i(5)),m=i(40),D=r(i(4)),b=r(i(41)),S=r(i(42)),w=r(i(43));class I extends y.default{constructor({pks:e=[],bleHandleParams:t={serviceUUIDSuffix:"abf0",characteristicUUIDSuffix:"abf7"},offlineThreshold:i}){super(),this.connectedList=[],this.connectingDevId=null,this.pks=[],this.listenDevOfflineTimer=null,this.boradcastDataCache={},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=>{g.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=>{g.default.error("openBluetoothAdapter fail",new Error(JSON.stringify(e))),this.notifyError({errMsg:e.errMsg,errCode:-1}),i({success:!1,err:e})}})}),this.handleOnBLECharacteristicValueChange=e=>n(this,void 0,void 0,(function*(){if(!e.value)return;const t=c.ab2hex(e.value);try{const i=new h.default(d.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=()=>n(this,void 0,void 0,(function*(){this.isRunInit=!0;const{platform:e}=wx.getSystemInfoSync();yield this.openBluetoothAdapter(),"ios"===e&&(yield this.openBluetoothAdapter("peripheral"));try{this.peripheralServer=(yield wx.createBLEPeripheralServer()).server,g.default.info("GIZ_SDK: 广播初始化成功",this.peripheralServer)}catch(e){g.default.error("GIZ_SDK: 广播初始化失败",new Error(JSON.stringify(e)))}const t=yield this.getBluetoothAdapterState();return this.isInitSuccess=!0,t})),this.checkPermission=()=>n(this,void 0,void 0,(function*(){if((yield wx.getSetting()).authSetting["scope.bluetooth"])return yield this.init();try{return yield wx.authorize({scope:"scope.bluetooth"}),yield this.init()}catch(e){g.default.log("授权失败",e),this.openBluetoothAdapter(),this.notifyError({errMsg:e.errMsg,errCode:-1})}})),this.getBluetoothAdapterState=()=>n(this,void 0,void 0,(function*(){g.default.log("getBluetoothAdapterState",yield wx.getBluetoothAdapterState());const e=yield wx.getBluetoothAdapterState(),{errMsg:t,available:i}=e,n=s(e,["errMsg","available"]);return{data:Object.assign({},n),err:c.wrapErrorInfo(t),success:i}})),this.getDeviceStatus=(e,t,i,s)=>n(this,void 0,void 0,(function*(){const n=yield p.default.pack(t,i,s);return n?yield this.write(e,c.numberArray2Uint8Array(n).buffer):{success:!1}})),this.updateDevice=e=>{const t=e.bleDeviceID,i=this.scanList.findIndex(e=>t==e.bleDeviceID);-1!==i&&(this.scanList[i]=e)},this.updateCtime=e=>{const t=e.deviceId,i=this.scanList.findIndex(e=>t==e.bleDeviceID);-1!==i&&(this.scanList[i].ctime=Date.now())},this.checkDeviceIsChange=(e,t)=>e.bleWorkStatus!==t.bleWorkStatus||e.name!==t.name||e.isBleOnline!==t.isBleOnline||e.isOnline!==t.isOnline,this.handleBluetoothDeviceFound=(e,t)=>{c.unionBy(e.devices,"deviceId").map(e=>{const{advertisData:i,deviceId:n,name:s,localName:r}=e,a=c.ab2hex(i);let o=null;try{o=c.parseBroadcastData(c.ab2numbers(i))}catch(e){}const u=this.scanList.find(e=>e.bleDeviceID===n);if(o&&148===o.cmd){const t=c.ab2hex(i);if(this.boradcastDataCache[n]&&this.boradcastDataCache[n]===t)return!1;if(!u)return!1;this.boradcastDataCache[n]=c.ab2hex(i);const s=v.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(u){const i=c.BTDevice2GDevice(e,this.pks);if(i.productKey&&i.mac){const e=this.checkDeviceIsChange(i,u);i.ctime=Date.now(),this.updateDevice(i),e&&t(this.scanList)}}else{if(this.pks.some(e=>a.includes(e))){const i=c.BTDevice2GDevice(e,this.pks);i.productKey&&i.mac&&(this.scanList.push(i),t(this.scanList))}}})},this.startScan=(e,t=5e3,i)=>n(this,void 0,void 0,(function*(){return this.disableScanFlag?{scanList:[]}:new Promise(s=>n(this,void 0,void 0,(function*(){wx.onBluetoothDeviceFound(t=>{this.handleBluetoothDeviceFound(t,e)}),g.default.debug("GIZ_SDK: start scan",t),yield wx.startBluetoothDevicesDiscovery({services:i||this.baseServices,powerLevel:"high",allowDuplicatesKey:!0,interval:200}),t>0&&setTimeout(()=>{this.stopScan(),s({scanList:this.scanList})},t)})))})),this.stopScan=()=>n(this,void 0,void 0,(function*(){try{return yield wx.stopBluetoothDevicesDiscovery()}catch(e){return e}})),this.disableScan=()=>n(this,void 0,void 0,(function*(){this.disableScanFlag=!0;const e=yield wx.stopBluetoothDevicesDiscovery();return yield _.default(200),e})),this.enableScan=()=>{this.disableScanFlag=!1},this.connectDevice=e=>n(this,void 0,void 0,(function*(){var t;try{this.connectingDevId=e;try{yield this.disableScan();const t=yield u.retryConnect(e);this.enableScan(),g.default.debug("connect res",t)}catch(e){if(g.default.error("GIZ_SDK: createBLEConnection error",new Error(JSON.stringify(e))),"createBLEConnection:fail:already connect"!==(null==e?void 0:e.errMsg))return this.notifyError(e),{success:!1,message:null==e?void 0:e.errMsg}}const i=yield wx.getBLEDeviceServices({deviceId:e}).catch(e=>this.notifyError(e)),n=null===(t=null==i?void 0:i.services.find(e=>e.isPrimary&&e.uuid.toLowerCase().includes(this.serviceUUIDSuffix)))||void 0===t?void 0:t.uuid;if(!n)return{message:"can not find valid serviceId",success:!1};const s=yield wx.getBLEDeviceCharacteristics({deviceId:e,serviceId:n}).catch(e=>this.notifyError(e)),r=null==s?void 0:s.characteristics[0].uuid;this.connectedList.every(t=>t.deviceId!==e)&&this.connectedList.push({deviceId:e,serviceId:n,characteristicId:r}),yield wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:n,characteristicId:r,state:!0,type:"notification"}).catch(e=>this.notifyError(e)),this.write(e,c.numberArray2Uint8Array(l.default.pack()).buffer);const a=yield this.handleBindReq(e);if(g.default.log("handleBindReq",a),a.success){this.write(e,c.numberArray2Uint8Array(f.default.pack({passcode:a.data})).buffer);const t=yield this.handleLoginReq(e).catch(e=>this.notifyError(e));if(null==t?void 0:t.success)return{success:!0,message:"ok"}}return yield wx.closeBLEConnection({deviceId:e}),{success:!1,message:"ok"}}finally{this.connectingDevId=null}})),this.handleWatchBleData=(e,t)=>n(this,void 0,void 0,(function*(){return new Promise(i=>{let n=(s,r)=>{if(e!==s.deviceId)return;const a=t(s,r);a&&(i({success:!0,data:a}),this.removeEventListener("GizBleDeviceData",n))};this.addEventListener("GizBleDeviceData",n),setTimeout(()=>{n&&(this.removeEventListener("GizBleDeviceData",n),i({success:!1,err:D.default.GIZ_SDK_DEVICE_NO_RESPONSE}))},3e3)})})),this.handleBindReq=e=>new Promise(t=>{const i=(n,s)=>{if(n.deviceId!==e)return;g.default.log("监听蓝牙特征值发生变化");const r=new l.default(d.hexStrint2byte(s));this.removeEventListener("GizBleDeviceData",i),r.passcode?t({success:!0,data:r.passcode}):t({success:!1,data:""})};this.watchBleDevice(e,i)}),this.handleLoginReq=e=>new Promise(t=>{const i=(n,s)=>{if(n.deviceId!==e)return;g.default.log("设备回复LoginReq",s);const r=new f.default(d.hexStrint2byte(s));this.removeEventListener("GizBleDeviceData",i),!0===r.result?t({success:!0,data:r.did}):t({success:!1,data:""})};this.watchBleDevice(e,i)}),this.startUpgrade=({deviceId:e,did:t,type:i,onEvent:s,onProgress:r,productKey:l})=>n(this,void 0,void 0,(function*(){s({code:"GizOTAEventPretreatment"});const n=yield this.checkUpdate({deviceId:e,did:t,type:i});if(n.success){const t=n.data.download_url,r=n.data.soft_ver;s({code:"GizOTAEventDownload"});let f="";try{f=(yield u.downloadFile({url:t})).tempFilePath}catch(e){return{success:!1,err:D.default.GIZ_SDK_OTA_FIRMWARE_DOWNLOAD_FAILED}}console.log("downloadRes",f),s({code:"GizOTAEventTransmit"});const p=(e,t)=>{const i=d.hexStrint2byte(t);switch(new h.default(i).cmd){case"0042":return new S.default(i)}return null},v=S.default.pack(i);yield this.write(e,c.numberArray2Uint8Array(v).buffer);const g=yield this.handleWatchBleData(e,p);if(g.success&&g.data.type!==i)return{success:!1,err:D.default.GIZ_SDK_OTA_FIRMWARE_TYPE_NOT_MATCH};if(g.success&&0===g.data.state){const e=wx.getFileSystemManager();let t=[];try{t=yield e.readFileSync(f,"binary",0)}catch(e){return{success:!1,err:D.default.GIZ_SDK_OTA_FIRMWARE_DOWNLOAD_FAILED}}const i=c.arrayBufferToWordArray(t),n=a.default(i).toString(),s=o.default.crc32(t);console.log("fileData",n,s);const u=w.default.pack(l,r,n,1,"");console.log("preOtaData",u)}return{success:!1,err:D.default.GIZ_SDK_OTA_DEVICE_BUSY_IN_UPGRADE}}return n})),this.checkUpdate=({deviceId:e,did:t,type:i})=>n(this,void 0,void 0,(function*(){const n=b.default.pack();g.default.debug("DeviceInfo.pack",n),yield this.write(e,c.numberArray2Uint8Array(n).buffer);const s=yield this.handleWatchBleData(e,(e,t)=>{const i=d.hexStrint2byte(t);switch(new h.default(i).cmd){case"0014":try{const e=new b.default(i);return g.default.debug("parse DeviceInfo",e),e}catch(e){g.default.debug("parse DeviceInfo error",e)}}return null});if(s.success){let e="",n="";return"MCU"===i?(e=s.data.mcuSoftVersion,n=s.data.mcuHardVersion):(e=s.data.moduleSoftVersion,n=s.data.moduleHardVersion),yield m.checkUpdate({did:t,type:i,softVersion:e,hardVersion:n})}return s})),this.watchBleDevice=(e,t)=>n(this,void 0,void 0,(function*(){const{serviceId:i,characteristicId:n,errMsg:s}=this.getTargetDevice(e);return s?{success:!1,message:s}:(yield wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:i,characteristicId:n,state:!0,type:"notification"}).catch(e=>this.notifyError(e)),g.default.log(`监听设备 ${e} 成功!`),this.addEventListener("GizBleDeviceData",t),{message:"ok",success:!0})})),this.writeBoradcast=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.scanList.find(t=>t.bleDeviceID===e);if(!i)return{success:!1,message:"not found device"};this.boradcastTimer&&clearTimeout(this.boradcastTimer);try{this.peripheralServer.stopAdvertising({});const e=c.convertToServiceUuids({mac:i.mac,index:0,data:t,len:t.length});return this.peripheralServer.startAdvertising({advertiseRequest:{connectable:!0,serviceUuids:e},powerLevel:"high",success:e=>{g.default.debug("GIZ_SDK: startAdvertising success",e)},fail:e=>{g.default.error("GIZ_SDK: startAdvertising error",new Error(JSON.stringify(e)))}}),g.default.debug("GIZ_SDK: start adv",e),this.boradcastTimer=setTimeout(()=>{this.peripheralServer.stopAdvertising({}),this.boradcastTimer=null},1e3),{success:!0}}catch(e){return g.default.log("GIZ_SDK:",e),clearTimeout(this.boradcastTimer),{success:!1,message:"send cmd error"}}})),this.write=(e,t)=>n(this,void 0,void 0,(function*(){g.default.log("app => dev:",c.ab2hex(t));const i=this.getTargetDevice(e);if(i.serviceId&&i.characteristicId){return yield u.unpackWriteBLECharacteristicValue(e,i.serviceId,i.characteristicId,t)}return{success:!1,message:"send cmd error"}})),this.disConnectDevice=e=>n(this,void 0,void 0,(function*(){this.removeDevById(e);const{errMsg:t}=yield wx.closeBLEConnection({deviceId:e}),i=this.scanList.find(t=>t.bleDeviceID===e);return i&&(i.ctime=Date.now(),this.updateDevice(i)),"closeBLEConnection:ok"===t?{err:t,success:!0}:{err:t,success:!1}})),this.removeDevById=e=>{const t=this.connectedList.findIndex(t=>t.deviceId===e);-1!==t&&this.connectedList.splice(t,1)},this.getTargetDevice=e=>{const t=this.connectedList.find(t=>e===t.deviceId);return t||{errMsg:"Unable get this device,maybe you forgot to connect it."}},this.destory=()=>{this.listenDevOfflineTimer&&clearInterval(this.listenDevOfflineTimer),wx.offAppShow(this.onAppShow),wx.offAppHide(this.onAppHide),wx.offBluetoothAdapterStateChange(this.onBluetoothAdapterStateChange)};const{serviceUUIDSuffix:r}=t;this.serviceUUIDSuffix=r,this.pks=e,this.offlineThreshold=i,this.listenDevOffline(),this.listenConnection(),wx.onAppShow(this.onAppShow),wx.onAppHide(this.onAppHide),wx.onBluetoothAdapterStateChange(this.onBluetoothAdapterStateChange)}set offlineThreshold(e){this._offlineThreshold=e}get offlineThreshold(){return this._offlineThreshold||1e4}}t.BleHandle=I},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){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){return new Promise((i,n)=>{wx.request(Object.assign(Object.assign({url:e,timeout:3e3},t),{success:e=>{i(e)},fail:e=>{n(e)}}))})}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(3)),a=s(i(5));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 c(e,t,i,n){return new Promise(s=>{wx.writeBLECharacteristicValue({deviceId:e,serviceId:t,characteristicId:i,value:n,complete:s})})}t.retryConnect=function(e,t=1e4){return n(this,void 0,void 0,(function*(){let i={success:!1};for(let n=0;n<5;n++)try{return console.debug("start createBLEConnection"),yield o(e,t)}catch(e){i=e,console.debug("createBLEConnection error retry"),yield a.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=c,t.unpackWriteBLECharacteristicValue=function(e,t,i,s){if(!s||0===s.byteLength)throw new Error("value is empty");return new Promise((o,u)=>n(this,void 0,void 0,(function*(){let n,l=0,d=s.byteLength;for(;d>0;){yield a.default(30);const o=s.slice(l,l+20);if(l+=20,d-=20,n=yield c(e,t,i,o),r.default.log("unpackWriteBLECharacteristicValue",l/20,n),0!==n.errCode)break}0!==n.errCode?u(n):o(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)}})})}))}},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(0)),r=i(1);class a extends s.default{constructor(e){super(e),this.passcode="";let t=0;const i=parseInt(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}}a.pack=()=>[0,0,0,3,3,0,0,6],t.default=a},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(0)),r=i(1);class a 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(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}}}a.pack=({passcode:e})=>{let t=[0];const i=r.hexStrint2byte(r.fillString(e.length.toString(16),4)),n=r.string2Bytes(e),s=[0].concat([0,8]).concat(i).concat(n);return t=r.hexStrint2byte(s.length.toString(16)),[0,0,0,3].concat(t).concat(s)},t.default=a},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});t.default=class{constructor(){this.listenerMap={},this.addEventListener=(e,t)=>n(this,void 0,void 0,(function*(){return this.listenerMap[e]||(this.listenerMap[e]=[]),-1===this.listenerMap[e].indexOf(t)&&this.listenerMap[e].push(t),{success:!0}})),this.removeEventListener=(e,t)=>{if(this.listenerMap[e]){const i=this.listenerMap[e].indexOf(t);if(-1!==i)return this.listenerMap[e].splice(i,1),{success:!0}}return{success:!1}}}}},function(e,t,i){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=n(i(0)),r=i(1);class a extends s.default{constructor(e){super(e)}}a.pack=(e,t)=>{const i=[],[n,s]=r.formatCodesFromStr(e),[a,o]=r.formatCodesFromStr(t),c=[0].concat([0,1],s,n,o,a);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=a},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(5)),a=s(i(4)),o=i(26),c=s(i(3));t.default=class{constructor(e,t,i,s){this.ssid="",this.password="",this.specialProductKeys=[],this.disableSearchDevice=!1,this.specialProductKeySecrets=[],this.timeoutHandler=null,this.setDeviceOnboardingDeployRej=()=>{},this.cleanTimeout=()=>{this.disableSearchDevice=!0,this.timeoutHandler&&clearTimeout(this.timeoutHandler),this.timeoutHandler=null},this.stopDeviceOnboardingDeploy=()=>{this.setDeviceOnboardingDeployRej&&this.setDeviceOnboardingDeployRej({success:!1,err:a.default.GIZ_SDK_ONBOARDING_STOPPED}),this.cleanTimeout()},this.hasTimeoutHandler=e=>!!this.timeoutHandler&&(e&&e({success:!1,err:a.default.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING}),!0),this.handleTimeout=()=>{this.setDeviceOnboardingDeployRej&&this.setDeviceOnboardingDeployRej({success:!1,err:{errorCode:a.default.CONFIG_TIME_OUT,errorMessage:"time out"}}),this.timeoutHandler=null},this.searchDevice=({ssid:e,password:t})=>new Promise((i,s)=>{c.default.debug("GIZ_SDK: 开始大循环搜索设备");const u=()=>n(this,void 0,void 0,(function*(){var n;if(this.hasTimeoutHandler())try{const l=yield o.checkDeviceRegister({SSID:e,password:t,productKeys:this.specialProductKeys});if((null===(n=l.err)||void 0===n?void 0:n.errorCode)===a.default.GIZ_OPENAPI_TOKEN_INVALID.errorCode)return void s({success:!1,err:a.default.GIZ_OPENAPI_TOKEN_INVALID});l.err||0===l.data.length?(c.default.debug("GIZ_SDK: 大循环没有发现设备"),yield r.default(1500),!this.disableSearchDevice&&u()):(c.default.debug("GIZ_SDK: 大循环搜索到设备",l),i({success:!0,data:l.data}))}catch(e){yield r.default(3e3),!this.disableSearchDevice&&u()}}));u()}),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"),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 o.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});r.length>0?(c.default.log("GIZ_SDK: bind device success",r),t({success:!0,data:r})):(c.default.log("GIZ_SDK: bind device error",s),i({success:!1,data:e,err:a.default.GIZ_SDK_BIND_DEVICE_FAILED}))}catch(e){i(e)}})))),this.ssid=e,this.password=t,this.specialProductKeys=i,this.specialProductKeySecrets=s}}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(12)),a=s(i(28)),o=s(i(13)),c=s(i(14)),u=s(i(15)),l=s(i(29)),d=s(i(6)),h=s(i(48)),f=i(50);class p{constructor(){this.pad=(e,t)=>{},this.unpad=e=>{const t=e.sigBytes;let i=0,n=1;const s=e.toString(c.default);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 d.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,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:o}=f.psKeySign(i);return yield d.default("/app/bind_mac",{method:"POST",data:n,headers:{"X-Gizwits-Signature":a,"X-Gizwits-Timestamp":o}})}))},t.unbindDevice=function({devices:e}){return n(this,void 0,void 0,(function*(){return yield d.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=h.default({SSID:e,password:t,pks:i});let s="";return n.map(e=>{s+=`${e},`}),s=s.substring(0,s.length-1),yield d.default(`/app/device_register?random_codes=${s}`,{method:"get"})}))},t.safeRegister=function({productKey:e,productSecret:t,mac:i,passcode:s,gwDid:l,isReset:h}){return n(this,void 0,void 0,(function*(){let n=`is_reset=${h?1:0}&mac=${i}&passcode=${s}`;l&&(n+=`&gw_did=${l}`);const f=u.default.parse(t),p=u.default.parse(""),g=c.default.parse(n),y=o.default.encrypt(g,f,{iv:p,mode:r.default,padding:a.default}).ciphertext.toString().toUpperCase(),_=yield d.default(`/dev/${e}/device`,{method:"POST",data:{data:y},headers:{"content-type":"application/x-www-form-urlencoded"}},!1);if(_.success){const e=v({productSecret:t,iv:p,data:_.data}),n=[];return e.find(e=>e.mac===i)||n.push({mac:i}),{success:!0,data:{successDevices:e,failedDevices:n}}}return{success:!1,err:_.err}}))};const v=({productSecret:e,data:t,iv:i})=>{const n=u.default.parse(e),s=u.default.parse(t);const a=o.default.decrypt(l.default.stringify(s),n,{iv:i,mode:r.default,padding:new p}).toString(c.default),d=[];return a.split(",").map(e=>{const t=e.split("&"),i=t[0].replace("mac=",""),n=t[1].replace("did=","");d.push({mac:i,did:n})}),d};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 d.default(`/app/bindings/${i}`,{method:"PUT",data:n},!0)}))}},function(e,t,i){var n,s,r,a,o,c,u,l;e.exports=(l=i(2),i(46),i(47),s=(n=l).lib,r=s.Base,a=s.WordArray,o=n.algo,c=o.MD5,u=o.EvpKDF=r.extend({cfg:r.extend({keySize:4,hasher:c,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var i,n=this.cfg,s=n.hasher.create(),r=a.create(),o=r.words,c=n.keySize,u=n.iterations;o.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){var n;e.exports=(n=i(2),i(9),n.pad.Pkcs7)},function(e,t,i){var n,s,r;e.exports=(r=i(2),s=(n=r).lib.WordArray,n.enc.Base64={stringify:function(e){var t=e.words,i=e.sigBytes,n=this._map;e.clamp();for(var s=[],r=0;r<i;r+=3)for(var a=(t[r>>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;o<4&&r+.75*o<i;o++)s.push(n.charAt(a>>>6*(3-o)&63));var c=n.charAt(64);if(c)for(;s.length%4;)s.push(c);return s.join("")},parse:function(e){var t=e.length,i=this._map,n=this._reverseMap;if(!n){n=this._reverseMap=[];for(var r=0;r<i.length;r++)n[i.charCodeAt(r)]=r}var a=i.charAt(64);if(a){var o=e.indexOf(a);-1!==o&&(t=o)}return function(e,t,i){for(var n=[],r=0,a=0;a<t;a++)if(a%4){var o=i[e.charCodeAt(a-1)]<<a%4*2,c=i[e.charCodeAt(a)]>>>6-a%4*2,u=o|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){"use strict";(function(e){
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=32)}([function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=i(1);class s{constructor(e){this.header="",this.len=0,this.flag=[0],this.cmd="",this.content=[],this.formatP0=e=>{let t=n.checkHeader(e);if(!1===t)throw new Error("Header Error");this.header=n.arrayToString(e.slice(0,t));const i=e.slice(t,e.length),r=n.getProtocolLen(i);this.len=s.decodeLen(i.slice(0,r)),t+=r,this.flag=e.slice(t,t+1),t+=1,this.cmd=n.arrayToString(e.slice(t,t+2)),t+=2,this.content=e.slice(t,e.length)},e&&e.length>0&&this.formatP0(e)}}s.decodeLen=e=>{let t=1,i=0,n=0,s=0;do{n=e[s],i+=(127&n)*t,t*=128,s+=1}while(0!=(128&n));return i},t.default=s},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.checkHeader=e=>{let t=0;return 0===e[0]&&0===e[1]&&0===e[2]&&3===e[3]&&(t=4,4)},t.completeBlock=e=>{const t=n(e,8*Math.ceil(e.length/8)),i=[];for(let e=0;e<t.length;e+=8)i.push(parseInt(t.substring(e,e+8),2));return i};t.getProtocolLen=e=>{let t=0;for(;t<e.length&&"1"===n(e[t].toString(2),8)[0];t++);return t+1},t.arrayToString=function(e){let t="";return e.map(e=>(t+=n(e.toString(16),2),null)),t},t.arrayToASCII=function(e){let t="";return e.map(e=>(t+=String.fromCharCode(e),null)),t};const n=(e,t,i=!1)=>{const n=t-e.length,s=new Array(n).fill(0).join("");return i?e+=s:e=s+e,e};t.fillString=n;t.bytesToInt=e=>{let t=0;for(let i=0;i<e.length;i++)t=t<<8|e[i];return t};t.bytesToHexString=e=>Array.from(e,e=>("0"+e.toString(16)).slice(-2)).join("");t.string2Bytes=e=>{const t=[];for(let i=0;i<e.length;i++)t.push(e.charCodeAt(i));return t};t.hexStrint2byte=e=>{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){(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(35)}catch(e){}var r=function(){if(s){if("function"==typeof s.getRandomValues)try{return s.getRandomValues(new Uint32Array(1))[0]}catch(e){}if("function"==typeof s.randomBytes)try{return s.randomBytes(4).readInt32LE()}catch(e){}}throw new Error("Native crypto module could not be used to get secure random number.")},a=Object.create||function(){function e(){}return function(t){var i;return e.prototype=t,i=new e,e.prototype=null,i}}(),o={},c=o.lib={},u=c.Base={extend:function(e){var t=a(this);return e&&t.mixIn(e),t.hasOwnProperty("init")&&this.init!==t.init||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},d=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 a=i[r>>>2]>>>24-r%4*8&255;t[n+r>>>2]|=a<<24-(n+r)%4*8}else for(var o=0;o<s;o+=4)t[n+o>>>2]=i[o>>>2];return this.sigBytes+=s,this},clamp:function(){var t=this.words,i=this.sigBytes;t[i>>>2]&=4294967295<<32-i%4*8,t.length=e.ceil(i/4)},clone:function(){var e=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 d.init(t,e)}}),l=o.enc={},h=l.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 d.init(i,t/2)}},f=l.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 d.init(i,t)}},p=l.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 d.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=p.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var i,n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a),c=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,u=e.min(4*c,r);if(c){for(var l=0;l<c;l+=a)this._doProcessBlock(s,l);i=s.splice(0,c),n.sigBytes-=u}return new d.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)}}}),o.algo={});return o}(Math),n)}).call(this,i(18))},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(4)),r=n(i(39));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),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){"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.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(19)),a=i(16),o=s(i(4));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":a.getGlobalData("appID")};i&&(s["X-Gizwits-User-token"]=a.getGlobalData("token")),n.header=Object.assign(Object.assign({},s),t.headers),delete n.headers;const c=a.getGlobalData("cloudServiceInfo").openAPIInfo,u=yield r.default("https://"+c+e,n);if(u.statusCode>=200&&u.statusCode<300)return{success:!0,data:u.data};let d={success:!1,err:{errorCode:o.default.GIZ_SDK_HTTP_REQUEST_FAILED.errorCode,errorMessage:""}};try{d={success:!1,err:{errorCode:u.data.error_code,errorMessage:u.data.error_message}}}catch(e){}return d}))},function(e,t,i){var n;e.exports=(n=i(2),function(e){var t=n,i=t.lib,s=i.WordArray,r=i.Hasher,a=t.algo,o=[];!function(){for(var t=0;t<64;t++)o[t]=4294967296*e.abs(e.sin(t+1))|0}();var c=a.MD5=r.extend({_doReset:function(){this._hash=new s.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,t){for(var i=0;i<16;i++){var n=t+i,s=e[n];e[n]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8)}var r=this._hash.words,a=e[t+0],c=e[t+1],f=e[t+2],p=e[t+3],v=e[t+4],g=e[t+5],y=e[t+6],_=e[t+7],m=e[t+8],D=e[t+9],b=e[t+10],S=e[t+11],w=e[t+12],I=e[t+13],A=e[t+14],B=e[t+15],k=r[0],E=r[1],C=r[2],T=r[3];k=u(k,E,C,T,a,7,o[0]),T=u(T,k,E,C,c,12,o[1]),C=u(C,T,k,E,f,17,o[2]),E=u(E,C,T,k,p,22,o[3]),k=u(k,E,C,T,v,7,o[4]),T=u(T,k,E,C,g,12,o[5]),C=u(C,T,k,E,y,17,o[6]),E=u(E,C,T,k,_,22,o[7]),k=u(k,E,C,T,m,7,o[8]),T=u(T,k,E,C,D,12,o[9]),C=u(C,T,k,E,b,17,o[10]),E=u(E,C,T,k,S,22,o[11]),k=u(k,E,C,T,w,7,o[12]),T=u(T,k,E,C,I,12,o[13]),C=u(C,T,k,E,A,17,o[14]),k=d(k,E=u(E,C,T,k,B,22,o[15]),C,T,c,5,o[16]),T=d(T,k,E,C,y,9,o[17]),C=d(C,T,k,E,S,14,o[18]),E=d(E,C,T,k,a,20,o[19]),k=d(k,E,C,T,g,5,o[20]),T=d(T,k,E,C,b,9,o[21]),C=d(C,T,k,E,B,14,o[22]),E=d(E,C,T,k,v,20,o[23]),k=d(k,E,C,T,D,5,o[24]),T=d(T,k,E,C,A,9,o[25]),C=d(C,T,k,E,p,14,o[26]),E=d(E,C,T,k,m,20,o[27]),k=d(k,E,C,T,I,5,o[28]),T=d(T,k,E,C,f,9,o[29]),C=d(C,T,k,E,_,14,o[30]),k=l(k,E=d(E,C,T,k,w,20,o[31]),C,T,g,4,o[32]),T=l(T,k,E,C,m,11,o[33]),C=l(C,T,k,E,S,16,o[34]),E=l(E,C,T,k,A,23,o[35]),k=l(k,E,C,T,c,4,o[36]),T=l(T,k,E,C,v,11,o[37]),C=l(C,T,k,E,_,16,o[38]),E=l(E,C,T,k,b,23,o[39]),k=l(k,E,C,T,I,4,o[40]),T=l(T,k,E,C,a,11,o[41]),C=l(C,T,k,E,p,16,o[42]),E=l(E,C,T,k,y,23,o[43]),k=l(k,E,C,T,D,4,o[44]),T=l(T,k,E,C,w,11,o[45]),C=l(C,T,k,E,B,16,o[46]),k=h(k,E=l(E,C,T,k,f,23,o[47]),C,T,a,6,o[48]),T=h(T,k,E,C,_,10,o[49]),C=h(C,T,k,E,A,15,o[50]),E=h(E,C,T,k,g,21,o[51]),k=h(k,E,C,T,w,6,o[52]),T=h(T,k,E,C,p,10,o[53]),C=h(C,T,k,E,b,15,o[54]),E=h(E,C,T,k,c,21,o[55]),k=h(k,E,C,T,m,6,o[56]),T=h(T,k,E,C,B,10,o[57]),C=h(C,T,k,E,y,15,o[58]),E=h(E,C,T,k,I,21,o[59]),k=h(k,E,C,T,v,6,o[60]),T=h(T,k,E,C,S,10,o[61]),C=h(C,T,k,E,f,15,o[62]),E=h(E,C,T,k,D,21,o[63]),r[0]=r[0]+k|0,r[1]=r[1]+E|0,r[2]=r[2]+C|0,r[3]=r[3]+T|0},_doFinalize:function(){var t=this._data,i=t.words,n=8*this._nDataBytes,s=8*t.sigBytes;i[s>>>5]|=128<<24-s%32;var r=e.floor(n/4294967296),a=n;i[15+(s+64>>>9<<4)]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),i[14+(s+64>>>9<<4)]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),t.sigBytes=4*(i.length+1),this._process();for(var o=this._hash,c=o.words,u=0;u<4;u++){var d=c[u];c[u]=16711935&(d<<8|d>>>24)|4278255360&(d<<24|d>>>8)}return o},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});function u(e,t,i,n,s,r,a){var o=e+(t&i|~t&n)+s+a;return(o<<r|o>>>32-r)+t}function d(e,t,i,n,s,r,a){var o=e+(t&n|i&~n)+s+a;return(o<<r|o>>>32-r)+t}function l(e,t,i,n,s,r,a){var o=e+(t^i^n)+s+a;return(o<<r|o>>>32-r)+t}function h(e,t,i,n,s,r,a){var o=e+(i^(t|~n))+s+a;return(o<<r|o>>>32-r)+t}t.MD5=r._createHelper(c),t.HmacMD5=r._createHmacHelper(c)}(Math),n.MD5)},function(e,t,i){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=i(2),r=n(i(3));function a(e){return Array.prototype.map.call(new Uint8Array(e),(function(e){return("00"+e.toString(16)).slice(-2)})).join("")}t.ab2hex=a,t.compareWXSDKVersion=function(e,t){const i=e.split("."),n=t.split("."),s=Math.max(e.length,t.length);for(;i.length<s;)i.push("0");for(;n.length<s;)n.push("0");for(let i=0;i<s;i++){const n=parseInt(e[i]),s=parseInt(t[i]);if(n>s)return 1;if(n<s)return-1}return 0},t.isError=e=>null!=e&&"symbol"==typeof e.errorCode,t.wrapErrorInfo=e=>({errorCode:e,errorMessage:e}),t.unionBy=(e,t)=>e.reduce((e,i)=>{const n=i[t];return e.some(e=>e[t]===n)||e.push(i),e},[]),t.isWXDevicesResult=function(e){return e.success&&"[object Array]"===Object.prototype.toString.call(e.bleDevices)},t.str2Buf=function(e){var t=e.length,i=new ArrayBuffer(t+2),n=new DataView(i);for(let i=0;i<t;i++)n.setUint8(i,parseInt(e[i],16));return i},t.numberArray2Uint8Array=e=>{const t=new ArrayBuffer(e.length),i=new Uint8Array(t);for(let n=0;n<t.byteLength;n++)i[n]=e[n];return i};function o(e){if(25!=(e=e.slice(0,25)).length)throw new Error("数据不合法");const t=`${u(e[0])}${u(e[1])}`;if(e[2]!==(255&e.slice(3).reduce((e,t)=>e+t,0)))throw new Error("校验和不合法");const i=u(e[3]),n=e.slice(5,5+e[4]).map(e=>u(e));return{mac:t,cmd:parseInt(i,16),data:n}}function c(e){return Array.prototype.map.call(new Uint8Array(e),(function(e){return e}))}function u(e,t=2){return`${new Array(t).fill(0).join("")}${e.toString(16)}`.slice(-t)}t.advertisData2PkAndMac=(e,t)=>e&&e.byteLength>=22&&e.byteLength<=24?Object.assign(Object.assign({},((e,t)=>{let i=e.slice(e.byteLength-16),n=e.slice(0,e.byteLength-16),s=a(i);if(t.find(e=>e===s)){const e=a(n);return{productKey:s,mac:e}}{i=e.slice(0,16),n=e.slice(16),s=a(i);const t=a(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 o=new Uint8Array(e);for(;!(i>e.byteLength-1);){const c=o[i];if(c<=0||!c)break;if(e.byteLength<c+i+1)break;const u=e.slice(i+1,i+c+1);if(c>=6&&c<=8&&(n=a(u),16==n.length&&(n=n.substring(0,15))),16==c){const e=a(u).toLowerCase();t.find(t=>t===e)&&(s=e)}1==c&&(r=new Uint8Array(u)[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.merageBleLocalDevices=(e,i)=>(e.map(e=>{e.isBleOnline=!1,e.bleWorkStatus=0}),i.map(i=>{const n=e.find(e=>t.isSameDevice(e,i));n?(n.isBleOnline=!0,n.bleDeviceID=i.bleDeviceID,n.connectType=i.connectType,n.bleWorkStatus=i.bleWorkStatus):e.push(i)}),e),t.merageLanLocalDevices=(e,i)=>(e.map(e=>{e.isLanOnline=!1}),i.map(i=>{const n=e.find(e=>t.isSameDevice(e,i));n?n.isLanOnline=!0:e.push(i)}),e),t.BTDevice2GDevice=(e,i)=>{let n={productKey:"",mac:"",bleWorkStatus:0},s={did:"",productKey:"",mac:"",bleWorkStatus:0,connectType:"NONE",isBleOnline:!0,isLanOnline:!1,isOnline:!1,name:e.name,isBind:!1,bleDeviceID:e.deviceId,ctime:(new Date).getTime()};switch(e.communicationType){case"BLE_BROADCAST":try{r.default.log("parse BLE_BROADCAST");const t=o(c(e.advertisData));n.productKey=t.data.join(""),n.mac=t.mac,s.connectType="BLE_BROADCAST"}catch(e){}break;default:n=t.advertisData2PkAndMac(e.advertisData,i)}return s=Object.assign(Object.assign({},s),n),s},t.getFirstConnectType=(e,t)=>{if(!t)return e.isLanOnline?"LAN":e.isBleOnline?"BLE":"WAN";if("WAN"===t)return"WAN";switch(t){case"BLE":return e.isBleOnline?"BLE":"NONE";case"LAN":return e.isLanOnline?"LAN":"NONE"}return"WAN"},t.getProductInfoThroughPK=(e,t)=>t.find(t=>t.productKey===e),t.mergeObject=(e,t)=>{for(let i in t)null!=t[i]&&""!==t[i]&&(e[i]=t[i]);return e},t.hex2ab=function(e){const t=[];for(let n=0;n<e.length;n+=2){var i=e.slice(n,n+2);t.push(parseInt(i,16))}return new Uint8Array(t)},t.parseBroadcastData=o,t.ab2numbers=c;let d=0;function l(e,t){let i=1,n=t;return e.map(e=>{const t=65535&(e^n);return n=i-t&65535,i<<=1,u(t,4)})}function h(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),a=(t>>4<<12)+(s>>4<<8)+((15&t)<<4)+(15&s),o=Array.from({length:11},(e,t)=>(n[2*t]<<8)+n[2*t+1]);return r.default.log("明文",u(e,4),u((t<<8)+s,4),o.map(e=>u(e,4))),[u(e,4),u((t<<8)+s,4),...l(o,a)].map(e=>`${e.slice(2)}${e.slice(0,2)}`)}t.encrypt=l,t.convertToServiceUuids=({len:e=null,data:i=null,index:n=0,mac:s})=>{const r=null==e?Math.round(18*Math.random())+1:e,a=null==i?Array.from({length:r},e=>Math.round(255*Math.random())):i,o=[147,r,...a],c=h(s,(()=>{const e=d;return d=d+1&255,e})(),o);return[...new Set(c)].length!==c.length?t.convertToServiceUuids({len:r,data:a,index:n++,mac:s}):c},t.convertToUuids=h,t.arrayBufferToWordArray=function(e){for(var t=[],i=new Uint8Array(e),n=0;n<i.length;n+=4){var r=i[n]<<24|i[n+1]<<16|i[n+2]<<8|i[n+3];t.push(r)}return s.lib.WordArray.create(t,i.length)}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(11)),a=i(1),o=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=a.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=a.fillString(e.toString(2),8*i.position.len);break}case"binary":{let e=t[i.name]||"";e instanceof Array&&(e=a.arrayToString(e));const s=a.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+=a.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+=a.fillString(parseInt(s,2).toString(16),2)}return a.fillString(n,2*e,!0)}case"number":return parseInt(t,2)/(1/i.uint_spec.ratio)+i.uint_spec.addition;default:return""}},d=({config:e,data:t,isAdaptiveDatapoint:i})=>{let n=e;const s=[0,0,0,3],r=[0],u=[0,147],d=[0,0,0,0];let h=[1],f="";const p=[];i||(n=n.filter(e=>"status_writable"===e.type)),n.map(e=>{void 0!==t[e.name]?(f=`1${f}`,p.push(e)):f=`0${f}`}),i&&(h=[17],n=p),f=a.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(a.completeBlock(g)),g=""),g=((e,i)=>{const n=o(e.data_type);return i=c(n,t,e)+i})(e,g)):(g.length>0&&(h=h.concat(a.completeBlock(g)),g=""),h=((e,i)=>{const n=o(e.data_type),s=c(n,t,e);return i=i.concat(a.completeBlock(s))})(e,h)),v=e}),g.length>0&&(h=h.concat(a.completeBlock(g)),g="");const y=r.concat(u).concat(d).concat(h),_=l(y);return s.push(..._),{data:s.concat(y),raw:{header:[0,0,0,3],flag:r,len:_,headerCmd:u,sn:d,cmd:h}}};function l(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,a={},o=0;return["status_writable","status_readonly","alert","fault"].map(c=>{const u=e.filter(e=>h(c,e.type)).length,{cmd:d,cmdDataLength:l}=p({type:c,attrs:e.slice(o,o+u),activeAttrs:t,flagString:i.substring(o,o+u),cmdData:n.slice(r,n.length),accumulate:s});return r+=l,a=Object.assign(Object.assign({},a),d),o+=u,null}),a}function p({type:e,attrs:t,activeAttrs:i,cmdData:n,flagString:s,accumulate:r}){let c=0,d=0,l=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?d+=e:l+=e}return null}),c=Math.ceil(l/8)+Math.ceil(d/8),{cmdDataLength:c,cmd:function({attrs:e,flagString:t,boolEnumLength:i,cmdData:n,accumulate:s}){const r={};let c=0;for(let d=0;d<t.length;d++)if(e[d]&&"1"===t[d]){const{data_type:t,position:{len:s}}=e[d];let l="";if("bool"===t||"enum"===t){let e="";n.slice(0,i).map(t=>(e+=a.fillString(t.toString(2),8),null));const t=e.length-c;l=e.substring(t-s,t),c+=s}else{const e=i,t=i+s;n.slice(e,t).map(e=>(l+=a.fillString(e.toString(2),8),null)),i+=s}const h=o(t);r[e[d].name]=u(h,l,e[d])}else if(s){const t=e[d]||{position:{len:0}};"byte"===t.position.unit?i+=t.position.len:c+=t.position.len}return r}({attrs:t,flagString:s,boolEnumLength:Math.ceil(d/8),cmdData:n,accumulate:r})}}t.getVariableLength=l;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:a.arrayToString(t.slice(0,4)),flag:"",len:"",cmd:"",sn:"",action:"",payload:""},o=e;let c=a.checkHeader(t);if(!1===c)return;const u=t.slice(c,t.length),d=a.getProtocolLen(u);if(c+=d,r.len=a.arrayToString(u.slice(0,d)),c+=1,r.flag=a.arrayToString(t.slice(c-1,c)),c+=2,r.cmd=a.arrayToString(t.slice(c-2,c)),r.sn="",("0093"===r.cmd||"0094"===r.cmd)&&(c+=4,r.sn=a.arrayToString(t.slice(c-4,c)),"01"===r.flag)){c+=2,c+=parseInt(a.arrayToString(t.slice(c-2,c)),16)}c+=1,r.action=a.arrayToString(t.slice(c-1,c)),i=parseInt(r.action,16),r.payload=a.arrayToString(t.slice(c,t.length));const l=t.slice(c,t.length);let h=o;1===i&&(h=o.filter(e=>"status_writable"===e.type));const v=JSON.parse(JSON.stringify(h)),g=Math.ceil(h.length/8);let y=l.slice(0,g),_=l.slice(g,l.length);3!==i&&4!==i||(y=new Array(g).fill(255),_=l);let m="";y.map(e=>(m+=a.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===o.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 d({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=l(t);return a.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]=a.hexStrint2byte(e[n])),"string"===i&&"object"==typeof e[n]&&(e[n]=a.arrayToString(e[n])))}return e}));t.formatBinary=v},function(e,t,i){var n,s,r,a,o,c,u,d,l,h,f,p,v,g,y,_,m,D,b;e.exports=(n=i(2),i(27),void(n.lib.Cipher||(s=n,r=s.lib,a=r.Base,o=r.WordArray,c=r.BufferedBlockAlgorithm,u=s.enc,u.Utf8,d=u.Base64,l=s.algo.EvpKDF,h=r.Cipher=c.extend({cfg:a.extend(),createEncryptor:function(e,t){return this.create(this._ENC_XFORM_MODE,e,t)},createDecryptor:function(e,t){return this.create(this._DEC_XFORM_MODE,e,t)},init:function(e,t,i){this.cfg=this.cfg.extend(i),this._xformMode=e,this._key=t,this.reset()},reset:function(){c.reset.call(this),this._doReset()},process:function(e){return this._append(e),this._process()},finalize:function(e){return e&&this._append(e),this._doFinalize()},keySize:4,ivSize:4,_ENC_XFORM_MODE:1,_DEC_XFORM_MODE:2,_createHelper:function(){function e(e){return"string"==typeof e?b: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=a.extend({createEncryptor:function(e,t){return this.Encryptor.create(e,t)},createDecryptor:function(e,t){return this.Decryptor.create(e,t)},init:function(e,t){this._cipher=e,this._iv=t}}),v=f.CBC=function(){var e=p.extend();function t(e,t,i){var n,s=this._iv;s?(n=s,this._iv=void 0):n=this._prevBlock;for(var r=0;r<i;r++)e[t+r]^=n[r]}return e.Encryptor=e.extend({processBlock:function(e,i){var n=this._cipher,s=n.blockSize;t.call(this,e,i,s),n.encryptBlock(e,i),this._prevBlock=e.slice(i,i+s)}}),e.Decryptor=e.extend({processBlock:function(e,i){var n=this._cipher,s=n.blockSize,r=e.slice(i,i+s);n.decryptBlock(e,i),t.call(this,e,i,s),this._prevBlock=r}}),e}(),g=(s.pad={}).Pkcs7={pad:function(e,t){for(var i=4*t,n=i-e.sigBytes%i,s=n<<24|n<<16|n<<8|n,r=[],a=0;a<n;a+=4)r.push(s);var c=o.create(r,n);e.concat(c)},unpad:function(e){var t=255&e.words[e.sigBytes-1>>>2];e.sigBytes-=t}},r.BlockCipher=h.extend({cfg:h.cfg.extend({mode:v,padding:g}),reset:function(){var e;h.reset.call(this);var t=this.cfg,i=t.iv,n=t.mode;this._xformMode==this._ENC_XFORM_MODE?e=n.createEncryptor:(e=n.createDecryptor,this._minBufferSize=1),this._mode&&this._mode.__creator==e?this._mode.init(this,i&&i.words):(this._mode=e.call(n,this,i&&i.words),this._mode.__creator=e)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e,t=this.cfg.padding;return this._xformMode==this._ENC_XFORM_MODE?(t.pad(this._data,this.blockSize),e=this._process(!0)):(e=this._process(!0),t.unpad(e)),e},blockSize:4}),y=r.CipherParams=a.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),_=(s.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext,i=e.salt;return(i?o.create([1398893684,1701076831]).concat(i).concat(t):t).toString(d)},parse:function(e){var t,i=d.parse(e),n=i.words;return 1398893684==n[0]&&1701076831==n[1]&&(t=o.create(n.slice(2,4)),n.splice(0,4),i.sigBytes-=16),y.create({ciphertext:i,salt:t})}},m=r.SerializableCipher=a.extend({cfg:a.extend({format:_}),encrypt:function(e,t,i,n){n=this.cfg.extend(n);var s=e.createEncryptor(i,n),r=s.finalize(t),a=s.cfg;return y.create({ciphertext:r,key:i,iv:a.iv,algorithm:e,mode:a.mode,padding:a.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,i,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(i,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}}),D=(s.kdf={}).OpenSSL={execute:function(e,t,i,n){n||(n=o.random(8));var s=l.create({keySize:t+i}).compute(e,n),r=o.create(s.words.slice(t),4*i);return s.sigBytes=4*t,y.create({key:s,iv:r,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.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);return n.iv=s.iv,m.decrypt.call(this,e,t,s.key,n)}}))))},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(6));const a=new class{constructor(){this.data={},this.key="dataPointConfig",this.init=()=>n(this,void 0,void 0,(function*(){const e=(yield wx.getStorageSync(this.key))||"{}";let t={};try{t=JSON.parse(e)}catch(e){}this.data=t})),this.getConfigFile=e=>n(this,void 0,void 0,(function*(){var t;if(!this.data[e]){const i=`/app/datapoint?product_key=${e}`,n=yield r.default(`${i}`,{method:"GET"});if(!n.success||!(null===(t=n.data)||void 0===t?void 0:t.entities))return null;this.data[e]=n.data,wx.setStorageSync(this.key,JSON.stringify(this.data))}return this.data[e]})),this.getAttrItem=(e,t)=>n(this,void 0,void 0,(function*(){this.data[e]||(yield this.getConfigFile(e));for(let i in this.data[e].entities[0].attrs){const n=this.data[e].entities[0].attrs[i];if(n.name===t)return n}return null}))}};a.init(),t.default=a},function(e,t,i){var n,s;e.exports=(s=i(2),i(10),s.mode.ECB=((n=s.lib.BlockCipherMode.extend()).Encryptor=n.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),n.Decryptor=n.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),n),s.mode.ECB)},function(e,t,i){var n;e.exports=(n=i(2),i(29),i(7),i(27),i(10),function(){var e=n,t=e.lib.BlockCipher,i=e.algo,s=[],r=[],a=[],o=[],c=[],u=[],d=[],l=[],h=[],f=[];!function(){for(var e=[],t=0;t<256;t++)e[t]=t<128?t<<1:t<<1^283;var i=0,n=0;for(t=0;t<256;t++){var p=n^n<<1^n<<2^n<<3^n<<4;p=p>>>8^255&p^99,s[i]=p,r[p]=i;var v=e[i],g=e[v],y=e[g],_=257*e[p]^16843008*p;a[i]=_<<24|_>>>8,o[i]=_<<16|_>>>16,c[i]=_<<8|_>>>24,u[i]=_,_=16843009*y^65537*g^257*v^16843008*i,d[p]=_<<24|_>>>8,l[p]=_<<16|_>>>16,h[p]=_<<8|_>>>24,f[p]=_,i?(i=v^e[e[e[y^v]]],n^=e[e[n]]):i=n=1}}();var p=[0,1,2,4,8,16,32,64,128,27,54],v=i.AES=t.extend({_doReset:function(){if(!this._nRounds||this._keyPriorReset!==this._key){for(var e=this._keyPriorReset=this._key,t=e.words,i=e.sigBytes/4,n=4*((this._nRounds=i+6)+1),r=this._keySchedule=[],a=0;a<n;a++)a<i?r[a]=t[a]:(u=r[a-1],a%i?i>6&&a%i==4&&(u=s[u>>>24]<<24|s[u>>>16&255]<<16|s[u>>>8&255]<<8|s[255&u]):(u=s[(u=u<<8|u>>>24)>>>24]<<24|s[u>>>16&255]<<16|s[u>>>8&255]<<8|s[255&u],u^=p[a/i|0]<<24),r[a]=r[a-i]^u);for(var o=this._invKeySchedule=[],c=0;c<n;c++){if(a=n-c,c%4)var u=r[a];else u=r[a-4];o[c]=c<4||a<=4?u:d[s[u>>>24]]^l[s[u>>>16&255]]^h[s[u>>>8&255]]^f[s[255&u]]}}},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,a,o,c,u,s)},decryptBlock:function(e,t){var i=e[t+1];e[t+1]=e[t+3],e[t+3]=i,this._doCryptBlock(e,t,this._invKeySchedule,d,l,h,f,r),i=e[t+1],e[t+1]=e[t+3],e[t+3]=i},_doCryptBlock:function(e,t,i,n,s,r,a,o){for(var c=this._nRounds,u=e[t]^i[0],d=e[t+1]^i[1],l=e[t+2]^i[2],h=e[t+3]^i[3],f=4,p=1;p<c;p++){var v=n[u>>>24]^s[d>>>16&255]^r[l>>>8&255]^a[255&h]^i[f++],g=n[d>>>24]^s[l>>>16&255]^r[h>>>8&255]^a[255&u]^i[f++],y=n[l>>>24]^s[h>>>16&255]^r[u>>>8&255]^a[255&d]^i[f++],_=n[h>>>24]^s[u>>>16&255]^r[d>>>8&255]^a[255&l]^i[f++];u=v,d=g,l=y,h=_}v=(o[u>>>24]<<24|o[d>>>16&255]<<16|o[l>>>8&255]<<8|o[255&h])^i[f++],g=(o[d>>>24]<<24|o[l>>>16&255]<<16|o[h>>>8&255]<<8|o[255&u])^i[f++],y=(o[l>>>24]<<24|o[h>>>16&255]<<16|o[u>>>8&255]<<8|o[255&d])^i[f++],_=(o[h>>>24]<<24|o[u>>>16&255]<<16|o[d>>>8&255]<<8|o[255&l])^i[f++],e[t]=v,e[t+1]=g,e[t+2]=y,e[t+3]=_},keySize:8});e.AES=t._createHelper(v)}(),n.AES)},function(e,t,i){var n;e.exports=(n=i(2),n.enc.Utf8)},function(e,t,i){var n;e.exports=(n=i(2),n.enc.Hex)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n={};t.setGlobalData=function(e,t){n[e]=t},t.getGlobalData=function(e){return n[e]}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__rest||function(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(e);s<n.length;s++)t.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(e,n[s])&&(i[n[s]]=e[n[s]])}return i},r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=r(i(7)),o=r(i(30)),c=i(8),u=i(20),d=r(i(21)),l=i(1),h=r(i(0)),f=r(i(22)),p=r(i(40)),v=i(9),g=r(i(3)),y=r(i(23)),_=r(i(5)),m=i(41),D=r(i(4)),b=r(i(42)),S=r(i(43)),w=r(i(44)),I=r(i(45)),A=r(i(46)),B=r(i(47)),k=r(i(48));class E extends y.default{constructor({pks:e=[],bleHandleParams:t={serviceUUIDSuffix:"abf0",characteristicUUIDSuffix:"abf7"},offlineThreshold:i}){super(),this.connectedList=[],this.connectingDevId=null,this.pks=[],this.listenDevOfflineTimer=null,this.boradcastDataCache={},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=>{g.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=>{g.default.error("openBluetoothAdapter fail",new Error(JSON.stringify(e))),this.notifyError({errMsg:e.errMsg,errCode:-1}),i({success:!1,err:e})}})}),this.handleOnBLECharacteristicValueChange=e=>n(this,void 0,void 0,(function*(){if(!e.value)return;const t=c.ab2hex(e.value);try{const i=new h.default(l.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=()=>n(this,void 0,void 0,(function*(){this.isRunInit=!0;const{platform:e}=wx.getSystemInfoSync();yield this.openBluetoothAdapter(),"ios"===e&&(yield this.openBluetoothAdapter("peripheral"));try{this.peripheralServer=(yield wx.createBLEPeripheralServer()).server,g.default.info("GIZ_SDK: 广播初始化成功",this.peripheralServer)}catch(e){g.default.error("GIZ_SDK: 广播初始化失败",new Error(JSON.stringify(e)))}const t=yield this.getBluetoothAdapterState();return this.isInitSuccess=!0,t})),this.checkPermission=()=>n(this,void 0,void 0,(function*(){if((yield wx.getSetting()).authSetting["scope.bluetooth"])return yield this.init();try{return yield wx.authorize({scope:"scope.bluetooth"}),yield this.init()}catch(e){g.default.log("授权失败",e),this.openBluetoothAdapter(),this.notifyError({errMsg:e.errMsg,errCode:-1})}})),this.getBluetoothAdapterState=()=>n(this,void 0,void 0,(function*(){g.default.log("getBluetoothAdapterState",yield wx.getBluetoothAdapterState());const e=yield wx.getBluetoothAdapterState(),{errMsg:t,available:i}=e,n=s(e,["errMsg","available"]);return{data:Object.assign({},n),err:c.wrapErrorInfo(t),success:i}})),this.getDeviceStatus=(e,t,i,s)=>n(this,void 0,void 0,(function*(){const n=yield p.default.pack(t,i,s);return n?yield this.write(e,c.numberArray2Uint8Array(n).buffer):{success:!1}})),this.updateDevice=e=>{const t=e.bleDeviceID,i=this.scanList.findIndex(e=>t==e.bleDeviceID);-1!==i&&(this.scanList[i]=e)},this.updateCtime=e=>{const t=e.deviceId,i=this.scanList.findIndex(e=>t==e.bleDeviceID);-1!==i&&(this.scanList[i].ctime=Date.now())},this.checkDeviceIsChange=(e,t)=>e.bleWorkStatus!==t.bleWorkStatus||e.name!==t.name||e.isBleOnline!==t.isBleOnline||e.isOnline!==t.isOnline,this.handleBluetoothDeviceFound=(e,t)=>{c.unionBy(e.devices,"deviceId").map(e=>{const{advertisData:i,deviceId:n,name:s,localName:r}=e,a=c.ab2hex(i);let o=null;try{o=c.parseBroadcastData(c.ab2numbers(i))}catch(e){}const u=this.scanList.find(e=>e.bleDeviceID===n);if(o&&148===o.cmd){const t=c.ab2hex(i);if(this.boradcastDataCache[n]&&this.boradcastDataCache[n]===t)return!1;if(!u)return!1;this.boradcastDataCache[n]=c.ab2hex(i);const s=v.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(u){const i=c.BTDevice2GDevice(e,this.pks);if(i.productKey&&i.mac){const e=this.checkDeviceIsChange(i,u);i.ctime=Date.now(),this.updateDevice(i),e&&t(this.scanList)}}else{if(this.pks.some(e=>a.includes(e))){const i=c.BTDevice2GDevice(e,this.pks);i.productKey&&i.mac&&(this.scanList.push(i),t(this.scanList))}}})},this.startScan=(e,t=5e3,i)=>n(this,void 0,void 0,(function*(){return this.disableScanFlag?{scanList:[]}:new Promise(s=>n(this,void 0,void 0,(function*(){wx.onBluetoothDeviceFound(t=>{this.handleBluetoothDeviceFound(t,e)}),g.default.debug("GIZ_SDK: start scan",t),yield wx.startBluetoothDevicesDiscovery({services:i||this.baseServices,powerLevel:"high",allowDuplicatesKey:!0,interval:200}),t>0&&setTimeout(()=>{this.stopScan(),s({scanList:this.scanList})},t)})))})),this.stopScan=()=>n(this,void 0,void 0,(function*(){try{return yield wx.stopBluetoothDevicesDiscovery()}catch(e){return e}})),this.disableScan=()=>n(this,void 0,void 0,(function*(){this.disableScanFlag=!0;const e=yield wx.stopBluetoothDevicesDiscovery();return yield _.default(200),e})),this.enableScan=()=>{this.disableScanFlag=!1},this.connectDevice=e=>n(this,void 0,void 0,(function*(){var t;try{this.connectingDevId=e;try{yield this.disableScan();const t=yield u.retryConnect(e);this.enableScan(),g.default.debug("connect res",t)}catch(e){if(g.default.error("GIZ_SDK: createBLEConnection error",new Error(JSON.stringify(e))),"createBLEConnection:fail:already connect"!==(null==e?void 0:e.errMsg))return this.notifyError(e),{success:!1,message:null==e?void 0:e.errMsg}}const i=yield wx.getBLEDeviceServices({deviceId:e}).catch(e=>this.notifyError(e)),n=null===(t=null==i?void 0:i.services.find(e=>e.isPrimary&&e.uuid.toLowerCase().includes(this.serviceUUIDSuffix)))||void 0===t?void 0:t.uuid;if(!n)return{message:"can not find valid serviceId",success:!1};const s=yield wx.getBLEDeviceCharacteristics({deviceId:e,serviceId:n}).catch(e=>this.notifyError(e)),r=null==s?void 0:s.characteristics[0].uuid;this.connectedList.every(t=>t.deviceId!==e)&&this.connectedList.push({deviceId:e,serviceId:n,characteristicId:r}),g.default.debug("获取特征值成功"),wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:n,characteristicId:r,state:!0,type:"notification"}).catch(e=>this.notifyError(e)),yield _.default(100),g.default.debug("监听设备成功"),this.write(e,c.numberArray2Uint8Array(d.default.pack()).buffer);const a=yield this.handleBindReq(e);if(g.default.log("handleBindReq",a),a.success){this.write(e,c.numberArray2Uint8Array(f.default.pack({passcode:a.data})).buffer);const t=yield this.handleLoginReq(e).catch(e=>this.notifyError(e));if(null==t?void 0:t.success)return{success:!0,message:"ok"}}return yield wx.closeBLEConnection({deviceId:e}),{success:!1,message:"ok"}}finally{this.connectingDevId=null}})),this.handleWatchBleData=(e,t,i=3e3)=>n(this,void 0,void 0,(function*(){return new Promise(n=>{let s=(i,r)=>{if(e!==i.deviceId)return;const a=t(i,r);a&&(n({success:!0,data:a}),this.removeEventListener("GizBleDeviceData",s))};this.addEventListener("GizBleDeviceData",s),setTimeout(()=>{s&&(this.removeEventListener("GizBleDeviceData",s),n({success:!1,err:D.default.GIZ_SDK_DEVICE_NO_RESPONSE}))},i)})})),this.handleBindReq=e=>new Promise(t=>{const i=(n,s)=>{if(n.deviceId!==e)return;g.default.log("监听蓝牙特征值发生变化");const r=new d.default(l.hexStrint2byte(s));this.removeEventListener("GizBleDeviceData",i),r.passcode?t({success:!0,data:r.passcode}):t({success:!1,data:""})};this.watchBleDevice(e,i)}),this.handleLoginReq=e=>new Promise(t=>{const i=(n,s)=>{if(n.deviceId!==e)return;g.default.log("设备回复LoginReq",s);const r=new f.default(l.hexStrint2byte(s));this.removeEventListener("GizBleDeviceData",i),!0===r.result?t({success:!0,data:r.did}):t({success:!1,data:""})};this.watchBleDevice(e,i)}),this.startUpgrade=({deviceId:e,did:t,type:i,onEvent:s,onProgress:r,productKey:d})=>n(this,void 0,void 0,(function*(){s({code:"GizOTAEventPretreatment"});const n=yield this.checkUpdate({deviceId:e,did:t,type:i});if(g.default.debug("检查设备是否有新固件",n),n.success){const t=n.data.download_url,f=n.data.soft_ver;s({code:"GizOTAEventDownload"});let p="";try{p=(yield u.downloadFile({url:t})).tempFilePath}catch(e){return g.default.error("固件下载失败",e),{success:!1,err:D.default.GIZ_SDK_OTA_FIRMWARE_DOWNLOAD_FAILED}}g.default.debug("下载固件成功",p),s({code:"GizOTAEventTransmit"});const v=(e,t)=>{const i=l.hexStrint2byte(t);switch(new h.default(i).cmd){case"0042":return new S.default(i)}return null},y=(e,t)=>{const i=l.hexStrint2byte(t);switch(new h.default(i).cmd){case"0044":return new w.default(i)}return null},m=(e,t)=>{const i=l.hexStrint2byte(t);switch(new h.default(i).cmd){case"0052":return new B.default(i)}return null};g.default.debug("查询设备是否可以OTA");const b=S.default.pack(i);yield this.write(e,c.numberArray2Uint8Array(b).buffer);const E=yield this.handleWatchBleData(e,v);if(g.default.debug("设备回复是否可以OTA",E),E.success&&E.data.type!==i)return g.default.error(null,new Error("OTA类型不匹配")),{success:!1,err:D.default.GIZ_SDK_OTA_FIRMWARE_TYPE_NOT_MATCH};if(E.success&&0===E.data.state){const t=wx.getFileSystemManager();let n=[];try{n=yield t.readFileSync(p,"hex",0)}catch(e){return g.default.error("读取固件失败",e),{success:!1,err:D.default.GIZ_SDK_OTA_FIRMWARE_DOWNLOAD_FAILED}}const u=n.match(/.{1,2}/g).map((function(e){return parseInt(e,16)})),v=c.arrayBufferToWordArray(u),b=a.default(v).toString(),S=o.default.crc32(u),B=w.default.pack(d,f,b,u.length,S);yield this.write(e,c.numberArray2Uint8Array(B).buffer);const E=yield this.handleWatchBleData(e,y,5e3);if(g.default.debug("设备回复ota 预请求",E),E.success&&0===E.data.state){let t=0;if(E.data.processedLen>0){o.default.crc32(u.slice(0,E.data.processedLen)).toString(16)===E.data.processedCrc32?(t=E.data.processedLen,g.default.debug(`断点续传,从 ${t} 开始`)):(g.default.debug("从位置0开始OTA"),yield this.write(e,c.numberArray2Uint8Array(I.default.pack(0)).buffer),yield _.default(100))}const n=u.length,a=E.data.packageMaxLen;let d=Math.ceil(t/a),p=0;for(;t<n;){const i=u.slice(t,t+a),s=A.default.pack(i,d);yield this.write(e,c.numberArray2Uint8Array(s).buffer);const o=(e,t)=>{const i=l.hexStrint2byte(t);switch(new h.default(i).cmd){case"0048":{const e=new A.default(i);return e.packageNum===d?e:null}}return null},f=yield this.handleWatchBleData(e,o,5e3);let v=!1;if(!1===f.success&&(v=!0),f.success&&0!==f.data.state&&4!==f.data.state&&(v=!0),v){if(p+=1,g.default.debug(`发送OTA包失败,重试次数 ${p}`,f),p>3)return g.default.debug("发送OTA包失败次数超过限制"),{success:!1};continue}g.default.debug("设备接收ota子包成功",f),p=0,t+=a,d+=1;let y=parseInt(`${d*a/n*100}`);if(y>100&&(y=100),r({firmwareSize:n,packageMaxLen:a,currentNumber:d,currentProgress:y}),yield _.default(100),4===f.data.state){g.default.debug("设备请求等待OTA");const t=yield this.handleWatchBleData(e,m,6e4);if(g.default.debug("设备回复等待结果",t),1===t.data.state)return{success:!1}}}g.default.debug("发送完所有数据包,等待设备回复");const v=(e,t)=>{const i=l.hexStrint2byte(t);switch(new h.default(i).cmd){case"0050":return new k.default(i)}return null},y=yield this.handleWatchBleData(e,v,1e4);if(y.success&&0===y.data.state){g.default.debug("设备回复收到固件,准备重启设备"),s({code:"GizOTAEventReboot"}),this.disConnectDevice(e),yield _.default(1e4);const t=yield this.connectDevice(e);if(console.log("connectRes",t),!t.success)return g.default.debug("设备重启后,无法连接"),{success:!1};const n=yield this.getDeviceInfo({deviceId:e});if(!n.success)return g.default.debug("获取设备版本号失败"),{success:!1};let r="";return r="MCU"===i?n.data.mcuSoftVersion:n.data.moduleSoftVersion,s({code:"GizOTAEventFinish"}),r===f?{success:!0}:(g.default.debug("设备上报版本号与更新的固件版本号不匹配,更新失败"),{success:!1})}return{success:!1}}return{success:!1}}return{success:!1,err:D.default.GIZ_SDK_OTA_DEVICE_BUSY_IN_UPGRADE}}return n})),this.getDeviceInfo=({deviceId:e})=>n(this,void 0,void 0,(function*(){const t=b.default.pack();g.default.debug("DeviceInfo.pack",t),yield this.write(e,c.numberArray2Uint8Array(t).buffer);return yield this.handleWatchBleData(e,(e,t)=>{const i=l.hexStrint2byte(t);switch(new h.default(i).cmd){case"0014":try{const e=new b.default(i);return g.default.debug("parse DeviceInfo",e),e}catch(e){g.default.debug("parse DeviceInfo error",e)}}return null})})),this.checkUpdate=({deviceId:e,did:t,type:i})=>n(this,void 0,void 0,(function*(){const n=yield this.getDeviceInfo({deviceId:e});if(n.success){let e="",s="";return"MCU"===i?(e=n.data.mcuSoftVersion,s=n.data.mcuHardVersion):(e=n.data.moduleSoftVersion,s=n.data.moduleHardVersion),yield m.checkUpdate({did:t,type:i,softVersion:e,hardVersion:s})}return n})),this.watchBleDevice=(e,t)=>n(this,void 0,void 0,(function*(){const{serviceId:i,characteristicId:n,errMsg:s}=this.getTargetDevice(e);return s?{success:!1,message:s}:(yield wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:i,characteristicId:n,state:!0,type:"notification"}).catch(e=>this.notifyError(e)),g.default.log(`监听设备 ${e} 成功!`),this.addEventListener("GizBleDeviceData",t),{message:"ok",success:!0})})),this.writeBoradcast=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.scanList.find(t=>t.bleDeviceID===e);if(!i)return{success:!1,message:"not found device"};this.boradcastTimer&&clearTimeout(this.boradcastTimer);try{this.peripheralServer.stopAdvertising({});const e=c.convertToServiceUuids({mac:i.mac,index:0,data:t,len:t.length});return this.peripheralServer.startAdvertising({advertiseRequest:{connectable:!0,serviceUuids:e},powerLevel:"high",success:e=>{g.default.debug("GIZ_SDK: startAdvertising success",e)},fail:e=>{g.default.error("GIZ_SDK: startAdvertising error",new Error(JSON.stringify(e)))}}),g.default.debug("GIZ_SDK: start adv",e),this.boradcastTimer=setTimeout(()=>{this.peripheralServer.stopAdvertising({}),this.boradcastTimer=null},1e3),{success:!0}}catch(e){return g.default.log("GIZ_SDK:",e),clearTimeout(this.boradcastTimer),{success:!1,message:"send cmd error"}}})),this.write=(e,t)=>n(this,void 0,void 0,(function*(){g.default.log("app => dev:",c.ab2hex(t));const i=this.getTargetDevice(e);if(i.serviceId&&i.characteristicId){return yield u.unpackWriteBLECharacteristicValue(e,i.serviceId,i.characteristicId,t)}return{success:!1,message:"send cmd error"}})),this.disConnectDevice=e=>n(this,void 0,void 0,(function*(){this.removeDevById(e);const{errMsg:t}=yield wx.closeBLEConnection({deviceId:e}),i=this.scanList.find(t=>t.bleDeviceID===e);return i&&(i.ctime=Date.now(),this.updateDevice(i)),"closeBLEConnection:ok"===t?{err:t,success:!0}:{err:t,success:!1}})),this.removeDevById=e=>{const t=this.connectedList.findIndex(t=>t.deviceId===e);-1!==t&&this.connectedList.splice(t,1)},this.getTargetDevice=e=>{const t=this.connectedList.find(t=>e===t.deviceId);return t||{errMsg:"Unable get this device,maybe you forgot to connect it."}},this.destory=()=>{this.listenDevOfflineTimer&&clearInterval(this.listenDevOfflineTimer),wx.offAppShow(this.onAppShow),wx.offAppHide(this.onAppHide),wx.offBluetoothAdapterStateChange(this.onBluetoothAdapterStateChange)};const{serviceUUIDSuffix:r}=t;this.serviceUUIDSuffix=r,this.pks=e,this.offlineThreshold=i,this.listenDevOffline(),this.listenConnection(),wx.onAppShow(this.onAppShow),wx.onAppHide(this.onAppHide),wx.onBluetoothAdapterStateChange(this.onBluetoothAdapterStateChange)}set offlineThreshold(e){this._offlineThreshold=e}get offlineThreshold(){return this._offlineThreshold||1e4}}t.BleHandle=E},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){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){return new Promise((i,n)=>{wx.request(Object.assign(Object.assign({url:e,timeout:3e3},t),{success:e=>{i(e)},fail:e=>{n(e)}}))})}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(5));function a(e,t){return new Promise((i,n)=>{wx.createBLEConnection({deviceId:e,timeout:t,success:e=>i(e),fail:e=>{-1===e.errCode?i(e):n(e)}})})}function o(e,t,i,n){return new Promise(s=>{wx.writeBLECharacteristicValue({deviceId:e,serviceId:t,characteristicId:i,value:n,complete:s})})}t.retryConnect=function(e,t=1e4){return n(this,void 0,void 0,(function*(){let i={success:!1};for(let n=0;n<5;n++)try{return console.debug("start createBLEConnection"),yield a(e,t)}catch(e){i=e,console.debug("createBLEConnection error retry"),yield r.default(1e3)}return i}))},t.openBluetoothAdapter=function(){return new Promise((e,t)=>{wx.openBluetoothAdapter({success:e,fail:t})})},t.closeBluetoothAdapter=function(){return new Promise((e,t)=>{wx.closeBluetoothAdapter({success:e,fail:t})})},t.getBluetoothAdapterState=function(){return new Promise((e,t)=>{wx.getBluetoothAdapterState({success:e,fail:t})})},t.startBluetoothDevicesDiscovery=function(e=!0){return new Promise((t,i)=>{wx.startBluetoothDevicesDiscovery({success:t,fail:i,allowDuplicatesKey:e,powerLevel:"high",interval:200})})},t.getBluetoothDevices=function(){return new Promise((e,t)=>{wx.getBluetoothDevices({success:({devices:t})=>e(t),fail:t})})},t.createBLEConnection=a,t.getBLEDeviceServices=function(e){return new Promise((t,i)=>{wx.getBLEDeviceServices({deviceId:e,success:({services:e})=>t(e),fail:i})})},t.getBLEDeviceCharacteristics=function(e,t){return new Promise((i,n)=>{wx.getBLEDeviceCharacteristics({deviceId:e,serviceId:t,success:({characteristics:e})=>i(e),fail:n})})},t.notifyBLECharacteristicValueChange=function(e,t,i,n=!0){return new Promise((s,r)=>{wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:t,characteristicId:i,state:n,success:s,fail:r})})},t.writeBLECharacteristicValue=o,t.unpackWriteBLECharacteristicValue=function(e,t,i,s,a=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,d=0,l=s.byteLength;for(;l>0;){yield r.default(10);const c=s.slice(d,d+a);if(d+=a,l-=a,n=yield o(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(0)),r=i(1);class a extends s.default{constructor(e){super(e),this.passcode="";let t=0;const i=parseInt(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}}a.pack=()=>[0,0,0,3,3,0,0,6],t.default=a},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(0)),r=i(1);class a 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(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}}}a.pack=({passcode:e})=>{let t=[0];const i=r.hexStrint2byte(r.fillString(e.length.toString(16),4)),n=r.string2Bytes(e),s=[0].concat([0,8]).concat(i).concat(n);return t=r.hexStrint2byte(s.length.toString(16)),[0,0,0,3].concat(t).concat(s)},t.default=a},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});t.default=class{constructor(){this.listenerMap={},this.addEventListener=(e,t)=>n(this,void 0,void 0,(function*(){return this.listenerMap[e]||(this.listenerMap[e]=[]),-1===this.listenerMap[e].indexOf(t)&&this.listenerMap[e].push(t),{success:!0}})),this.removeEventListener=(e,t)=>{if(this.listenerMap[e]){const i=this.listenerMap[e].indexOf(t);if(-1!==i)return this.listenerMap[e].splice(i,1),{success:!0}}return{success:!1}}}}},function(e,t,i){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=n(i(0)),r=i(1);class a extends s.default{constructor(e){super(e)}}a.pack=(e,t)=>{const i=[],[n,s]=r.formatCodesFromStr(e),[a,o]=r.formatCodesFromStr(t),c=[0].concat([0,1],s,n,o,a);let u=c.length;for(;u>0;)i.push(u),u-=255;const d=[0,0,0,3].concat(i).concat(c),l=new ArrayBuffer(d.length),h=new Uint8Array(l);for(let e=0;e<l.byteLength;e++)h[e]=d[e];return h},t.default=a},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(5)),a=s(i(4)),o=i(26),c=s(i(3));t.default=class{constructor(e,t,i,s){this.ssid="",this.password="",this.specialProductKeys=[],this.disableSearchDevice=!1,this.specialProductKeySecrets=[],this.timeoutHandler=null,this.setDeviceOnboardingDeployRej=()=>{},this.cleanTimeout=()=>{this.disableSearchDevice=!0,this.timeoutHandler&&clearTimeout(this.timeoutHandler),this.timeoutHandler=null},this.stopDeviceOnboardingDeploy=()=>{this.setDeviceOnboardingDeployRej&&this.setDeviceOnboardingDeployRej({success:!1,err:a.default.GIZ_SDK_ONBOARDING_STOPPED}),this.cleanTimeout()},this.hasTimeoutHandler=e=>!!this.timeoutHandler&&(e&&e({success:!1,err:a.default.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING}),!0),this.handleTimeout=()=>{this.setDeviceOnboardingDeployRej&&this.setDeviceOnboardingDeployRej({success:!1,err:{errorCode:a.default.CONFIG_TIME_OUT,errorMessage:"time out"}}),this.timeoutHandler=null},this.searchDevice=({ssid:e,password:t})=>new Promise((i,s)=>{c.default.debug("GIZ_SDK: 开始大循环搜索设备");const u=()=>n(this,void 0,void 0,(function*(){var n;if(this.hasTimeoutHandler())try{const d=yield o.checkDeviceRegister({SSID:e,password:t,productKeys:this.specialProductKeys});if((null===(n=d.err)||void 0===n?void 0:n.errorCode)===a.default.GIZ_OPENAPI_TOKEN_INVALID.errorCode)return void s({success:!1,err:a.default.GIZ_OPENAPI_TOKEN_INVALID});d.err||0===d.data.length?(c.default.debug("GIZ_SDK: 大循环没有发现设备"),yield r.default(1500),!this.disableSearchDevice&&u()):(c.default.debug("GIZ_SDK: 大循环搜索到设备",d),i({success:!0,data:d.data}))}catch(e){yield r.default(3e3),!this.disableSearchDevice&&u()}}));u()}),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"),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 o.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});r.length>0?(c.default.log("GIZ_SDK: bind device success",r),t({success:!0,data:r})):(c.default.log("GIZ_SDK: bind device error",s),i({success:!1,data:e,err:a.default.GIZ_SDK_BIND_DEVICE_FAILED}))}catch(e){i(e)}})))),this.ssid=e,this.password=t,this.specialProductKeys=i,this.specialProductKeySecrets=s}}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(12)),a=s(i(28)),o=s(i(13)),c=s(i(14)),u=s(i(15)),d=s(i(29)),l=s(i(6)),h=s(i(53)),f=i(55);class p{constructor(){this.pad=(e,t)=>{},this.unpad=e=>{const t=e.sigBytes;let i=0,n=1;const s=e.toString(c.default);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 l.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,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:o}=f.psKeySign(i);return yield l.default("/app/bind_mac",{method:"POST",data:n,headers:{"X-Gizwits-Signature":a,"X-Gizwits-Timestamp":o}})}))},t.unbindDevice=function({devices:e}){return n(this,void 0,void 0,(function*(){return yield l.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=h.default({SSID:e,password:t,pks:i});let s="";return n.map(e=>{s+=`${e},`}),s=s.substring(0,s.length-1),yield l.default(`/app/device_register?random_codes=${s}`,{method:"get"})}))},t.safeRegister=function({productKey:e,productSecret:t,mac:i,passcode:s,gwDid:d,isReset:h}){return n(this,void 0,void 0,(function*(){let n=`is_reset=${h?1:0}&mac=${i}&passcode=${s}`;d&&(n+=`&gw_did=${d}`);const f=u.default.parse(t),p=u.default.parse(""),g=c.default.parse(n),y=o.default.encrypt(g,f,{iv:p,mode:r.default,padding:a.default}).ciphertext.toString().toUpperCase(),_=yield l.default(`/dev/${e}/device`,{method:"POST",data:{data:y},headers:{"content-type":"application/x-www-form-urlencoded"}},!1);if(_.success){const e=v({productSecret:t,iv:p,data:_.data}),n=[];return e.find(e=>e.mac===i)||n.push({mac:i}),{success:!0,data:{successDevices:e,failedDevices:n}}}return{success:!1,err:_.err}}))};const v=({productSecret:e,data:t,iv:i})=>{const n=u.default.parse(e),s=u.default.parse(t);const a=o.default.decrypt(d.default.stringify(s),n,{iv:i,mode:r.default,padding:new p}).toString(c.default),l=[];return a.split(",").map(e=>{const t=e.split("&"),i=t[0].replace("mac=",""),n=t[1].replace("did=","");l.push({mac:i,did:n})}),l};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 l.default(`/app/bindings/${i}`,{method:"PUT",data:n},!0)}))}},function(e,t,i){var n,s,r,a,o,c,u,d;e.exports=(d=i(2),i(51),i(52),s=(n=d).lib,r=s.Base,a=s.WordArray,o=n.algo,c=o.MD5,u=o.EvpKDF=r.extend({cfg:r.extend({keySize:4,hasher:c,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var i,n=this.cfg,s=n.hasher.create(),r=a.create(),o=r.words,c=n.keySize,u=n.iterations;o.length<c;){i&&s.update(i),i=s.update(e).finalize(t),s.reset();for(var d=1;d<u;d++)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)},d.EvpKDF)},function(e,t,i){var n;e.exports=(n=i(2),i(10),n.pad.Pkcs7)},function(e,t,i){var n,s,r;e.exports=(r=i(2),s=(n=r).lib.WordArray,n.enc.Base64={stringify:function(e){var t=e.words,i=e.sigBytes,n=this._map;e.clamp();for(var s=[],r=0;r<i;r+=3)for(var a=(t[r>>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;o<4&&r+.75*o<i;o++)s.push(n.charAt(a>>>6*(3-o)&63));var c=n.charAt(64);if(c)for(;s.length%4;)s.push(c);return s.join("")},parse:function(e){var t=e.length,i=this._map,n=this._reverseMap;if(!n){n=this._reverseMap=[];for(var r=0;r<i.length;r++)n[i.charCodeAt(r)]=r}var a=i.charAt(64);if(a){var o=e.indexOf(a);-1!==o&&(t=o)}return function(e,t,i){for(var n=[],r=0,a=0;a<t;a++)if(a%4){var o=i[e.charCodeAt(a-1)]<<a%4*2,c=i[e.charCodeAt(a)]>>>6-a%4*2,u=o|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){"use strict";i.r(t),i.d(t,"crc1",(function(){return o})),i.d(t,"crc8",(function(){return u})),i.d(t,"crc81wire",(function(){return l})),i.d(t,"crc8dvbs2",(function(){return f})),i.d(t,"crc16",(function(){return v})),i.d(t,"crc16ccitt",(function(){return y})),i.d(t,"crc16modbus",(function(){return m})),i.d(t,"crc16xmodem",(function(){return D})),i.d(t,"crc16kermit",(function(){return S})),i.d(t,"crc24",(function(){return I})),i.d(t,"crc32",(function(){return B})),i.d(t,"crc32mpeg2",(function(){return E})),i.d(t,"crcjam",(function(){return T}));var n=(e,t=0)=>{let i=~~t,n=0;for(let t=0;t<e.length;t++)n+=e[t];return i+=n%256,i%256},s=i(31);var r=(e,t)=>s.Buffer.from(e,t);function a(e,t){const i=(e,i)=>t(r(e),i)>>>0;return i.signed=(e,i)=>t(r(e),i),i.unsigned=i,i.model=e,i}var o=a("crc1",n);let c=[0,7,14,9,28,27,18,21,56,63,54,49,36,35,42,45,112,119,126,121,108,107,98,101,72,79,70,65,84,83,90,93,224,231,238,233,252,251,242,245,216,223,214,209,196,195,202,205,144,151,158,153,140,139,130,133,168,175,166,161,180,179,186,189,199,192,201,206,219,220,213,210,255,248,241,246,227,228,237,234,183,176,185,190,171,172,165,162,143,136,129,134,147,148,157,154,39,32,41,46,59,60,53,50,31,24,17,22,3,4,13,10,87,80,89,94,75,76,69,66,111,104,97,102,115,116,125,122,137,142,135,128,149,146,155,156,177,182,191,184,173,170,163,164,249,254,247,240,229,226,235,236,193,198,207,200,221,218,211,212,105,110,103,96,117,114,123,124,81,86,95,88,77,74,67,68,25,30,23,16,5,2,11,12,33,38,47,40,61,58,51,52,78,73,64,71,82,85,92,91,118,113,120,127,106,109,100,99,62,57,48,55,34,37,44,43,6,1,8,15,26,29,20,19,174,169,160,167,178,181,188,187,150,145,152,159,138,141,132,131,222,217,208,215,194,197,204,203,230,225,232,239,250,253,244,243];"undefined"!=typeof Int32Array&&(c=new Int32Array(c));var u=a("crc-8",(e,t=0)=>{let i=~~t;for(let t=0;t<e.length;t++)i=255&c[255&(i^e[t])];return i});let d=[0,94,188,226,97,63,221,131,194,156,126,32,163,253,31,65,157,195,33,127,252,162,64,30,95,1,227,189,62,96,130,220,35,125,159,193,66,28,254,160,225,191,93,3,128,222,60,98,190,224,2,92,223,129,99,61,124,34,192,158,29,67,161,255,70,24,250,164,39,121,155,197,132,218,56,102,229,187,89,7,219,133,103,57,186,228,6,88,25,71,165,251,120,38,196,154,101,59,217,135,4,90,184,230,167,249,27,69,198,152,122,36,248,166,68,26,153,199,37,123,58,100,134,216,91,5,231,185,140,210,48,110,237,179,81,15,78,16,242,172,47,113,147,205,17,79,173,243,112,46,204,146,211,141,111,49,178,236,14,80,175,241,19,77,206,144,114,44,109,51,209,143,12,82,176,238,50,108,142,208,83,13,239,177,240,174,76,18,145,207,45,115,202,148,118,40,171,245,23,73,8,86,180,234,105,55,213,139,87,9,235,181,54,104,138,212,149,203,41,119,244,170,72,22,233,183,85,11,136,214,52,106,43,117,151,201,74,20,246,168,116,42,200,150,21,75,169,247,182,232,10,84,215,137,107,53];"undefined"!=typeof Int32Array&&(d=new Int32Array(d));var l=a("dallas-1-wire",(e,t=0)=>{let i=~~t;for(let t=0;t<e.length;t++)i=255&d[255&(i^e[t])];return i});let h=[0,213,127,170,254,43,129,84,41,252,86,131,215,2,168,125,82,135,45,248,172,121,211,6,123,174,4,209,133,80,250,47,164,113,219,14,90,143,37,240,141,88,242,39,115,166,12,217,246,35,137,92,8,221,119,162,223,10,160,117,33,244,94,139,157,72,226,55,99,182,28,201,180,97,203,30,74,159,53,224,207,26,176,101,49,228,78,155,230,51,153,76,24,205,103,178,57,236,70,147,199,18,184,109,16,197,111,186,238,59,145,68,107,190,20,193,149,64,234,63,66,151,61,232,188,105,195,22,239,58,144,69,17,196,110,187,198,19,185,108,56,237,71,146,189,104,194,23,67,150,60,233,148,65,235,62,106,191,21,192,75,158,52,225,181,96,202,31,98,183,29,200,156,73,227,54,25,204,102,179,231,50,152,77,48,229,79,154,206,27,177,100,114,167,13,216,140,89,243,38,91,142,36,241,165,112,218,15,32,245,95,138,222,11,161,116,9,220,118,163,247,34,136,93,214,3,169,124,40,253,87,130,255,42,128,85,1,212,126,171,132,81,251,46,122,175,5,208,173,120,210,7,83,134,44,249];"undefined"!=typeof Int32Array&&(h=new Int32Array(h));var f=a("crc-8-dvbs2",(e,t=0)=>{let i=~~t;for(let t=0;t<e.length;t++)i=255&h[255&(i^e[t])];return i});let p=[0,49345,49537,320,49921,960,640,49729,50689,1728,1920,51009,1280,50625,50305,1088,52225,3264,3456,52545,3840,53185,52865,3648,2560,51905,52097,2880,51457,2496,2176,51265,55297,6336,6528,55617,6912,56257,55937,6720,7680,57025,57217,8e3,56577,7616,7296,56385,5120,54465,54657,5440,55041,6080,5760,54849,53761,4800,4992,54081,4352,53697,53377,4160,61441,12480,12672,61761,13056,62401,62081,12864,13824,63169,63361,14144,62721,13760,13440,62529,15360,64705,64897,15680,65281,16320,16e3,65089,64001,15040,15232,64321,14592,63937,63617,14400,10240,59585,59777,10560,60161,11200,10880,59969,60929,11968,12160,61249,11520,60865,60545,11328,58369,9408,9600,58689,9984,59329,59009,9792,8704,58049,58241,9024,57601,8640,8320,57409,40961,24768,24960,41281,25344,41921,41601,25152,26112,42689,42881,26432,42241,26048,25728,42049,27648,44225,44417,27968,44801,28608,28288,44609,43521,27328,27520,43841,26880,43457,43137,26688,30720,47297,47489,31040,47873,31680,31360,47681,48641,32448,32640,48961,32e3,48577,48257,31808,46081,29888,30080,46401,30464,47041,46721,30272,29184,45761,45953,29504,45313,29120,28800,45121,20480,37057,37249,20800,37633,21440,21120,37441,38401,22208,22400,38721,21760,38337,38017,21568,39937,23744,23936,40257,24320,40897,40577,24128,23040,39617,39809,23360,39169,22976,22656,38977,34817,18624,18816,35137,19200,35777,35457,19008,19968,36545,36737,20288,36097,19904,19584,35905,17408,33985,34177,17728,34561,18368,18048,34369,33281,17088,17280,33601,16640,33217,32897,16448];"undefined"!=typeof Int32Array&&(p=new Int32Array(p));var v=a("crc-16",(e,t=0)=>{let i=~~t;for(let t=0;t<e.length;t++)i=65535&(p[255&(i^e[t])]^i>>8);return i});let g=[0,4129,8258,12387,16516,20645,24774,28903,33032,37161,41290,45419,49548,53677,57806,61935,4657,528,12915,8786,21173,17044,29431,25302,37689,33560,45947,41818,54205,50076,62463,58334,9314,13379,1056,5121,25830,29895,17572,21637,42346,46411,34088,38153,58862,62927,50604,54669,13907,9842,5649,1584,30423,26358,22165,18100,46939,42874,38681,34616,63455,59390,55197,51132,18628,22757,26758,30887,2112,6241,10242,14371,51660,55789,59790,63919,35144,39273,43274,47403,23285,19156,31415,27286,6769,2640,14899,10770,56317,52188,64447,60318,39801,35672,47931,43802,27814,31879,19684,23749,11298,15363,3168,7233,60846,64911,52716,56781,44330,48395,36200,40265,32407,28342,24277,20212,15891,11826,7761,3696,65439,61374,57309,53244,48923,44858,40793,36728,37256,33193,45514,41451,53516,49453,61774,57711,4224,161,12482,8419,20484,16421,28742,24679,33721,37784,41979,46042,49981,54044,58239,62302,689,4752,8947,13010,16949,21012,25207,29270,46570,42443,38312,34185,62830,58703,54572,50445,13538,9411,5280,1153,29798,25671,21540,17413,42971,47098,34713,38840,59231,63358,50973,55100,9939,14066,1681,5808,26199,30326,17941,22068,55628,51565,63758,59695,39368,35305,47498,43435,22596,18533,30726,26663,6336,2273,14466,10403,52093,56156,60223,64286,35833,39896,43963,48026,19061,23124,27191,31254,2801,6864,10931,14994,64814,60687,56684,52557,48554,44427,40424,36297,31782,27655,23652,19525,15522,11395,7392,3265,61215,65342,53085,57212,44955,49082,36825,40952,28183,32310,20053,24180,11923,16050,3793,7920];"undefined"!=typeof Int32Array&&(g=new Int32Array(g));var y=a("ccitt",(e,t)=>{let i=void 0!==t?~~t:65535;for(let t=0;t<e.length;t++)i=65535&(g[255&(i>>8^e[t])]^i<<8);return i});let _=[0,49345,49537,320,49921,960,640,49729,50689,1728,1920,51009,1280,50625,50305,1088,52225,3264,3456,52545,3840,53185,52865,3648,2560,51905,52097,2880,51457,2496,2176,51265,55297,6336,6528,55617,6912,56257,55937,6720,7680,57025,57217,8e3,56577,7616,7296,56385,5120,54465,54657,5440,55041,6080,5760,54849,53761,4800,4992,54081,4352,53697,53377,4160,61441,12480,12672,61761,13056,62401,62081,12864,13824,63169,63361,14144,62721,13760,13440,62529,15360,64705,64897,15680,65281,16320,16e3,65089,64001,15040,15232,64321,14592,63937,63617,14400,10240,59585,59777,10560,60161,11200,10880,59969,60929,11968,12160,61249,11520,60865,60545,11328,58369,9408,9600,58689,9984,59329,59009,9792,8704,58049,58241,9024,57601,8640,8320,57409,40961,24768,24960,41281,25344,41921,41601,25152,26112,42689,42881,26432,42241,26048,25728,42049,27648,44225,44417,27968,44801,28608,28288,44609,43521,27328,27520,43841,26880,43457,43137,26688,30720,47297,47489,31040,47873,31680,31360,47681,48641,32448,32640,48961,32e3,48577,48257,31808,46081,29888,30080,46401,30464,47041,46721,30272,29184,45761,45953,29504,45313,29120,28800,45121,20480,37057,37249,20800,37633,21440,21120,37441,38401,22208,22400,38721,21760,38337,38017,21568,39937,23744,23936,40257,24320,40897,40577,24128,23040,39617,39809,23360,39169,22976,22656,38977,34817,18624,18816,35137,19200,35777,35457,19008,19968,36545,36737,20288,36097,19904,19584,35905,17408,33985,34177,17728,34561,18368,18048,34369,33281,17088,17280,33601,16640,33217,32897,16448];"undefined"!=typeof Int32Array&&(_=new Int32Array(_));var m=a("crc-16-modbus",(e,t)=>{let i=void 0!==t?~~t:65535;for(let t=0;t<e.length;t++)i=65535&(_[255&(i^e[t])]^i>>8);return i});var D=a("xmodem",(e,t)=>{let i=void 0!==t?~~t:0;for(let t=0;t<e.length;t++){let n=i>>>8&255;n^=255&e[t],n^=n>>>4,i=i<<8&65535,i^=n,n=n<<5&65535,i^=n,n=n<<7&65535,i^=n}return i});let b=[0,4489,8978,12955,17956,22445,25910,29887,35912,40385,44890,48851,51820,56293,59774,63735,4225,264,13203,8730,22181,18220,30135,25662,40137,36160,49115,44626,56045,52068,63999,59510,8450,12427,528,5017,26406,30383,17460,21949,44362,48323,36440,40913,60270,64231,51324,55797,12675,8202,4753,792,30631,26158,21685,17724,48587,44098,40665,36688,64495,60006,55549,51572,16900,21389,24854,28831,1056,5545,10034,14011,52812,57285,60766,64727,34920,39393,43898,47859,21125,17164,29079,24606,5281,1320,14259,9786,57037,53060,64991,60502,39145,35168,48123,43634,25350,29327,16404,20893,9506,13483,1584,6073,61262,65223,52316,56789,43370,47331,35448,39921,29575,25102,20629,16668,13731,9258,5809,1848,65487,60998,56541,52564,47595,43106,39673,35696,33800,38273,42778,46739,49708,54181,57662,61623,2112,6601,11090,15067,20068,24557,28022,31999,38025,34048,47003,42514,53933,49956,61887,57398,6337,2376,15315,10842,24293,20332,32247,27774,42250,46211,34328,38801,58158,62119,49212,53685,10562,14539,2640,7129,28518,32495,19572,24061,46475,41986,38553,34576,62383,57894,53437,49460,14787,10314,6865,2904,32743,28270,23797,19836,50700,55173,58654,62615,32808,37281,41786,45747,19012,23501,26966,30943,3168,7657,12146,16123,54925,50948,62879,58390,37033,33056,46011,41522,23237,19276,31191,26718,7393,3432,16371,11898,59150,63111,50204,54677,41258,45219,33336,37809,27462,31439,18516,23005,11618,15595,3696,8185,63375,58886,54429,50452,45483,40994,37561,33584,31687,27214,22741,18780,15843,11370,7921,3960];"undefined"!=typeof Int32Array&&(b=new Int32Array(b));var S=a("kermit",(e,t)=>{let i=void 0!==t?~~t:0;for(let t=0;t<e.length;t++)i=65535&(b[255&(i^e[t])]^i>>8);return i});let w=[0,8801531,9098509,825846,9692897,1419802,1651692,10452759,10584377,2608578,2839604,11344079,3303384,11807523,12104405,4128302,12930697,4391538,5217156,13227903,5679208,13690003,14450021,5910942,6606768,14844747,15604413,6837830,16197969,7431594,8256604,16494759,840169,9084178,8783076,18463,10434312,1670131,1434117,9678590,11358416,2825259,2590173,10602790,4109873,12122826,11821884,3289031,13213536,5231515,4409965,12912278,5929345,14431610,13675660,5693559,6823513,15618722,14863188,6588335,16513208,8238147,7417269,16212302,1680338,10481449,9664223,1391140,9061683,788936,36926,8838341,12067563,4091408,3340262,11844381,2868234,11372785,10555655,2579964,14478683,5939616,5650518,13661357,5180346,13190977,12967607,4428364,8219746,16457881,16234863,7468436,15633027,6866552,6578062,14816117,1405499,9649856,10463030,1698765,8819930,55329,803287,9047340,11858690,3325945,4072975,12086004,2561507,10574104,11387118,2853909,13647026,5664841,5958079,14460228,4446803,12949160,13176670,5194661,7454091,16249200,16476294,8201341,14834538,6559633,6852199,15647388,3360676,11864927,12161705,4185682,10527045,2551230,2782280,11286707,9619101,1346150,1577872,10379115,73852,8875143,9172337,899466,16124205,7357910,8182816,16421083,6680524,14918455,15678145,6911546,5736468,13747439,14507289,5968354,12873461,4334094,5159928,13170435,4167245,12180150,11879232,3346363,11301036,2767959,2532769,10545498,10360692,1596303,1360505,9604738,913813,9157998,8856728,92259,16439492,8164415,7343561,16138546,6897189,15692510,14936872,6662099,5986813,14488838,13733104,5750795,13156124,5174247,4352529,12855018,2810998,11315341,10498427,2522496,12124823,4148844,3397530,11901793,9135439,862644,110658,8912057,1606574,10407765,9590435,1317464,15706879,6940164,6651890,14889737,8145950,16384229,16161043,7394792,5123014,13133629,12910283,4370992,14535975,5997020,5707818,13718737,2504095,10516836,11329682,2796649,11916158,3383173,4130419,12143240,8893606,129117,876971,9121104,1331783,9576124,10389322,1625009,14908182,6633453,6925851,15721184,7380471,16175372,16402682,8127489,4389423,12891860,13119266,5137369,13704398,5722165,6015427,14517560];"undefined"!=typeof Int32Array&&(w=new Int32Array(w));var I=a("crc-24",(e,t)=>{let i=void 0!==t?~~t:11994318;for(let t=0;t<e.length;t++)i=16777215&(w[255&(i>>16^e[t])]^i<<8);return i});let A=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117];"undefined"!=typeof Int32Array&&(A=new Int32Array(A));var B=a("crc-32",(e,t)=>{let i=0===t?0:-1^~~t;for(let t=0;t<e.length;t++)i=A[255&(i^e[t])]^i>>>8;return-1^i});let k=[0,79764919,159529838,222504665,319059676,398814059,445009330,507990021,638119352,583659535,797628118,726387553,890018660,835552979,1015980042,944750013,1276238704,1221641927,1167319070,1095957929,1595256236,1540665371,1452775106,1381403509,1780037320,1859660671,1671105958,1733955601,2031960084,2111593891,1889500026,1952343757,2552477408,2632100695,2443283854,2506133561,2334638140,2414271883,2191915858,2254759653,3190512472,3135915759,3081330742,3009969537,2905550212,2850959411,2762807018,2691435357,3560074640,3505614887,3719321342,3648080713,3342211916,3287746299,3467911202,3396681109,4063920168,4143685023,4223187782,4286162673,3779000052,3858754371,3904687514,3967668269,881225847,809987520,1023691545,969234094,662832811,591600412,771767749,717299826,311336399,374308984,453813921,533576470,25881363,88864420,134795389,214552010,2023205639,2086057648,1897238633,1976864222,1804852699,1867694188,1645340341,1724971778,1587496639,1516133128,1461550545,1406951526,1302016099,1230646740,1142491917,1087903418,2896545431,2825181984,2770861561,2716262478,3215044683,3143675388,3055782693,3001194130,2326604591,2389456536,2200899649,2280525302,2578013683,2640855108,2418763421,2498394922,3769900519,3832873040,3912640137,3992402750,4088425275,4151408268,4197601365,4277358050,3334271071,3263032808,3476998961,3422541446,3585640067,3514407732,3694837229,3640369242,1762451694,1842216281,1619975040,1682949687,2047383090,2127137669,1938468188,2001449195,1325665622,1271206113,1183200824,1111960463,1543535498,1489069629,1434599652,1363369299,622672798,568075817,748617968,677256519,907627842,853037301,1067152940,995781531,51762726,131386257,177728840,240578815,269590778,349224269,429104020,491947555,4046411278,4126034873,4172115296,4234965207,3794477266,3874110821,3953728444,4016571915,3609705398,3555108353,3735388376,3664026991,3290680682,3236090077,3449943556,3378572211,3174993278,3120533705,3032266256,2961025959,2923101090,2868635157,2813903052,2742672763,2604032198,2683796849,2461293480,2524268063,2284983834,2364738477,2175806836,2238787779,1569362073,1498123566,1409854455,1355396672,1317987909,1246755826,1192025387,1137557660,2072149281,2135122070,1912620623,1992383480,1753615357,1816598090,1627664531,1707420964,295390185,358241886,404320391,483945776,43990325,106832002,186451547,266083308,932423249,861060070,1041341759,986742920,613929101,542559546,756411363,701822548,3316196985,3244833742,3425377559,3370778784,3601682597,3530312978,3744426955,3689838204,3819031489,3881883254,3928223919,4007849240,4037393693,4100235434,4180117107,4259748804,2310601993,2373574846,2151335527,2231098320,2596047829,2659030626,2470359227,2550115596,2947551409,2876312838,2788305887,2733848168,3165939309,3094707162,3040238851,2985771188];"undefined"!=typeof Int32Array&&(k=new Int32Array(k));var E=a("crc-32-mpeg",(e,t)=>{let i=void 0!==t?~~t:4294967295;for(let t=0;t<e.length;t++)i=k[255&(i>>24^e[t])]^i<<8;return i});let C=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117];"undefined"!=typeof Int32Array&&(C=new Int32Array(C));var T=a("jam",(e,t=-1)=>{let i=0===t?0:~~t;for(let t=0;t<e.length;t++)i=C[255&(i^e[t])]^i>>>8;return i});t.default={crc1:o,crc8:u,crc81wire:l,crc8dvbs2:f,crc16:v,crc16ccitt:y,crc16modbus:m,crc16xmodem:D,crc16kermit:S,crc24:I,crc32:B,crc32mpeg2:E,crcjam:T}},function(e,t,i){"use strict";(function(e){
2
2
  /*!
3
3
  * The buffer module from node.js, for the browser.
4
4
  *
5
5
  * @author Feross Aboukhadijeh <http://feross.org>
6
6
  * @license MIT
7
7
  */
8
- var n=i(35),s=i(36),r=i(37);function a(){return c.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function o(e,t){if(a()<t)throw new RangeError("Invalid typed array length");return c.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=c.prototype:(null===e&&(e=new c(t)),e.length=t),e}function c(e,t,i){if(!(c.TYPED_ARRAY_SUPPORT||this instanceof c))return new c(e,t,i);if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return d(this,e)}return u(this,e,t,i)}function u(e,t,i,n){if("number"==typeof t)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer?function(e,t,i,n){if(t.byteLength,i<0||t.byteLength<i)throw new RangeError("'offset' is out of bounds");if(t.byteLength<i+(n||0))throw new RangeError("'length' is out of bounds");t=void 0===i&&void 0===n?new Uint8Array(t):void 0===n?new Uint8Array(t,i):new Uint8Array(t,i,n);c.TYPED_ARRAY_SUPPORT?(e=t).__proto__=c.prototype:e=h(e,t);return e}(e,t,i,n):"string"==typeof t?function(e,t,i){"string"==typeof i&&""!==i||(i="utf8");if(!c.isEncoding(i))throw new TypeError('"encoding" must be a valid string encoding');var n=0|p(t,i),s=(e=o(e,n)).write(t,i);s!==n&&(e=e.slice(0,s));return e}(e,t,i):function(e,t){if(c.isBuffer(t)){var i=0|f(t.length);return 0===(e=o(e,i)).length||t.copy(e,0,0,i),e}if(t){if("undefined"!=typeof ArrayBuffer&&t.buffer instanceof ArrayBuffer||"length"in t)return"number"!=typeof t.length||(n=t.length)!=n?o(e,0):h(e,t);if("Buffer"===t.type&&r(t.data))return h(e,t.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function l(e){if("number"!=typeof e)throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function d(e,t){if(l(t),e=o(e,t<0?0:0|f(t)),!c.TYPED_ARRAY_SUPPORT)for(var i=0;i<t;++i)e[i]=0;return e}function h(e,t){var i=t.length<0?0:0|f(t.length);e=o(e,i);for(var n=0;n<i;n+=1)e[n]=255&t[n];return e}function f(e){if(e>=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|e}function p(e,t){if(c.isBuffer(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var i=e.length;if(0===i)return 0;for(var n=!1;;)switch(t){case"ascii":case"latin1":case"binary":return i;case"utf8":case"utf-8":case void 0:return H(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*i;case"hex":return i>>>1;case"base64":return G(e).length;default:if(n)return H(e).length;t=(""+t).toLowerCase(),n=!0}}function v(e,t,i){var n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return"";if((i>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return C(this,t,i);case"utf8":case"utf-8":return B(this,t,i);case"ascii":return k(this,t,i);case"latin1":case"binary":return E(this,t,i);case"base64":return A(this,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,t,i);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function g(e,t,i){var n=e[t];e[t]=e[i],e[i]=n}function y(e,t,i,n,s){if(0===e.length)return-1;if("string"==typeof i?(n=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),i=+i,isNaN(i)&&(i=s?0:e.length-1),i<0&&(i=e.length+i),i>=e.length){if(s)return-1;i=e.length-1}else if(i<0){if(!s)return-1;i=0}if("string"==typeof t&&(t=c.from(t,n)),c.isBuffer(t))return 0===t.length?-1:_(e,t,i,n,s);if("number"==typeof t)return t&=255,c.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?s?Uint8Array.prototype.indexOf.call(e,t,i):Uint8Array.prototype.lastIndexOf.call(e,t,i):_(e,[t],i,n,s);throw new TypeError("val must be string, number or Buffer")}function _(e,t,i,n,s){var r,a=1,o=e.length,c=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;a=2,o/=2,c/=2,i/=2}function u(e,t){return 1===a?e[t]:e.readUInt16BE(t*a)}if(s){var l=-1;for(r=i;r<o;r++)if(u(e,r)===u(t,-1===l?0:r-l)){if(-1===l&&(l=r),r-l+1===c)return l*a}else-1!==l&&(r-=r-l),l=-1}else for(i+c>o&&(i=o-c),r=i;r>=0;r--){for(var d=!0,h=0;h<c;h++)if(u(e,r+h)!==u(t,h)){d=!1;break}if(d)return r}return-1}function m(e,t,i,n){i=Number(i)||0;var s=e.length-i;n?(n=Number(n))>s&&(n=s):n=s;var r=t.length;if(r%2!=0)throw new TypeError("Invalid hex string");n>r/2&&(n=r/2);for(var a=0;a<n;++a){var o=parseInt(t.substr(2*a,2),16);if(isNaN(o))return a;e[i+a]=o}return a}function D(e,t,i,n){return j(H(t,e.length-i),e,i,n)}function b(e,t,i,n){return j(function(e){for(var t=[],i=0;i<e.length;++i)t.push(255&e.charCodeAt(i));return t}(t),e,i,n)}function S(e,t,i,n){return b(e,t,i,n)}function w(e,t,i,n){return j(G(t),e,i,n)}function I(e,t,i,n){return j(function(e,t){for(var i,n,s,r=[],a=0;a<e.length&&!((t-=2)<0);++a)i=e.charCodeAt(a),n=i>>8,s=i%256,r.push(s),r.push(n);return r}(t,e.length-i),e,i,n)}function A(e,t,i){return 0===t&&i===e.length?n.fromByteArray(e):n.fromByteArray(e.slice(t,i))}function B(e,t,i){i=Math.min(e.length,i);for(var n=[],s=t;s<i;){var r,a,o,c,u=e[s],l=null,d=u>239?4:u>223?3:u>191?2:1;if(s+d<=i)switch(d){case 1:u<128&&(l=u);break;case 2:128==(192&(r=e[s+1]))&&(c=(31&u)<<6|63&r)>127&&(l=c);break;case 3:r=e[s+1],a=e[s+2],128==(192&r)&&128==(192&a)&&(c=(15&u)<<12|(63&r)<<6|63&a)>2047&&(c<55296||c>57343)&&(l=c);break;case 4:r=e[s+1],a=e[s+2],o=e[s+3],128==(192&r)&&128==(192&a)&&128==(192&o)&&(c=(15&u)<<18|(63&r)<<12|(63&a)<<6|63&o)>65535&&c<1114112&&(l=c)}null===l?(l=65533,d=1):l>65535&&(l-=65536,n.push(l>>>10&1023|55296),l=56320|1023&l),n.push(l),s+=d}return function(e){var t=e.length;if(t<=4096)return String.fromCharCode.apply(String,e);var i="",n=0;for(;n<t;)i+=String.fromCharCode.apply(String,e.slice(n,n+=4096));return i}(n)}t.Buffer=c,t.SlowBuffer=function(e){+e!=e&&(e=0);return c.alloc(+e)},t.INSPECT_MAX_BYTES=50,c.TYPED_ARRAY_SUPPORT=void 0!==e.TYPED_ARRAY_SUPPORT?e.TYPED_ARRAY_SUPPORT:function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()&&"function"==typeof e.subarray&&0===e.subarray(1,1).byteLength}catch(e){return!1}}(),t.kMaxLength=a(),c.poolSize=8192,c._augment=function(e){return e.__proto__=c.prototype,e},c.from=function(e,t,i){return u(null,e,t,i)},c.TYPED_ARRAY_SUPPORT&&(c.prototype.__proto__=Uint8Array.prototype,c.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&c[Symbol.species]===c&&Object.defineProperty(c,Symbol.species,{value:null,configurable:!0})),c.alloc=function(e,t,i){return function(e,t,i,n){return l(t),t<=0?o(e,t):void 0!==i?"string"==typeof n?o(e,t).fill(i,n):o(e,t).fill(i):o(e,t)}(null,e,t,i)},c.allocUnsafe=function(e){return d(null,e)},c.allocUnsafeSlow=function(e){return d(null,e)},c.isBuffer=function(e){return!(null==e||!e._isBuffer)},c.compare=function(e,t){if(!c.isBuffer(e)||!c.isBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var i=e.length,n=t.length,s=0,r=Math.min(i,n);s<r;++s)if(e[s]!==t[s]){i=e[s],n=t[s];break}return i<n?-1:n<i?1:0},c.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},c.concat=function(e,t){if(!r(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return c.alloc(0);var i;if(void 0===t)for(t=0,i=0;i<e.length;++i)t+=e[i].length;var n=c.allocUnsafe(t),s=0;for(i=0;i<e.length;++i){var a=e[i];if(!c.isBuffer(a))throw new TypeError('"list" argument must be an Array of Buffers');a.copy(n,s),s+=a.length}return n},c.byteLength=p,c.prototype._isBuffer=!0,c.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)g(this,t,t+1);return this},c.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)g(this,t,t+3),g(this,t+1,t+2);return this},c.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)g(this,t,t+7),g(this,t+1,t+6),g(this,t+2,t+5),g(this,t+3,t+4);return this},c.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?B(this,0,e):v.apply(this,arguments)},c.prototype.equals=function(e){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===c.compare(this,e)},c.prototype.inspect=function(){var e="",i=t.INSPECT_MAX_BYTES;return this.length>0&&(e=this.toString("hex",0,i).match(/.{2}/g).join(" "),this.length>i&&(e+=" ... ")),"<Buffer "+e+">"},c.prototype.compare=function(e,t,i,n,s){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===i&&(i=e?e.length:0),void 0===n&&(n=0),void 0===s&&(s=this.length),t<0||i>e.length||n<0||s>this.length)throw new RangeError("out of range index");if(n>=s&&t>=i)return 0;if(n>=s)return-1;if(t>=i)return 1;if(this===e)return 0;for(var r=(s>>>=0)-(n>>>=0),a=(i>>>=0)-(t>>>=0),o=Math.min(r,a),u=this.slice(n,s),l=e.slice(t,i),d=0;d<o;++d)if(u[d]!==l[d]){r=u[d],a=l[d];break}return r<a?-1:a<r?1:0},c.prototype.includes=function(e,t,i){return-1!==this.indexOf(e,t,i)},c.prototype.indexOf=function(e,t,i){return y(this,e,t,i,!0)},c.prototype.lastIndexOf=function(e,t,i){return y(this,e,t,i,!1)},c.prototype.write=function(e,t,i,n){if(void 0===t)n="utf8",i=this.length,t=0;else if(void 0===i&&"string"==typeof t)n=t,i=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t|=0,isFinite(i)?(i|=0,void 0===n&&(n="utf8")):(n=i,i=void 0)}var s=this.length-t;if((void 0===i||i>s)&&(i=s),e.length>0&&(i<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var r=!1;;)switch(n){case"hex":return m(this,e,t,i);case"utf8":case"utf-8":return D(this,e,t,i);case"ascii":return b(this,e,t,i);case"latin1":case"binary":return S(this,e,t,i);case"base64":return w(this,e,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return I(this,e,t,i);default:if(r)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),r=!0}},c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function k(e,t,i){var n="";i=Math.min(e.length,i);for(var s=t;s<i;++s)n+=String.fromCharCode(127&e[s]);return n}function E(e,t,i){var n="";i=Math.min(e.length,i);for(var s=t;s<i;++s)n+=String.fromCharCode(e[s]);return n}function C(e,t,i){var n=e.length;(!t||t<0)&&(t=0),(!i||i<0||i>n)&&(i=n);for(var s="",r=t;r<i;++r)s+=U(e[r]);return s}function T(e,t,i){for(var n=e.slice(t,i),s="",r=0;r<n.length;r+=2)s+=String.fromCharCode(n[r]+256*n[r+1]);return s}function O(e,t,i){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>i)throw new RangeError("Trying to access beyond buffer length")}function P(e,t,i,n,s,r){if(!c.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>s||t<r)throw new RangeError('"value" argument is out of bounds');if(i+n>e.length)throw new RangeError("Index out of range")}function L(e,t,i,n){t<0&&(t=65535+t+1);for(var s=0,r=Math.min(e.length-i,2);s<r;++s)e[i+s]=(t&255<<8*(n?s:1-s))>>>8*(n?s:1-s)}function M(e,t,i,n){t<0&&(t=4294967295+t+1);for(var s=0,r=Math.min(e.length-i,4);s<r;++s)e[i+s]=t>>>8*(n?s:3-s)&255}function x(e,t,i,n,s,r){if(i+n>e.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function N(e,t,i,n,r){return r||x(e,0,i,4),s.write(e,t,i,n,23,4),i+4}function R(e,t,i,n,r){return r||x(e,0,i,8),s.write(e,t,i,n,52,8),i+8}c.prototype.slice=function(e,t){var i,n=this.length;if((e=~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),(t=void 0===t?n:~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),t<e&&(t=e),c.TYPED_ARRAY_SUPPORT)(i=this.subarray(e,t)).__proto__=c.prototype;else{var s=t-e;i=new c(s,void 0);for(var r=0;r<s;++r)i[r]=this[r+e]}return i},c.prototype.readUIntLE=function(e,t,i){e|=0,t|=0,i||O(e,t,this.length);for(var n=this[e],s=1,r=0;++r<t&&(s*=256);)n+=this[e+r]*s;return n},c.prototype.readUIntBE=function(e,t,i){e|=0,t|=0,i||O(e,t,this.length);for(var n=this[e+--t],s=1;t>0&&(s*=256);)n+=this[e+--t]*s;return n},c.prototype.readUInt8=function(e,t){return t||O(e,1,this.length),this[e]},c.prototype.readUInt16LE=function(e,t){return t||O(e,2,this.length),this[e]|this[e+1]<<8},c.prototype.readUInt16BE=function(e,t){return t||O(e,2,this.length),this[e]<<8|this[e+1]},c.prototype.readUInt32LE=function(e,t){return t||O(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},c.prototype.readUInt32BE=function(e,t){return t||O(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},c.prototype.readIntLE=function(e,t,i){e|=0,t|=0,i||O(e,t,this.length);for(var n=this[e],s=1,r=0;++r<t&&(s*=256);)n+=this[e+r]*s;return n>=(s*=128)&&(n-=Math.pow(2,8*t)),n},c.prototype.readIntBE=function(e,t,i){e|=0,t|=0,i||O(e,t,this.length);for(var n=t,s=1,r=this[e+--n];n>0&&(s*=256);)r+=this[e+--n]*s;return r>=(s*=128)&&(r-=Math.pow(2,8*t)),r},c.prototype.readInt8=function(e,t){return t||O(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},c.prototype.readInt16LE=function(e,t){t||O(e,2,this.length);var i=this[e]|this[e+1]<<8;return 32768&i?4294901760|i:i},c.prototype.readInt16BE=function(e,t){t||O(e,2,this.length);var i=this[e+1]|this[e]<<8;return 32768&i?4294901760|i:i},c.prototype.readInt32LE=function(e,t){return t||O(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},c.prototype.readInt32BE=function(e,t){return t||O(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},c.prototype.readFloatLE=function(e,t){return t||O(e,4,this.length),s.read(this,e,!0,23,4)},c.prototype.readFloatBE=function(e,t){return t||O(e,4,this.length),s.read(this,e,!1,23,4)},c.prototype.readDoubleLE=function(e,t){return t||O(e,8,this.length),s.read(this,e,!0,52,8)},c.prototype.readDoubleBE=function(e,t){return t||O(e,8,this.length),s.read(this,e,!1,52,8)},c.prototype.writeUIntLE=function(e,t,i,n){(e=+e,t|=0,i|=0,n)||P(this,e,t,i,Math.pow(2,8*i)-1,0);var s=1,r=0;for(this[t]=255&e;++r<i&&(s*=256);)this[t+r]=e/s&255;return t+i},c.prototype.writeUIntBE=function(e,t,i,n){(e=+e,t|=0,i|=0,n)||P(this,e,t,i,Math.pow(2,8*i)-1,0);var s=i-1,r=1;for(this[t+s]=255&e;--s>=0&&(r*=256);)this[t+s]=e/r&255;return t+i},c.prototype.writeUInt8=function(e,t,i){return e=+e,t|=0,i||P(this,e,t,1,255,0),c.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},c.prototype.writeUInt16LE=function(e,t,i){return e=+e,t|=0,i||P(this,e,t,2,65535,0),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):L(this,e,t,!0),t+2},c.prototype.writeUInt16BE=function(e,t,i){return e=+e,t|=0,i||P(this,e,t,2,65535,0),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):L(this,e,t,!1),t+2},c.prototype.writeUInt32LE=function(e,t,i){return e=+e,t|=0,i||P(this,e,t,4,4294967295,0),c.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):M(this,e,t,!0),t+4},c.prototype.writeUInt32BE=function(e,t,i){return e=+e,t|=0,i||P(this,e,t,4,4294967295,0),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):M(this,e,t,!1),t+4},c.prototype.writeIntLE=function(e,t,i,n){if(e=+e,t|=0,!n){var s=Math.pow(2,8*i-1);P(this,e,t,i,s-1,-s)}var r=0,a=1,o=0;for(this[t]=255&e;++r<i&&(a*=256);)e<0&&0===o&&0!==this[t+r-1]&&(o=1),this[t+r]=(e/a>>0)-o&255;return t+i},c.prototype.writeIntBE=function(e,t,i,n){if(e=+e,t|=0,!n){var s=Math.pow(2,8*i-1);P(this,e,t,i,s-1,-s)}var r=i-1,a=1,o=0;for(this[t+r]=255&e;--r>=0&&(a*=256);)e<0&&0===o&&0!==this[t+r+1]&&(o=1),this[t+r]=(e/a>>0)-o&255;return t+i},c.prototype.writeInt8=function(e,t,i){return e=+e,t|=0,i||P(this,e,t,1,127,-128),c.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},c.prototype.writeInt16LE=function(e,t,i){return e=+e,t|=0,i||P(this,e,t,2,32767,-32768),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):L(this,e,t,!0),t+2},c.prototype.writeInt16BE=function(e,t,i){return e=+e,t|=0,i||P(this,e,t,2,32767,-32768),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):L(this,e,t,!1),t+2},c.prototype.writeInt32LE=function(e,t,i){return e=+e,t|=0,i||P(this,e,t,4,2147483647,-2147483648),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):M(this,e,t,!0),t+4},c.prototype.writeInt32BE=function(e,t,i){return e=+e,t|=0,i||P(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):M(this,e,t,!1),t+4},c.prototype.writeFloatLE=function(e,t,i){return N(this,e,t,!0,i)},c.prototype.writeFloatBE=function(e,t,i){return N(this,e,t,!1,i)},c.prototype.writeDoubleLE=function(e,t,i){return R(this,e,t,!0,i)},c.prototype.writeDoubleBE=function(e,t,i){return R(this,e,t,!1,i)},c.prototype.copy=function(e,t,i,n){if(i||(i=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<i&&(n=i),n===i)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(i<0||i>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-i&&(n=e.length-t+i);var s,r=n-i;if(this===e&&i<t&&t<n)for(s=r-1;s>=0;--s)e[s+t]=this[s+i];else if(r<1e3||!c.TYPED_ARRAY_SUPPORT)for(s=0;s<r;++s)e[s+t]=this[s+i];else Uint8Array.prototype.set.call(e,this.subarray(i,i+r),t);return r},c.prototype.fill=function(e,t,i,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=0,i=this.length):"string"==typeof i&&(n=i,i=this.length),1===e.length){var s=e.charCodeAt(0);s<256&&(e=s)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!c.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<i)throw new RangeError("Out of range index");if(i<=t)return this;var r;if(t>>>=0,i=void 0===i?this.length:i>>>0,e||(e=0),"number"==typeof e)for(r=t;r<i;++r)this[r]=e;else{var a=c.isBuffer(e)?e:H(new c(e,n).toString()),o=a.length;for(r=0;r<i-t;++r)this[r+t]=a[r%o]}return this};var K=/[^+\/0-9A-Za-z-_]/g;function U(e){return e<16?"0"+e.toString(16):e.toString(16)}function H(e,t){var i;t=t||1/0;for(var n=e.length,s=null,r=[],a=0;a<n;++a){if((i=e.charCodeAt(a))>55295&&i<57344){if(!s){if(i>56319){(t-=3)>-1&&r.push(239,191,189);continue}if(a+1===n){(t-=3)>-1&&r.push(239,191,189);continue}s=i;continue}if(i<56320){(t-=3)>-1&&r.push(239,191,189),s=i;continue}i=65536+(s-55296<<10|i-56320)}else s&&(t-=3)>-1&&r.push(239,191,189);if(s=null,i<128){if((t-=1)<0)break;r.push(i)}else if(i<2048){if((t-=2)<0)break;r.push(i>>6|192,63&i|128)}else if(i<65536){if((t-=3)<0)break;r.push(i>>12|224,i>>6&63|128,63&i|128)}else{if(!(i<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;r.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128)}}return r}function G(e){return n.toByteArray(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(K,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function j(e,t,i,n){for(var s=0;s<n&&!(s+i>=t.length||s>=e.length);++s)t[s+i]=e[s];return s}}).call(this,i(18))},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}),i(32);const s=n(i(33)),r=n(i(4));t.errorCode=r.default;const a=i(17);t.BleHandle=a.BleHandle,t.default=s.default},function(e,t){},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=i(16),a=i(17),o=s(i(44)),c=s(i(45)),u=s(i(51)),l=s(i(3)),d=s(i(4)),h=i(52),f=i(26),p=i(8),v=s(i(10)),g=i(11),y=i(1),_=i(53),m=s(i(0)),D=i(55),b=i(56),S=s(i(5)),w=s(i(57)),I=s(i(58)),A=s(i(59)),B=s(i(60)),k=I.default.version;class E{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:a,offlineThreshold:o})=>{this.productInfo=i,r.setGlobalData("appID",e),r.setGlobalData("appSecret",t),r.setGlobalData("productInfo",i),r.setGlobalData("token",s),r.setGlobalData("uid",a),this.setDomain(n),this.offlineThreshold=o,l.default.debug(`init sdk success, current version: ${E.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 g.unpack(y.hexStrint2byte(t),i.productKey);(null==e?void 0:e.kvData)&&this.listenerMap.GizDeviceAttrsNotifications&&this.listenerMap.GizDeviceAttrsNotifications.map(t=>{t({device:i,data:null==e?void 0:e.kvData})})}})),this.handleBleDeviceData=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>t.bleDeviceID===e.deviceId);if(i){const s=y.hexStrint2byte(t);switch(new m.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);b.uploadP0({device:i,data:[{raw:t,created_at:n}],productSecret:e.productSecret}).then(e=>{l.default.debug("设备上报数据:timestemp",new Date(1e3*n).toLocaleString(),e)})}}const e=yield g.unpack(y.hexStrint2byte(t),i.productKey);(null==e?void 0:e.kvData)&&this.listenerMap.GizDeviceAttrsNotifications&&this.listenerMap.GizDeviceAttrsNotifications.map(t=>{t({device:i,data:null==e?void 0:e.kvData})});break}case"0062":{const t=new A.default(s);l.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*(){l.default.debug("代理重置结果",t),t.success&&t.data.successDevices.length>0&&(l.default.debug("重置成功,回写数据"),yield this.bleHandle.write(e.deviceId,p.numberArray2Uint8Array(B.default.pack(0)).buffer))})));break}case"0064":break;case"0052":{const t=new D.RequestSync(s);if(l.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}),l.default.debug("查询第一条离线数据"),yield this.bleHandle.write(e.deviceId,p.numberArray2Uint8Array(D.SyncPackage.pack(0)).buffer)):(l.default.debug("设备返回状态为1,同步失败"),this.syncDataCallBack({event:"SYNC_FAIL"}));break}case"0054":{if(!this.syncDataCallBack)break;l.default.debug("设备上报离线数据");const t=new D.SyncPackage(s),i=D.DeletePackage.pack(t.id);l.default.debug("设备上报离线数据:payload",t.payload);try{l.default.debug("设备上报离线数据:timestemp",new Date(1e3*t.timestemp).toLocaleString())}catch(e){}const n=this.productInfo.find(e=>e.productKey===this.syncDevice.productKey);if(n){const e=yield b.uploadP0({device:this.syncDevice,data:[{raw:y.arrayToString(t.payload),created_at:t.timestemp}],productSecret:n.productSecret});l.default.debug("上传离线数据结果",e)}this.syncCurrnetNum+=1,this.syncDataCallBack({event:"SYNC_PROGRESS",totalNum:this.syncTotalNum,currentNum:this.syncCurrnetNum}),l.default.debug("通知设备删除:",t.id),yield this.bleHandle.write(e.deviceId,p.numberArray2Uint8Array(i).buffer),yield S.default(100),t.id<this.syncTotalNum-1?(l.default.debug("查询新数据:",t.id+1),yield this.bleHandle.write(e.deviceId,p.numberArray2Uint8Array(D.SyncPackage.pack(t.id+1)).buffer)):(l.default.debug("send cancel sync to device"),this.bleHandle.write(e.deviceId,p.numberArray2Uint8Array(D.CancelSync.pack()).buffer),this.syncDataCallBack({event:"SYNC_END"}),this.cleanSyncDeviceData());break}case"0058":{if(!this.syncDataCallBack)break;const e=new D.CancelSync(s);l.default.debug("设备上报停止同步 state:",e.state),0===e.state?this.syncDataCallBack({event:"SYNC_END"}):this.syncDataCallBack({event:"SYNC_FAIL"}),this.cleanSyncDeviceData();break}}}})),this.handleSocketDeviceData=e=>n(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>t.did===e.did);if(t){if(e.attrs&&null!=e.attrs.is_online){const i=e.attrs.is_online;this.setDeviceMeta(t,"isOnline",i)}this.listenerMap.GizDeviceAttrsNotifications&&(e.attrs&&(e.attrs=yield g.formatEnum(e.attrs,t.productKey,"int")),this.listenerMap.GizDeviceAttrsNotifications.map(i=>{i(Object.assign({device:t},"attrs"in e?{data:e.attrs}:{raw:e.raw}))}))}})),this.handleSocketStatus=(e,t)=>{const i=this.allDevices.filter(t=>e.includes(t.did)&&"WAN"===t.connectType);l.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){l.default.error("init lan error",e)}},this.startAutoScan=e=>{this.keepScanTimer||(this.keepScanTimer=setInterval(()=>n(this,void 0,void 0,(function*(){this.bleHandle.startScan(e=>{this.bleDevices=e},-1,e)})),9e3),this.bleHandle.startScan(e=>{this.bleDevices=e},-1,e))},this.stopAutoScan=()=>{this.keepScanTimer&&clearInterval(this.keepScanTimer),this.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.initBle=()=>n(this,void 0,void 0,(function*(){const e=yield this.bleHandle.checkPermission();return e.success?(this.bleHandle.addEventListener("GizBleDeviceData",this.handleBleDeviceData),this.bleHandle.addEventListener("GizBleDeviceList",this.handleBleDevices),this.bleHandle.addEventListener("GizBleError",this.handleBleError),l.default.debug("init BLE succcess",e),{success:!0}):(l.default.error("init BLE Error",new Error(JSON.stringify(e))),{success:!1,err:d.default.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON})})),this.scanBleDevice=(e,t)=>n(this,void 0,void 0,(function*(){return this.bleHandle.scanList=[],{success:!0,data:(yield this.bleHandle.startScan(e=>{this.bleDevices=e},e,t)).scanList}})),this.write=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>p.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};if("NONE"!==i.connectType){const{data:e,raw:n}=yield g.pack(t,i.productKey);switch(i.connectType){case"BLE_BROADCAST":return yield this.bleHandle.writeBoradcast(i.bleDeviceID,n.cmd);case"BLE":return e?yield this.bleHandle.write(i.bleDeviceID,p.numberArray2Uint8Array(e).buffer):{success:!1};case"WAN":{const e=yield g.formatEnum(t,i.productKey,"string");return this.socketHandle.writeData(i,e)}case"LAN":return this.lanHandle.write(i,p.numberArray2Uint8Array(e).buffer)}}return{success:!1}})),this.writeRaw=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>p.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};if("NONE"!==i.connectType)switch(i.connectType){case"BLE_BROADCAST":return yield this.bleHandle.writeBoradcast(i.bleDeviceID,t);case"BLE":return t?yield this.bleHandle.write(i.bleDeviceID,p.numberArray2Uint8Array(t).buffer):{success:!1};case"WAN":return this.socketHandle.send(i.did,t);case"LAN":return this.lanHandle.write(i,p.numberArray2Uint8Array(t).buffer)}return{success:!1}})),this.setDeviceTimeStamp=e=>n(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>p.isSameDevice(t,e));if(!t)return{success:!1,message:"target is undefind"};const i=w.default.pack();switch(t.connectType){case"BLE":return this.bleHandle.write(e.bleDeviceID,p.numberArray2Uint8Array(i).buffer)}return{success:!1,message:"the connectType not support set timestamp"}})),this.syncDeviceData=(e,t=(()=>{}))=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>p.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};if(!i.isBind)return{success:!1,message:"Only the bound devices are supported"};if(this.syncDevice)return{success:!1,message:"Synchronizing"};switch(this.syncDevice=Object.assign({},i),i.connectType){case"BLE":{l.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 l.default.debug("sent RequestSync data"),this.bleHandle.write(e.bleDeviceID,p.numberArray2Uint8Array(i).buffer)}}return{success:!1,message:"the connectType not support sync data"}})),this.queryNeedSyncDataLength=e=>n(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>p.isSameDevice(t,e));if(!t)return{success:!1,message:"target is undefind"};if(!t.isBind)return{success:!1,message:"Only the bound devices are supported"};switch(t.connectType){case"BLE":{const i=D.RequestSync.pack();return this.syncDevice=Object.assign({},t),l.default.debug("sent RequestSync data len"),this.bleHandle.write(e.bleDeviceID,p.numberArray2Uint8Array(i).buffer),new Promise(e=>{this.syncDataLengthCallback=e,setTimeout(()=>{try{e({success:!1,message:"timeout"})}catch(e){}},3e3)})}}return{success:!1,message:"the connectType not support sync data"}})),this.cancelSyncDeviceData=()=>n(this,void 0,void 0,(function*(){this.cleanSyncDeviceData()})),this.cleanSyncDeviceData=()=>{this.syncDataCallBack&&(this.syncDataCallBack({event:"SYNC_CANCEL"}),this.syncDataCallBack=null),this.syncCurrnetNum=0,this.syncTotalNum=0,this.syncDevice=null,this.syncDataTimoutTimer&&clearTimeout(this.syncDataTimoutTimer)},this.getProductConfig=e=>n(this,void 0,void 0,(function*(){const t=yield v.default.getConfigFile(e);return t?{success:!0,data:t}:{success:!1}})),this.stopScanBleDevice=()=>{this.bleHandle.stopScan()},this.login=e=>n(this,void 0,void 0,(function*(){var t,i;const n=yield h.AnonymousLogin({uid:e});return n.success&&(r.setGlobalData("token",null===(t=n.data)||void 0===t?void 0:t.token),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=>p.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};switch(i.connectType){case"BLE":return yield this.bleHandle.getDeviceStatus(i.bleDeviceID,i.productKey,i.rootDeviceId,t);case"WAN":return this.socketHandle.readStatus(i,t);default:return{success:!1,message:"Device connectType is unsupported"}}})),this.subscribe=(e,t,i=!0)=>n(this,void 0,void 0,(function*(){l.default.debug("subscribe device:",e);let i=this.allDevices.find(t=>p.isSameDevice(t,e));if(!i)return l.default.warn("Device Target Not Found"),l.default.warn("current devices ",this.allDevices),{success:!1,message:"device not found"};if("BLE_BROADCAST"===i.connectType)return{success:!0};const n=p.getFirstConnectType(i,t);switch("NONE"!==i.connectType&&i.connectType!==n&&(yield this.unSubscribe(i)),n){case"BLE":{const e=yield this.bleHandle.connectDevice(i.bleDeviceID);return e.success&&(this.setDeviceMeta(i,"connectType","BLE",!0),setTimeout(()=>{this.setDeviceTimeStamp(i)},250),setTimeout(()=>{this.getDeviceStatus(i)},500)),e}case"WAN":{const t=this.socketHandle.connectDevice(i);return t.success&&this.setDeviceMeta(e,"connectType","WAN",!0),t}case"LAN":{const t=yield this.lanHandle.connectDevice(i);return t.success&&this.setDeviceMeta(e,"connectType","LAN",!0),t}}return{success:!1}})),this.unSubscribe=e=>n(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>p.isSameDevice(t,e));switch(t.connectType){case"BLE":{const e=yield this.bleHandle.disConnectDevice(t.bleDeviceID);return e.success&&this.setDeviceMeta(t,"connectType","NONE",!0),e}case"WAN":{const e=this.socketHandle.disConnectDevice(t);return e.success&&this.setDeviceMeta(t,"connectType","NONE",!0),e}case"LAN":{const e=this.lanHandle.disConnectDevice(t);return e.success&&this.setDeviceMeta(t,"connectType","NONE",!0),e}}return{success:!1}})),this.bindRemoteDevice=({mac:e,productKey:t,alias:i,beOwner:s})=>n(this,void 0,void 0,(function*(){const n=p.getProductInfoThroughPK(t,this.productInfo);if(n){const r=yield f.bindMac({mac:e,productKey:t,productSecret:n.productSecret,alias:i,beOwner:s});return this.getBindingList(),r}return{success:!1,err:d.default.GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY}})),this.checkUpdate=({device:e,type:t})=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>p.isSameDevice(t,e));if(i){if(!i.did)return{success:!1,err:d.default.GIZ_OPENAPI_DEVICE_NOT_BOUND};switch(i.connectType){case"BLE":return this.bleHandle.checkUpdate({deviceId:e.bleDeviceID,did:e.did,type:t});default:return{success:!1,err:d.default.GIZ_SDK_OTA_DEVICE_NOT_SUPPORT}}}return{success:!1,err:d.default.GIZ_SDK_DEVICE_NOT_SUBSCRIBED}})),this.startUpgrade=({device:e,type:t,onProgress:i,onEvent:s})=>n(this,void 0,void 0,(function*(){const n=this.allDevices.find(t=>p.isSameDevice(t,e));if(n){if(!n.did)return{success:!1,err:d.default.GIZ_OPENAPI_DEVICE_NOT_BOUND};switch(n.connectType){case"BLE":return this.bleHandle.startUpgrade({deviceId:e.bleDeviceID,did:e.did,type:t,productKey:e.productKey,onProgress:i,onEvent:s});default:return{success:!1,err:d.default.GIZ_SDK_OTA_DEVICE_NOT_SUPPORT}}}return{success:!1,err:d.default.GIZ_SDK_DEVICE_NOT_SUBSCRIBED}})),this.unbindDevice=({devices:e})=>n(this,void 0,void 0,(function*(){const t=yield f.unbindDevice({devices:e});return t.success&&this.getBindingList(),t})),this.deviceSafetyRegister=({mac:e,productKey:t})=>n(this,void 0,void 0,(function*(){return yield this.deviceSafetyApi({mac:e,productKey:t,isReset:!1})})),this.deviceSafetyUnbind=({mac:e,productKey:t})=>n(this,void 0,void 0,(function*(){return yield this.deviceSafetyApi({mac:e,productKey:t,isReset:!0})})),this.setDeviceOnboardingDeploy=({ssid:e,password:t,mode:i=0,timeout:s,isBind:r=!0,softAPSSIDPrefix:a})=>n(this,void 0,void 0,(function*(){if(this.currentWifiConfigHandle)return{success:!1,err:d.default.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING};const n=(new Date).getTime();l.default.debug("GIZ_SDK: 配网开始时间:"+n);try{switch(i){case 0:{this.currentWifiConfigHandle=new c.default(e,t,this.specialProductKeys,this.specialProductKeySecrets);const i=yield this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:s,isBind:r,softAPSSIDPrefix:a});this.currentWifiConfigHandle=null;const o=(new Date).getTime();return l.default.debug("GIZ_SDK: 配网结束时间:"+o),l.default.debug("GIZ_SDK: 配网用时:"+(o-n)),i}case 3:{this.currentWifiConfigHandle=new u.default(e,t,this.specialProductKeys,this.specialProductKeySecrets,this.bleHandle);const i=yield this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:s,isBind:r,softAPSSIDPrefix:a});this.currentWifiConfigHandle=null;const o=(new Date).getTime();return l.default.debug("GIZ_SDK: 配网结束时间:"+o),l.default.debug("GIZ_SDK: 配网用时:"+(o-n)),i}}}catch(e){return l.default.error("GIZ_SDK: setDeviceOnboardingDeploy",new Error(JSON.stringify(e))),e.err&&e.err.errorCode?e:{success:!1,err:d.default.GIZ_SDK_OTHERWISE}}finally{this.currentWifiConfigHandle=null}})),this.setDomain=e=>{const t=e&&e.openAPIInfo||"api.gizwits.com",i=Object.assign(Object.assign({},e||{}),{openAPIInfo:t});r.setGlobalData("cloudServiceInfo",i)},this.deviceSafetyApi=({mac:e,productKey:t,isReset:i})=>n(this,void 0,void 0,(function*(){const n=p.getProductInfoThroughPK(t,this.productInfo);return n?yield f.safeRegister({productKey:t,productSecret:n.productSecret,mac:e,isReset:i,passcode:"1234567890"}):{success:!1,err:d.default.GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY}})),this.getBindingList=()=>n(this,void 0,void 0,(function*(){const e=yield f.getBindingList();return this.deviceList=e.data||[],e})),this.getDevices=()=>n(this,void 0,void 0,(function*(){return yield this.getBindingList(),{success:!0,data:this.allDevices}})),this.stopDeviceOnboardingDeploy=()=>{this.currentWifiConfigHandle&&(this.currentWifiConfigHandle.stopDeviceOnboardingDeploy(),this.currentWifiConfigHandle=null)},this.setLogLevel=e=>l.default.setLogLevel(e),this.renameDevice=(e,t)=>n(this,void 0,void 0,(function*(){return t?e.isBind?yield f.editBindInfo({did:e.did,name:t}):{success:!1,message:"device not bind"}:{success:!1,message:"please input device name"}})),this.removeEventListener=(e,t)=>{if(this.listenerMap[e]){const i=this.listenerMap[e].indexOf(t);if(-1!==i)return this.listenerMap[e].splice(i,1),{success:!0}}return{success:!1}},this.addEventListener=(e,t)=>n(this,void 0,void 0,(function*(){return this.listenerMap[e]||(this.listenerMap[e]=[]),-1===this.listenerMap[e].indexOf(t)&&this.listenerMap[e].push(t),{success:!0}})),this.destory=()=>{this.bleHandle.destory(),this.lanHandle.destory(),this.socketHandle.destory(),this.keepScanTimer&&clearInterval(this.keepScanTimer)},this.init(e)}get deviceList(){return this._deviceList}set deviceList(e){this._deviceList=e,this.notiDeviceList()}get bleDevices(){return this._bleDevices}set bleDevices(e){this._bleDevices=e,this.notiDeviceList()}get lanDevices(){return this._lanDevices}set lanDevices(e){this._lanDevices=e,this.notiDeviceList()}get allDevices(){let e=p.merageBleLocalDevices([...this.deviceList],this.bleDevices);e=p.merageLanLocalDevices(e,this.lanDevices),this.bleHandle.connectedList.map(t=>{const i=e.findIndex(e=>e.bleDeviceID===t.deviceId);-1!==i&&(e[i].connectType="BLE")});const t=this.socketHandle._connections;return Object.keys(t).forEach(i=>{const n=t[i];n&&n._subDids.forEach(t=>{const i=e.findIndex(e=>e.did===t);-1!==i&&(e[i].connectType="WAN")})}),this.lanHandle.connectedList.map(t=>{const i=e.findIndex(e=>e.mac===t.mac&&e.productKey===t.productKey);-1!==i&&(e[i].connectType="LAN")}),e}get bleScanDevice(){return this.bleDevices.filter(e=>!0===e.isBleOnline)}get bleHandle(){return this._bleHandle||(this._bleHandle=new a.BleHandle({pks:this.specialProductKeys,offlineThreshold:this.offlineThreshold})),this._bleHandle}get lanHandle(){return this._lanHandle||(this._lanHandle=new _.LanHandle({pks:this.specialProductKeys})),this._lanHandle}get socketHandle(){return this._gizSocket||(this._gizSocket=new o.default({appID:r.getGlobalData("appID"),token:r.getGlobalData("token"),uid: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===r.getGlobalData("appID")&&i===r.getGlobalData("token")&&s===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:""})}}E.getVersion=()=>({success:!0,data:k}),t.default=E},function(e,t){},function(e,t,i){"use strict";t.byteLength=function(e){var t=u(e),i=t[0],n=t[1];return 3*(i+n)/4-n},t.toByteArray=function(e){var t,i,n=u(e),a=n[0],o=n[1],c=new r(function(e,t,i){return 3*(t+i)/4-i}(0,a,o)),l=0,d=o>0?a-4:a;for(i=0;i<d;i+=4)t=s[e.charCodeAt(i)]<<18|s[e.charCodeAt(i+1)]<<12|s[e.charCodeAt(i+2)]<<6|s[e.charCodeAt(i+3)],c[l++]=t>>16&255,c[l++]=t>>8&255,c[l++]=255&t;2===o&&(t=s[e.charCodeAt(i)]<<2|s[e.charCodeAt(i+1)]>>4,c[l++]=255&t);1===o&&(t=s[e.charCodeAt(i)]<<10|s[e.charCodeAt(i+1)]<<4|s[e.charCodeAt(i+2)]>>2,c[l++]=t>>8&255,c[l++]=255&t);return c},t.fromByteArray=function(e){for(var t,i=e.length,s=i%3,r=[],a=0,o=i-s;a<o;a+=16383)r.push(l(e,a,a+16383>o?o:a+16383));1===s?(t=e[i-1],r.push(n[t>>2]+n[t<<4&63]+"==")):2===s&&(t=(e[i-2]<<8)+e[i-1],r.push(n[t>>10]+n[t>>4&63]+n[t<<2&63]+"="));return r.join("")};for(var n=[],s=[],r="undefined"!=typeof Uint8Array?Uint8Array:Array,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0,c=a.length;o<c;++o)n[o]=a[o],s[a.charCodeAt(o)]=o;function u(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var i=e.indexOf("=");return-1===i&&(i=t),[i,i===t?0:4-i%4]}function l(e,t,i){for(var s,r,a=[],o=t;o<i;o+=3)s=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(255&e[o+2]),a.push(n[(r=s)>>18&63]+n[r>>12&63]+n[r>>6&63]+n[63&r]);return a.join("")}s["-".charCodeAt(0)]=62,s["_".charCodeAt(0)]=63},function(e,t){t.read=function(e,t,i,n,s){var r,a,o=8*s-n-1,c=(1<<o)-1,u=c>>1,l=-7,d=i?s-1:0,h=i?-1:1,f=e[t+d];for(d+=h,r=f&(1<<-l)-1,f>>=-l,l+=o;l>0;r=256*r+e[t+d],d+=h,l-=8);for(a=r&(1<<-l)-1,r>>=-l,l+=n;l>0;a=256*a+e[t+d],d+=h,l-=8);if(0===r)r=1-u;else{if(r===c)return a?NaN:1/0*(f?-1:1);a+=Math.pow(2,n),r-=u}return(f?-1:1)*a*Math.pow(2,r-n)},t.write=function(e,t,i,n,s,r){var a,o,c,u=8*r-s-1,l=(1<<u)-1,d=l>>1,h=23===s?Math.pow(2,-24)-Math.pow(2,-77):0,f=n?0:r-1,p=n?1:-1,v=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(o=isNaN(t)?1:0,a=l):(a=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-a))<1&&(a--,c*=2),(t+=a+d>=1?h/c:h*Math.pow(2,1-d))*c>=2&&(a++,c/=2),a+d>=l?(o=0,a=l):a+d>=1?(o=(t*c-1)*Math.pow(2,s),a+=d):(o=t*Math.pow(2,d-1)*Math.pow(2,s),a=0));s>=8;e[i+f]=255&o,f+=p,o/=256,s-=8);for(a=a<<s|o,u+=s;u>0;e[i+f]=255&a,f+=p,a/=256,u-=8);e[i+f-p]|=128*v}},function(e,t){var i={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==i.call(e)}},function(e,t,i){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=n(i(7)),r=n(i(19));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:s.default(`${(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)};r.default("https://appmonitor.gizwits.com/api/21/store/?sentry_key=0b2de791abf548a1bedf0b0ebdd8ecc7&sentry_version=7",n)}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(10)),a=s(i(0)),o=i(1);class c extends a.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 a=[0];const c=[0,147];let u=[0,0,0,0],l=[2];if(t){a=[1];const e=o.fillString(t.length.toString(16),4),i=o.hexStrint2byte(e),n=o.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=o.fillString(e,8*Math.ceil(e.length/8)),l=l.concat(o.hexStrint2byte(parseInt(e,2).toString(16)))}const d=a.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.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(6));t.checkUpdate=function({did:e,type:t,hardVersion:i,softVersion:s}){return n(this,void 0,void 0,(function*(){const n="MCU"==t?"2":"1";return r.default(`/app/ota/v4.1/update_and_check/${e}`,{data:{type:n,hard_version:i,soft_version:s,https:"1"},method:"POST"},!0)}))}},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(0)),r=i(1);class a extends s.default{constructor(e){super(e),this.moduleSoftVersion="",this.moduleHardVersion="",this.mcuSoftVersion="",this.mcuHardVersion="",this.businessVersion="";let t=0;this.moduleHardVersion=r.arrayToASCII(this.content.slice(t,t+8)),t+=8,this.moduleSoftVersion=r.arrayToASCII(this.content.slice(t,t+8)),t+=8,this.mcuHardVersion=r.arrayToASCII(this.content.slice(t,t+8)),t+=8,this.mcuSoftVersion=r.arrayToASCII(this.content.slice(t,t+8)),t+=8,this.businessVersion=r.arrayToASCII(this.content.slice(t,t+8)),t+=8}}a.pack=()=>[0,0,0,3,3,0,0,19],t.default=a},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(0));class r extends s.default{constructor(e){super(e),this.type="MCU",this.state=0,this.version=0;let t=0;this.type=1===e[t]?"MODULE":"MCU",t+=1,this.state=e[t],t+=1,this.version=e[t]}}r.pack=e=>[0,0,0,3,4,0,0,65,"MCU"===e?2:1],t.default=r},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(11),r=n(i(0)),a=i(1);class o extends r.default{constructor(e){super(e)}}o.pack=(e,t,i,n,r)=>{const o=a.string2Bytes(e),c=e.length,u=a.string2Bytes(t),l=a.string2Bytes(i),d=a.string2Bytes(r),h=a.hexStrint2byte(a.fillString(n.toString(16),8));let f=[0];f=f.concat([0,67],[c],o,u,l,h,d);const p=s.getVariableLength(f);return[0,0,0,3].concat(p,f)},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 a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(4)),a=s(i(3)),o=s(i(6)),c=i(8);t.default=class{constructor({appID:e,token:t,uid:i,limitSocketNum:s=!0}){this._bindingDevices=null,this._connections={},this.updateToken=({token:e,uid:t})=>{this.token=e,this.uid=t},this._getDevice=e=>{if(null===this._bindingDevices)return r.default.GIZ_SDK_SDK_NOT_INITIALIZED;const t=this._bindingDevices[e];return null==t?r.default.GIZ_OPENAPI_DEVICE_NOT_BOUND:t},this._getConnect=e=>{const t=this._getWebsocketConnInfo(e);return this._connections[t]},this._getDeviceAndConnect=e=>{const t=this._getDevice(e);if(c.isError(t))return t;const i=this._getConnect(t);return null==i?r.default.GIZ_SDK_DEVICE_NOT_SUBSCRIBED:[t,i]},this.connectDevice=e=>{const t=this._getWebsocketConnInfo(e);let i=this._connections[t];if(null==i){const e=Object.keys(this._connections).length;if(0!==this._maxSocketNum&&e>=this._maxSocketNum)return{success:!1,errorCode:r.default.MAX_CONNECT};i=new u({appID:this.appID,token:this.token,uid:this.uid,wsInfo:t,onDeviceStatusChanged:this._handleDeviceStatusChanged,onBindingChanged:this._handleBindingChanged,onSocketStatusChanged:this._handleSocketStatusChanged}),this._connections[t]=i}return i._addSubDid(e.did),null==i._websocket?i._connectWS():i.ready&&i._subDevices([e.did]),{success:!0}},this.disConnectDevice=e=>{const t=this._getWebsocketConnInfo(e);let i=this._connections[t];return i&&i._unSubDevices([e.did]),{success:!0}},this.connect=e=>{const t=this._getDevice(e);if(c.isError(t))return t;const i=this.connectDevice(t);return i.success?null:i.errorCode},this.send=(e,t)=>{const i=this._getDeviceAndConnect(e);return c.isError(i)?i:i[1]._send({cmd:"c2s_raw",data:{did:e,raw:t}})},this.writeData=(e,t)=>{const i=this._getConnect(e);return null!=i?i._send({cmd:"c2s_write",data:{did:e.did,attrs:t}}):{success:!1}},this.write=(e,t)=>{const i=this._getDeviceAndConnect(e);return c.isError(i)?i:i[1]._send({cmd:"c2s_write",data:{did:e,attrs:t}})},this.readStatus=(e,t)=>{const i=this._getConnect(e),n=null!=i;return n&&i._send({cmd:"c2s_read",data:{did:e.did,names:t}}),{success:n}},this.read=(e,t)=>{const i=this._getDeviceAndConnect(e);return c.isError(i)?i:i[1]._send({cmd:"c2s_read",data:{did:e,names:t}})},this.destory=()=>{Object.values(this._connections).forEach(e=>e.destory())},this.subscribeDeviceStatus=e=>{this._onDeviceStatusChanged=e},this.subscribeBindingChanged=e=>{this._onBindingChanged=e},this.subscribeSocketStatus=e=>{this._onSocketStatusChanged=e},this._handleDeviceStatusChanged=e=>{this._onDeviceStatusChanged&&this._onDeviceStatusChanged(e)},this._handleBindingChanged=()=>{this._onBindingChanged&&this._onBindingChanged()},this._handleSocketStatusChanged=(...e)=>{this._onSocketStatusChanged&&this._onSocketStatusChanged(...e)},this._getBindingList=(e=20,t=0,i=[])=>n(this,void 0,void 0,(function*(){const n=`/app/bindings?show_disabled=0&limit=${e}&skip=${t}`,{err:s,data:r}=yield o.default(`${n}`,{method:"GET"});if(s)return{err:s};const a=[...i,...(null==r?void 0:r.devices)||[]];return r&&r.devices.length===e?yield this._getBindingList(e,e+t,a):a})),this._getWebsocketConnInfo=e=>e.host?`wss://wx${e.host}`:"wss://wxstage.gizwits.com",this.appID=e,this.token=t,this.uid=i;const a=wx.getSystemInfoSync().SDKVersion;this._maxSocketNum=s?-1===c.compareWXSDKVersion(a||"1.0.0","1.7.0")?1:5:0}init(){var e,t;return n(this,void 0,void 0,(function*(){try{const i=yield this._getBindingList();return(null===(e=i.err)||void 0===e?void 0:e.errorCode)?{errorCode:null===(t=i.err)||void 0===t?void 0:t.errorCode,errorMessage:"getting binding list failed"}:(this._bindingDevices=i.reduce((e,t)=>Object.assign(Object.assign({},e),{[t.did]:t}),{}),null)}catch(e){return r.default.GIZ_SDK_OTHERWISE}}))}};class u{constructor({appID:e,token:t,uid:i,wsInfo:s,onDeviceStatusChanged:r,onBindingChanged:o,onSocketStatusChanged:c}){this.ready=!1,this.commType="attrs_v4",this._heartbeatInterval=60,this._keepaliveTime=180,this._loginIntveral=5e3,this.autoSubscribe=!1,this._websocket=null,this._loginFailedTimes=0,this._subDids=new Set,this._socketRespHandleMap={},this._waitSends=[],this.destory=()=>{this._heartbeatTimerId&&clearInterval(this._heartbeatTimerId),this._checkConnectTimerId&&clearInterval(this._checkConnectTimerId),this.close()},this._networkChange=e=>n(this,void 0,void 0,(function*(){a.default.log("network change",e)})),this._appShow=()=>n(this,void 0,void 0,(function*(){a.default.log("app show")})),this._addSubDid=e=>{this._subDids.add(e)},this._removeSubDid=e=>{this._subDids.delete(e)},this._connectWS=()=>{a.default.log("GIZ_SDK: start connect ws"),this._websocket=wx.connectSocket({url:this._wsUrl,fail:e=>{a.default.error("GIZ_SDK: connectSocket error",new Error(JSON.stringify(e)))}}),this._websocket.onClose(this.handleClose),this._websocket.onOpen(this.handleOpen),this._websocket.onError(this.handleError),this._websocket.onMessage(this.handleMessage),this._checkConnectTimerId||(this._checkConnectTimerId=setInterval(()=>{this._websocket||this._connectWS()},1e3))},this._subDevices=e=>{const t={cmd:"subscribe_req",data:e.map(e=>({did:e}))};this._send(t)},this._unSubDevices=e=>{e.map(e=>this._removeSubDid(e))},this._send=(e,t=!1)=>(a.default.log("GIZ_SDK: Socket send",e,t),new Promise(i=>{this._websocket?t||this.ready?this._websocket&&(t||this.ready)&&this._websocket.send({data:JSON.stringify(e),complete:e=>{a.default.log("GIZ_SDK: socket send res",e),a.default.log("resres",e);let t=!1;"sendSocketMessage:ok"===e.errMsg&&(t=!0),i({success:t,message:e.errMsg})},fail:e=>{a.default.error("GIZ_SDK: Socket send error",new Error(JSON.stringify(e))),i({success:!1,message:e.errMsg})}}):i({success:!1,message:"Socket not ready"}):i({success:!1,message:"Socket not init"})})),this.close=()=>{this.ready=!1,this._heartbeatTimerId&&clearInterval(this._heartbeatTimerId),this._websocket&&(this._websocket.close({}),this._websocket=null),this._handleSocketStatusChanged(!1)},this.handleClose=e=>{a.default.error("GIZ_SDK: socket close",new Error(JSON.stringify(e))),this.close(),this._stopPing()},this.handleOpen=()=>{a.default.log(" socket open"),this._login()},this.handleMessage=({data:e})=>{a.default.log("GIZ_SDK: message",e);const t=JSON.parse(e),i=this._socketRespHandleMap[t.cmd];i&&i(t.data)},this.handleError=e=>{a.default.error("GIZ_SDK: socket error",new Error(JSON.stringify(e))),this.close(),this._stopPing()},this._login=()=>{const e={cmd:"login_req",data:{appid:this.appID,uid:this.uid,token:this.token,p0_type:this.commType,heartbeat_interval:this._keepaliveTime,auto_subscribe:this.autoSubscribe}};this._send(e,!0)},this._tryLoginAgain=()=>{this._loginFailedTimes+=1,setTimeout(()=>{this._login()},this._loginFailedTimes*this._loginIntveral)},this._startPing=()=>{this._heartbeatTimerId=setInterval(()=>{this._send({cmd:"ping"})},1e3*this._heartbeatInterval)},this._stopPing=()=>{this._heartbeatTimerId&&clearInterval(this._heartbeatTimerId)},this.pongResp=()=>{},this._loginResp=e=>{1==e.success?(this._loginFailedTimes=0,this.ready=!0,this._startPing(),this._subDevices([...this._subDids]),this._handleSocketStatusChanged(!0),this._consumeWaitSends()):this._loginFailedTimes<3?(a.default.log("GIZ_SDK: Login failed, will try again, please wait..."),this._tryLoginAgain()):(a.default.error("GIZ_SDK: Login failed",new Error("m2m socket login failed")),this.close())},this._consumeWaitSends=()=>{let e=this._waitSends.pop();for(;e;)this._send(e),e=this._waitSends.pop()},this._handleSocketStatusChanged=e=>{this._onSocketStatusChanged&&this._onSocketStatusChanged([...this._subDids],e)},this._subscribeResp=e=>{a.default.log("GIZ_SDK: subscribe_res",e),e&&e.success&&e.success.forEach(e=>this._send({cmd:"c2s_read",data:{did:e.did}})),a.default.debug("GIZ_SDK: subscribe_res",e)},this._onlineResp=e=>{this._isSub(e.did)&&this._onDeviceStatusChanged&&this._onDeviceStatusChanged({did:e.did,attrs:Object.assign({is_online:e.online},e)})},this._rawChangedResp=e=>{this._isSub(e.did)&&this._onDeviceStatusChanged&&this._onDeviceStatusChanged(e)},this._statusChangedResp=e=>{this._isSub(e.did)&&this._onDeviceStatusChanged&&this._onDeviceStatusChanged(e)},this._isSub=e=>this._subDids.has(e),this._invalidMsgResp=e=>{1003===e.error_code&&this._login(),a.default.error("GIZ_SDK: s2c_invalid_msg",new Error(JSON.stringify(e)))},this._bindingChangedResp=e=>{!e.bind&&e.did&&this._removeSubDid(e.did),this._onBindingChanged&&this._onBindingChanged()},this.appID=e,this.token=t,this.uid=i,this._wsUrl=`${s}/ws/app/v1`,this._heartbeatTimerId=void 0,this._loginFailedTimes=0,this._onDeviceStatusChanged=r,this._onBindingChanged=o,this._onSocketStatusChanged=c,this._socketRespHandleMap={pong:this.pongResp,login_res:this._loginResp,subscribe_res:this._subscribeResp,s2c_online_status:this._onlineResp,s2c_raw:this._rawChangedResp,s2c_noti:this._statusChangedResp,s2c_invalid_msg:this._invalidMsgResp,s2c_binding_changed:this._bindingChangedResp},wx.onNetworkStatusChange(this._networkChange),wx.onAppShow(this._appShow)}}t.Connection=u},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(4)),a=s(i(3)),o=s(i(24)),c=s(i(25));class u extends c.default{constructor(){super(...arguments),this.disableSendUDP=!1,this.sendMessageInterval=null,this.UDPSocketHandler=null,this.destroy=()=>{this.cleanTimeout(),this.sendMessageInterval&&clearInterval(this.sendMessageInterval),this.sendMessageInterval=null,this.UDPSocketHandler&&(this.UDPSocketHandler.offError(),this.UDPSocketHandler.offMessage(),this.UDPSocketHandler.close())},this.configDevice=({ssid:e,password:t,softAPSSIDPrefix:i})=>new Promise((s,c)=>{a.default.debug("GIZ_SDK: start config device");let u=!1,l=0;const d=o.default.pack(e,t);this.UDPSocketHandler=wx.createUDPSocket(),this.UDPSocketHandler.bind(),this.disableSendUDP=!1;const h=()=>{try{!this.disableSendUDP&&this.UDPSocketHandler.send({address:"10.10.100.254",port:12414,message:d,offset:0,length:d.byteLength})}catch(e){}};this.sendMessageInterval=setInterval(()=>{h()},2e3),this.UDPSocketHandler.onError(e=>{l+=1,l>2&&(this.destroy(),c({success:!1,err:{errorCode:r.default.WECHAT_ERROR.errorCode,errorMessage:e.errMsg}}))});const f=()=>n(this,void 0,void 0,(function*(){if(!u){this.UDPSocketHandler.offMessage(),this.UDPSocketHandler.offError(),this.sendMessageInterval&&clearInterval(this.sendMessageInterval),this.disableSendUDP=!0,u=!0;try{const i=yield this.searchDevice({ssid:e,password:t});s(i)}catch(e){c(e)}}}));this.UDPSocketHandler.onMessage(e=>{f()}),wx.onNetworkStatusChange(()=>n(this,void 0,void 0,(function*(){!u&&wx.getConnectedWifi({success:e=>n(this,void 0,void 0,(function*(){-1===e.wifi.SSID.indexOf(i)&&f()}))})})))}),this.setDeviceOnboardingDeploy=({timeout:e,isBind:t=!0,softAPSSIDPrefix:i})=>{const s=this.ssid,r=this.password;return new Promise((a,o)=>n(this,void 0,void 0,(function*(){this.destroy(),this.initDeviceOnboardingDeploy(a,o),this.startTimeoutTimer(e);try{const e=((yield this.configDevice({ssid:s,password:r,softAPSSIDPrefix:i})).data||[]).map(e=>({mac:e.mac,productKey:e.product_key,did:e.did,name:"",isBind:!1,connectType:"NONE",isBleOnline:!1,isLanOnline:!1,isOnline:!1}));if(t)try{a(yield this.bindDevices(e))}catch(e){o(e)}else a({success:!0,data:e})}catch(e){o(e)}finally{this.destroy()}})))}}}t.default=u},function(e,t,i){var n,s,r,a,o,c,u,l;e.exports=(l=i(2),s=(n=l).lib,r=s.WordArray,a=s.Hasher,o=n.algo,c=[],u=o.SHA1=a.extend({_doReset:function(){this._hash=new r.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(e,t){for(var i=this._hash.words,n=i[0],s=i[1],r=i[2],a=i[3],o=i[4],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)+o+c[u];d+=u<20?1518500249+(s&r|~s&a):u<40?1859775393+(s^r^a):u<60?(s&r|s&a|r&a)-1894007588:(s^r^a)-899497514,o=a,a=r,r=s<<30|s>>>2,s=n,n=d}i[0]=i[0]+n|0,i[1]=i[1]+s|0,i[2]=i[2]+r|0,i[3]=i[3]+a|0,i[4]=i[4]+o|0},_doFinalize:function(){var e=this._data,t=e.words,i=8*this._nDataBytes,n=8*e.sigBytes;return t[n>>>5]|=128<<24-n%32,t[14+(n+64>>>9<<4)]=Math.floor(i/4294967296),t[15+(n+64>>>9<<4)]=i,e.sigBytes=4*t.length,this._process(),this._hash},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),n.SHA1=a._createHelper(u),n.HmacSHA1=a._createHmacHelper(u),l.SHA1)},function(e,t,i){var n,s,r,a;e.exports=(n=i(2),r=(s=n).lib.Base,a=s.enc.Utf8,void(s.algo.HMAC=r.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=a.parse(t));var i=e.blockSize,n=4*i;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var s=this._oKey=t.clone(),r=this._iKey=t.clone(),o=s.words,c=r.words,u=0;u<i;u++)o[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.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=n(i(14)),r=n(i(15)),a=n(i(13)),o=n(i(7)),c=n(i(12)),u=n(i(49)),l=({SSID:e,password:t,pk:i})=>{let n=o.default(e+t).toString();n=r.default.parse(n);let l=s.default.parse(i),d=a.default.encrypt(l,n,{iv:n,mode:c.default,padding:u.default});return o.default(d.ciphertext).toString()};t.default=({SSID:e,password:t,pks:i})=>{const n=[];return i.map(i=>{const s=l({SSID:e,password:t,pk:i});n.push(s)}),n}},function(e,t,i){var n;e.exports=(n=i(2),i(9),n.pad.ZeroPadding={pad:function(e,t){var i=4*t;e.clamp(),e.sigBytes+=i-(e.sigBytes%i||i)},unpad:function(e){var t=e.words,i=e.sigBytes-1;for(i=e.sigBytes-1;i>=0;i--)if(t[i>>>2]>>>24-i%4*8&255){e.sigBytes=i+1;break}}},n.pad.ZeroPadding)},function(e,t,i){"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(7));t.psKeySign=e=>{const t=Math.round((new Date).getTime()/1e3),i=e+t;return{Signature:s.default(i).toString(),timestamp:t}}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(4)),a=i(8),o=i(20),c=s(i(5)),u=s(i(25)),l=s(i(24)),d=s(i(3));function h({bleDeviceId:e,arrayBuffer:t,serviceUUIDSuffix:i="abf0",characteristicUUIDSuffix:s="abf7",bleHandle:r}){let c=null,u=null;const l=()=>null===u&&(c&&clearInterval(c),!0);return new Promise((h,f)=>n(this,void 0,void 0,(function*(){try{d.default.debug("GIZ_SDK: ssid info: ",t),u=setTimeout(()=>{c&&clearInterval(c),u=null,h(!1)},5e3),d.default.debug("GIZ_SDK: createBLEConnection start: ",e),yield r.disableScan();const n=yield o.retryConnect(e,1e4);r.enableScan(),d.default.debug("GIZ_SDK: createBLEConnection end, res:",n);const f=yield o.getBLEDeviceServices(e);d.default.debug("GIZ_SDK: getBLEDeviceServices end, res:",f);const p=f.find(e=>e.uuid.split("-")[0].toLowerCase().endsWith(i));if(!p)return d.default.debug("GIZ_SDK: get ble device services fail",e,f),void h(!1);const v=yield o.getBLEDeviceCharacteristics(e,p.uuid);d.default.debug("GIZ_SDK: getBLEDeviceCharacteristics end, res:",v);const g=v.find(e=>e.uuid.split("-")[0].toLowerCase().endsWith(s));if(!g)return d.default.debug("GIZ_SDK: get ble device characteristics fail",e,v),void h(!1);if(!g.properties.notify&&!g.properties.indicate)return d.default.debug("GIZ_SDK: the ble device characteristic not support notify or indicate",e,g),void h(!1);d.default.debug("GIZ_SDK: check characteristic and service success"),yield o.notifyBLECharacteristicValueChange(e,p.uuid,g.uuid);const y=e=>{const t=a.ab2hex(e.value);d.default.debug("GIZ_SDK: 收到设备返回ack",t),"0000000303000002"===t&&(r.removeEventListener("GizBleDeviceData",y),h(!0))};if(r.addEventListener("GizBleDeviceData",y),d.default.debug("GIZ_SDK: on notifyBLECharacteristicValueChange success"),l())return;yield o.unpackWriteBLECharacteristicValue(e,p.uuid,g.uuid,t),c=setInterval(()=>{l()||o.unpackWriteBLECharacteristicValue(e,p.uuid,g.uuid,t)},2e3),d.default.debug("GIZ_SDK: unpackWriteBLECharacteristicValue end")}catch(e){f(!1),d.default.debug("GIZ_SDK: sendBLEConfigCmd error",e)}}))).catch(e=>{d.default.debug("GIZ_SDK: sendBLEConfigCmd error",e)}).finally(()=>{u&&clearTimeout(u),c&&clearInterval(c),wx.closeBLEConnection({deviceId:e})})}t.sendBLEConfigCmd=h;class f extends u.default{constructor(e,t,i,s,u){super(e,t,i,s),this.destroy=()=>{this.cleanTimeout()},this.isValidBleDevice=(e,t)=>{if(!e||!e.advertisData)return!1;const{productKey:i,mac:n}=a.advertisData2PkAndMac(e.advertisData,this.specialProductKeys);return!!this.specialProductKeys.includes(i)&&(d.default.debug(`GIZ_SDK: isValidBleDevice mac: ${n} pk: ${i} name: ${e.name}`),d.default.debug(`GIZ_SDK: softAPSSIDPrefix: ${t} ismatch : ${e.name&&e.name.startsWith(t)}`),!t||e.name&&e.name.startsWith(t))},this.enableBluetoothDevicesDescovery=()=>n(this,void 0,void 0,(function*(){return(yield o.getBluetoothAdapterState()).available?(yield o.startBluetoothDevicesDiscovery(),{success:!0}):{success:!1,err:{errorCode:r.default.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON.errorCode,errorMessage:"蓝牙状态不可用"}}})),this.enableAndGetBluetoothDevices=e=>n(this,void 0,void 0,(function*(){const t=yield this.enableBluetoothDevicesDescovery();if(!t.success)return t;d.default.debug("GIZ_SDK: start enableAndGetBluetoothDevices");const i=(yield o.getBluetoothDevices()).filter(t=>this.isValidBleDevice(t,e));return d.default.debug("GIZ_SDK: getBluetoothDevices success",i),{success:!0,bleDevices:i}})),this.setDeviceOnboardingDeploy=({timeout:e,isBind:t=!0,softAPSSIDPrefix:i})=>new Promise((s,r)=>n(this,void 0,void 0,(function*(){const n=this.ssid,a=this.password;this.destroy(),this.initDeviceOnboardingDeploy(s,r),this.startTimeoutTimer(e);try{const r=((yield this.configBLEDevice({ssid:n,password:a,timeout:1e3*e,softAPSSIDPrefix:i})).data||[]).map(e=>({mac:e.mac,productKey:e.product_key,did:e.did,name:"",isBind:!1,connectType:"NONE",isBleOnline:!1,isLanOnline:!1,isOnline:!1}));s(t?yield this.bindDevices(r):{success:!0,data:r})}catch(e){s({success:!1,data:e})}finally{this.destroy()}}))),this.configBLEDevice=({ssid:e,password:t,softAPSSIDPrefix:i})=>new Promise((s,u)=>n(this,void 0,void 0,(function*(){d.default.debug("GIZ_SDK: start config ble device");const f=yield this.enableAndGetBluetoothDevices(i).catch(e=>({success:!1,err:{errorCode:r.default.WECHAT_ERROR.errorCode,errorMessage:JSON.stringify(e)}}));if(!a.isWXDevicesResult(f))return u(f);const{bleDevices:p}=f;d.default.debug("GIZ_SDK: enableAndGetBluetoothDevices success, target devices: ",p);const v=({devices:e})=>n(this,void 0,void 0,(function*(){this.hasTimeoutHandler()?Array.prototype.push.apply(p,e.filter(e=>this.isValidBleDevice(e,i))):wx.offBluetoothDeviceFound(v)}));wx.onBluetoothDeviceFound(v);const g=l.default.pack(e,t),y=()=>n(this,void 0,void 0,(function*(){if(d.default.debug("GIZ_SDK: startConfigDevice"),!this.hasTimeoutHandler())return;const e=p.shift();if(e&&d.default.debug("GIZ_SDK: startConfigDevice, target device: ",e),!(e&&(yield h({bleDeviceId:e.deviceId,arrayBuffer:g.buffer,bleHandle:this.bleHandle}))))return yield c.default(500),yield o.startBluetoothDevicesDiscovery(),void(yield y());d.default.debug("GIZ_SDK: offBluetoothDeviceFound ready search device"),wx.offBluetoothDeviceFound(v)}));try{this.searchDevice({ssid:e,password:t}).then(e=>{s(e)})}catch(e){u(e),d.default.error("GIZ_SDK: searchDevice error",new Error(JSON.stringify(e)))}yield y()}))),this.bleHandle=u}}t.default=f},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(6));t.AnonymousLogin=function({uid:e}){return n(this,void 0,void 0,(function*(){return r.default("/app/users",{data:{phone_id:e},method:"POST"},!1)}))}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(3)),a=s(i(21)),o=s(i(54)),c=s(i(22)),u=s(i(0)),l=i(1),d=s(i(5)),h=i(8),f=s(i(23));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=h.ab2numbers(e.message),i=new o.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,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:o.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:o}){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=a.default.pack();this.tcpHandler.write(l.arrayToUint8(e)),r.default.debug("connect success try login")},i=t=>{e({success:!0,err:t})},n=t=>{switch(new u.default(h.ab2numbers(t.message)).cmd){case"0007":{const e=new a.default(h.ab2numbers(t.message)),i=c.default.pack({passcode:e.passcode});this.tcpHandler.write(l.arrayToUint8(i));break}case"0009":new c.default(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 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=h.ab2hex(e.message),i=new u.default(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=o,this.onCloseListener=t}}},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(3)),r=n(i(0)),a=i(1);class o extends r.default{constructor(e){super(e),this.did="",this.mac="",this.productKey="",this.deviceType=0,this.apiUrl="",this.protocolVersion="",this.mcuVersion="",this.moduleVersion="",this.parseEndChat=(e,t)=>{let i="";const n=this.content.slice(e,this.content.length);for(let t in n){const s=n[t];if(e+=1,0===s)break;i+=String.fromCharCode(s)}return this[t]=i,e},this.baseParse=(e,t,i="ASCII")=>{const n=parseInt(a.arrayToString(this.content.slice(e,e+2)),16);e+=2;let s="";return this.content.slice(e,e+n).map(e=>{if("ASCII"===i)s+=String.fromCharCode(e);else{const t=e.toString(16);s+=a.fillString(t,2)}}),this[t]=s,e+n};let t=0;try{t=this.baseParse(t,"did"),t=this.baseParse(t,"mac","HEX"),t=this.baseParse(t,"moduleVersion"),t=this.baseParse(t,"productKey"),t+=8,t=this.parseEndChat(t,"apiUrl"),t=this.parseEndChat(t,"protocolVersion"),this.mcuVersion="",this.content.slice(t,this.content.length).map(e=>{this.mcuVersion+=String.fromCharCode(e)})}catch(e){s.default.warn("Parse DiscoverUDP error",e)}}}o.pack=()=>{const e=[0,0,0,3,3,0,0,3],t=new ArrayBuffer(e.length),i=new Uint8Array(t);for(let n=0;n<t.byteLength;n++)i[n]=e[n];return i},t.default=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(0)),r=i(1);class a extends s.default{constructor(e){super(e),this.state=0,this.len=0;let t=0;this.len=parseInt(r.arrayToString(this.content.slice(t,t+2)),16),t+=2,this.state=this.content[t]}}t.RequestSync=a,a.pack=()=>[0,0,0,3,3,0,0,81];class o extends s.default{constructor(e){super(e),this.id=0,this.timestemp=0,this.payloadLen=0,this.payload=[];let t=0;this.id=parseInt(r.arrayToString(this.content.slice(t,t+2)),16),t+=2,this.timestemp=parseInt(r.arrayToString(this.content.slice(t,t+5)),16),t+=5,this.payloadLen=parseInt(r.arrayToString(this.content.slice(t,t+2)),16),t+=2,this.payload=this.content.slice(t,this.content.length)}}t.SyncPackage=o,o.pack=e=>{let t=e.toString(2);return t=r.fillString(t,16),[0,0,0,3,5].concat([0,0,83]).concat(r.completeBlock(t))};class c extends s.default{}t.DeletePackage=c,c.pack=e=>{let t=e.toString(2);return t=r.fillString(t,16),[0,0,0,3,5].concat([0,0,85]).concat(r.completeBlock(t))};class u extends s.default{constructor(e){super(e),this.state=0,this.state=this.content[0]}}t.CancelSync=u,u.pack=()=>[0,0,0,3,3,0,0,87]},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(28)),a=s(i(14)),o=s(i(15)),c=s(i(13)),u=s(i(12)),l=s(i(6));t.uploadP0=function({device:e,data:t,productSecret:i}){return n(this,void 0,void 0,(function*(){const n=`/v2/products/${e.productKey}/devices/offline-data`;let s=e.passcode;const d=o.default.parse(i),h=o.default.parse(""),f=a.default.parse(s);return s=c.default.encrypt(f,d,{iv:h,mode:u.default,padding:r.default}).ciphertext.toString().toUpperCase(),l.default(n,{data:{data:t,encoding:"hex"},method:"POST",headers:{"X-Gizwits-Device-Id":e.did,"X-Gizwits-Device-passcode":s}},!1)}))}},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(0)),r=i(1);class a extends s.default{}a.pack=()=>{const e=parseInt(`${Date.now()/1e3}`,10),t=r.fillString(e.toString(2),40);return[0,0,0,3,8,0,0,89].concat(r.completeBlock(t))},t.default=a},function(e){e.exports=JSON.parse('{"name":"mini_program_gizwits_sdk","version":"3.4.0-beta","description":"ota","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.5.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":"^3.8.3","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":{"crc":"^4.3.2","crypto-js":"^4.1.1"}}')},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(0));class r extends s.default{constructor(e){super(e),this.status=0,this.status=this.content[0]}}r.pack=()=>[0,0,0,3,3,0,0,97],t.default=r},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(0));class r extends s.default{constructor(){super(...arguments),this.status=0}}r.pack=e=>[0,0,0,3,3,0,0,99,e],t.default=r},function(e,t,i){"use strict";i.r(t),i.d(t,"crc1",(function(){return o})),i.d(t,"crc8",(function(){return u})),i.d(t,"crc81wire",(function(){return d})),i.d(t,"crc8dvbs2",(function(){return f})),i.d(t,"crc16",(function(){return v})),i.d(t,"crc16ccitt",(function(){return y})),i.d(t,"crc16modbus",(function(){return m})),i.d(t,"crc16xmodem",(function(){return D})),i.d(t,"crc16kermit",(function(){return S})),i.d(t,"crc24",(function(){return I})),i.d(t,"crc32",(function(){return B})),i.d(t,"crc32mpeg2",(function(){return E})),i.d(t,"crcjam",(function(){return T}));var n=(e,t=0)=>{let i=~~t,n=0;for(let t=0;t<e.length;t++)n+=e[t];return i+=n%256,i%256},s=i(30);var r=(e,t)=>s.Buffer.from(e,t);function a(e,t){const i=(e,i)=>t(r(e),i)>>>0;return i.signed=(e,i)=>t(r(e),i),i.unsigned=i,i.model=e,i}var o=a("crc1",n);let c=[0,7,14,9,28,27,18,21,56,63,54,49,36,35,42,45,112,119,126,121,108,107,98,101,72,79,70,65,84,83,90,93,224,231,238,233,252,251,242,245,216,223,214,209,196,195,202,205,144,151,158,153,140,139,130,133,168,175,166,161,180,179,186,189,199,192,201,206,219,220,213,210,255,248,241,246,227,228,237,234,183,176,185,190,171,172,165,162,143,136,129,134,147,148,157,154,39,32,41,46,59,60,53,50,31,24,17,22,3,4,13,10,87,80,89,94,75,76,69,66,111,104,97,102,115,116,125,122,137,142,135,128,149,146,155,156,177,182,191,184,173,170,163,164,249,254,247,240,229,226,235,236,193,198,207,200,221,218,211,212,105,110,103,96,117,114,123,124,81,86,95,88,77,74,67,68,25,30,23,16,5,2,11,12,33,38,47,40,61,58,51,52,78,73,64,71,82,85,92,91,118,113,120,127,106,109,100,99,62,57,48,55,34,37,44,43,6,1,8,15,26,29,20,19,174,169,160,167,178,181,188,187,150,145,152,159,138,141,132,131,222,217,208,215,194,197,204,203,230,225,232,239,250,253,244,243];"undefined"!=typeof Int32Array&&(c=new Int32Array(c));var u=a("crc-8",(e,t=0)=>{let i=~~t;for(let t=0;t<e.length;t++)i=255&c[255&(i^e[t])];return i});let l=[0,94,188,226,97,63,221,131,194,156,126,32,163,253,31,65,157,195,33,127,252,162,64,30,95,1,227,189,62,96,130,220,35,125,159,193,66,28,254,160,225,191,93,3,128,222,60,98,190,224,2,92,223,129,99,61,124,34,192,158,29,67,161,255,70,24,250,164,39,121,155,197,132,218,56,102,229,187,89,7,219,133,103,57,186,228,6,88,25,71,165,251,120,38,196,154,101,59,217,135,4,90,184,230,167,249,27,69,198,152,122,36,248,166,68,26,153,199,37,123,58,100,134,216,91,5,231,185,140,210,48,110,237,179,81,15,78,16,242,172,47,113,147,205,17,79,173,243,112,46,204,146,211,141,111,49,178,236,14,80,175,241,19,77,206,144,114,44,109,51,209,143,12,82,176,238,50,108,142,208,83,13,239,177,240,174,76,18,145,207,45,115,202,148,118,40,171,245,23,73,8,86,180,234,105,55,213,139,87,9,235,181,54,104,138,212,149,203,41,119,244,170,72,22,233,183,85,11,136,214,52,106,43,117,151,201,74,20,246,168,116,42,200,150,21,75,169,247,182,232,10,84,215,137,107,53];"undefined"!=typeof Int32Array&&(l=new Int32Array(l));var d=a("dallas-1-wire",(e,t=0)=>{let i=~~t;for(let t=0;t<e.length;t++)i=255&l[255&(i^e[t])];return i});let h=[0,213,127,170,254,43,129,84,41,252,86,131,215,2,168,125,82,135,45,248,172,121,211,6,123,174,4,209,133,80,250,47,164,113,219,14,90,143,37,240,141,88,242,39,115,166,12,217,246,35,137,92,8,221,119,162,223,10,160,117,33,244,94,139,157,72,226,55,99,182,28,201,180,97,203,30,74,159,53,224,207,26,176,101,49,228,78,155,230,51,153,76,24,205,103,178,57,236,70,147,199,18,184,109,16,197,111,186,238,59,145,68,107,190,20,193,149,64,234,63,66,151,61,232,188,105,195,22,239,58,144,69,17,196,110,187,198,19,185,108,56,237,71,146,189,104,194,23,67,150,60,233,148,65,235,62,106,191,21,192,75,158,52,225,181,96,202,31,98,183,29,200,156,73,227,54,25,204,102,179,231,50,152,77,48,229,79,154,206,27,177,100,114,167,13,216,140,89,243,38,91,142,36,241,165,112,218,15,32,245,95,138,222,11,161,116,9,220,118,163,247,34,136,93,214,3,169,124,40,253,87,130,255,42,128,85,1,212,126,171,132,81,251,46,122,175,5,208,173,120,210,7,83,134,44,249];"undefined"!=typeof Int32Array&&(h=new Int32Array(h));var f=a("crc-8-dvbs2",(e,t=0)=>{let i=~~t;for(let t=0;t<e.length;t++)i=255&h[255&(i^e[t])];return i});let p=[0,49345,49537,320,49921,960,640,49729,50689,1728,1920,51009,1280,50625,50305,1088,52225,3264,3456,52545,3840,53185,52865,3648,2560,51905,52097,2880,51457,2496,2176,51265,55297,6336,6528,55617,6912,56257,55937,6720,7680,57025,57217,8e3,56577,7616,7296,56385,5120,54465,54657,5440,55041,6080,5760,54849,53761,4800,4992,54081,4352,53697,53377,4160,61441,12480,12672,61761,13056,62401,62081,12864,13824,63169,63361,14144,62721,13760,13440,62529,15360,64705,64897,15680,65281,16320,16e3,65089,64001,15040,15232,64321,14592,63937,63617,14400,10240,59585,59777,10560,60161,11200,10880,59969,60929,11968,12160,61249,11520,60865,60545,11328,58369,9408,9600,58689,9984,59329,59009,9792,8704,58049,58241,9024,57601,8640,8320,57409,40961,24768,24960,41281,25344,41921,41601,25152,26112,42689,42881,26432,42241,26048,25728,42049,27648,44225,44417,27968,44801,28608,28288,44609,43521,27328,27520,43841,26880,43457,43137,26688,30720,47297,47489,31040,47873,31680,31360,47681,48641,32448,32640,48961,32e3,48577,48257,31808,46081,29888,30080,46401,30464,47041,46721,30272,29184,45761,45953,29504,45313,29120,28800,45121,20480,37057,37249,20800,37633,21440,21120,37441,38401,22208,22400,38721,21760,38337,38017,21568,39937,23744,23936,40257,24320,40897,40577,24128,23040,39617,39809,23360,39169,22976,22656,38977,34817,18624,18816,35137,19200,35777,35457,19008,19968,36545,36737,20288,36097,19904,19584,35905,17408,33985,34177,17728,34561,18368,18048,34369,33281,17088,17280,33601,16640,33217,32897,16448];"undefined"!=typeof Int32Array&&(p=new Int32Array(p));var v=a("crc-16",(e,t=0)=>{let i=~~t;for(let t=0;t<e.length;t++)i=65535&(p[255&(i^e[t])]^i>>8);return i});let g=[0,4129,8258,12387,16516,20645,24774,28903,33032,37161,41290,45419,49548,53677,57806,61935,4657,528,12915,8786,21173,17044,29431,25302,37689,33560,45947,41818,54205,50076,62463,58334,9314,13379,1056,5121,25830,29895,17572,21637,42346,46411,34088,38153,58862,62927,50604,54669,13907,9842,5649,1584,30423,26358,22165,18100,46939,42874,38681,34616,63455,59390,55197,51132,18628,22757,26758,30887,2112,6241,10242,14371,51660,55789,59790,63919,35144,39273,43274,47403,23285,19156,31415,27286,6769,2640,14899,10770,56317,52188,64447,60318,39801,35672,47931,43802,27814,31879,19684,23749,11298,15363,3168,7233,60846,64911,52716,56781,44330,48395,36200,40265,32407,28342,24277,20212,15891,11826,7761,3696,65439,61374,57309,53244,48923,44858,40793,36728,37256,33193,45514,41451,53516,49453,61774,57711,4224,161,12482,8419,20484,16421,28742,24679,33721,37784,41979,46042,49981,54044,58239,62302,689,4752,8947,13010,16949,21012,25207,29270,46570,42443,38312,34185,62830,58703,54572,50445,13538,9411,5280,1153,29798,25671,21540,17413,42971,47098,34713,38840,59231,63358,50973,55100,9939,14066,1681,5808,26199,30326,17941,22068,55628,51565,63758,59695,39368,35305,47498,43435,22596,18533,30726,26663,6336,2273,14466,10403,52093,56156,60223,64286,35833,39896,43963,48026,19061,23124,27191,31254,2801,6864,10931,14994,64814,60687,56684,52557,48554,44427,40424,36297,31782,27655,23652,19525,15522,11395,7392,3265,61215,65342,53085,57212,44955,49082,36825,40952,28183,32310,20053,24180,11923,16050,3793,7920];"undefined"!=typeof Int32Array&&(g=new Int32Array(g));var y=a("ccitt",(e,t)=>{let i=void 0!==t?~~t:65535;for(let t=0;t<e.length;t++)i=65535&(g[255&(i>>8^e[t])]^i<<8);return i});let _=[0,49345,49537,320,49921,960,640,49729,50689,1728,1920,51009,1280,50625,50305,1088,52225,3264,3456,52545,3840,53185,52865,3648,2560,51905,52097,2880,51457,2496,2176,51265,55297,6336,6528,55617,6912,56257,55937,6720,7680,57025,57217,8e3,56577,7616,7296,56385,5120,54465,54657,5440,55041,6080,5760,54849,53761,4800,4992,54081,4352,53697,53377,4160,61441,12480,12672,61761,13056,62401,62081,12864,13824,63169,63361,14144,62721,13760,13440,62529,15360,64705,64897,15680,65281,16320,16e3,65089,64001,15040,15232,64321,14592,63937,63617,14400,10240,59585,59777,10560,60161,11200,10880,59969,60929,11968,12160,61249,11520,60865,60545,11328,58369,9408,9600,58689,9984,59329,59009,9792,8704,58049,58241,9024,57601,8640,8320,57409,40961,24768,24960,41281,25344,41921,41601,25152,26112,42689,42881,26432,42241,26048,25728,42049,27648,44225,44417,27968,44801,28608,28288,44609,43521,27328,27520,43841,26880,43457,43137,26688,30720,47297,47489,31040,47873,31680,31360,47681,48641,32448,32640,48961,32e3,48577,48257,31808,46081,29888,30080,46401,30464,47041,46721,30272,29184,45761,45953,29504,45313,29120,28800,45121,20480,37057,37249,20800,37633,21440,21120,37441,38401,22208,22400,38721,21760,38337,38017,21568,39937,23744,23936,40257,24320,40897,40577,24128,23040,39617,39809,23360,39169,22976,22656,38977,34817,18624,18816,35137,19200,35777,35457,19008,19968,36545,36737,20288,36097,19904,19584,35905,17408,33985,34177,17728,34561,18368,18048,34369,33281,17088,17280,33601,16640,33217,32897,16448];"undefined"!=typeof Int32Array&&(_=new Int32Array(_));var m=a("crc-16-modbus",(e,t)=>{let i=void 0!==t?~~t:65535;for(let t=0;t<e.length;t++)i=65535&(_[255&(i^e[t])]^i>>8);return i});var D=a("xmodem",(e,t)=>{let i=void 0!==t?~~t:0;for(let t=0;t<e.length;t++){let n=i>>>8&255;n^=255&e[t],n^=n>>>4,i=i<<8&65535,i^=n,n=n<<5&65535,i^=n,n=n<<7&65535,i^=n}return i});let b=[0,4489,8978,12955,17956,22445,25910,29887,35912,40385,44890,48851,51820,56293,59774,63735,4225,264,13203,8730,22181,18220,30135,25662,40137,36160,49115,44626,56045,52068,63999,59510,8450,12427,528,5017,26406,30383,17460,21949,44362,48323,36440,40913,60270,64231,51324,55797,12675,8202,4753,792,30631,26158,21685,17724,48587,44098,40665,36688,64495,60006,55549,51572,16900,21389,24854,28831,1056,5545,10034,14011,52812,57285,60766,64727,34920,39393,43898,47859,21125,17164,29079,24606,5281,1320,14259,9786,57037,53060,64991,60502,39145,35168,48123,43634,25350,29327,16404,20893,9506,13483,1584,6073,61262,65223,52316,56789,43370,47331,35448,39921,29575,25102,20629,16668,13731,9258,5809,1848,65487,60998,56541,52564,47595,43106,39673,35696,33800,38273,42778,46739,49708,54181,57662,61623,2112,6601,11090,15067,20068,24557,28022,31999,38025,34048,47003,42514,53933,49956,61887,57398,6337,2376,15315,10842,24293,20332,32247,27774,42250,46211,34328,38801,58158,62119,49212,53685,10562,14539,2640,7129,28518,32495,19572,24061,46475,41986,38553,34576,62383,57894,53437,49460,14787,10314,6865,2904,32743,28270,23797,19836,50700,55173,58654,62615,32808,37281,41786,45747,19012,23501,26966,30943,3168,7657,12146,16123,54925,50948,62879,58390,37033,33056,46011,41522,23237,19276,31191,26718,7393,3432,16371,11898,59150,63111,50204,54677,41258,45219,33336,37809,27462,31439,18516,23005,11618,15595,3696,8185,63375,58886,54429,50452,45483,40994,37561,33584,31687,27214,22741,18780,15843,11370,7921,3960];"undefined"!=typeof Int32Array&&(b=new Int32Array(b));var S=a("kermit",(e,t)=>{let i=void 0!==t?~~t:0;for(let t=0;t<e.length;t++)i=65535&(b[255&(i^e[t])]^i>>8);return i});let w=[0,8801531,9098509,825846,9692897,1419802,1651692,10452759,10584377,2608578,2839604,11344079,3303384,11807523,12104405,4128302,12930697,4391538,5217156,13227903,5679208,13690003,14450021,5910942,6606768,14844747,15604413,6837830,16197969,7431594,8256604,16494759,840169,9084178,8783076,18463,10434312,1670131,1434117,9678590,11358416,2825259,2590173,10602790,4109873,12122826,11821884,3289031,13213536,5231515,4409965,12912278,5929345,14431610,13675660,5693559,6823513,15618722,14863188,6588335,16513208,8238147,7417269,16212302,1680338,10481449,9664223,1391140,9061683,788936,36926,8838341,12067563,4091408,3340262,11844381,2868234,11372785,10555655,2579964,14478683,5939616,5650518,13661357,5180346,13190977,12967607,4428364,8219746,16457881,16234863,7468436,15633027,6866552,6578062,14816117,1405499,9649856,10463030,1698765,8819930,55329,803287,9047340,11858690,3325945,4072975,12086004,2561507,10574104,11387118,2853909,13647026,5664841,5958079,14460228,4446803,12949160,13176670,5194661,7454091,16249200,16476294,8201341,14834538,6559633,6852199,15647388,3360676,11864927,12161705,4185682,10527045,2551230,2782280,11286707,9619101,1346150,1577872,10379115,73852,8875143,9172337,899466,16124205,7357910,8182816,16421083,6680524,14918455,15678145,6911546,5736468,13747439,14507289,5968354,12873461,4334094,5159928,13170435,4167245,12180150,11879232,3346363,11301036,2767959,2532769,10545498,10360692,1596303,1360505,9604738,913813,9157998,8856728,92259,16439492,8164415,7343561,16138546,6897189,15692510,14936872,6662099,5986813,14488838,13733104,5750795,13156124,5174247,4352529,12855018,2810998,11315341,10498427,2522496,12124823,4148844,3397530,11901793,9135439,862644,110658,8912057,1606574,10407765,9590435,1317464,15706879,6940164,6651890,14889737,8145950,16384229,16161043,7394792,5123014,13133629,12910283,4370992,14535975,5997020,5707818,13718737,2504095,10516836,11329682,2796649,11916158,3383173,4130419,12143240,8893606,129117,876971,9121104,1331783,9576124,10389322,1625009,14908182,6633453,6925851,15721184,7380471,16175372,16402682,8127489,4389423,12891860,13119266,5137369,13704398,5722165,6015427,14517560];"undefined"!=typeof Int32Array&&(w=new Int32Array(w));var I=a("crc-24",(e,t)=>{let i=void 0!==t?~~t:11994318;for(let t=0;t<e.length;t++)i=16777215&(w[255&(i>>16^e[t])]^i<<8);return i});let A=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117];"undefined"!=typeof Int32Array&&(A=new Int32Array(A));var B=a("crc-32",(e,t)=>{let i=0===t?0:-1^~~t;for(let t=0;t<e.length;t++)i=A[255&(i^e[t])]^i>>>8;return-1^i});let k=[0,79764919,159529838,222504665,319059676,398814059,445009330,507990021,638119352,583659535,797628118,726387553,890018660,835552979,1015980042,944750013,1276238704,1221641927,1167319070,1095957929,1595256236,1540665371,1452775106,1381403509,1780037320,1859660671,1671105958,1733955601,2031960084,2111593891,1889500026,1952343757,2552477408,2632100695,2443283854,2506133561,2334638140,2414271883,2191915858,2254759653,3190512472,3135915759,3081330742,3009969537,2905550212,2850959411,2762807018,2691435357,3560074640,3505614887,3719321342,3648080713,3342211916,3287746299,3467911202,3396681109,4063920168,4143685023,4223187782,4286162673,3779000052,3858754371,3904687514,3967668269,881225847,809987520,1023691545,969234094,662832811,591600412,771767749,717299826,311336399,374308984,453813921,533576470,25881363,88864420,134795389,214552010,2023205639,2086057648,1897238633,1976864222,1804852699,1867694188,1645340341,1724971778,1587496639,1516133128,1461550545,1406951526,1302016099,1230646740,1142491917,1087903418,2896545431,2825181984,2770861561,2716262478,3215044683,3143675388,3055782693,3001194130,2326604591,2389456536,2200899649,2280525302,2578013683,2640855108,2418763421,2498394922,3769900519,3832873040,3912640137,3992402750,4088425275,4151408268,4197601365,4277358050,3334271071,3263032808,3476998961,3422541446,3585640067,3514407732,3694837229,3640369242,1762451694,1842216281,1619975040,1682949687,2047383090,2127137669,1938468188,2001449195,1325665622,1271206113,1183200824,1111960463,1543535498,1489069629,1434599652,1363369299,622672798,568075817,748617968,677256519,907627842,853037301,1067152940,995781531,51762726,131386257,177728840,240578815,269590778,349224269,429104020,491947555,4046411278,4126034873,4172115296,4234965207,3794477266,3874110821,3953728444,4016571915,3609705398,3555108353,3735388376,3664026991,3290680682,3236090077,3449943556,3378572211,3174993278,3120533705,3032266256,2961025959,2923101090,2868635157,2813903052,2742672763,2604032198,2683796849,2461293480,2524268063,2284983834,2364738477,2175806836,2238787779,1569362073,1498123566,1409854455,1355396672,1317987909,1246755826,1192025387,1137557660,2072149281,2135122070,1912620623,1992383480,1753615357,1816598090,1627664531,1707420964,295390185,358241886,404320391,483945776,43990325,106832002,186451547,266083308,932423249,861060070,1041341759,986742920,613929101,542559546,756411363,701822548,3316196985,3244833742,3425377559,3370778784,3601682597,3530312978,3744426955,3689838204,3819031489,3881883254,3928223919,4007849240,4037393693,4100235434,4180117107,4259748804,2310601993,2373574846,2151335527,2231098320,2596047829,2659030626,2470359227,2550115596,2947551409,2876312838,2788305887,2733848168,3165939309,3094707162,3040238851,2985771188];"undefined"!=typeof Int32Array&&(k=new Int32Array(k));var E=a("crc-32-mpeg",(e,t)=>{let i=void 0!==t?~~t:4294967295;for(let t=0;t<e.length;t++)i=k[255&(i>>24^e[t])]^i<<8;return i});let C=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117];"undefined"!=typeof Int32Array&&(C=new Int32Array(C));var T=a("jam",(e,t=-1)=>{let i=0===t?0:~~t;for(let t=0;t<e.length;t++)i=C[255&(i^e[t])]^i>>>8;return i});t.default={crc1:o,crc8:u,crc81wire:d,crc8dvbs2:f,crc16:v,crc16ccitt:y,crc16modbus:m,crc16xmodem:D,crc16kermit:S,crc24:I,crc32:B,crc32mpeg2:E,crcjam:T}}]);
8
+ var n=i(36),s=i(37),r=i(38);function a(){return c.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function o(e,t){if(a()<t)throw new RangeError("Invalid typed array length");return c.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=c.prototype:(null===e&&(e=new c(t)),e.length=t),e}function c(e,t,i){if(!(c.TYPED_ARRAY_SUPPORT||this instanceof c))return new c(e,t,i);if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return l(this,e)}return u(this,e,t,i)}function u(e,t,i,n){if("number"==typeof t)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer?function(e,t,i,n){if(t.byteLength,i<0||t.byteLength<i)throw new RangeError("'offset' is out of bounds");if(t.byteLength<i+(n||0))throw new RangeError("'length' is out of bounds");t=void 0===i&&void 0===n?new Uint8Array(t):void 0===n?new Uint8Array(t,i):new Uint8Array(t,i,n);c.TYPED_ARRAY_SUPPORT?(e=t).__proto__=c.prototype:e=h(e,t);return e}(e,t,i,n):"string"==typeof t?function(e,t,i){"string"==typeof i&&""!==i||(i="utf8");if(!c.isEncoding(i))throw new TypeError('"encoding" must be a valid string encoding');var n=0|p(t,i),s=(e=o(e,n)).write(t,i);s!==n&&(e=e.slice(0,s));return e}(e,t,i):function(e,t){if(c.isBuffer(t)){var i=0|f(t.length);return 0===(e=o(e,i)).length||t.copy(e,0,0,i),e}if(t){if("undefined"!=typeof ArrayBuffer&&t.buffer instanceof ArrayBuffer||"length"in t)return"number"!=typeof t.length||(n=t.length)!=n?o(e,0):h(e,t);if("Buffer"===t.type&&r(t.data))return h(e,t.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function d(e){if("number"!=typeof e)throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function l(e,t){if(d(t),e=o(e,t<0?0:0|f(t)),!c.TYPED_ARRAY_SUPPORT)for(var i=0;i<t;++i)e[i]=0;return e}function h(e,t){var i=t.length<0?0:0|f(t.length);e=o(e,i);for(var n=0;n<i;n+=1)e[n]=255&t[n];return e}function f(e){if(e>=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|e}function p(e,t){if(c.isBuffer(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var i=e.length;if(0===i)return 0;for(var n=!1;;)switch(t){case"ascii":case"latin1":case"binary":return i;case"utf8":case"utf-8":case void 0:return H(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*i;case"hex":return i>>>1;case"base64":return G(e).length;default:if(n)return H(e).length;t=(""+t).toLowerCase(),n=!0}}function v(e,t,i){var n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return"";if((i>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return C(this,t,i);case"utf8":case"utf-8":return B(this,t,i);case"ascii":return k(this,t,i);case"latin1":case"binary":return E(this,t,i);case"base64":return A(this,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,t,i);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function g(e,t,i){var n=e[t];e[t]=e[i],e[i]=n}function y(e,t,i,n,s){if(0===e.length)return-1;if("string"==typeof i?(n=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),i=+i,isNaN(i)&&(i=s?0:e.length-1),i<0&&(i=e.length+i),i>=e.length){if(s)return-1;i=e.length-1}else if(i<0){if(!s)return-1;i=0}if("string"==typeof t&&(t=c.from(t,n)),c.isBuffer(t))return 0===t.length?-1:_(e,t,i,n,s);if("number"==typeof t)return t&=255,c.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?s?Uint8Array.prototype.indexOf.call(e,t,i):Uint8Array.prototype.lastIndexOf.call(e,t,i):_(e,[t],i,n,s);throw new TypeError("val must be string, number or Buffer")}function _(e,t,i,n,s){var r,a=1,o=e.length,c=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;a=2,o/=2,c/=2,i/=2}function u(e,t){return 1===a?e[t]:e.readUInt16BE(t*a)}if(s){var d=-1;for(r=i;r<o;r++)if(u(e,r)===u(t,-1===d?0:r-d)){if(-1===d&&(d=r),r-d+1===c)return d*a}else-1!==d&&(r-=r-d),d=-1}else for(i+c>o&&(i=o-c),r=i;r>=0;r--){for(var l=!0,h=0;h<c;h++)if(u(e,r+h)!==u(t,h)){l=!1;break}if(l)return r}return-1}function m(e,t,i,n){i=Number(i)||0;var s=e.length-i;n?(n=Number(n))>s&&(n=s):n=s;var r=t.length;if(r%2!=0)throw new TypeError("Invalid hex string");n>r/2&&(n=r/2);for(var a=0;a<n;++a){var o=parseInt(t.substr(2*a,2),16);if(isNaN(o))return a;e[i+a]=o}return a}function D(e,t,i,n){return j(H(t,e.length-i),e,i,n)}function b(e,t,i,n){return j(function(e){for(var t=[],i=0;i<e.length;++i)t.push(255&e.charCodeAt(i));return t}(t),e,i,n)}function S(e,t,i,n){return b(e,t,i,n)}function w(e,t,i,n){return j(G(t),e,i,n)}function I(e,t,i,n){return j(function(e,t){for(var i,n,s,r=[],a=0;a<e.length&&!((t-=2)<0);++a)i=e.charCodeAt(a),n=i>>8,s=i%256,r.push(s),r.push(n);return r}(t,e.length-i),e,i,n)}function A(e,t,i){return 0===t&&i===e.length?n.fromByteArray(e):n.fromByteArray(e.slice(t,i))}function B(e,t,i){i=Math.min(e.length,i);for(var n=[],s=t;s<i;){var r,a,o,c,u=e[s],d=null,l=u>239?4:u>223?3:u>191?2:1;if(s+l<=i)switch(l){case 1:u<128&&(d=u);break;case 2:128==(192&(r=e[s+1]))&&(c=(31&u)<<6|63&r)>127&&(d=c);break;case 3:r=e[s+1],a=e[s+2],128==(192&r)&&128==(192&a)&&(c=(15&u)<<12|(63&r)<<6|63&a)>2047&&(c<55296||c>57343)&&(d=c);break;case 4:r=e[s+1],a=e[s+2],o=e[s+3],128==(192&r)&&128==(192&a)&&128==(192&o)&&(c=(15&u)<<18|(63&r)<<12|(63&a)<<6|63&o)>65535&&c<1114112&&(d=c)}null===d?(d=65533,l=1):d>65535&&(d-=65536,n.push(d>>>10&1023|55296),d=56320|1023&d),n.push(d),s+=l}return function(e){var t=e.length;if(t<=4096)return String.fromCharCode.apply(String,e);var i="",n=0;for(;n<t;)i+=String.fromCharCode.apply(String,e.slice(n,n+=4096));return i}(n)}t.Buffer=c,t.SlowBuffer=function(e){+e!=e&&(e=0);return c.alloc(+e)},t.INSPECT_MAX_BYTES=50,c.TYPED_ARRAY_SUPPORT=void 0!==e.TYPED_ARRAY_SUPPORT?e.TYPED_ARRAY_SUPPORT:function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()&&"function"==typeof e.subarray&&0===e.subarray(1,1).byteLength}catch(e){return!1}}(),t.kMaxLength=a(),c.poolSize=8192,c._augment=function(e){return e.__proto__=c.prototype,e},c.from=function(e,t,i){return u(null,e,t,i)},c.TYPED_ARRAY_SUPPORT&&(c.prototype.__proto__=Uint8Array.prototype,c.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&c[Symbol.species]===c&&Object.defineProperty(c,Symbol.species,{value:null,configurable:!0})),c.alloc=function(e,t,i){return function(e,t,i,n){return d(t),t<=0?o(e,t):void 0!==i?"string"==typeof n?o(e,t).fill(i,n):o(e,t).fill(i):o(e,t)}(null,e,t,i)},c.allocUnsafe=function(e){return l(null,e)},c.allocUnsafeSlow=function(e){return l(null,e)},c.isBuffer=function(e){return!(null==e||!e._isBuffer)},c.compare=function(e,t){if(!c.isBuffer(e)||!c.isBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var i=e.length,n=t.length,s=0,r=Math.min(i,n);s<r;++s)if(e[s]!==t[s]){i=e[s],n=t[s];break}return i<n?-1:n<i?1:0},c.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},c.concat=function(e,t){if(!r(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return c.alloc(0);var i;if(void 0===t)for(t=0,i=0;i<e.length;++i)t+=e[i].length;var n=c.allocUnsafe(t),s=0;for(i=0;i<e.length;++i){var a=e[i];if(!c.isBuffer(a))throw new TypeError('"list" argument must be an Array of Buffers');a.copy(n,s),s+=a.length}return n},c.byteLength=p,c.prototype._isBuffer=!0,c.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)g(this,t,t+1);return this},c.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)g(this,t,t+3),g(this,t+1,t+2);return this},c.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)g(this,t,t+7),g(this,t+1,t+6),g(this,t+2,t+5),g(this,t+3,t+4);return this},c.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?B(this,0,e):v.apply(this,arguments)},c.prototype.equals=function(e){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===c.compare(this,e)},c.prototype.inspect=function(){var e="",i=t.INSPECT_MAX_BYTES;return this.length>0&&(e=this.toString("hex",0,i).match(/.{2}/g).join(" "),this.length>i&&(e+=" ... ")),"<Buffer "+e+">"},c.prototype.compare=function(e,t,i,n,s){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===i&&(i=e?e.length:0),void 0===n&&(n=0),void 0===s&&(s=this.length),t<0||i>e.length||n<0||s>this.length)throw new RangeError("out of range index");if(n>=s&&t>=i)return 0;if(n>=s)return-1;if(t>=i)return 1;if(this===e)return 0;for(var r=(s>>>=0)-(n>>>=0),a=(i>>>=0)-(t>>>=0),o=Math.min(r,a),u=this.slice(n,s),d=e.slice(t,i),l=0;l<o;++l)if(u[l]!==d[l]){r=u[l],a=d[l];break}return r<a?-1:a<r?1:0},c.prototype.includes=function(e,t,i){return-1!==this.indexOf(e,t,i)},c.prototype.indexOf=function(e,t,i){return y(this,e,t,i,!0)},c.prototype.lastIndexOf=function(e,t,i){return y(this,e,t,i,!1)},c.prototype.write=function(e,t,i,n){if(void 0===t)n="utf8",i=this.length,t=0;else if(void 0===i&&"string"==typeof t)n=t,i=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t|=0,isFinite(i)?(i|=0,void 0===n&&(n="utf8")):(n=i,i=void 0)}var s=this.length-t;if((void 0===i||i>s)&&(i=s),e.length>0&&(i<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var r=!1;;)switch(n){case"hex":return m(this,e,t,i);case"utf8":case"utf-8":return D(this,e,t,i);case"ascii":return b(this,e,t,i);case"latin1":case"binary":return S(this,e,t,i);case"base64":return w(this,e,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return I(this,e,t,i);default:if(r)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),r=!0}},c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function k(e,t,i){var n="";i=Math.min(e.length,i);for(var s=t;s<i;++s)n+=String.fromCharCode(127&e[s]);return n}function E(e,t,i){var n="";i=Math.min(e.length,i);for(var s=t;s<i;++s)n+=String.fromCharCode(e[s]);return n}function C(e,t,i){var n=e.length;(!t||t<0)&&(t=0),(!i||i<0||i>n)&&(i=n);for(var s="",r=t;r<i;++r)s+=K(e[r]);return s}function T(e,t,i){for(var n=e.slice(t,i),s="",r=0;r<n.length;r+=2)s+=String.fromCharCode(n[r]+256*n[r+1]);return s}function O(e,t,i){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>i)throw new RangeError("Trying to access beyond buffer length")}function P(e,t,i,n,s,r){if(!c.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>s||t<r)throw new RangeError('"value" argument is out of bounds');if(i+n>e.length)throw new RangeError("Index out of range")}function L(e,t,i,n){t<0&&(t=65535+t+1);for(var s=0,r=Math.min(e.length-i,2);s<r;++s)e[i+s]=(t&255<<8*(n?s:1-s))>>>8*(n?s:1-s)}function x(e,t,i,n){t<0&&(t=4294967295+t+1);for(var s=0,r=Math.min(e.length-i,4);s<r;++s)e[i+s]=t>>>8*(n?s:3-s)&255}function M(e,t,i,n,s,r){if(i+n>e.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function N(e,t,i,n,r){return r||M(e,0,i,4),s.write(e,t,i,n,23,4),i+4}function R(e,t,i,n,r){return r||M(e,0,i,8),s.write(e,t,i,n,52,8),i+8}c.prototype.slice=function(e,t){var i,n=this.length;if((e=~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),(t=void 0===t?n:~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),t<e&&(t=e),c.TYPED_ARRAY_SUPPORT)(i=this.subarray(e,t)).__proto__=c.prototype;else{var s=t-e;i=new c(s,void 0);for(var r=0;r<s;++r)i[r]=this[r+e]}return i},c.prototype.readUIntLE=function(e,t,i){e|=0,t|=0,i||O(e,t,this.length);for(var n=this[e],s=1,r=0;++r<t&&(s*=256);)n+=this[e+r]*s;return n},c.prototype.readUIntBE=function(e,t,i){e|=0,t|=0,i||O(e,t,this.length);for(var n=this[e+--t],s=1;t>0&&(s*=256);)n+=this[e+--t]*s;return n},c.prototype.readUInt8=function(e,t){return t||O(e,1,this.length),this[e]},c.prototype.readUInt16LE=function(e,t){return t||O(e,2,this.length),this[e]|this[e+1]<<8},c.prototype.readUInt16BE=function(e,t){return t||O(e,2,this.length),this[e]<<8|this[e+1]},c.prototype.readUInt32LE=function(e,t){return t||O(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},c.prototype.readUInt32BE=function(e,t){return t||O(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},c.prototype.readIntLE=function(e,t,i){e|=0,t|=0,i||O(e,t,this.length);for(var n=this[e],s=1,r=0;++r<t&&(s*=256);)n+=this[e+r]*s;return n>=(s*=128)&&(n-=Math.pow(2,8*t)),n},c.prototype.readIntBE=function(e,t,i){e|=0,t|=0,i||O(e,t,this.length);for(var n=t,s=1,r=this[e+--n];n>0&&(s*=256);)r+=this[e+--n]*s;return r>=(s*=128)&&(r-=Math.pow(2,8*t)),r},c.prototype.readInt8=function(e,t){return t||O(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},c.prototype.readInt16LE=function(e,t){t||O(e,2,this.length);var i=this[e]|this[e+1]<<8;return 32768&i?4294901760|i:i},c.prototype.readInt16BE=function(e,t){t||O(e,2,this.length);var i=this[e+1]|this[e]<<8;return 32768&i?4294901760|i:i},c.prototype.readInt32LE=function(e,t){return t||O(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},c.prototype.readInt32BE=function(e,t){return t||O(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},c.prototype.readFloatLE=function(e,t){return t||O(e,4,this.length),s.read(this,e,!0,23,4)},c.prototype.readFloatBE=function(e,t){return t||O(e,4,this.length),s.read(this,e,!1,23,4)},c.prototype.readDoubleLE=function(e,t){return t||O(e,8,this.length),s.read(this,e,!0,52,8)},c.prototype.readDoubleBE=function(e,t){return t||O(e,8,this.length),s.read(this,e,!1,52,8)},c.prototype.writeUIntLE=function(e,t,i,n){(e=+e,t|=0,i|=0,n)||P(this,e,t,i,Math.pow(2,8*i)-1,0);var s=1,r=0;for(this[t]=255&e;++r<i&&(s*=256);)this[t+r]=e/s&255;return t+i},c.prototype.writeUIntBE=function(e,t,i,n){(e=+e,t|=0,i|=0,n)||P(this,e,t,i,Math.pow(2,8*i)-1,0);var s=i-1,r=1;for(this[t+s]=255&e;--s>=0&&(r*=256);)this[t+s]=e/r&255;return t+i},c.prototype.writeUInt8=function(e,t,i){return e=+e,t|=0,i||P(this,e,t,1,255,0),c.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},c.prototype.writeUInt16LE=function(e,t,i){return e=+e,t|=0,i||P(this,e,t,2,65535,0),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):L(this,e,t,!0),t+2},c.prototype.writeUInt16BE=function(e,t,i){return e=+e,t|=0,i||P(this,e,t,2,65535,0),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):L(this,e,t,!1),t+2},c.prototype.writeUInt32LE=function(e,t,i){return e=+e,t|=0,i||P(this,e,t,4,4294967295,0),c.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):x(this,e,t,!0),t+4},c.prototype.writeUInt32BE=function(e,t,i){return e=+e,t|=0,i||P(this,e,t,4,4294967295,0),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):x(this,e,t,!1),t+4},c.prototype.writeIntLE=function(e,t,i,n){if(e=+e,t|=0,!n){var s=Math.pow(2,8*i-1);P(this,e,t,i,s-1,-s)}var r=0,a=1,o=0;for(this[t]=255&e;++r<i&&(a*=256);)e<0&&0===o&&0!==this[t+r-1]&&(o=1),this[t+r]=(e/a>>0)-o&255;return t+i},c.prototype.writeIntBE=function(e,t,i,n){if(e=+e,t|=0,!n){var s=Math.pow(2,8*i-1);P(this,e,t,i,s-1,-s)}var r=i-1,a=1,o=0;for(this[t+r]=255&e;--r>=0&&(a*=256);)e<0&&0===o&&0!==this[t+r+1]&&(o=1),this[t+r]=(e/a>>0)-o&255;return t+i},c.prototype.writeInt8=function(e,t,i){return e=+e,t|=0,i||P(this,e,t,1,127,-128),c.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},c.prototype.writeInt16LE=function(e,t,i){return e=+e,t|=0,i||P(this,e,t,2,32767,-32768),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):L(this,e,t,!0),t+2},c.prototype.writeInt16BE=function(e,t,i){return e=+e,t|=0,i||P(this,e,t,2,32767,-32768),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):L(this,e,t,!1),t+2},c.prototype.writeInt32LE=function(e,t,i){return e=+e,t|=0,i||P(this,e,t,4,2147483647,-2147483648),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):x(this,e,t,!0),t+4},c.prototype.writeInt32BE=function(e,t,i){return e=+e,t|=0,i||P(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):x(this,e,t,!1),t+4},c.prototype.writeFloatLE=function(e,t,i){return N(this,e,t,!0,i)},c.prototype.writeFloatBE=function(e,t,i){return N(this,e,t,!1,i)},c.prototype.writeDoubleLE=function(e,t,i){return R(this,e,t,!0,i)},c.prototype.writeDoubleBE=function(e,t,i){return R(this,e,t,!1,i)},c.prototype.copy=function(e,t,i,n){if(i||(i=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<i&&(n=i),n===i)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(i<0||i>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-i&&(n=e.length-t+i);var s,r=n-i;if(this===e&&i<t&&t<n)for(s=r-1;s>=0;--s)e[s+t]=this[s+i];else if(r<1e3||!c.TYPED_ARRAY_SUPPORT)for(s=0;s<r;++s)e[s+t]=this[s+i];else Uint8Array.prototype.set.call(e,this.subarray(i,i+r),t);return r},c.prototype.fill=function(e,t,i,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=0,i=this.length):"string"==typeof i&&(n=i,i=this.length),1===e.length){var s=e.charCodeAt(0);s<256&&(e=s)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!c.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<i)throw new RangeError("Out of range index");if(i<=t)return this;var r;if(t>>>=0,i=void 0===i?this.length:i>>>0,e||(e=0),"number"==typeof e)for(r=t;r<i;++r)this[r]=e;else{var a=c.isBuffer(e)?e:H(new c(e,n).toString()),o=a.length;for(r=0;r<i-t;++r)this[r+t]=a[r%o]}return this};var U=/[^+\/0-9A-Za-z-_]/g;function K(e){return e<16?"0"+e.toString(16):e.toString(16)}function H(e,t){var i;t=t||1/0;for(var n=e.length,s=null,r=[],a=0;a<n;++a){if((i=e.charCodeAt(a))>55295&&i<57344){if(!s){if(i>56319){(t-=3)>-1&&r.push(239,191,189);continue}if(a+1===n){(t-=3)>-1&&r.push(239,191,189);continue}s=i;continue}if(i<56320){(t-=3)>-1&&r.push(239,191,189),s=i;continue}i=65536+(s-55296<<10|i-56320)}else s&&(t-=3)>-1&&r.push(239,191,189);if(s=null,i<128){if((t-=1)<0)break;r.push(i)}else if(i<2048){if((t-=2)<0)break;r.push(i>>6|192,63&i|128)}else if(i<65536){if((t-=3)<0)break;r.push(i>>12|224,i>>6&63|128,63&i|128)}else{if(!(i<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;r.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128)}}return r}function G(e){return n.toByteArray(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(U,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function j(e,t,i,n){for(var s=0;s<n&&!(s+i>=t.length||s>=e.length);++s)t[s+i]=e[s];return s}}).call(this,i(18))},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}),i(33);const s=n(i(34)),r=n(i(4));t.errorCode=r.default;const a=i(17);t.BleHandle=a.BleHandle,t.default=s.default},function(e,t){},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=i(16),a=i(17),o=s(i(49)),c=s(i(50)),u=s(i(56)),d=s(i(3)),l=s(i(4)),h=i(57),f=i(26),p=i(8),v=s(i(11)),g=i(9),y=i(1),_=i(58),m=s(i(0)),D=i(60),b=i(61),S=s(i(5)),w=s(i(62)),I=s(i(63)),A=s(i(64)),B=s(i(65)),k=I.default.version;class E{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:a,offlineThreshold:o})=>{this.productInfo=i,r.setGlobalData("appID",e),r.setGlobalData("appSecret",t),r.setGlobalData("productInfo",i),r.setGlobalData("token",s),r.setGlobalData("uid",a),this.setDomain(n),this.offlineThreshold=o,d.default.debug(`init sdk success, current version: ${E.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 g.unpack(y.hexStrint2byte(t),i.productKey);(null==e?void 0:e.kvData)&&this.listenerMap.GizDeviceAttrsNotifications&&this.listenerMap.GizDeviceAttrsNotifications.map(t=>{t({device:i,data:null==e?void 0:e.kvData})})}})),this.handleBleDeviceData=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>t.bleDeviceID===e.deviceId);if(i){const s=y.hexStrint2byte(t);switch(new m.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);b.uploadP0({device:i,data:[{raw:t,created_at:n}],productSecret:e.productSecret}).then(e=>{d.default.debug("设备上报数据:timestemp",new Date(1e3*n).toLocaleString(),e)})}}const e=yield g.unpack(y.hexStrint2byte(t),i.productKey);(null==e?void 0:e.kvData)&&this.listenerMap.GizDeviceAttrsNotifications&&this.listenerMap.GizDeviceAttrsNotifications.map(t=>{t({device:i,data:null==e?void 0:e.kvData})});break}case"0062":{const t=new A.default(s);d.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*(){d.default.debug("代理重置结果",t),t.success&&t.data.successDevices.length>0&&(d.default.debug("重置成功,回写数据"),yield this.bleHandle.write(e.deviceId,p.numberArray2Uint8Array(B.default.pack(0)).buffer))})));break}case"0064":break;case"0052":{const t=new D.RequestSync(s);if(d.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}),d.default.debug("查询第一条离线数据"),yield this.bleHandle.write(e.deviceId,p.numberArray2Uint8Array(D.SyncPackage.pack(0)).buffer)):(d.default.debug("设备返回状态为1,同步失败"),this.syncDataCallBack({event:"SYNC_FAIL"}));break}case"0054":{if(!this.syncDataCallBack)break;d.default.debug("设备上报离线数据");const t=new D.SyncPackage(s),i=D.DeletePackage.pack(t.id);d.default.debug("设备上报离线数据:payload",t.payload);try{d.default.debug("设备上报离线数据:timestemp",new Date(1e3*t.timestemp).toLocaleString())}catch(e){}const n=this.productInfo.find(e=>e.productKey===this.syncDevice.productKey);if(n){const e=yield b.uploadP0({device:this.syncDevice,data:[{raw:y.arrayToString(t.payload),created_at:t.timestemp}],productSecret:n.productSecret});d.default.debug("上传离线数据结果",e)}this.syncCurrnetNum+=1,this.syncDataCallBack({event:"SYNC_PROGRESS",totalNum:this.syncTotalNum,currentNum:this.syncCurrnetNum}),d.default.debug("通知设备删除:",t.id),yield this.bleHandle.write(e.deviceId,p.numberArray2Uint8Array(i).buffer),yield S.default(100),t.id<this.syncTotalNum-1?(d.default.debug("查询新数据:",t.id+1),yield this.bleHandle.write(e.deviceId,p.numberArray2Uint8Array(D.SyncPackage.pack(t.id+1)).buffer)):(d.default.debug("send cancel sync to device"),this.bleHandle.write(e.deviceId,p.numberArray2Uint8Array(D.CancelSync.pack()).buffer),this.syncDataCallBack({event:"SYNC_END"}),this.cleanSyncDeviceData());break}case"0058":{if(!this.syncDataCallBack)break;const e=new D.CancelSync(s);d.default.debug("设备上报停止同步 state:",e.state),0===e.state?this.syncDataCallBack({event:"SYNC_END"}):this.syncDataCallBack({event:"SYNC_FAIL"}),this.cleanSyncDeviceData();break}}}})),this.handleSocketDeviceData=e=>n(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>t.did===e.did);if(t){if(e.attrs&&null!=e.attrs.is_online){const i=e.attrs.is_online;this.setDeviceMeta(t,"isOnline",i)}this.listenerMap.GizDeviceAttrsNotifications&&(e.attrs&&(e.attrs=yield g.formatEnum(e.attrs,t.productKey,"int")),this.listenerMap.GizDeviceAttrsNotifications.map(i=>{i(Object.assign({device:t},"attrs"in e?{data:e.attrs}:{raw:e.raw}))}))}})),this.handleSocketStatus=(e,t)=>{const i=this.allDevices.filter(t=>e.includes(t.did)&&"WAN"===t.connectType);d.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){d.default.error("init lan error",e)}},this.startAutoScan=e=>{this.keepScanTimer||(this.keepScanTimer=setInterval(()=>n(this,void 0,void 0,(function*(){this.bleHandle.startScan(e=>{this.bleDevices=e},-1,e)})),9e3),this.bleHandle.startScan(e=>{this.bleDevices=e},-1,e))},this.stopAutoScan=()=>{this.keepScanTimer&&clearInterval(this.keepScanTimer),this.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.initBle=()=>n(this,void 0,void 0,(function*(){const e=yield this.bleHandle.checkPermission();return e.success?(this.bleHandle.addEventListener("GizBleDeviceData",this.handleBleDeviceData),this.bleHandle.addEventListener("GizBleDeviceList",this.handleBleDevices),this.bleHandle.addEventListener("GizBleError",this.handleBleError),d.default.debug("init BLE succcess",e),{success:!0}):(d.default.error("init BLE Error",new Error(JSON.stringify(e))),{success:!1,err:l.default.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON})})),this.scanBleDevice=(e,t)=>n(this,void 0,void 0,(function*(){return this.bleHandle.scanList=[],{success:!0,data:(yield this.bleHandle.startScan(e=>{this.bleDevices=e},e,t)).scanList}})),this.write=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>p.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};if("NONE"!==i.connectType){const{data:e,raw:n}=yield g.pack(t,i.productKey);switch(i.connectType){case"BLE_BROADCAST":return yield this.bleHandle.writeBoradcast(i.bleDeviceID,n.cmd);case"BLE":return e?yield this.bleHandle.write(i.bleDeviceID,p.numberArray2Uint8Array(e).buffer):{success:!1};case"WAN":{const e=yield g.formatEnum(t,i.productKey,"string");return this.socketHandle.writeData(i,e)}case"LAN":return this.lanHandle.write(i,p.numberArray2Uint8Array(e).buffer)}}return{success:!1}})),this.writeRaw=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>p.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};if("NONE"!==i.connectType)switch(i.connectType){case"BLE_BROADCAST":return yield this.bleHandle.writeBoradcast(i.bleDeviceID,t);case"BLE":return t?yield this.bleHandle.write(i.bleDeviceID,p.numberArray2Uint8Array(t).buffer):{success:!1};case"WAN":return this.socketHandle.send(i.did,t);case"LAN":return this.lanHandle.write(i,p.numberArray2Uint8Array(t).buffer)}return{success:!1}})),this.setDeviceTimeStamp=e=>n(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>p.isSameDevice(t,e));if(!t)return{success:!1,message:"target is undefind"};const i=w.default.pack();switch(t.connectType){case"BLE":return this.bleHandle.write(e.bleDeviceID,p.numberArray2Uint8Array(i).buffer)}return{success:!1,message:"the connectType not support set timestamp"}})),this.syncDeviceData=(e,t=(()=>{}))=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>p.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};if(!i.isBind)return{success:!1,message:"Only the bound devices are supported"};if(this.syncDevice)return{success:!1,message:"Synchronizing"};switch(this.syncDevice=Object.assign({},i),i.connectType){case"BLE":{d.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 d.default.debug("sent RequestSync data"),this.bleHandle.write(e.bleDeviceID,p.numberArray2Uint8Array(i).buffer)}}return{success:!1,message:"the connectType not support sync data"}})),this.queryNeedSyncDataLength=e=>n(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>p.isSameDevice(t,e));if(!t)return{success:!1,message:"target is undefind"};if(!t.isBind)return{success:!1,message:"Only the bound devices are supported"};switch(t.connectType){case"BLE":{const i=D.RequestSync.pack();return this.syncDevice=Object.assign({},t),d.default.debug("sent RequestSync data len"),this.bleHandle.write(e.bleDeviceID,p.numberArray2Uint8Array(i).buffer),new Promise(e=>{this.syncDataLengthCallback=e,setTimeout(()=>{try{e({success:!1,message:"timeout"})}catch(e){}},3e3)})}}return{success:!1,message:"the connectType not support sync data"}})),this.cancelSyncDeviceData=()=>n(this,void 0,void 0,(function*(){this.cleanSyncDeviceData()})),this.cleanSyncDeviceData=()=>{this.syncDataCallBack&&(this.syncDataCallBack({event:"SYNC_CANCEL"}),this.syncDataCallBack=null),this.syncCurrnetNum=0,this.syncTotalNum=0,this.syncDevice=null,this.syncDataTimoutTimer&&clearTimeout(this.syncDataTimoutTimer)},this.getProductConfig=e=>n(this,void 0,void 0,(function*(){const t=yield v.default.getConfigFile(e);return t?{success:!0,data:t}:{success:!1}})),this.stopScanBleDevice=()=>{this.bleHandle.stopScan()},this.login=e=>n(this,void 0,void 0,(function*(){var t,i;const n=yield h.AnonymousLogin({uid:e});return n.success&&(r.setGlobalData("token",null===(t=n.data)||void 0===t?void 0:t.token),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=>p.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};switch(i.connectType){case"BLE":return yield this.bleHandle.getDeviceStatus(i.bleDeviceID,i.productKey,i.rootDeviceId,t);case"WAN":return this.socketHandle.readStatus(i,t);default:return{success:!1,message:"Device connectType is unsupported"}}})),this.subscribe=(e,t,i=!0)=>n(this,void 0,void 0,(function*(){d.default.debug("subscribe device:",e);let i=this.allDevices.find(t=>p.isSameDevice(t,e));if(!i)return d.default.warn("Device Target Not Found"),d.default.warn("current devices ",this.allDevices),{success:!1,message:"device not found"};if("BLE_BROADCAST"===i.connectType)return{success:!0};const n=p.getFirstConnectType(i,t);switch("NONE"!==i.connectType&&i.connectType!==n&&(yield this.unSubscribe(i)),n){case"BLE":{const e=yield this.bleHandle.connectDevice(i.bleDeviceID);return e.success&&(this.setDeviceMeta(i,"connectType","BLE",!0),setTimeout(()=>{this.setDeviceTimeStamp(i)},250),setTimeout(()=>{this.getDeviceStatus(i)},500)),e}case"WAN":{const t=this.socketHandle.connectDevice(i);return t.success&&this.setDeviceMeta(e,"connectType","WAN",!0),t}case"LAN":{const t=yield this.lanHandle.connectDevice(i);return t.success&&this.setDeviceMeta(e,"connectType","LAN",!0),t}}return{success:!1}})),this.unSubscribe=e=>n(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>p.isSameDevice(t,e));switch(t.connectType){case"BLE":{const e=yield this.bleHandle.disConnectDevice(t.bleDeviceID);return e.success&&this.setDeviceMeta(t,"connectType","NONE",!0),e}case"WAN":{const e=this.socketHandle.disConnectDevice(t);return e.success&&this.setDeviceMeta(t,"connectType","NONE",!0),e}case"LAN":{const e=this.lanHandle.disConnectDevice(t);return e.success&&this.setDeviceMeta(t,"connectType","NONE",!0),e}}return{success:!1}})),this.bindRemoteDevice=({mac:e,productKey:t,alias:i,beOwner:s})=>n(this,void 0,void 0,(function*(){const n=p.getProductInfoThroughPK(t,this.productInfo);if(n){const r=yield f.bindMac({mac:e,productKey:t,productSecret:n.productSecret,alias:i,beOwner:s});return this.getBindingList(),r}return{success:!1,err:l.default.GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY}})),this.checkUpdate=({device:e,type:t})=>n(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>p.isSameDevice(t,e));if(i){if(!i.did)return{success:!1,err:l.default.GIZ_OPENAPI_DEVICE_NOT_BOUND};switch(i.connectType){case"BLE":return this.bleHandle.checkUpdate({deviceId:e.bleDeviceID,did:e.did,type:t});default:return{success:!1,err:l.default.GIZ_SDK_OTA_DEVICE_NOT_SUPPORT}}}return{success:!1,err:l.default.GIZ_SDK_DEVICE_NOT_SUBSCRIBED}})),this.getDeviceInfo=({device:e})=>n(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>p.isSameDevice(t,e));if(t){if(!t.did)return{success:!1,err:l.default.GIZ_OPENAPI_DEVICE_NOT_BOUND};switch(t.connectType){case"BLE":return this.bleHandle.getDeviceInfo({deviceId:e.bleDeviceID});default:return{success:!1,err:l.default.GIZ_SDK_OTA_DEVICE_NOT_SUPPORT}}}return{success:!1,err:l.default.GIZ_SDK_DEVICE_NOT_SUBSCRIBED}})),this.startUpgrade=({device:e,type:t,onProgress:i,onEvent:s})=>n(this,void 0,void 0,(function*(){const n=this.allDevices.find(t=>p.isSameDevice(t,e));if(n){if(!n.did)return{success:!1,err:l.default.GIZ_OPENAPI_DEVICE_NOT_BOUND};switch(n.connectType){case"BLE":return this.bleHandle.startUpgrade({deviceId:e.bleDeviceID,did:e.did,type:t,productKey:e.productKey,onProgress:i,onEvent:s});default:return{success:!1,err:l.default.GIZ_SDK_OTA_DEVICE_NOT_SUPPORT}}}return{success:!1,err:l.default.GIZ_SDK_DEVICE_NOT_SUBSCRIBED}})),this.unbindDevice=({devices:e})=>n(this,void 0,void 0,(function*(){const t=yield f.unbindDevice({devices:e});return t.success&&this.getBindingList(),t})),this.deviceSafetyRegister=({mac:e,productKey:t})=>n(this,void 0,void 0,(function*(){return yield this.deviceSafetyApi({mac:e,productKey:t,isReset:!1})})),this.deviceSafetyUnbind=({mac:e,productKey:t})=>n(this,void 0,void 0,(function*(){return yield this.deviceSafetyApi({mac:e,productKey:t,isReset:!0})})),this.setDeviceOnboardingDeploy=({ssid:e,password:t,mode:i=0,timeout:s,isBind:r=!0,softAPSSIDPrefix:a})=>n(this,void 0,void 0,(function*(){if(this.currentWifiConfigHandle)return{success:!1,err:l.default.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING};const n=(new Date).getTime();d.default.debug("GIZ_SDK: 配网开始时间:"+n);try{switch(i){case 0:{this.currentWifiConfigHandle=new c.default(e,t,this.specialProductKeys,this.specialProductKeySecrets);const i=yield this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:s,isBind:r,softAPSSIDPrefix:a});this.currentWifiConfigHandle=null;const o=(new Date).getTime();return d.default.debug("GIZ_SDK: 配网结束时间:"+o),d.default.debug("GIZ_SDK: 配网用时:"+(o-n)),i}case 3:{this.currentWifiConfigHandle=new u.default(e,t,this.specialProductKeys,this.specialProductKeySecrets,this.bleHandle);const i=yield this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:s,isBind:r,softAPSSIDPrefix:a});this.currentWifiConfigHandle=null;const o=(new Date).getTime();return d.default.debug("GIZ_SDK: 配网结束时间:"+o),d.default.debug("GIZ_SDK: 配网用时:"+(o-n)),i}}}catch(e){return d.default.error("GIZ_SDK: setDeviceOnboardingDeploy",new Error(JSON.stringify(e))),e.err&&e.err.errorCode?e:{success:!1,err:l.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});r.setGlobalData("cloudServiceInfo",i)},this.deviceSafetyApi=({mac:e,productKey:t,isReset:i})=>n(this,void 0,void 0,(function*(){const n=p.getProductInfoThroughPK(t,this.productInfo);return n?yield f.safeRegister({productKey:t,productSecret:n.productSecret,mac:e,isReset:i,passcode:"1234567890"}):{success:!1,err:l.default.GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY}})),this.getBindingList=()=>n(this,void 0,void 0,(function*(){const e=yield f.getBindingList();return this.deviceList=e.data||[],e})),this.getDevices=()=>n(this,void 0,void 0,(function*(){return yield this.getBindingList(),{success:!0,data:this.allDevices}})),this.stopDeviceOnboardingDeploy=()=>{this.currentWifiConfigHandle&&(this.currentWifiConfigHandle.stopDeviceOnboardingDeploy(),this.currentWifiConfigHandle=null)},this.setLogLevel=e=>d.default.setLogLevel(e),this.renameDevice=(e,t)=>n(this,void 0,void 0,(function*(){return t?e.isBind?yield f.editBindInfo({did:e.did,name:t}):{success:!1,message:"device not bind"}:{success:!1,message:"please input device name"}})),this.removeEventListener=(e,t)=>{if(this.listenerMap[e]){const i=this.listenerMap[e].indexOf(t);if(-1!==i)return this.listenerMap[e].splice(i,1),{success:!0}}return{success:!1}},this.addEventListener=(e,t)=>n(this,void 0,void 0,(function*(){return this.listenerMap[e]||(this.listenerMap[e]=[]),-1===this.listenerMap[e].indexOf(t)&&this.listenerMap[e].push(t),{success:!0}})),this.destory=()=>{this.bleHandle.destory(),this.lanHandle.destory(),this.socketHandle.destory(),this.keepScanTimer&&clearInterval(this.keepScanTimer)},this.init(e)}get deviceList(){return this._deviceList}set deviceList(e){this._deviceList=e,this.notiDeviceList()}get bleDevices(){return this._bleDevices}set bleDevices(e){this._bleDevices=e,this.notiDeviceList()}get lanDevices(){return this._lanDevices}set lanDevices(e){this._lanDevices=e,this.notiDeviceList()}get allDevices(){let e=p.merageBleLocalDevices([...this.deviceList],this.bleDevices);e=p.merageLanLocalDevices(e,this.lanDevices),this.bleHandle.connectedList.map(t=>{const i=e.findIndex(e=>e.bleDeviceID===t.deviceId);-1!==i&&(e[i].connectType="BLE")});const t=this.socketHandle._connections;return Object.keys(t).forEach(i=>{const n=t[i];n&&n._subDids.forEach(t=>{const i=e.findIndex(e=>e.did===t);-1!==i&&(e[i].connectType="WAN")})}),this.lanHandle.connectedList.map(t=>{const i=e.findIndex(e=>e.mac===t.mac&&e.productKey===t.productKey);-1!==i&&(e[i].connectType="LAN")}),e}get bleScanDevice(){return this.bleDevices.filter(e=>!0===e.isBleOnline)}get bleHandle(){return this._bleHandle||(this._bleHandle=new a.BleHandle({pks:this.specialProductKeys,offlineThreshold:this.offlineThreshold})),this._bleHandle}get lanHandle(){return this._lanHandle||(this._lanHandle=new _.LanHandle({pks:this.specialProductKeys})),this._lanHandle}get socketHandle(){return this._gizSocket||(this._gizSocket=new o.default({appID:r.getGlobalData("appID"),token:r.getGlobalData("token"),uid: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===r.getGlobalData("appID")&&i===r.getGlobalData("token")&&s===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:""})}}E.getVersion=()=>({success:!0,data:k}),t.default=E},function(e,t){},function(e,t,i){"use strict";t.byteLength=function(e){var t=u(e),i=t[0],n=t[1];return 3*(i+n)/4-n},t.toByteArray=function(e){var t,i,n=u(e),a=n[0],o=n[1],c=new r(function(e,t,i){return 3*(t+i)/4-i}(0,a,o)),d=0,l=o>0?a-4:a;for(i=0;i<l;i+=4)t=s[e.charCodeAt(i)]<<18|s[e.charCodeAt(i+1)]<<12|s[e.charCodeAt(i+2)]<<6|s[e.charCodeAt(i+3)],c[d++]=t>>16&255,c[d++]=t>>8&255,c[d++]=255&t;2===o&&(t=s[e.charCodeAt(i)]<<2|s[e.charCodeAt(i+1)]>>4,c[d++]=255&t);1===o&&(t=s[e.charCodeAt(i)]<<10|s[e.charCodeAt(i+1)]<<4|s[e.charCodeAt(i+2)]>>2,c[d++]=t>>8&255,c[d++]=255&t);return c},t.fromByteArray=function(e){for(var t,i=e.length,s=i%3,r=[],a=0,o=i-s;a<o;a+=16383)r.push(d(e,a,a+16383>o?o:a+16383));1===s?(t=e[i-1],r.push(n[t>>2]+n[t<<4&63]+"==")):2===s&&(t=(e[i-2]<<8)+e[i-1],r.push(n[t>>10]+n[t>>4&63]+n[t<<2&63]+"="));return r.join("")};for(var n=[],s=[],r="undefined"!=typeof Uint8Array?Uint8Array:Array,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0,c=a.length;o<c;++o)n[o]=a[o],s[a.charCodeAt(o)]=o;function u(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var i=e.indexOf("=");return-1===i&&(i=t),[i,i===t?0:4-i%4]}function d(e,t,i){for(var s,r,a=[],o=t;o<i;o+=3)s=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(255&e[o+2]),a.push(n[(r=s)>>18&63]+n[r>>12&63]+n[r>>6&63]+n[63&r]);return a.join("")}s["-".charCodeAt(0)]=62,s["_".charCodeAt(0)]=63},function(e,t){t.read=function(e,t,i,n,s){var r,a,o=8*s-n-1,c=(1<<o)-1,u=c>>1,d=-7,l=i?s-1:0,h=i?-1:1,f=e[t+l];for(l+=h,r=f&(1<<-d)-1,f>>=-d,d+=o;d>0;r=256*r+e[t+l],l+=h,d-=8);for(a=r&(1<<-d)-1,r>>=-d,d+=n;d>0;a=256*a+e[t+l],l+=h,d-=8);if(0===r)r=1-u;else{if(r===c)return a?NaN:1/0*(f?-1:1);a+=Math.pow(2,n),r-=u}return(f?-1:1)*a*Math.pow(2,r-n)},t.write=function(e,t,i,n,s,r){var a,o,c,u=8*r-s-1,d=(1<<u)-1,l=d>>1,h=23===s?Math.pow(2,-24)-Math.pow(2,-77):0,f=n?0:r-1,p=n?1:-1,v=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(o=isNaN(t)?1:0,a=d):(a=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-a))<1&&(a--,c*=2),(t+=a+l>=1?h/c:h*Math.pow(2,1-l))*c>=2&&(a++,c/=2),a+l>=d?(o=0,a=d):a+l>=1?(o=(t*c-1)*Math.pow(2,s),a+=l):(o=t*Math.pow(2,l-1)*Math.pow(2,s),a=0));s>=8;e[i+f]=255&o,f+=p,o/=256,s-=8);for(a=a<<s|o,u+=s;u>0;e[i+f]=255&a,f+=p,a/=256,u-=8);e[i+f-p]|=128*v}},function(e,t){var i={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==i.call(e)}},function(e,t,i){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=n(i(7)),r=n(i(19));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:s.default(`${(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)};r.default("https://appmonitor.gizwits.com/api/21/store/?sentry_key=0b2de791abf548a1bedf0b0ebdd8ecc7&sentry_version=7",n)}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(11)),a=s(i(0)),o=i(1);class c extends a.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 a=[0];const c=[0,147];let u=[0,0,0,0],d=[2];if(t){a=[1];const e=o.fillString(t.length.toString(16),4),i=o.hexStrint2byte(e),n=o.string2Bytes(t);u=u.concat(i).concat(n)}if(e){d=[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=o.fillString(e,8*Math.ceil(e.length/8)),d=d.concat(o.hexStrint2byte(parseInt(e,2).toString(16)))}const l=a.concat(c).concat(u).concat(d);return r[0]=l.length,s.concat(r).concat(l)}return null})),t.default=c},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(6));t.checkUpdate=function({did:e,type:t,hardVersion:i,softVersion:s}){return n(this,void 0,void 0,(function*(){const n="MCU"==t?"2":"1";return r.default(`/app/ota/v4.1/update_and_check/${e}`,{data:{type:n,hard_version:i,soft_version:s,https:"1"},method:"POST"},!0)}))}},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(0)),r=i(1);class a extends s.default{constructor(e){super(e),this.moduleSoftVersion="",this.moduleHardVersion="",this.mcuSoftVersion="",this.mcuHardVersion="",this.businessVersion="";let t=0;this.moduleHardVersion=r.arrayToASCII(this.content.slice(t,t+8)),t+=8,this.moduleSoftVersion=r.arrayToASCII(this.content.slice(t,t+8)),t+=8,this.mcuHardVersion=r.arrayToASCII(this.content.slice(t,t+8)),t+=8,this.mcuSoftVersion=r.arrayToASCII(this.content.slice(t,t+8)),t+=8,this.businessVersion=r.arrayToASCII(this.content.slice(t,t+8)),t+=8}}a.pack=()=>[0,0,0,3,3,0,0,19],t.default=a},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(0));class r extends s.default{constructor(e){super(e),this.type="MCU",this.state=0,this.version=0;let t=0;this.type=1===this.content[t]?"MODULE":"MCU",t+=1,this.state=this.content[t],t+=1,this.version=this.content[t]}}r.pack=e=>[0,0,0,3,4,0,0,65,"MCU"===e?2:1],t.default=r},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(9),r=n(i(0)),a=i(1);class o extends r.default{constructor(e){super(e),this.state=0,this.processedLen=0,this.processedCrc32="",this.packageMaxLen=20;let t=0;this.state=this.content[t],t+=1,this.processedLen=a.bytesToInt(this.content.slice(t,t+4)),t+=4,this.processedCrc32=a.bytesToHexString(this.content.slice(t,t+4)),t+=4,this.packageMaxLen=a.bytesToInt(this.content.slice(t,t+2))}}o.pack=(e,t,i,n,r)=>{const o=a.string2Bytes(e),c=e.length,u=a.string2Bytes(a.fillString(t,8)),d=a.hexStrint2byte(i),l=a.hexStrint2byte(a.fillString(r.toString(16),8)),h=a.hexStrint2byte(a.fillString(n.toString(16),8));let f=[0];f=f.concat([0,67],[c],o,u,d,h,l);const p=s.getVariableLength(f);return[0,0,0,3].concat(p,f)},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(0)),r=i(1);class a extends s.default{constructor(e){super(e)}}a.pack=e=>[0,0,0,3,7,0,0,69,...r.hexStrint2byte(r.fillString(e.toString(16),8))],t.default=a},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(30),r=i(9),a=n(i(0)),o=i(1);class c extends a.default{constructor(e){super(e),this.packageNum=0,this.state=0;let t=0;this.packageNum=o.bytesToInt(this.content.slice(t,t+2)),t+=2,this.state=this.content[t]}}c.pack=(e,t)=>{const i=o.hexStrint2byte(o.fillString(t.toString(16),4)),n=o.hexStrint2byte(o.fillString(e.length.toString(16),4)),a=o.fillString(s.crc16modbus(new Uint8Array(e)).toString(16),4),c=o.hexStrint2byte(a);let u=[0];u=u.concat([0,71],i,n,c,e);const d=r.getVariableLength(u);return[0,0,0,3].concat(d,u)},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});const s=n(i(0));class r extends s.default{constructor(e){super(e),this.state=0,this.state=this.content[0]}}r.pack=e=>[0,0,0,3],t.default=r},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(0));class r extends s.default{constructor(e){super(e),this.state=0;this.state=this.content[0]}}r.pack=e=>[0,0,0,3,4,0,0,80,e],t.default=r},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(4)),a=s(i(3)),o=s(i(6)),c=i(8);t.default=class{constructor({appID:e,token:t,uid:i,limitSocketNum:s=!0}){this._bindingDevices=null,this._connections={},this.updateToken=({token:e,uid:t})=>{this.token=e,this.uid=t},this._getDevice=e=>{if(null===this._bindingDevices)return r.default.GIZ_SDK_SDK_NOT_INITIALIZED;const t=this._bindingDevices[e];return null==t?r.default.GIZ_OPENAPI_DEVICE_NOT_BOUND:t},this._getConnect=e=>{const t=this._getWebsocketConnInfo(e);return this._connections[t]},this._getDeviceAndConnect=e=>{const t=this._getDevice(e);if(c.isError(t))return t;const i=this._getConnect(t);return null==i?r.default.GIZ_SDK_DEVICE_NOT_SUBSCRIBED:[t,i]},this.connectDevice=e=>{const t=this._getWebsocketConnInfo(e);let i=this._connections[t];if(null==i){const e=Object.keys(this._connections).length;if(0!==this._maxSocketNum&&e>=this._maxSocketNum)return{success:!1,errorCode:r.default.MAX_CONNECT};i=new u({appID:this.appID,token:this.token,uid:this.uid,wsInfo:t,onDeviceStatusChanged:this._handleDeviceStatusChanged,onBindingChanged:this._handleBindingChanged,onSocketStatusChanged:this._handleSocketStatusChanged}),this._connections[t]=i}return i._addSubDid(e.did),null==i._websocket?i._connectWS():i.ready&&i._subDevices([e.did]),{success:!0}},this.disConnectDevice=e=>{const t=this._getWebsocketConnInfo(e);let i=this._connections[t];return i&&i._unSubDevices([e.did]),{success:!0}},this.connect=e=>{const t=this._getDevice(e);if(c.isError(t))return t;const i=this.connectDevice(t);return i.success?null:i.errorCode},this.send=(e,t)=>{const i=this._getDeviceAndConnect(e);return c.isError(i)?i:i[1]._send({cmd:"c2s_raw",data:{did:e,raw:t}})},this.writeData=(e,t)=>{const i=this._getConnect(e);return null!=i?i._send({cmd:"c2s_write",data:{did:e.did,attrs:t}}):{success:!1}},this.write=(e,t)=>{const i=this._getDeviceAndConnect(e);return c.isError(i)?i:i[1]._send({cmd:"c2s_write",data:{did:e,attrs:t}})},this.readStatus=(e,t)=>{const i=this._getConnect(e),n=null!=i;return n&&i._send({cmd:"c2s_read",data:{did:e.did,names:t}}),{success:n}},this.read=(e,t)=>{const i=this._getDeviceAndConnect(e);return c.isError(i)?i:i[1]._send({cmd:"c2s_read",data:{did:e,names:t}})},this.destory=()=>{Object.values(this._connections).forEach(e=>e.destory())},this.subscribeDeviceStatus=e=>{this._onDeviceStatusChanged=e},this.subscribeBindingChanged=e=>{this._onBindingChanged=e},this.subscribeSocketStatus=e=>{this._onSocketStatusChanged=e},this._handleDeviceStatusChanged=e=>{this._onDeviceStatusChanged&&this._onDeviceStatusChanged(e)},this._handleBindingChanged=()=>{this._onBindingChanged&&this._onBindingChanged()},this._handleSocketStatusChanged=(...e)=>{this._onSocketStatusChanged&&this._onSocketStatusChanged(...e)},this._getBindingList=(e=20,t=0,i=[])=>n(this,void 0,void 0,(function*(){const n=`/app/bindings?show_disabled=0&limit=${e}&skip=${t}`,{err:s,data:r}=yield o.default(`${n}`,{method:"GET"});if(s)return{err:s};const a=[...i,...(null==r?void 0:r.devices)||[]];return r&&r.devices.length===e?yield this._getBindingList(e,e+t,a):a})),this._getWebsocketConnInfo=e=>e.host?`wss://wx${e.host}`:"wss://wxstage.gizwits.com",this.appID=e,this.token=t,this.uid=i;const a=wx.getSystemInfoSync().SDKVersion;this._maxSocketNum=s?-1===c.compareWXSDKVersion(a||"1.0.0","1.7.0")?1:5:0}init(){var e,t;return n(this,void 0,void 0,(function*(){try{const i=yield this._getBindingList();return(null===(e=i.err)||void 0===e?void 0:e.errorCode)?{errorCode:null===(t=i.err)||void 0===t?void 0:t.errorCode,errorMessage:"getting binding list failed"}:(this._bindingDevices=i.reduce((e,t)=>Object.assign(Object.assign({},e),{[t.did]:t}),{}),null)}catch(e){return r.default.GIZ_SDK_OTHERWISE}}))}};class u{constructor({appID:e,token:t,uid:i,wsInfo:s,onDeviceStatusChanged:r,onBindingChanged:o,onSocketStatusChanged:c}){this.ready=!1,this.commType="attrs_v4",this._heartbeatInterval=60,this._keepaliveTime=180,this._loginIntveral=5e3,this.autoSubscribe=!1,this._websocket=null,this._loginFailedTimes=0,this._subDids=new Set,this._socketRespHandleMap={},this._waitSends=[],this.destory=()=>{this._heartbeatTimerId&&clearInterval(this._heartbeatTimerId),this._checkConnectTimerId&&clearInterval(this._checkConnectTimerId),this.close()},this._networkChange=e=>n(this,void 0,void 0,(function*(){a.default.log("network change",e)})),this._appShow=()=>n(this,void 0,void 0,(function*(){a.default.log("app show")})),this._addSubDid=e=>{this._subDids.add(e)},this._removeSubDid=e=>{this._subDids.delete(e)},this._connectWS=()=>{a.default.log("GIZ_SDK: start connect ws"),this._websocket=wx.connectSocket({url:this._wsUrl,fail:e=>{a.default.error("GIZ_SDK: connectSocket error",new Error(JSON.stringify(e)))}}),this._websocket.onClose(this.handleClose),this._websocket.onOpen(this.handleOpen),this._websocket.onError(this.handleError),this._websocket.onMessage(this.handleMessage),this._checkConnectTimerId||(this._checkConnectTimerId=setInterval(()=>{this._websocket||this._connectWS()},1e3))},this._subDevices=e=>{const t={cmd:"subscribe_req",data:e.map(e=>({did:e}))};this._send(t)},this._unSubDevices=e=>{e.map(e=>this._removeSubDid(e))},this._send=(e,t=!1)=>(a.default.log("GIZ_SDK: Socket send",e,t),new Promise(i=>{this._websocket?t||this.ready?this._websocket&&(t||this.ready)&&this._websocket.send({data:JSON.stringify(e),complete:e=>{a.default.log("GIZ_SDK: socket send res",e),a.default.log("resres",e);let t=!1;"sendSocketMessage:ok"===e.errMsg&&(t=!0),i({success:t,message:e.errMsg})},fail:e=>{a.default.error("GIZ_SDK: Socket send error",new Error(JSON.stringify(e))),i({success:!1,message:e.errMsg})}}):i({success:!1,message:"Socket not ready"}):i({success:!1,message:"Socket not init"})})),this.close=()=>{this.ready=!1,this._heartbeatTimerId&&clearInterval(this._heartbeatTimerId),this._websocket&&(this._websocket.close({}),this._websocket=null),this._handleSocketStatusChanged(!1)},this.handleClose=e=>{a.default.error("GIZ_SDK: socket close",new Error(JSON.stringify(e))),this.close(),this._stopPing()},this.handleOpen=()=>{a.default.log(" socket open"),this._login()},this.handleMessage=({data:e})=>{a.default.log("GIZ_SDK: message",e);const t=JSON.parse(e),i=this._socketRespHandleMap[t.cmd];i&&i(t.data)},this.handleError=e=>{a.default.error("GIZ_SDK: socket error",new Error(JSON.stringify(e))),this.close(),this._stopPing()},this._login=()=>{const e={cmd:"login_req",data:{appid:this.appID,uid:this.uid,token:this.token,p0_type:this.commType,heartbeat_interval:this._keepaliveTime,auto_subscribe:this.autoSubscribe}};this._send(e,!0)},this._tryLoginAgain=()=>{this._loginFailedTimes+=1,setTimeout(()=>{this._login()},this._loginFailedTimes*this._loginIntveral)},this._startPing=()=>{this._heartbeatTimerId=setInterval(()=>{this._send({cmd:"ping"})},1e3*this._heartbeatInterval)},this._stopPing=()=>{this._heartbeatTimerId&&clearInterval(this._heartbeatTimerId)},this.pongResp=()=>{},this._loginResp=e=>{1==e.success?(this._loginFailedTimes=0,this.ready=!0,this._startPing(),this._subDevices([...this._subDids]),this._handleSocketStatusChanged(!0),this._consumeWaitSends()):this._loginFailedTimes<3?(a.default.log("GIZ_SDK: Login failed, will try again, please wait..."),this._tryLoginAgain()):(a.default.error("GIZ_SDK: Login failed",new Error("m2m socket login failed")),this.close())},this._consumeWaitSends=()=>{let e=this._waitSends.pop();for(;e;)this._send(e),e=this._waitSends.pop()},this._handleSocketStatusChanged=e=>{this._onSocketStatusChanged&&this._onSocketStatusChanged([...this._subDids],e)},this._subscribeResp=e=>{a.default.log("GIZ_SDK: subscribe_res",e),e&&e.success&&e.success.forEach(e=>this._send({cmd:"c2s_read",data:{did:e.did}})),a.default.debug("GIZ_SDK: subscribe_res",e)},this._onlineResp=e=>{this._isSub(e.did)&&this._onDeviceStatusChanged&&this._onDeviceStatusChanged({did:e.did,attrs:Object.assign({is_online:e.online},e)})},this._rawChangedResp=e=>{this._isSub(e.did)&&this._onDeviceStatusChanged&&this._onDeviceStatusChanged(e)},this._statusChangedResp=e=>{this._isSub(e.did)&&this._onDeviceStatusChanged&&this._onDeviceStatusChanged(e)},this._isSub=e=>this._subDids.has(e),this._invalidMsgResp=e=>{1003===e.error_code&&this._login(),a.default.error("GIZ_SDK: s2c_invalid_msg",new Error(JSON.stringify(e)))},this._bindingChangedResp=e=>{!e.bind&&e.did&&this._removeSubDid(e.did),this._onBindingChanged&&this._onBindingChanged()},this.appID=e,this.token=t,this.uid=i,this._wsUrl=`${s}/ws/app/v1`,this._heartbeatTimerId=void 0,this._loginFailedTimes=0,this._onDeviceStatusChanged=r,this._onBindingChanged=o,this._onSocketStatusChanged=c,this._socketRespHandleMap={pong:this.pongResp,login_res:this._loginResp,subscribe_res:this._subscribeResp,s2c_online_status:this._onlineResp,s2c_raw:this._rawChangedResp,s2c_noti:this._statusChangedResp,s2c_invalid_msg:this._invalidMsgResp,s2c_binding_changed:this._bindingChangedResp},wx.onNetworkStatusChange(this._networkChange),wx.onAppShow(this._appShow)}}t.Connection=u},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(4)),a=s(i(3)),o=s(i(24)),c=s(i(25));class u extends c.default{constructor(){super(...arguments),this.disableSendUDP=!1,this.sendMessageInterval=null,this.UDPSocketHandler=null,this.destroy=()=>{this.cleanTimeout(),this.sendMessageInterval&&clearInterval(this.sendMessageInterval),this.sendMessageInterval=null,this.UDPSocketHandler&&(this.UDPSocketHandler.offError(),this.UDPSocketHandler.offMessage(),this.UDPSocketHandler.close())},this.configDevice=({ssid:e,password:t,softAPSSIDPrefix:i})=>new Promise((s,c)=>{a.default.debug("GIZ_SDK: start config device");let u=!1,d=0;const l=o.default.pack(e,t);this.UDPSocketHandler=wx.createUDPSocket(),this.UDPSocketHandler.bind(),this.disableSendUDP=!1;const h=()=>{try{!this.disableSendUDP&&this.UDPSocketHandler.send({address:"10.10.100.254",port:12414,message:l,offset:0,length:l.byteLength})}catch(e){}};this.sendMessageInterval=setInterval(()=>{h()},2e3),this.UDPSocketHandler.onError(e=>{d+=1,d>2&&(this.destroy(),c({success:!1,err:{errorCode:r.default.WECHAT_ERROR.errorCode,errorMessage:e.errMsg}}))});const f=()=>n(this,void 0,void 0,(function*(){if(!u){this.UDPSocketHandler.offMessage(),this.UDPSocketHandler.offError(),this.sendMessageInterval&&clearInterval(this.sendMessageInterval),this.disableSendUDP=!0,u=!0;try{const i=yield this.searchDevice({ssid:e,password:t});s(i)}catch(e){c(e)}}}));this.UDPSocketHandler.onMessage(e=>{f()}),wx.onNetworkStatusChange(()=>n(this,void 0,void 0,(function*(){!u&&wx.getConnectedWifi({success:e=>n(this,void 0,void 0,(function*(){-1===e.wifi.SSID.indexOf(i)&&f()}))})})))}),this.setDeviceOnboardingDeploy=({timeout:e,isBind:t=!0,softAPSSIDPrefix:i})=>{const s=this.ssid,r=this.password;return new Promise((a,o)=>n(this,void 0,void 0,(function*(){this.destroy(),this.initDeviceOnboardingDeploy(a,o),this.startTimeoutTimer(e);try{const e=((yield this.configDevice({ssid:s,password:r,softAPSSIDPrefix:i})).data||[]).map(e=>({mac:e.mac,productKey:e.product_key,did:e.did,name:"",isBind:!1,connectType:"NONE",isBleOnline:!1,isLanOnline:!1,isOnline:!1}));if(t)try{a(yield this.bindDevices(e))}catch(e){o(e)}else a({success:!0,data:e})}catch(e){o(e)}finally{this.destroy()}})))}}}t.default=u},function(e,t,i){var n,s,r,a,o,c,u,d;e.exports=(d=i(2),s=(n=d).lib,r=s.WordArray,a=s.Hasher,o=n.algo,c=[],u=o.SHA1=a.extend({_doReset:function(){this._hash=new r.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(e,t){for(var i=this._hash.words,n=i[0],s=i[1],r=i[2],a=i[3],o=i[4],u=0;u<80;u++){if(u<16)c[u]=0|e[t+u];else{var d=c[u-3]^c[u-8]^c[u-14]^c[u-16];c[u]=d<<1|d>>>31}var l=(n<<5|n>>>27)+o+c[u];l+=u<20?1518500249+(s&r|~s&a):u<40?1859775393+(s^r^a):u<60?(s&r|s&a|r&a)-1894007588:(s^r^a)-899497514,o=a,a=r,r=s<<30|s>>>2,s=n,n=l}i[0]=i[0]+n|0,i[1]=i[1]+s|0,i[2]=i[2]+r|0,i[3]=i[3]+a|0,i[4]=i[4]+o|0},_doFinalize:function(){var e=this._data,t=e.words,i=8*this._nDataBytes,n=8*e.sigBytes;return t[n>>>5]|=128<<24-n%32,t[14+(n+64>>>9<<4)]=Math.floor(i/4294967296),t[15+(n+64>>>9<<4)]=i,e.sigBytes=4*t.length,this._process(),this._hash},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),n.SHA1=a._createHelper(u),n.HmacSHA1=a._createHmacHelper(u),d.SHA1)},function(e,t,i){var n,s,r,a;e.exports=(n=i(2),r=(s=n).lib.Base,a=s.enc.Utf8,void(s.algo.HMAC=r.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=a.parse(t));var i=e.blockSize,n=4*i;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var s=this._oKey=t.clone(),r=this._iKey=t.clone(),o=s.words,c=r.words,u=0;u<i;u++)o[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.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=n(i(14)),r=n(i(15)),a=n(i(13)),o=n(i(7)),c=n(i(12)),u=n(i(54)),d=({SSID:e,password:t,pk:i})=>{let n=o.default(e+t).toString();n=r.default.parse(n);let d=s.default.parse(i),l=a.default.encrypt(d,n,{iv:n,mode:c.default,padding:u.default});return o.default(l.ciphertext).toString()};t.default=({SSID:e,password:t,pks:i})=>{const n=[];return i.map(i=>{const s=d({SSID:e,password:t,pk:i});n.push(s)}),n}},function(e,t,i){var n;e.exports=(n=i(2),i(10),n.pad.ZeroPadding={pad:function(e,t){var i=4*t;e.clamp(),e.sigBytes+=i-(e.sigBytes%i||i)},unpad:function(e){var t=e.words,i=e.sigBytes-1;for(i=e.sigBytes-1;i>=0;i--)if(t[i>>>2]>>>24-i%4*8&255){e.sigBytes=i+1;break}}},n.pad.ZeroPadding)},function(e,t,i){"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(7));t.psKeySign=e=>{const t=Math.round((new Date).getTime()/1e3),i=e+t;return{Signature:s.default(i).toString(),timestamp:t}}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(4)),a=i(8),o=i(20),c=s(i(5)),u=s(i(25)),d=s(i(24)),l=s(i(3));function h({bleDeviceId:e,arrayBuffer:t,serviceUUIDSuffix:i="abf0",characteristicUUIDSuffix:s="abf7",bleHandle:r}){let c=null,u=null;const d=()=>null===u&&(c&&clearInterval(c),!0);return new Promise((h,f)=>n(this,void 0,void 0,(function*(){try{l.default.debug("GIZ_SDK: ssid info: ",t),u=setTimeout(()=>{c&&clearInterval(c),u=null,h(!1)},5e3),l.default.debug("GIZ_SDK: createBLEConnection start: ",e),yield r.disableScan();const n=yield o.retryConnect(e,1e4);r.enableScan(),l.default.debug("GIZ_SDK: createBLEConnection end, res:",n);const f=yield o.getBLEDeviceServices(e);l.default.debug("GIZ_SDK: getBLEDeviceServices end, res:",f);const p=f.find(e=>e.uuid.split("-")[0].toLowerCase().endsWith(i));if(!p)return l.default.debug("GIZ_SDK: get ble device services fail",e,f),void h(!1);const v=yield o.getBLEDeviceCharacteristics(e,p.uuid);l.default.debug("GIZ_SDK: getBLEDeviceCharacteristics end, res:",v);const g=v.find(e=>e.uuid.split("-")[0].toLowerCase().endsWith(s));if(!g)return l.default.debug("GIZ_SDK: get ble device characteristics fail",e,v),void h(!1);if(!g.properties.notify&&!g.properties.indicate)return l.default.debug("GIZ_SDK: the ble device characteristic not support notify or indicate",e,g),void h(!1);l.default.debug("GIZ_SDK: check characteristic and service success"),yield o.notifyBLECharacteristicValueChange(e,p.uuid,g.uuid);const y=e=>{const t=a.ab2hex(e.value);l.default.debug("GIZ_SDK: 收到设备返回ack",t),"0000000303000002"===t&&(r.removeEventListener("GizBleDeviceData",y),h(!0))};if(r.addEventListener("GizBleDeviceData",y),l.default.debug("GIZ_SDK: on notifyBLECharacteristicValueChange success"),d())return;yield o.unpackWriteBLECharacteristicValue(e,p.uuid,g.uuid,t),c=setInterval(()=>{d()||o.unpackWriteBLECharacteristicValue(e,p.uuid,g.uuid,t)},2e3),l.default.debug("GIZ_SDK: unpackWriteBLECharacteristicValue end")}catch(e){f(!1),l.default.debug("GIZ_SDK: sendBLEConfigCmd error",e)}}))).catch(e=>{l.default.debug("GIZ_SDK: sendBLEConfigCmd error",e)}).finally(()=>{u&&clearTimeout(u),c&&clearInterval(c),wx.closeBLEConnection({deviceId:e})})}t.sendBLEConfigCmd=h;class f extends u.default{constructor(e,t,i,s,u){super(e,t,i,s),this.destroy=()=>{this.cleanTimeout()},this.isValidBleDevice=(e,t)=>{if(!e||!e.advertisData)return!1;const{productKey:i,mac:n}=a.advertisData2PkAndMac(e.advertisData,this.specialProductKeys);return!!this.specialProductKeys.includes(i)&&(l.default.debug(`GIZ_SDK: isValidBleDevice mac: ${n} pk: ${i} name: ${e.name}`),l.default.debug(`GIZ_SDK: softAPSSIDPrefix: ${t} ismatch : ${e.name&&e.name.startsWith(t)}`),!t||e.name&&e.name.startsWith(t))},this.enableBluetoothDevicesDescovery=()=>n(this,void 0,void 0,(function*(){return(yield o.getBluetoothAdapterState()).available?(yield o.startBluetoothDevicesDiscovery(),{success:!0}):{success:!1,err:{errorCode:r.default.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON.errorCode,errorMessage:"蓝牙状态不可用"}}})),this.enableAndGetBluetoothDevices=e=>n(this,void 0,void 0,(function*(){const t=yield this.enableBluetoothDevicesDescovery();if(!t.success)return t;l.default.debug("GIZ_SDK: start enableAndGetBluetoothDevices");const i=(yield o.getBluetoothDevices()).filter(t=>this.isValidBleDevice(t,e));return l.default.debug("GIZ_SDK: getBluetoothDevices success",i),{success:!0,bleDevices:i}})),this.setDeviceOnboardingDeploy=({timeout:e,isBind:t=!0,softAPSSIDPrefix:i})=>new Promise((s,r)=>n(this,void 0,void 0,(function*(){const n=this.ssid,a=this.password;this.destroy(),this.initDeviceOnboardingDeploy(s,r),this.startTimeoutTimer(e);try{const r=((yield this.configBLEDevice({ssid:n,password:a,timeout:1e3*e,softAPSSIDPrefix:i})).data||[]).map(e=>({mac:e.mac,productKey:e.product_key,did:e.did,name:"",isBind:!1,connectType:"NONE",isBleOnline:!1,isLanOnline:!1,isOnline:!1}));s(t?yield this.bindDevices(r):{success:!0,data:r})}catch(e){s({success:!1,data:e})}finally{this.destroy()}}))),this.configBLEDevice=({ssid:e,password:t,softAPSSIDPrefix:i})=>new Promise((s,u)=>n(this,void 0,void 0,(function*(){l.default.debug("GIZ_SDK: start config ble device");const f=yield this.enableAndGetBluetoothDevices(i).catch(e=>({success:!1,err:{errorCode:r.default.WECHAT_ERROR.errorCode,errorMessage:JSON.stringify(e)}}));if(!a.isWXDevicesResult(f))return u(f);const{bleDevices:p}=f;l.default.debug("GIZ_SDK: enableAndGetBluetoothDevices success, target devices: ",p);const v=({devices:e})=>n(this,void 0,void 0,(function*(){this.hasTimeoutHandler()?Array.prototype.push.apply(p,e.filter(e=>this.isValidBleDevice(e,i))):wx.offBluetoothDeviceFound(v)}));wx.onBluetoothDeviceFound(v);const g=d.default.pack(e,t),y=()=>n(this,void 0,void 0,(function*(){if(l.default.debug("GIZ_SDK: startConfigDevice"),!this.hasTimeoutHandler())return;const e=p.shift();if(e&&l.default.debug("GIZ_SDK: startConfigDevice, target device: ",e),!(e&&(yield h({bleDeviceId:e.deviceId,arrayBuffer:g.buffer,bleHandle:this.bleHandle}))))return yield c.default(500),yield o.startBluetoothDevicesDiscovery(),void(yield y());l.default.debug("GIZ_SDK: offBluetoothDeviceFound ready search device"),wx.offBluetoothDeviceFound(v)}));try{this.searchDevice({ssid:e,password:t}).then(e=>{s(e)})}catch(e){u(e),l.default.error("GIZ_SDK: searchDevice error",new Error(JSON.stringify(e)))}yield y()}))),this.bleHandle=u}}t.default=f},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(6));t.AnonymousLogin=function({uid:e}){return n(this,void 0,void 0,(function*(){return r.default("/app/users",{data:{phone_id:e},method:"POST"},!1)}))}},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(3)),a=s(i(21)),o=s(i(59)),c=s(i(22)),u=s(i(0)),d=i(1),l=s(i(5)),h=i(8),f=s(i(23));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=h.ab2numbers(e.message),i=new o.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,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:o.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:o}){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=a.default.pack();this.tcpHandler.write(d.arrayToUint8(e)),r.default.debug("connect success try login")},i=t=>{e({success:!0,err:t})},n=t=>{switch(new u.default(h.ab2numbers(t.message)).cmd){case"0007":{const e=new a.default(h.ab2numbers(t.message)),i=c.default.pack({passcode:e.passcode});this.tcpHandler.write(d.arrayToUint8(i));break}case"0009":new c.default(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 l.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=h.ab2hex(e.message),i=new u.default(d.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=o,this.onCloseListener=t}}},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(3)),r=n(i(0)),a=i(1);class o extends r.default{constructor(e){super(e),this.did="",this.mac="",this.productKey="",this.deviceType=0,this.apiUrl="",this.protocolVersion="",this.mcuVersion="",this.moduleVersion="",this.parseEndChat=(e,t)=>{let i="";const n=this.content.slice(e,this.content.length);for(let t in n){const s=n[t];if(e+=1,0===s)break;i+=String.fromCharCode(s)}return this[t]=i,e},this.baseParse=(e,t,i="ASCII")=>{const n=parseInt(a.arrayToString(this.content.slice(e,e+2)),16);e+=2;let s="";return this.content.slice(e,e+n).map(e=>{if("ASCII"===i)s+=String.fromCharCode(e);else{const t=e.toString(16);s+=a.fillString(t,2)}}),this[t]=s,e+n};let t=0;try{t=this.baseParse(t,"did"),t=this.baseParse(t,"mac","HEX"),t=this.baseParse(t,"moduleVersion"),t=this.baseParse(t,"productKey"),t+=8,t=this.parseEndChat(t,"apiUrl"),t=this.parseEndChat(t,"protocolVersion"),this.mcuVersion="",this.content.slice(t,this.content.length).map(e=>{this.mcuVersion+=String.fromCharCode(e)})}catch(e){s.default.warn("Parse DiscoverUDP error",e)}}}o.pack=()=>{const e=[0,0,0,3,3,0,0,3],t=new ArrayBuffer(e.length),i=new Uint8Array(t);for(let n=0;n<t.byteLength;n++)i[n]=e[n];return i},t.default=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(0)),r=i(1);class a extends s.default{constructor(e){super(e),this.state=0,this.len=0;let t=0;this.len=parseInt(r.arrayToString(this.content.slice(t,t+2)),16),t+=2,this.state=this.content[t]}}t.RequestSync=a,a.pack=()=>[0,0,0,3,3,0,0,81];class o extends s.default{constructor(e){super(e),this.id=0,this.timestemp=0,this.payloadLen=0,this.payload=[];let t=0;this.id=parseInt(r.arrayToString(this.content.slice(t,t+2)),16),t+=2,this.timestemp=parseInt(r.arrayToString(this.content.slice(t,t+5)),16),t+=5,this.payloadLen=parseInt(r.arrayToString(this.content.slice(t,t+2)),16),t+=2,this.payload=this.content.slice(t,this.content.length)}}t.SyncPackage=o,o.pack=e=>{let t=e.toString(2);return t=r.fillString(t,16),[0,0,0,3,5].concat([0,0,83]).concat(r.completeBlock(t))};class c extends s.default{}t.DeletePackage=c,c.pack=e=>{let t=e.toString(2);return t=r.fillString(t,16),[0,0,0,3,5].concat([0,0,85]).concat(r.completeBlock(t))};class u extends s.default{constructor(e){super(e),this.state=0,this.state=this.content[0]}}t.CancelSync=u,u.pack=()=>[0,0,0,3,3,0,0,87]},function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(s,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function o(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(28)),a=s(i(14)),o=s(i(15)),c=s(i(13)),u=s(i(12)),d=s(i(6));t.uploadP0=function({device:e,data:t,productSecret:i}){return n(this,void 0,void 0,(function*(){const n=`/v2/products/${e.productKey}/devices/offline-data`;let s=e.passcode;const l=o.default.parse(i),h=o.default.parse(""),f=a.default.parse(s);return s=c.default.encrypt(f,l,{iv:h,mode:u.default,padding:r.default}).ciphertext.toString().toUpperCase(),d.default(n,{data:{data:t,encoding:"hex"},method:"POST",headers:{"X-Gizwits-Device-Id":e.did,"X-Gizwits-Device-passcode":s}},!1)}))}},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(0)),r=i(1);class a extends s.default{}a.pack=()=>{const e=parseInt(`${Date.now()/1e3}`,10),t=r.fillString(e.toString(2),40);return[0,0,0,3,8,0,0,89].concat(r.completeBlock(t))},t.default=a},function(e){e.exports=JSON.parse('{"name":"mini_program_gizwits_sdk","version":"3.4.0-beta.1","description":"ota","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.5.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":"^3.8.3","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":{"crc":"^4.3.2","crypto-js":"^4.1.1"}}')},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(0));class r extends s.default{constructor(e){super(e),this.status=0,this.status=this.content[0]}}r.pack=()=>[0,0,0,3,3,0,0,97],t.default=r},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(0));class r extends s.default{constructor(){super(...arguments),this.status=0}}r.pack=e=>[0,0,0,3,3,0,0,99,e],t.default=r}]);