Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@onbright/bluetooth-sdk

Package Overview
Dependencies
Maintainers
0
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@onbright/bluetooth-sdk - npm Package Compare versions

Comparing version 1.1.37 to 1.1.38

2

dist/index.js

@@ -1,1 +0,1 @@

function e(e,n){if(n==null||n>e.length)n=e.length;for(var t=0,a=new Array(n);t<n;t++)a[t]=e[t];return a}function n(n){if(Array.isArray(n))return e(n)}function t(e,n,t,a,i,o,c){try{var r=e[o](c);var u=r.value}catch(e){t(e);return}if(r.done){n(u)}else{Promise.resolve(u).then(a,i)}}function a(e){return function(){var n=this,a=arguments;return new Promise(function(i,o){var c=e.apply(n,a);function r(e){t(c,i,o,r,u,"next",e)}function u(e){t(c,i,o,r,u,"throw",e)}r(undefined)})}}function i(e,n){if(!(e instanceof n)){throw new TypeError("Cannot call a class as a function")}}function o(e,n){for(var t=0;t<n.length;t++){var a=n[t];a.enumerable=a.enumerable||false;a.configurable=true;if("value"in a)a.writable=true;Object.defineProperty(e,a.key,a)}}function c(e,n,t){if(n)o(e.prototype,n);if(t)o(e,t);return e}function r(e,n,t){if(n in e){Object.defineProperty(e,n,{value:t,enumerable:true,configurable:true,writable:true})}else{e[n]=t}return e}function u(e){if(typeof Symbol!=="undefined"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function s(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function l(e){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};var a=Object.keys(t);if(typeof Object.getOwnPropertySymbols==="function"){a=a.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))}a.forEach(function(n){r(e,n,t[n])})}return e}function d(e){return n(e)||u(e)||v(e)||s()}function v(n,t){if(!n)return;if(typeof n==="string")return e(n,t);var a=Object.prototype.toString.call(n).slice(8,-1);if(a==="Object"&&n.constructor)a=n.constructor.name;if(a==="Map"||a==="Set")return Array.from(a);if(a==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a))return e(n,t)}function f(e,n){var t,a,i,o,c={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]};return o={next:r(0),"throw":r(1),"return":r(2)},typeof Symbol==="function"&&(o[Symbol.iterator]=function(){return this}),o;function r(e){return function(n){return u([e,n])}}function u(o){if(t)throw new TypeError("Generator is already executing.");while(c)try{if(t=1,a&&(i=o[0]&2?a["return"]:o[0]?a["throw"]||((i=a["return"])&&i.call(a),0):a.next)&&!(i=i.call(a,o[1])).done)return i;if(a=0,i)o=[o[0]&2,i.value];switch(o[0]){case 0:case 1:i=o;break;case 4:c.label++;return{value:o[1],done:false};case 5:c.label++;a=o[1];o=[0];continue;case 7:o=c.ops.pop();c.trys.pop();continue;default:if(!(i=c.trys,i=i.length>0&&i[i.length-1])&&(o[0]===6||o[0]===2)){c=0;continue}if(o[0]===3&&(!i||o[1]>i[0]&&o[1]<i[3])){c.label=o[1];break}if(o[0]===6&&c.label<i[1]){c.label=i[1];i=o;break}if(i&&c.label<i[2]){c.label=i[2];c.ops.push(o);break}if(i[2])c.ops.pop();c.trys.pop();continue}o=n.call(e,c)}catch(e){o=[6,e];a=0}finally{t=i=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:true}}}var h=Object.defineProperty;var S=function(e,n){for(var t in n)h(e,t,{get:n[t],enumerable:!0})};import{dataConversion as p}from"@onbright/common-sdk";var g={};S(g,{Chinese:function(){return B},Dispense:function(){return F},HighLowConversion:function(){return eu},ab2hex:function(){return J},ab2hex2:function(){return j},abToA:function(){return R},advertisData:function(){return eo},binaryReverse:function(){return er},binaryToHex:function(){return V},checkSum:function(){return ea},checkSumValue:function(){return ei},dateTime2unixHex:function(){return X},dealMAC:function(){return ee},decimalToBinary:function(){return U},decimalToHex:function(){return N},getRandomNum:function(){return K},getSm4Value:function(){return Y},hex2Array:function(){return G},hex2Buff:function(){return W},hexReverse:function(){return ec},hexToDecimal:function(){return O},highLowBitCV:function(){return en},openKeyEctopicOr:function(){return et},padEndHex:function(){return q},padStartHex:function(){return Q},passTo8DBC:function(){return P},setSm4Value:function(){return z},setbit:function(){return Z},sliceHex:function(){return $}});import m from"bitwise";var y=[214,144,233,254,204,225,61,183,22,182,20,194,40,251,44,5,43,103,154,118,42,190,4,195,170,68,19,38,73,134,6,153,156,66,80,244,145,239,152,122,51,84,11,67,237,207,172,98,228,179,28,169,201,8,232,149,128,223,148,250,117,143,63,166,71,7,167,252,243,115,23,186,131,89,60,25,230,133,79,168,104,107,129,178,113,100,218,139,248,235,15,75,112,86,157,53,30,36,14,94,99,88,209,162,37,34,124,59,1,33,120,135,212,0,70,87,159,211,39,82,76,54,2,231,160,196,200,158,234,191,138,210,64,199,56,181,163,247,242,206,249,97,21,161,224,174,93,164,155,52,26,85,173,147,50,48,245,140,177,227,29,246,226,46,130,102,202,96,192,41,35,171,13,83,78,111,213,219,55,69,222,253,142,47,3,255,106,114,109,108,91,81,141,27,175,146,187,221,188,127,17,217,92,65,31,16,90,216,10,193,49,136,165,205,123,189,45,116,208,18,184,229,180,176,137,105,151,74,12,150,119,126,101,185,241,9,197,110,198,132,24,240,125,236,58,220,77,32,121,238,95,62,215,203,57,72],_=[462357,0x1c232a31,0x383f464d,0x545b6269,0x70777e85,0x8c939aa1,0xa8afb6bd,0xc4cbd2d9,0xe0e7eef5,0xfc030a11,0x181f262d,0x343b4249,0x50575e65,0x6c737a81,0x888f969d,0xa4abb2b9,0xc0c7ced5,0xdce3eaf1,0xf8ff060d,0x141b2229,0x30373e45,0x4c535a61,0x686f767d,0x848b9299,0xa0a7aeb5,0xbcc3cad1,0xd8dfe6ed,0xf4fb0209,0x10171e25,0x2c333a41,0x484f565d,0x646b7279];function k(e){var n=[];for(var t=0,a=e.length;t<a;t+=2)n.push(parseInt(e.substr(t,2),16));return n}function x(e){return e.map(function(e){return e=e.toString(16),e.length===1?"0"+e:e}).join("")}function C(e){var n=[];for(var t=0,a=e.length;t<a;t++){var i=e.codePointAt(t);if(i<=127)n.push(i);else if(i<=2047)n.push(192|i>>>6),n.push(128|i&63);else if(i<=55295||i>=57344&&i<=65535)n.push(224|i>>>12),n.push(128|i>>>6&63),n.push(128|i&63);else if(i>=65536&&i<=1114111)t++,n.push(240|i>>>18&28),n.push(128|i>>>12&63),n.push(128|i>>>6&63),n.push(128|i&63);else throw n.push(i),new Error("input is not supported")}return n}function b(e,n){return e<<n|e>>>32-n}function H(e){return(y[e>>>24&255]&255)<<24|(y[e>>>16&255]&255)<<16|(y[e>>>8&255]&255)<<8|y[e&255]&255}function D(e){return e^b(e,2)^b(e,10)^b(e,18)^b(e,24)}function A(e){return e^b(e,13)^b(e,23)}function w(e,n,t){var a=new Array(4),i=new Array(4);for(var o=0;o<4;o++)i[0]=e[4*o]&255,i[1]=e[4*o+1]&255,i[2]=e[4*o+2]&255,i[3]=e[4*o+3]&255,a[o]=i[0]<<24|i[1]<<16|i[2]<<8|i[3];for(var c=0,r;c<32;c+=4)r=a[1]^a[2]^a[3]^t[c+0],a[0]^=D(H(r)),r=a[2]^a[3]^a[0]^t[c+1],a[1]^=D(H(r)),r=a[3]^a[0]^a[1]^t[c+2],a[2]^=D(H(r)),r=a[0]^a[1]^a[2]^t[c+3],a[3]^=D(H(r));for(var u=0;u<16;u+=4)n[u]=a[3-u/4]>>>24&255,n[u+1]=a[3-u/4]>>>16&255,n[u+2]=a[3-u/4]>>>8&255,n[u+3]=a[3-u/4]&255}function E(e,n,t){var a=new Array(4),i=new Array(4);for(var o=0;o<4;o++)i[0]=e[0+4*o]&255,i[1]=e[1+4*o]&255,i[2]=e[2+4*o]&255,i[3]=e[3+4*o]&255,a[o]=i[0]<<24|i[1]<<16|i[2]<<8|i[3];a[0]^=0xa3b1bac6,a[1]^=0x56aa3350,a[2]^=0x677d9197,a[3]^=0xb27022dc;for(var c=0,r;c<32;c+=4)r=a[1]^a[2]^a[3]^_[c+0],n[c+0]=a[0]^=A(H(r)),r=a[2]^a[3]^a[0]^_[c+1],n[c+1]=a[1]^=A(H(r)),r=a[3]^a[0]^a[1]^_[c+2],n[c+2]=a[2]^=A(H(r)),r=a[0]^a[1]^a[2]^_[c+3],n[c+3]=a[3]^=A(H(r));if(t===0)for(var u=0,s;u<16;u++)s=n[u],n[u]=n[31-u],n[31-u]=s}function I(e,n,t){var a=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{},i=a.padding,o=i===void 0?"pkcs#7":i,c=a.mode,r=a.iv,u=r===void 0?[]:r,s=a.output,l=s===void 0?"string":s;if(c==="cbc"&&(typeof u=="string"&&(u=k(u)),u.length!==128/8))throw new Error("iv is invalid");if(console.log("inArray, key",e,n),typeof n=="string"&&(n=k(n)),n.length!==128/8)throw new Error("key is invalid");if(typeof e=="string"?t!==0?e=C(e):e=k(e):e=d(e),(o==="pkcs#5"||o==="pkcs#7")&&t!==0){var v=16-e.length%16;for(var f=0;f<v;f++)e.push(v)}var h=new Array(32);E(n,h,t);var S=[],p=u,g=e.length,m=0;for(;g>=16;){var y=e.slice(m,m+16),_=new Array(16);if(c==="cbc")for(var b=0;b<16;b++)t!==0&&(y[b]^=p[b]);w(y,_,h);for(var H=0;H<16;H++)c==="cbc"&&t===0&&(_[H]^=p[H]),S[m+H]=_[H];c==="cbc"&&(t!==0?p=_:p=y),g-=16,m+=16}return l!=="array"?x(S):S}var T={encrypt:function e(e,n,t){return I(e,n,1,t)},decrypt:function e(e,n,t){return I(e,n,0,t)}};function B(e,n){e.value=e.options[e.value],n()}function F(e,n){n()}var L=function(e,n,t){return parseInt(e,n).toString(t)},M=function(e,n){var t=L(e,n,16);return t.length<2?"0".concat(t):t};function U(e,n){e.value=L(e.value,10,2),n()}function V(e,n){e.value=M(e.value,2),n()}function N(e,n){e.value=M(e.value,10),n()}function O(e,n){var t=L(e.value,16,10);e.value=t,n()}function P(e,n){var t=new Array(16),a=e.value.split("");e.value=t.fill("F").map(function(e,n){return a[n]&&(e=a[n]),e}).join(""),n()}function R(e,n){e.value=Array.from(new Uint8Array(e.value)),n()}function J(e,n){var t=Array.from(new Uint8Array(e.value),function(e){return("00"+e.toString(16)).slice(-2)});e.value=t.join(""),n()}function j(e,n){e.ab2hex2="";var t=Array.from(new Uint8Array(e.value),function(n,t){if(t!==0&&t!==1)return("00"+n.toString(16)).slice(-2);e.ab2hex2+=("00"+n.toString(16)).slice(-2)});e.value=t.join(""),n()}function K(e,n){var t=parseInt(e.value,16).toString(2).padStart(32,"0").split("").map(function(e){return e==="0"?1:0}).join("");e.value=parseInt(t,2).toString(16),n()}function W(e,n){var t=new Uint8Array(e.value.match(/[\da-f]{2}/gi).map(function(e){return parseInt(e,16)}));e.value=t.buffer,n()}function G(e,n){var t=new Uint8Array(e.value.match(/[\da-f]{2}/gi).map(function(e){return parseInt(e,16)}));e.value=t,n()}function z(e,n){console.log("加密参数",e.value,e.key);var t=T.encrypt(e.value,e.key);e.value=t.slice(0,32),console.log("加密后",e.value),e.checkSum&&(e.value=e.checkSum+e.value,console.log("加密后有校验核添加校验核",e.value)),n()}function Y(e,n){console.log("解密参数",e.key,e.value),e.value=T.decrypt(e.value,e.key),console.log("解密后",e.value),e.ab2hex2&&(e.value=e.ab2hex2+e.value,console.log("解密后有操作命令和校验核添加命令和校验",e.value)),n()}function $(e,n){e.value=e.value.slice(e.sliceHex),n()}function q(e,n){e.value=e.value.padEnd(e.padEndHex,e.padEndValue),n()}function Q(e,n){e.value=e.value.padStart(e.padStartHex,e.padStartValue),n()}function X(e,n){e.value=dayjs(e.value).unix().toString(16).padStart(8,"0"),n()}function Z(e,n){e.value=e.value.reduce(function(e,n){return console.log(e,n),m.integer.setBit(e,parseInt(n),1)},0),n()}function ee(e,n){e.value=e.value.replace(/:/g,""),n()}function en(e,n){var t=e.value.slice(0,2),a=e.value.slice(2,4);e.value="".concat(a).concat(t),n()}function et(e,n){var t="";for(var a=0;a<16;a++){var i=(parseInt(e.value.slice(0,16).charAt(a),16)^parseInt(e.value.slice(16,32).charAt(a),16)).toString(16).toUpperCase();t+=i}e.value=t,n()}function ea(e,n){e.checkSum=(e.value.split("").reduce(function(e,n,t,a){if(t%2===0){var i=a[t]+""+a[t+1];return e+parseInt(i,16)}else return e},0)&255).toString(16).padStart(2,"0").slice(-2),console.log("o命令校验核",e.checkSum),n()}function ei(e,n){var t=e.value.split(""),a=[];for(var i=0;i<t.length-1;i++)if(i%2===0){var o=t[i]+""+t[i+1];a.push(o)}var c=0;a.forEach(function(e){c+=parseInt(e,16)}),e.value=c.toString(16).padStart(4,"0").slice(-4),n()}function eo(e,n){var t=e.value.slice(2,14),a=e.value.slice(14,16),i=e.value.slice(16,18);e.value="".concat(t,"|").concat(a,"|").concat(i),n()}function ec(e,n){e.value=e.value.match(/[\da-f]{2}/gi).reverse().join(""),n()}function er(e,n){e.value=e.value.split("").reverse().join(""),n()}function eu(e,n){var t=[];for(var a=0;a<e.value.length;a+=2)t.push(e.value.substring(a,a+2));e.value=t.reverse().join(""),n()}function es(e,n){var t=el(e);n=n||{use:[]};var i=ed(n.use);return /*#__PURE__*/function(){var o=a(function(a){var o,c,r,u,s,d,v;var h=arguments;return f(this,function(f){switch(f.label){case 0:o=h.length>1&&h[1]!==void 0?h[1]:{};c=function(n,t){return e.map(function(e,n){return e.value=t[n],e=l({},e,o),r(e,n)})},r=function(e,n){return new Promise(function(a,i){t[n](e,function(e,n){n(),a(e.value)})})},u=function(e){return new Promise(function(t,a){n.value=e,n=l({},n,o),i(n,function(e,n){n(),t(e.value)})})};f.label=1;case 1:f.trys.push([1,4,,5]);return[4,c(e,a)];case 2:s=f.sent();return[4,Promise.all(s)];case 3:d=f.sent().join("");return[2,u(d)];case 4:v=f.sent();throw new Error(v);case 5:return[2]}})});return function(e){return o.apply(this,arguments)}}()}function el(e){return function(e){return e.map(function(e){return ed(e.use)})}(e)}function ed(e){if(!Array.isArray(e))throw new Error("use stack must be an array!");var n=true,t=false,a=undefined;try{for(var i=e[Symbol.iterator](),o;!(n=(o=i.next()).done);n=true){var c=o.value;if(typeof g[c]!="function")throw new Error("use must be composed of functions!")}}catch(e){t=true;a=e}finally{try{if(!n&&i.return!=null){i.return()}}finally{if(t){throw a}}}return function(n,t){var a=-1;return i(0);function i(o){if(o<=a)return Promise.reject(new Error("next() called multiple times"));a=o;var c=g[e[o]]||(o===e.length?t:null);if(!c)return Promise.resolve();try{return Promise.resolve(c(n,i.bind(null,o+1)))}catch(e){return Promise.reject(e)}}}}var ev=es([{use:[]},{use:["passTo8DBC"]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),ef=es([{use:[]},{use:[]},{use:["passTo8DBC"]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eh=es([{use:[]},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eS=es([{use:["padEndHex"],padEndHex:10}]),ep=es([{use:["ab2hex","sliceHex","getRandomNum","padStartHex"],sliceHex:-8,padStartHex:8,padStartValue:"0"},{use:[]},{use:[]},{use:[]}],{use:["padEndHex","hex2Array","setSm4Value","hex2Buff"],padEndHex:32}),eg=es([{use:["ab2hex","sliceHex","getRandomNum","padStartHex"],sliceHex:-8,padStartHex:0,padStartValue:"0"},{use:[]},{use:[]},{use:[]}],{use:["padEndHex","hex2Array","setSm4Value","hex2Buff"],padEndHex:32}),em=es([{use:[]},{use:[]}],{use:["hex2Buff"]}),ey=es([{use:["decimalToHex","padStartHex","HighLowConversion"],padStartHex:6,padStartValue:"0"},{use:[]}],{use:["hex2Buff"]}),e_=es([{use:["ab2hex","hex2Array","getSm4Value"]}]),ek=es([{use:["ab2hex2","hex2Array","getSm4Value"]}]),ex=es([{use:["advertisData"]}]),eC=es([{use:["highLowBitCV"]}]),eb=es([{use:[]},{use:[]},{use:[]}],{use:["padEndHex","hex2Array","setSm4Value","openKeyEctopicOr"],padEndHex:32}),eH=es([{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eD=es([{use:[]},{use:["decimalToBinary","padStartHex"],padStartHex:2,padStartValue:"0"},{use:[]}],{use:["binaryToHex","HighLowConversion"]}),eA=es([{use:["decimalToHex"]},{use:["decimalToHex"]},{use:["setbit","decimalToHex"]},{use:[]}],{use:["hexReverse"]}),ew=es([{use:["decimalToHex"]},{use:["decimalToHex"]},{use:[]},{use:[]}],{use:["hexReverse"]}),eE=es([{use:[]},{use:["padStartHex"],padStartHex:4,padStartValue:"0"},{use:["padStartHex"],padStartHex:4,padStartValue:"0"},{use:[]},{use:["HighLowConversion"]},{use:["HighLowConversion"]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eI=es([{use:[]},{use:["padStartHex"],padStartHex:4,padStartValue:"0"},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eT=es([{use:[]},{use:[]},{use:[]},{use:[]}],{use:["checkSumValue"]}),eB=es([{use:["HighLowConversion"]},{use:[]},{use:["HighLowConversion"]},{use:[]},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eF=es([{use:[]},{use:["decimalToHex"]},{use:["padStartHex"],padStartHex:4,padStartValue:"0"},{use:[]},{use:["decimalToHex"]},{use:["decimalToHex"]},{use:["padEndHex"],padEndHex:16},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eL=es([{use:["ab2hex"]}]),eM=es([{use:["ab2hex","hexToDecimal"]},{use:[]}]),eU=es([{use:[]},{use:[]},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eV=es([{use:[]},{use:[]},{use:[]},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eN=es([{use:[]},{use:[]},{use:[]},{use:[]},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eO=es([{use:[]},{use:[]},{use:["padStartHex"],padStartHex:4,padStartValue:"0"},{use:[]},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eP=es([{use:[]},{use:["decimalToHex","padStartHex"],padStartHex:2,padStartValue:"0"},{use:["padStartHex"],padStartHex:8,padStartValue:"0"},{use:["decimalToHex","padStartHex"],padStartHex:8,padStartValue:"0"},{use:["decimalToHex","padStartHex"],padStartHex:8,padStartValue:"0"},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eR=es([{use:[]},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eJ=es([{use:[]},{use:["decimalToHex","padStartHex"],padStartHex:8,padStartValue:"0"},{use:[]},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),ej=es([{use:["decimalToHex","padStartHex","HighLowConversion"],padStartHex:6,padStartValue:"0"},{use:[]}]),eK=es([{use:[]},{use:["decimalToHex","padStartHex","HighLowConversion"],padStartHex:8,padStartValue:"0"}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eW=es([{use:[]},{use:["decimalToHex","padStartHex","HighLowConversion"],padStartHex:8,padStartValue:"0"},{use:["HighLowConversion"]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eG=es([{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),ez=es([{use:[]},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eY={deviceBind:ev,deviceBindNew:ef,setSm4Auth:ep,deviceOperate:em,firmwareContent:ey,getSm4Auth:e_,getSm4AuthOperate:ek,getadvertisData:ex,getHighLow:eC,getOpenHushKey:eb,getDeviceSerialId:eH,passwordDbc:eS,getUserProperty:eD,getCycleStart:eA,getCycleEnd:ew,updateUser:eE,deleteUser:eI,getLockDataSum:eT,getLockDataSm4:eB,createKeySm4:eF,getNoSm4Data:eL,setBuletVolume:eU,setBuleStay:eV,setBuleClose:eN,deleteKeySm4:eO,voiceMessageSm4:eP,voicePgVsSm4:eR,issuceVoicePgSm4:eJ,issuceAnySm4:ej,getNoSm4Butter:eM,setSm4AuthCon:eg,syncKeyList:eh,getLogSm4Data:eK,firmwareUpReady:eW,getLockState:eG,setBuleLocked:ez},e$=eY;var eq="00004F42-0000-1000-8000-00805F9B34FB",eQ="00004F00-0000-1000-8000-00805F9B34FB",eX="00004F00-0000-1000-8000-00805F9B34FB",eZ="00004F00-0000-1000-8000-00805F9B34FB",e0=/*#__PURE__*/function(){"use strict";function e(n,t,a){i(this,e);this.grade="";this.userId="";this.advertisData=new ArrayBuffer(1);this.hexStr="";this.padEndValue="ab";this.timeUnix="";this.callback=null;this.grade=n,this.userId=t,this.timeUnix=a}c(e,[{key:"handleAuthenticationData",value:function e(){return new Uint8Array}},{key:"handleSendData",value:function e(e,n){var t=this;return a(function(){var i;return f(this,function(o){switch(o.label){case 0:t.hexStr=n;return[4,t.onProcessingSentData()];case 1:i=o.sent();console.log("data",i),wx.writeBLECharacteristicValue({deviceId:e,serviceId:eq,characteristicId:eQ,value:i,fail:function(e){console.log("发送数据失败:-> err="+JSON.stringify(e))},success:function(){console.log("发送数据成功:->"+p.ab2hex(i)+" serviceId:"+eq)}}),wx.notifyBLECharacteristicValueChange({state:!0,deviceId:e,serviceId:eq,characteristicId:eX,success:function(e){console.log("使能通知成功:"+JSON.stringify(e))},fail:function(e){console.log("使能通知失败"+JSON.stringify(e)),t.callback&&t.callback.onAuthFailed&&t.callback.onAuthFailed()}}),wx.onBLECharacteristicValueChange(/*#__PURE__*/function(){var e=a(function(e){var n,a,i,o,c,r,u,s;return f(this,function(l){switch(l.label){case 0:console.log("收到数据 serviceId uuid:"+e.serviceId+" characteristicId: "+e.characteristicId),console.log("收到数据:"+p.ab2hex(e.value));r=e$.getSm4Auth;u=[[e.value]];s={};return[4,t._getKey()];case 1:return[4,r.apply(e$,u.concat([(s.key=l.sent(),s)]))];case 2:i=l.sent(),o=i.slice(0,2),c=i.slice(2,6);console.log("notifyValue",i,"grade",o,"userId",c),o===t.grade&&c===t.userId?(n=t.callback)===null||n===void 0?void 0:n.onAuthSuccess():(a=t.callback)===null||a===void 0?void 0:a.onAuthFailed(),wx.offBLECharacteristicValueChange();return[2]}})});return function(n){return e.apply(this,arguments)}}());return[2]}})})()}},{key:"setCallback",value:function e(e){this.callback=e}},{key:"onMatchingServiceCharacteristic",value:function e(){return{write:eQ,notify:eX,read:eZ}}},{key:"onProcessingSentData",value:function e(){var e=this;return new Promise(/*#__PURE__*/function(){var n=a(function(n,t){var a,i,o;return f(this,function(t){switch(t.label){case 0:a=e$.setSm4Auth;i=[[e.advertisData,e.grade,e.userId,e.timeUnix]];o={};return[4,e._getKey()];case 1:return[4,a.apply(e$,i.concat([(o.key=t.sent(),o.padEndValue="0",o)]))];case 2:n.apply(void 0,[t.sent()]);return[2]}})});return function(e,t){return n.apply(this,arguments)}}())}},{key:"onProcessNotifyData",value:function e(e){return console.log("onProcessNotifyData收到协议了",e),console.log("onProcessNotifyData收到协议了",e.value),new Promise(function(){})}},{key:"onProcessReadData",value:function e(e){return console.log("onProcessReadData 收到协议了",e),new Promise(function(){})}},{key:"_getKey",value:function e(){var e=this;return new Promise(/*#__PURE__*/function(){var n=a(function(n,t){var a,i,o,c,r;return f(this,function(t){switch(t.label){case 0:a="4F42424C45",i=e.hexStr.slice(2,14),o=e.hexStr.slice(-8),c=a+i+o;return[4,e._getSum(c)];case 1:r=t.sent();console.log("getSum",r),console.log("mac",i,"random",o,"numStr",r,"sm4Key",a+i+o+r),n(a+i+o+r);return[2]}})});return function(e,t){return n.apply(this,arguments)}}())}},{key:"_getSum",value:function e(e){return new Promise(function(n,t){n(e.split("").reduce(function(e,n,t,a){if(t%2===0){var i=a[t]+""+a[t+1];return e+parseInt(i,16)}else return e},0).toString(16).padStart(2,"0").slice(-2))})}}]);return e}();var e1=/*#__PURE__*/function(){"use strict";function e(n){i(this,e);this.status=0;this.callback=null;this.currentDevice=null;this.disconnectTime=0;this.mtu=0;this.maxMTU=512;this.communicationService=null;this.communicationWriteCharacteristic=null;this.communicationReadCharacteristic=null;this.communication=n}c(e,[{key:"connect",value:function e(e,n){var t=this;return new Date().getTime()-this.disconnectTime<2e3&&!n?(console.log("connect failed interval time <2000"),!1):this.isConnectedOrConnecting()?(console.log("connect failed is connected Or connecting"),!1):(this.status=1,this.currentDevice=e,console.log("开始连接设备 "+JSON.stringify(e)),wx.createBLEConnection({deviceId:e.deviceId,success:function(n){console.log("连接蓝牙成功:"+JSON.stringify(n.errMsg)),t.status=2,wx.getDeviceInfo().platform=="android"?wx.setBLEMTU({deviceId:e.deviceId,mtu:t.maxMTU,success:function(e){console.log("调节MTU成功,"+e.mtu),t.mtu=e.mtu,t.callback&&t.callback.onMTUChange&&t.currentDevice&&t.callback.onMTUChange(t.currentDevice,t.mtu),t._getBLEDeviceServices(),t._registerConnStatusListener()},fail:function(n){console.log("调节失败,直接获取MTU,"+JSON.stringify(n)),wx.getBLEMTU({deviceId:e.deviceId,success:function(e){console.log("调节MTU成功,"+JSON.stringify(e.mtu)),t.mtu=e.mtu,t.callback&&t.callback.onMTUChange&&t.currentDevice&&t.callback.onMTUChange(t.currentDevice,t.mtu),t._getBLEDeviceServices(),t._registerConnStatusListener()},fail:function(e){console.log("调节MTU失败,"+JSON.stringify(e)),t.disconnect(),t._connectFailed()}})}}):setTimeout(function(){wx.getBLEMTU({writeType:"writeNoResponse",deviceId:e.deviceId,success:function(e){console.log("iOS调节MTU成功,api的mtu"+JSON.stringify(e.mtu)),e.mtu==23?t.mtu=128:t.mtu=e.mtu,console.log("iOS调节MTU成功,最终的mtu"+JSON.stringify(e.mtu)),t.callback&&t.callback.onMTUChange&&t.currentDevice&&(console.log("iOS调节MTU成功回调"),t.callback.onMTUChange(t.currentDevice,t.mtu)),t._getBLEDeviceServices(),t._registerConnStatusListener()},fail:function(e){console.log("调节MTU失败,"+JSON.stringify(e)),t.disconnect(),t._connectFailed()}})},100)},fail:function(e){if(console.log("连接失败,"+ +JSON.stringify(e)),t.status==2){console.log("连接失败,已在onBLEConnectionStateChange处理,所以不做回调");return}else t._connectFailed()}}),!0)}},{key:"setMaxMTU",value:function e(e){this.maxMTU=e}},{key:"disconnect",value:function e(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!0;this.isConnectedOrConnecting()&&this.currentDevice&&(wx.closeBLEConnection({deviceId:this.currentDevice.deviceId}),e&&this._disconnect())}},{key:"setCallback",value:function e(e){this.callback=e}},{key:"getConnectedDevice",value:function e(){return this.isConnected()?this.currentDevice:null}},{key:"getCommunicationService",value:function e(){return this.communicationService}},{key:"getCommunication",value:function e(){return this.communication}},{key:"getCommunicationWriteCharacteristic",value:function e(){return this.communicationWriteCharacteristic}},{key:"getCommunicationReadCharacteristic",value:function e(){return this.communicationReadCharacteristic}},{key:"getMTU",value:function e(){if(this.isConnected())return this.mtu}},{key:"isConnectedOrConnecting",value:function e(){return this.isConnected()||this.isConnecting()}},{key:"isConnecting",value:function e(){return this.status==1||this.status==2}},{key:"isConnected",value:function e(){return this.status==3}},{key:"_registerConnStatusListener",value:function e(){var e=this,n=function t(t){if(console.log("蓝牙连接状态变化"+JSON.stringify(t)),e.currentDevice&&e.currentDevice.deviceId!=t.deviceId){console.log("不是同一设备"+JSON.stringify(t)),console.log("不是同一设备1"+JSON.stringify(e.currentDevice));return}if(!t.connected)if(wx.offBLEConnectionStateChange(n),e.status==3){var a=new Date;e.disconnectTime=a.getTime(),e._disconnect()}else e._connectFailed()};wx.onBLEConnectionStateChange(n)}},{key:"_getBLEDeviceServices",value:function e(){var e=this;if(this.currentDevice){var n=this.currentDevice.deviceId;console.log("获取所有服务的 uuid:"+n),setTimeout(function(){wx.getBLEDeviceServices({deviceId:n,success:function(t){console.log("获取设备服务成功:"+JSON.stringify(t.services));var a=t.services;if(a.length<=0){e._connectFailed();return}e.communicationService=e.communication.onMatchingService(a),e.communicationService?e._getBLEDeviceCharacteristics(n,e.communicationService.uuid):(console.log("未能找到对应的service uuid"),e._connectFailed())},fail:function(n){console.log("获取设备服务失败,错误码:"+n.errCode),e._connectFailed()}})},1e3)}}},{key:"_getBLEDeviceCharacteristics",value:function e(e,n){var t=this;console.log("获取某个服务下的所有特征值 deviceId="+e+" serviceId="+n),wx.getBLEDeviceCharacteristics({deviceId:e,serviceId:n,success:function(a){var i=a.characteristics;if(console.log("getBLEDeviceCharacteristics list="+JSON.stringify(i)),i.length<=0){t._connectFailed();return}var o=!1,c=t.communication.onMatchingServiceCharacteristic();i.forEach(function(a){c.write==a.uuid&&(t.communicationWriteCharacteristic=a),c.notify==a.uuid&&(t._notifyBLECharacteristicValueChange({deviceId:e,serviceId:n,characteristicId:a.uuid}),o=!0),c.read==a.uuid&&(t.communicationReadCharacteristic=a)}),o||(console.log("未能找到Notify特征值!"),t._connectFailed())},fail:function(e){console.log("获取特征值失败,错误码:"+e.errCode),t._connectFailed()}})}},{key:"_notifyBLECharacteristicValueChange",value:function e(e){var n=this;wx.notifyBLECharacteristicValueChange({state:!0,deviceId:e.deviceId,serviceId:e.serviceId,characteristicId:e.characteristicId,success:function(t){console.log("使能通知成功:"+JSON.stringify(t),e.characteristicId),n._connectSuccsed()},fail:function(e){console.log("使能通知失败"+JSON.stringify(e)),n._connectFailed()}})}},{key:"_disconnect",value:function e(){this.status=0,this.callback&&this.callback.onDisconnect&&this.currentDevice&&this.callback.onDisconnect(this.currentDevice)}},{key:"_connectFailed",value:function e(){this.status=0,this.callback&&this.callback.onFailed&&this.currentDevice&&this.callback.onFailed(this.currentDevice)}},{key:"_connectSuccsed",value:function e(){this.status=3,this.callback&&this.callback.onSuccess&&this.currentDevice&&this.callback.onSuccess(this.currentDevice)}}]);return e}();var e2=/*#__PURE__*/function(){"use strict";function e(){var n=this;i(this,e);this.services=[];this.scanList=[];this.foundDeviceMacSet=new Set;this.timeoutId=null;this.callback=null;this.scanTime=3e4;this._onBluetoothDeviceFound(),wx.onBluetoothAdapterStateChange(function(e){n._onAdapter(e),e.available?e.available&&e.discovering&&(n.scanList=[],n.foundDeviceMacSet=new Set,n._onFound(n.scanList)):(e.discovering&&n.stopScan(),n.scanList=[],n.foundDeviceMacSet=new Set)})}c(e,[{key:"setCallback",value:function e(e){this.callback=e}},{key:"setScanTime",value:function e(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:3e4;this.scanTime=e}},{key:"setServices",value:function e(e){this.services=e}},{key:"startScan",value:function e(){var e=this;this._stopTiming(),this.scanList=[],this.foundDeviceMacSet=new Set,this._getAdapterStatus({fail:function(){e._openAdapter()}})}},{key:"stopScan",value:function e(){var e=this;var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!0;this._stopTiming(),wx.stopBluetoothDevicesDiscovery({success:function(){n&&e._onStop()},fail:function(){}})}},{key:"_onBluetoothDeviceFound",value:function e(){var e=this;wx.onBluetoothDeviceFound(function(n){var t=n.devices;!t||t.length<1||(t.forEach(function(n){var t=n.deviceId;!e.foundDeviceMacSet.has(t)&&n.name&&(e.scanList.push(n),e.foundDeviceMacSet.add(t))}),e._onFound(e.scanList))})}},{key:"_openAdapter",value:function e(){var e=this;wx.openBluetoothAdapter({fail:function(n){e._onFailed(n)},success:function(){e._getAdapterStatus(null)}})}},{key:"_getAdapterStatus",value:function e(e){var n=this;wx.getBluetoothAdapterState({success:function(e){if(e.available&&e.discovering){n._startTiming(),n._onFound(n.scanList),n._onSuccess();return}n._startScan()},fail:function(t){e!=null&&e.fail?e.fail(t):n._onFailed(t)}})}},{key:"_startScan",value:function e(){var e=this;wx.startBluetoothDevicesDiscovery({allowDuplicatesKey:!0,services:this.services,interval:200,success:function(n){e._onBluetoothDeviceFound(),e._startTiming(),e._onSuccess()},fail:function(n){e._onFailed(n)}})}},{key:"_stopTiming",value:function e(){this.timeoutId!=null&&clearTimeout(this.timeoutId),this.timeoutId=null}},{key:"_startTiming",value:function e(){var e=this;this.timeoutId=setTimeout(function(){e.stopScan()},this.scanTime)}},{key:"_onAdapter",value:function e(e){this.callback&&this.callback.onAdapter&&this.callback.onAdapter(e)}},{key:"_onSuccess",value:function e(){this.callback&&this.callback.onSuccess&&this.callback.onSuccess()}},{key:"_onFailed",value:function e(e){this.callback&&this.callback.onFailed&&this.callback.onFailed(e)}},{key:"_onFound",value:function e(e){this.callback&&this.callback.onFound&&this.callback.onFound(e)}},{key:"_onStop",value:function e(){this.callback&&this.callback.onStop&&this.callback.onStop()}}]);return e}();import{dataConversion as e4}from"@onbright/common-sdk";var e3=/*#__PURE__*/function(){"use strict";function e(n){i(this,e);this.callbacks=[];this.mtuMap=new Map;this.sendInfoArray=[];this.retryNum=0;this.protocolComponent=n}c(e,[{key:"init",value:function e(){var e=this;wx.onBLECharacteristicValueChange(function(n){var t,a;console.log("收到数据 serviceId uuid:"+n.serviceId+" characteristicId: "+n.characteristicId),console.log("收到数据:"+e4.ab2hex(n.value)),(t=(a=e.protocolComponent).onProcessNotifyData)===null||t===void 0?void 0:t.call(a,n).then(function(n){e._handlerData(n)})})}},{key:"addCallbacks",value:function e(e){this.callbacks.indexOf(e)==-1&&this.callbacks.push(e)}},{key:"removeCallbacks",value:function e(e){var n=this.callbacks.indexOf(e);n!=-1&&this.callbacks.splice(n,1)}},{key:"_handlerData",value:function e(e){this._doAction({action:function n(n){n.onReceiveData&&n.onReceiveData(e)}})}},{key:"_doAction",value:function e(e){this.callbacks.forEach(function(n){e.action(n)})}},{key:"setMtu",value:function e(e,n){this.mtuMap.set(e,n)}},{key:"sendData",value:function e(e,n,t,a){var i=this;var o,c;(o=(c=this.protocolComponent).onProcessingSentData)===null||o===void 0?void 0:o.call(c,a).then(function(a){var o=i.mtuMap.get(e),c=20;o!=null&&(c=o-3),console.log("realMTU --->"+c),console.log("realData length --->"+a.byteLength);var r=a.byteLength,u=Math.floor(r/c);for(var s=0;s<u;s++){var l=new Uint8Array(c);l.set(a.slice(s*c,s*c+l.length)),i._addSendData(e,n,t,l)}if(r%c!=0){var d=new Uint8Array(r%c);d.set(a.slice(r-r%c,r)),i._addSendData(e,n,t,d)}})}},{key:"_addSendData",value:function e(e,n,t,a){var i=this;var o=new e5(e,n,t,a);if(this.sendInfoArray.push(o),this.sendInfoArray.length>1)return!0;var c={complete:function(){i._writeDataToDevice(i.sendInfoArray,c)}};return this._writeDataToDevice(this.sendInfoArray,c),!0}},{key:"_writeDataToDevice",value:function e(e,n){var t=e.shift();if(t==null){var a;if(e.length==0)return;(a=n.complete)===null||a===void 0?void 0:a.call(n);return}this._sendData(t,n)}},{key:"_sendData",value:function e(e,n){var t=this;var a,i;return console.log("开始发送数据:->"+e4.ab2hex(e.data.buffer)+" serviceId:"+e.serviceId+" characteristicId:"+e.characteristicId),console.log("this.protocolComponent.sendDataWriteType()",((a=this.protocolComponent)===null||a===void 0?void 0:a.sendDataWriteType)?(i=this.protocolComponent)===null||i===void 0?void 0:i.sendDataWriteType():""),wx.writeBLECharacteristicValue({deviceId:e.deviceId,serviceId:e.serviceId,characteristicId:e.characteristicId,value:e.data.buffer,writeType:this.protocolComponent&&this.protocolComponent.sendDataWriteType?this.protocolComponent.sendDataWriteType():"write",fail:function(a){var i;t.retryNum++,t.retryNum>=3?(console.log("发送失败,重发数据:-> err="+JSON.stringify(a)+" retryNum = "+t.retryNum),t._sendData(e,n)):(t.retryNum=0,(i=n.complete)===null||i===void 0?void 0:i.call(n)),console.log("发送数据失败:-> err="+JSON.stringify(a))},success:function(){var a;console.log("发送数据成功:->"+e4.ab2hex(e.data.buffer)+" serviceId:"+e.serviceId),t.retryNum=0,(a=n.complete)===null||a===void 0?void 0:a.call(n)}}),!0}},{key:"readData",value:function e(e,n,t){wx.readBLECharacteristicValue({deviceId:e,serviceId:n,characteristicId:t})}}]);return e}(),e5=function e(n,t,a,o){"use strict";i(this,e);this.deviceId=n,this.serviceId=t,this.characteristicId=a,this.data=o};import{dataConversion as e6}from"@onbright/common-sdk";var e8,e7=/*#__PURE__*/function(){"use strict";function e(){i(this,e);this._ConnectHandler=null;this._ScanHandler=null;this._DataHandler=null;this._Cat1LockAuthHandler=null;this._isNeedAuth=!1;this._isHasAuth=!1;this._isAutoConnectDevices=!1;e8=this,this._BluetoothCallbackManager=new e9,console.log(" 初始化BluesManager"+this._BluetoothCallbackManager),e8._ScanHandler=new e2,e8.init()}c(e,[{key:"init",value:function e(){var e;var n={onFound:e8._onScanFound,onAdapter:e8._onScanAdapter,onSuccess:e8._onScanSuccess,onFailed:e8._onScanFailed,onStop:e8._onScanStop};(e=e8._ScanHandler)===null||e===void 0?void 0:e.setCallback(n)}},{key:"setConnectHandler",value:function e(e){var n={onDisconnect:e8._onConnectStateDisconnect,onFailed:e8._onConnectStateFailed,onSuccess:e8._onConnectStateSuccess,onMTUChange:e8._onConnectStateMTUChange};e8._ConnectHandler=new e1(e),e8._ConnectHandler.setCallback(n)}},{key:"setDataHandler",value:function e(e){e8._DataHandler=new e3(e)}},{key:"setNeedAuth",value:function e(e){e8._isNeedAuth=e}},{key:"setAutoConnectDevices",value:function e(e){e8._isAutoConnectDevices=e}},{key:"setHasAuth",value:function e(e){e8._isHasAuth=e}},{key:"hasAuth",value:function e(){return e8._isHasAuth}},{key:"setCat1LockAuthHandler",value:function e(e){e8._Cat1LockAuthHandler=e}},{key:"addBluetoothEventCallback",value:function e(e){e8._BluetoothCallbackManager.resetCallbacks(e)}},{key:"removeBluetoothEventCallback",value:function e(e){e8._BluetoothCallbackManager.removeCallbacks(e)}},{key:"startDeviceScan",value:function e(){var e;var n=wx.getAppAuthorizeSetting(),t=n.locationAuthorized,a=wx.getSystemSetting(),i=a.locationEnabled,o=a.bluetoothEnabled;if(t==="authorized"&&i&&o)(e=e8._ScanHandler)===null||e===void 0?void 0:e.startScan();else{var c="";t!=="authorized"?c="请允许微信使用定位的开关":i?o||(c="请打开蓝牙的系统开关"):c="请打开地理位置的系统开关",e8._BluetoothCallbackManager.onPermissionDenied({code:1e3,describe:c})}}},{key:"stopDeviceScan",value:function e(){var e;(e=e8._ScanHandler)===null||e===void 0?void 0:e.stopScan()}},{key:"isConnected",value:function e(){return e8._ConnectHandler&&e8._ConnectHandler.isConnected()}},{key:"getConnectedDevice",value:function e(){return e8._ConnectHandler&&e8._ConnectHandler.getConnectedDevice()}},{key:"connectDevice",value:function e(e,n){var t,a,i;var o,c;return((o=(a=this._ConnectHandler)===null||a===void 0?void 0:(t=a.getCommunication())===null||t===void 0?void 0:t.onConnectDeviceBefore)!==null&&o!==void 0?o:function(){return!1})(e)?(c=(i=this._ConnectHandler)===null||i===void 0?void 0:i.connect(e,n))!==null&&c!==void 0?c:!1:!1}},{key:"disconnectDevice",value:function e(){try{e8._ConnectHandler&&e8._ConnectHandler.disconnect()}catch(e){console.error("disconnectDevice error",e)}}},{key:"setScanTime",value:function e(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:3e4;var n;(n=e8._ScanHandler)===null||n===void 0?void 0:n.setScanTime(e)}},{key:"setServices",value:function e(e){var n;(n=e8._ScanHandler)===null||n===void 0?void 0:n.setServices(e)}},{key:"sendData",value:function e(e,n){return e8._SendData(e,n)}},{key:"readData",value:function e(e){if(e8._ConnectHandler&&e8._ConnectHandler.isConnected()&&e8._DataHandler){var n=e8._ConnectHandler.getConnectedDevice();if(n&&n.deviceId==e){var t=e8._ConnectHandler.getCommunicationService();if(t){var a=e8._ConnectHandler.getCommunicationReadCharacteristic();a&&e8._DataHandler.readData(e,t.uuid,a.uuid)}}}else console.error("readData error, _DataHandler is null")}},{key:"_SendData",value:function e(e,n){try{if(e8._ConnectHandler&&e8._ConnectHandler.isConnected()&&e8._DataHandler){var t=e8._ConnectHandler.getConnectedDevice();if(t&&t.deviceId==e){var a=e8._ConnectHandler.getCommunicationService();if(a){var i=e8._ConnectHandler.getCommunicationWriteCharacteristic();if(i)return e8._DataHandler.sendData(e,a.uuid,i.uuid,n),!0}}}}catch(e){console.error("_SendData error",e)}return!1}},{key:"_onScanFound",value:function e(e){var n,t;if(e&&e.length>0&&e8._isAutoConnectDevices){var a,i,o;var c=(a=e8._ConnectHandler)===null||a===void 0?void 0:a.getCommunication().onMatchingConnectDevice(e);c&&((i=e8._ConnectHandler)===null||i===void 0?void 0:i.connect(c,!1),(o=e8._ScanHandler)===null||o===void 0?void 0:o.stopScan())}var r;var u=((r=(t=e8._ConnectHandler)===null||t===void 0?void 0:(n=t.getCommunication())===null||n===void 0?void 0:n.onMatchingScanFound)!==null&&r!==void 0?r:function(){})(e);u&&(e=u),e8._BluetoothCallbackManager.onFoundDev(e)}},{key:"_onScanAdapter",value:function e(e){e8._BluetoothCallbackManager.onAdapter(e)}},{key:"_onScanSuccess",value:function e(){e8._BluetoothCallbackManager.onScanSuccess()}},{key:"_onScanFailed",value:function e(e){e8._BluetoothCallbackManager.onScanFailed(e)}},{key:"_onScanStop",value:function e(){var e;((e=e8._ConnectHandler)===null||e===void 0?void 0:e.isConnectedOrConnecting())||e8._BluetoothCallbackManager.onScanNotFound(),e8._BluetoothCallbackManager.onScanStop()}},{key:"_onConnectStateDisconnect",value:function e(e){e8._isHasAuth=!1,e8._BluetoothCallbackManager.onDevStatusDisconnect(e)}},{key:"_onConnectStateFailed",value:function e(e){var n;e8._isHasAuth=!1,(n=e8._ScanHandler)===null||n===void 0?void 0:n.startScan(),e8._BluetoothCallbackManager.onDevStatusFailed(e)}},{key:"_onConnectStateSuccess",value:function e(e){return a(function(){var n,t,a,i,o;return f(this,function(c){if(e&&e8._DataHandler){;(n=e8._DataHandler)===null||n===void 0?void 0:n.init();a={onReceiveData:function e(e){e8._onTransmitDeviceData(e)}};if(e8._isNeedAuth&&!e8._isHasAuth&&e8._Cat1LockAuthHandler){i={onAuthSuccess:function n(){if(e8._ConnectHandler&&e8._ConnectHandler.getCommunicationService()){var n;var t=e8._ConnectHandler.getCommunicationService();e8._resetNotifyBLECharacteristicValueChange({deviceId:e.deviceId,serviceId:t?t.uuid:"",characteristicId:(n=e8._ConnectHandler)===null||n===void 0?void 0:n.getCommunication().onMatchingServiceCharacteristic().notify})}e8._BluetoothCallbackManager.onAuthSuccess(),e8._isHasAuth=!0},onAuthFailed:function e(){console.log("Cat1LockAuthCallback onAuthFailed"),e8._BluetoothCallbackManager.onAuthFailed(),e8._isHasAuth=!1}};e8._Cat1LockAuthHandler.setCallback(i);o=e6.ab2hex(e.advertisData);e8._Cat1LockAuthHandler.handleSendData(e.deviceId,o)}(t=e8._DataHandler)===null||t===void 0?void 0:t.addCallbacks(a),console.log("onDevStatusSuccess 连接成功"),e8._BluetoothCallbackManager.onDevStatusSuccess(e)}else console.error("_onConnectStateSuccess error, dev or _DataHandler is null");return[2]})})()}},{key:"_onConnectStateMTUChange",value:function e(e,n){var t;e&&e8._DataHandler?((t=e8._DataHandler)===null||t===void 0?void 0:t.setMtu(e.deviceId,n),e8._BluetoothCallbackManager.onDevStatusMTUChange(e,n)):console.error("_onConnectStateMTUChange error, dev or _DataHandler is null")}},{key:"_resetNotifyBLECharacteristicValueChange",value:function e(e){wx.notifyBLECharacteristicValueChange({state:!0,deviceId:e.deviceId,serviceId:e.serviceId,characteristicId:e.characteristicId,success:function(e){var n;console.log("重置通知成功:"+JSON.stringify(e)),(n=e8._DataHandler)===null||n===void 0?void 0:n.init()},fail:function(e){console.log("重置通知失败"+JSON.stringify(e))}})}},{key:"_onTransmitDeviceData",value:function e(e){e8._BluetoothCallbackManager.onTransmitDeviceData(e)}},{key:"resetBluetoothData",value:function e(){e8._handleCloseMonitoring(),e8.setHasAuth(!1)}},{key:"_handleCloseMonitoring",value:function e(){var e,n;(e=e8._ScanHandler)===null||e===void 0?void 0:e.stopScan(!1),wx.offBluetoothDeviceFound(),wx.offBluetoothAdapterStateChange(),wx.closeBluetoothAdapter(),wx.offBLEMTUChange(),wx.offBLEConnectionStateChange(),wx.offBLECharacteristicValueChange(),(n=e8._ConnectHandler)===null||n===void 0?void 0:n.disconnect(!1)}}]);return e}(),e9=/*#__PURE__*/function(){"use strict";function e(){i(this,e);this.callbacks=Array()}c(e,[{key:"resetCallbacks",value:function e(e){this.callbacks=[e]}},{key:"addCallbacks",value:function e(e){this.callbacks.indexOf(e)==-1&&this.callbacks.push(e)}},{key:"removeCallbacks",value:function e(e){var n=this.callbacks.indexOf(e);n!=-1&&this.callbacks.splice(n,1)}},{key:"onPermissionDenied",value:function e(e){this._doAction({action:function n(n){n.onPermissionDenied&&n.onPermissionDenied(e)}})}},{key:"onAdapter",value:function e(e){this._doAction({action:function n(n){n.onAdapter&&n.onAdapter(e)}})}},{key:"onFoundDev",value:function e(e){this._doAction({action:function n(n){n.onFoundDev&&n.onFoundDev(e)}})}},{key:"onScanSuccess",value:function e(){this._doAction({action:function e(e){e.onScanSuccess&&e.onScanSuccess()}})}},{key:"onScanFailed",value:function e(e){this._doAction({action:function n(n){n.onScanFailed&&n.onScanFailed(e)}})}},{key:"onScanStop",value:function e(){this._doAction({action:function e(e){e.onScanStop&&e.onScanStop()}})}},{key:"onScanNotFound",value:function e(){this._doAction({action:function e(e){e.onScanNotFound&&e.onScanNotFound()}})}},{key:"onDevStatusDisconnect",value:function e(e){this._doAction({action:function n(n){n.onDevStatusDisconnect&&n.onDevStatusDisconnect(e)}})}},{key:"onDevStatusFailed",value:function e(e){this._doAction({action:function n(n){n.onDevStatusFailed&&n.onDevStatusFailed(e)}})}},{key:"onDevStatusSuccess",value:function e(e){this._doAction({action:function n(n){n.onDevStatusSuccess&&n.onDevStatusSuccess(e)}})}},{key:"onDevStatusMTUChange",value:function e(e,n){this._doAction({action:function t(t){t.onDevStatusMTUChange&&t.onDevStatusMTUChange(e,n)}})}},{key:"onTransmitDeviceData",value:function e(e){this._doAction({action:function n(n){n.onTransmitDeviceData&&n.onTransmitDeviceData(e)}})}},{key:"onAuthSuccess",value:function e(){this._doAction({action:function e(e){e.onAuthSuccess&&e.onAuthSuccess()}})}},{key:"onAuthFailed",value:function e(){this._doAction({action:function e(e){e.onAuthFailed&&e.onAuthFailed()}})}},{key:"_doAction",value:function e(e){this.callbacks.forEach(function(n){e.action(n)})}}]);return e}();var ne={BluetoothManager:e7,GenerationRule:es};export{e0 as Cat1LockAuthHandler,eX as ONBRIGHT_AUTH_BLUE_NOTIFY_UUID,eZ as ONBRIGHT_AUTH_BLUE_READ_UUID,eq as ONBRIGHT_AUTH_BLUE_UUID_SERVICE,eQ as ONBRIGHT_AUTH_BLUE_WRITE_UUID,ne as default};//# sourceMappingURL=index.js.map
function e(e,n){if(n==null||n>e.length)n=e.length;for(var t=0,a=new Array(n);t<n;t++)a[t]=e[t];return a}function n(n){if(Array.isArray(n))return e(n)}function t(e,n,t,a,i,o,c){try{var r=e[o](c);var u=r.value}catch(e){t(e);return}if(r.done){n(u)}else{Promise.resolve(u).then(a,i)}}function a(e){return function(){var n=this,a=arguments;return new Promise(function(i,o){var c=e.apply(n,a);function r(e){t(c,i,o,r,u,"next",e)}function u(e){t(c,i,o,r,u,"throw",e)}r(undefined)})}}function i(e,n){if(!(e instanceof n)){throw new TypeError("Cannot call a class as a function")}}function o(e,n){for(var t=0;t<n.length;t++){var a=n[t];a.enumerable=a.enumerable||false;a.configurable=true;if("value"in a)a.writable=true;Object.defineProperty(e,a.key,a)}}function c(e,n,t){if(n)o(e.prototype,n);if(t)o(e,t);return e}function r(e,n,t){if(n in e){Object.defineProperty(e,n,{value:t,enumerable:true,configurable:true,writable:true})}else{e[n]=t}return e}function u(e){if(typeof Symbol!=="undefined"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function s(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function l(e){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};var a=Object.keys(t);if(typeof Object.getOwnPropertySymbols==="function"){a=a.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))}a.forEach(function(n){r(e,n,t[n])})}return e}function d(e){return n(e)||u(e)||v(e)||s()}function v(n,t){if(!n)return;if(typeof n==="string")return e(n,t);var a=Object.prototype.toString.call(n).slice(8,-1);if(a==="Object"&&n.constructor)a=n.constructor.name;if(a==="Map"||a==="Set")return Array.from(a);if(a==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a))return e(n,t)}function f(e,n){var t,a,i,o,c={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]};return o={next:r(0),"throw":r(1),"return":r(2)},typeof Symbol==="function"&&(o[Symbol.iterator]=function(){return this}),o;function r(e){return function(n){return u([e,n])}}function u(o){if(t)throw new TypeError("Generator is already executing.");while(c)try{if(t=1,a&&(i=o[0]&2?a["return"]:o[0]?a["throw"]||((i=a["return"])&&i.call(a),0):a.next)&&!(i=i.call(a,o[1])).done)return i;if(a=0,i)o=[o[0]&2,i.value];switch(o[0]){case 0:case 1:i=o;break;case 4:c.label++;return{value:o[1],done:false};case 5:c.label++;a=o[1];o=[0];continue;case 7:o=c.ops.pop();c.trys.pop();continue;default:if(!(i=c.trys,i=i.length>0&&i[i.length-1])&&(o[0]===6||o[0]===2)){c=0;continue}if(o[0]===3&&(!i||o[1]>i[0]&&o[1]<i[3])){c.label=o[1];break}if(o[0]===6&&c.label<i[1]){c.label=i[1];i=o;break}if(i&&c.label<i[2]){c.label=i[2];c.ops.push(o);break}if(i[2])c.ops.pop();c.trys.pop();continue}o=n.call(e,c)}catch(e){o=[6,e];a=0}finally{t=i=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:true}}}var h=Object.defineProperty;var S=function(e,n){for(var t in n)h(e,t,{get:n[t],enumerable:!0})};import{dataConversion as p}from"@onbright/common-sdk";var g={};S(g,{Chinese:function(){return B},Dispense:function(){return F},HighLowConversion:function(){return eu},ab2hex:function(){return J},ab2hex2:function(){return j},abToA:function(){return R},advertisData:function(){return eo},binaryReverse:function(){return er},binaryToHex:function(){return V},checkSum:function(){return ea},checkSumValue:function(){return ei},dateTime2unixHex:function(){return X},dealMAC:function(){return ee},decimalToBinary:function(){return U},decimalToHex:function(){return N},getRandomNum:function(){return K},getSm4Value:function(){return Y},hex2Array:function(){return G},hex2Buff:function(){return W},hexReverse:function(){return ec},hexToDecimal:function(){return O},highLowBitCV:function(){return en},openKeyEctopicOr:function(){return et},padEndHex:function(){return q},padStartHex:function(){return Q},passTo8DBC:function(){return P},setSm4Value:function(){return z},setbit:function(){return Z},sliceHex:function(){return $}});import m from"bitwise";var y=[214,144,233,254,204,225,61,183,22,182,20,194,40,251,44,5,43,103,154,118,42,190,4,195,170,68,19,38,73,134,6,153,156,66,80,244,145,239,152,122,51,84,11,67,237,207,172,98,228,179,28,169,201,8,232,149,128,223,148,250,117,143,63,166,71,7,167,252,243,115,23,186,131,89,60,25,230,133,79,168,104,107,129,178,113,100,218,139,248,235,15,75,112,86,157,53,30,36,14,94,99,88,209,162,37,34,124,59,1,33,120,135,212,0,70,87,159,211,39,82,76,54,2,231,160,196,200,158,234,191,138,210,64,199,56,181,163,247,242,206,249,97,21,161,224,174,93,164,155,52,26,85,173,147,50,48,245,140,177,227,29,246,226,46,130,102,202,96,192,41,35,171,13,83,78,111,213,219,55,69,222,253,142,47,3,255,106,114,109,108,91,81,141,27,175,146,187,221,188,127,17,217,92,65,31,16,90,216,10,193,49,136,165,205,123,189,45,116,208,18,184,229,180,176,137,105,151,74,12,150,119,126,101,185,241,9,197,110,198,132,24,240,125,236,58,220,77,32,121,238,95,62,215,203,57,72],_=[462357,0x1c232a31,0x383f464d,0x545b6269,0x70777e85,0x8c939aa1,0xa8afb6bd,0xc4cbd2d9,0xe0e7eef5,0xfc030a11,0x181f262d,0x343b4249,0x50575e65,0x6c737a81,0x888f969d,0xa4abb2b9,0xc0c7ced5,0xdce3eaf1,0xf8ff060d,0x141b2229,0x30373e45,0x4c535a61,0x686f767d,0x848b9299,0xa0a7aeb5,0xbcc3cad1,0xd8dfe6ed,0xf4fb0209,0x10171e25,0x2c333a41,0x484f565d,0x646b7279];function k(e){var n=[];for(var t=0,a=e.length;t<a;t+=2)n.push(parseInt(e.substr(t,2),16));return n}function x(e){return e.map(function(e){return e=e.toString(16),e.length===1?"0"+e:e}).join("")}function C(e){var n=[];for(var t=0,a=e.length;t<a;t++){var i=e.codePointAt(t);if(i<=127)n.push(i);else if(i<=2047)n.push(192|i>>>6),n.push(128|i&63);else if(i<=55295||i>=57344&&i<=65535)n.push(224|i>>>12),n.push(128|i>>>6&63),n.push(128|i&63);else if(i>=65536&&i<=1114111)t++,n.push(240|i>>>18&28),n.push(128|i>>>12&63),n.push(128|i>>>6&63),n.push(128|i&63);else throw n.push(i),new Error("input is not supported")}return n}function b(e,n){return e<<n|e>>>32-n}function H(e){return(y[e>>>24&255]&255)<<24|(y[e>>>16&255]&255)<<16|(y[e>>>8&255]&255)<<8|y[e&255]&255}function D(e){return e^b(e,2)^b(e,10)^b(e,18)^b(e,24)}function A(e){return e^b(e,13)^b(e,23)}function w(e,n,t){var a=new Array(4),i=new Array(4);for(var o=0;o<4;o++)i[0]=e[4*o]&255,i[1]=e[4*o+1]&255,i[2]=e[4*o+2]&255,i[3]=e[4*o+3]&255,a[o]=i[0]<<24|i[1]<<16|i[2]<<8|i[3];for(var c=0,r;c<32;c+=4)r=a[1]^a[2]^a[3]^t[c+0],a[0]^=D(H(r)),r=a[2]^a[3]^a[0]^t[c+1],a[1]^=D(H(r)),r=a[3]^a[0]^a[1]^t[c+2],a[2]^=D(H(r)),r=a[0]^a[1]^a[2]^t[c+3],a[3]^=D(H(r));for(var u=0;u<16;u+=4)n[u]=a[3-u/4]>>>24&255,n[u+1]=a[3-u/4]>>>16&255,n[u+2]=a[3-u/4]>>>8&255,n[u+3]=a[3-u/4]&255}function E(e,n,t){var a=new Array(4),i=new Array(4);for(var o=0;o<4;o++)i[0]=e[0+4*o]&255,i[1]=e[1+4*o]&255,i[2]=e[2+4*o]&255,i[3]=e[3+4*o]&255,a[o]=i[0]<<24|i[1]<<16|i[2]<<8|i[3];a[0]^=0xa3b1bac6,a[1]^=0x56aa3350,a[2]^=0x677d9197,a[3]^=0xb27022dc;for(var c=0,r;c<32;c+=4)r=a[1]^a[2]^a[3]^_[c+0],n[c+0]=a[0]^=A(H(r)),r=a[2]^a[3]^a[0]^_[c+1],n[c+1]=a[1]^=A(H(r)),r=a[3]^a[0]^a[1]^_[c+2],n[c+2]=a[2]^=A(H(r)),r=a[0]^a[1]^a[2]^_[c+3],n[c+3]=a[3]^=A(H(r));if(t===0)for(var u=0,s;u<16;u++)s=n[u],n[u]=n[31-u],n[31-u]=s}function I(e,n,t){var a=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{},i=a.padding,o=i===void 0?"pkcs#7":i,c=a.mode,r=a.iv,u=r===void 0?[]:r,s=a.output,l=s===void 0?"string":s;if(c==="cbc"&&(typeof u=="string"&&(u=k(u)),u.length!==128/8))throw new Error("iv is invalid");if(console.log("inArray, key",e,n),typeof n=="string"&&(n=k(n)),n.length!==128/8)throw new Error("key is invalid");if(typeof e=="string"?t!==0?e=C(e):e=k(e):e=d(e),(o==="pkcs#5"||o==="pkcs#7")&&t!==0){var v=16-e.length%16;for(var f=0;f<v;f++)e.push(v)}var h=new Array(32);E(n,h,t);var S=[],p=u,g=e.length,m=0;for(;g>=16;){var y=e.slice(m,m+16),_=new Array(16);if(c==="cbc")for(var b=0;b<16;b++)t!==0&&(y[b]^=p[b]);w(y,_,h);for(var H=0;H<16;H++)c==="cbc"&&t===0&&(_[H]^=p[H]),S[m+H]=_[H];c==="cbc"&&(t!==0?p=_:p=y),g-=16,m+=16}return l!=="array"?x(S):S}var T={encrypt:function e(e,n,t){return I(e,n,1,t)},decrypt:function e(e,n,t){return I(e,n,0,t)}};function B(e,n){e.value=e.options[e.value],n()}function F(e,n){n()}var L=function(e,n,t){return parseInt(e,n).toString(t)},M=function(e,n){var t=L(e,n,16);return t.length<2?"0".concat(t):t};function U(e,n){e.value=L(e.value,10,2),n()}function V(e,n){e.value=M(e.value,2),n()}function N(e,n){e.value=M(e.value,10),n()}function O(e,n){var t=L(e.value,16,10);e.value=t,n()}function P(e,n){var t=new Array(16),a=e.value.split("");e.value=t.fill("F").map(function(e,n){return a[n]&&(e=a[n]),e}).join(""),n()}function R(e,n){e.value=Array.from(new Uint8Array(e.value)),n()}function J(e,n){var t=Array.from(new Uint8Array(e.value),function(e){return("00"+e.toString(16)).slice(-2)});e.value=t.join(""),n()}function j(e,n){e.ab2hex2="";var t=Array.from(new Uint8Array(e.value),function(n,t){if(t!==0&&t!==1)return("00"+n.toString(16)).slice(-2);e.ab2hex2+=("00"+n.toString(16)).slice(-2)});e.value=t.join(""),n()}function K(e,n){var t=parseInt(e.value,16).toString(2).padStart(32,"0").split("").map(function(e){return e==="0"?1:0}).join("");e.value=parseInt(t,2).toString(16),n()}function W(e,n){var t=new Uint8Array(e.value.match(/[\da-f]{2}/gi).map(function(e){return parseInt(e,16)}));e.value=t.buffer,n()}function G(e,n){console.log("转之前数据",e.value);var t=new Uint8Array(e.value.match(/[\da-f]{2}/gi).map(function(e){return parseInt(e,16)}));e.value=t,n()}function z(e,n){console.log("加密参数",e.value,e.key);var t=T.encrypt(e.value,e.key);e.value=t.slice(0,32),console.log("加密后",e.value),e.checkSum&&(e.value=e.checkSum+e.value,console.log("加密后有校验核添加校验核",e.value)),n()}function Y(e,n){console.log("解密参数",e.key,e.value),e.value=T.decrypt(e.value,e.key),console.log("解密后",e.value),e.ab2hex2&&(e.value=e.ab2hex2+e.value,console.log("解密后有操作命令和校验核添加命令和校验",e.value)),n()}function $(e,n){e.value=e.value.slice(e.sliceHex),n()}function q(e,n){e.value=e.value.padEnd(e.padEndHex,e.padEndValue),n()}function Q(e,n){e.value=e.value.padStart(e.padStartHex,e.padStartValue),n()}function X(e,n){e.value=dayjs(e.value).unix().toString(16).padStart(8,"0"),n()}function Z(e,n){e.value=e.value.reduce(function(e,n){return console.log(e,n),m.integer.setBit(e,parseInt(n),1)},0),n()}function ee(e,n){e.value=e.value.replace(/:/g,""),n()}function en(e,n){var t=e.value.slice(0,2),a=e.value.slice(2,4);e.value="".concat(a).concat(t),n()}function et(e,n){var t="";for(var a=0;a<16;a++){var i=(parseInt(e.value.slice(0,16).charAt(a),16)^parseInt(e.value.slice(16,32).charAt(a),16)).toString(16).toUpperCase();t+=i}e.value=t,n()}function ea(e,n){e.checkSum=(e.value.split("").reduce(function(e,n,t,a){if(t%2===0){var i=a[t]+""+a[t+1];return e+parseInt(i,16)}else return e},0)&255).toString(16).padStart(2,"0").slice(-2),console.log("o命令校验核",e.checkSum),n()}function ei(e,n){var t=e.value.split(""),a=[];for(var i=0;i<t.length-1;i++)if(i%2===0){var o=t[i]+""+t[i+1];a.push(o)}var c=0;a.forEach(function(e){c+=parseInt(e,16)}),e.value=c.toString(16).padStart(4,"0").slice(-4),n()}function eo(e,n){var t=e.value.slice(2,14),a=e.value.slice(14,16),i=e.value.slice(16,18);e.value="".concat(t,"|").concat(a,"|").concat(i),n()}function ec(e,n){e.value=e.value.match(/[\da-f]{2}/gi).reverse().join(""),n()}function er(e,n){e.value=e.value.split("").reverse().join(""),n()}function eu(e,n){var t=[];for(var a=0;a<e.value.length;a+=2)t.push(e.value.substring(a,a+2));e.value=t.reverse().join(""),n()}function es(e,n){var t=el(e);n=n||{use:[]};var i=ed(n.use);return /*#__PURE__*/function(){var o=a(function(a){var o,c,r,u,s,d,v;var h=arguments;return f(this,function(f){switch(f.label){case 0:o=h.length>1&&h[1]!==void 0?h[1]:{};c=function(n,t){return e.map(function(e,n){return e.value=t[n],e=l({},e,o),r(e,n)})},r=function(e,n){return new Promise(function(a,i){t[n](e,function(e,n){n(),a(e.value)})})},u=function(e){return new Promise(function(t,a){n.value=e,n=l({},n,o),i(n,function(e,n){n(),t(e.value)})})};f.label=1;case 1:f.trys.push([1,4,,5]);return[4,c(e,a)];case 2:s=f.sent();return[4,Promise.all(s)];case 3:d=f.sent().join("");return[2,u(d)];case 4:v=f.sent();throw new Error(v);case 5:return[2]}})});return function(e){return o.apply(this,arguments)}}()}function el(e){return function(e){return e.map(function(e){return ed(e.use)})}(e)}function ed(e){if(!Array.isArray(e))throw new Error("use stack must be an array!");var n=true,t=false,a=undefined;try{for(var i=e[Symbol.iterator](),o;!(n=(o=i.next()).done);n=true){var c=o.value;if(typeof g[c]!="function")throw new Error("use must be composed of functions!")}}catch(e){t=true;a=e}finally{try{if(!n&&i.return!=null){i.return()}}finally{if(t){throw a}}}return function(n,t){var a=-1;return i(0);function i(o){if(o<=a)return Promise.reject(new Error("next() called multiple times"));a=o;var c=g[e[o]]||(o===e.length?t:null);if(!c)return Promise.resolve();try{return Promise.resolve(c(n,i.bind(null,o+1)))}catch(e){return Promise.reject(e)}}}}var ev=es([{use:[]},{use:["passTo8DBC"]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),ef=es([{use:[]},{use:[]},{use:["passTo8DBC"]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eh=es([{use:[]},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eS=es([{use:["padEndHex"],padEndHex:10}]),ep=es([{use:["ab2hex","sliceHex","getRandomNum","padStartHex"],sliceHex:-8,padStartHex:8,padStartValue:"0"},{use:[]},{use:[]},{use:[]}],{use:["padEndHex","hex2Array","setSm4Value","hex2Buff"],padEndHex:32}),eg=es([{use:["ab2hex","sliceHex","getRandomNum","padStartHex"],sliceHex:-8,padStartHex:0,padStartValue:"0"},{use:[]},{use:[]},{use:[]}],{use:["padEndHex","hex2Array","setSm4Value","hex2Buff"],padEndHex:32}),em=es([{use:[]},{use:[]}],{use:["hex2Buff"]}),ey=es([{use:["decimalToHex","padStartHex","HighLowConversion"],padStartHex:6,padStartValue:"0"},{use:[]}],{use:["hex2Buff"]}),e_=es([{use:["ab2hex","hex2Array","getSm4Value"]}]),ek=es([{use:["ab2hex2","hex2Array","getSm4Value"]}]),ex=es([{use:["advertisData"]}]),eC=es([{use:["highLowBitCV"]}]),eb=es([{use:[]},{use:[]},{use:[]}],{use:["padEndHex","hex2Array","setSm4Value","openKeyEctopicOr"],padEndHex:32}),eH=es([{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eD=es([{use:[]},{use:["decimalToBinary","padStartHex"],padStartHex:2,padStartValue:"0"},{use:[]}],{use:["binaryToHex","HighLowConversion"]}),eA=es([{use:["decimalToHex"]},{use:["decimalToHex"]},{use:["setbit","decimalToHex"]},{use:[]}],{use:["hexReverse"]}),ew=es([{use:["decimalToHex"]},{use:["decimalToHex"]},{use:[]},{use:[]}],{use:["hexReverse"]}),eE=es([{use:[]},{use:["padStartHex"],padStartHex:4,padStartValue:"0"},{use:["padStartHex"],padStartHex:4,padStartValue:"0"},{use:[]},{use:["HighLowConversion"]},{use:["HighLowConversion"]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eI=es([{use:[]},{use:["padStartHex"],padStartHex:4,padStartValue:"0"},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eT=es([{use:[]},{use:[]},{use:[]},{use:[]}],{use:["checkSumValue"]}),eB=es([{use:["HighLowConversion"]},{use:[]},{use:["HighLowConversion"]},{use:[]},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eF=es([{use:[]},{use:["decimalToHex"]},{use:["padStartHex"],padStartHex:4,padStartValue:"0"},{use:[]},{use:["decimalToHex"]},{use:["decimalToHex"]},{use:["padEndHex"],padEndHex:16},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eL=es([{use:["ab2hex"]}]),eM=es([{use:["ab2hex","hexToDecimal"]},{use:[]}]),eU=es([{use:[]},{use:[]},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eV=es([{use:[]},{use:[]},{use:[]},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eN=es([{use:[]},{use:[]},{use:[]},{use:[]},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eO=es([{use:[]},{use:[]},{use:["padStartHex"],padStartHex:4,padStartValue:"0"},{use:[]},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eP=es([{use:[]},{use:["decimalToHex","padStartHex"],padStartHex:2,padStartValue:"0"},{use:["padStartHex"],padStartHex:8,padStartValue:"0"},{use:["decimalToHex","padStartHex"],padStartHex:8,padStartValue:"0"},{use:["decimalToHex","padStartHex"],padStartHex:8,padStartValue:"0"},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eR=es([{use:[]},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eJ=es([{use:[]},{use:["decimalToHex","padStartHex"],padStartHex:8,padStartValue:"0"},{use:[]},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),ej=es([{use:["decimalToHex","padStartHex","HighLowConversion"],padStartHex:6,padStartValue:"0"},{use:[]}]),eK=es([{use:[]},{use:["decimalToHex","padStartHex","HighLowConversion"],padStartHex:8,padStartValue:"0"}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eW=es([{use:[]},{use:["decimalToHex","padStartHex","HighLowConversion"],padStartHex:8,padStartValue:"0"},{use:["HighLowConversion"]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eG=es([{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),ez=es([{use:[]},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eY={deviceBind:ev,deviceBindNew:ef,setSm4Auth:ep,deviceOperate:em,firmwareContent:ey,getSm4Auth:e_,getSm4AuthOperate:ek,getadvertisData:ex,getHighLow:eC,getOpenHushKey:eb,getDeviceSerialId:eH,passwordDbc:eS,getUserProperty:eD,getCycleStart:eA,getCycleEnd:ew,updateUser:eE,deleteUser:eI,getLockDataSum:eT,getLockDataSm4:eB,createKeySm4:eF,getNoSm4Data:eL,setBuletVolume:eU,setBuleStay:eV,setBuleClose:eN,deleteKeySm4:eO,voiceMessageSm4:eP,voicePgVsSm4:eR,issuceVoicePgSm4:eJ,issuceAnySm4:ej,getNoSm4Butter:eM,setSm4AuthCon:eg,syncKeyList:eh,getLogSm4Data:eK,firmwareUpReady:eW,getLockState:eG,setBuleLocked:ez},e$=eY;var eq="00004F42-0000-1000-8000-00805F9B34FB",eQ="00004F00-0000-1000-8000-00805F9B34FB",eX="00004F00-0000-1000-8000-00805F9B34FB",eZ="00004F00-0000-1000-8000-00805F9B34FB",e0=/*#__PURE__*/function(){"use strict";function e(n,t,a){i(this,e);this.grade="";this.userId="";this.advertisData=new ArrayBuffer(1);this.hexStr="";this.padEndValue="ab";this.timeUnix="";this.callback=null;this.grade=n,this.userId=t,this.timeUnix=a}c(e,[{key:"handleAuthenticationData",value:function e(){return new Uint8Array}},{key:"handleSendData",value:function e(e,n){var t=this;return a(function(){var i;return f(this,function(o){switch(o.label){case 0:t.hexStr=n;return[4,t.onProcessingSentData()];case 1:i=o.sent();console.log("data",i),wx.writeBLECharacteristicValue({deviceId:e,serviceId:eq,characteristicId:eQ,value:i,fail:function(e){console.log("发送数据失败:-> err="+JSON.stringify(e))},success:function(){console.log("发送数据成功:->"+p.ab2hex(i)+" serviceId:"+eq)}}),wx.notifyBLECharacteristicValueChange({state:!0,deviceId:e,serviceId:eq,characteristicId:eX,success:function(e){console.log("使能通知成功:"+JSON.stringify(e))},fail:function(e){console.log("使能通知失败"+JSON.stringify(e)),t.callback&&t.callback.onAuthFailed&&t.callback.onAuthFailed()}}),wx.onBLECharacteristicValueChange(/*#__PURE__*/function(){var e=a(function(e){var n,a,i,o,c,r,u,s;return f(this,function(l){switch(l.label){case 0:console.log("收到数据 serviceId uuid:"+e.serviceId+" characteristicId: "+e.characteristicId),console.log("收到数据:"+p.ab2hex(e.value));r=e$.getSm4Auth;u=[[e.value]];s={};return[4,t._getKey()];case 1:return[4,r.apply(e$,u.concat([(s.key=l.sent(),s)]))];case 2:i=l.sent(),o=i.slice(0,2),c=i.slice(2,6);console.log("notifyValue",i,"grade",o,"userId",c),o===t.grade&&c===t.userId?(n=t.callback)===null||n===void 0?void 0:n.onAuthSuccess():(a=t.callback)===null||a===void 0?void 0:a.onAuthFailed(),wx.offBLECharacteristicValueChange();return[2]}})});return function(n){return e.apply(this,arguments)}}());return[2]}})})()}},{key:"setCallback",value:function e(e){this.callback=e}},{key:"onMatchingServiceCharacteristic",value:function e(){return{write:eQ,notify:eX,read:eZ}}},{key:"onProcessingSentData",value:function e(){var e=this;return new Promise(/*#__PURE__*/function(){var n=a(function(n,t){var a,i,o;return f(this,function(t){switch(t.label){case 0:a=e$.setSm4Auth;i=[[e.advertisData,e.grade,e.userId,e.timeUnix]];o={};return[4,e._getKey()];case 1:return[4,a.apply(e$,i.concat([(o.key=t.sent(),o.padEndValue="0",o)]))];case 2:n.apply(void 0,[t.sent()]);return[2]}})});return function(e,t){return n.apply(this,arguments)}}())}},{key:"onProcessNotifyData",value:function e(e){return console.log("onProcessNotifyData收到协议了",e),console.log("onProcessNotifyData收到协议了",e.value),new Promise(function(){})}},{key:"onProcessReadData",value:function e(e){return console.log("onProcessReadData 收到协议了",e),new Promise(function(){})}},{key:"_getKey",value:function e(){var e=this;return new Promise(/*#__PURE__*/function(){var n=a(function(n,t){var a,i,o,c,r;return f(this,function(t){switch(t.label){case 0:a="4F42424C45",i=e.hexStr.slice(2,14),o=e.hexStr.slice(-8),c=a+i+o;return[4,e._getSum(c)];case 1:r=t.sent();console.log("getSum",r),console.log("mac",i,"random",o,"numStr",r,"sm4Key",a+i+o+r),n(a+i+o+r);return[2]}})});return function(e,t){return n.apply(this,arguments)}}())}},{key:"_getSum",value:function e(e){return new Promise(function(n,t){n(e.split("").reduce(function(e,n,t,a){if(t%2===0){var i=a[t]+""+a[t+1];return e+parseInt(i,16)}else return e},0).toString(16).padStart(2,"0").slice(-2))})}}]);return e}();var e1=/*#__PURE__*/function(){"use strict";function e(n){i(this,e);this.status=0;this.callback=null;this.currentDevice=null;this.disconnectTime=0;this.mtu=0;this.maxMTU=512;this.communicationService=null;this.communicationWriteCharacteristic=null;this.communicationReadCharacteristic=null;this.communication=n}c(e,[{key:"connect",value:function e(e,n){var t=this;return new Date().getTime()-this.disconnectTime<2e3&&!n?(console.log("connect failed interval time <2000"),!1):this.isConnectedOrConnecting()?(console.log("connect failed is connected Or connecting"),!1):(this.status=1,this.currentDevice=e,console.log("开始连接设备 "+JSON.stringify(e)),wx.createBLEConnection({deviceId:e.deviceId,success:function(n){console.log("连接蓝牙成功:"+JSON.stringify(n.errMsg)),t.status=2,wx.getDeviceInfo().platform=="android"?wx.setBLEMTU({deviceId:e.deviceId,mtu:t.maxMTU,success:function(e){console.log("调节MTU成功,"+e.mtu),t.mtu=e.mtu,t.callback&&t.callback.onMTUChange&&t.currentDevice&&t.callback.onMTUChange(t.currentDevice,t.mtu),t._getBLEDeviceServices(),t._registerConnStatusListener()},fail:function(n){console.log("调节失败,直接获取MTU,"+JSON.stringify(n)),wx.getBLEMTU({deviceId:e.deviceId,success:function(e){console.log("调节MTU成功,"+JSON.stringify(e.mtu)),t.mtu=e.mtu,t.callback&&t.callback.onMTUChange&&t.currentDevice&&t.callback.onMTUChange(t.currentDevice,t.mtu),t._getBLEDeviceServices(),t._registerConnStatusListener()},fail:function(e){console.log("调节MTU失败,"+JSON.stringify(e)),t.disconnect(),t._connectFailed()}})}}):setTimeout(function(){wx.getBLEMTU({writeType:"writeNoResponse",deviceId:e.deviceId,success:function(e){console.log("iOS调节MTU成功,api的mtu"+JSON.stringify(e.mtu)),e.mtu==23?t.mtu=128:t.mtu=e.mtu,console.log("iOS调节MTU成功,最终的mtu"+JSON.stringify(e.mtu)),t.callback&&t.callback.onMTUChange&&t.currentDevice&&(console.log("iOS调节MTU成功回调"),t.callback.onMTUChange(t.currentDevice,t.mtu)),t._getBLEDeviceServices(),t._registerConnStatusListener()},fail:function(e){console.log("调节MTU失败,"+JSON.stringify(e)),t.disconnect(),t._connectFailed()}})},100)},fail:function(e){if(console.log("连接失败,"+ +JSON.stringify(e)),t.status==2){console.log("连接失败,已在onBLEConnectionStateChange处理,所以不做回调");return}else t._connectFailed()}}),!0)}},{key:"setMaxMTU",value:function e(e){this.maxMTU=e}},{key:"disconnect",value:function e(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!0;this.isConnectedOrConnecting()&&this.currentDevice&&(wx.closeBLEConnection({deviceId:this.currentDevice.deviceId}),e&&this._disconnect())}},{key:"setCallback",value:function e(e){this.callback=e}},{key:"getConnectedDevice",value:function e(){return this.isConnected()?this.currentDevice:null}},{key:"getCommunicationService",value:function e(){return this.communicationService}},{key:"getCommunication",value:function e(){return this.communication}},{key:"getCommunicationWriteCharacteristic",value:function e(){return this.communicationWriteCharacteristic}},{key:"getCommunicationReadCharacteristic",value:function e(){return this.communicationReadCharacteristic}},{key:"getMTU",value:function e(){if(this.isConnected())return this.mtu}},{key:"isConnectedOrConnecting",value:function e(){return this.isConnected()||this.isConnecting()}},{key:"isConnecting",value:function e(){return this.status==1||this.status==2}},{key:"isConnected",value:function e(){return this.status==3}},{key:"_registerConnStatusListener",value:function e(){var e=this,n=function t(t){if(console.log("蓝牙连接状态变化"+JSON.stringify(t)),e.currentDevice&&e.currentDevice.deviceId!=t.deviceId){console.log("不是同一设备"+JSON.stringify(t)),console.log("不是同一设备1"+JSON.stringify(e.currentDevice));return}if(!t.connected)if(wx.offBLEConnectionStateChange(n),e.status==3){var a=new Date;e.disconnectTime=a.getTime(),e._disconnect()}else e._connectFailed()};wx.onBLEConnectionStateChange(n)}},{key:"_getBLEDeviceServices",value:function e(){var e=this;if(this.currentDevice){var n=this.currentDevice.deviceId;console.log("获取所有服务的 uuid:"+n),setTimeout(function(){wx.getBLEDeviceServices({deviceId:n,success:function(t){console.log("获取设备服务成功:"+JSON.stringify(t.services));var a=t.services;if(a.length<=0){e._connectFailed();return}e.communicationService=e.communication.onMatchingService(a),e.communicationService?e._getBLEDeviceCharacteristics(n,e.communicationService.uuid):(console.log("未能找到对应的service uuid"),e._connectFailed())},fail:function(n){console.log("获取设备服务失败,错误码:"+n.errCode),e._connectFailed()}})},1e3)}}},{key:"_getBLEDeviceCharacteristics",value:function e(e,n){var t=this;console.log("获取某个服务下的所有特征值 deviceId="+e+" serviceId="+n),wx.getBLEDeviceCharacteristics({deviceId:e,serviceId:n,success:function(a){var i=a.characteristics;if(console.log("getBLEDeviceCharacteristics list="+JSON.stringify(i)),i.length<=0){t._connectFailed();return}var o=!1,c=t.communication.onMatchingServiceCharacteristic();i.forEach(function(a){c.write==a.uuid&&(t.communicationWriteCharacteristic=a),c.notify==a.uuid&&(t._notifyBLECharacteristicValueChange({deviceId:e,serviceId:n,characteristicId:a.uuid}),o=!0),c.read==a.uuid&&(t.communicationReadCharacteristic=a)}),o||(console.log("未能找到Notify特征值!"),t._connectFailed())},fail:function(e){console.log("获取特征值失败,错误码:"+e.errCode),t._connectFailed()}})}},{key:"_notifyBLECharacteristicValueChange",value:function e(e){var n=this;wx.notifyBLECharacteristicValueChange({state:!0,deviceId:e.deviceId,serviceId:e.serviceId,characteristicId:e.characteristicId,success:function(t){console.log("使能通知成功:"+JSON.stringify(t),e.characteristicId),n._connectSuccsed()},fail:function(e){console.log("使能通知失败"+JSON.stringify(e)),n._connectFailed()}})}},{key:"_disconnect",value:function e(){this.status=0,this.callback&&this.callback.onDisconnect&&this.currentDevice&&this.callback.onDisconnect(this.currentDevice)}},{key:"_connectFailed",value:function e(){this.status=0,this.callback&&this.callback.onFailed&&this.currentDevice&&this.callback.onFailed(this.currentDevice)}},{key:"_connectSuccsed",value:function e(){this.status=3,this.callback&&this.callback.onSuccess&&this.currentDevice&&this.callback.onSuccess(this.currentDevice)}}]);return e}();var e2=/*#__PURE__*/function(){"use strict";function e(){var n=this;i(this,e);this.services=[];this.scanList=[];this.foundDeviceMacSet=new Set;this.timeoutId=null;this.callback=null;this.scanTime=3e4;this._onBluetoothDeviceFound(),wx.onBluetoothAdapterStateChange(function(e){n._onAdapter(e),e.available?e.available&&e.discovering&&(n.scanList=[],n.foundDeviceMacSet=new Set,n._onFound(n.scanList)):(e.discovering&&n.stopScan(),n.scanList=[],n.foundDeviceMacSet=new Set)})}c(e,[{key:"setCallback",value:function e(e){this.callback=e}},{key:"setScanTime",value:function e(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:3e4;this.scanTime=e}},{key:"setServices",value:function e(e){this.services=e}},{key:"startScan",value:function e(){var e=this;this._stopTiming(),this.scanList=[],this.foundDeviceMacSet=new Set,this._getAdapterStatus({fail:function(){e._openAdapter()}})}},{key:"stopScan",value:function e(){var e=this;var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!0;this._stopTiming(),wx.stopBluetoothDevicesDiscovery({success:function(){n&&e._onStop()},fail:function(){}})}},{key:"_onBluetoothDeviceFound",value:function e(){var e=this;wx.onBluetoothDeviceFound(function(n){var t=n.devices;!t||t.length<1||(t.forEach(function(n){var t=n.deviceId;!e.foundDeviceMacSet.has(t)&&n.name&&(e.scanList.push(n),e.foundDeviceMacSet.add(t))}),e._onFound(e.scanList))})}},{key:"_openAdapter",value:function e(){var e=this;wx.openBluetoothAdapter({fail:function(n){e._onFailed(n)},success:function(){e._getAdapterStatus(null)}})}},{key:"_getAdapterStatus",value:function e(e){var n=this;wx.getBluetoothAdapterState({success:function(e){if(e.available&&e.discovering){n._startTiming(),n._onFound(n.scanList),n._onSuccess();return}n._startScan()},fail:function(t){e!=null&&e.fail?e.fail(t):n._onFailed(t)}})}},{key:"_startScan",value:function e(){var e=this;wx.startBluetoothDevicesDiscovery({allowDuplicatesKey:!0,services:this.services,interval:200,success:function(n){e._onBluetoothDeviceFound(),e._startTiming(),e._onSuccess()},fail:function(n){e._onFailed(n)}})}},{key:"_stopTiming",value:function e(){this.timeoutId!=null&&clearTimeout(this.timeoutId),this.timeoutId=null}},{key:"_startTiming",value:function e(){var e=this;this.timeoutId=setTimeout(function(){e.stopScan()},this.scanTime)}},{key:"_onAdapter",value:function e(e){this.callback&&this.callback.onAdapter&&this.callback.onAdapter(e)}},{key:"_onSuccess",value:function e(){this.callback&&this.callback.onSuccess&&this.callback.onSuccess()}},{key:"_onFailed",value:function e(e){this.callback&&this.callback.onFailed&&this.callback.onFailed(e)}},{key:"_onFound",value:function e(e){this.callback&&this.callback.onFound&&this.callback.onFound(e)}},{key:"_onStop",value:function e(){this.callback&&this.callback.onStop&&this.callback.onStop()}}]);return e}();import{dataConversion as e4}from"@onbright/common-sdk";var e3=/*#__PURE__*/function(){"use strict";function e(n){i(this,e);this.callbacks=[];this.mtuMap=new Map;this.sendInfoArray=[];this.retryNum=0;this.protocolComponent=n}c(e,[{key:"init",value:function e(){var e=this;wx.onBLECharacteristicValueChange(function(n){var t,a;console.log("收到数据 serviceId uuid:"+n.serviceId+" characteristicId: "+n.characteristicId),console.log("收到数据:"+e4.ab2hex(n.value)),(t=(a=e.protocolComponent).onProcessNotifyData)===null||t===void 0?void 0:t.call(a,n).then(function(n){e._handlerData(n)})})}},{key:"addCallbacks",value:function e(e){this.callbacks.indexOf(e)==-1&&this.callbacks.push(e)}},{key:"removeCallbacks",value:function e(e){var n=this.callbacks.indexOf(e);n!=-1&&this.callbacks.splice(n,1)}},{key:"_handlerData",value:function e(e){this._doAction({action:function n(n){n.onReceiveData&&n.onReceiveData(e)}})}},{key:"_doAction",value:function e(e){this.callbacks.forEach(function(n){e.action(n)})}},{key:"setMtu",value:function e(e,n){this.mtuMap.set(e,n)}},{key:"sendData",value:function e(e,n,t,a){var i=this;var o,c;(o=(c=this.protocolComponent).onProcessingSentData)===null||o===void 0?void 0:o.call(c,a).then(function(a){var o=i.mtuMap.get(e),c=20;o!=null&&(c=o-3),console.log("realMTU --->"+c),console.log("realData length --->"+a.byteLength);var r=a.byteLength,u=Math.floor(r/c);for(var s=0;s<u;s++){var l=new Uint8Array(c);l.set(a.slice(s*c,s*c+l.length)),i._addSendData(e,n,t,l)}if(r%c!=0){var d=new Uint8Array(r%c);d.set(a.slice(r-r%c,r)),i._addSendData(e,n,t,d)}})}},{key:"_addSendData",value:function e(e,n,t,a){var i=this;var o=new e5(e,n,t,a);if(this.sendInfoArray.push(o),this.sendInfoArray.length>1)return!0;var c={complete:function(){i._writeDataToDevice(i.sendInfoArray,c)}};return this._writeDataToDevice(this.sendInfoArray,c),!0}},{key:"_writeDataToDevice",value:function e(e,n){var t=e.shift();if(t==null){var a;if(e.length==0)return;(a=n.complete)===null||a===void 0?void 0:a.call(n);return}this._sendData(t,n)}},{key:"_sendData",value:function e(e,n){var t=this;var a,i;return console.log("开始发送数据:->"+e4.ab2hex(e.data.buffer)+" serviceId:"+e.serviceId+" characteristicId:"+e.characteristicId),console.log("this.protocolComponent.sendDataWriteType()",((a=this.protocolComponent)===null||a===void 0?void 0:a.sendDataWriteType)?(i=this.protocolComponent)===null||i===void 0?void 0:i.sendDataWriteType():""),wx.writeBLECharacteristicValue({deviceId:e.deviceId,serviceId:e.serviceId,characteristicId:e.characteristicId,value:e.data.buffer,writeType:this.protocolComponent&&this.protocolComponent.sendDataWriteType?this.protocolComponent.sendDataWriteType():"write",fail:function(a){var i;t.retryNum++,t.retryNum>=3?(console.log("发送失败,重发数据:-> err="+JSON.stringify(a)+" retryNum = "+t.retryNum),t._sendData(e,n)):(t.retryNum=0,(i=n.complete)===null||i===void 0?void 0:i.call(n)),console.log("发送数据失败:-> err="+JSON.stringify(a))},success:function(){var a;console.log("发送数据成功:->"+e4.ab2hex(e.data.buffer)+" serviceId:"+e.serviceId),t.retryNum=0,(a=n.complete)===null||a===void 0?void 0:a.call(n)}}),!0}},{key:"readData",value:function e(e,n,t){wx.readBLECharacteristicValue({deviceId:e,serviceId:n,characteristicId:t})}}]);return e}(),e5=function e(n,t,a,o){"use strict";i(this,e);this.deviceId=n,this.serviceId=t,this.characteristicId=a,this.data=o};import{dataConversion as e6}from"@onbright/common-sdk";var e8,e7=/*#__PURE__*/function(){"use strict";function e(){i(this,e);this._ConnectHandler=null;this._ScanHandler=null;this._DataHandler=null;this._Cat1LockAuthHandler=null;this._isNeedAuth=!1;this._isHasAuth=!1;this._isAutoConnectDevices=!1;e8=this,this._BluetoothCallbackManager=new e9,console.log(" 初始化BluesManager"+this._BluetoothCallbackManager),e8._ScanHandler=new e2,e8.init()}c(e,[{key:"init",value:function e(){var e;var n={onFound:e8._onScanFound,onAdapter:e8._onScanAdapter,onSuccess:e8._onScanSuccess,onFailed:e8._onScanFailed,onStop:e8._onScanStop};(e=e8._ScanHandler)===null||e===void 0?void 0:e.setCallback(n)}},{key:"setConnectHandler",value:function e(e){var n={onDisconnect:e8._onConnectStateDisconnect,onFailed:e8._onConnectStateFailed,onSuccess:e8._onConnectStateSuccess,onMTUChange:e8._onConnectStateMTUChange};e8._ConnectHandler=new e1(e),e8._ConnectHandler.setCallback(n)}},{key:"setDataHandler",value:function e(e){e8._DataHandler=new e3(e)}},{key:"setNeedAuth",value:function e(e){e8._isNeedAuth=e}},{key:"setAutoConnectDevices",value:function e(e){e8._isAutoConnectDevices=e}},{key:"setHasAuth",value:function e(e){e8._isHasAuth=e}},{key:"hasAuth",value:function e(){return e8._isHasAuth}},{key:"setCat1LockAuthHandler",value:function e(e){e8._Cat1LockAuthHandler=e}},{key:"addBluetoothEventCallback",value:function e(e){e8._BluetoothCallbackManager.resetCallbacks(e)}},{key:"removeBluetoothEventCallback",value:function e(e){e8._BluetoothCallbackManager.removeCallbacks(e)}},{key:"startDeviceScan",value:function e(){var e;var n=wx.getAppAuthorizeSetting(),t=n.locationAuthorized,a=wx.getSystemSetting(),i=a.locationEnabled,o=a.bluetoothEnabled;if(t==="authorized"&&i&&o)(e=e8._ScanHandler)===null||e===void 0?void 0:e.startScan();else{var c="";t!=="authorized"?c="请允许微信使用定位的开关":i?o||(c="请打开蓝牙的系统开关"):c="请打开地理位置的系统开关",e8._BluetoothCallbackManager.onPermissionDenied({code:1e3,describe:c})}}},{key:"stopDeviceScan",value:function e(){var e;(e=e8._ScanHandler)===null||e===void 0?void 0:e.stopScan()}},{key:"isConnected",value:function e(){return e8._ConnectHandler&&e8._ConnectHandler.isConnected()}},{key:"getConnectedDevice",value:function e(){return e8._ConnectHandler&&e8._ConnectHandler.getConnectedDevice()}},{key:"connectDevice",value:function e(e,n){var t,a,i;var o,c;return((o=(a=this._ConnectHandler)===null||a===void 0?void 0:(t=a.getCommunication())===null||t===void 0?void 0:t.onConnectDeviceBefore)!==null&&o!==void 0?o:function(){return!1})(e)?(c=(i=this._ConnectHandler)===null||i===void 0?void 0:i.connect(e,n))!==null&&c!==void 0?c:!1:!1}},{key:"disconnectDevice",value:function e(){try{e8._ConnectHandler&&e8._ConnectHandler.disconnect()}catch(e){console.error("disconnectDevice error",e)}}},{key:"setScanTime",value:function e(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:3e4;var n;(n=e8._ScanHandler)===null||n===void 0?void 0:n.setScanTime(e)}},{key:"setServices",value:function e(e){var n;(n=e8._ScanHandler)===null||n===void 0?void 0:n.setServices(e)}},{key:"sendData",value:function e(e,n){return e8._SendData(e,n)}},{key:"readData",value:function e(e){if(e8._ConnectHandler&&e8._ConnectHandler.isConnected()&&e8._DataHandler){var n=e8._ConnectHandler.getConnectedDevice();if(n&&n.deviceId==e){var t=e8._ConnectHandler.getCommunicationService();if(t){var a=e8._ConnectHandler.getCommunicationReadCharacteristic();a&&e8._DataHandler.readData(e,t.uuid,a.uuid)}}}else console.error("readData error, _DataHandler is null")}},{key:"_SendData",value:function e(e,n){try{if(e8._ConnectHandler&&e8._ConnectHandler.isConnected()&&e8._DataHandler){var t=e8._ConnectHandler.getConnectedDevice();if(t&&t.deviceId==e){var a=e8._ConnectHandler.getCommunicationService();if(a){var i=e8._ConnectHandler.getCommunicationWriteCharacteristic();if(i)return e8._DataHandler.sendData(e,a.uuid,i.uuid,n),!0}}}}catch(e){console.error("_SendData error",e)}return!1}},{key:"_onScanFound",value:function e(e){var n,t;if(e&&e.length>0&&e8._isAutoConnectDevices){var a,i,o;var c=(a=e8._ConnectHandler)===null||a===void 0?void 0:a.getCommunication().onMatchingConnectDevice(e);c&&((i=e8._ConnectHandler)===null||i===void 0?void 0:i.connect(c,!1),(o=e8._ScanHandler)===null||o===void 0?void 0:o.stopScan())}var r;var u=((r=(t=e8._ConnectHandler)===null||t===void 0?void 0:(n=t.getCommunication())===null||n===void 0?void 0:n.onMatchingScanFound)!==null&&r!==void 0?r:function(){})(e);u&&(e=u),e8._BluetoothCallbackManager.onFoundDev(e)}},{key:"_onScanAdapter",value:function e(e){e8._BluetoothCallbackManager.onAdapter(e)}},{key:"_onScanSuccess",value:function e(){e8._BluetoothCallbackManager.onScanSuccess()}},{key:"_onScanFailed",value:function e(e){e8._BluetoothCallbackManager.onScanFailed(e)}},{key:"_onScanStop",value:function e(){var e;((e=e8._ConnectHandler)===null||e===void 0?void 0:e.isConnectedOrConnecting())||e8._BluetoothCallbackManager.onScanNotFound(),e8._BluetoothCallbackManager.onScanStop()}},{key:"_onConnectStateDisconnect",value:function e(e){e8._isHasAuth=!1,e8._BluetoothCallbackManager.onDevStatusDisconnect(e)}},{key:"_onConnectStateFailed",value:function e(e){var n;e8._isHasAuth=!1,(n=e8._ScanHandler)===null||n===void 0?void 0:n.startScan(),e8._BluetoothCallbackManager.onDevStatusFailed(e)}},{key:"_onConnectStateSuccess",value:function e(e){return a(function(){var n,t,a,i,o;return f(this,function(c){if(e&&e8._DataHandler){;(n=e8._DataHandler)===null||n===void 0?void 0:n.init();a={onReceiveData:function e(e){e8._onTransmitDeviceData(e)}};if(e8._isNeedAuth&&!e8._isHasAuth&&e8._Cat1LockAuthHandler){i={onAuthSuccess:function n(){if(e8._ConnectHandler&&e8._ConnectHandler.getCommunicationService()){var n;var t=e8._ConnectHandler.getCommunicationService();e8._resetNotifyBLECharacteristicValueChange({deviceId:e.deviceId,serviceId:t?t.uuid:"",characteristicId:(n=e8._ConnectHandler)===null||n===void 0?void 0:n.getCommunication().onMatchingServiceCharacteristic().notify})}e8._BluetoothCallbackManager.onAuthSuccess(),e8._isHasAuth=!0},onAuthFailed:function e(){console.log("Cat1LockAuthCallback onAuthFailed"),e8._BluetoothCallbackManager.onAuthFailed(),e8._isHasAuth=!1}};e8._Cat1LockAuthHandler.setCallback(i);o=e6.ab2hex(e.advertisData);e8._Cat1LockAuthHandler.handleSendData(e.deviceId,o)}(t=e8._DataHandler)===null||t===void 0?void 0:t.addCallbacks(a),console.log("onDevStatusSuccess 连接成功"),e8._BluetoothCallbackManager.onDevStatusSuccess(e)}else console.error("_onConnectStateSuccess error, dev or _DataHandler is null");return[2]})})()}},{key:"_onConnectStateMTUChange",value:function e(e,n){var t;e&&e8._DataHandler?((t=e8._DataHandler)===null||t===void 0?void 0:t.setMtu(e.deviceId,n),e8._BluetoothCallbackManager.onDevStatusMTUChange(e,n)):console.error("_onConnectStateMTUChange error, dev or _DataHandler is null")}},{key:"_resetNotifyBLECharacteristicValueChange",value:function e(e){wx.notifyBLECharacteristicValueChange({state:!0,deviceId:e.deviceId,serviceId:e.serviceId,characteristicId:e.characteristicId,success:function(e){var n;console.log("重置通知成功:"+JSON.stringify(e)),(n=e8._DataHandler)===null||n===void 0?void 0:n.init()},fail:function(e){console.log("重置通知失败"+JSON.stringify(e))}})}},{key:"_onTransmitDeviceData",value:function e(e){e8._BluetoothCallbackManager.onTransmitDeviceData(e)}},{key:"resetBluetoothData",value:function e(){e8._handleCloseMonitoring(),e8.setHasAuth(!1)}},{key:"_handleCloseMonitoring",value:function e(){var e,n;(e=e8._ScanHandler)===null||e===void 0?void 0:e.stopScan(!1),wx.offBluetoothDeviceFound(),wx.offBluetoothAdapterStateChange(),wx.closeBluetoothAdapter(),wx.offBLEMTUChange(),wx.offBLEConnectionStateChange(),wx.offBLECharacteristicValueChange(),(n=e8._ConnectHandler)===null||n===void 0?void 0:n.disconnect(!1)}}]);return e}(),e9=/*#__PURE__*/function(){"use strict";function e(){i(this,e);this.callbacks=Array()}c(e,[{key:"resetCallbacks",value:function e(e){this.callbacks=[e]}},{key:"addCallbacks",value:function e(e){this.callbacks.indexOf(e)==-1&&this.callbacks.push(e)}},{key:"removeCallbacks",value:function e(e){var n=this.callbacks.indexOf(e);n!=-1&&this.callbacks.splice(n,1)}},{key:"onPermissionDenied",value:function e(e){this._doAction({action:function n(n){n.onPermissionDenied&&n.onPermissionDenied(e)}})}},{key:"onAdapter",value:function e(e){this._doAction({action:function n(n){n.onAdapter&&n.onAdapter(e)}})}},{key:"onFoundDev",value:function e(e){this._doAction({action:function n(n){n.onFoundDev&&n.onFoundDev(e)}})}},{key:"onScanSuccess",value:function e(){this._doAction({action:function e(e){e.onScanSuccess&&e.onScanSuccess()}})}},{key:"onScanFailed",value:function e(e){this._doAction({action:function n(n){n.onScanFailed&&n.onScanFailed(e)}})}},{key:"onScanStop",value:function e(){this._doAction({action:function e(e){e.onScanStop&&e.onScanStop()}})}},{key:"onScanNotFound",value:function e(){this._doAction({action:function e(e){e.onScanNotFound&&e.onScanNotFound()}})}},{key:"onDevStatusDisconnect",value:function e(e){this._doAction({action:function n(n){n.onDevStatusDisconnect&&n.onDevStatusDisconnect(e)}})}},{key:"onDevStatusFailed",value:function e(e){this._doAction({action:function n(n){n.onDevStatusFailed&&n.onDevStatusFailed(e)}})}},{key:"onDevStatusSuccess",value:function e(e){this._doAction({action:function n(n){n.onDevStatusSuccess&&n.onDevStatusSuccess(e)}})}},{key:"onDevStatusMTUChange",value:function e(e,n){this._doAction({action:function t(t){t.onDevStatusMTUChange&&t.onDevStatusMTUChange(e,n)}})}},{key:"onTransmitDeviceData",value:function e(e){this._doAction({action:function n(n){n.onTransmitDeviceData&&n.onTransmitDeviceData(e)}})}},{key:"onAuthSuccess",value:function e(){this._doAction({action:function e(e){e.onAuthSuccess&&e.onAuthSuccess()}})}},{key:"onAuthFailed",value:function e(){this._doAction({action:function e(e){e.onAuthFailed&&e.onAuthFailed()}})}},{key:"_doAction",value:function e(e){this.callbacks.forEach(function(n){e.action(n)})}}]);return e}();var ne={BluetoothManager:e7,GenerationRule:es};export{e0 as Cat1LockAuthHandler,eX as ONBRIGHT_AUTH_BLUE_NOTIFY_UUID,eZ as ONBRIGHT_AUTH_BLUE_READ_UUID,eq as ONBRIGHT_AUTH_BLUE_UUID_SERVICE,eQ as ONBRIGHT_AUTH_BLUE_WRITE_UUID,ne as default};//# sourceMappingURL=index.js.map
{
"name": "@onbright/bluetooth-sdk",
"version": "1.1.37",
"version": "1.1.38",
"scripts": {

@@ -5,0 +5,0 @@ "build": "tsup",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc