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
48
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.44 to 1.1.45

2

dist/index.d.ts

@@ -94,4 +94,4 @@ interface Communication {

sendData(deviceId: string, data: Uint8Array): boolean;
private _SendData;
readData(deviceId: string): void;
private _SendData;
private _onScanFound;

@@ -98,0 +98,0 @@ private _onScanAdapter;

@@ -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 g}from"@onbright/common-sdk";var p={};S(p,{Chinese:function(){return T},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 W},hex2Buff:function(){return z},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 G},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],k=[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 _(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 C(e){return e.map(function(e){return e=e.toString(16),e.length===1?"0"+e:e}).join("")}function x(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]^k[c+0],n[c+0]=a[0]^=A(H(r)),r=a[2]^a[3]^a[0]^k[c+1],n[c+1]=a[1]^=A(H(r)),r=a[3]^a[0]^a[1]^k[c+2],n[c+2]=a[2]^=A(H(r)),r=a[0]^a[1]^a[2]^k[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=_(u)),u.length!==128/8))throw new Error("iv is invalid");if(console.log("inArray, key",e,n),typeof n=="string"&&(n=_(n)),n.length!==128/8)throw new Error("key is invalid");if(typeof e=="string"?t!==0?e=x(e):e=_(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=[],g=u,p=e.length,m=0;for(;p>=16;){var y=e.slice(m,m+16),k=new Array(16);if(c==="cbc")for(var b=0;b<16;b++)t!==0&&(y[b]^=g[b]);w(y,k,h);for(var H=0;H<16;H++)c==="cbc"&&t===0&&(k[H]^=g[H]),S[m+H]=k[H];c==="cbc"&&(t!==0?g=k:g=y),p-=16,m+=16}return l!=="array"?C(S):S}var B={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 T(e,n){e.value=e.options[e.value],n()}function F(e,n){n()}var M=function(e,n,t){return parseInt(e,n).toString(t)},L=function(e,n){var t=M(e,n,16);return t.length<2?"0".concat(t):t};function U(e,n){e.value=M(e.value,10,2),n()}function V(e,n){e.value=L(e.value,2),n()}function N(e,n){e.value=L(e.value,10),n()}function O(e,n){var t=M(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 z(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 W(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 G(e,n){console.log("加密参数",e.value,e.key);var t=B.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=B.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 p[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=p[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}]),eg=es([{use:["ab2hex","sliceHex","getRandomNum","padStartHex"],sliceHex:-8,padStartHex:8,padStartValue:"0"},{use:[]},{use:[]},{use:[]}],{use:["padEndHex","hex2Array","setSm4Value","hex2Buff"],padEndHex:32}),ep=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"]}),ek=es([{use:["ab2hex","hex2Array","getSm4Value"]}]),e_=es([{use:["ab2hex2","hex2Array","getSm4Value"]}]),eC=es([{use:["advertisData"]}]),ex=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}),eB=es([{use:[]},{use:[]},{use:[]},{use:[]}],{use:["checkSumValue"]}),eT=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}),eM=es([{use:["ab2hex"]}]),eL=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}),ez=es([{use:[]},{use:["decimalToHex","padStartHex","HighLowConversion"],padStartHex:8,padStartValue:"0"},{use:["HighLowConversion"]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eW=es([{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eG=es([{use:[]},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eY={deviceBind:ev,deviceBindNew:ef,setSm4Auth:eg,deviceOperate:em,firmwareContent:ey,getSm4Auth:ek,getSm4AuthOperate:e_,getadvertisData:eC,getHighLow:ex,getOpenHushKey:eb,getDeviceSerialId:eH,passwordDbc:eS,getUserProperty:eD,getCycleStart:eA,getCycleEnd:ew,updateUser:eE,deleteUser:eI,getLockDataSum:eB,getLockDataSm4:eT,createKeySm4:eF,getNoSm4Data:eM,setBuletVolume:eU,setBuleStay:eV,setBuleClose:eN,deleteKeySm4:eO,voiceMessageSm4:eP,voicePgVsSm4:eR,issuceVoicePgSm4:eJ,issuceAnySm4:ej,getNoSm4Butter:eL,setSm4AuthCon:ep,syncKeyList:eh,getLogSm4Data:eK,firmwareUpReady:ez,getLockState:eW,setBuleLocked:eG},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("Cat1LockAuthHandler 发送数据成功:->"+g.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("收到数据:"+g.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}();function e1(e){if(e){var n={tipMsg:"",errCode:e.errCode,errMsg:e.errMsg},t=n.tipMsg;switch(e.errCode){case 0:t="蓝牙正常使用";break;case-1:t="蓝牙已连接";break;case 1e4:t="未初始化蓝牙适配器";break;case 10001:t="当前蓝牙适配器不可用";break;case 10002:t="没有找到指定设备";break;case 10003:t="蓝牙连接失败";break;case 10004:t="蓝牙没有找到指定服务";break;case 10005:t="蓝牙没有找到指定特征";break;case 10006:t="当前蓝牙连接已断开";break;case 10007:t="当前蓝牙特征不支持此操作";break;case 10008:t="其余所有系统上报的异常";break;case 10009:t="Android 系统特有,系统版本低于 4.3 不支持 BLE";break;case 10012:t="当前蓝牙连接超时";break;case 10013:t="连接 deviceId 为空或者是格式不正确";break;default:t="蓝牙功能暂不支持";break}return n.tipMsg=t,n}else return{errCode:-1e3,errMsg:"error",tipMsg:"蓝牙功能暂不支持"}}var e2=/*#__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(e1(e))}})}}):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(e1(e))}})},100)},fail:function(e){if(console.log("连接失败,"+ +JSON.stringify(e)),t.status==2){console.log("连接失败,已在onBLEConnectionStateChange处理,所以不做回调");return}else t._connectFailed(e1(e))}}),!0)}},{key:"setMaxMTU",value:function e(e){this.maxMTU=e}},{key:"changeCharacteristics",value:function e(){return console.log("changeCharacteristics 重置蓝牙监听"),wx.offBLECharacteristicValueChange(),this._getBLEDeviceServices(),new Promise(function(e){setTimeout(function(){e()},1500)})}},{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,success:function(){console.log("蓝牙关闭成功")},fail:function(e){console.log("蓝牙关闭失败"+JSON.stringify(e1(e)))}}),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:"setCommunication",value:function e(e){var n=this;return a(function(){return f(this,function(t){switch(t.label){case 0:n.communication=e;return[4,n.changeCharacteristics()];case 1:t.sent();return[2]}})})()}},{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(console.log("_getBLEDeviceServices",this.currentDevice),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(e1(n))}})},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(e1(e))}})}},{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(e1(e))}})}},{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(e){this.status=0,this.callback&&this.callback.onFailed&&this.currentDevice&&this.callback.onFailed(this.currentDevice,e)}},{key:"_connectSuccsed",value:function e(){this.status=3,this.callback&&this.callback.onSuccess&&this.currentDevice&&this.callback.onSuccess(this.currentDevice)}}]);return e}();var e4=/*#__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(n){e._onFailed(e1(n))}})}},{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(e1(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(e1(t)):n._onFailed(e1(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(e1(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 e3}from"@onbright/common-sdk";var e5=/*#__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("收到数据:"+e3.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 e6(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;return console.log("开始发送数据:->"+e3.ab2hex(e.data.buffer)+" serviceId:"+e.serviceId+" characteristicId:"+e.characteristicId),wx.writeBLECharacteristicValue({deviceId:e.deviceId,serviceId:e.serviceId,characteristicId:e.characteristicId,value:e.data.buffer,writeType:this.protocolComponent&&this.protocolComponent.sendDataWriteType&&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)),t.protocolComponent.onProcessSentFailed&&t.protocolComponent.onProcessSentFailed(e1(a))},success:function(){var a;console.log("发送数据成功:->"+e3.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){var a=this;wx.readBLECharacteristicValue({deviceId:e,serviceId:n,characteristicId:t,success:function(e){console.log("读取数据成功")},fail:function(e){console.log("读取数据失败"),a.protocolComponent.onProcessReadFailed&&a.protocolComponent.onProcessReadFailed(e)}})}}]);return e}(),e6=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 e8,permisson as e7}from"@onbright/common-sdk";var e9,ne=/*#__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;e9=this,this._BluetoothCallbackManager=new nn,console.log(" 初始化BluesManager"+this._BluetoothCallbackManager),e9._ScanHandler=new e4,e9.init()}c(e,[{key:"init",value:function e(){var e;var n={onFound:e9._onScanFound,onAdapter:e9._onScanAdapter,onSuccess:e9._onScanSuccess,onFailed:e9._onScanFailed,onStop:e9._onScanStop};(e=e9._ScanHandler)===null||e===void 0?void 0:e.setCallback(n)}},{key:"setConnectHandler",value:function e(e){var n={onDisconnect:e9._onConnectStateDisconnect,onFailed:e9._onConnectStateFailed,onSuccess:e9._onConnectStateSuccess,onMTUChange:e9._onConnectStateMTUChange};e9._ConnectHandler=new e2(e),e9._ConnectHandler.setCallback(n)}},{key:"changeCommunicationCharacteristics",value:function e(e){return a(function(){var n;return f(this,function(t){switch(t.label){case 0:return[4,(n=e9._ConnectHandler)===null||n===void 0?void 0:n.setCommunication(e)];case 1:t.sent();return[2]}})})()}},{key:"setDataHandler",value:function e(e){e9._DataHandler=new e5(e)}},{key:"setNeedAuth",value:function e(e){e9._isNeedAuth=e}},{key:"setAutoConnectDevices",value:function e(e){e9._isAutoConnectDevices=e}},{key:"setHasAuth",value:function e(e){e9._isHasAuth=e}},{key:"hasAuth",value:function e(){return e9._isHasAuth}},{key:"setCat1LockAuthHandler",value:function e(e){e9._Cat1LockAuthHandler=e}},{key:"addBluetoothEventCallback",value:function e(e){e9._BluetoothCallbackManager.resetCallbacks(e)}},{key:"removeBluetoothEventCallback",value:function e(e){e9._BluetoothCallbackManager.removeCallbacks(e)}},{key:"startDeviceScan",value:function e(){var e;var n=wx.getAppAuthorizeSetting(),t=n.locationAuthorized,a=n.bluetoothAuthorized,i=wx.getSystemSetting(),o=i.locationEnabled,c=i.bluetoothEnabled;if(t==="authorized"&&a==="authorized"&&o&&c)(e=e9._ScanHandler)===null||e===void 0?void 0:e.startScan();else{var r="",u=0;t!=="authorized"?(r="请允许微信使用定位的开关",u=1e3):o?c?a!=="authorized"&&(r="请允许微信使用蓝牙的开关",u=1003):(r="请打开蓝牙的系统开关",u=1002):(r="请打开地理位置的系统开关",u=1001),(t!=="authorized"||!o)&&e7.checkLocationPermissions(!1).then(function(e){}).catch(function(){e9._BluetoothCallbackManager.onPermissionDenied({code:u,describe:r})}),(a!=="authorized"||!c)&&e7.checkBluetoothPermissions(!1).then(function(e){}).catch(function(){e9._BluetoothCallbackManager.onPermissionDenied({code:u,describe:r})})}}},{key:"stopDeviceScan",value:function e(){var e;(e=e9._ScanHandler)===null||e===void 0?void 0:e.stopScan()}},{key:"isConnected",value:function e(){return e9._ConnectHandler&&e9._ConnectHandler.isConnected()}},{key:"getConnectedDevice",value:function e(){return e9._ConnectHandler&&e9._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{e9._ConnectHandler&&(e9._ConnectHandler.disconnect(),e9.setHasAuth(!1))}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=e9._ScanHandler)===null||n===void 0?void 0:n.setScanTime(e)}},{key:"setServices",value:function e(e){var n;(n=e9._ScanHandler)===null||n===void 0?void 0:n.setServices(e)}},{key:"sendData",value:function e(e,n){return e9._SendData(e,n)}},{key:"readData",value:function e(e){if(e9._ConnectHandler&&e9._ConnectHandler.isConnected()&&e9._DataHandler){var n=e9._ConnectHandler.getConnectedDevice();if(n&&n.deviceId==e){var t=e9._ConnectHandler.getCommunicationService();if(t){var a=e9._ConnectHandler.getCommunicationReadCharacteristic();a&&e9._DataHandler.readData(e,t.uuid,a.uuid)}}}else console.error("readData error, _DataHandler is null")}},{key:"_SendData",value:function e(e,n){try{if(e9._ConnectHandler&&e9._ConnectHandler.isConnected()&&e9._DataHandler){var t=e9._ConnectHandler.getConnectedDevice();if(console.log("connectedDevice",t,t===null||t===void 0?void 0:t.deviceId),t&&t.deviceId==e){var a=e9._ConnectHandler.getCommunicationService();if(a){var i=e9._ConnectHandler.getCommunicationWriteCharacteristic();if(i)return console.log("_SendData",e,a.uuid,i.uuid,n),e9._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&&e9._isAutoConnectDevices){var a,i,o;var c=(a=e9._ConnectHandler)===null||a===void 0?void 0:a.getCommunication().onMatchingConnectDevice(e);c&&((i=e9._ConnectHandler)===null||i===void 0?void 0:i.connect(c,!1),(o=e9._ScanHandler)===null||o===void 0?void 0:o.stopScan())}var r;var u=((r=(t=e9._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),e9._BluetoothCallbackManager.onFoundDev(e)}},{key:"_onScanAdapter",value:function e(e){e9._BluetoothCallbackManager.onAdapter(e)}},{key:"_onScanSuccess",value:function e(){e9._BluetoothCallbackManager.onScanSuccess()}},{key:"_onScanFailed",value:function e(e){e9._BluetoothCallbackManager.onScanFailed(e)}},{key:"_onScanStop",value:function e(){var e;((e=e9._ConnectHandler)===null||e===void 0?void 0:e.isConnectedOrConnecting())||e9._BluetoothCallbackManager.onScanNotFound(),e9._BluetoothCallbackManager.onScanStop()}},{key:"_onConnectStateDisconnect",value:function e(e){e9._isHasAuth=!1,e9._BluetoothCallbackManager.onDevStatusDisconnect(e)}},{key:"_onConnectStateFailed",value:function e(e){var n;e9._isHasAuth=!1,(n=e9._ScanHandler)===null||n===void 0?void 0:n.startScan(),e9._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&&e9._DataHandler){;(n=e9._DataHandler)===null||n===void 0?void 0:n.init();a={onReceiveData:function e(e){e9._onTransmitDeviceData(e)}};if(e9._isNeedAuth&&!e9._isHasAuth&&e9._Cat1LockAuthHandler){i={onAuthSuccess:function n(){if(e9._ConnectHandler&&e9._ConnectHandler.getCommunicationService()){var n;var t=e9._ConnectHandler.getCommunicationService();e9._resetNotifyBLECharacteristicValueChange({deviceId:e.deviceId,serviceId:t?t.uuid:"",characteristicId:(n=e9._ConnectHandler)===null||n===void 0?void 0:n.getCommunication().onMatchingServiceCharacteristic().notify})}e9._BluetoothCallbackManager.onAuthSuccess(),e9._isHasAuth=!0},onAuthFailed:function e(){console.log("Cat1LockAuthCallback onAuthFailed"),e9._BluetoothCallbackManager.onAuthFailed(),e9._isHasAuth=!1}};e9._Cat1LockAuthHandler.setCallback(i);o=e8.ab2hex(e.advertisData);e9._Cat1LockAuthHandler.handleSendData(e.deviceId,o)}(t=e9._DataHandler)===null||t===void 0?void 0:t.addCallbacks(a),console.log("onDevStatusSuccess 连接成功"),e9._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&&e9._DataHandler?((t=e9._DataHandler)===null||t===void 0?void 0:t.setMtu(e.deviceId,n),e9._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=e9._DataHandler)===null||n===void 0?void 0:n.init()},fail:function(e){console.log("重置通知失败"+JSON.stringify(e))}})}},{key:"_onTransmitDeviceData",value:function e(e){e9._BluetoothCallbackManager.onTransmitDeviceData(e)}},{key:"resetBluetoothData",value:function e(){e9._handleCloseMonitoring(),e9.setHasAuth(!1)}},{key:"_handleCloseMonitoring",value:function e(){var e,n;(e=e9._ScanHandler)===null||e===void 0?void 0:e.stopScan(!1),wx.offBluetoothDeviceFound(),wx.offBluetoothAdapterStateChange(),wx.closeBluetoothAdapter(),wx.offBLEMTUChange(),wx.offBLEConnectionStateChange(),wx.offBLECharacteristicValueChange(),(n=e9._ConnectHandler)===null||n===void 0?void 0:n.disconnect(!1)}}]);return e}(),nn=/*#__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 nt={BluetoothManager:ne,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,nt 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,c,o){try{var r=e[c](o);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,c){var o=e.apply(n,a);function r(e){t(o,i,c,r,u,"next",e)}function u(e){t(o,i,c,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 c(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 o(e,n,t){if(n)c(e.prototype,n);if(t)c(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,c,o={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]};return c={next:r(0),"throw":r(1),"return":r(2)},typeof Symbol==="function"&&(c[Symbol.iterator]=function(){return this}),c;function r(e){return function(n){return u([e,n])}}function u(c){if(t)throw new TypeError("Generator is already executing.");while(o)try{if(t=1,a&&(i=c[0]&2?a["return"]:c[0]?a["throw"]||((i=a["return"])&&i.call(a),0):a.next)&&!(i=i.call(a,c[1])).done)return i;if(a=0,i)c=[c[0]&2,i.value];switch(c[0]){case 0:case 1:i=c;break;case 4:o.label++;return{value:c[1],done:false};case 5:o.label++;a=c[1];c=[0];continue;case 7:c=o.ops.pop();o.trys.pop();continue;default:if(!(i=o.trys,i=i.length>0&&i[i.length-1])&&(c[0]===6||c[0]===2)){o=0;continue}if(c[0]===3&&(!i||c[1]>i[0]&&c[1]<i[3])){o.label=c[1];break}if(c[0]===6&&o.label<i[1]){o.label=i[1];i=c;break}if(i&&o.label<i[2]){o.label=i[2];o.ops.push(c);break}if(i[2])o.ops.pop();o.trys.pop();continue}c=n.call(e,o)}catch(e){c=[6,e];a=0}finally{t=i=0}if(c[0]&5)throw c[1];return{value:c[0]?c[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 g}from"@onbright/common-sdk";var m={};S(m,{Chinese:function(){return B},Dispense:function(){return M},HighLowConversion:function(){return eu},ab2hex:function(){return J},ab2hex2:function(){return j},abToA:function(){return R},advertisData:function(){return ec},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 F},decimalToHex:function(){return O},getRandomNum:function(){return K},getSm4Value:function(){return Y},hex2Array:function(){return W},hex2Buff:function(){return z},hexReverse:function(){return eo},hexToDecimal:function(){return N},highLowBitCV:function(){return en},openKeyEctopicOr:function(){return et},padEndHex:function(){return q},padStartHex:function(){return Q},passTo8DBC:function(){return P},setSm4Value:function(){return G},setbit:function(){return Z},sliceHex:function(){return $}});import p 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],k=[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 _(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 C(e){return e.map(function(e){return e=e.toString(16),e.length===1?"0"+e:e}).join("")}function x(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 D(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 H(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 c=0;c<4;c++)i[0]=e[4*c]&255,i[1]=e[4*c+1]&255,i[2]=e[4*c+2]&255,i[3]=e[4*c+3]&255,a[c]=i[0]<<24|i[1]<<16|i[2]<<8|i[3];for(var o=0,r;o<32;o+=4)r=a[1]^a[2]^a[3]^t[o+0],a[0]^=H(D(r)),r=a[2]^a[3]^a[0]^t[o+1],a[1]^=H(D(r)),r=a[3]^a[0]^a[1]^t[o+2],a[2]^=H(D(r)),r=a[0]^a[1]^a[2]^t[o+3],a[3]^=H(D(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 c=0;c<4;c++)i[0]=e[0+4*c]&255,i[1]=e[1+4*c]&255,i[2]=e[2+4*c]&255,i[3]=e[3+4*c]&255,a[c]=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 o=0,r;o<32;o+=4)r=a[1]^a[2]^a[3]^k[o+0],n[o+0]=a[0]^=A(D(r)),r=a[2]^a[3]^a[0]^k[o+1],n[o+1]=a[1]^=A(D(r)),r=a[3]^a[0]^a[1]^k[o+2],n[o+2]=a[2]^=A(D(r)),r=a[0]^a[1]^a[2]^k[o+3],n[o+3]=a[3]^=A(D(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 T(e,n,t){var a=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{},i=a.padding,c=i===void 0?"pkcs#7":i,o=a.mode,r=a.iv,u=r===void 0?[]:r,s=a.output,l=s===void 0?"string":s;if(o==="cbc"&&(typeof u=="string"&&(u=_(u)),u.length!==128/8))throw new Error("iv is invalid");if(console.log("inArray, key",e,n),typeof n=="string"&&(n=_(n)),n.length!==128/8)throw new Error("key is invalid");if(typeof e=="string"?t!==0?e=x(e):e=_(e):e=d(e),(c==="pkcs#5"||c==="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=[],g=u,m=e.length,p=0;for(;m>=16;){var y=e.slice(p,p+16),k=new Array(16);if(o==="cbc")for(var b=0;b<16;b++)t!==0&&(y[b]^=g[b]);w(y,k,h);for(var D=0;D<16;D++)o==="cbc"&&t===0&&(k[D]^=g[D]),S[p+D]=k[D];o==="cbc"&&(t!==0?g=k:g=y),m-=16,p+=16}return l!=="array"?C(S):S}var I={encrypt:function e(e,n,t){return T(e,n,1,t)},decrypt:function e(e,n,t){return T(e,n,0,t)}};function B(e,n){e.value=e.options[e.value],n()}function M(e,n){n()}var U=function(e,n,t){return parseInt(e,n).toString(t)},L=function(e,n){var t=U(e,n,16);return t.length<2?"0".concat(t):t};function F(e,n){e.value=U(e.value,10,2),n()}function V(e,n){e.value=L(e.value,2),n()}function O(e,n){e.value=L(e.value,10),n()}function N(e,n){var t=U(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 z(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 W(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 G(e,n){console.log("加密参数",e.value,e.key);var t=I.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=I.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),p.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 c=t[i]+""+t[i+1];a.push(c)}var o=0;a.forEach(function(e){o+=parseInt(e,16)}),e.value=o.toString(16).padStart(4,"0").slice(-4),n()}function ec(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 eo(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 c=a(function(a){var c,o,r,u,s,d,v;var h=arguments;return f(this,function(f){switch(f.label){case 0:c=h.length>1&&h[1]!==void 0?h[1]:{};o=function(n,t){return e.map(function(e,n){return e.value=t[n],e=l({},e,c),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,c),i(n,function(e,n){n(),t(e.value)})})};f.label=1;case 1:f.trys.push([1,4,,5]);return[4,o(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 c.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](),c;!(n=(c=i.next()).done);n=true){var o=c.value;if(typeof m[o]!="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(c){if(c<=a)return Promise.reject(new Error("next() called multiple times"));a=c;var o=m[e[c]]||(c===e.length?t:null);if(!o)return Promise.resolve();try{return Promise.resolve(o(n,i.bind(null,c+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}]),eg=es([{use:["ab2hex","sliceHex","getRandomNum","padStartHex"],sliceHex:-8,padStartHex:8,padStartValue:"0"},{use:[]},{use:[]},{use:[]}],{use:["padEndHex","hex2Array","setSm4Value","hex2Buff"],padEndHex:32}),em=es([{use:["ab2hex","sliceHex","getRandomNum","padStartHex"],sliceHex:-8,padStartHex:0,padStartValue:"0"},{use:[]},{use:[]},{use:[]}],{use:["padEndHex","hex2Array","setSm4Value","hex2Buff"],padEndHex:32}),ep=es([{use:[]},{use:[]}],{use:["hex2Buff"]}),ey=es([{use:["decimalToHex","padStartHex","HighLowConversion"],padStartHex:6,padStartValue:"0"},{use:[]}],{use:["hex2Buff"]}),ek=es([{use:["ab2hex","hex2Array","getSm4Value"]}]),e_=es([{use:["ab2hex2","hex2Array","getSm4Value"]}]),eC=es([{use:["advertisData"]}]),ex=es([{use:["highLowBitCV"]}]),eb=es([{use:[]},{use:[]},{use:[]}],{use:["padEndHex","hex2Array","setSm4Value","openKeyEctopicOr"],padEndHex:32}),eD=es([{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eH=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}),eT=es([{use:[]},{use:["padStartHex"],padStartHex:4,padStartValue:"0"},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eI=es([{use:[]},{use:[]},{use:[]},{use:[]}],{use:["checkSumValue"]}),eB=es([{use:["HighLowConversion"]},{use:[]},{use:["HighLowConversion"]},{use:[]},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eM=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}),eU=es([{use:["ab2hex"]}]),eL=es([{use:["ab2hex","hexToDecimal"]},{use:[]}]),eF=es([{use:[]},{use:[]},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eV=es([{use:[]},{use:[]},{use:[]},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eO=es([{use:[]},{use:[]},{use:[]},{use:[]},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eN=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}),ez=es([{use:[]},{use:["decimalToHex","padStartHex","HighLowConversion"],padStartHex:8,padStartValue:"0"},{use:["HighLowConversion"]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eW=es([{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eG=es([{use:[]},{use:[]}],{use:["padEndHex","checkSum","hex2Array","setSm4Value"],padEndHex:32}),eY={deviceBind:ev,deviceBindNew:ef,setSm4Auth:eg,deviceOperate:ep,firmwareContent:ey,getSm4Auth:ek,getSm4AuthOperate:e_,getadvertisData:eC,getHighLow:ex,getOpenHushKey:eb,getDeviceSerialId:eD,passwordDbc:eS,getUserProperty:eH,getCycleStart:eA,getCycleEnd:ew,updateUser:eE,deleteUser:eT,getLockDataSum:eI,getLockDataSm4:eB,createKeySm4:eM,getNoSm4Data:eU,setBuletVolume:eF,setBuleStay:eV,setBuleClose:eO,deleteKeySm4:eN,voiceMessageSm4:eP,voicePgVsSm4:eR,issuceVoicePgSm4:eJ,issuceAnySm4:ej,getNoSm4Butter:eL,setSm4AuthCon:em,syncKeyList:eh,getLogSm4Data:eK,firmwareUpReady:ez,getLockState:eW,setBuleLocked:eG},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}o(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(c){switch(c.label){case 0:t.hexStr=n;return[4,t.onProcessingSentData()];case 1:i=c.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("Cat1LockAuthHandler 发送数据成功:->"+g.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,c,o,r,u,s;return f(this,function(l){switch(l.label){case 0:console.log("收到数据 serviceId uuid:"+e.serviceId+" characteristicId: "+e.characteristicId),console.log("收到数据:"+g.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(),c=i.slice(0,2),o=i.slice(2,6);console.log("notifyValue",i,"grade",c,"userId",o),c===t.grade&&o===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,c;return f(this,function(t){switch(t.label){case 0:a=e$.setSm4Auth;i=[[e.advertisData,e.grade,e.userId,e.timeUnix]];c={};return[4,e._getKey()];case 1:return[4,a.apply(e$,i.concat([(c.key=t.sent(),c.padEndValue="0",c)]))];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,c,o,r;return f(this,function(t){switch(t.label){case 0:a="4F42424C45",i=e.hexStr.slice(2,14),c=e.hexStr.slice(-8),o=a+i+c;return[4,e._getSum(o)];case 1:r=t.sent();console.log("getSum",r),console.log("mac",i,"random",c,"numStr",r,"sm4Key",a+i+c+r),n(a+i+c+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}();function e1(e){if(e){var n={tipMsg:"",errCode:e.errCode,errMsg:e.errMsg},t=n.tipMsg;switch(e.errCode){case 0:t="蓝牙正常使用";break;case-1:t="蓝牙已连接";break;case 1e4:t="未初始化蓝牙适配器";break;case 10001:t="当前蓝牙适配器不可用";break;case 10002:t="没有找到指定设备";break;case 10003:t="蓝牙连接失败";break;case 10004:t="蓝牙没有找到指定服务";break;case 10005:t="蓝牙没有找到指定特征";break;case 10006:t="当前蓝牙连接已断开";break;case 10007:t="当前蓝牙特征不支持此操作";break;case 10008:t="其余所有系统上报的异常";break;case 10009:t="Android 系统特有,系统版本低于 4.3 不支持 BLE";break;case 10012:t="当前蓝牙连接超时";break;case 10013:t="连接 deviceId 为空或者是格式不正确";break;default:t="蓝牙功能暂不支持";break}return n.tipMsg=t,n}else return{errCode:-1e3,errMsg:"error",tipMsg:"蓝牙功能暂不支持"}}var e2=/*#__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}o(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(e1(e))}})}}):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(e1(e))}})},100)},fail:function(e){if(console.log("连接失败,"+ +JSON.stringify(e)),t.status==2){console.log("连接失败,已在onBLEConnectionStateChange处理,所以不做回调");return}else t._connectFailed(e1(e))}}),!0)}},{key:"setMaxMTU",value:function e(e){this.maxMTU=e}},{key:"changeCharacteristics",value:function e(){var e=this;console.log("changeCharacteristics 重置蓝牙监听"),wx.offBLECharacteristicValueChange(),this._getBLEDeviceServices();var n=wx.getDeviceInfo(),t=this;if(t.currentDevice){var a=t.currentDevice.deviceId;n.platform=="android"?wx.setBLEMTU({deviceId:a,mtu:t.maxMTU,success:function(n){console.log("调节MTU成功,"+n.mtu),e.mtu=n.mtu,e.callback&&e.callback.onMTUChange&&e.currentDevice&&e.callback.onMTUChange(e.currentDevice,e.mtu)},fail:function(n){console.log("调节失败,直接获取MTU,"+JSON.stringify(n)),wx.getBLEMTU({deviceId:a,success:function(n){console.log("调节MTU成功,"+JSON.stringify(n.mtu)),e.mtu=n.mtu,e.callback&&e.callback.onMTUChange&&e.currentDevice&&e.callback.onMTUChange(e.currentDevice,e.mtu)},fail:function(e){console.log("调节MTU失败,"+JSON.stringify(e))}})}}):setTimeout(function(){wx.getBLEMTU({writeType:"writeNoResponse",deviceId:a,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))},fail:function(e){console.log("调节MTU失败,"+JSON.stringify(e))}})},100)}else console.log("currentDevice is null");return new Promise(function(e){setTimeout(function(){e()},1500)})}},{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,success:function(){console.log("蓝牙关闭成功")},fail:function(e){console.log("蓝牙关闭失败"+JSON.stringify(e1(e)))}}),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:"setCommunication",value:function e(e){var n=this;return a(function(){return f(this,function(t){switch(t.label){case 0:n.communication=e;return[4,n.changeCharacteristics()];case 1:t.sent();return[2]}})})()}},{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(console.log("_getBLEDeviceServices",this.currentDevice),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(e1(n))}})},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 c=!1,o=t.communication.onMatchingServiceCharacteristic();i.forEach(function(a){o.write==a.uuid&&(t.communicationWriteCharacteristic=a),o.notify==a.uuid&&(t._notifyBLECharacteristicValueChange({deviceId:e,serviceId:n,characteristicId:a.uuid}),c=!0),o.read==a.uuid&&(t.communicationReadCharacteristic=a)}),c||(console.log("未能找到Notify特征值!"),t._connectFailed())},fail:function(e){console.log("获取特征值失败,错误码:"+e.errCode),t._connectFailed(e1(e))}})}},{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(e1(e))}})}},{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(e){this.status=0,this.callback&&this.callback.onFailed&&this.currentDevice&&this.callback.onFailed(this.currentDevice,e)}},{key:"_connectSuccsed",value:function e(){this.status=3,this.callback&&this.callback.onSuccess&&this.currentDevice&&this.callback.onSuccess(this.currentDevice)}}]);return e}();var e4=/*#__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)})}o(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(n){e._onFailed(e1(n))}})}},{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(e1(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(e1(t)):n._onFailed(e1(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(e1(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 e3}from"@onbright/common-sdk";var e5=/*#__PURE__*/function(){"use strict";function e(n){i(this,e);this.callbacks=[];this.mtuMap=new Map;this.sendInfoArray=[];this.retryNum=0;this.protocolComponent=n}o(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("收到数据:"+e3.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 c,o;console.log("sendData:",e,n,t,a),(c=(o=this.protocolComponent).onProcessingSentData)===null||c===void 0?void 0:c.call(o,a).then(function(a){var c=i.mtuMap.get(e),o=20;c!=null&&(o=c-3),console.log("realMTU --->"+o),console.log("realData length --->"+a.byteLength);var r=a.byteLength,u=Math.floor(r/o);for(var s=0;s<u;s++){var l=new Uint8Array(o);l.set(a.slice(s*o,s*o+l.length)),i._addSendData(e,n,t,l)}if(r%o!=0){var d=new Uint8Array(r%o);d.set(a.slice(r-r%o,r)),i._addSendData(e,n,t,d)}})}},{key:"_addSendData",value:function e(e,n,t,a){var i=this;var c=new e6(e,n,t,a);if(this.sendInfoArray.push(c),this.sendInfoArray.length>1)return!0;var o={complete:function(){i._writeDataToDevice(i.sendInfoArray,o)}};return this._writeDataToDevice(this.sendInfoArray,o),!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;return console.log("开始发送数据:->"+e3.ab2hex(e.data.buffer)+" serviceId:"+e.serviceId+" characteristicId:"+e.characteristicId),wx.writeBLECharacteristicValue({deviceId:e.deviceId,serviceId:e.serviceId,characteristicId:e.characteristicId,value:e.data.buffer,writeType:this.protocolComponent&&this.protocolComponent.sendDataWriteType&&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)),t.protocolComponent.onProcessSentFailed&&t.protocolComponent.onProcessSentFailed(e1(a))},success:function(){var a;console.log("发送数据成功:->"+e3.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){var a=this;wx.readBLECharacteristicValue({deviceId:e,serviceId:n,characteristicId:t,success:function(e){console.log("读取数据成功",e)},fail:function(e){console.log("读取数据失败"),a.protocolComponent.onProcessReadFailed&&a.protocolComponent.onProcessReadFailed(e)}})}}]);return e}(),e6=function e(n,t,a,c){"use strict";i(this,e);this.deviceId=n,this.serviceId=t,this.characteristicId=a,this.data=c};import{dataConversion as e8,permisson as e7}from"@onbright/common-sdk";var e9,ne=/*#__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;e9=this,this._BluetoothCallbackManager=new nn,console.log(" 初始化BluesManager"+this._BluetoothCallbackManager),e9._ScanHandler=new e4,e9.init()}o(e,[{key:"init",value:function e(){var e;var n={onFound:e9._onScanFound,onAdapter:e9._onScanAdapter,onSuccess:e9._onScanSuccess,onFailed:e9._onScanFailed,onStop:e9._onScanStop};(e=e9._ScanHandler)===null||e===void 0?void 0:e.setCallback(n)}},{key:"setConnectHandler",value:function e(e){var n={onDisconnect:e9._onConnectStateDisconnect,onFailed:e9._onConnectStateFailed,onSuccess:e9._onConnectStateSuccess,onMTUChange:e9._onConnectStateMTUChange};e9._ConnectHandler=new e2(e),e9._ConnectHandler.setCallback(n)}},{key:"changeCommunicationCharacteristics",value:function e(e){return a(function(){var n;return f(this,function(t){switch(t.label){case 0:return[4,(n=e9._ConnectHandler)===null||n===void 0?void 0:n.setCommunication(e)];case 1:t.sent();return[2]}})})()}},{key:"setDataHandler",value:function e(e){e9._DataHandler=new e5(e)}},{key:"setNeedAuth",value:function e(e){e9._isNeedAuth=e}},{key:"setAutoConnectDevices",value:function e(e){e9._isAutoConnectDevices=e}},{key:"setHasAuth",value:function e(e){e9._isHasAuth=e}},{key:"hasAuth",value:function e(){return e9._isHasAuth}},{key:"setCat1LockAuthHandler",value:function e(e){e9._Cat1LockAuthHandler=e}},{key:"addBluetoothEventCallback",value:function e(e){e9._BluetoothCallbackManager.resetCallbacks(e)}},{key:"removeBluetoothEventCallback",value:function e(e){e9._BluetoothCallbackManager.removeCallbacks(e)}},{key:"startDeviceScan",value:function e(){var e;var n=wx.getAppAuthorizeSetting(),t=n.locationAuthorized,a=n.bluetoothAuthorized,i=wx.getSystemSetting(),c=i.locationEnabled,o=i.bluetoothEnabled;if(t==="authorized"&&a==="authorized"&&c&&o)(e=e9._ScanHandler)===null||e===void 0?void 0:e.startScan();else{var r="",u=0;t!=="authorized"?(r="请允许微信使用定位的开关",u=1e3):c?o?a!=="authorized"&&(r="请允许微信使用蓝牙的开关",u=1003):(r="请打开蓝牙的系统开关",u=1002):(r="请打开地理位置的系统开关",u=1001),(t!=="authorized"||!c)&&e7.checkLocationPermissions(!1).then(function(e){}).catch(function(){e9._BluetoothCallbackManager.onPermissionDenied({code:u,describe:r})}),(a!=="authorized"||!o)&&e7.checkBluetoothPermissions(!1).then(function(e){}).catch(function(){e9._BluetoothCallbackManager.onPermissionDenied({code:u,describe:r})})}}},{key:"stopDeviceScan",value:function e(){var e;(e=e9._ScanHandler)===null||e===void 0?void 0:e.stopScan()}},{key:"isConnected",value:function e(){return e9._ConnectHandler&&e9._ConnectHandler.isConnected()}},{key:"getConnectedDevice",value:function e(){return e9._ConnectHandler&&e9._ConnectHandler.getConnectedDevice()}},{key:"connectDevice",value:function e(e,n){var t,a,i;var c,o;return((c=(a=this._ConnectHandler)===null||a===void 0?void 0:(t=a.getCommunication())===null||t===void 0?void 0:t.onConnectDeviceBefore)!==null&&c!==void 0?c:function(){return!1})(e)?(o=(i=this._ConnectHandler)===null||i===void 0?void 0:i.connect(e,n))!==null&&o!==void 0?o:!1:!1}},{key:"disconnectDevice",value:function e(){try{e9._ConnectHandler&&(e9._ConnectHandler.disconnect(),e9.setHasAuth(!1))}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=e9._ScanHandler)===null||n===void 0?void 0:n.setScanTime(e)}},{key:"setServices",value:function e(e){var n;(n=e9._ScanHandler)===null||n===void 0?void 0:n.setServices(e)}},{key:"sendData",value:function e(e,n){return e9._SendData(e,n)}},{key:"_SendData",value:function e(e,n){try{if(e9._ConnectHandler&&e9._ConnectHandler.isConnected()&&e9._DataHandler){var t=e9._ConnectHandler.getConnectedDevice();if(console.log("connectedDevice",t,t===null||t===void 0?void 0:t.deviceId),t&&t.deviceId==e){var a=e9._ConnectHandler.getCommunicationService();if(a){var i=e9._ConnectHandler.getCommunicationWriteCharacteristic();if(i)return console.log("_SendData",e,a.uuid,i.uuid,n),e9._DataHandler.sendData(e,a.uuid,i.uuid,n),!0}}}}catch(e){console.error("_SendData error",e)}return!1}},{key:"readData",value:function e(e){if(e9._ConnectHandler&&e9._ConnectHandler.isConnected()&&e9._DataHandler){var n=e9._ConnectHandler.getConnectedDevice();if(n&&n.deviceId==e){var t=e9._ConnectHandler.getCommunicationService();if(t){var a=e9._ConnectHandler.getCommunicationReadCharacteristic();a&&e9._DataHandler.readData(e,t.uuid,a.uuid)}}}else console.error("readData error, _DataHandler is null")}},{key:"_onScanFound",value:function e(e){var n,t;if(e&&e.length>0&&e9._isAutoConnectDevices){var a,i,c;var o=(a=e9._ConnectHandler)===null||a===void 0?void 0:a.getCommunication().onMatchingConnectDevice(e);o&&((i=e9._ConnectHandler)===null||i===void 0?void 0:i.connect(o,!1),(c=e9._ScanHandler)===null||c===void 0?void 0:c.stopScan())}var r;var u=((r=(t=e9._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),e9._BluetoothCallbackManager.onFoundDev(e)}},{key:"_onScanAdapter",value:function e(e){e9._BluetoothCallbackManager.onAdapter(e)}},{key:"_onScanSuccess",value:function e(){e9._BluetoothCallbackManager.onScanSuccess()}},{key:"_onScanFailed",value:function e(e){e9._BluetoothCallbackManager.onScanFailed(e)}},{key:"_onScanStop",value:function e(){var e;((e=e9._ConnectHandler)===null||e===void 0?void 0:e.isConnectedOrConnecting())||e9._BluetoothCallbackManager.onScanNotFound(),e9._BluetoothCallbackManager.onScanStop()}},{key:"_onConnectStateDisconnect",value:function e(e){e9._isHasAuth=!1,e9._BluetoothCallbackManager.onDevStatusDisconnect(e)}},{key:"_onConnectStateFailed",value:function e(e){var n;e9._isHasAuth=!1,(n=e9._ScanHandler)===null||n===void 0?void 0:n.startScan(),e9._BluetoothCallbackManager.onDevStatusFailed(e)}},{key:"_onConnectStateSuccess",value:function e(e){return a(function(){var n,t,a,i,c;return f(this,function(o){if(e&&e9._DataHandler){;(n=e9._DataHandler)===null||n===void 0?void 0:n.init();a={onReceiveData:function e(e){e9._onTransmitDeviceData(e)}};if(e9._isNeedAuth&&!e9._isHasAuth&&e9._Cat1LockAuthHandler){i={onAuthSuccess:function n(){if(e9._ConnectHandler&&e9._ConnectHandler.getCommunicationService()){var n;var t=e9._ConnectHandler.getCommunicationService();e9._resetNotifyBLECharacteristicValueChange({deviceId:e.deviceId,serviceId:t?t.uuid:"",characteristicId:(n=e9._ConnectHandler)===null||n===void 0?void 0:n.getCommunication().onMatchingServiceCharacteristic().notify})}e9._BluetoothCallbackManager.onAuthSuccess(),e9._isHasAuth=!0},onAuthFailed:function e(){console.log("Cat1LockAuthCallback onAuthFailed"),e9._BluetoothCallbackManager.onAuthFailed(),e9._isHasAuth=!1}};e9._Cat1LockAuthHandler.setCallback(i);c=e8.ab2hex(e.advertisData);e9._Cat1LockAuthHandler.handleSendData(e.deviceId,c)}(t=e9._DataHandler)===null||t===void 0?void 0:t.addCallbacks(a),console.log("onDevStatusSuccess 连接成功"),e9._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&&e9._DataHandler?((t=e9._DataHandler)===null||t===void 0?void 0:t.setMtu(e.deviceId,n),e9._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=e9._DataHandler)===null||n===void 0?void 0:n.init()},fail:function(e){console.log("重置通知失败"+JSON.stringify(e))}})}},{key:"_onTransmitDeviceData",value:function e(e){e9._BluetoothCallbackManager.onTransmitDeviceData(e)}},{key:"resetBluetoothData",value:function e(){e9._handleCloseMonitoring(),e9.setHasAuth(!1)}},{key:"_handleCloseMonitoring",value:function e(){var e,n;(e=e9._ScanHandler)===null||e===void 0?void 0:e.stopScan(!1),wx.offBluetoothDeviceFound(),wx.offBluetoothAdapterStateChange(),wx.closeBluetoothAdapter(),wx.offBLEMTUChange(),wx.offBLEConnectionStateChange(),wx.offBLECharacteristicValueChange(),(n=e9._ConnectHandler)===null||n===void 0?void 0:n.disconnect(!1)}}]);return e}(),nn=/*#__PURE__*/function(){"use strict";function e(){i(this,e);this.callbacks=Array()}o(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:"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:"onScanFailed",value:function e(e){this._doAction({action:function n(n){n.onScanFailed&&n.onScanFailed(e)}})}},{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 nt={BluetoothManager:ne,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,nt as default};//# sourceMappingURL=index.js.map
{
"name": "@onbright/bluetooth-sdk",
"version": "1.1.44",
"version": "1.1.45",
"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

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