qcloud-iotexplorer-bluetooth-adapter-llsync
Advanced tools
Comparing version 2.3.2 to 2.3.3
import { DeviceFilterFunction } from 'qcloud-iotexplorer-bluetooth-adapter'; | ||
import { ProductUIDevConfig } from 'iotexplorer-ui-dev-config'; | ||
import * as constants from '../../constants'; | ||
import { AppDevSdk, Reporter } from 'qcloud-iotexplorer-appdev-sdk'; | ||
@@ -55,11 +56,17 @@ import { Action } from '../../libs'; | ||
setLLEventHandleEnabled(enabled: boolean): void; | ||
onPropertyReport(data: any): Promise<void>; | ||
onPropertyReport({ data }: { | ||
data: any; | ||
}): Promise<void>; | ||
onGetStatus(): Promise<never>; | ||
onEventReport(data: any): Promise<never>; | ||
bindDevice({ familyId, roomId, }: { | ||
familyId: any; | ||
roomId: any; | ||
onEventReport({ data }: { | ||
data: any; | ||
}): Promise<never>; | ||
bindDevice({ familyId, roomId, secureBindInfo, }: { | ||
familyId: string; | ||
roomId: string; | ||
secureBindInfo?: constants.LLSyncSecureBindInfo; | ||
}): Promise<string>; | ||
bindDeviceEncrypted({ isDynamicRegister }: { | ||
bindDeviceEncrypted({ isDynamicRegister, secureBindInfo, }: { | ||
isDynamicRegister: boolean; | ||
secureBindInfo?: constants.LLSyncSecureBindInfo; | ||
}): Promise<{ | ||
@@ -84,3 +91,3 @@ sign: string; | ||
getDeviceNameEncrypted(): Promise<{ | ||
nonce: any; | ||
nonce: string; | ||
deviceName: any; | ||
@@ -122,3 +129,3 @@ }>; | ||
/** | ||
* @param data 要发送的hexdata string | ||
* @param data 要发送的hexdata string | ||
* @param mode 绑定,解绑等类型常数 | ||
@@ -125,0 +132,0 @@ * @returns {Promise} |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.StandardDeviceAdapter=exports.LLSyncDeviceAdapter=void 0;var tslib_1=require("tslib"),constants=tslib_1.__importStar(require("../../constants")),qcloud_iotexplorer_appdev_sdk_1=require("qcloud-iotexplorer-appdev-sdk"),constants_1=require("../../constants"),libs_1=require("../../libs"),utils=tslib_1.__importStar(require("../../libs")),Models_1=require("./Models"),LLSyncDeviceAdapterBase_1=require("../LLSyncDeviceAdapterBase"),LLSyncOtaProcessor_1=require("./LLSyncOtaProcessor"),LLSyncProtocol_1=require("./LLSyncProtocol"),_a=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils,arrayBufferToHexStringArray=_a.arrayBufferToHexStringArray,envDetect=_a.envDetect,delay=_a.delay,convertToMs=function(e){if("number"!=typeof e)throw new Error("timestamp should be a number");return e.toString().length>=13?e:1e3*e},WRITE_TO_DEVICE_CONF={timeout:LLSyncProtocol_1.LLSyncConfig.waitGetRegisterDeviceInfo,timeoutCode:constants.WAIT_REGISTER_DEVICE_INFO_REPLY_TIMEOUT,writeId:constants.DEVICE_INFO_WRITE_ID},LLSyncDeviceAdapter=function(e){function t(r){var n=e.call(this,r)||this;n._enableWsEventHandle=!0,n._enableLLEventHandle=!0;var s=function(e){return function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return tslib_1.__awaiter(n,void 0,void 0,(function(){return tslib_1.__generator(this,(function(r){switch(r.label){case 0:return[4,this.init()];case 1:return r.sent(),[2,e.apply(void 0,tslib_1.__spread(t))]}}))}))}};n.models=new Models_1.Models(t.options.appDevSdk),n.userIdentify=t.getUserIdentify(),n.on("disconnect",(function(){n.authorized=!1})),n.appDevSdk=t.options.appDevSdk,n.protocol=new LLSyncProtocol_1.LLSyncProtocol(n),n.otaProcessor=new LLSyncOtaProcessor_1.LLSyncOtaProcessor(n),Object.assign(n,{bindDevice:s(n.bindDevice.bind(n)),unbindDevice:s(n.unbindDevice.bind(n)),controlDevice:s(n.controlDevice.bind(n)),controlAction:s(n.controlAction.bind(n)),authenticateConnection:s(n.authenticateConnection.bind(n)),reconnectDevice:s(n.authenticateConnection.bind(n)),startOta:s(n.startOta.bind(n)),cancelOta:s(n.cancelOta.bind(n)),userCancelBindDevice:s(n.protocol.cancelUserCheck.bind(n.protocol,"cancel"))}),n.init(),n.reporter={info:function(e,r){void 0===e&&(e=""),void 0===r&&(r={});var s=r.message,i=void 0===s?"":s,o=r.serviceId,c=tslib_1.__rest(r,["message","serviceId"]),a=n,d=a.explorerDeviceId,l=a.deviceId,u=a.isConnected;t.options.appDevSdk.reporter.info(constants_1.REPORT_EVENT_TYPE,{serviceId:o||t.serviceId,message:i||(e&&constants.ACTION_DESC[e]?e+"("+constants.ACTION_DESC[e]+")":e),timeCost:c.timeCost||0,action:e,data:tslib_1.__assign({deviceId:d,bleDeviceId:l,isConnected:u},c)})},error:function(e,r){void 0===e&&(e=""),void 0===r&&(r={});var s=r.error,i=tslib_1.__rest(r,["error"]),o=n,c=o.explorerDeviceId,a=o.deviceId,d=o.isConnected;s&&s.code&&constants.ERROR_MESSAGES[s.code]&&(s.msg=constants.ERROR_MESSAGES[s.code]),t.options.appDevSdk.reporter.error(constants_1.REPORT_EVENT_TYPE,{message:constants.ERROR_MESSAGES[e]?e+"("+constants.ERROR_MESSAGES[e]+":"+(s&&(s.message||s.errMsg||s.msg||s.code))+")":"",timeCost:i.timeCost||0,action:e,error:s,data:tslib_1.__assign(tslib_1.__assign({deviceId:c,bleDeviceId:a,isConnected:d},i),s)})}};var i=function(e){var t=e.deviceId,r=e.deviceData;if(n._enableWsEventHandle&&(console.log("llsync receive onControl",t,r,n.ready,n.explorerDeviceId),n.ready&&t===n.explorerDeviceId)){var s={};Object.keys(r).forEach((function(e){s[e]=r[e].Value})),n.controlDevice({deviceData:s})}},o=function(e){var t=e.deviceId,r=e.Payload;n._enableWsEventHandle&&n.ready&&t===n.explorerDeviceId&&n.controlAction({actionData:r})};return n.on("authorized",(function(){n.init(!0),n.appDevSdk.on(qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.constants.EventTypes.WsControl,i),n.appDevSdk.on(qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.constants.EventTypes.WsActionPush,o)})).on("disconnect",(function(){n.appDevSdk.off(qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.constants.EventTypes.WsControl,i),n.appDevSdk.off(qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.constants.EventTypes.WsActionPush,o)})),n}return tslib_1.__extends(t,e),t.getUserIdentify=function(){var e,r,n,s;return libs_1.getUserIdentify(null===(s=null===(n=null===(r=null===(e=t.options)||void 0===e?void 0:e.appDevSdk)||void 0===r?void 0:r.loginManager)||void 0===n?void 0:n.userInfo)||void 0===s?void 0:s.UserID)},t.injectOptions=function(e){e.appDevSdk.reporter&&e.appDevSdk.requestApi||console.warn("invalid appDevSdk",e.appDevSdk),t.options=e},Object.defineProperty(t.prototype,"ready",{get:function(){return console.log("isConnected",this.isConnected,"isAuthorized",this.authorized),this.isConnected&&this.authorized},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"needUserCheck",{get:function(){var e,t,r;try{return!!parseInt((null===(r=null===(t=null===(e=null==this?void 0:this.productConfig)||void 0===e?void 0:e.BleConfig)||void 0===t?void 0:t.bindingBootConfig)||void 0===r?void 0:r.confirmRequired)||"0")}catch(e){return console.warn("LLSync check confirmRequired fail",e),!1}},enumerable:!1,configurable:!0}),t.prototype.normalizeError=function(t){return!(t=e.prototype._normalizeError.call(this,t)).msg&&t.code&&constants.ERROR_MESSAGES[t.code]&&(t.msg=constants.ERROR_MESSAGES[t.code]),t},t.prototype.init=function(r){return tslib_1.__awaiter(this,void 0,void 0,(function(){var n=this;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:if(!t.options)throw"标准蓝牙适配器未初始化Options";return[4,e.prototype.init.call(this)];case 1:return s.sent(),r&&(this.productInfo=this.productConfig=this._initPromise=null),[2,this._initPromise||(this._initPromise=new Promise((function(e,t){return tslib_1.__awaiter(n,void 0,void 0,(function(){var r,n,s,i,o,c,a;return tslib_1.__generator(this,(function(d){switch(d.label){case 0:return d.trys.push([0,2,,3]),n=(r=this).productConfig,s=r.productInfo,[4,Promise.all([n?Promise.resolve(n):this.models.getProduct({ProductId:this.productId}),s?Promise.resolve(s):this.models.getProductConfig({ProductId:this.productId})])];case 1:return i=tslib_1.__read.apply(void 0,[d.sent(),2]),o=i[0],c=i[1],this.dataTemplate=libs_1.getProductDateTemplate(o),this.productInfo=o,this.productConfig=c,console.log("init llsync done",{productInfo:this.productInfo,productConfig:this.productConfig,dataTemplate:this.dataTemplate}),e(),[3,3];case 2:return a=d.sent(),console.error("init standard device adapter fail",a),t(a),this._initPromise=null,[3,3];case 3:return[2]}}))}))})))]}}))}))},t.prototype.getDevicePsk=function(e){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,r,n,s,i,o;return tslib_1.__generator(this,(function(c){switch(c.label){case 0:return t={DeviceId:this.productId+"/"+(e||this.deviceName),DeviceKey:LLSyncProtocol_1.LLSyncConfig.BLE_PSK_DEVICE_KEY},[4,Promise.all([this.models.getDeviceConfig(tslib_1.__assign(tslib_1.__assign({},t),{isUserConfig:!0})),this.models.getDeviceConfig(t)])];case 1:if(r=tslib_1.__read.apply(void 0,[c.sent(),2]),n=r[0],s=r[1],!n||s)return[3,5];c.label=2;case 2:return c.trys.push([2,4,,5]),[4,this.models.setDeviceConfig({DeviceId:t.DeviceId,DeviceKey:t.DeviceKey,DeviceValue:n})];case 3:return c.sent(),[3,5];case 4:return i=c.sent(),console.error("update psk to DeviceConfig fail",i),[3,5];case 5:if(!(o=s||n))throw{code:constants.PSK_GET_ERROR};return[2,o]}}))}))},t.prototype.startOta=function(e){var t=e.onProgress;return this.otaProcessor.startOta({onProgress:t})},t.prototype.cancelOta=function(){return this.otaProcessor.cancelOta()},t.prototype.startListenLLEvents=function(){this.on(constants.PROPERTY_REPORT,utils.wrapEventHandler(this.onPropertyReport.bind(this),constants.PROPERTY_REPORT)),this.on(constants.GET_STATUS,this.onGetStatus.bind(this)),this.on(constants.EVENT_REPORT,utils.wrapEventHandler(this.onEventReport.bind(this),constants.EVENT_REPORT))},t.prototype.stopListenLLEvents=function(){this.off(constants.PROPERTY_REPORT),this.off(constants.GET_STATUS),this.off(constants.EVENT_REPORT)},t.prototype.setWsEventHandleEnabled=function(e){this._enableWsEventHandle=e},t.prototype.setLLEventHandleEnabled=function(e){this._enableLLEventHandle=e},t.prototype.onPropertyReport=function(e){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,r,n,s,i;return tslib_1.__generator(this,(function(o){switch(o.label){case 0:if(!this._enableLLEventHandle)return[2];try{console.log("onPropertyReport check this",this),t=utils.convertPropertiesTlvToJsObject(e.slice(2),this.dataTemplate),this.reporter.info(constants.REPORT_RESULT,{data:utils.formatArrayToReportString(e),jsObj:t}),this.emit("propertyReport",{deviceData:t})}catch(e){return this.reporter.error(constants.REPORT_RESULT_ERROR,{error:e}),this.protocol.reportPropertyReportResult(constants.PropertyReportReplyResult.ParseDataFail),[2]}o.label=1;case 1:return o.trys.push([1,3,,4]),r=t["_sys _timestamp"],[4,this.models.reportBlueToothDeviceData({ProductId:this.productId,DeviceName:this.deviceName,Data:t,DataTimeStamp:r?convertToMs(r):Date.now()})];case 2:if(n=o.sent().Data){if((s=JSON.parse(n)).code)throw{code:constants.PROPERTY_REPORT_API_FAIL,reportReplyCode:s.code};this.protocol.reportPropertyReportResult(constants.PropertyReportReplyResult.Success)}return[3,4];case 3:return i=o.sent(),this.reporter.error(constants.REPORT_RESULT_ERROR,{error:i}),this.protocol.reportPropertyReportResult(constants.PropertyReportReplyResult.Fail),[3,4];case 4:return[2]}}))}))},t.prototype.onGetStatus=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,t,r,n,s,i;return tslib_1.__generator(this,(function(o){switch(o.label){case 0:if(!this._enableLLEventHandle)return[2];o.label=1;case 1:return o.trys.push([1,3,,4]),[4,this.models.getDeviceData({ProductId:this.productId,DeviceName:this.deviceName})];case 2:return e=o.sent(),t={},Object.keys(e).forEach((function(r){t[r]=e[r].Value})),r=utils.convertPropertiesChangeToTlv(t,this.dataTemplate),n=r.tlvData,s=r.tmpData,this.reporter.info(constants.GET_STATUS,{properties:t,tlvData:utils.formatArrayToReportString(n),tmpData:s}),this.protocol.reportGetStatusResult(0,n,s),[3,4];case 3:return i=o.sent(),this.reporter.error(constants.GET_STATUS_ERROR,{error:i}),this.protocol.reportGetStatusResult(-1),[2,Promise.reject(this.normalizeError(i))];case 4:return[2]}}))}))},t.prototype.onEventReport=function(e){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,r,n,s,i,o,c,a;return tslib_1.__generator(this,(function(d){switch(d.label){case 0:if(!this._enableLLEventHandle)return[2];d.label=1;case 1:d.trys.push([1,9,,10]),console.log("onEventReport check this",this),t=utils.getStrLength(e),r=utils.convertEventTlvToJsObject(e.slice(2,2+t),this.dataTemplate),n=r.eventId,s=r.params,i=r.eventIndex,o={DeviceId:this.explorerDeviceId,EventId:n,Params:JSON.stringify(s)},this.emit("eventReport",{eventIndex:i,params:s}),this.reporter.info(constants.EVENT_REPLY,tslib_1.__assign(tslib_1.__assign({},o),{eventIndex:i})),d.label=2;case 2:return d.trys.push([2,7,,8]),[4,this.models.reportDeviceEvent(o)];case 3:return d.sent(),console.log("reportDeviceEvent success"),e.length-2>t?(console.log("have more event data to report",e.length,t),[4,this.onEventReport({data:e.slice(t+2+1)})]):[3,5];case 4:return d.sent(),[3,6];case 5:this.protocol.reportEventReportResult(0,i),d.label=6;case 6:return[3,8];case 7:throw c=d.sent(),console.error({error:c,eventIndex:i}),this.protocol.reportEventReportResult(-1,i),c;case 8:return[3,10];case 9:return a=d.sent(),this.reporter.error(constants.EVENT_REPLY_ERROR,{error:a}),[2,Promise.reject(this.normalizeError(a))];case 10:return[2]}}))}))},t.prototype.bindDevice=function(e){var t=e.familyId,r=e.roomId;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,n,s,i,o,c,a,d,l,u,_,p,v,h,E,I,f;return tslib_1.__generator(this,(function(D){switch(D.label){case 0:e=this.extendInfo,n=e.isDynamicRegister,s=e.isEncrypted,libs_1.log("bindDevice isEncrypted:",{isEncrypted:s,isDynamicRegister:n}),this.isEncrypted=s,D.label=1;case 1:return D.trys.push([1,6,,7]),s?[4,this.bindDeviceEncrypted({isDynamicRegister:n})]:[3,3];case 2:return I=D.sent(),i=I.sign,o=I.timestamp,c=I.nonce,a=I.deviceName,d=I.secretKey,[3,5];case 3:return[4,this.protocol.requestBindDevice({needUserCheck:this.needUserCheck,isDynamicRegister:n})];case 4:f=D.sent(),i=f.sign,o=f.timestamp,c=f.nonce,a=f.deviceName,D.label=5;case 5:return this.extendInfo.isDynamicRegister=!1,[3,7];case 6:return l=D.sent(),libs_1.log("get bind sign failed, isEncrypted:",s,l),!s&&this.protocol.reportBindError(l.code),[2,Promise.reject(this.normalizeError(l))];case 7:D.trys.push([7,16,,17]),this.reporter.info(constants.BIND_AUTH),u=Date.now(),this.deviceName=a,D.label=8;case 8:return D.trys.push([8,10,,11]),_={Signature:i,DeviceTimestamp:o,DeviceId:this.explorerDeviceId,ConnId:""+c,FamilyId:t,RoomId:r,BindType:"bluetooth_sign",SignMethod:s?"hmacsha256":"hmacsha1"},this.reporter.info(constants.BIND_AUTH_DETAIL,_),[4,this.models.addDeviceBySigInFamily(_)];case 9:return D.sent(),[3,11];case 10:return p=D.sent(),s?this.protocol.reportBindEncryptedError(d):this.protocol.reportBindError(p.code),[2,Promise.reject(this.normalizeError(p))];case 11:return s?[4,this.protocol.reportBindEncryptedSuccess(u,d)]:[3,13];case 12:return D.sent(),[3,15];case 13:return v=this,[4,this.protocol.reportBindSuccess(u)];case 14:v.localPsk=D.sent(),D.label=15;case 15:try{if(this.reporter.info(constants.BIND_AUTH_DETAIL,tslib_1.__assign({},this.extendInfo)),!this.extendInfo.macStr)return[2];h={productId:this.productId,deviceName:a,deviceInfo:{mac:this.extendInfo.macStr}},this.reporter.info(constants.BIND_AUTH_DETAIL,tslib_1.__assign({msg:"START_REPORT_DEVICE_INFO"},h)),this.models.reportDeviceInfo(h)}catch(e){}return[2,this.explorerDeviceId];case 16:return E=D.sent(),console.log(E),console.log("error in bindDevice",E),this.reporter.error(constants.BIND_AUTH_FAIL,{error:E}),[2,Promise.reject(this.normalizeError(E))];case 17:return[2]}}))}))},t.prototype.bindDeviceEncrypted=function(e){var t=e.isDynamicRegister,r=void 0!==t&&t;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,t,n,s,i,o,c,a,d,l,u,_,p,v;return tslib_1.__generator(this,(function(h){switch(h.label){case 0:return h.trys.push([0,9,,10]),e=void 0,t=void 0,r?[4,this.getDeviceNameWithRegister()]:[3,2];case 1:return p=h.sent(),e=p.deviceName,t=p.nonce,[3,4];case 2:return[4,this.getDeviceNameEncrypted()];case 3:v=h.sent(),e=v.deviceName,t=v.nonce,h.label=4;case 4:return this.deviceName=e,[4,this.models.getDeviceSignAgitated({DeviceId:this.productId+"/"+e,Content:t})];case 5:return n=h.sent(),libs_1.log("get device sign response: ",n),s=n.AgitatedSignature,i=n.Timestamp,o=n.AgitatedContent,[4,this.requestBindEncrypted(s,i)];case 6:return c=h.sent(),a=c.deviceSign,d=c.R2,[4,this.verifyDeviceSign(o,d,a)];case 7:return l=h.sent(),libs_1.log("ks:",l),[4,this.notifyBindDevice(l)];case 8:return u=h.sent(),this.secretKey=l,libs_1.log("get notifyRes:",u),[2,{sign:u.sign,timestamp:Number(i),nonce:libs_1.hex2Base64(t),secretKey:l,deviceName:e}];case 9:return _=h.sent(),console.warn("bind device encrypted failed",_),[2,Promise.reject(_)];case 10:return[2]}}))}))},t.prototype.requestBindEncrypted=function(e,t){return tslib_1.__awaiter(this,void 0,void 0,(function(){var r,n,s,i,o,c,a,d,l,u=this;return tslib_1.__generator(this,(function(_){switch(_.label){case 0:return r=constants.DEVICE_INFO_WRITE_PREFIX,n=constants.REQUEST_BIND,s=r[n],i=Number(t).toString(16),o=libs_1.base64toHEX(e),c=libs_1.randomBytesHex(16),a=""+s+c+i+o,libs_1.log("REQUEST_BIND_PAYLOAD: ",s+"/"+c+"/"+i+"/"+o),[4,this.sendBleData(a,n).then((function(e){var t=parseInt(e.slice(2,3).join(""),16);if(1===t)throw{code:constants.REQUEST_BIND_FAILED};var r=e.slice(3,19).join("").toLowerCase(),n=parseInt(e.slice(19,23).join(""),16).toString(),s=e.slice(23).join("").toLowerCase(),i="/".charCodeAt(0).toString(16),o=""+r+i+libs_1.str2hexStr(n)+i;return libs_1.log("bind request response",{nonce:r,timestamp:n,sign:s,R2:o}),u.reporter.info(constants.REQUEST_BIND_SUCCESS,{nonce:r,timestamp:n,sign:s,R2:o}),{ack:t,timestamp:n,R2:o,deviceSign:s}}))];case 1:return d=_.sent(),l=d.deviceSign,libs_1.log("verify sign succeed",l),[2,d]}}))}))},t.prototype.verifyDeviceSign=function(e,t,r){return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(n){switch(n.label){case 0:return[4,this.models.getDeviceSecret({DeviceId:this.productId+"/"+this.deviceName,AppNonce:e,DeviceNonce:t,DeviceNonceSign:r})];case 1:return[2,n.sent()]}}))}))},t.prototype.getDeviceNameWithRegister=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,t,r,n,s,i,o,c,a=this;return tslib_1.__generator(this,(function(d){switch(d.label){case 0:return e=constants.DEVICE_INFO_WRITE_PREFIX[constants.GET_DEVICE_NAME],t=Math.floor(Date.now()/1e3),r=parseInt(utils.gen4BytesIntHex(),16),n=""+e+r.toString(16)+t.toString(16),[4,this.sendBleData(n,constants.GET_DEVICE_NAME_WITH_REGISTER).then((function(e){var t=parseInt(e[2],16);if(1===t)throw libs_1.log("get register data failed",{ack:t,data:e}),{code:constants.GET_DEVICE_NAME_WITH_REGISTER_FAILED};var r=parseInt(e.slice(3,4).join(""),16),n=libs_1.hex2str(e.slice(4,4+r)),s=libs_1.hex2str(e.slice(4+r));return libs_1.log("register data",{bleData:e,sign:s,deviceName:n}),{deviceName:n,sign:s}}))];case 1:return s=d.sent(),i=s.deviceName,o=s.sign,[4,this.models.dynamicRegisterDevice({deviceName:i,sign:o,productId:this.productId,timestamp:t,nonce:r})];case 2:return c=d.sent().payload,libs_1.log("dynamic register payload",c),[4,this.sendBleData(""+constants.DEVICE_INFO_WRITE_PREFIX[constants.GET_DEVICE_NAME_WITH_REGISTER]+libs_1.str2hexStr(c),constants.GET_DEVICE_NAME).then((function(e){var t=parseInt(e[2],16);if(1===t)throw a.reporter.error(constants.REGISTER_DEVICE_INFO_REPLY_INVALID,{ack:t,data:e}),{code:constants.REGISTER_DEVICE_INFO_REPLY_INVALID};var r=e.slice(3,19).join(""),n=libs_1.hex2str(e.slice(19));return libs_1.log("dyna register res",{deviceName:n,sign:r}),{deviceName:n,nonce:r}}))];case 3:return[2,d.sent()]}}))}))},t.prototype.getDeviceNameEncrypted=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,t,r=this;return tslib_1.__generator(this,(function(n){switch(n.label){case 0:return e=constants.DEVICE_INFO_WRITE_PREFIX[constants.GET_DEVICE_NAME],[4,this.writeAndWait4Response([e],constants.GET_DEVICE_NAME,(function(e){if(!e.length)throw{code:constants.REGISTER_DEVICE_INFO_REPLY_INVALID};var t=libs_1.getStrLength(e),n=parseInt(e.slice(2,3).join(""),16),s=e.slice(3,19).join(""),i=libs_1.hex2str(e.slice(19));return r.reporter.info(constants.GET_DEVICE_NAME,{allLength:t,nonce:s,ack:n,deviceName:i}),{nonce:s,deviceName:i}}),WRITE_TO_DEVICE_CONF)];case 1:return t=n.sent(),libs_1.log("getDeviceName res",t),[2,t]}}))}))},t.prototype.encrypt=function(e,t,r){void 0===r&&(r={}),libs_1.log("start to encrypt data",e);var n=this.appDevSdk.utils.CryptoJS,s=function(e){"hex"===r.contentType&&(e=n.enc.Hex.parse(e));var s=n.AES.encrypt(e,n.enc.Hex.parse(t),{mode:n.mode.ECB,padding:n.pad.Pkcs7});return libs_1.base64toHEX(s.toString())};return"string"==typeof e?s(e):e.map(s)},t.prototype.notifyBindDevice=function(e){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,r,n=this;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:return t=constants.DEVICE_INFO_WRITE_PREFIX[constants.NOTIFY_BIND],"BindRequest",r=this.encrypt("BindRequest",e),[4,this.sendBleData(""+t+r,constants.NOTIFY_BIND).then((function(t){var r=parseInt(t.slice(2,3).join(""),16);if(1===r){var s={code:constants.NOTIFY_BIND_FAILED};throw n.reporter.error(constants.NOTIFY_BIND_FAILED,{ack:r,error:s,res:t}),s}var i=t.slice(3).join(""),o=utils.decrypt(i,e);return libs_1.log("bind decrypted sign:",o),n.reporter.info(constants.NOTIFY_BIND_SUCCESS,{ack:r,sign:o}),{ack:r,sign:o}}))];case 1:return[2,s.sent()]}}))}))},t.prototype.unbindDevice=function(e){var t=e.familyId,r=e.deviceName;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,n,s,i,o;return tslib_1.__generator(this,(function(c){switch(c.label){case 0:e=Date.now(),c.label=1;case 1:return c.trys.push([1,9,,10]),this.isEncrypted?[4,this.unbindDeviceEncrypted()]:[3,3];case 2:return c.sent(),[3,6];case 3:if(!r)throw{code:constants.DEVICE_NAME_IS_EMPTY};return[4,this.getDevicePsk(r)];case 4:return n=c.sent(),this.reporter.info(constants.UNBIND_AUTH,{localPsk:n}),[4,this.protocol.getUnbindAuthSign()];case 5:if(s=c.sent().sign,i=utils.encrypt(constants.UNBIND_RESPONSE,n),s!==i)throw{code:constants.UNBIND_REPLY_ERROR};this.localPsk=n,this.deviceName=r,c.label=6;case 6:return[4,this.models.deleteDeviceFromFamily({FamilyId:t,DeviceId:this.explorerDeviceId})];case 7:return c.sent(),this.reporter.info(constants.UNBIND_RESULT_AUTH_SUCCESS,{timeCost:Date.now()-e}),[4,this.protocol.reportUnbindResult("success")];case 8:return c.sent(),this.stopListenLLEvents(),this.authorized=!1,this.disconnectDevice(),[3,10];case 9:return o=c.sent(),this.protocol.reportUnbindResult("fail"),this.reporter.error(constants.UNBIND_RESULT_AUTH_FAIL,{error:o}),[2,Promise.reject(this.normalizeError(o))];case 10:return[2]}}))}))},t.prototype.unbindDeviceEncrypted=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,t,r=this;return tslib_1.__generator(this,(function(n){switch(n.label){case 0:return e=constants.DEVICE_INFO_WRITE_PREFIX[constants.UNBIND_REQUEST],"UnbindRequest",t=this.encrypt("UnbindRequest",this.sessionKey),[4,this.sendBleData(""+e+t,constants.UNBIND_REQUEST).then((function(e){if(libs_1.log("unbind res encrypted data",e),1===parseInt(e[2],16))throw{code:constants.UNBIND_REPLY_INVALID};var t=utils.decrypt(e.slice(3).join(""),r.sessionKey);if(libs_1.log("unbind payload",libs_1.hex2str(t)),"UnbindResponse"===libs_1.hex2str(t))return!0;throw{code:constants.UNBIND_REPLY_ERROR}}))];case 1:return[2,n.sent()]}}))}))},t.prototype.controlDevice=function(e){var t=e.deviceData;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e;return tslib_1.__generator(this,(function(r){switch(r.label){case 0:return r.trys.push([0,3,,4]),console.log("controlDevice check this",this),this.reporter.info(constants.CONTROL_DEVICE,{deviceData:t}),[4,this.protocol.controlDeviceProperty(t)];case 1:return r.sent(),this.emit("controlPropertySuccess",{deviceData:t}),[4,this.models.reportBlueToothDeviceData({ProductId:this.productId,DeviceName:this.deviceName,Data:t,DataTimeStamp:Date.now()})];case 2:return r.sent(),[3,4];case 3:return e=r.sent(),this.reporter.error(constants.CONTROL_DEVICE_REPLY_ERROR,{error:e}),[2,Promise.reject(this.normalizeError(e))];case 4:return[2]}}))}))},t.prototype.controlAction=function(e){var t=e.actionData;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,r,n,s,i,o;return tslib_1.__generator(this,(function(c){switch(c.label){case 0:return c.trys.push([0,4,,5]),console.log("controlAction check this",this),[4,this.protocol.controlDeviceAction(t)];case 1:return e=c.sent().output,[4,utils.convertActionOutputTlvToJsObject(e,this.dataTemplate)];case 2:return r=c.sent(),n=r.outputParams,s=r.actionIndex,i=r.actionId,[4,this.models.publishDeviceActionMessage({deviceName:this.deviceName,productId:this.productId,actionId:i,clientToken:t.clientToken,output:n})];case 3:return c.sent(),this.reporter.info(constants.CONTROL_ACTION_SUCCESS,{outputParams:n,actionIndex:s,actionId:i}),[3,5];case 4:return o=c.sent(),this.reporter.error(constants.CONTROL_ACTION_ERROR,{error:o}),[2,Promise.reject(this.normalizeError(o))];case 5:return[2]}}))}))},t.prototype.authenticateConnection=function(e){var t=(void 0===e?{}:e).deviceName;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,r,n,s,i,o,c,a,d,l,u,_,p,v,h;return tslib_1.__generator(this,(function(E){switch(E.label){case 0:if(E.trys.push([0,18,,19]),console.log("start authenticate connection",t),!t)throw{code:constants.DEVICE_NAME_IS_EMPTY};return[4,this.models.getDeviceConfig({DeviceId:this.productId+"/"+t,DeviceKey:LLSyncProtocol_1.LLSyncConfig.Secret_Encrypt_Key})];case 1:return e=E.sent(),envDetect.isIOS&&this.extendInfo.moduleVersion>=2?[4,this.protocol.notifyAppOnIOSDevice()]:[3,4];case 2:return E.sent(),[4,delay(100)];case 3:E.sent(),E.label=4;case 4:if(r=void 0,n=void 0,s=void 0,i=void 0,o=Date.now(),!e)return[3,9];this.isEncrypted=!0,this.authorized=!1,this.secretKey=e,E.label=5;case 5:return E.trys.push([5,7,,8]),[4,this.authConnectionEncrypted({deviceName:t})];case 6:return v=E.sent(),r=v.version,n=v.mtu,s=v.needSetMtu,i=v.otaVersion,[3,8];case 7:return c=E.sent(),libs_1.log("auth connection encrypted faild",c),[2,Promise.reject(c)];case 8:return[3,13];case 9:return[4,this.getDevicePsk(t)];case 10:return a=E.sent(),this.localPsk=a,this.reporter.info(constants.CONNECT_AUTH,{localPsk:a}),[4,this.protocol.getDeviceAuthInfo()];case 11:if(d=E.sent(),l=d.sign,u=d.timestamp,_=utils.encrypt(""+(u+60)+this.productId+t,a),l!==_)throw{code:constants.CONNECT_SIGN_AUTH_ERROR};return[4,this.protocol.getDeviceInfo()];case 12:h=E.sent(),r=h.version,n=h.mtu,s=h.needSetMtu,i=h.otaVersion,E.label=13;case 13:if(this.deviceName=t,this.bleVersion=r,this.mtu=Math.max(constants.MIN_ATT_MTU,n)-constants.ATT_MTU_TO_LLSYNC_MTU_DELTA,!s)return[3,17];E.label=14;case 14:return E.trys.push([14,16,,17]),[4,this.setMtu(n)];case 15:return E.sent(),this.writeMtuResult("success"),[3,17];case 16:return E.sent(),this.writeMtuResult("fail"),[3,17];case 17:return this.otaVersion=i,i&&this.models.reportOTAVersion({Version:i,DeviceId:this.explorerDeviceId}),this.reporter.info(constants.CONNECT_RESULT_WRITE_SUCCESS,{timeCost:Date.now()-o,version:r,mtu:n,otaVersion:i}),this.authorized=!0,this.emit("authorized",{version:r,mtu:n,otaVersion:i}),this.stopListenLLEvents(),this.startListenLLEvents(),this.extendInfo.moduleVersion>=2&&this.protocol.notifyAppReady(),[3,19];case 18:return p=E.sent(),this.protocol.reportConnectError(),this.reporter.error(constants.CONNECT_RESULT_WRITE_FAIL,{error:p}),[2,Promise.reject(this.normalizeError(p))];case 19:return[2]}}))}))},t.prototype.authConnectionEncrypted=function(e){var t=e.deviceName;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,r,n,s,i,o,c,a,d,l,u,_=this;return tslib_1.__generator(this,(function(p){switch(p.label){case 0:return e=constants.DEVICE_INFO_WRITE_PREFIX,r=constants.CONNECT_REQUEST,n=constants.CONNECT_ACK,s=""+e[r]+this.encrypt("ConnectRequest",this.secretKey),[4,this.sendBleData(s,r).then((function(e){libs_1.log("connect res",e);var t=parseInt(e[2],16),r=e.slice(3,19).join(""),n=e.slice(19).join("");if(1===t)throw{code:constants.CONNECT_SIGN_AUTH_ERROR};return{ack:t,R3:r,sign:n}}))];case 1:return i=p.sent(),o=i.R3,c=i.sign,[4,this.models.getDeviceSign({DeviceId:this.productId+"/"+(t||this.deviceName),Content:""+o+";".charCodeAt(0).toString(16)+this.secretKey,ContentType:"hex"})];case 2:if(a=p.sent(),libs_1.log("get sessionKey",a),d=this.encrypt(o,a,{contentType:"hex"}),libs_1.log("verify sign:",d,c),d.toLowerCase()!==c.toLowerCase())throw{code:constants.CONNECT_SIGN_VERIFY_ERROR};return this.sessionKey=a,l=""+e[n]+this.encrypt("ConnectResult",this.sessionKey),[4,this.sendBleData(l,n).then((function(e){if(1===parseInt(e[2],16))throw{code:constants.CONNECT_SIGN_VERIFY_ERROR};var t=e.slice(3,19).join(""),r=utils.decrypt(t,_.sessionKey);libs_1.log("decrypted data",r,t);var n=_.appDevSdk.utils.byteUtil.hexString2hexArray(r),s=parseInt(n[0],16),i=parseInt(n.slice(1,3).join(""),16),o=n.slice(4).join("");return{version:s,mtu:8191&i,needSetMtu:!!(i>>15),otaVersion:o?libs_1.hex2str(o):o}}))];case 3:return u=p.sent(),libs_1.log("connect ack res",u),[2,u]}}))}))},t.prototype.getAdvertisingData=function(){var e,t;return tslib_1.__awaiter(this,void 0,void 0,(function(){var r;return tslib_1.__generator(this,(function(n){if(!(r=null===(e=this.extendInfo)||void 0===e?void 0:e.moduleVersion)||r<3)throw{code:"MODULE_VERSION_NOT_SUPPORT_GET_ADV_DATA",msg:"LLSync 版本 "+r+" 不支持 getAdvertisingData"};if((null===(t=this.extendInfo)||void 0===t?void 0:t.isEncrypted)&&this.authorized)throw{code:"GET_ADV_DATA_NOT_SUPPORTED_IN_CURRENT_STATE",msg:"LLSync 加密协议连接鉴权完成后暂不支持获取广播信息"};return[2,this.protocol.getAdvertisingData()]}))}))},t.prototype.sendHeartbeat=function(){var e;return tslib_1.__awaiter(this,void 0,void 0,(function(){var t;return tslib_1.__generator(this,(function(r){return!(t=null===(e=this.extendInfo)||void 0===e?void 0:e.moduleVersion)||t<3?(console.warn("LLSyncDeviceAdapter.sendHeartbeat noop: moduleVersion "+t+" not support heartbeat"),[2]):[2,this.protocol.sendHeartbeat()]}))}))},t.prototype.notifyLocalRssi=function(e){var t=e.rssi;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e;return tslib_1.__generator(this,(function(r){return(e=Math.round(t))<-255&&(e=-255),e>0&&(e=0),[2,this.protocol.notifyLocalRssi({rssi:e})]}))}))},t.prototype.sendBleData=function(e,t){return tslib_1.__awaiter(this,void 0,void 0,(function(){var r;return tslib_1.__generator(this,(function(n){return r=this.protocol._parseDataBeforeConnect(e,t),[2,this.writeAndWait4Response(r,t,(function(e){return e}),WRITE_TO_DEVICE_CONF)]}))}))},t.prototype.toString=function(){return"[LLSyncDeviceAdapter]"},t.serviceId16="0000FFE0-0000-1000-8000-00805F9B34FB",t.serviceId="0000FFE0-65D0-4E20-B56A-E493541BA4E2",t.deviceFilter=function(e,r){if(!e.advertisServiceUUIDs||!e.advertisServiceUUIDs.find((function(e){return e===t.serviceId16}))||!e.advertisData)return null;var n=t.options.appDevSdk.reporter;try{var s=Math.floor(10*Math.random())%10==1||!0,i=arrayBufferToHexStringArray(e.advertisData);s&&n.info(constants_1.REPORT_EVENT_TYPE,{message:"收到广播",serviceId:t.serviceId,hexArr:i.join(",")});var o=parseInt(i[2],16),c=o-(o>>2<<2),a=o>>4,d=o>>2&1,l=o>>3&1;libs_1.log("BLE_STATE =>",o.toString(2));var u=r.productId&&r.deviceName?r.productId+"/"+r.deviceName:"",_=u?utils.get8ByteFromStr(""+u.replace("/","")):"",p=!!u,v="",h="",E="",I=constants.DEVICE_STATE_MAP[c],f=[constants.DEVICE_HAS_BINDED,constants.DEVICE_HAS_CONNECTED].indexOf(I)>-1;if(f)E=i.slice(3,11).join("").toLocaleLowerCase(),h=i.slice(11).join("").toLocaleLowerCase(),v=r.productId;else{var D=i.slice(3,9);e.name&&-1===e.name.indexOf("_")&&(e.name=e.name+"_"+D.slice(0,2).join("")),v=libs_1.hex2str(i.slice(9))}s&&n.info(constants_1.REPORT_EVENT_TYPE,{message:"解析广播",serviceId:t.serviceId,data:{bindState:I||"x",targetDeviceId:u,targetDeviceIdentify:_,deviceUserIdentify:h||"x",deviceProductId:v||"x",deviceIdentify:E||"x",isDynamicRegister:!!d,isEncrypted:!!l,macStr:f?"":i.slice(3,9).join(":")}});var y=function(){var n=tslib_1.__assign(tslib_1.__assign({},e),{serviceId:t.serviceId,deviceName:r.deviceName||"",productId:v,extendInfo:{bindState:constants.DEVICE_STATE_MAP[I],moduleVersion:a,isDynamicRegister:!!d,isEncrypted:!!l,standard:!0,macStr:f?"":i.slice(3,9).join(":")}});return console.log("---设备匹配成功---",n),n};return p&&f&&E===_?y():p||f?null:y()}catch(e){console.error("llsync device filter error",e),n.error(constants_1.REPORT_EVENT_TYPE,{message:"协议广播出错",error:e})}},t}(LLSyncDeviceAdapterBase_1.LLSyncDeviceAdapterBase);exports.LLSyncDeviceAdapter=LLSyncDeviceAdapter,exports.StandardDeviceAdapter=LLSyncDeviceAdapter; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.StandardDeviceAdapter=exports.LLSyncDeviceAdapter=void 0;var tslib_1=require("tslib"),constants=tslib_1.__importStar(require("../../constants")),qcloud_iotexplorer_appdev_sdk_1=require("qcloud-iotexplorer-appdev-sdk"),constants_1=require("../../constants"),libs_1=require("../../libs"),utils=tslib_1.__importStar(require("../../libs")),Models_1=require("./Models"),LLSyncDeviceAdapterBase_1=require("../LLSyncDeviceAdapterBase"),LLSyncOtaProcessor_1=require("./LLSyncOtaProcessor"),LLSyncProtocol_1=require("./LLSyncProtocol"),_a=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils,arrayBufferToHexStringArray=_a.arrayBufferToHexStringArray,envDetect=_a.envDetect,delay=_a.delay,convertToMs=function(e){if("number"!=typeof e)throw new Error("timestamp should be a number");return e.toString().length>=13?e:1e3*e},WRITE_TO_DEVICE_CONF={timeout:LLSyncProtocol_1.LLSyncConfig.waitGetRegisterDeviceInfo,timeoutCode:constants.WAIT_REGISTER_DEVICE_INFO_REPLY_TIMEOUT,writeId:constants.DEVICE_INFO_WRITE_ID},LLSyncDeviceAdapter=function(e){function t(r){var n=e.call(this,r)||this;n._enableWsEventHandle=!0,n._enableLLEventHandle=!0;var s=function(e){return function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return tslib_1.__awaiter(n,void 0,void 0,(function(){return tslib_1.__generator(this,(function(r){switch(r.label){case 0:return[4,this.init()];case 1:return r.sent(),[2,e.apply(void 0,tslib_1.__spread(t))]}}))}))}};n.models=new Models_1.Models(t.options.appDevSdk),n.userIdentify=t.getUserIdentify(),n.on("disconnect",(function(){n.authorized=!1})),n.appDevSdk=t.options.appDevSdk,n.protocol=new LLSyncProtocol_1.LLSyncProtocol(n),n.otaProcessor=new LLSyncOtaProcessor_1.LLSyncOtaProcessor(n),Object.assign(n,{bindDevice:s(n.bindDevice.bind(n)),unbindDevice:s(n.unbindDevice.bind(n)),controlDevice:s(n.controlDevice.bind(n)),controlAction:s(n.controlAction.bind(n)),authenticateConnection:s(n.authenticateConnection.bind(n)),reconnectDevice:s(n.authenticateConnection.bind(n)),startOta:s(n.startOta.bind(n)),cancelOta:s(n.cancelOta.bind(n)),userCancelBindDevice:s(n.protocol.cancelUserCheck.bind(n.protocol,"cancel"))}),n.init(),n.reporter={info:function(e,r){void 0===e&&(e=""),void 0===r&&(r={});var s=r.message,i=void 0===s?"":s,o=r.serviceId,c=tslib_1.__rest(r,["message","serviceId"]),a=n,d=a.explorerDeviceId,l=a.deviceId,_=a.isConnected;t.options.appDevSdk.reporter.info(constants_1.REPORT_EVENT_TYPE,{serviceId:o||t.serviceId,message:i||(e&&constants.ACTION_DESC[e]?e+"("+constants.ACTION_DESC[e]+")":e),timeCost:c.timeCost||0,action:e,data:tslib_1.__assign({deviceId:d,bleDeviceId:l,isConnected:_},c)})},error:function(e,r){void 0===e&&(e=""),void 0===r&&(r={});var s=r.error,i=tslib_1.__rest(r,["error"]),o=n,c=o.explorerDeviceId,a=o.deviceId,d=o.isConnected;s&&s.code&&constants.ERROR_MESSAGES[s.code]&&(s.msg=constants.ERROR_MESSAGES[s.code]),t.options.appDevSdk.reporter.error(constants_1.REPORT_EVENT_TYPE,{message:constants.ERROR_MESSAGES[e]?e+"("+constants.ERROR_MESSAGES[e]+":"+(s&&(s.message||s.errMsg||s.msg||s.code))+")":"",timeCost:i.timeCost||0,action:e,error:s,data:tslib_1.__assign(tslib_1.__assign({deviceId:c,bleDeviceId:a,isConnected:d},i),s)})}};var i=function(e){var t=e.deviceId,r=e.deviceData;if(n._enableWsEventHandle&&(console.log("llsync receive onControl",t,r,n.ready,n.explorerDeviceId),n.ready&&t===n.explorerDeviceId)){var s={};Object.keys(r).forEach((function(e){s[e]=r[e].Value})),n.controlDevice({deviceData:s})}},o=function(e){var t=e.deviceId,r=e.Payload;n._enableWsEventHandle&&n.ready&&t===n.explorerDeviceId&&n.controlAction({actionData:r})};return n.on("authorized",(function(){n.init(!0),n.appDevSdk.on(qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.constants.EventTypes.WsControl,i),n.appDevSdk.on(qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.constants.EventTypes.WsActionPush,o)})).on("disconnect",(function(){n.appDevSdk.off(qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.constants.EventTypes.WsControl,i),n.appDevSdk.off(qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.constants.EventTypes.WsActionPush,o)})),n}return tslib_1.__extends(t,e),t.getUserIdentify=function(){var e,r,n,s;return libs_1.getUserIdentify(null===(s=null===(n=null===(r=null===(e=t.options)||void 0===e?void 0:e.appDevSdk)||void 0===r?void 0:r.loginManager)||void 0===n?void 0:n.userInfo)||void 0===s?void 0:s.UserID)},t.injectOptions=function(e){e.appDevSdk.reporter&&e.appDevSdk.requestApi||console.warn("invalid appDevSdk",e.appDevSdk),t.options=e},Object.defineProperty(t.prototype,"ready",{get:function(){return console.log("isConnected",this.isConnected,"isAuthorized",this.authorized),this.isConnected&&this.authorized},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"needUserCheck",{get:function(){var e,t,r;try{return!!parseInt((null===(r=null===(t=null===(e=null==this?void 0:this.productConfig)||void 0===e?void 0:e.BleConfig)||void 0===t?void 0:t.bindingBootConfig)||void 0===r?void 0:r.confirmRequired)||"0")}catch(e){return console.warn("LLSync check confirmRequired fail",e),!1}},enumerable:!1,configurable:!0}),t.prototype.normalizeError=function(t){return!(t=e.prototype._normalizeError.call(this,t)).msg&&t.code&&constants.ERROR_MESSAGES[t.code]&&(t.msg=constants.ERROR_MESSAGES[t.code]),t},t.prototype.init=function(r){return tslib_1.__awaiter(this,void 0,void 0,(function(){var n=this;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:if(!t.options)throw"标准蓝牙适配器未初始化Options";return[4,e.prototype.init.call(this)];case 1:return s.sent(),r&&(this.productInfo=this.productConfig=this._initPromise=null),[2,this._initPromise||(this._initPromise=new Promise((function(e,t){return tslib_1.__awaiter(n,void 0,void 0,(function(){var r,n,s,i,o,c,a;return tslib_1.__generator(this,(function(d){switch(d.label){case 0:return d.trys.push([0,2,,3]),n=(r=this).productConfig,s=r.productInfo,[4,Promise.all([n?Promise.resolve(n):this.models.getProduct({ProductId:this.productId}),s?Promise.resolve(s):this.models.getProductConfig({ProductId:this.productId})])];case 1:return i=tslib_1.__read.apply(void 0,[d.sent(),2]),o=i[0],c=i[1],this.dataTemplate=libs_1.getProductDateTemplate(o),this.productInfo=o,this.productConfig=c,console.log("init llsync done",{productInfo:this.productInfo,productConfig:this.productConfig,dataTemplate:this.dataTemplate}),e(),[3,3];case 2:return a=d.sent(),console.error("init standard device adapter fail",a),t(a),this._initPromise=null,[3,3];case 3:return[2]}}))}))})))]}}))}))},t.prototype.getDevicePsk=function(e){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,r,n,s,i,o;return tslib_1.__generator(this,(function(c){switch(c.label){case 0:return t={DeviceId:this.productId+"/"+(e||this.deviceName),DeviceKey:LLSyncProtocol_1.LLSyncConfig.BLE_PSK_DEVICE_KEY},[4,Promise.all([this.models.getDeviceConfig(tslib_1.__assign(tslib_1.__assign({},t),{isUserConfig:!0})),this.models.getDeviceConfig(t)])];case 1:if(r=tslib_1.__read.apply(void 0,[c.sent(),2]),n=r[0],s=r[1],!n||s)return[3,5];c.label=2;case 2:return c.trys.push([2,4,,5]),[4,this.models.setDeviceConfig({DeviceId:t.DeviceId,DeviceKey:t.DeviceKey,DeviceValue:n})];case 3:return c.sent(),[3,5];case 4:return i=c.sent(),console.error("update psk to DeviceConfig fail",i),[3,5];case 5:if(!(o=s||n))throw{code:constants.PSK_GET_ERROR};return[2,o]}}))}))},t.prototype.startOta=function(e){var t=e.onProgress;return this.otaProcessor.startOta({onProgress:t})},t.prototype.cancelOta=function(){return this.otaProcessor.cancelOta()},t.prototype.startListenLLEvents=function(){this.on(constants.PROPERTY_REPORT,utils.wrapEventHandler(this.onPropertyReport.bind(this),constants.PROPERTY_REPORT)),this.on(constants.GET_STATUS,this.onGetStatus.bind(this)),this.on(constants.EVENT_REPORT,utils.wrapEventHandler(this.onEventReport.bind(this),constants.EVENT_REPORT))},t.prototype.stopListenLLEvents=function(){this.off(constants.PROPERTY_REPORT),this.off(constants.GET_STATUS),this.off(constants.EVENT_REPORT)},t.prototype.setWsEventHandleEnabled=function(e){this._enableWsEventHandle=e},t.prototype.setLLEventHandleEnabled=function(e){this._enableLLEventHandle=e},t.prototype.onPropertyReport=function(e){var t=e.data;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,r,n,s,i;return tslib_1.__generator(this,(function(o){switch(o.label){case 0:if(!this._enableLLEventHandle)return[2];try{console.log("onPropertyReport check this",this),e=utils.convertPropertiesTlvToJsObject(t.slice(2),this.dataTemplate),this.reporter.info(constants.REPORT_RESULT,{data:utils.formatArrayToReportString(t),jsObj:e}),this.emit("propertyReport",{deviceData:e})}catch(e){return this.reporter.error(constants.REPORT_RESULT_ERROR,{error:e}),this.protocol.reportPropertyReportResult(constants.PropertyReportReplyResult.ParseDataFail),[2]}o.label=1;case 1:return o.trys.push([1,3,,4]),r=e["_sys _timestamp"],[4,this.models.reportBlueToothDeviceData({ProductId:this.productId,DeviceName:this.deviceName,Data:e,DataTimeStamp:r?convertToMs(r):Date.now()})];case 2:if(n=o.sent().Data){if((s=JSON.parse(n)).code)throw{code:constants.PROPERTY_REPORT_API_FAIL,reportReplyCode:s.code};this.protocol.reportPropertyReportResult(constants.PropertyReportReplyResult.Success)}return[3,4];case 3:return i=o.sent(),this.reporter.error(constants.REPORT_RESULT_ERROR,{error:i}),this.protocol.reportPropertyReportResult(constants.PropertyReportReplyResult.Fail),[3,4];case 4:return[2]}}))}))},t.prototype.onGetStatus=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,t,r,n,s,i;return tslib_1.__generator(this,(function(o){switch(o.label){case 0:if(!this._enableLLEventHandle)return[2];o.label=1;case 1:return o.trys.push([1,3,,4]),[4,this.models.getDeviceData({ProductId:this.productId,DeviceName:this.deviceName})];case 2:return e=o.sent(),t={},Object.keys(e).forEach((function(r){t[r]=e[r].Value})),r=utils.convertPropertiesChangeToTlv(t,this.dataTemplate),n=r.tlvData,s=r.tmpData,this.reporter.info(constants.GET_STATUS,{properties:t,tlvData:utils.formatArrayToReportString(n),tmpData:s}),this.protocol.reportGetStatusResult(0,n,s),[3,4];case 3:return i=o.sent(),this.reporter.error(constants.GET_STATUS_ERROR,{error:i}),this.protocol.reportGetStatusResult(-1),[2,Promise.reject(this.normalizeError(i))];case 4:return[2]}}))}))},t.prototype.onEventReport=function(e){var t=e.data;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,r,n,s,i,o,c,a;return tslib_1.__generator(this,(function(d){switch(d.label){case 0:if(!this._enableLLEventHandle)return[2];d.label=1;case 1:d.trys.push([1,9,,10]),console.log("onEventReport check this",this),e=utils.getStrLength(t),r=utils.convertEventTlvToJsObject(t.slice(2,2+e),this.dataTemplate),n=r.eventId,s=r.params,i=r.eventIndex,o={DeviceId:this.explorerDeviceId,EventId:n,Params:JSON.stringify(s)},this.emit("eventReport",{eventIndex:i,params:s}),this.reporter.info(constants.EVENT_REPLY,tslib_1.__assign(tslib_1.__assign({},o),{eventIndex:i})),d.label=2;case 2:return d.trys.push([2,7,,8]),[4,this.models.reportDeviceEvent(o)];case 3:return d.sent(),console.log("reportDeviceEvent success"),t.length-2>e?(console.log("have more event data to report",t.length,e),[4,this.onEventReport({data:t.slice(e+2+1)})]):[3,5];case 4:return d.sent(),[3,6];case 5:this.protocol.reportEventReportResult(0,i),d.label=6;case 6:return[3,8];case 7:throw c=d.sent(),console.error({error:c,eventIndex:i}),this.protocol.reportEventReportResult(-1,i),c;case 8:return[3,10];case 9:return a=d.sent(),this.reporter.error(constants.EVENT_REPLY_ERROR,{error:a}),[2,Promise.reject(this.normalizeError(a))];case 10:return[2]}}))}))},t.prototype.bindDevice=function(e){var t=e.familyId,r=e.roomId,n=e.secureBindInfo;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,s,i,o,c,a,d,l,_,u,p,v,h,E,I,f,D;return tslib_1.__generator(this,(function(R){switch(R.label){case 0:e=this.extendInfo,s=e.isDynamicRegister,i=e.isEncrypted,libs_1.log("bindDevice isEncrypted:",{isEncrypted:i,isDynamicRegister:s}),this.isEncrypted=i,this.authorized=!1,R.label=1;case 1:return R.trys.push([1,6,,7]),i?[4,this.bindDeviceEncrypted({isDynamicRegister:s,secureBindInfo:n})]:[3,3];case 2:return f=R.sent(),o=f.sign,c=f.timestamp,a=f.nonce,d=f.deviceName,l=f.secretKey,[3,5];case 3:return[4,this.protocol.requestBindDevice({needUserCheck:this.needUserCheck,isDynamicRegister:s})];case 4:D=R.sent(),o=D.sign,c=D.timestamp,a=D.nonce,d=D.deviceName,R.label=5;case 5:return this.extendInfo.isDynamicRegister=!1,[3,7];case 6:return _=R.sent(),libs_1.log("get bind sign failed, isEncrypted:",i,_),!i&&this.protocol.reportBindError(_.code),[2,Promise.reject(this.normalizeError(_))];case 7:R.trys.push([7,16,,17]),this.reporter.info(constants.BIND_AUTH),u=Date.now(),this.deviceName=d,R.label=8;case 8:return R.trys.push([8,10,,11]),p={Signature:o,DeviceTimestamp:c,DeviceId:this.explorerDeviceId,ConnId:""+a,FamilyId:t,RoomId:r,BindType:"bluetooth_sign",SignMethod:i?"hmacsha256":"hmacsha1"},this.reporter.info(constants.BIND_AUTH_DETAIL,p),[4,this.models.addDeviceBySigInFamily(p)];case 9:return R.sent(),[3,11];case 10:return v=R.sent(),i?this.protocol.reportBindEncryptedError(l):this.protocol.reportBindError(v.code),[2,Promise.reject(this.normalizeError(v))];case 11:return i?[4,this.protocol.reportBindEncryptedSuccess(u,l)]:[3,13];case 12:return R.sent(),[3,15];case 13:return h=this,[4,this.protocol.reportBindSuccess(u)];case 14:h.localPsk=R.sent(),R.label=15;case 15:try{if(this.reporter.info(constants.BIND_AUTH_DETAIL,tslib_1.__assign({},this.extendInfo)),!this.extendInfo.macStr)return[2];E={productId:this.productId,deviceName:d,deviceInfo:{mac:this.extendInfo.macStr}},this.reporter.info(constants.BIND_AUTH_DETAIL,tslib_1.__assign({msg:"START_REPORT_DEVICE_INFO"},E)),this.models.reportDeviceInfo(E)}catch(e){}return[2,this.explorerDeviceId];case 16:return I=R.sent(),console.log(I),console.log("error in bindDevice",I),this.reporter.error(constants.BIND_AUTH_FAIL,{error:I}),[2,Promise.reject(this.normalizeError(I))];case 17:return[2]}}))}))},t.prototype.bindDeviceEncrypted=function(e){var t=e.isDynamicRegister,r=void 0!==t&&t,n=e.secureBindInfo;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,t,s,i,o,c,a,d,l,_,u,p,v,h;return tslib_1.__generator(this,(function(E){switch(E.label){case 0:return E.trys.push([0,11,,12]),n?[4,this.protocol.checkSecureBindInfo(n)]:[3,2];case 1:E.sent(),E.label=2;case 2:return e=void 0,t=void 0,r?[4,this.getDeviceNameWithRegister()]:[3,4];case 3:return v=E.sent(),e=v.deviceName,t=v.nonce,[3,6];case 4:return[4,this.getDeviceNameEncrypted()];case 5:h=E.sent(),e=h.deviceName,t=h.nonce,E.label=6;case 6:return this.deviceName=e,[4,this.models.getDeviceSignAgitated({DeviceId:this.productId+"/"+e,Content:t})];case 7:return s=E.sent(),libs_1.log("get device sign response: ",s),i=s.AgitatedSignature,o=s.Timestamp,c=s.AgitatedContent,[4,this.requestBindEncrypted(i,o)];case 8:return a=E.sent(),d=a.deviceSign,l=a.R2,[4,this.verifyDeviceSign(c,l,d)];case 9:return _=E.sent(),libs_1.log("ks:",_),[4,this.notifyBindDevice(_)];case 10:return u=E.sent(),this.secretKey=_,libs_1.log("get notifyRes:",u),[2,{sign:u.sign,timestamp:Number(o),nonce:libs_1.hex2Base64(t),secretKey:_,deviceName:e}];case 11:return p=E.sent(),console.warn("bind device encrypted failed",p),[2,Promise.reject(p)];case 12:return[2]}}))}))},t.prototype.requestBindEncrypted=function(e,t){return tslib_1.__awaiter(this,void 0,void 0,(function(){var r,n,s,i,o,c,a,d,l,_=this;return tslib_1.__generator(this,(function(u){switch(u.label){case 0:return r=constants.DEVICE_INFO_WRITE_PREFIX,n=constants.REQUEST_BIND,s=r[n],i=Number(t).toString(16),o=libs_1.base64toHEX(e),c=libs_1.randomBytesHex(16),a=""+s+c+i+o,libs_1.log("REQUEST_BIND_PAYLOAD: ",s+"/"+c+"/"+i+"/"+o),[4,this.sendBleData(a,n).then((function(e){var t=parseInt(e.slice(2,3).join(""),16);if(1===t)throw{code:constants.REQUEST_BIND_FAILED};var r=e.slice(3,19).join("").toLowerCase(),n=parseInt(e.slice(19,23).join(""),16).toString(),s=e.slice(23).join("").toLowerCase(),i="/".charCodeAt(0).toString(16),o=""+r+i+libs_1.str2hexStr(n)+i;return libs_1.log("bind request response",{nonce:r,timestamp:n,sign:s,R2:o}),_.reporter.info(constants.REQUEST_BIND_SUCCESS,{nonce:r,timestamp:n,sign:s,R2:o}),{ack:t,timestamp:n,R2:o,deviceSign:s}}))];case 1:return d=u.sent(),l=d.deviceSign,libs_1.log("verify sign succeed",l),[2,d]}}))}))},t.prototype.verifyDeviceSign=function(e,t,r){return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(n){switch(n.label){case 0:return[4,this.models.getDeviceSecret({DeviceId:this.productId+"/"+this.deviceName,AppNonce:e,DeviceNonce:t,DeviceNonceSign:r})];case 1:return[2,n.sent()]}}))}))},t.prototype.getDeviceNameWithRegister=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,t,r,n,s,i,o,c,a=this;return tslib_1.__generator(this,(function(d){switch(d.label){case 0:return e=constants.DEVICE_INFO_WRITE_PREFIX[constants.GET_DEVICE_NAME],t=Math.floor(Date.now()/1e3),r=parseInt(utils.gen4BytesIntHex(),16),n=""+e+r.toString(16)+t.toString(16),[4,this.sendBleData(n,constants.GET_DEVICE_NAME_WITH_REGISTER).then((function(e){var t=parseInt(e[2],16);if(1===t)throw libs_1.log("get register data failed",{ack:t,data:e}),{code:constants.GET_DEVICE_NAME_WITH_REGISTER_FAILED};var r=parseInt(e.slice(3,4).join(""),16),n=libs_1.hex2str(e.slice(4,4+r)),s=libs_1.hex2str(e.slice(4+r));return libs_1.log("register data",{bleData:e,sign:s,deviceName:n}),{deviceName:n,sign:s}}))];case 1:return s=d.sent(),i=s.deviceName,o=s.sign,[4,this.models.dynamicRegisterDevice({deviceName:i,sign:o,productId:this.productId,timestamp:t,nonce:r})];case 2:return c=d.sent().payload,libs_1.log("dynamic register payload",c),[4,this.sendBleData(""+constants.DEVICE_INFO_WRITE_PREFIX[constants.GET_DEVICE_NAME_WITH_REGISTER]+libs_1.str2hexStr(c),constants.GET_DEVICE_NAME).then((function(e){var t=parseInt(e[2],16);if(1===t)throw a.reporter.error(constants.REGISTER_DEVICE_INFO_REPLY_INVALID,{ack:t,data:e}),{code:constants.REGISTER_DEVICE_INFO_REPLY_INVALID};var r=e.slice(3,19).join(""),n=libs_1.hex2str(e.slice(19));return libs_1.log("dyna register res",{deviceName:n,sign:r}),{deviceName:n,nonce:r}}))];case 3:return[2,d.sent()]}}))}))},t.prototype.getDeviceNameEncrypted=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,t,r=this;return tslib_1.__generator(this,(function(n){switch(n.label){case 0:return e=constants.DEVICE_INFO_WRITE_PREFIX[constants.GET_DEVICE_NAME],[4,this.writeAndWait4Response([e],[constants.GET_DEVICE_NAME,constants.CHECK_SECURE_BIND_INFO_REPLY],(function(e,t){var n=t.type;if(!e.length)throw{code:constants.REGISTER_DEVICE_INFO_REPLY_INVALID};if(n===constants.CHECK_SECURE_BIND_INFO_REPLY)throw{code:constants.CHECK_SECURE_BIND_INFO_REQUIRED};var s=libs_1.getStrLength(e),i=parseInt(e.slice(2,3).join(""),16),o=e.slice(3,19).join(""),c=libs_1.hex2str(e.slice(19));return r.reporter.info(constants.GET_DEVICE_NAME,{allLength:s,nonce:o,ack:i,deviceName:c}),{nonce:o,deviceName:c}}),WRITE_TO_DEVICE_CONF)];case 1:return t=n.sent(),libs_1.log("getDeviceName res",t),[2,t]}}))}))},t.prototype.encrypt=function(e,t,r){void 0===r&&(r={}),libs_1.log("start to encrypt data",e);var n=this.appDevSdk.utils.CryptoJS,s=function(e){"hex"===r.contentType&&(e=n.enc.Hex.parse(e));var s=n.AES.encrypt(e,n.enc.Hex.parse(t),{mode:n.mode.ECB,padding:n.pad.Pkcs7});return libs_1.base64toHEX(s.toString())};return"string"==typeof e?s(e):e.map(s)},t.prototype.notifyBindDevice=function(e){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,r,n=this;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:return t=constants.DEVICE_INFO_WRITE_PREFIX[constants.NOTIFY_BIND],"BindRequest",r=this.encrypt("BindRequest",e),[4,this.sendBleData(""+t+r,constants.NOTIFY_BIND).then((function(t){var r=parseInt(t.slice(2,3).join(""),16);if(1===r){var s={code:constants.NOTIFY_BIND_FAILED};throw n.reporter.error(constants.NOTIFY_BIND_FAILED,{ack:r,error:s,res:t}),s}var i=t.slice(3).join(""),o=utils.decrypt(i,e);return libs_1.log("bind decrypted sign:",o),n.reporter.info(constants.NOTIFY_BIND_SUCCESS,{ack:r,sign:o}),{ack:r,sign:o}}))];case 1:return[2,s.sent()]}}))}))},t.prototype.unbindDevice=function(e){var t=e.familyId,r=e.deviceName;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,n,s,i,o;return tslib_1.__generator(this,(function(c){switch(c.label){case 0:e=Date.now(),c.label=1;case 1:return c.trys.push([1,9,,10]),this.isEncrypted?[4,this.unbindDeviceEncrypted()]:[3,3];case 2:return c.sent(),[3,6];case 3:if(!r)throw{code:constants.DEVICE_NAME_IS_EMPTY};return[4,this.getDevicePsk(r)];case 4:return n=c.sent(),this.reporter.info(constants.UNBIND_AUTH,{localPsk:n}),[4,this.protocol.getUnbindAuthSign()];case 5:if(s=c.sent().sign,i=utils.encrypt(constants.UNBIND_RESPONSE,n),s!==i)throw{code:constants.UNBIND_REPLY_ERROR};this.localPsk=n,this.deviceName=r,c.label=6;case 6:return[4,this.models.deleteDeviceFromFamily({FamilyId:t,DeviceId:this.explorerDeviceId})];case 7:return c.sent(),this.reporter.info(constants.UNBIND_RESULT_AUTH_SUCCESS,{timeCost:Date.now()-e}),[4,this.protocol.reportUnbindResult("success")];case 8:return c.sent(),this.stopListenLLEvents(),this.authorized=!1,this.disconnectDevice(),[3,10];case 9:return o=c.sent(),this.protocol.reportUnbindResult("fail"),this.reporter.error(constants.UNBIND_RESULT_AUTH_FAIL,{error:o}),[2,Promise.reject(this.normalizeError(o))];case 10:return[2]}}))}))},t.prototype.unbindDeviceEncrypted=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,t,r=this;return tslib_1.__generator(this,(function(n){switch(n.label){case 0:return e=constants.DEVICE_INFO_WRITE_PREFIX[constants.UNBIND_REQUEST],"UnbindRequest",t=this.encrypt("UnbindRequest",this.sessionKey),[4,this.sendBleData(""+e+t,constants.UNBIND_REQUEST).then((function(e){if(libs_1.log("unbind res encrypted data",e),1===parseInt(e[2],16))throw{code:constants.UNBIND_REPLY_INVALID};var t=utils.decrypt(e.slice(3).join(""),r.sessionKey);if(libs_1.log("unbind payload",libs_1.hex2str(t)),"UnbindResponse"===libs_1.hex2str(t))return!0;throw{code:constants.UNBIND_REPLY_ERROR}}))];case 1:return[2,n.sent()]}}))}))},t.prototype.controlDevice=function(e){var t=e.deviceData;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e;return tslib_1.__generator(this,(function(r){switch(r.label){case 0:return r.trys.push([0,3,,4]),console.log("controlDevice check this",this),this.reporter.info(constants.CONTROL_DEVICE,{deviceData:t}),[4,this.protocol.controlDeviceProperty(t)];case 1:return r.sent(),this.emit("controlPropertySuccess",{deviceData:t}),[4,this.models.reportBlueToothDeviceData({ProductId:this.productId,DeviceName:this.deviceName,Data:t,DataTimeStamp:Date.now()})];case 2:return r.sent(),[3,4];case 3:return e=r.sent(),this.reporter.error(constants.CONTROL_DEVICE_REPLY_ERROR,{error:e}),[2,Promise.reject(this.normalizeError(e))];case 4:return[2]}}))}))},t.prototype.controlAction=function(e){var t=e.actionData;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,r,n,s,i,o;return tslib_1.__generator(this,(function(c){switch(c.label){case 0:return c.trys.push([0,4,,5]),console.log("controlAction check this",this),[4,this.protocol.controlDeviceAction(t)];case 1:return e=c.sent().output,[4,utils.convertActionOutputTlvToJsObject(e,this.dataTemplate)];case 2:return r=c.sent(),n=r.outputParams,s=r.actionIndex,i=r.actionId,[4,this.models.publishDeviceActionMessage({deviceName:this.deviceName,productId:this.productId,actionId:i,clientToken:t.clientToken,output:n})];case 3:return c.sent(),this.reporter.info(constants.CONTROL_ACTION_SUCCESS,{outputParams:n,actionIndex:s,actionId:i}),[3,5];case 4:return o=c.sent(),this.reporter.error(constants.CONTROL_ACTION_ERROR,{error:o}),[2,Promise.reject(this.normalizeError(o))];case 5:return[2]}}))}))},t.prototype.authenticateConnection=function(e){var t=(void 0===e?{}:e).deviceName;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,r,n,s,i,o,c,a,d,l,_,u,p,v,h;return tslib_1.__generator(this,(function(E){switch(E.label){case 0:if(E.trys.push([0,18,,19]),console.log("start authenticate connection",t),!t)throw{code:constants.DEVICE_NAME_IS_EMPTY};return[4,this.models.getDeviceConfig({DeviceId:this.productId+"/"+t,DeviceKey:LLSyncProtocol_1.LLSyncConfig.Secret_Encrypt_Key})];case 1:return e=E.sent(),envDetect.isIOS&&this.extendInfo.moduleVersion>=2?[4,this.protocol.notifyAppOnIOSDevice()]:[3,4];case 2:return E.sent(),[4,delay(100)];case 3:E.sent(),E.label=4;case 4:if(r=void 0,n=void 0,s=void 0,i=void 0,o=Date.now(),!e)return[3,9];this.isEncrypted=!0,this.authorized=!1,this.secretKey=e,E.label=5;case 5:return E.trys.push([5,7,,8]),[4,this.authConnectionEncrypted({deviceName:t})];case 6:return v=E.sent(),r=v.version,n=v.mtu,s=v.needSetMtu,i=v.otaVersion,[3,8];case 7:return c=E.sent(),libs_1.log("auth connection encrypted faild",c),[2,Promise.reject(c)];case 8:return[3,13];case 9:return[4,this.getDevicePsk(t)];case 10:return a=E.sent(),this.localPsk=a,this.reporter.info(constants.CONNECT_AUTH,{localPsk:a}),[4,this.protocol.getDeviceAuthInfo()];case 11:if(d=E.sent(),l=d.sign,_=d.timestamp,u=utils.encrypt(""+(_+60)+this.productId+t,a),l!==u)throw{code:constants.CONNECT_SIGN_AUTH_ERROR};return[4,this.protocol.getDeviceInfo()];case 12:h=E.sent(),r=h.version,n=h.mtu,s=h.needSetMtu,i=h.otaVersion,E.label=13;case 13:if(this.deviceName=t,this.bleVersion=r,this.mtu=Math.max(constants.MIN_ATT_MTU,n)-constants.ATT_MTU_TO_LLSYNC_MTU_DELTA,!s)return[3,17];E.label=14;case 14:return E.trys.push([14,16,,17]),[4,this.setMtu(n)];case 15:return E.sent(),this.writeMtuResult("success"),[3,17];case 16:return E.sent(),this.writeMtuResult("fail"),[3,17];case 17:return this.otaVersion=i,i&&this.models.reportOTAVersion({Version:i,DeviceId:this.explorerDeviceId}),this.reporter.info(constants.CONNECT_RESULT_WRITE_SUCCESS,{timeCost:Date.now()-o,version:r,mtu:n,otaVersion:i}),this.authorized=!0,this.emit("authorized",{version:r,mtu:n,otaVersion:i}),this.stopListenLLEvents(),this.startListenLLEvents(),this.extendInfo.moduleVersion>=2&&this.protocol.notifyAppReady(),[3,19];case 18:return p=E.sent(),this.protocol.reportConnectError(),this.reporter.error(constants.CONNECT_RESULT_WRITE_FAIL,{error:p}),[2,Promise.reject(this.normalizeError(p))];case 19:return[2]}}))}))},t.prototype.authConnectionEncrypted=function(e){var t=e.deviceName;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,r,n,s,i,o,c,a,d,l,_,u=this;return tslib_1.__generator(this,(function(p){switch(p.label){case 0:return e=constants.DEVICE_INFO_WRITE_PREFIX,r=constants.CONNECT_REQUEST,n=constants.CONNECT_ACK,s=""+e[r]+this.encrypt("ConnectRequest",this.secretKey),[4,this.sendBleData(s,r).then((function(e){libs_1.log("connect res",e);var t=parseInt(e[2],16),r=e.slice(3,19).join(""),n=e.slice(19).join("");if(1===t)throw{code:constants.CONNECT_SIGN_AUTH_ERROR};return{ack:t,R3:r,sign:n}}))];case 1:return i=p.sent(),o=i.R3,c=i.sign,[4,this.models.getDeviceSign({DeviceId:this.productId+"/"+(t||this.deviceName),Content:""+o+";".charCodeAt(0).toString(16)+this.secretKey,ContentType:"hex"})];case 2:if(a=p.sent(),libs_1.log("get sessionKey",a),d=this.encrypt(o,a,{contentType:"hex"}),libs_1.log("verify sign:",d,c),d.toLowerCase()!==c.toLowerCase())throw{code:constants.CONNECT_SIGN_VERIFY_ERROR};return this.sessionKey=a,l=""+e[n]+this.encrypt("ConnectResult",this.sessionKey),[4,this.sendBleData(l,n).then((function(e){if(1===parseInt(e[2],16))throw{code:constants.CONNECT_SIGN_VERIFY_ERROR};var t=e.slice(3,19).join(""),r=utils.decrypt(t,u.sessionKey);libs_1.log("decrypted data",r,t);var n=u.appDevSdk.utils.byteUtil.hexString2hexArray(r),s=parseInt(n[0],16),i=parseInt(n.slice(1,3).join(""),16),o=n.slice(4).join("");return{version:s,mtu:8191&i,needSetMtu:!!(i>>15),otaVersion:o?libs_1.hex2str(o):o}}))];case 3:return _=p.sent(),libs_1.log("connect ack res",_),[2,_]}}))}))},t.prototype.getAdvertisingData=function(){var e,t;return tslib_1.__awaiter(this,void 0,void 0,(function(){var r;return tslib_1.__generator(this,(function(n){if(!(r=null===(e=this.extendInfo)||void 0===e?void 0:e.moduleVersion)||r<3)throw{code:"MODULE_VERSION_NOT_SUPPORT_GET_ADV_DATA",msg:"LLSync 版本 "+r+" 不支持 getAdvertisingData"};if((null===(t=this.extendInfo)||void 0===t?void 0:t.isEncrypted)&&this.authorized)throw{code:"GET_ADV_DATA_NOT_SUPPORTED_IN_CURRENT_STATE",msg:"LLSync 加密协议连接鉴权完成后暂不支持获取广播信息"};return[2,this.protocol.getAdvertisingData()]}))}))},t.prototype.sendHeartbeat=function(){var e;return tslib_1.__awaiter(this,void 0,void 0,(function(){var t;return tslib_1.__generator(this,(function(r){return!(t=null===(e=this.extendInfo)||void 0===e?void 0:e.moduleVersion)||t<3?(console.warn("LLSyncDeviceAdapter.sendHeartbeat noop: moduleVersion "+t+" not support heartbeat"),[2]):[2,this.protocol.sendHeartbeat()]}))}))},t.prototype.notifyLocalRssi=function(e){var t=e.rssi;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e;return tslib_1.__generator(this,(function(r){return(e=Math.round(t))<-255&&(e=-255),e>0&&(e=0),[2,this.protocol.notifyLocalRssi({rssi:e})]}))}))},t.prototype.sendBleData=function(e,t){return tslib_1.__awaiter(this,void 0,void 0,(function(){var r;return tslib_1.__generator(this,(function(n){return r=this.protocol._parseDataBeforeConnect(e,t),[2,this.writeAndWait4Response(r,t,(function(e){return e}),WRITE_TO_DEVICE_CONF)]}))}))},t.prototype.toString=function(){return"[LLSyncDeviceAdapter]"},t.serviceId16="0000FFE0-0000-1000-8000-00805F9B34FB",t.serviceId="0000FFE0-65D0-4E20-B56A-E493541BA4E2",t.deviceFilter=function(e,r){if(!e.advertisServiceUUIDs||!e.advertisServiceUUIDs.find((function(e){return e===t.serviceId16}))||!e.advertisData)return null;var n=t.options.appDevSdk.reporter;try{var s=Math.floor(10*Math.random())%10==1||!0,i=arrayBufferToHexStringArray(e.advertisData);s&&n.info(constants_1.REPORT_EVENT_TYPE,{message:"收到广播",serviceId:t.serviceId,hexArr:i.join(",")});var o=parseInt(i[2],16),c=o-(o>>2<<2),a=o>>4,d=o>>2&1,l=o>>3&1;libs_1.log("BLE_STATE =>",o.toString(2));var _=r.productId&&r.deviceName?r.productId+"/"+r.deviceName:"",u=_?utils.get8ByteFromStr(""+_.replace("/","")):"",p=!!_,v="",h="",E="",I=constants.DEVICE_STATE_MAP[c],f=[constants.DEVICE_HAS_BINDED,constants.DEVICE_HAS_CONNECTED].indexOf(I)>-1;if(f)E=i.slice(3,11).join("").toLocaleLowerCase(),h=i.slice(11).join("").toLocaleLowerCase(),v=r.productId;else{var D=i.slice(3,9);e.name&&-1===e.name.indexOf("_")&&(e.name=e.name+"_"+D.slice(0,2).join("")),v=libs_1.hex2str(i.slice(9))}s&&n.info(constants_1.REPORT_EVENT_TYPE,{message:"解析广播",serviceId:t.serviceId,data:{bindState:I||"x",targetDeviceId:_,targetDeviceIdentify:u,deviceUserIdentify:h||"x",deviceProductId:v||"x",deviceIdentify:E||"x",isDynamicRegister:!!d,isEncrypted:!!l,macStr:f?"":i.slice(3,9).join(":")}});var R=function(){var n=tslib_1.__assign(tslib_1.__assign({},e),{serviceId:t.serviceId,deviceName:r.deviceName||"",productId:v,extendInfo:{bindState:constants.DEVICE_STATE_MAP[I],moduleVersion:a,isDynamicRegister:!!d,isEncrypted:!!l,standard:!0,macStr:f?"":i.slice(3,9).join(":")}});return console.log("---设备匹配成功---",n),n};return p&&f&&E===u?R():p||f?null:R()}catch(e){console.error("llsync device filter error",e),n.error(constants_1.REPORT_EVENT_TYPE,{message:"协议广播出错",error:e})}},t}(LLSyncDeviceAdapterBase_1.LLSyncDeviceAdapterBase);exports.LLSyncDeviceAdapter=LLSyncDeviceAdapter,exports.StandardDeviceAdapter=LLSyncDeviceAdapter; | ||
//# sourceMappingURL=LLSyncDeviceAdapter.js.map |
@@ -138,2 +138,10 @@ import { LLSyncDeviceAdapter } from './LLSyncDeviceAdapter'; | ||
getAdvertisingData(): Promise<AdvertisingData>; | ||
checkSecureBindInfo(reqData: { | ||
/** 产品 ID /^[A-Z0-9]{10}$/ */ | ||
productId: string; | ||
/** MAC 地址(不含冒号) /^[a-fA-F0-9]{12}$/ */ | ||
mac: string; | ||
/** 签名(十六进制,原文长度为16字节) /^[a-fA-F0-9]{32}$/ */ | ||
sign: string; | ||
}): Promise<void>; | ||
/** | ||
@@ -140,0 +148,0 @@ * Helpers |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.isHeartbeatResp=exports.LLSyncProtocol=exports.LLSyncConfig=exports.BindState=void 0;var BindState,tslib_1=require("tslib"),constants=tslib_1.__importStar(require("../../constants")),qcloud_iotexplorer_appdev_sdk_1=require("qcloud-iotexplorer-appdev-sdk"),libs_1=require("../../libs"),_a=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils,noop=_a.noop,genPromise=_a.genPromise,byteUtil=_a.byteUtil;!function(t){t[t.NOT_BOUND=0]="NOT_BOUND",t[t.WAITING_BIND=1]="WAITING_BIND",t[t.HAS_BOUND=2]="HAS_BOUND",t[t.CONNECTED=3]="CONNECTED"}(BindState=exports.BindState||(exports.BindState={})),exports.LLSyncConfig={BLE_PSK_DEVICE_KEY:"ble_psk_device_ket",Secret_Encrypt_Key:"secret_encrypt_key",waitConnectReplyTime:1e4,waitBindReplyTime:1e4,waitGetRegisterDeviceInfo:1e4,waitGetCheckTimeoutReplyTime:1e4,waitGetCheckTimeoutDefaultReplyTime:6e4,waitControlReplyTime:1e4,waitGetDeviceInfoTime:1e4,waitUpdateReplyInt:1e4,waitGetAdvDataReplyTime:1e4,mtuDefaultMap:{0:void 0,1:20,2:20}};var LLSyncProtocol=function(){function t(t){this._cleanupUserCheckHandleAfterCancel=noop,this.deviceAdapter=t,this._parseDataBeforeConnect=this._parseDataBeforeConnect.bind(this)}return Object.defineProperty(t.prototype,"reporter",{get:function(){return this.deviceAdapter.reporter},enumerable:!1,configurable:!0}),t.prototype.requestBindDevice=function(t){var e=t.needUserCheck,n=void 0!==e&&e,i=t.isDynamicRegister,s=void 0!==i&&i;return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,e,i,o,r,a=this;return tslib_1.__generator(this,(function(c){switch(c.label){case 0:return t=Math.floor(Date.now()/1e3),e=parseInt(libs_1.gen4BytesIntHex(),16),i=this._parseDataBeforeConnect(""+constants.DEVICE_INFO_WRITE_PREFIX[constants.TIME_SYNC]+e.toString(16)+t.toString(16),constants.TIME_SYNC),this.reporter.info(constants.TIME_SYNC,{timestamp:t,nonce:e,bindDeviceData:i,needUserCheck:n,isDynamicRegister:s}),s?[4,this.registerDevice({timestamp:t,bindDeviceData:i,nonce:e})]:[3,2];case 1:o=c.sent(),i=o.bleData,t=o.timestamp,c.label=2;case 2:return r={bindDeviceData:i,dataHandler:function(i){if(!i.length)throw{code:constants.CONNECT_REPLY_INVALID};if(n){var s=!(libs_1.getStrLength(i)>>15);if(console.log("bind auth response userCheckResult",s),!s)throw{code:constants.GET_USER_CHECK_REJECT}}var o=i.slice(2,22).join(""),r=libs_1.hex2str(i.slice(22)),c={sign:o.toLocaleLowerCase(),deviceName:r,nonce:e,timestamp:t+60};return a.reporter.info(constants.TIME_SYNC,c),c}},this.reporter.info(constants.TIME_SYNC,r),[2,n?this.waitUserCheckAndBindDevice(r):this.bindDeviceDirectly(r)]}}))}))},t.prototype.registerDevice=function(t){var e=t.timestamp,n=t.nonce,i=t.bindDeviceData;return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,s,o,r,a,c,_,E,I=this;return tslib_1.__generator(this,(function(d){switch(d.label){case 0:return[4,this.deviceAdapter.writeAndWait4Response(i,constants.REGISTER_DEVICE_INFO_REPLY,(function(t){if(!t.length)throw{code:constants.REGISTER_DEVICE_INFO_REPLY_INVALID};var e=libs_1.getStrLength(t),n=parseInt(t.slice(2,3).join(""),16),i=libs_1.hex2str(t.slice(3,3+n)),s=libs_1.hex2str(t.slice(3+n,3+e));return I.reporter.info(constants.REGISTER_DEVICE_INFO_REPLY,{allLength:e,deviceNameLength:n,deviceName:i,sign:s}),{sign:s,deviceName:i}}),{timeout:exports.LLSyncConfig.waitGetRegisterDeviceInfo,timeoutCode:constants.WAIT_REGISTER_DEVICE_INFO_REPLY_TIMEOUT,writeId:constants.DEVICE_INFO_WRITE_ID})];case 1:t=d.sent(),s=t.deviceName,o=t.sign,this.reporter.info(constants.TIME_SYNC,{deviceName:s,sign:o}),r=0,d.label=2;case 2:return d.trys.push([2,4,,5]),[4,this.deviceAdapter.models.dynamicRegisterDevice({deviceName:s,sign:o,productId:this.deviceAdapter.productId,timestamp:e,nonce:n})];case 3:return a=d.sent().payload,c=Math.floor(Date.now()/1e3),r=1,_=this._parseDataBeforeConnect(constants.DEVICE_INFO_WRITE_PREFIX[constants.SEND_REGISTER_DEVICE_PAYLOAD]+""+libs_1.U8ToHexString(r)+libs_1.U8ToHexString(a.length)+libs_1.str2hexStr(a)+n.toString(16)+c.toString(16),constants.SEND_REGISTER_DEVICE_PAYLOAD),this.reporter.info(constants.REGISTER_DEVICE_SUCCESS,{payload:a,bleData:_}),[2,{bleData:_,timestamp:c}];case 4:throw E=d.sent(),tslib_1.__assign(tslib_1.__assign({},E),{code:constants.REGISTER_DEVICE_ERROR});case 5:return[2]}}))}))},t.prototype.bindDeviceDirectly=function(t){var e=t.bindDeviceData,n=t.dataHandler;return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(t){return[2,this.deviceAdapter.writeAndWait4Response(e,constants.BIND_AUTH,n,{timeout:exports.LLSyncConfig.waitBindReplyTime,timeoutCode:constants.WAIT_CONNECT_REPLY_TIMEOUT,writeId:constants.DEVICE_INFO_WRITE_ID})]}))}))},t.prototype.waitUserCheckAndBindDevice=function(t){var e=t.bindDeviceData,n=t.dataHandler;return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,i,s,o=this;return tslib_1.__generator(this,(function(r){switch(r.label){case 0:return t=genPromise(),s=function(e){clearTimeout(i),console.log("registerUserCheckTimer",e),i=setTimeout((function(){console.log("user check timeout",e),o.cancelUserCheck("timeout"),t.reject({code:constants.WAIT_USER_CHECK_TIMEOUT})}),e)},this.deviceAdapter.wait4EventResponse(constants.USER_CHECK_TIMEOUT_CALLBACK,(function(t){if(!t.length)return console.log("get user check timeout duration fail, trigger default timeout timer"),o.reporter.info(constants.GET_USER_CHECK_TIMEOUT_ERROR),s(exports.LLSyncConfig.waitGetCheckTimeoutDefaultReplyTime);var e=1e3*parseInt(t.slice(2).join(""),16);o.reporter.info(constants.GET_USER_CHECK_TIMEOUT_SUCCESS,{timeoutDuration:e}),s(e)}),{timeout:exports.LLSyncConfig.waitGetCheckTimeoutReplyTime,timeoutHandler:function(){o.reporter.info(constants.GET_USER_CHECK_TIMEOUT_TIMEOUT),s(exports.LLSyncConfig.waitGetCheckTimeoutDefaultReplyTime-exports.LLSyncConfig.waitGetCheckTimeoutReplyTime)}}),this._cleanupUserCheckHandleAfterCancel=function(){console.log("process cleanup user check handler"),t.reject(null),o.deviceAdapter.off(constants.BIND_AUTH),o._cleanupUserCheckHandleAfterCancel=noop},[4,Promise.race([t.promise,this.deviceAdapter.writeAndWait4Response(e,constants.BIND_AUTH,n,{timeout:exports.LLSyncConfig.waitGetCheckTimeoutDefaultReplyTime+exports.LLSyncConfig.waitGetCheckTimeoutReplyTime,timeoutCode:constants.WAIT_CONNECT_REPLY_TIMEOUT,writeId:constants.DEVICE_INFO_WRITE_ID})])];case 1:return[2,r.sent()]}}))}))},t.prototype.cancelUserCheck=function(t){void 0===t&&(t="timeout"),console.log("cancel user check, reason: ",t),"cancel"===t&&this._cleanupUserCheckHandleAfterCancel();var e=""+constants.DEVICE_INFO_WRITE_PREFIX[constants.USER_CHECK_TIMEOUT]+libs_1.U8ToHexString("timeout"===t?constants.WRITE_USER_CHECK_TIMEOUT:constants.WRITE_USER_CHECK_CANCEL);this.deviceAdapter.write(e,{writeId:constants.DEVICE_INFO_WRITE_ID})},t.prototype.getDeviceAuthInfo=function(){var t=Math.floor(Date.now()/1e3),e=this._parseDataBeforeConnect(""+constants.DEVICE_INFO_WRITE_PREFIX[constants.CONNECT_AUTH]+t.toString(16)+libs_1.encrypt(t,this.deviceAdapter.localPsk),constants.CONNECT_AUTH);return console.log("[LLsyncProtocol] auth data:",{data:e,moduleVersion:this.deviceAdapter.extendInfo.moduleVersion,localPsk:this.deviceAdapter.localPsk,dataStr:""+constants.DEVICE_INFO_WRITE_PREFIX[constants.CONNECT_AUTH]+t.toString(16)+libs_1.encrypt(t,this.deviceAdapter.localPsk)}),this.deviceAdapter.writeAndWait4Response(e,constants.CONNECT_AUTH,(function(e){if(!e.length)throw{code:constants.CONNECT_REPLY_INVALID};return{sign:e.slice(2,22).join("").toLocaleLowerCase(),timestamp:t}}),{timeout:exports.LLSyncConfig.waitConnectReplyTime,timeoutCode:constants.WAIT_CONNECT_REPLY_TIMEOUT,writeId:constants.DEVICE_INFO_WRITE_ID})},t.prototype.getDeviceInfo=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(t){return[2,this.deviceAdapter.writeAndWait4Response(constants.DEVICE_INFO_WRITE_PREFIX[constants.CONNECT_RESULT_WRITE_SUCCESS],constants.DEVICE_INFO,(function(t){if(!t.length)throw{code:constants.DEVICE_INFO_INVALID};var e=parseInt(t.slice(2,3).join(""),16),n=parseInt(t.slice(3,5).join(""),16),i=!!(n>>15),s=8191&n,o=t.slice(6).join("");return{version:e,mtu:s,needSetMtu:i,otaVersion:o?libs_1.hex2str(o):o}}),{timeout:exports.LLSyncConfig.waitGetDeviceInfoTime,timeoutCode:constants.WAIT_GET_DEVICE_INFO_TIMEOUT,writeId:constants.DEVICE_INFO_WRITE_ID})]}))}))},t.prototype.getUnbindAuthSign=function(){var t=this._parseDataBeforeConnect(""+constants.DEVICE_INFO_WRITE_PREFIX[constants.UNBIND_AUTH]+libs_1.encrypt(constants.UNBIND_REQUEST,this.deviceAdapter.localPsk),constants.UNBIND_AUTH);return this.deviceAdapter.writeAndWait4Response(t,constants.UNBIND_AUTH,(function(t){if(!t.length)throw{code:constants.UNBIND_REPLY_INVALID};return{sign:t.slice(2,22).join("").toLocaleLowerCase()}}),{timeout:exports.LLSyncConfig.waitConnectReplyTime,timeoutCode:constants.WAIT_UNBIND_REPLY_TIMEOUT,writeId:constants.DEVICE_INFO_WRITE_ID})},t.prototype.controlDeviceAction=function(t){var e=libs_1.convertActionControlToTlv(t,this.deviceAdapter.dataTemplate),n=e.actionIndex,i=e.tlvData,s=e.tmpData,o=this.deviceAdapter.sliceData(tslib_1.__spread([libs_1.getTypeHead(constants.DEVICE_DATA_WRITE_HEAD[constants.CONTROL_ACTION],n),libs_1.U16ToHexString(i.length)],i),s,constants.CONTROL_ACTION);return this.deviceAdapter.isEncrypted&&(o=this.deviceAdapter.encrypt(o,this.deviceAdapter.sessionKey,{contentType:"hex"})),this.deviceAdapter.writeAndWait4Response(o,constants.ACTION_REPLY,(function(t){if(!t.length)throw{code:constants.CONTROL_REPLY_INVALID};var e=parseInt(t.slice(2,3).join(""),16),n=t.slice(3);if(0===e)return{success:!0,output:n};throw{code:constants.CONTROL_REPLY_CODE_INVALID,errCode:e}}),{timeout:exports.LLSyncConfig.waitControlReplyTime,timeoutCode:constants.WAIT_CONTROL_ACTION_REPLY_TIMEOUT,writeId:constants.DEVICE_DATA_WRITE_ID,wrapSplitDataMode:constants.ACTION_REPLY})},t.prototype.controlDeviceProperty=function(t){var e=libs_1.convertPropertiesChangeToTlv(t,this.deviceAdapter.dataTemplate),n=e.tlvData,i=e.tmpData,s=this.deviceAdapter.sliceData(tslib_1.__spread([libs_1.getTypeHead(constants.DEVICE_DATA_WRITE_HEAD[constants.CONTROL_DEVICE],constants.DEVICE_DATA_WRITE_SUFFIX[constants.CONTROL_DEVICE]),libs_1.U16ToHexString(n.length)],n),i,constants.CONTROL_DEVICE);return this.deviceAdapter.isEncrypted&&(s=this.deviceAdapter.encrypt(s,this.deviceAdapter.sessionKey,{contentType:"hex"})),this.deviceAdapter.writeAndWait4Response(s,constants.CONTROL_REPLY,(function(t){if(!t.length)throw{code:constants.CONTROL_REPLY_INVALID};var e=parseInt(t.slice(2).join(""),16);if(0===e)return{code:0};throw{code:constants.CONTROL_REPLY_CODE_INVALID,errCode:e}}),{timeout:exports.LLSyncConfig.waitControlReplyTime,timeoutCode:constants.WAIT_CONTROL_DEVICE_REPLY_TIMEOUT,writeId:constants.DEVICE_DATA_WRITE_ID})},t.prototype.reportBindSuccess=function(t){return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,n;return tslib_1.__generator(this,(function(i){switch(i.label){case 0:return e=libs_1.gen4BytesIntHex(),this.reporter.info(constants.BIND_AUTH_SUCCESS,{identify:this.deviceAdapter.userIdentify,localPsk:e,timeCost:Date.now()-t}),n=""+constants.DEVICE_INFO_WRITE_PREFIX[constants.BIND_AUTH_SUCCESS]+constants.DEVICE_INFO_WRITE_PREFIX[constants.BIND_AUTH_SUCCESS]+e+this.deviceAdapter.userIdentify,[4,this.deviceAdapter.writeData(this._parseDataBeforeConnect(n,constants.BIND_AUTH_SUCCESS),{writeId:constants.DEVICE_INFO_WRITE_ID})];case 1:return i.sent(),[4,this.deviceAdapter.models.setDeviceConfig({DeviceId:this.deviceAdapter.explorerDeviceId,DeviceKey:exports.LLSyncConfig.BLE_PSK_DEVICE_KEY,DeviceValue:e})];case 2:return i.sent(),[2,e]}}))}))},t.prototype.reportBindEncryptedSuccess=function(t,e){return tslib_1.__awaiter(this,void 0,void 0,(function(){var n,i;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:return this.reporter.info(constants.BIND_AUTH_SUCCESS,{identify:this.deviceAdapter.userIdentify,timeCost:Date.now()-t,secretkey:e}),n=this.deviceAdapter.encrypt("BindResult0",e),libs_1.log("bind result encrypted",n),[4,this.deviceAdapter.writeAndWait4Response(this._parseDataBeforeConnect(""+constants.DEVICE_INFO_WRITE_PREFIX[constants.RESPONSE_BIND]+n,constants.BIND_AUTH_SUCCESS),constants.RESPONSE_BIND,(function(t){return libs_1.log("result res data",t),{ack:parseInt(t[2],16),errCode:constants.BleErrorMsg[t[3]]}}),{writeId:constants.DEVICE_INFO_WRITE_ID,timeout:exports.LLSyncConfig.waitGetRegisterDeviceInfo,timeoutCode:constants.WAIT_REGISTER_DEVICE_INFO_REPLY_TIMEOUT})];case 1:if(1===(i=s.sent()).ack)throw{code:i.errCode};return[4,this.deviceAdapter.models.setDeviceConfig({DeviceId:this.deviceAdapter.explorerDeviceId,DeviceKey:exports.LLSyncConfig.Secret_Encrypt_Key,DeviceValue:e})];case 2:return s.sent(),[2,i]}}))}))},t.prototype.reportBindError=function(t){void 0===t&&(t="");var e=""+constants.DEVICE_INFO_WRITE_PREFIX[constants.BIND_AUTH_FAIL]+libs_1.str2hexStr(t);this.deviceAdapter.write(e,{writeId:constants.DEVICE_INFO_WRITE_ID})},t.prototype.reportBindEncryptedError=function(t){var e=this.deviceAdapter.encrypt("BindResult1",t);this.deviceAdapter.write(""+constants.DEVICE_INFO_WRITE_PREFIX[constants.RESPONSE_BIND]+e,{writeId:constants.DEVICE_INFO_WRITE_ID})},t.prototype.reportConnectError=function(){var t=constants.DEVICE_INFO_WRITE_PREFIX[constants.CONNECT_RESULT_WRITE_FAIL];this.deviceAdapter.write(t,{writeId:constants.DEVICE_INFO_WRITE_ID})},t.prototype.reportPropertyReportResult=function(t){void 0===t&&(t=0);var e=constants.DEVICE_DATA_WRITE_HEAD,n=constants.DEVICE_DATA_WRITE_SUFFIX,i=constants.REPORT_RESULT,s=constants.DEVICE_DATA_WRITE_ID,o=""+libs_1.getTypeHead(e[i],n[i])+byteUtil.byteToHex(byteUtil.convertNumberToByte(t));this.deviceAdapter.isEncrypted&&(o=this.deviceAdapter.encrypt(o,this.deviceAdapter.sessionKey,{contentType:"hex"})),this.deviceAdapter.writeData(o,{writeId:s})},t.prototype.reportEventReportResult=function(t,e){void 0===t&&(t=0);var n=constants.DEVICE_DATA_WRITE_HEAD,i=constants.EVENT_REPLY,s=constants.DEVICE_DATA_WRITE_ID,o=""+libs_1.getTypeHead(n[i],e)+byteUtil.byteToHex(byteUtil.convertNumberToByte(t));this.deviceAdapter.isEncrypted&&(o=this.deviceAdapter.encrypt(o,this.deviceAdapter.sessionKey,{contentType:"hex"})),this.deviceAdapter.writeData(o,{writeId:s})},t.prototype.reportGetStatusResult=function(t,e,n){void 0===t&&(t=0);var i=constants.DEVICE_DATA_WRITE_HEAD,s=constants.DEVICE_DATA_WRITE_SUFFIX,o=constants.GET_STATUS,r=constants.DEVICE_DATA_WRITE_ID,a=[""+libs_1.getTypeHead(i[o],s[o]),byteUtil.byteToHex(byteUtil.convertNumberToByte(t))];e&&(a=this.deviceAdapter.sliceData(a.concat(tslib_1.__spread([libs_1.U16ToHexString(e.length)],e)),n,constants.GET_STATUS)),this.deviceAdapter.isEncrypted&&(a=this.deviceAdapter.encrypt(a,this.deviceAdapter.sessionKey,{contentType:"hex"})),this.deviceAdapter.writeData(a,{writeId:r})},t.prototype.reportUnbindResult=function(t){if(this.deviceAdapter.isEncrypted){var e=this.deviceAdapter.encrypt("fail"===t?"UnbindFail":"UnbindOk",this.deviceAdapter.sessionKey);libs_1.log("unbind send payload",e);var n=""+constants.DEVICE_INFO_WRITE_PREFIX[constants.UNBIND_RESPONSE]+e,i=this._parseDataBeforeConnect(n,constants.UNBIND_RESPONSE);return this.deviceAdapter.writeData(i,{writeId:constants.DEVICE_INFO_WRITE_ID})}i=constants.DEVICE_INFO_WRITE_PREFIX[constants.UNBIND_RESULT_AUTH_SUCCESS];return"fail"===t&&(i=constants.DEVICE_INFO_WRITE_PREFIX[constants.UNBIND_RESULT_AUTH_FAIL]),this.deviceAdapter.write(i,{writeId:constants.DEVICE_INFO_WRITE_ID})},t.prototype.notifyAppReady=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,e,n,i;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:return t=constants.DEVICE_INFO_WRITE_PREFIX,e=constants.APP_IS_READY,n=constants.DEVICE_INFO_WRITE_ID,i=t[e],this.reporter.info(e),[4,this.deviceAdapter.writeData(i,{writeId:n})];case 1:return s.sent(),[2]}}))}))},t.prototype.notifyAppOnIOSDevice=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,e,n,i;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:return t=constants.DEVICE_INFO_WRITE_PREFIX,e=constants.APP_ON_IOS_DEVICE,n=constants.DEVICE_INFO_WRITE_ID,i=t[e],this.reporter.info(e),[4,this.deviceAdapter.writeData(i,{writeId:n})];case 1:return s.sent(),[2]}}))}))},t.prototype.notifyLocalRssi=function(t){var e=t.rssi;return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,n,i,s,o;return tslib_1.__generator(this,(function(r){switch(r.label){case 0:return!Number.isSafeInteger(e)||e<-255||e>0?[2,Promise.reject({msg:"RSSI 取值超出范围",code:"INVALID_RSSI_VALUE"})]:(t=constants.DEVICE_INFO_WRITE_PREFIX,n=constants.NOTIFY_LOCAL_RSSI,i=constants.DEVICE_INFO_WRITE_ID,s=e+255,o=[t[n],s.toString(16).padStart(2,"0")].join(""),[4,this.deviceAdapter.writeData(o,{writeId:i})]);case 1:return r.sent(),[2]}}))}))},t.prototype.sendHeartbeat=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,e,n,i;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:return t=constants.DEVICE_INFO_WRITE_PREFIX,e=constants.HEARTBEAT_REQ,n=constants.DEVICE_INFO_WRITE_ID,i=t[e],[4,this.deviceAdapter.writeData(i,{writeId:n})];case 1:return s.sent(),[2]}}))}))},t.prototype.getAdvertisingData=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t=this;return tslib_1.__generator(this,(function(e){return this.reporter.info(constants.GET_ADV_DATA,{}),[2,this.deviceAdapter.writeAndWait4Response(constants.DEVICE_INFO_WRITE_PREFIX[constants.GET_ADV_DATA],constants.GET_ADV_DATA_REPLY,(function(e){if(e.length<20)throw{code:constants.GET_ADV_DATA_REPLY_INVALID};var n=parseInt(e[2],16);if(n)throw{code:constants.GET_ADV_DATA_FAIL,ack:n};var i=parseInt(e[3],16),s=3&i,o={bindState:s,isEncrypted:!!(i>>>3&1),isDynamicRegister:!!(i>>>2&1),moduleVersion:i>>>4};if(s===BindState.CONNECTED||s===BindState.HAS_BOUND){var r=e.slice(4,12).join("").toLocaleLowerCase(),a=e.slice(12,20).join("").toLocaleLowerCase();Object.assign(o,{deviceIdentify:r,deviceUserIdentify:a})}else{var c=e.slice(4,10).join(":"),_=libs_1.hex2str(e.slice(10,20));Object.assign(o,{macAddress:c,productId:_})}return t.reporter.info(constants.GET_ADV_DATA_RESULT,o),o}),{timeout:exports.LLSyncConfig.waitGetAdvDataReplyTime,timeoutCode:constants.WAIT_GET_ADV_DATA_REPLY_TIMEOUT,writeId:constants.DEVICE_INFO_WRITE_ID})]}))}))},t.prototype._parseDataBeforeConnect=function(t,e){void 0===this.deviceAdapter.extendInfo.moduleVersion&&console.warn("[LLsyncProtocol] invalid moduleVersion:",this.deviceAdapter.extendInfo.moduleVersion);var n,i=this.deviceAdapter.extendInfo.moduleVersion||2;i&&(n=exports.LLSyncConfig.mtuDefaultMap[i],i>=2&&(n=exports.LLSyncConfig.mtuDefaultMap[2])),this.reporter.info(constants.SET_MTU_BEFORE_CONNECT,{version:i,mtuLength:n}),this.deviceAdapter.bleVersion=i,this.deviceAdapter.mtu=n;var s=byteUtil.hexString2hexArray(t.slice(2)),o=[s],r=[t.slice(0,2)];return i>0&&r.push(libs_1.U16ToHexString(s.length)),r=r.concat(s),this.deviceAdapter.sliceData(r,o,e)},t}();exports.LLSyncProtocol=LLSyncProtocol,exports.isHeartbeatResp=function(t){return 4===t.length&&"1B"===t[0]&&"00"===t[1]&&"01"===t[2]&&"00"===t[3]}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.isHeartbeatResp=exports.LLSyncProtocol=exports.LLSyncConfig=exports.BindState=void 0;var BindState,tslib_1=require("tslib"),constants=tslib_1.__importStar(require("../../constants")),qcloud_iotexplorer_appdev_sdk_1=require("qcloud-iotexplorer-appdev-sdk"),libs_1=require("../../libs"),_a=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils,noop=_a.noop,genPromise=_a.genPromise,byteUtil=_a.byteUtil;!function(t){t[t.NOT_BOUND=0]="NOT_BOUND",t[t.WAITING_BIND=1]="WAITING_BIND",t[t.HAS_BOUND=2]="HAS_BOUND",t[t.CONNECTED=3]="CONNECTED"}(BindState=exports.BindState||(exports.BindState={})),exports.LLSyncConfig={BLE_PSK_DEVICE_KEY:"ble_psk_device_ket",Secret_Encrypt_Key:"secret_encrypt_key",waitConnectReplyTime:1e4,waitBindReplyTime:1e4,waitGetRegisterDeviceInfo:1e4,waitGetCheckTimeoutReplyTime:1e4,waitGetCheckTimeoutDefaultReplyTime:6e4,waitControlReplyTime:1e4,waitGetDeviceInfoTime:1e4,waitUpdateReplyInt:1e4,waitGetAdvDataReplyTime:1e4,mtuDefaultMap:{0:void 0,1:20,2:20}};var LLSyncProtocol=function(){function t(t){this._cleanupUserCheckHandleAfterCancel=noop,this.deviceAdapter=t,this._parseDataBeforeConnect=this._parseDataBeforeConnect.bind(this)}return Object.defineProperty(t.prototype,"reporter",{get:function(){return this.deviceAdapter.reporter},enumerable:!1,configurable:!0}),t.prototype.requestBindDevice=function(t){var e=t.needUserCheck,n=void 0!==e&&e,i=t.isDynamicRegister,s=void 0!==i&&i;return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,e,i,o,r,a=this;return tslib_1.__generator(this,(function(c){switch(c.label){case 0:return t=Math.floor(Date.now()/1e3),e=parseInt(libs_1.gen4BytesIntHex(),16),i=this._parseDataBeforeConnect(""+constants.DEVICE_INFO_WRITE_PREFIX[constants.TIME_SYNC]+e.toString(16)+t.toString(16),constants.TIME_SYNC),this.reporter.info(constants.TIME_SYNC,{timestamp:t,nonce:e,bindDeviceData:i,needUserCheck:n,isDynamicRegister:s}),s?[4,this.registerDevice({timestamp:t,bindDeviceData:i,nonce:e})]:[3,2];case 1:o=c.sent(),i=o.bleData,t=o.timestamp,c.label=2;case 2:return r={bindDeviceData:i,dataHandler:function(i){if(!i.length)throw{code:constants.CONNECT_REPLY_INVALID};if(n){var s=!(libs_1.getStrLength(i)>>15);if(console.log("bind auth response userCheckResult",s),!s)throw{code:constants.GET_USER_CHECK_REJECT}}var o=i.slice(2,22).join(""),r=libs_1.hex2str(i.slice(22)),c={sign:o.toLocaleLowerCase(),deviceName:r,nonce:e,timestamp:t+60};return a.reporter.info(constants.TIME_SYNC,c),c}},this.reporter.info(constants.TIME_SYNC,r),[2,n?this.waitUserCheckAndBindDevice(r):this.bindDeviceDirectly(r)]}}))}))},t.prototype.registerDevice=function(t){var e=t.timestamp,n=t.nonce,i=t.bindDeviceData;return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,s,o,r,a,c,_,E,I=this;return tslib_1.__generator(this,(function(d){switch(d.label){case 0:return[4,this.deviceAdapter.writeAndWait4Response(i,constants.REGISTER_DEVICE_INFO_REPLY,(function(t){if(!t.length)throw{code:constants.REGISTER_DEVICE_INFO_REPLY_INVALID};var e=libs_1.getStrLength(t),n=parseInt(t.slice(2,3).join(""),16),i=libs_1.hex2str(t.slice(3,3+n)),s=libs_1.hex2str(t.slice(3+n,3+e));return I.reporter.info(constants.REGISTER_DEVICE_INFO_REPLY,{allLength:e,deviceNameLength:n,deviceName:i,sign:s}),{sign:s,deviceName:i}}),{timeout:exports.LLSyncConfig.waitGetRegisterDeviceInfo,timeoutCode:constants.WAIT_REGISTER_DEVICE_INFO_REPLY_TIMEOUT,writeId:constants.DEVICE_INFO_WRITE_ID})];case 1:t=d.sent(),s=t.deviceName,o=t.sign,this.reporter.info(constants.TIME_SYNC,{deviceName:s,sign:o}),r=0,d.label=2;case 2:return d.trys.push([2,4,,5]),[4,this.deviceAdapter.models.dynamicRegisterDevice({deviceName:s,sign:o,productId:this.deviceAdapter.productId,timestamp:e,nonce:n})];case 3:return a=d.sent().payload,c=Math.floor(Date.now()/1e3),r=1,_=this._parseDataBeforeConnect(constants.DEVICE_INFO_WRITE_PREFIX[constants.SEND_REGISTER_DEVICE_PAYLOAD]+""+libs_1.U8ToHexString(r)+libs_1.U8ToHexString(a.length)+libs_1.str2hexStr(a)+n.toString(16)+c.toString(16),constants.SEND_REGISTER_DEVICE_PAYLOAD),this.reporter.info(constants.REGISTER_DEVICE_SUCCESS,{payload:a,bleData:_}),[2,{bleData:_,timestamp:c}];case 4:throw E=d.sent(),tslib_1.__assign(tslib_1.__assign({},E),{code:constants.REGISTER_DEVICE_ERROR});case 5:return[2]}}))}))},t.prototype.bindDeviceDirectly=function(t){var e=t.bindDeviceData,n=t.dataHandler;return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(t){return[2,this.deviceAdapter.writeAndWait4Response(e,constants.BIND_AUTH,n,{timeout:exports.LLSyncConfig.waitBindReplyTime,timeoutCode:constants.WAIT_CONNECT_REPLY_TIMEOUT,writeId:constants.DEVICE_INFO_WRITE_ID})]}))}))},t.prototype.waitUserCheckAndBindDevice=function(t){var e=t.bindDeviceData,n=t.dataHandler;return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,i,s,o=this;return tslib_1.__generator(this,(function(r){switch(r.label){case 0:return t=genPromise(),s=function(e){clearTimeout(i),console.log("registerUserCheckTimer",e),i=setTimeout((function(){console.log("user check timeout",e),o.cancelUserCheck("timeout"),t.reject({code:constants.WAIT_USER_CHECK_TIMEOUT})}),e)},this.deviceAdapter.wait4EventResponse(constants.USER_CHECK_TIMEOUT_CALLBACK,(function(t){if(!t.length)return console.log("get user check timeout duration fail, trigger default timeout timer"),o.reporter.info(constants.GET_USER_CHECK_TIMEOUT_ERROR),s(exports.LLSyncConfig.waitGetCheckTimeoutDefaultReplyTime);var e=1e3*parseInt(t.slice(2).join(""),16);o.reporter.info(constants.GET_USER_CHECK_TIMEOUT_SUCCESS,{timeoutDuration:e}),s(e)}),{timeout:exports.LLSyncConfig.waitGetCheckTimeoutReplyTime,timeoutHandler:function(){o.reporter.info(constants.GET_USER_CHECK_TIMEOUT_TIMEOUT),s(exports.LLSyncConfig.waitGetCheckTimeoutDefaultReplyTime-exports.LLSyncConfig.waitGetCheckTimeoutReplyTime)}}),this._cleanupUserCheckHandleAfterCancel=function(){console.log("process cleanup user check handler"),t.reject(null),o.deviceAdapter.off(constants.BIND_AUTH),o._cleanupUserCheckHandleAfterCancel=noop},[4,Promise.race([t.promise,this.deviceAdapter.writeAndWait4Response(e,constants.BIND_AUTH,n,{timeout:exports.LLSyncConfig.waitGetCheckTimeoutDefaultReplyTime+exports.LLSyncConfig.waitGetCheckTimeoutReplyTime,timeoutCode:constants.WAIT_CONNECT_REPLY_TIMEOUT,writeId:constants.DEVICE_INFO_WRITE_ID})])];case 1:return[2,r.sent()]}}))}))},t.prototype.cancelUserCheck=function(t){void 0===t&&(t="timeout"),console.log("cancel user check, reason: ",t),"cancel"===t&&this._cleanupUserCheckHandleAfterCancel();var e=""+constants.DEVICE_INFO_WRITE_PREFIX[constants.USER_CHECK_TIMEOUT]+libs_1.U8ToHexString("timeout"===t?constants.WRITE_USER_CHECK_TIMEOUT:constants.WRITE_USER_CHECK_CANCEL);this.deviceAdapter.write(e,{writeId:constants.DEVICE_INFO_WRITE_ID})},t.prototype.getDeviceAuthInfo=function(){var t=Math.floor(Date.now()/1e3),e=this._parseDataBeforeConnect(""+constants.DEVICE_INFO_WRITE_PREFIX[constants.CONNECT_AUTH]+t.toString(16)+libs_1.encrypt(t,this.deviceAdapter.localPsk),constants.CONNECT_AUTH);return console.log("[LLsyncProtocol] auth data:",{data:e,moduleVersion:this.deviceAdapter.extendInfo.moduleVersion,localPsk:this.deviceAdapter.localPsk,dataStr:""+constants.DEVICE_INFO_WRITE_PREFIX[constants.CONNECT_AUTH]+t.toString(16)+libs_1.encrypt(t,this.deviceAdapter.localPsk)}),this.deviceAdapter.writeAndWait4Response(e,constants.CONNECT_AUTH,(function(e){if(!e.length)throw{code:constants.CONNECT_REPLY_INVALID};return{sign:e.slice(2,22).join("").toLocaleLowerCase(),timestamp:t}}),{timeout:exports.LLSyncConfig.waitConnectReplyTime,timeoutCode:constants.WAIT_CONNECT_REPLY_TIMEOUT,writeId:constants.DEVICE_INFO_WRITE_ID})},t.prototype.getDeviceInfo=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){return tslib_1.__generator(this,(function(t){return[2,this.deviceAdapter.writeAndWait4Response(constants.DEVICE_INFO_WRITE_PREFIX[constants.CONNECT_RESULT_WRITE_SUCCESS],constants.DEVICE_INFO,(function(t){if(!t.length)throw{code:constants.DEVICE_INFO_INVALID};var e=parseInt(t.slice(2,3).join(""),16),n=parseInt(t.slice(3,5).join(""),16),i=!!(n>>15),s=8191&n,o=t.slice(6).join("");return{version:e,mtu:s,needSetMtu:i,otaVersion:o?libs_1.hex2str(o):o}}),{timeout:exports.LLSyncConfig.waitGetDeviceInfoTime,timeoutCode:constants.WAIT_GET_DEVICE_INFO_TIMEOUT,writeId:constants.DEVICE_INFO_WRITE_ID})]}))}))},t.prototype.getUnbindAuthSign=function(){var t=this._parseDataBeforeConnect(""+constants.DEVICE_INFO_WRITE_PREFIX[constants.UNBIND_AUTH]+libs_1.encrypt(constants.UNBIND_REQUEST,this.deviceAdapter.localPsk),constants.UNBIND_AUTH);return this.deviceAdapter.writeAndWait4Response(t,constants.UNBIND_AUTH,(function(t){if(!t.length)throw{code:constants.UNBIND_REPLY_INVALID};return{sign:t.slice(2,22).join("").toLocaleLowerCase()}}),{timeout:exports.LLSyncConfig.waitConnectReplyTime,timeoutCode:constants.WAIT_UNBIND_REPLY_TIMEOUT,writeId:constants.DEVICE_INFO_WRITE_ID})},t.prototype.controlDeviceAction=function(t){var e=libs_1.convertActionControlToTlv(t,this.deviceAdapter.dataTemplate),n=e.actionIndex,i=e.tlvData,s=e.tmpData,o=this.deviceAdapter.sliceData(tslib_1.__spread([libs_1.getTypeHead(constants.DEVICE_DATA_WRITE_HEAD[constants.CONTROL_ACTION],n),libs_1.U16ToHexString(i.length)],i),s,constants.CONTROL_ACTION);return this.deviceAdapter.isEncrypted&&(o=this.deviceAdapter.encrypt(o,this.deviceAdapter.sessionKey,{contentType:"hex"})),this.deviceAdapter.writeAndWait4Response(o,constants.ACTION_REPLY,(function(t){if(!t.length)throw{code:constants.CONTROL_REPLY_INVALID};var e=parseInt(t.slice(2,3).join(""),16),n=t.slice(3);if(0===e)return{success:!0,output:n};throw{code:constants.CONTROL_REPLY_CODE_INVALID,errCode:e}}),{timeout:exports.LLSyncConfig.waitControlReplyTime,timeoutCode:constants.WAIT_CONTROL_ACTION_REPLY_TIMEOUT,writeId:constants.DEVICE_DATA_WRITE_ID,wrapSplitDataMode:constants.ACTION_REPLY})},t.prototype.controlDeviceProperty=function(t){var e=libs_1.convertPropertiesChangeToTlv(t,this.deviceAdapter.dataTemplate),n=e.tlvData,i=e.tmpData,s=this.deviceAdapter.sliceData(tslib_1.__spread([libs_1.getTypeHead(constants.DEVICE_DATA_WRITE_HEAD[constants.CONTROL_DEVICE],constants.DEVICE_DATA_WRITE_SUFFIX[constants.CONTROL_DEVICE]),libs_1.U16ToHexString(n.length)],n),i,constants.CONTROL_DEVICE);return this.deviceAdapter.isEncrypted&&(s=this.deviceAdapter.encrypt(s,this.deviceAdapter.sessionKey,{contentType:"hex"})),this.deviceAdapter.writeAndWait4Response(s,constants.CONTROL_REPLY,(function(t){if(!t.length)throw{code:constants.CONTROL_REPLY_INVALID};var e=parseInt(t.slice(2).join(""),16);if(0===e)return{code:0};throw{code:constants.CONTROL_REPLY_CODE_INVALID,errCode:e}}),{timeout:exports.LLSyncConfig.waitControlReplyTime,timeoutCode:constants.WAIT_CONTROL_DEVICE_REPLY_TIMEOUT,writeId:constants.DEVICE_DATA_WRITE_ID})},t.prototype.reportBindSuccess=function(t){return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,n;return tslib_1.__generator(this,(function(i){switch(i.label){case 0:return e=libs_1.gen4BytesIntHex(),this.reporter.info(constants.BIND_AUTH_SUCCESS,{identify:this.deviceAdapter.userIdentify,localPsk:e,timeCost:Date.now()-t}),n=""+constants.DEVICE_INFO_WRITE_PREFIX[constants.BIND_AUTH_SUCCESS]+constants.DEVICE_INFO_WRITE_PREFIX[constants.BIND_AUTH_SUCCESS]+e+this.deviceAdapter.userIdentify,[4,this.deviceAdapter.writeData(this._parseDataBeforeConnect(n,constants.BIND_AUTH_SUCCESS),{writeId:constants.DEVICE_INFO_WRITE_ID})];case 1:return i.sent(),[4,this.deviceAdapter.models.setDeviceConfig({DeviceId:this.deviceAdapter.explorerDeviceId,DeviceKey:exports.LLSyncConfig.BLE_PSK_DEVICE_KEY,DeviceValue:e})];case 2:return i.sent(),[2,e]}}))}))},t.prototype.reportBindEncryptedSuccess=function(t,e){return tslib_1.__awaiter(this,void 0,void 0,(function(){var n,i;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:return this.reporter.info(constants.BIND_AUTH_SUCCESS,{identify:this.deviceAdapter.userIdentify,timeCost:Date.now()-t,secretkey:e}),n=this.deviceAdapter.encrypt("BindResult0",e),libs_1.log("bind result encrypted",n),[4,this.deviceAdapter.writeAndWait4Response(this._parseDataBeforeConnect(""+constants.DEVICE_INFO_WRITE_PREFIX[constants.RESPONSE_BIND]+n,constants.BIND_AUTH_SUCCESS),constants.RESPONSE_BIND,(function(t){return libs_1.log("result res data",t),{ack:parseInt(t[2],16),errCode:constants.BleErrorMsg[t[3]]}}),{writeId:constants.DEVICE_INFO_WRITE_ID,timeout:exports.LLSyncConfig.waitGetRegisterDeviceInfo,timeoutCode:constants.WAIT_REGISTER_DEVICE_INFO_REPLY_TIMEOUT})];case 1:if(1===(i=s.sent()).ack)throw{code:i.errCode};return[4,this.deviceAdapter.models.setDeviceConfig({DeviceId:this.deviceAdapter.explorerDeviceId,DeviceKey:exports.LLSyncConfig.Secret_Encrypt_Key,DeviceValue:e})];case 2:return s.sent(),[2,i]}}))}))},t.prototype.reportBindError=function(t){void 0===t&&(t="");var e=""+constants.DEVICE_INFO_WRITE_PREFIX[constants.BIND_AUTH_FAIL]+libs_1.str2hexStr(t);this.deviceAdapter.write(e,{writeId:constants.DEVICE_INFO_WRITE_ID})},t.prototype.reportBindEncryptedError=function(t){var e=this.deviceAdapter.encrypt("BindResult1",t);this.deviceAdapter.write(""+constants.DEVICE_INFO_WRITE_PREFIX[constants.RESPONSE_BIND]+e,{writeId:constants.DEVICE_INFO_WRITE_ID})},t.prototype.reportConnectError=function(){var t=constants.DEVICE_INFO_WRITE_PREFIX[constants.CONNECT_RESULT_WRITE_FAIL];this.deviceAdapter.write(t,{writeId:constants.DEVICE_INFO_WRITE_ID})},t.prototype.reportPropertyReportResult=function(t){void 0===t&&(t=0);var e=constants.DEVICE_DATA_WRITE_HEAD,n=constants.DEVICE_DATA_WRITE_SUFFIX,i=constants.REPORT_RESULT,s=constants.DEVICE_DATA_WRITE_ID,o=""+libs_1.getTypeHead(e[i],n[i])+byteUtil.byteToHex(byteUtil.convertNumberToByte(t));this.deviceAdapter.isEncrypted&&(o=this.deviceAdapter.encrypt(o,this.deviceAdapter.sessionKey,{contentType:"hex"})),this.deviceAdapter.writeData(o,{writeId:s})},t.prototype.reportEventReportResult=function(t,e){void 0===t&&(t=0);var n=constants.DEVICE_DATA_WRITE_HEAD,i=constants.EVENT_REPLY,s=constants.DEVICE_DATA_WRITE_ID,o=""+libs_1.getTypeHead(n[i],e)+byteUtil.byteToHex(byteUtil.convertNumberToByte(t));this.deviceAdapter.isEncrypted&&(o=this.deviceAdapter.encrypt(o,this.deviceAdapter.sessionKey,{contentType:"hex"})),this.deviceAdapter.writeData(o,{writeId:s})},t.prototype.reportGetStatusResult=function(t,e,n){void 0===t&&(t=0);var i=constants.DEVICE_DATA_WRITE_HEAD,s=constants.DEVICE_DATA_WRITE_SUFFIX,o=constants.GET_STATUS,r=constants.DEVICE_DATA_WRITE_ID,a=[""+libs_1.getTypeHead(i[o],s[o]),byteUtil.byteToHex(byteUtil.convertNumberToByte(t))];e&&(a=this.deviceAdapter.sliceData(a.concat(tslib_1.__spread([libs_1.U16ToHexString(e.length)],e)),n,constants.GET_STATUS)),this.deviceAdapter.isEncrypted&&(a=this.deviceAdapter.encrypt(a,this.deviceAdapter.sessionKey,{contentType:"hex"})),this.deviceAdapter.writeData(a,{writeId:r})},t.prototype.reportUnbindResult=function(t){if(this.deviceAdapter.isEncrypted){var e=this.deviceAdapter.encrypt("fail"===t?"UnbindFail":"UnbindOk",this.deviceAdapter.sessionKey);libs_1.log("unbind send payload",e);var n=""+constants.DEVICE_INFO_WRITE_PREFIX[constants.UNBIND_RESPONSE]+e,i=this._parseDataBeforeConnect(n,constants.UNBIND_RESPONSE);return this.deviceAdapter.writeData(i,{writeId:constants.DEVICE_INFO_WRITE_ID})}i=constants.DEVICE_INFO_WRITE_PREFIX[constants.UNBIND_RESULT_AUTH_SUCCESS];return"fail"===t&&(i=constants.DEVICE_INFO_WRITE_PREFIX[constants.UNBIND_RESULT_AUTH_FAIL]),this.deviceAdapter.write(i,{writeId:constants.DEVICE_INFO_WRITE_ID})},t.prototype.notifyAppReady=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,e,n,i;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:return t=constants.DEVICE_INFO_WRITE_PREFIX,e=constants.APP_IS_READY,n=constants.DEVICE_INFO_WRITE_ID,i=t[e],this.reporter.info(e),[4,this.deviceAdapter.writeData(i,{writeId:n})];case 1:return s.sent(),[2]}}))}))},t.prototype.notifyAppOnIOSDevice=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,e,n,i;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:return t=constants.DEVICE_INFO_WRITE_PREFIX,e=constants.APP_ON_IOS_DEVICE,n=constants.DEVICE_INFO_WRITE_ID,i=t[e],this.reporter.info(e),[4,this.deviceAdapter.writeData(i,{writeId:n})];case 1:return s.sent(),[2]}}))}))},t.prototype.notifyLocalRssi=function(t){var e=t.rssi;return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,n,i,s,o;return tslib_1.__generator(this,(function(r){switch(r.label){case 0:return!Number.isSafeInteger(e)||e<-255||e>0?[2,Promise.reject({msg:"RSSI 取值超出范围",code:"INVALID_RSSI_VALUE"})]:(t=constants.DEVICE_INFO_WRITE_PREFIX,n=constants.NOTIFY_LOCAL_RSSI,i=constants.DEVICE_INFO_WRITE_ID,s=e+255,o=[t[n],s.toString(16).padStart(2,"0")].join(""),[4,this.deviceAdapter.writeData(o,{writeId:i})]);case 1:return r.sent(),[2]}}))}))},t.prototype.sendHeartbeat=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,e,n,i;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:return t=constants.DEVICE_INFO_WRITE_PREFIX,e=constants.HEARTBEAT_REQ,n=constants.DEVICE_INFO_WRITE_ID,i=t[e],[4,this.deviceAdapter.writeData(i,{writeId:n})];case 1:return s.sent(),[2]}}))}))},t.prototype.getAdvertisingData=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t=this;return tslib_1.__generator(this,(function(e){return this.reporter.info(constants.GET_ADV_DATA,{}),[2,this.deviceAdapter.writeAndWait4Response(constants.DEVICE_INFO_WRITE_PREFIX[constants.GET_ADV_DATA],constants.GET_ADV_DATA_REPLY,(function(e){if(e.length<20)throw{code:constants.GET_ADV_DATA_REPLY_INVALID};var n=parseInt(e[2],16);if(n)throw{code:constants.GET_ADV_DATA_FAIL,ack:n};var i=parseInt(e[3],16),s=3&i,o={bindState:s,isEncrypted:!!(i>>>3&1),isDynamicRegister:!!(i>>>2&1),moduleVersion:i>>>4};if(s===BindState.CONNECTED||s===BindState.HAS_BOUND){var r=e.slice(4,12).join("").toLocaleLowerCase(),a=e.slice(12,20).join("").toLocaleLowerCase();Object.assign(o,{deviceIdentify:r,deviceUserIdentify:a})}else{var c=e.slice(4,10).join(":"),_=libs_1.hex2str(e.slice(10,20));Object.assign(o,{macAddress:c,productId:_})}return t.reporter.info(constants.GET_ADV_DATA_RESULT,o),o}),{timeout:exports.LLSyncConfig.waitGetAdvDataReplyTime,timeoutCode:constants.WAIT_GET_ADV_DATA_REPLY_TIMEOUT,writeId:constants.DEVICE_INFO_WRITE_ID})]}))}))},t.prototype.checkSecureBindInfo=function(t){if(!/^[A-Z0-9]{10}$/.test(t.productId))return Promise.reject({code:"InvalidParam.LLSync.checkSecureBindInfo.productId",msg:"一机一密验证的 productId 入参有误"});if(!/^[a-fA-F0-9]{12}$/.test(t.mac))return Promise.reject({code:"InvalidParam.LLSync.checkSecureBindInfo.mac",msg:"一机一密验证的 mac 入参有误"});if(!/^[a-fA-F0-9]{32}$/.test(t.sign))return Promise.reject({code:"InvalidParam.LLSync.checkSecureBindInfo.sign",msg:"一机一密验证的 sign 入参有误"});var e=[constants.DEVICE_INFO_WRITE_PREFIX[constants.CHECK_SECURE_BIND_INFO],libs_1.str2hexStr(t.productId),t.mac,t.sign].join("");console.log("[LLSync.checkSecureBindInfo]",e);var n=this._parseDataBeforeConnect(e,constants.CHECK_SECURE_BIND_INFO);return this.deviceAdapter.writeAndWait4Response(n,constants.CHECK_SECURE_BIND_INFO_REPLY,(function(t){if(t.length<3)throw{code:constants.CHECK_SECURE_BIND_INFO_REPLY_INVALID};if(0!==parseInt(t[2],10)){if(t.length<4)throw{code:constants.CHECK_SECURE_BIND_INFO_REPLY_INVALID};var e=parseInt(t[3],10);throw{code:constants.CHECK_SECURE_BIND_INFO_FAIL,detail:{errorCode:e}}}}),{timeout:exports.LLSyncConfig.waitConnectReplyTime,timeoutCode:constants.CHECK_SECURE_BIND_INFO_REPLY_TIMEOUT,writeId:constants.DEVICE_INFO_WRITE_ID})},t.prototype._parseDataBeforeConnect=function(t,e){void 0===this.deviceAdapter.extendInfo.moduleVersion&&console.warn("[LLsyncProtocol] invalid moduleVersion:",this.deviceAdapter.extendInfo.moduleVersion);var n,i=this.deviceAdapter.extendInfo.moduleVersion||2;i&&(n=exports.LLSyncConfig.mtuDefaultMap[i],i>=2&&(n=exports.LLSyncConfig.mtuDefaultMap[2])),this.reporter.info(constants.SET_MTU_BEFORE_CONNECT,{version:i,mtuLength:n}),this.deviceAdapter.bleVersion=i,this.deviceAdapter.mtu=n;var s=byteUtil.hexString2hexArray(t.slice(2)),o=[s],r=[t.slice(0,2)];return i>0&&r.push(libs_1.U16ToHexString(s.length)),r=r.concat(s),this.deviceAdapter.sliceData(r,o,e)},t}();exports.LLSyncProtocol=LLSyncProtocol,exports.isHeartbeatResp=function(t){return 4===t.length&&"1B"===t[0]&&"00"===t[1]&&"01"===t[2]&&"00"===t[3]}; | ||
//# sourceMappingURL=LLSyncProtocol.js.map |
@@ -22,2 +22,9 @@ import { Reporter } from 'qcloud-iotexplorer-appdev-sdk'; | ||
} | ||
export declare type LLSyncEventHandlerFn<T> = (data: string[], event: { | ||
type: string; | ||
}) => T; | ||
export declare type LLSyncRawEventHandlerFn<T> = (event: { | ||
data: any; | ||
type: string; | ||
}) => T; | ||
/** | ||
@@ -40,4 +47,4 @@ * 处理底层数据传输及协议层数据传输 | ||
handleBLEMessage(hex: string[]): {}; | ||
wait4EventResponse<T>(eventName: string, handler: (data: any) => T, { timeout, timeoutCode, timeoutHandler, wrapSplitDataMode, shouldWrapSplitDataFn, afterBindEvent, }?: Wait4EventResponseOptions): Promise<T>; | ||
writeAndWait4Response<T>(data2Write: any, eventName: string, handler: (data: any) => T, { timeout, timeoutCode, timeoutHandler, writeId, wrapSplitDataMode, shouldWrapSplitDataFn, }?: WriteAndWait4ResponseOptions): Promise<T>; | ||
wait4EventResponse<T>(eventNameOrEventNameList: string | string[], handler: LLSyncEventHandlerFn<T> | LLSyncRawEventHandlerFn<T>, { timeout, timeoutCode, timeoutHandler, wrapSplitDataMode, shouldWrapSplitDataFn, afterBindEvent, }?: Wait4EventResponseOptions): Promise<T>; | ||
writeAndWait4Response<T>(data2Write: any, eventName: string | string[], handler: LLSyncEventHandlerFn<T> | LLSyncRawEventHandlerFn<T>, { timeout, timeoutCode, timeoutHandler, writeId, wrapSplitDataMode, shouldWrapSplitDataFn, }?: WriteAndWait4ResponseOptions): Promise<T>; | ||
writeMtuResult(type: 'success' | 'fail'): void; | ||
@@ -44,0 +51,0 @@ sliceData(data: any, tmpData: any, mode: any): string[]; |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LLSyncDeviceAdapterBase=void 0;var tslib_1=require("tslib"),qcloud_iotexplorer_appdev_sdk_1=require("qcloud-iotexplorer-appdev-sdk"),utils=tslib_1.__importStar(require("../libs")),constants=tslib_1.__importStar(require("../constants")),qcloud_iotexplorer_bluetooth_adapter_1=require("qcloud-iotexplorer-bluetooth-adapter"),qcloud_iotexplorer_common_libs_1=require("qcloud-iotexplorer-common-libs"),LLSyncProtocol_1=require("./LLSync/LLSyncProtocol"),libs_1=require("../libs"),_a=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils,genPromise=_a.genPromise,delay=_a.delay,envDetect=_a.envDetect,LLSyncDeviceAdapterBase=function(e){function t(t){var r=e.call(this,t)||this;return r.on("message",r.notifyMessage.bind(r)),r.on("disconnect",(function(){r.writeDataQueue.cancelAllTasks({code:10006,errCode:10006,msg:"当前连接已断开",cause:"LLSyncDeviceAdapter disconnect event"})})),r.writeDataQueue=new qcloud_iotexplorer_common_libs_1.CancelableQueue({autoStart:!0,handler:function(e){var t=e.businessData,i=e.isCancelled;return r.writeDataInternal({params:t,isCancelled:i})},onTaskSuccess:function(e){var t=e.businessData;return"function"==typeof t.onSuccess&&t.onSuccess()},onTaskError:function(e,t){var r=t.businessData;return"function"==typeof r.onError&&r.onError(e)}}),r}return tslib_1.__extends(t,e),t.prototype.notifyMessage=function(e){var t=void 0===e?{}:e,r=t.type,i=t.data;if("unknown"!==r)return console.log("check this in notifyMessage",this,{type:r,data:i}),this.emit(r,{type:r,data:i})},t.prototype.handleBLEMessage=function(e){if(this.isEncrypted&&this.authorized&&!LLSyncProtocol_1.isHeartbeatResp(e)){var t=utils.decrypt(e.join(""),this.sessionKey).match(/[\da-f]{2}/gi);if(!t)return console.error("llsync decrypt ble message fail",e.join(""),this.sessionKey),{};e=t}var r=parseInt(e[0],16),i={type:constants.INDICATE_TYPE_MAP[r]||"unknown",data:e.splice(1)};return console.log("Message(hex)",i),i},t.prototype.wait4EventResponse=function(e,t,r){var i=void 0===r?{}:r,n=i.timeout,o=i.timeoutCode,s=i.timeoutHandler,a=i.wrapSplitDataMode,c=i.shouldWrapSplitDataFn,u=void 0===c||c,l=i.afterBindEvent;return tslib_1.__awaiter(this,void 0,void 0,(function(){var r,i,c,d,_,p=this;return tslib_1.__generator(this,(function(v){switch(v.label){case 0:r=genPromise(),console.log("wait4EventResponse",{eventName:e}),i=!1,c=function(n){return tslib_1.__awaiter(p,void 0,void 0,(function(){return tslib_1.__generator(this,(function(o){try{i?console.log("Target event: "+e+" triggered, but is already timeout"):(r.resolve(t(n)),i=!0)}catch(e){r.reject(e)}finally{this.off(e,d)}return[2]}))}))},d=u?utils.wrapEventHandler(c,a):c,this.on(e,d),v.label=1;case 1:return v.trys.push([1,5,,6]),"function"!=typeof l?[3,3]:[4,l()];case 2:v.sent(),v.label=3;case 3:return[4,Promise.race([r.promise,new Promise((function(t,r){n&&n>0&&setTimeout((function(){i||(libs_1.log("Wait for target event: "+e+" timeout"),i=!0,p.off(e,d),"function"==typeof s?(console.log("trigger timeout handler"),t(s())):r({code:o}))}),n)}))])];case 4:return[2,v.sent()];case 5:return _=v.sent(),this.off(e,d),[2,Promise.reject(_)];case 6:return[2]}}))}))},t.prototype.writeAndWait4Response=function(e,t,r,i){var n=void 0===i?{}:i,o=n.timeout,s=n.timeoutCode,a=n.timeoutHandler,c=n.writeId,u=n.wrapSplitDataMode,l=n.shouldWrapSplitDataFn,d=void 0===l||l;return tslib_1.__awaiter(this,void 0,void 0,(function(){var i=this;return tslib_1.__generator(this,(function(n){return libs_1.log("data2Write:",e),[2,this.wait4EventResponse(t,r,{timeout:o,timeoutCode:s,timeoutHandler:a,wrapSplitDataMode:u,shouldWrapSplitDataFn:d,afterBindEvent:function(){return i.writeData(e,{writeId:c}).catch((function(e){return Promise.reject(tslib_1.__assign({code:constants.BLE_WRITE_ERROR},e))}))}})]}))}))},t.prototype.writeMtuResult=function(e){var t="success"===e?0:65535,r=""+constants.DEVICE_INFO_WRITE_PREFIX[constants.WRITE_MTU_RESULT]+libs_1.U16ToHexString(t);this.write(r,{writeId:constants.DEVICE_INFO_WRITE_ID})},t.prototype.sliceData=function(e,t,r){var i=this.mtu;if(this.isEncrypted&&(i=libs_1.getMtuEncrypted(this.mtu)),!this.mtu||e.join("").length<=2*i)return[e.join("")];var n=e.slice(0,r===constants.GET_STATUS?2:1);return console.log("---head----",n),utils.sliceData(t,{mtu:i,head:n,mode:r})},t.prototype.writeData=function(e,t){var r=this;return void 0===t&&(t={}),new Promise((function(i,n){r.writeDataQueue.push(tslib_1.__assign({data:e,onSuccess:i,onError:n},t))}))},t.prototype.setMtu=function(e){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t;return tslib_1.__generator(this,(function(r){switch(r.label){case 0:return envDetect.isIOS?[2]:[4,this.setBLEMTU({deviceId:this.deviceId,mtu:e})];case 1:return t=r.sent(),this.reporter.info(constants.ANDROID_SET_MTU,{mtu:e,ret:t}),[2,t]}}))}))},t.prototype.writeDataInternal=function(e){var t=e.params,r=e.isCancelled;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,i,n,o,s,a,c,u,l,d,_;return tslib_1.__generator(this,(function(p){switch(p.label){case 0:e=t.data,i=t.writeId,n=t.waitGap,o=void 0===n?0:n,s=t.retryTime,a=void 0===s?5:s,Array.isArray(e)||(e=[e]),c=0,p.label=1;case 1:return c<e.length?(u=e[c],0!==c&&o>0?[4,delay(o)]:[3,3]):[3,11];case 2:p.sent(),p.label=3;case 3:l=a,p.label=4;case 4:if(r())return[2,Promise.reject({code:constants.WRITE_DATA_CANCEL_ERROR_CODE})];p.label=5;case 5:return p.trys.push([5,7,,9]),[4,this.write(u,{writeId:i})];case 6:return p.sent(),[3,10];case 7:if(d=p.sent(),console.log("--- LLSync core writeData error ---- retry time "+l,d),--l<=0)throw d;return _=o>0?o:100,[4,delay(Math.min(10*_*(a-l),constants.MAX_WRITE_DATA_WAIT_GAP))];case 8:return p.sent(),[3,9];case 9:if(l>0)return[3,4];p.label=10;case 10:return c++,[3,1];case 11:return[2]}}))}))},t}(qcloud_iotexplorer_bluetooth_adapter_1.DeviceAdapter);exports.LLSyncDeviceAdapterBase=LLSyncDeviceAdapterBase; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LLSyncDeviceAdapterBase=void 0;var tslib_1=require("tslib"),qcloud_iotexplorer_appdev_sdk_1=require("qcloud-iotexplorer-appdev-sdk"),utils=tslib_1.__importStar(require("../libs")),constants=tslib_1.__importStar(require("../constants")),qcloud_iotexplorer_bluetooth_adapter_1=require("qcloud-iotexplorer-bluetooth-adapter"),qcloud_iotexplorer_common_libs_1=require("qcloud-iotexplorer-common-libs"),LLSyncProtocol_1=require("./LLSync/LLSyncProtocol"),libs_1=require("../libs"),_a=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils,genPromise=_a.genPromise,delay=_a.delay,envDetect=_a.envDetect,LLSyncDeviceAdapterBase=function(e){function t(t){var r=e.call(this,t)||this;return r.on("message",r.notifyMessage.bind(r)),r.on("disconnect",(function(){r.writeDataQueue.cancelAllTasks({code:10006,errCode:10006,msg:"当前连接已断开",cause:"LLSyncDeviceAdapter disconnect event"})})),r.writeDataQueue=new qcloud_iotexplorer_common_libs_1.CancelableQueue({autoStart:!0,handler:function(e){var t=e.businessData,n=e.isCancelled;return r.writeDataInternal({params:t,isCancelled:n})},onTaskSuccess:function(e){var t=e.businessData;return"function"==typeof t.onSuccess&&t.onSuccess()},onTaskError:function(e,t){var r=t.businessData;return"function"==typeof r.onError&&r.onError(e)}}),r}return tslib_1.__extends(t,e),t.prototype.notifyMessage=function(e){var t=void 0===e?{}:e,r=t.type,n=t.data;if("unknown"!==r)return console.log("check this in notifyMessage",this,{type:r,data:n}),this.emit(r,{type:r,data:n})},t.prototype.handleBLEMessage=function(e){if(this.isEncrypted&&this.authorized&&!LLSyncProtocol_1.isHeartbeatResp(e)){var t=utils.decrypt(e.join(""),this.sessionKey).match(/[\da-f]{2}/gi);if(!t)return console.error("llsync decrypt ble message fail",e.join(""),this.sessionKey),{};e=t}var r=parseInt(e[0],16),n={type:constants.INDICATE_TYPE_MAP[r]||"unknown",data:e.splice(1)};return console.log("Message(hex)",n),n},t.prototype.wait4EventResponse=function(e,t,r){var n=void 0===r?{}:r,i=n.timeout,o=n.timeoutCode,s=n.timeoutHandler,a=n.wrapSplitDataMode,c=n.shouldWrapSplitDataFn,u=void 0===c||c,l=n.afterBindEvent;return tslib_1.__awaiter(this,void 0,void 0,(function(){var r,n,c,d,_,p,f,v=this;return tslib_1.__generator(this,(function(h){switch(h.label){case 0:r=genPromise(),console.log("wait4EventResponse",{eventName:e}),n=!1,c=Array.isArray(e)?e:[e],d=null,_=function(){d&&c.forEach((function(e){v.off(e,d)}))},p=function(e){var i=e.data,o=tslib_1.__rest(e,["data"]);if(!n){n=!0,_();try{u?r.resolve(t(i,o)):r.resolve(t(e))}catch(e){r.reject(e)}}},d=u?utils.wrapEventHandler(p,a):p,c.forEach((function(e){v.on(e,d)})),h.label=1;case 1:return h.trys.push([1,5,,6]),"function"!=typeof l?[3,3]:[4,l()];case 2:h.sent(),h.label=3;case 3:return[4,Promise.race([r.promise,new Promise((function(t,r){i&&i>0&&setTimeout((function(){n||(libs_1.log("Wait for target event: "+e+" timeout"),n=!0,v.off(e,d),"function"==typeof s?(console.log("trigger timeout handler"),t(s())):r({code:o}))}),i)}))])];case 4:return[2,h.sent()];case 5:return f=h.sent(),_(),[2,Promise.reject(f)];case 6:return[2]}}))}))},t.prototype.writeAndWait4Response=function(e,t,r,n){var i=void 0===n?{}:n,o=i.timeout,s=i.timeoutCode,a=i.timeoutHandler,c=i.writeId,u=i.wrapSplitDataMode,l=i.shouldWrapSplitDataFn,d=void 0===l||l;return tslib_1.__awaiter(this,void 0,void 0,(function(){var n=this;return tslib_1.__generator(this,(function(i){return libs_1.log("data2Write:",e),[2,this.wait4EventResponse(t,r,{timeout:o,timeoutCode:s,timeoutHandler:a,wrapSplitDataMode:u,shouldWrapSplitDataFn:d,afterBindEvent:function(){return n.writeData(e,{writeId:c}).catch((function(e){return Promise.reject(tslib_1.__assign({code:constants.BLE_WRITE_ERROR},e))}))}})]}))}))},t.prototype.writeMtuResult=function(e){var t="success"===e?0:65535,r=""+constants.DEVICE_INFO_WRITE_PREFIX[constants.WRITE_MTU_RESULT]+libs_1.U16ToHexString(t);this.write(r,{writeId:constants.DEVICE_INFO_WRITE_ID})},t.prototype.sliceData=function(e,t,r){var n=this.mtu;if(this.isEncrypted&&(n=libs_1.getMtuEncrypted(this.mtu)),!this.mtu||e.join("").length<=2*n)return[e.join("")];var i=e.slice(0,r===constants.GET_STATUS?2:1);return console.log("---head----",i),utils.sliceData(t,{mtu:n,head:i,mode:r})},t.prototype.writeData=function(e,t){var r=this;return void 0===t&&(t={}),new Promise((function(n,i){r.writeDataQueue.push(tslib_1.__assign({data:e,onSuccess:n,onError:i},t))}))},t.prototype.setMtu=function(e){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t;return tslib_1.__generator(this,(function(r){switch(r.label){case 0:return envDetect.isIOS?[2]:[4,this.setBLEMTU({deviceId:this.deviceId,mtu:e})];case 1:return t=r.sent(),this.reporter.info(constants.ANDROID_SET_MTU,{mtu:e,ret:t}),[2,t]}}))}))},t.prototype.writeDataInternal=function(e){var t=e.params,r=e.isCancelled;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,n,i,o,s,a,c,u,l,d,_;return tslib_1.__generator(this,(function(p){switch(p.label){case 0:e=t.data,n=t.writeId,i=t.waitGap,o=void 0===i?0:i,s=t.retryTime,a=void 0===s?5:s,Array.isArray(e)||(e=[e]),c=0,p.label=1;case 1:return c<e.length?(u=e[c],0!==c&&o>0?[4,delay(o)]:[3,3]):[3,11];case 2:p.sent(),p.label=3;case 3:l=a,p.label=4;case 4:if(r())return[2,Promise.reject({code:constants.WRITE_DATA_CANCEL_ERROR_CODE})];p.label=5;case 5:return p.trys.push([5,7,,9]),[4,this.write(u,{writeId:n})];case 6:return p.sent(),[3,10];case 7:if(d=p.sent(),console.log("--- LLSync core writeData error ---- retry time "+l,d),--l<=0)throw d;return _=o>0?o:100,[4,delay(Math.min(10*_*(a-l),constants.MAX_WRITE_DATA_WAIT_GAP))];case 8:return p.sent(),[3,9];case 9:if(l>0)return[3,4];p.label=10;case 10:return c++,[3,1];case 11:return[2]}}))}))},t}(qcloud_iotexplorer_bluetooth_adapter_1.DeviceAdapter);exports.LLSyncDeviceAdapterBase=LLSyncDeviceAdapterBase; | ||
//# sourceMappingURL=LLSyncDeviceAdapterBase.js.map |
@@ -54,2 +54,5 @@ export declare const REPORT_EVENT_TYPE = "standard-ble"; | ||
export declare const NOTIFY_LOCAL_RSSI = "NOTIFY_LOCAL_RSSI"; | ||
export declare const CHECK_SECURE_BIND_INFO = "CHECK_SECURE_BIND_INFO"; | ||
export declare const CHECK_SECURE_BIND_INFO_REPLY = "CHECK_SECURE_BIND_INFO_REPLY"; | ||
export declare const CHECK_SECURE_BIND_INFO_REQUIRED = "CHECK_SECURE_BIND_INFO_REQUIRED"; | ||
export declare const GET_DEVICE_INFO = "GET_DEVICE_INFO"; | ||
@@ -126,2 +129,3 @@ export declare const SET_WIFI_MODE = "SET_WIFI_MODE"; | ||
27: string; | ||
30: string; | ||
224: string; | ||
@@ -172,2 +176,3 @@ 225: string; | ||
NOTIFY_LOCAL_RSSI: string; | ||
CHECK_SECURE_BIND_INFO: string; | ||
}; | ||
@@ -259,2 +264,5 @@ export declare const DEVICE_DATA_WRITE_HEAD: { | ||
export declare const GET_ADV_DATA_REPLY_INVALID = "GET_ADV_DATA_REPLY_INVALID"; | ||
export declare const CHECK_SECURE_BIND_INFO_FAIL = "CHECK_SECURE_BIND_INFO_FAIL"; | ||
export declare const CHECK_SECURE_BIND_INFO_REPLY_TIMEOUT = "CHECK_SECURE_BIND_INFO_REPLY_TIMEOUT"; | ||
export declare const CHECK_SECURE_BIND_INFO_REPLY_INVALID = "CHECK_SECURE_BIND_INFO_REPLY_INVALID"; | ||
export declare const WAIT_GET_UPDATE_INFO_TIMEOUT = "WAIT_GET_UPDATE_INFO_TIMEOUT"; | ||
@@ -340,2 +348,5 @@ export declare const WAIT_MODULE_UPDATE_TIMEOUT = "WAIT_MODULE_UPDATE_TIMEOUT"; | ||
GET_ADV_DATA_FAIL: string; | ||
CHECK_SECURE_BIND_INFO_REPLY_INVALID: string; | ||
CHECK_SECURE_BIND_INFO_REQUIRED: string; | ||
CHECK_SECURE_BIND_INFO_FAIL: string; | ||
GET_OTA_INFO_FAIL: string; | ||
@@ -405,3 +416,13 @@ MODULE_VERSION_IS_UPDATED: string; | ||
export declare const WRITE_DATA_CANCEL_ERROR_CODE = "BLE_WRITE_CHARACTERISTIC_CANCELLED"; | ||
export declare enum CheckSecureBindInfoErrorCode { | ||
PayloadLengthMismatch = 1, | ||
PayloadMismatch = 2, | ||
ForgetToCheck = 3 | ||
} | ||
export interface LLSyncSecureBindInfo { | ||
productId: string; | ||
mac: string; | ||
sign: string; | ||
} | ||
export declare const MIN_ATT_MTU = 23; | ||
export declare const ATT_MTU_TO_LLSYNC_MTU_DELTA = 3; |
@@ -1,2 +0,2 @@ | ||
"use strict";var _a,_b,_c,_d,_e,_f,_g,_h,_j,_k,_l;Object.defineProperty(exports,"__esModule",{value:!0}),exports.ATT_MTU_TO_LLSYNC_MTU_DELTA=exports.MIN_ATT_MTU=exports.WRITE_DATA_CANCEL_ERROR_CODE=exports.PropertyReportReplyResult=exports.ERROR_MESSAGES=exports.MAX_WRITE_DATA_WAIT_GAP=exports.UPDATE_WRITE_ERROR_TIMES_PER_CIRCLE=exports.WAIT_MODULE_UPDATE_CONNECT_TIME_GAP=exports.WAIT_MODULE_UPDATE_CONNECT_TIMES=exports.MODULE_UPDATE_REPLAY_DATA_CODE_MAP=exports.MODULE_UPDATE_DATA_REPLAY_CODE_MAP=exports.MODULE_UPDATE_REPLAY_CODE_MAP=exports.BLE_COMBO_ERRORS=exports.OTA_UPDATE_ERRORS=exports.OTA_UPDATE_STEPS_MESSAGE=exports.OTA_UPDATE_STEPS=exports.GET_DEV_LOG_INFO_TIMEOUT=exports.GET_DEV_LOG_INFO_INVALID=exports.SET_WIFI_TOKEN_RESULT_TIMEOUT=exports.SET_WIFI_TOKEN_RESULT_INVALID=exports.SET_WIFI_CONNECT_RESULT_TIMEOUT=exports.SET_WIFI_CONNECT_RESULT_INVALID=exports.SET_WIFI_INFO_RESULT_TIMEOUT=exports.SET_WIFI_INFO_RESULT_INVALID=exports.SET_WIFI_MODE_RESULT_TIMEOUT=exports.SET_WIFI_MODE_RESULT_INVALID=exports.WAIT_MODULE_UPDATE_TIMEOUT=exports.WAIT_GET_UPDATE_INFO_TIMEOUT=exports.GET_ADV_DATA_REPLY_INVALID=exports.GET_ADV_DATA_FAIL=exports.WAIT_GET_ADV_DATA_REPLY_TIMEOUT=exports.PROPERTY_REPORT_API_FAIL=exports.DEVICE_INFO_INVALID=exports.WAIT_GET_DEVICE_INFO_TIMEOUT=exports.BLE_WRITE_ERROR=exports.EVENT_REPLY_ERROR=exports.GET_STATUS_ERROR=exports.REPORT_RESULT_ERROR=exports.CONTROL_DEVICE_REPLY_ERROR=exports.CONTROL_REPLY_CODE_INVALID=exports.UNBIND_REPLY_ERROR=exports.CONNECT_SIGN_VERIFY_ERROR=exports.CONNECT_SIGN_AUTH_ERROR=exports.PSK_GET_ERROR=exports.DEVICE_NAME_IS_EMPTY=exports.CANNOT_FIND_DEVICE=exports.CONNECT_DEVICE_ERROR=exports.CONTROL_ACTION_ERROR=exports.CONTROL_REPLY_INVALID=exports.UNBIND_REPLY_INVALID=exports.WAIT_CONTROL_ACTION_REPLY_TIMEOUT=exports.WAIT_CONTROL_DEVICE_REPLY_TIMEOUT=exports.WAIT_UNBIND_REPLY_TIMEOUT=exports.CONNECT_REPLY_INVALID=exports.WAIT_CONNECT_REPLY_TIMEOUT=exports.USER_NEED_LOGIN=exports.LL_OTA_WRITE_PREFIX=exports.OTA_UPDATE_DATA_END=exports.OTA_UPDATE_DATA=exports.OTA_UPDATE_REQUEST=exports.BLE_IOT_DATA_TYPE_ARRAY=exports.BLE_IOT_DATA_TYPE_STRUCT=exports.BLE_IOT_DATA_TYPE_TIME=exports.BLE_IOT_DATA_TYPE_ENUM=exports.BLE_IOT_DATA_TYPE_FLOAT=exports.BLE_IOT_DATA_TYPE_STRING=exports.BLE_IOT_DATA_TYPE_INT=exports.BLE_IOT_DATA_TYPE_BOOL=exports.ACTION_DESC=exports.WIFI_LOG_TYPE_MAP=exports.WIFI_MODE_MAP=exports.DEVICE_DATA_WRITE_SUFFIX=exports.DEVICE_DATA_WRITE_HEAD=exports.DEVICE_INFO_WRITE_PREFIX=exports.BleErrorMsg=exports.INDICATE_TYPE_MAP=exports.NOTIFY_BIND_SUCCESS=exports.NOTIFY_BIND_FAILED=exports.CONNECT_ACK=exports.CONNECT_REQUEST=exports.RESPONSE_BIND=exports.NOTIFY_BIND=exports.REQUEST_BIND_SUCCESS=exports.REQUEST_BIND_FAILED=exports.REQUEST_BIND=exports.GET_DEVICE_NAME_WITH_REGISTER_FAILED=exports.GET_DEVICE_NAME_WITH_REGISTER=exports.GET_DEVICE_NAME=exports.UNBIND_RESPONSE=exports.UNBIND_REQUEST=exports.REGISTER_DEVICE_SUCCESS=exports.REGISTER_DEVICE_ERROR=exports.REGISTER_DEVICE_INFO_REPLY_INVALID=exports.WAIT_REGISTER_DEVICE_INFO_REPLY_TIMEOUT=exports.SEND_REGISTER_DEVICE_PAYLOAD=exports.REGISTER_DEVICE_INFO_REPLY=exports.WRITE_USER_CHECK_CANCEL=exports.WRITE_USER_CHECK_TIMEOUT=exports.GET_USER_CHECK_TIMEOUT_SUCCESS=exports.GET_USER_CHECK_TIMEOUT_ERROR=exports.GET_USER_CHECK_TIMEOUT_TIMEOUT=exports.USER_CHECK_TIMEOUT_CALLBACK=exports.USER_CHECK_TIMEOUT=exports.GET_USER_CHECK_REJECT=exports.GET_USER_CHECK_APPROVE=exports.WAIT_USER_CHECK_TIMEOUT=exports.GET_ADV_DATA_RESULT=exports.NULL_WIFI_MODE=exports.STA_WIFI_MODE=exports.GET_DEV_LOG_INFO=exports.SET_WIFI_TOKEN_RESULT=exports.SET_WIFI_CONNECT_RESULT=exports.SET_WIFI_INFO_RESULT=exports.SET_WIFI_MODE_RESULT=exports.GET_DEV_LOG=exports.SET_WIFI_TOKEN=exports.SET_WIFI_CONNECT=exports.SET_WIFI_INFO=exports.SET_WIFI_MODE=exports.GET_DEVICE_INFO=exports.NOTIFY_LOCAL_RSSI=exports.HEARTBEAT_RESP=exports.HEARTBEAT_REQ=exports.GET_ADV_DATA_REPLY=exports.GET_ADV_DATA=exports.APP_ON_IOS_DEVICE=exports.APP_IS_READY=exports.VERIFY_SIGN_FAIL=exports.MTU_MODULE_CALLBACK=exports.WRITE_MTU_RESULT=exports.CONTROL_ACTION_SUCCESS=exports.TIME_SYNC=exports.UNBIND_AUTH=exports.UNBIND_RESULT_AUTH_FAIL=exports.UNBIND_RESULT_AUTH_SUCCESS=exports.CONNECT_RESULT_WRITE_FAIL=exports.CONNECT_RESULT_WRITE_SUCCESS=exports.ANDROID_SET_MTU=exports.DEVICE_INFO=exports.CONNECT_AUTH=exports.BIND_AUTH_FAIL=exports.BIND_AUTH_SUCCESS=exports.BIND_AUTH_DETAIL=exports.SET_MTU_BEFORE_CONNECT=exports.BIND_AUTH=exports.UPDATE_REPLY_INVALID=exports.UPDATE_DATA_CHECK_REPLY=exports.UPDATE_DATA_REPLY=exports.UPDATE_REPLY=exports.ACTION_REPLY=exports.EVENT_REPLY=exports.EVENT_REPORT=exports.GET_STATUS=exports.CONTROL_REPLY=exports.REPORT_RESULT=exports.CONTROL_ACTION=exports.CONTROL_DEVICE=exports.PROPERTY_REPORT=exports.LL_OTA_WRITE_ID=exports.DEVICE_EVENT_WRITE_ID=exports.DEVICE_DATA_WRITE_ID=exports.DEVICE_INFO_WRITE_ID=exports.DEVICE_STATE_MAP=exports.DEVICE_HAS_CONNECTED=exports.DEVICE_WAITING_BIND=exports.DEVICE_NOT_BIND=exports.DEVICE_HAS_BINDED=exports.REPORT_EVENT_TYPE=void 0;var PropertyReportReplyResult,tslib_1=require("tslib");exports.REPORT_EVENT_TYPE="standard-ble",exports.DEVICE_HAS_BINDED="DEVICE_HAS_BINDED",exports.DEVICE_NOT_BIND="DEVICE_NOT_BIND",exports.DEVICE_WAITING_BIND="DEVICE_WAITING_BIND",exports.DEVICE_HAS_CONNECTED="DEVICE_HAS_CONNECTED",exports.DEVICE_STATE_MAP={0:exports.DEVICE_NOT_BIND,1:exports.DEVICE_WAITING_BIND,2:exports.DEVICE_HAS_BINDED,3:exports.DEVICE_HAS_CONNECTED},exports.DEVICE_INFO_WRITE_ID="0000FFE1-65D0-4E20-B56A-E493541BA4E2",exports.DEVICE_DATA_WRITE_ID="0000FFE2-65D0-4E20-B56A-E493541BA4E2",exports.DEVICE_EVENT_WRITE_ID="0000FFE3-65D0-4E20-B56A-E493541BA4E2",exports.LL_OTA_WRITE_ID="0000FFE4-65D0-4E20-B56A-E493541BA4E2",exports.PROPERTY_REPORT="PROPERTY_REPORT",exports.CONTROL_DEVICE="CONTROL_DEVICE",exports.CONTROL_ACTION="CONTROL_ACTION",exports.REPORT_RESULT="REPORT_RESULT",exports.CONTROL_REPLY="CONTROL_REPLY",exports.GET_STATUS="GET_STATUS",exports.EVENT_REPORT="EVENT_REPORT",exports.EVENT_REPLY="EVENT_REPLY",exports.ACTION_REPLY="ACTION_REPLY",exports.UPDATE_REPLY="UPDATE_REPLY",exports.UPDATE_DATA_REPLY="UPDATE_DATA_REPLY",exports.UPDATE_DATA_CHECK_REPLY="UPDATE_DATA_CHECK_REPLY",exports.UPDATE_REPLY_INVALID="UPDATE_REPLY_INVALID",exports.BIND_AUTH="BIND_AUTH",exports.SET_MTU_BEFORE_CONNECT="SET_MTU_BEFORE_CONNECT",exports.BIND_AUTH_DETAIL="BIND_AUTH_DETAIL",exports.BIND_AUTH_SUCCESS="BIND_AUTH_SUCCESS",exports.BIND_AUTH_FAIL="BIND_AUTH_FAIL",exports.CONNECT_AUTH="CONNECT_AUTH",exports.DEVICE_INFO="DEVICE_INFO",exports.ANDROID_SET_MTU="ANDROID_SET_MTU",exports.CONNECT_RESULT_WRITE_SUCCESS="CONNECT_RESULT_WRITE_SUCCESS",exports.CONNECT_RESULT_WRITE_FAIL="CONNECT_RESULT_WRITE_FAIL",exports.UNBIND_RESULT_AUTH_SUCCESS="UNBIND_RESULT_AUTH_SUCCESS",exports.UNBIND_RESULT_AUTH_FAIL="UNBIND_RESULT_AUTH_FAIL",exports.UNBIND_AUTH="UNBIND_AUTH",exports.TIME_SYNC="TIME_SYNC",exports.CONTROL_ACTION_SUCCESS="CONTROL_ACTION_SUCCESS",exports.WRITE_MTU_RESULT="WRITE_MTU_RESULT",exports.MTU_MODULE_CALLBACK="MTU_MODULE_CALLBACK",exports.VERIFY_SIGN_FAIL="VERIFY_SIGN_FAIL",exports.APP_IS_READY="APP_IS_READY",exports.APP_ON_IOS_DEVICE="APP_ON_IOS_DEVICE",exports.GET_ADV_DATA="GET_ADV_DATA",exports.GET_ADV_DATA_REPLY="GET_ADV_DATA_REPLY",exports.HEARTBEAT_REQ="HEARTBEAT_REQ",exports.HEARTBEAT_RESP="HEARTBEAT_RESP",exports.NOTIFY_LOCAL_RSSI="NOTIFY_LOCAL_RSSI",exports.GET_DEVICE_INFO="GET_DEVICE_INFO",exports.SET_WIFI_MODE="SET_WIFI_MODE",exports.SET_WIFI_INFO="SET_WIFI_INFO",exports.SET_WIFI_CONNECT="SET_WIFI_CONNECT",exports.SET_WIFI_TOKEN="SET_WIFI_TOKEN",exports.GET_DEV_LOG="GET_DEV_LOG",exports.SET_WIFI_MODE_RESULT="SET_WIFI_MODE_RESULT",exports.SET_WIFI_INFO_RESULT="SET_WIFI_INFO_RESULT",exports.SET_WIFI_CONNECT_RESULT="SET_WIFI_CONNECT_RESULT",exports.SET_WIFI_TOKEN_RESULT="SET_WIFI_TOKEN_RESULT",exports.GET_DEV_LOG_INFO="GET_DEV_LOG_INFO",exports.STA_WIFI_MODE="STA_WIFI_MODE",exports.NULL_WIFI_MODE="NULL_WIFI_MODE",exports.GET_ADV_DATA_RESULT="GET_ADV_DATA_RESULT",exports.WAIT_USER_CHECK_TIMEOUT="WAIT_USER_CHECK_TIMEOUT",exports.GET_USER_CHECK_APPROVE="GET_USER_CHECK_APPROVE",exports.GET_USER_CHECK_REJECT="GET_USER_CHECK_REJECT",exports.USER_CHECK_TIMEOUT="USER_CHECK_TIMEOUT",exports.USER_CHECK_TIMEOUT_CALLBACK="USER_CHECK_TIMEOUT_CALLBACK",exports.GET_USER_CHECK_TIMEOUT_TIMEOUT="GET_USER_CHECK_TIMEOUT_TIMEOUT",exports.GET_USER_CHECK_TIMEOUT_ERROR="GET_USER_CHECK_TIMEOUT_ERROR",exports.GET_USER_CHECK_TIMEOUT_SUCCESS="GET_USER_CHECK_TIMEOUT_SUCCESS",exports.WRITE_USER_CHECK_TIMEOUT=1,exports.WRITE_USER_CHECK_CANCEL=0,exports.REGISTER_DEVICE_INFO_REPLY="REGISTER_DEVICE_INFO_REPLY",exports.SEND_REGISTER_DEVICE_PAYLOAD="SEND_REGISTER_DEVICE_PAYLOAD",exports.WAIT_REGISTER_DEVICE_INFO_REPLY_TIMEOUT="WAIT_REGISTER_DEVICE_INFO_REPLY_TIMEOUT",exports.REGISTER_DEVICE_INFO_REPLY_INVALID="REGISTER_DEVICE_INFO_REPLY_INVALID",exports.REGISTER_DEVICE_ERROR="REGISTER_DEVICE_ERROR",exports.REGISTER_DEVICE_SUCCESS="REGISTER_DEVICE_SUCCESS",exports.UNBIND_REQUEST="UnbindRequest",exports.UNBIND_RESPONSE="UnbindResponse",exports.GET_DEVICE_NAME="GET_DEVICE_NAME",exports.GET_DEVICE_NAME_WITH_REGISTER="GET_DEVICE_NAME_WITH_REGISTER",exports.GET_DEVICE_NAME_WITH_REGISTER_FAILED="GET_DEVICE_NAME_WITH_REGISTER_FAILED",exports.REQUEST_BIND="REQUEST_BIND",exports.REQUEST_BIND_FAILED="REQUEST_BIND_FAILED",exports.REQUEST_BIND_SUCCESS="REQUEST_BIND_SUCCESS",exports.NOTIFY_BIND="NOTIFY_BIND",exports.RESPONSE_BIND="RESPONSE_BIND",exports.CONNECT_REQUEST="CONNECT_REQUEST",exports.CONNECT_ACK="CONNECT_ACK",exports.NOTIFY_BIND_FAILED="NOTIFY_BIND_FAILED",exports.NOTIFY_BIND_SUCCESS="NOTIFY_BIND_SUCCESS",exports.INDICATE_TYPE_MAP={0:exports.PROPERTY_REPORT,1:exports.CONTROL_REPLY,2:exports.GET_STATUS,3:exports.EVENT_REPORT,4:exports.ACTION_REPLY,5:exports.BIND_AUTH,6:exports.CONNECT_AUTH,7:exports.UNBIND_AUTH,8:exports.DEVICE_INFO,9:exports.UPDATE_REPLY,10:exports.UPDATE_DATA_REPLY,11:exports.UPDATE_DATA_CHECK_REPLY,12:exports.MTU_MODULE_CALLBACK,13:exports.USER_CHECK_TIMEOUT_CALLBACK,14:exports.REGISTER_DEVICE_INFO_REPLY,17:exports.GET_DEVICE_NAME,18:exports.REQUEST_BIND,19:exports.NOTIFY_BIND,20:exports.RESPONSE_BIND,21:exports.CONNECT_REQUEST,22:exports.CONNECT_ACK,23:exports.UNBIND_REQUEST,24:exports.UNBIND_RESPONSE,25:exports.GET_DEVICE_NAME_WITH_REGISTER,26:exports.GET_ADV_DATA_REPLY,27:exports.HEARTBEAT_RESP,224:exports.SET_WIFI_MODE_RESULT,225:exports.SET_WIFI_INFO_RESULT,226:exports.SET_WIFI_CONNECT_RESULT,227:exports.SET_WIFI_TOKEN_RESULT,228:exports.GET_DEV_LOG_INFO},exports.BleErrorMsg={1:"BLE_QIOT_SIGN_ERR",2:"BLE_QIOT_BIND_ERR",3:"BLE_QIOT_CONN_ERR",4:"BLE_QIOT_UNBIND_ERR"},exports.DEVICE_INFO_WRITE_PREFIX=((_a={})[exports.TIME_SYNC]="00",_a[exports.CONNECT_AUTH]="01",_a[exports.BIND_AUTH_SUCCESS]="02",_a[exports.BIND_AUTH_FAIL]="03",_a[exports.UNBIND_AUTH]="04",_a[exports.CONNECT_RESULT_WRITE_SUCCESS]="05",_a[exports.CONNECT_RESULT_WRITE_FAIL]="06",_a[exports.UNBIND_RESULT_AUTH_SUCCESS]="07",_a[exports.UNBIND_RESULT_AUTH_FAIL]="08",_a[exports.WRITE_MTU_RESULT]="09",_a[exports.USER_CHECK_TIMEOUT]="0A",_a[exports.SEND_REGISTER_DEVICE_PAYLOAD]="0B",_a[exports.APP_IS_READY]="0C",_a[exports.APP_ON_IOS_DEVICE]="0D",_a[exports.GET_DEVICE_INFO]="E0",_a[exports.SET_WIFI_MODE]="E1",_a[exports.SET_WIFI_INFO]="E2",_a[exports.SET_WIFI_CONNECT]="E3",_a[exports.SET_WIFI_TOKEN]="E4",_a[exports.GET_DEV_LOG]="E5",_a[exports.GET_DEVICE_NAME]="11",_a[exports.REQUEST_BIND]="12",_a[exports.NOTIFY_BIND]="13",_a[exports.RESPONSE_BIND]="14",_a[exports.CONNECT_REQUEST]="15",_a[exports.CONNECT_ACK]="16",_a[exports.UNBIND_REQUEST]="17",_a[exports.UNBIND_RESPONSE]="18",_a[exports.GET_DEVICE_NAME_WITH_REGISTER]="19",_a[exports.GET_ADV_DATA]="1A",_a[exports.HEARTBEAT_REQ]="1B",_a[exports.NOTIFY_LOCAL_RSSI]="1C",_a),exports.DEVICE_DATA_WRITE_HEAD=((_b={})[exports.CONTROL_DEVICE]="000",_b[exports.REPORT_RESULT]="001",_b[exports.GET_STATUS]="001",_b[exports.EVENT_REPLY]="011",_b[exports.CONTROL_ACTION]="100",_b),exports.DEVICE_DATA_WRITE_SUFFIX=((_c={})[exports.CONTROL_DEVICE]="00000",_c[exports.REPORT_RESULT]="00000",_c[exports.GET_STATUS]="00010",_c),exports.WIFI_MODE_MAP=((_d={})[exports.NULL_WIFI_MODE]=0,_d[exports.STA_WIFI_MODE]=1,_d),exports.WIFI_LOG_TYPE_MAP={ERROR_LOG:0,NORMAL_LOG:1},exports.ACTION_DESC=((_e={})[exports.CONTROL_DEVICE]="远程控制",_e[exports.REPORT_RESULT]="属性上报结果通知",_e[exports.GET_STATUS]="写入设备最新状态",_e[exports.EVENT_REPLY]="处理设备端事件上报",_e[exports.CONTROL_ACTION]="对设备进行行为调用",_e[exports.CONTROL_ACTION_SUCCESS]="对设备进行行为调用成功",_e[exports.TIME_SYNC]="时间同步",_e[exports.CONNECT_AUTH]="连接鉴权",_e[exports.BIND_AUTH]="绑定鉴权",_e[exports.BIND_AUTH_DETAIL]="绑定鉴权详情",_e[exports.BIND_AUTH_SUCCESS]="绑定鉴权成功",_e[exports.UNBIND_AUTH]="解绑鉴权",_e[exports.CONNECT_RESULT_WRITE_SUCCESS]="连接小程序端鉴权成功",_e[exports.UNBIND_RESULT_AUTH_SUCCESS]="解绑小程序端鉴权成功",_e[exports.APP_IS_READY]="通知设备端小程序已经就绪",_e[exports.APP_ON_IOS_DEVICE]="通知设备端小程序运行于 iOS 环境",_e[exports.GET_ADV_DATA]="获取设备广播信息",_e[exports.HEARTBEAT_REQ]="蓝牙连接心跳",_e[exports.NOTIFY_LOCAL_RSSI]="同步小程序侧 RSSI",_e),exports.BLE_IOT_DATA_TYPE_BOOL="bool",exports.BLE_IOT_DATA_TYPE_INT="int",exports.BLE_IOT_DATA_TYPE_STRING="string",exports.BLE_IOT_DATA_TYPE_FLOAT="float",exports.BLE_IOT_DATA_TYPE_ENUM="enum",exports.BLE_IOT_DATA_TYPE_TIME="timestamp",exports.BLE_IOT_DATA_TYPE_STRUCT="struct",exports.BLE_IOT_DATA_TYPE_ARRAY="array",exports.OTA_UPDATE_REQUEST="OTA_UPDATE_REQUEST",exports.OTA_UPDATE_DATA="OTA_UPDATE_DATA",exports.OTA_UPDATE_DATA_END="OTA_UPDATE_DATA_END",exports.LL_OTA_WRITE_PREFIX=((_f={})[exports.OTA_UPDATE_REQUEST]="00",_f[exports.OTA_UPDATE_DATA]="01",_f[exports.OTA_UPDATE_DATA_END]="02",_f),exports.USER_NEED_LOGIN="USER_NEED_LOGIN",exports.WAIT_CONNECT_REPLY_TIMEOUT="WAIT_CONNECT_REPLY_TIMEOUT",exports.CONNECT_REPLY_INVALID="CONNECT_REPLY_INVALID",exports.WAIT_UNBIND_REPLY_TIMEOUT="WAIT_UNBIND_REPLY_TIMEOUT",exports.WAIT_CONTROL_DEVICE_REPLY_TIMEOUT="WAIT_CONTROL_DEVICE_REPLY_TIMEOUT",exports.WAIT_CONTROL_ACTION_REPLY_TIMEOUT="WAIT_CONTROL_ACTION_REPLY_TIMEOUT",exports.UNBIND_REPLY_INVALID="UNBIND_REPLY_INVALID",exports.CONTROL_REPLY_INVALID="CONTROL_REPLY_INVALID",exports.CONTROL_ACTION_ERROR="CONTROL_ACTION_ERROR",exports.CONNECT_DEVICE_ERROR="CONNECT_DEVICE_ERROR",exports.CANNOT_FIND_DEVICE="CANNOT_FIND_DEVICE",exports.DEVICE_NAME_IS_EMPTY="DEVICE_NAME_IS_EMPTY",exports.PSK_GET_ERROR="PSK_GET_ERROR",exports.CONNECT_SIGN_AUTH_ERROR="CONNECT_SIGN_AUTH_ERROR",exports.CONNECT_SIGN_VERIFY_ERROR="CONNECT_SIGN_VERIFY_ERROR",exports.UNBIND_REPLY_ERROR="UNBIND_REPLY_ERROR",exports.CONTROL_REPLY_CODE_INVALID="CONTROL_REPLY_CODE_INVALID",exports.CONTROL_DEVICE_REPLY_ERROR="CONTROL_DEVICE_REPLY_ERROR",exports.REPORT_RESULT_ERROR="REPORT_RESULT_ERROR",exports.GET_STATUS_ERROR="GET_STATUS_ERROR",exports.EVENT_REPLY_ERROR="EVENT_REPLY_ERROR",exports.BLE_WRITE_ERROR="BLE_WRITE_ERROR",exports.WAIT_GET_DEVICE_INFO_TIMEOUT="WAIT_GET_DEVICE_INFO_TIMEOUT",exports.DEVICE_INFO_INVALID="DEVICE_INFO_INVALID",exports.PROPERTY_REPORT_API_FAIL="PROPERTY_REPORT_API_FAIL",exports.WAIT_GET_ADV_DATA_REPLY_TIMEOUT="WAIT_GET_ADV_DATA_REPLY_TIMEOUT",exports.GET_ADV_DATA_FAIL="GET_ADV_DATA_FAIL",exports.GET_ADV_DATA_REPLY_INVALID="GET_ADV_DATA_REPLY_INVALID",exports.WAIT_GET_UPDATE_INFO_TIMEOUT="WAIT_GET_UPDATE_INFO_TIMEOUT",exports.WAIT_MODULE_UPDATE_TIMEOUT="WAIT_MODULE_UPDATE_TIMEOUT",exports.SET_WIFI_MODE_RESULT_INVALID="SET_WIFI_MODE_RESULT_INVALID",exports.SET_WIFI_MODE_RESULT_TIMEOUT="SET_WIFI_MODE_RESULT_TIMEOUT",exports.SET_WIFI_INFO_RESULT_INVALID="SET_WIFI_INFO_INVALID",exports.SET_WIFI_INFO_RESULT_TIMEOUT="SET_WIFI_INFO_TIMEOUT",exports.SET_WIFI_CONNECT_RESULT_INVALID="SET_WIFI_CONNECT_RESULT_INVALID",exports.SET_WIFI_CONNECT_RESULT_TIMEOUT="SET_WIFI_CONNECT_RESULT_TIMEOUT",exports.SET_WIFI_TOKEN_RESULT_INVALID="SET_WIFI_TOKEN_RESULT_INVALID",exports.SET_WIFI_TOKEN_RESULT_TIMEOUT="SET_WIFI_TOKEN_RESULT_TIMEOUT",exports.GET_DEV_LOG_INFO_INVALID="GET_DEV_LOG_INFO_INVALID",exports.GET_DEV_LOG_INFO_TIMEOUT="GET_DEV_LOG_INFO_TIMEOUT",exports.OTA_UPDATE_STEPS={GET_OTA_UPDATE_INFO:"GET_OTA_UPDATE_INFO",GET_OTA_UPDATE_INFO_SUCCESS:"GET_OTA_UPDATE_INFO_SUCCESS",DOWNLOADING_OTA_FILE:"DOWNLOADING_OTA_FILE",DOWNLOADING_OTA_FILE_DETAIL:"DOWNLOADING_OTA_FILE_DETAIL",DOWNLOAD_OTA_FILE_SUCCESS:"DOWNLOAD_OTA_FILE_SUCCESS",REQUEST_MODULE_UPDATE_START:"REQUEST_MODULE_UPDATE",REQUEST_MODULE_UPDATE_SUCCESS:"REQUEST_MODULE_UPDATE_SUCCESS",MODULE_UPDATE_CHECK_FILE_SUCCESS:"MODULE_UPDATE_CHECK_FILE_SUCCESS",SEND_UPDATE_DATA_START:"SEND_UPDATE_DATA_START",SEND_UPDATE_DATA_DETAIL:"SEND_UPDATE_DATA_DETAIL",SEND_UPDATE_DATA_SUCCESS:"SEND_UPDATE_DATA_SUCCESS",WAITING_MODULE_UPDATE:"WAITING_MODULE_UPDATE",MODULE_UPDATE_SUCCESS:"MODULE_UPDATE_SUCCESS"},exports.OTA_UPDATE_STEPS_MESSAGE=((_g={})[exports.OTA_UPDATE_STEPS.GET_OTA_UPDATE_INFO]="获取固件版本信息",_g[exports.OTA_UPDATE_STEPS.GET_OTA_UPDATE_INFO_SUCCESS]="获取固件版本信息成功",_g[exports.OTA_UPDATE_STEPS.DOWNLOADING_OTA_FILE]="正在下载OTA文件",_g[exports.OTA_UPDATE_STEPS.DOWNLOADING_OTA_FILE_DETAIL]="正在下载OTA文件详情",_g[exports.OTA_UPDATE_STEPS.DOWNLOAD_OTA_FILE_SUCCESS]="下载OTA文件成功",_g[exports.OTA_UPDATE_STEPS.REQUEST_MODULE_UPDATE_START]="开始检查设备端固件升级支持情况",_g[exports.OTA_UPDATE_STEPS.REQUEST_MODULE_UPDATE_SUCCESS]="检查设备端固件升级支持情况成功",_g[exports.OTA_UPDATE_STEPS.SEND_UPDATE_DATA_START]="开始发送固件升级文件",_g[exports.OTA_UPDATE_STEPS.SEND_UPDATE_DATA_DETAIL]="固件升级文件详情",_g[exports.OTA_UPDATE_STEPS.SEND_UPDATE_DATA_SUCCESS]="固件升级文件发送成功",_g[exports.OTA_UPDATE_STEPS.WAITING_MODULE_UPDATE]="开始烧录固件升级文件",_g[exports.OTA_UPDATE_STEPS.MODULE_UPDATE_SUCCESS]="设备端固件升级成功",_g),exports.OTA_UPDATE_ERRORS=((_h={GET_OTA_INFO_FAIL:"获取OTA升级信息失败",MODULE_VERSION_IS_UPDATED:"设备端固件已经是最新版",MODULE_DONNOT_SUPPORT:"设备端固件不支持",USER_CANCEL_OTA_UPDATE:"用户取消固件升级",MODULE_DONNOT_ALLOW:"设备端固件不允许,可能是当前状态不允许",MODULE_UPDATE_CHECK_FILE_FAIL:"升级文件校验失败",GET_FILE_CRC_ERROR:"获取文件和crc错误"})[exports.WAIT_GET_UPDATE_INFO_TIMEOUT]="获取设备端分片包回包超时",_h[exports.WAIT_MODULE_UPDATE_TIMEOUT]="等待设备端升级超时",_h.UPDATE_DATA_REPLAY_TIMEOUT="发送固件升级文件超时",_h.MODULE_UPDATE_FAIL="设备端固件升级失败",_h.MODULE_UPDATE_CONNECT_TIMEOUT="设备端固件升级连接设备超时",_h.BLE_CONNECTION_BREAK="蓝牙连接断开",_h),exports.BLE_COMBO_ERRORS=((_j={})[exports.SET_WIFI_MODE_RESULT_INVALID]="设置WiFi模式返回格式错误",_j[exports.SET_WIFI_MODE_RESULT_TIMEOUT]="设置WiFi模式返回超时,请稍后再试",_j[exports.SET_WIFI_INFO_RESULT_INVALID]="WiFi信息传输返回格式错误",_j[exports.SET_WIFI_INFO_RESULT_TIMEOUT]="WiFi信息传输返回超时,请稍后再试",_j[exports.SET_WIFI_CONNECT_RESULT_INVALID]="WiFi连接失败",_j[exports.SET_WIFI_CONNECT_RESULT_TIMEOUT]="获取WiFi连接状态超时",_j[exports.SET_WIFI_TOKEN_RESULT_INVALID]="发送配网token结果非法",_j[exports.SET_WIFI_TOKEN_RESULT_TIMEOUT]="发送配网token结果超时,请稍后再试",_j[exports.GET_DEV_LOG_INFO_INVALID]="获取配网日志格式错误",_j[exports.GET_DEV_LOG_INFO_TIMEOUT]="获取配网日志超时,请稍后再试",_j),exports.MODULE_UPDATE_REPLAY_CODE_MAP={0:"设备电量不足",1:"版本号错误"},exports.MODULE_UPDATE_DATA_REPLAY_CODE_MAP={1:exports.OTA_UPDATE_STEPS.MODULE_UPDATE_CHECK_FILE_SUCCESS,0:"MODULE_UPDATE_CHECK_FILE_FAIL"},exports.MODULE_UPDATE_REPLAY_DATA_CODE_MAP={0:"CRC错误",1:"文件读取失败",2:"文件错误"},exports.WAIT_MODULE_UPDATE_CONNECT_TIMES=5,exports.WAIT_MODULE_UPDATE_CONNECT_TIME_GAP=2e3,exports.UPDATE_WRITE_ERROR_TIMES_PER_CIRCLE=5,exports.MAX_WRITE_DATA_WAIT_GAP=200,exports.ERROR_MESSAGES=tslib_1.__assign(tslib_1.__assign(((_k={})[exports.USER_NEED_LOGIN]="用户未登录,不能连接蓝牙",_k[exports.CONTROL_ACTION_ERROR]="行为调用失败",_k[exports.CONNECT_DEVICE_ERROR]="连接设备失败",_k[exports.CANNOT_FIND_DEVICE]="无法找到设备",_k[exports.USER_NEED_LOGIN]="请重新登录",_k[exports.WAIT_CONNECT_REPLY_TIMEOUT]="等待连接回复超时",_k[exports.CONNECT_REPLY_INVALID]="等待连接回复非法",_k[exports.GET_USER_CHECK_REJECT]="用户端确认拒绝",_k[exports.WAIT_USER_CHECK_TIMEOUT]="等待用户确认超时",_k[exports.GET_USER_CHECK_TIMEOUT_TIMEOUT]="获取设备端用户确认超时时间超时,使用默认超时时间",_k[exports.GET_USER_CHECK_TIMEOUT_ERROR]="获取设备端用户确认超时时间失败,使用默认超时时间",_k[exports.DEVICE_NAME_IS_EMPTY]="设备名称非法",_k[exports.PSK_GET_ERROR]="获取local psk失败",_k[exports.CONNECT_SIGN_AUTH_ERROR]="获取连接认证失败",_k[exports.WAIT_UNBIND_REPLY_TIMEOUT]="获取解绑回复超时",_k[exports.UNBIND_REPLY_INVALID]="解绑回复非法",_k[exports.UNBIND_REPLY_ERROR]="解绑回复失败",_k[exports.WAIT_CONTROL_DEVICE_REPLY_TIMEOUT]="等待控制设备回复超时",_k[exports.CONTROL_DEVICE_REPLY_ERROR]="控制设备失败",_k[exports.CONTROL_REPLY_INVALID]="等待控制设备回复非法",_k[exports.BIND_AUTH_FAIL]="绑定鉴权失败",_k[exports.UNBIND_RESULT_AUTH_FAIL]="解绑小程序端鉴权失败",_k[exports.CONNECT_RESULT_WRITE_FAIL]="连接小程序端鉴权失败",_k[exports.CONTROL_REPLY_CODE_INVALID]="设备端控制回包code非0",_k[exports.REPORT_RESULT_ERROR]="上报设备最新状态失败",_k[exports.GET_STATUS_ERROR]="获取最新状态失败",_k[exports.EVENT_REPLY_ERROR]="EVENT_REPLY_ERROR",_k[exports.BLE_WRITE_ERROR]="设备写入失败",_k[exports.WAIT_GET_DEVICE_INFO_TIMEOUT]="获取设备信息超时",_k[exports.DEVICE_INFO_INVALID]="设备版本和MTU信息非法",_k.ID_TEMPLATE_IS_NOT_EXIT="设备端传的id在物模型里面不存在",_k.TYPE_IN_MODULE_IS_WRONG="设备端的type和后台的不一致",_k[exports.PROPERTY_REPORT_API_FAIL]="属性上报云端回复失败",_k),exports.OTA_UPDATE_ERRORS),((_l={})[exports.REGISTER_DEVICE_ERROR]="从云端动态注册失败",_l[exports.REGISTER_DEVICE_INFO_REPLY_INVALID]="设备端回复的云端注册信息非法",_l[exports.WAIT_REGISTER_DEVICE_INFO_REPLY_TIMEOUT]="等待设备端回复的云端注册信息超时",_l[exports.WAIT_GET_ADV_DATA_REPLY_TIMEOUT]="等待设备端回复广播信息超时",_l[exports.GET_ADV_DATA_FAIL]="设备端回复获取广播信息失败",_l)),function(_){_[_.Success=0]="Success",_[_.Fail=1]="Fail",_[_.ParseDataFail=2]="ParseDataFail"}(PropertyReportReplyResult=exports.PropertyReportReplyResult||(exports.PropertyReportReplyResult={})),exports.WRITE_DATA_CANCEL_ERROR_CODE="BLE_WRITE_CHARACTERISTIC_CANCELLED",exports.MIN_ATT_MTU=23,exports.ATT_MTU_TO_LLSYNC_MTU_DELTA=3; | ||
"use strict";var _a,_b,_c,_d,_e,_f,_g,_h,_j,_k,_l;Object.defineProperty(exports,"__esModule",{value:!0}),exports.ATT_MTU_TO_LLSYNC_MTU_DELTA=exports.MIN_ATT_MTU=exports.CheckSecureBindInfoErrorCode=exports.WRITE_DATA_CANCEL_ERROR_CODE=exports.PropertyReportReplyResult=exports.ERROR_MESSAGES=exports.MAX_WRITE_DATA_WAIT_GAP=exports.UPDATE_WRITE_ERROR_TIMES_PER_CIRCLE=exports.WAIT_MODULE_UPDATE_CONNECT_TIME_GAP=exports.WAIT_MODULE_UPDATE_CONNECT_TIMES=exports.MODULE_UPDATE_REPLAY_DATA_CODE_MAP=exports.MODULE_UPDATE_DATA_REPLAY_CODE_MAP=exports.MODULE_UPDATE_REPLAY_CODE_MAP=exports.BLE_COMBO_ERRORS=exports.OTA_UPDATE_ERRORS=exports.OTA_UPDATE_STEPS_MESSAGE=exports.OTA_UPDATE_STEPS=exports.GET_DEV_LOG_INFO_TIMEOUT=exports.GET_DEV_LOG_INFO_INVALID=exports.SET_WIFI_TOKEN_RESULT_TIMEOUT=exports.SET_WIFI_TOKEN_RESULT_INVALID=exports.SET_WIFI_CONNECT_RESULT_TIMEOUT=exports.SET_WIFI_CONNECT_RESULT_INVALID=exports.SET_WIFI_INFO_RESULT_TIMEOUT=exports.SET_WIFI_INFO_RESULT_INVALID=exports.SET_WIFI_MODE_RESULT_TIMEOUT=exports.SET_WIFI_MODE_RESULT_INVALID=exports.WAIT_MODULE_UPDATE_TIMEOUT=exports.WAIT_GET_UPDATE_INFO_TIMEOUT=exports.CHECK_SECURE_BIND_INFO_REPLY_INVALID=exports.CHECK_SECURE_BIND_INFO_REPLY_TIMEOUT=exports.CHECK_SECURE_BIND_INFO_FAIL=exports.GET_ADV_DATA_REPLY_INVALID=exports.GET_ADV_DATA_FAIL=exports.WAIT_GET_ADV_DATA_REPLY_TIMEOUT=exports.PROPERTY_REPORT_API_FAIL=exports.DEVICE_INFO_INVALID=exports.WAIT_GET_DEVICE_INFO_TIMEOUT=exports.BLE_WRITE_ERROR=exports.EVENT_REPLY_ERROR=exports.GET_STATUS_ERROR=exports.REPORT_RESULT_ERROR=exports.CONTROL_DEVICE_REPLY_ERROR=exports.CONTROL_REPLY_CODE_INVALID=exports.UNBIND_REPLY_ERROR=exports.CONNECT_SIGN_VERIFY_ERROR=exports.CONNECT_SIGN_AUTH_ERROR=exports.PSK_GET_ERROR=exports.DEVICE_NAME_IS_EMPTY=exports.CANNOT_FIND_DEVICE=exports.CONNECT_DEVICE_ERROR=exports.CONTROL_ACTION_ERROR=exports.CONTROL_REPLY_INVALID=exports.UNBIND_REPLY_INVALID=exports.WAIT_CONTROL_ACTION_REPLY_TIMEOUT=exports.WAIT_CONTROL_DEVICE_REPLY_TIMEOUT=exports.WAIT_UNBIND_REPLY_TIMEOUT=exports.CONNECT_REPLY_INVALID=exports.WAIT_CONNECT_REPLY_TIMEOUT=exports.USER_NEED_LOGIN=exports.LL_OTA_WRITE_PREFIX=exports.OTA_UPDATE_DATA_END=exports.OTA_UPDATE_DATA=exports.OTA_UPDATE_REQUEST=exports.BLE_IOT_DATA_TYPE_ARRAY=exports.BLE_IOT_DATA_TYPE_STRUCT=exports.BLE_IOT_DATA_TYPE_TIME=exports.BLE_IOT_DATA_TYPE_ENUM=exports.BLE_IOT_DATA_TYPE_FLOAT=exports.BLE_IOT_DATA_TYPE_STRING=exports.BLE_IOT_DATA_TYPE_INT=exports.BLE_IOT_DATA_TYPE_BOOL=exports.ACTION_DESC=exports.WIFI_LOG_TYPE_MAP=exports.WIFI_MODE_MAP=exports.DEVICE_DATA_WRITE_SUFFIX=exports.DEVICE_DATA_WRITE_HEAD=exports.DEVICE_INFO_WRITE_PREFIX=exports.BleErrorMsg=exports.INDICATE_TYPE_MAP=exports.NOTIFY_BIND_SUCCESS=exports.NOTIFY_BIND_FAILED=exports.CONNECT_ACK=exports.CONNECT_REQUEST=exports.RESPONSE_BIND=exports.NOTIFY_BIND=exports.REQUEST_BIND_SUCCESS=exports.REQUEST_BIND_FAILED=exports.REQUEST_BIND=exports.GET_DEVICE_NAME_WITH_REGISTER_FAILED=exports.GET_DEVICE_NAME_WITH_REGISTER=exports.GET_DEVICE_NAME=exports.UNBIND_RESPONSE=exports.UNBIND_REQUEST=exports.REGISTER_DEVICE_SUCCESS=exports.REGISTER_DEVICE_ERROR=exports.REGISTER_DEVICE_INFO_REPLY_INVALID=exports.WAIT_REGISTER_DEVICE_INFO_REPLY_TIMEOUT=exports.SEND_REGISTER_DEVICE_PAYLOAD=exports.REGISTER_DEVICE_INFO_REPLY=exports.WRITE_USER_CHECK_CANCEL=exports.WRITE_USER_CHECK_TIMEOUT=exports.GET_USER_CHECK_TIMEOUT_SUCCESS=exports.GET_USER_CHECK_TIMEOUT_ERROR=exports.GET_USER_CHECK_TIMEOUT_TIMEOUT=exports.USER_CHECK_TIMEOUT_CALLBACK=exports.USER_CHECK_TIMEOUT=exports.GET_USER_CHECK_REJECT=exports.GET_USER_CHECK_APPROVE=exports.WAIT_USER_CHECK_TIMEOUT=exports.GET_ADV_DATA_RESULT=exports.NULL_WIFI_MODE=exports.STA_WIFI_MODE=exports.GET_DEV_LOG_INFO=exports.SET_WIFI_TOKEN_RESULT=exports.SET_WIFI_CONNECT_RESULT=exports.SET_WIFI_INFO_RESULT=exports.SET_WIFI_MODE_RESULT=exports.GET_DEV_LOG=exports.SET_WIFI_TOKEN=exports.SET_WIFI_CONNECT=exports.SET_WIFI_INFO=exports.SET_WIFI_MODE=exports.GET_DEVICE_INFO=exports.CHECK_SECURE_BIND_INFO_REQUIRED=exports.CHECK_SECURE_BIND_INFO_REPLY=exports.CHECK_SECURE_BIND_INFO=exports.NOTIFY_LOCAL_RSSI=exports.HEARTBEAT_RESP=exports.HEARTBEAT_REQ=exports.GET_ADV_DATA_REPLY=exports.GET_ADV_DATA=exports.APP_ON_IOS_DEVICE=exports.APP_IS_READY=exports.VERIFY_SIGN_FAIL=exports.MTU_MODULE_CALLBACK=exports.WRITE_MTU_RESULT=exports.CONTROL_ACTION_SUCCESS=exports.TIME_SYNC=exports.UNBIND_AUTH=exports.UNBIND_RESULT_AUTH_FAIL=exports.UNBIND_RESULT_AUTH_SUCCESS=exports.CONNECT_RESULT_WRITE_FAIL=exports.CONNECT_RESULT_WRITE_SUCCESS=exports.ANDROID_SET_MTU=exports.DEVICE_INFO=exports.CONNECT_AUTH=exports.BIND_AUTH_FAIL=exports.BIND_AUTH_SUCCESS=exports.BIND_AUTH_DETAIL=exports.SET_MTU_BEFORE_CONNECT=exports.BIND_AUTH=exports.UPDATE_REPLY_INVALID=exports.UPDATE_DATA_CHECK_REPLY=exports.UPDATE_DATA_REPLY=exports.UPDATE_REPLY=exports.ACTION_REPLY=exports.EVENT_REPLY=exports.EVENT_REPORT=exports.GET_STATUS=exports.CONTROL_REPLY=exports.REPORT_RESULT=exports.CONTROL_ACTION=exports.CONTROL_DEVICE=exports.PROPERTY_REPORT=exports.LL_OTA_WRITE_ID=exports.DEVICE_EVENT_WRITE_ID=exports.DEVICE_DATA_WRITE_ID=exports.DEVICE_INFO_WRITE_ID=exports.DEVICE_STATE_MAP=exports.DEVICE_HAS_CONNECTED=exports.DEVICE_WAITING_BIND=exports.DEVICE_NOT_BIND=exports.DEVICE_HAS_BINDED=exports.REPORT_EVENT_TYPE=void 0;var PropertyReportReplyResult,CheckSecureBindInfoErrorCode,tslib_1=require("tslib");exports.REPORT_EVENT_TYPE="standard-ble",exports.DEVICE_HAS_BINDED="DEVICE_HAS_BINDED",exports.DEVICE_NOT_BIND="DEVICE_NOT_BIND",exports.DEVICE_WAITING_BIND="DEVICE_WAITING_BIND",exports.DEVICE_HAS_CONNECTED="DEVICE_HAS_CONNECTED",exports.DEVICE_STATE_MAP={0:exports.DEVICE_NOT_BIND,1:exports.DEVICE_WAITING_BIND,2:exports.DEVICE_HAS_BINDED,3:exports.DEVICE_HAS_CONNECTED},exports.DEVICE_INFO_WRITE_ID="0000FFE1-65D0-4E20-B56A-E493541BA4E2",exports.DEVICE_DATA_WRITE_ID="0000FFE2-65D0-4E20-B56A-E493541BA4E2",exports.DEVICE_EVENT_WRITE_ID="0000FFE3-65D0-4E20-B56A-E493541BA4E2",exports.LL_OTA_WRITE_ID="0000FFE4-65D0-4E20-B56A-E493541BA4E2",exports.PROPERTY_REPORT="PROPERTY_REPORT",exports.CONTROL_DEVICE="CONTROL_DEVICE",exports.CONTROL_ACTION="CONTROL_ACTION",exports.REPORT_RESULT="REPORT_RESULT",exports.CONTROL_REPLY="CONTROL_REPLY",exports.GET_STATUS="GET_STATUS",exports.EVENT_REPORT="EVENT_REPORT",exports.EVENT_REPLY="EVENT_REPLY",exports.ACTION_REPLY="ACTION_REPLY",exports.UPDATE_REPLY="UPDATE_REPLY",exports.UPDATE_DATA_REPLY="UPDATE_DATA_REPLY",exports.UPDATE_DATA_CHECK_REPLY="UPDATE_DATA_CHECK_REPLY",exports.UPDATE_REPLY_INVALID="UPDATE_REPLY_INVALID",exports.BIND_AUTH="BIND_AUTH",exports.SET_MTU_BEFORE_CONNECT="SET_MTU_BEFORE_CONNECT",exports.BIND_AUTH_DETAIL="BIND_AUTH_DETAIL",exports.BIND_AUTH_SUCCESS="BIND_AUTH_SUCCESS",exports.BIND_AUTH_FAIL="BIND_AUTH_FAIL",exports.CONNECT_AUTH="CONNECT_AUTH",exports.DEVICE_INFO="DEVICE_INFO",exports.ANDROID_SET_MTU="ANDROID_SET_MTU",exports.CONNECT_RESULT_WRITE_SUCCESS="CONNECT_RESULT_WRITE_SUCCESS",exports.CONNECT_RESULT_WRITE_FAIL="CONNECT_RESULT_WRITE_FAIL",exports.UNBIND_RESULT_AUTH_SUCCESS="UNBIND_RESULT_AUTH_SUCCESS",exports.UNBIND_RESULT_AUTH_FAIL="UNBIND_RESULT_AUTH_FAIL",exports.UNBIND_AUTH="UNBIND_AUTH",exports.TIME_SYNC="TIME_SYNC",exports.CONTROL_ACTION_SUCCESS="CONTROL_ACTION_SUCCESS",exports.WRITE_MTU_RESULT="WRITE_MTU_RESULT",exports.MTU_MODULE_CALLBACK="MTU_MODULE_CALLBACK",exports.VERIFY_SIGN_FAIL="VERIFY_SIGN_FAIL",exports.APP_IS_READY="APP_IS_READY",exports.APP_ON_IOS_DEVICE="APP_ON_IOS_DEVICE",exports.GET_ADV_DATA="GET_ADV_DATA",exports.GET_ADV_DATA_REPLY="GET_ADV_DATA_REPLY",exports.HEARTBEAT_REQ="HEARTBEAT_REQ",exports.HEARTBEAT_RESP="HEARTBEAT_RESP",exports.NOTIFY_LOCAL_RSSI="NOTIFY_LOCAL_RSSI",exports.CHECK_SECURE_BIND_INFO="CHECK_SECURE_BIND_INFO",exports.CHECK_SECURE_BIND_INFO_REPLY="CHECK_SECURE_BIND_INFO_REPLY",exports.CHECK_SECURE_BIND_INFO_REQUIRED="CHECK_SECURE_BIND_INFO_REQUIRED",exports.GET_DEVICE_INFO="GET_DEVICE_INFO",exports.SET_WIFI_MODE="SET_WIFI_MODE",exports.SET_WIFI_INFO="SET_WIFI_INFO",exports.SET_WIFI_CONNECT="SET_WIFI_CONNECT",exports.SET_WIFI_TOKEN="SET_WIFI_TOKEN",exports.GET_DEV_LOG="GET_DEV_LOG",exports.SET_WIFI_MODE_RESULT="SET_WIFI_MODE_RESULT",exports.SET_WIFI_INFO_RESULT="SET_WIFI_INFO_RESULT",exports.SET_WIFI_CONNECT_RESULT="SET_WIFI_CONNECT_RESULT",exports.SET_WIFI_TOKEN_RESULT="SET_WIFI_TOKEN_RESULT",exports.GET_DEV_LOG_INFO="GET_DEV_LOG_INFO",exports.STA_WIFI_MODE="STA_WIFI_MODE",exports.NULL_WIFI_MODE="NULL_WIFI_MODE",exports.GET_ADV_DATA_RESULT="GET_ADV_DATA_RESULT",exports.WAIT_USER_CHECK_TIMEOUT="WAIT_USER_CHECK_TIMEOUT",exports.GET_USER_CHECK_APPROVE="GET_USER_CHECK_APPROVE",exports.GET_USER_CHECK_REJECT="GET_USER_CHECK_REJECT",exports.USER_CHECK_TIMEOUT="USER_CHECK_TIMEOUT",exports.USER_CHECK_TIMEOUT_CALLBACK="USER_CHECK_TIMEOUT_CALLBACK",exports.GET_USER_CHECK_TIMEOUT_TIMEOUT="GET_USER_CHECK_TIMEOUT_TIMEOUT",exports.GET_USER_CHECK_TIMEOUT_ERROR="GET_USER_CHECK_TIMEOUT_ERROR",exports.GET_USER_CHECK_TIMEOUT_SUCCESS="GET_USER_CHECK_TIMEOUT_SUCCESS",exports.WRITE_USER_CHECK_TIMEOUT=1,exports.WRITE_USER_CHECK_CANCEL=0,exports.REGISTER_DEVICE_INFO_REPLY="REGISTER_DEVICE_INFO_REPLY",exports.SEND_REGISTER_DEVICE_PAYLOAD="SEND_REGISTER_DEVICE_PAYLOAD",exports.WAIT_REGISTER_DEVICE_INFO_REPLY_TIMEOUT="WAIT_REGISTER_DEVICE_INFO_REPLY_TIMEOUT",exports.REGISTER_DEVICE_INFO_REPLY_INVALID="REGISTER_DEVICE_INFO_REPLY_INVALID",exports.REGISTER_DEVICE_ERROR="REGISTER_DEVICE_ERROR",exports.REGISTER_DEVICE_SUCCESS="REGISTER_DEVICE_SUCCESS",exports.UNBIND_REQUEST="UnbindRequest",exports.UNBIND_RESPONSE="UnbindResponse",exports.GET_DEVICE_NAME="GET_DEVICE_NAME",exports.GET_DEVICE_NAME_WITH_REGISTER="GET_DEVICE_NAME_WITH_REGISTER",exports.GET_DEVICE_NAME_WITH_REGISTER_FAILED="GET_DEVICE_NAME_WITH_REGISTER_FAILED",exports.REQUEST_BIND="REQUEST_BIND",exports.REQUEST_BIND_FAILED="REQUEST_BIND_FAILED",exports.REQUEST_BIND_SUCCESS="REQUEST_BIND_SUCCESS",exports.NOTIFY_BIND="NOTIFY_BIND",exports.RESPONSE_BIND="RESPONSE_BIND",exports.CONNECT_REQUEST="CONNECT_REQUEST",exports.CONNECT_ACK="CONNECT_ACK",exports.NOTIFY_BIND_FAILED="NOTIFY_BIND_FAILED",exports.NOTIFY_BIND_SUCCESS="NOTIFY_BIND_SUCCESS",exports.INDICATE_TYPE_MAP={0:exports.PROPERTY_REPORT,1:exports.CONTROL_REPLY,2:exports.GET_STATUS,3:exports.EVENT_REPORT,4:exports.ACTION_REPLY,5:exports.BIND_AUTH,6:exports.CONNECT_AUTH,7:exports.UNBIND_AUTH,8:exports.DEVICE_INFO,9:exports.UPDATE_REPLY,10:exports.UPDATE_DATA_REPLY,11:exports.UPDATE_DATA_CHECK_REPLY,12:exports.MTU_MODULE_CALLBACK,13:exports.USER_CHECK_TIMEOUT_CALLBACK,14:exports.REGISTER_DEVICE_INFO_REPLY,17:exports.GET_DEVICE_NAME,18:exports.REQUEST_BIND,19:exports.NOTIFY_BIND,20:exports.RESPONSE_BIND,21:exports.CONNECT_REQUEST,22:exports.CONNECT_ACK,23:exports.UNBIND_REQUEST,24:exports.UNBIND_RESPONSE,25:exports.GET_DEVICE_NAME_WITH_REGISTER,26:exports.GET_ADV_DATA_REPLY,27:exports.HEARTBEAT_RESP,30:exports.CHECK_SECURE_BIND_INFO_REPLY,224:exports.SET_WIFI_MODE_RESULT,225:exports.SET_WIFI_INFO_RESULT,226:exports.SET_WIFI_CONNECT_RESULT,227:exports.SET_WIFI_TOKEN_RESULT,228:exports.GET_DEV_LOG_INFO},exports.BleErrorMsg={1:"BLE_QIOT_SIGN_ERR",2:"BLE_QIOT_BIND_ERR",3:"BLE_QIOT_CONN_ERR",4:"BLE_QIOT_UNBIND_ERR"},exports.DEVICE_INFO_WRITE_PREFIX=((_a={})[exports.TIME_SYNC]="00",_a[exports.CONNECT_AUTH]="01",_a[exports.BIND_AUTH_SUCCESS]="02",_a[exports.BIND_AUTH_FAIL]="03",_a[exports.UNBIND_AUTH]="04",_a[exports.CONNECT_RESULT_WRITE_SUCCESS]="05",_a[exports.CONNECT_RESULT_WRITE_FAIL]="06",_a[exports.UNBIND_RESULT_AUTH_SUCCESS]="07",_a[exports.UNBIND_RESULT_AUTH_FAIL]="08",_a[exports.WRITE_MTU_RESULT]="09",_a[exports.USER_CHECK_TIMEOUT]="0A",_a[exports.SEND_REGISTER_DEVICE_PAYLOAD]="0B",_a[exports.APP_IS_READY]="0C",_a[exports.APP_ON_IOS_DEVICE]="0D",_a[exports.GET_DEVICE_INFO]="E0",_a[exports.SET_WIFI_MODE]="E1",_a[exports.SET_WIFI_INFO]="E2",_a[exports.SET_WIFI_CONNECT]="E3",_a[exports.SET_WIFI_TOKEN]="E4",_a[exports.GET_DEV_LOG]="E5",_a[exports.GET_DEVICE_NAME]="11",_a[exports.REQUEST_BIND]="12",_a[exports.NOTIFY_BIND]="13",_a[exports.RESPONSE_BIND]="14",_a[exports.CONNECT_REQUEST]="15",_a[exports.CONNECT_ACK]="16",_a[exports.UNBIND_REQUEST]="17",_a[exports.UNBIND_RESPONSE]="18",_a[exports.GET_DEVICE_NAME_WITH_REGISTER]="19",_a[exports.GET_ADV_DATA]="1A",_a[exports.HEARTBEAT_REQ]="1B",_a[exports.NOTIFY_LOCAL_RSSI]="1C",_a[exports.CHECK_SECURE_BIND_INFO]="1E",_a),exports.DEVICE_DATA_WRITE_HEAD=((_b={})[exports.CONTROL_DEVICE]="000",_b[exports.REPORT_RESULT]="001",_b[exports.GET_STATUS]="001",_b[exports.EVENT_REPLY]="011",_b[exports.CONTROL_ACTION]="100",_b),exports.DEVICE_DATA_WRITE_SUFFIX=((_c={})[exports.CONTROL_DEVICE]="00000",_c[exports.REPORT_RESULT]="00000",_c[exports.GET_STATUS]="00010",_c),exports.WIFI_MODE_MAP=((_d={})[exports.NULL_WIFI_MODE]=0,_d[exports.STA_WIFI_MODE]=1,_d),exports.WIFI_LOG_TYPE_MAP={ERROR_LOG:0,NORMAL_LOG:1},exports.ACTION_DESC=((_e={})[exports.CONTROL_DEVICE]="远程控制",_e[exports.REPORT_RESULT]="属性上报结果通知",_e[exports.GET_STATUS]="写入设备最新状态",_e[exports.EVENT_REPLY]="处理设备端事件上报",_e[exports.CONTROL_ACTION]="对设备进行行为调用",_e[exports.CONTROL_ACTION_SUCCESS]="对设备进行行为调用成功",_e[exports.TIME_SYNC]="时间同步",_e[exports.CONNECT_AUTH]="连接鉴权",_e[exports.BIND_AUTH]="绑定鉴权",_e[exports.BIND_AUTH_DETAIL]="绑定鉴权详情",_e[exports.BIND_AUTH_SUCCESS]="绑定鉴权成功",_e[exports.UNBIND_AUTH]="解绑鉴权",_e[exports.CONNECT_RESULT_WRITE_SUCCESS]="连接小程序端鉴权成功",_e[exports.UNBIND_RESULT_AUTH_SUCCESS]="解绑小程序端鉴权成功",_e[exports.APP_IS_READY]="通知设备端小程序已经就绪",_e[exports.APP_ON_IOS_DEVICE]="通知设备端小程序运行于 iOS 环境",_e[exports.GET_ADV_DATA]="获取设备广播信息",_e[exports.HEARTBEAT_REQ]="蓝牙连接心跳",_e[exports.NOTIFY_LOCAL_RSSI]="同步小程序侧 RSSI",_e),exports.BLE_IOT_DATA_TYPE_BOOL="bool",exports.BLE_IOT_DATA_TYPE_INT="int",exports.BLE_IOT_DATA_TYPE_STRING="string",exports.BLE_IOT_DATA_TYPE_FLOAT="float",exports.BLE_IOT_DATA_TYPE_ENUM="enum",exports.BLE_IOT_DATA_TYPE_TIME="timestamp",exports.BLE_IOT_DATA_TYPE_STRUCT="struct",exports.BLE_IOT_DATA_TYPE_ARRAY="array",exports.OTA_UPDATE_REQUEST="OTA_UPDATE_REQUEST",exports.OTA_UPDATE_DATA="OTA_UPDATE_DATA",exports.OTA_UPDATE_DATA_END="OTA_UPDATE_DATA_END",exports.LL_OTA_WRITE_PREFIX=((_f={})[exports.OTA_UPDATE_REQUEST]="00",_f[exports.OTA_UPDATE_DATA]="01",_f[exports.OTA_UPDATE_DATA_END]="02",_f),exports.USER_NEED_LOGIN="USER_NEED_LOGIN",exports.WAIT_CONNECT_REPLY_TIMEOUT="WAIT_CONNECT_REPLY_TIMEOUT",exports.CONNECT_REPLY_INVALID="CONNECT_REPLY_INVALID",exports.WAIT_UNBIND_REPLY_TIMEOUT="WAIT_UNBIND_REPLY_TIMEOUT",exports.WAIT_CONTROL_DEVICE_REPLY_TIMEOUT="WAIT_CONTROL_DEVICE_REPLY_TIMEOUT",exports.WAIT_CONTROL_ACTION_REPLY_TIMEOUT="WAIT_CONTROL_ACTION_REPLY_TIMEOUT",exports.UNBIND_REPLY_INVALID="UNBIND_REPLY_INVALID",exports.CONTROL_REPLY_INVALID="CONTROL_REPLY_INVALID",exports.CONTROL_ACTION_ERROR="CONTROL_ACTION_ERROR",exports.CONNECT_DEVICE_ERROR="CONNECT_DEVICE_ERROR",exports.CANNOT_FIND_DEVICE="CANNOT_FIND_DEVICE",exports.DEVICE_NAME_IS_EMPTY="DEVICE_NAME_IS_EMPTY",exports.PSK_GET_ERROR="PSK_GET_ERROR",exports.CONNECT_SIGN_AUTH_ERROR="CONNECT_SIGN_AUTH_ERROR",exports.CONNECT_SIGN_VERIFY_ERROR="CONNECT_SIGN_VERIFY_ERROR",exports.UNBIND_REPLY_ERROR="UNBIND_REPLY_ERROR",exports.CONTROL_REPLY_CODE_INVALID="CONTROL_REPLY_CODE_INVALID",exports.CONTROL_DEVICE_REPLY_ERROR="CONTROL_DEVICE_REPLY_ERROR",exports.REPORT_RESULT_ERROR="REPORT_RESULT_ERROR",exports.GET_STATUS_ERROR="GET_STATUS_ERROR",exports.EVENT_REPLY_ERROR="EVENT_REPLY_ERROR",exports.BLE_WRITE_ERROR="BLE_WRITE_ERROR",exports.WAIT_GET_DEVICE_INFO_TIMEOUT="WAIT_GET_DEVICE_INFO_TIMEOUT",exports.DEVICE_INFO_INVALID="DEVICE_INFO_INVALID",exports.PROPERTY_REPORT_API_FAIL="PROPERTY_REPORT_API_FAIL",exports.WAIT_GET_ADV_DATA_REPLY_TIMEOUT="WAIT_GET_ADV_DATA_REPLY_TIMEOUT",exports.GET_ADV_DATA_FAIL="GET_ADV_DATA_FAIL",exports.GET_ADV_DATA_REPLY_INVALID="GET_ADV_DATA_REPLY_INVALID",exports.CHECK_SECURE_BIND_INFO_FAIL="CHECK_SECURE_BIND_INFO_FAIL",exports.CHECK_SECURE_BIND_INFO_REPLY_TIMEOUT="CHECK_SECURE_BIND_INFO_REPLY_TIMEOUT",exports.CHECK_SECURE_BIND_INFO_REPLY_INVALID="CHECK_SECURE_BIND_INFO_REPLY_INVALID",exports.WAIT_GET_UPDATE_INFO_TIMEOUT="WAIT_GET_UPDATE_INFO_TIMEOUT",exports.WAIT_MODULE_UPDATE_TIMEOUT="WAIT_MODULE_UPDATE_TIMEOUT",exports.SET_WIFI_MODE_RESULT_INVALID="SET_WIFI_MODE_RESULT_INVALID",exports.SET_WIFI_MODE_RESULT_TIMEOUT="SET_WIFI_MODE_RESULT_TIMEOUT",exports.SET_WIFI_INFO_RESULT_INVALID="SET_WIFI_INFO_INVALID",exports.SET_WIFI_INFO_RESULT_TIMEOUT="SET_WIFI_INFO_TIMEOUT",exports.SET_WIFI_CONNECT_RESULT_INVALID="SET_WIFI_CONNECT_RESULT_INVALID",exports.SET_WIFI_CONNECT_RESULT_TIMEOUT="SET_WIFI_CONNECT_RESULT_TIMEOUT",exports.SET_WIFI_TOKEN_RESULT_INVALID="SET_WIFI_TOKEN_RESULT_INVALID",exports.SET_WIFI_TOKEN_RESULT_TIMEOUT="SET_WIFI_TOKEN_RESULT_TIMEOUT",exports.GET_DEV_LOG_INFO_INVALID="GET_DEV_LOG_INFO_INVALID",exports.GET_DEV_LOG_INFO_TIMEOUT="GET_DEV_LOG_INFO_TIMEOUT",exports.OTA_UPDATE_STEPS={GET_OTA_UPDATE_INFO:"GET_OTA_UPDATE_INFO",GET_OTA_UPDATE_INFO_SUCCESS:"GET_OTA_UPDATE_INFO_SUCCESS",DOWNLOADING_OTA_FILE:"DOWNLOADING_OTA_FILE",DOWNLOADING_OTA_FILE_DETAIL:"DOWNLOADING_OTA_FILE_DETAIL",DOWNLOAD_OTA_FILE_SUCCESS:"DOWNLOAD_OTA_FILE_SUCCESS",REQUEST_MODULE_UPDATE_START:"REQUEST_MODULE_UPDATE",REQUEST_MODULE_UPDATE_SUCCESS:"REQUEST_MODULE_UPDATE_SUCCESS",MODULE_UPDATE_CHECK_FILE_SUCCESS:"MODULE_UPDATE_CHECK_FILE_SUCCESS",SEND_UPDATE_DATA_START:"SEND_UPDATE_DATA_START",SEND_UPDATE_DATA_DETAIL:"SEND_UPDATE_DATA_DETAIL",SEND_UPDATE_DATA_SUCCESS:"SEND_UPDATE_DATA_SUCCESS",WAITING_MODULE_UPDATE:"WAITING_MODULE_UPDATE",MODULE_UPDATE_SUCCESS:"MODULE_UPDATE_SUCCESS"},exports.OTA_UPDATE_STEPS_MESSAGE=((_g={})[exports.OTA_UPDATE_STEPS.GET_OTA_UPDATE_INFO]="获取固件版本信息",_g[exports.OTA_UPDATE_STEPS.GET_OTA_UPDATE_INFO_SUCCESS]="获取固件版本信息成功",_g[exports.OTA_UPDATE_STEPS.DOWNLOADING_OTA_FILE]="正在下载OTA文件",_g[exports.OTA_UPDATE_STEPS.DOWNLOADING_OTA_FILE_DETAIL]="正在下载OTA文件详情",_g[exports.OTA_UPDATE_STEPS.DOWNLOAD_OTA_FILE_SUCCESS]="下载OTA文件成功",_g[exports.OTA_UPDATE_STEPS.REQUEST_MODULE_UPDATE_START]="开始检查设备端固件升级支持情况",_g[exports.OTA_UPDATE_STEPS.REQUEST_MODULE_UPDATE_SUCCESS]="检查设备端固件升级支持情况成功",_g[exports.OTA_UPDATE_STEPS.SEND_UPDATE_DATA_START]="开始发送固件升级文件",_g[exports.OTA_UPDATE_STEPS.SEND_UPDATE_DATA_DETAIL]="固件升级文件详情",_g[exports.OTA_UPDATE_STEPS.SEND_UPDATE_DATA_SUCCESS]="固件升级文件发送成功",_g[exports.OTA_UPDATE_STEPS.WAITING_MODULE_UPDATE]="开始烧录固件升级文件",_g[exports.OTA_UPDATE_STEPS.MODULE_UPDATE_SUCCESS]="设备端固件升级成功",_g),exports.OTA_UPDATE_ERRORS=((_h={GET_OTA_INFO_FAIL:"获取OTA升级信息失败",MODULE_VERSION_IS_UPDATED:"设备端固件已经是最新版",MODULE_DONNOT_SUPPORT:"设备端固件不支持",USER_CANCEL_OTA_UPDATE:"用户取消固件升级",MODULE_DONNOT_ALLOW:"设备端固件不允许,可能是当前状态不允许",MODULE_UPDATE_CHECK_FILE_FAIL:"升级文件校验失败",GET_FILE_CRC_ERROR:"获取文件和crc错误"})[exports.WAIT_GET_UPDATE_INFO_TIMEOUT]="获取设备端分片包回包超时",_h[exports.WAIT_MODULE_UPDATE_TIMEOUT]="等待设备端升级超时",_h.UPDATE_DATA_REPLAY_TIMEOUT="发送固件升级文件超时",_h.MODULE_UPDATE_FAIL="设备端固件升级失败",_h.MODULE_UPDATE_CONNECT_TIMEOUT="设备端固件升级连接设备超时",_h.BLE_CONNECTION_BREAK="蓝牙连接断开",_h),exports.BLE_COMBO_ERRORS=((_j={})[exports.SET_WIFI_MODE_RESULT_INVALID]="设置WiFi模式返回格式错误",_j[exports.SET_WIFI_MODE_RESULT_TIMEOUT]="设置WiFi模式返回超时,请稍后再试",_j[exports.SET_WIFI_INFO_RESULT_INVALID]="WiFi信息传输返回格式错误",_j[exports.SET_WIFI_INFO_RESULT_TIMEOUT]="WiFi信息传输返回超时,请稍后再试",_j[exports.SET_WIFI_CONNECT_RESULT_INVALID]="WiFi连接失败",_j[exports.SET_WIFI_CONNECT_RESULT_TIMEOUT]="获取WiFi连接状态超时",_j[exports.SET_WIFI_TOKEN_RESULT_INVALID]="发送配网token结果非法",_j[exports.SET_WIFI_TOKEN_RESULT_TIMEOUT]="发送配网token结果超时,请稍后再试",_j[exports.GET_DEV_LOG_INFO_INVALID]="获取配网日志格式错误",_j[exports.GET_DEV_LOG_INFO_TIMEOUT]="获取配网日志超时,请稍后再试",_j),exports.MODULE_UPDATE_REPLAY_CODE_MAP={0:"设备电量不足",1:"版本号错误"},exports.MODULE_UPDATE_DATA_REPLAY_CODE_MAP={1:exports.OTA_UPDATE_STEPS.MODULE_UPDATE_CHECK_FILE_SUCCESS,0:"MODULE_UPDATE_CHECK_FILE_FAIL"},exports.MODULE_UPDATE_REPLAY_DATA_CODE_MAP={0:"CRC错误",1:"文件读取失败",2:"文件错误"},exports.WAIT_MODULE_UPDATE_CONNECT_TIMES=5,exports.WAIT_MODULE_UPDATE_CONNECT_TIME_GAP=2e3,exports.UPDATE_WRITE_ERROR_TIMES_PER_CIRCLE=5,exports.MAX_WRITE_DATA_WAIT_GAP=200,exports.ERROR_MESSAGES=tslib_1.__assign(tslib_1.__assign(((_k={})[exports.USER_NEED_LOGIN]="用户未登录,不能连接蓝牙",_k[exports.CONTROL_ACTION_ERROR]="行为调用失败",_k[exports.CONNECT_DEVICE_ERROR]="连接设备失败",_k[exports.CANNOT_FIND_DEVICE]="无法找到设备",_k[exports.USER_NEED_LOGIN]="请重新登录",_k[exports.WAIT_CONNECT_REPLY_TIMEOUT]="等待连接回复超时",_k[exports.CONNECT_REPLY_INVALID]="等待连接回复非法",_k[exports.GET_USER_CHECK_REJECT]="用户端确认拒绝",_k[exports.WAIT_USER_CHECK_TIMEOUT]="等待用户确认超时",_k[exports.GET_USER_CHECK_TIMEOUT_TIMEOUT]="获取设备端用户确认超时时间超时,使用默认超时时间",_k[exports.GET_USER_CHECK_TIMEOUT_ERROR]="获取设备端用户确认超时时间失败,使用默认超时时间",_k[exports.DEVICE_NAME_IS_EMPTY]="设备名称非法",_k[exports.PSK_GET_ERROR]="获取local psk失败",_k[exports.CONNECT_SIGN_AUTH_ERROR]="获取连接认证失败",_k[exports.WAIT_UNBIND_REPLY_TIMEOUT]="获取解绑回复超时",_k[exports.UNBIND_REPLY_INVALID]="解绑回复非法",_k[exports.UNBIND_REPLY_ERROR]="解绑回复失败",_k[exports.WAIT_CONTROL_DEVICE_REPLY_TIMEOUT]="等待控制设备回复超时",_k[exports.CONTROL_DEVICE_REPLY_ERROR]="控制设备失败",_k[exports.CONTROL_REPLY_INVALID]="等待控制设备回复非法",_k[exports.BIND_AUTH_FAIL]="绑定鉴权失败",_k[exports.UNBIND_RESULT_AUTH_FAIL]="解绑小程序端鉴权失败",_k[exports.CONNECT_RESULT_WRITE_FAIL]="连接小程序端鉴权失败",_k[exports.CONTROL_REPLY_CODE_INVALID]="设备端控制回包code非0",_k[exports.REPORT_RESULT_ERROR]="上报设备最新状态失败",_k[exports.GET_STATUS_ERROR]="获取最新状态失败",_k[exports.EVENT_REPLY_ERROR]="EVENT_REPLY_ERROR",_k[exports.BLE_WRITE_ERROR]="设备写入失败",_k[exports.WAIT_GET_DEVICE_INFO_TIMEOUT]="获取设备信息超时",_k[exports.DEVICE_INFO_INVALID]="设备版本和MTU信息非法",_k.ID_TEMPLATE_IS_NOT_EXIT="设备端传的id在物模型里面不存在",_k.TYPE_IN_MODULE_IS_WRONG="设备端的type和后台的不一致",_k[exports.PROPERTY_REPORT_API_FAIL]="属性上报云端回复失败",_k),exports.OTA_UPDATE_ERRORS),((_l={})[exports.REGISTER_DEVICE_ERROR]="从云端动态注册失败",_l[exports.REGISTER_DEVICE_INFO_REPLY_INVALID]="设备端回复的云端注册信息非法",_l[exports.WAIT_REGISTER_DEVICE_INFO_REPLY_TIMEOUT]="等待设备端回复的云端注册信息超时",_l[exports.WAIT_GET_ADV_DATA_REPLY_TIMEOUT]="等待设备端回复广播信息超时",_l[exports.GET_ADV_DATA_FAIL]="设备端回复获取广播信息失败",_l[exports.CHECK_SECURE_BIND_INFO_REPLY_INVALID]="设备端回复获取广播信息失败",_l[exports.CHECK_SECURE_BIND_INFO_REQUIRED]="未完成一机一密校验",_l[exports.CHECK_SECURE_BIND_INFO_FAIL]="一机一密校验未通过",_l)),function(_){_[_.Success=0]="Success",_[_.Fail=1]="Fail",_[_.ParseDataFail=2]="ParseDataFail"}(PropertyReportReplyResult=exports.PropertyReportReplyResult||(exports.PropertyReportReplyResult={})),exports.WRITE_DATA_CANCEL_ERROR_CODE="BLE_WRITE_CHARACTERISTIC_CANCELLED",function(_){_[_.PayloadLengthMismatch=1]="PayloadLengthMismatch",_[_.PayloadMismatch=2]="PayloadMismatch",_[_.ForgetToCheck=3]="ForgetToCheck"}(CheckSecureBindInfoErrorCode=exports.CheckSecureBindInfoErrorCode||(exports.CheckSecureBindInfoErrorCode={})),exports.MIN_ATT_MTU=23,exports.ATT_MTU_TO_LLSYNC_MTU_DELTA=3; | ||
//# sourceMappingURL=constants.js.map |
@@ -11,3 +11,4 @@ import { TlvDataType } from 'qcloud-iotexplorer-common-libs'; | ||
export declare const getUserIdentify: (userId: string) => string; | ||
export declare const wrapEventHandler: (cb: any, dataType?: TlvDataType) => ({ data }: { | ||
export declare const wrapEventHandler: (cb: any, dataType?: TlvDataType) => ({ type, data }: { | ||
type: any; | ||
data: any; | ||
@@ -14,0 +15,0 @@ }) => void; |
@@ -1,2 +0,2 @@ | ||
"use strict";var _this=this;Object.defineProperty(exports,"__esModule",{value:!0}),exports.getMtuEncrypted=exports.randomBytesHex=exports.randomBytes=exports.formatArrayToReportString=exports.decrypt=exports.encrypt=exports.wrapEventHandler=exports.getUserIdentify=exports.base64toHEX=exports.hex2Base64=exports.log=exports.xorHalf=void 0;var tslib_1=require("tslib"),qcloud_iotexplorer_appdev_sdk_1=require("qcloud-iotexplorer-appdev-sdk"),qcloud_iotexplorer_common_libs_1=require("qcloud-iotexplorer-common-libs"),mp_debug_1=tslib_1.__importDefault(require("mp-debug")),_a=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils,byteUtil=_a.byteUtil,CryptoJS=_a.CryptoJS;function hex2Base64(e){return CryptoJS.enc.Hex.parse(e).toString(CryptoJS.enc.Base64)}function base64toHEX(e){return CryptoJS.enc.Base64.parse(e).toString(CryptoJS.enc.Hex)}function decrypt(e,r){var t=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.CryptoJS;return t.AES.decrypt(t.enc.Base64.stringify(t.enc.Hex.parse(e)),t.enc.Hex.parse(r),{mode:t.mode.ECB,padding:t.pad.Pkcs7}).toString(t.enc.Hex)}function randomBytes(e){for(var r=[],t=0;t<e;t++)r.push(Math.floor(256*Math.random()));return r}function randomBytesHex(e){var r=randomBytes(e);return byteUtil.byteArrayToHex(r)}function getMtuEncrypted(e){return Math.max(16*Math.floor(e/16)-1,15)}exports.xorHalf=function(e){if(e.length%2!=0)throw new Error("invalid hexStr");var r=e.length/2,t=byteUtil.hexString2hexArray(e.slice(0,r)),o=byteUtil.hexString2hexArray(e.slice(r));return t.map((function(e,r){return byteUtil.byteToHex(parseInt(e,16)^parseInt(o[r],16))})).join("")},exports.log=mp_debug_1.default("adapter:llsync"),exports.hex2Base64=hex2Base64,exports.base64toHEX=base64toHEX,exports.getUserIdentify=function(e){return qcloud_iotexplorer_common_libs_1.get8ByteFromStr(qcloud_iotexplorer_common_libs_1.md5(e))},exports.wrapEventHandler=function(e,r){void 0===r&&(r="default");var t=qcloud_iotexplorer_common_libs_1.getTlvDataParser(r);return function(r){var o=r.data;console.log("event triggered",o);var n=t(o);console.log("----result",n,_this),null!==n&&e(n)}},exports.encrypt=qcloud_iotexplorer_common_libs_1.hmacSHA1,exports.decrypt=decrypt,exports.formatArrayToReportString=function(e){return e.join(",")},exports.randomBytes=randomBytes,exports.randomBytesHex=randomBytesHex,exports.getMtuEncrypted=getMtuEncrypted; | ||
"use strict";var _this=this;Object.defineProperty(exports,"__esModule",{value:!0}),exports.getMtuEncrypted=exports.randomBytesHex=exports.randomBytes=exports.formatArrayToReportString=exports.decrypt=exports.encrypt=exports.wrapEventHandler=exports.getUserIdentify=exports.base64toHEX=exports.hex2Base64=exports.log=exports.xorHalf=void 0;var tslib_1=require("tslib"),qcloud_iotexplorer_appdev_sdk_1=require("qcloud-iotexplorer-appdev-sdk"),qcloud_iotexplorer_common_libs_1=require("qcloud-iotexplorer-common-libs"),mp_debug_1=tslib_1.__importDefault(require("mp-debug")),_a=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils,byteUtil=_a.byteUtil,CryptoJS=_a.CryptoJS;function hex2Base64(e){return CryptoJS.enc.Hex.parse(e).toString(CryptoJS.enc.Base64)}function base64toHEX(e){return CryptoJS.enc.Base64.parse(e).toString(CryptoJS.enc.Hex)}function decrypt(e,t){var r=qcloud_iotexplorer_appdev_sdk_1.AppDevSdk.utils.CryptoJS;return r.AES.decrypt(r.enc.Base64.stringify(r.enc.Hex.parse(e)),r.enc.Hex.parse(t),{mode:r.mode.ECB,padding:r.pad.Pkcs7}).toString(r.enc.Hex)}function randomBytes(e){for(var t=[],r=0;r<e;r++)t.push(Math.floor(256*Math.random()));return t}function randomBytesHex(e){var t=randomBytes(e);return byteUtil.byteArrayToHex(t)}function getMtuEncrypted(e){return Math.max(16*Math.floor(e/16)-1,15)}exports.xorHalf=function(e){if(e.length%2!=0)throw new Error("invalid hexStr");var t=e.length/2,r=byteUtil.hexString2hexArray(e.slice(0,t)),o=byteUtil.hexString2hexArray(e.slice(t));return r.map((function(e,t){return byteUtil.byteToHex(parseInt(e,16)^parseInt(o[t],16))})).join("")},exports.log=mp_debug_1.default("adapter:llsync"),exports.hex2Base64=hex2Base64,exports.base64toHEX=base64toHEX,exports.getUserIdentify=function(e){return qcloud_iotexplorer_common_libs_1.get8ByteFromStr(qcloud_iotexplorer_common_libs_1.md5(e))},exports.wrapEventHandler=function(e,t){void 0===t&&(t="default");var r=qcloud_iotexplorer_common_libs_1.getTlvDataParser(t);return function(t){var o=t.type,n=t.data;console.log("event triggered",n);var p=r(n);console.log("----result",p,_this),null!==p&&e({type:o,data:p})}},exports.encrypt=qcloud_iotexplorer_common_libs_1.hmacSHA1,exports.decrypt=decrypt,exports.formatArrayToReportString=function(e){return e.join(",")},exports.randomBytes=randomBytes,exports.randomBytesHex=randomBytesHex,exports.getMtuEncrypted=getMtuEncrypted; | ||
//# sourceMappingURL=util.js.map |
{ | ||
"name": "qcloud-iotexplorer-bluetooth-adapter-llsync", | ||
"version": "2.3.2", | ||
"version": "2.3.3", | ||
"description": "", | ||
@@ -30,3 +30,3 @@ "main": "lib/index.js", | ||
}, | ||
"gitHead": "606b36e9ef95cbe322c385c76a6c39b9ac32deeb" | ||
"gitHead": "67df287498971f109076368550e43166eb85a722" | ||
} |
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
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
268029
1680