@jiabaida/tools 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/core/BleApiManager.js +1 -1
- package/dist/cjs/core/BleCmdAnalysis/BleCmdAnalysis.js +1 -1
- package/dist/cjs/core/BleCmdAnalysis/BleCmdDD.js +1 -1
- package/dist/cjs/core/BleCmdAnalysis/readAndSetParam.js +1 -1
- package/dist/cjs/core/commonfun.js +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/esm/core/BleApiManager.js +1 -1
- package/dist/esm/core/BleCmdAnalysis/BleCmdAnalysis.js +1 -1
- package/dist/esm/core/BleCmdAnalysis/BleCmdDD.js +1 -1
- package/dist/esm/core/BleCmdAnalysis/readAndSetParam.js +1 -1
- package/dist/esm/core/commonfun.js +1 -1
- package/dist/esm/index.js +1 -1
- package/package.json +1 -1
- package/src/core/BleApiManager.js +16 -6
- package/src/core/BleCmdAnalysis/BleCmdAnalysis.js +4 -2
- package/src/core/BleCmdAnalysis/BleCmdDD.js +123 -2
- package/src/core/BleCmdAnalysis/BleCmdDDA4.js +761 -761
- package/src/core/BleCmdAnalysis/readAndSetParam.js +9 -7
- package/src/core/commonfun.js +3 -0
- package/dist/cjs/core/BleCmdAnalysis.js +0 -1
- package/dist/esm/core/BleCmdAnalysis.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var vue=require("vue"),BleDataProcess=require("./BleDataProcess.js"),commonfun=require("./commonfun.js");const serviceId="0000FF00-0000-1000-8000-00805F9B34FB",bluetoothAdapterState=vue.ref({available:!1,discovering:!1}),startDevicesDiscovery=async(allowDuplicatesKey=!0)=>new Promise((resolve,reject)=>{bluetoothAdapterState.value.discovering?reject(new Error("蓝牙设备搜索已在进行中")):uni.startBluetoothDevicesDiscovery({services:[serviceId],allowDuplicatesKey:allowDuplicatesKey,success:async res=>{console.log("广播设备 success",res),resolve(res)},fail:err=>{console.log("广播设备 fail",err),reject(err)}})}),onBluetoothDeviceFound=async()=>{uni.onBluetoothDeviceFound(characteristic=>{console.log("setBluetoothDeviceFound",characteristic);const device=(device=>{const adv=device?.advertisData;if(!adv)return null;if(adv){const advHex=Array.prototype.map.call(new Uint8Array(adv),o=>("00"+o.toString(16)).slice(-2)).join("").toUpperCase();let macAddr=advHex.slice(0,12).toUpperCase(),arr=macAddr.match(/(.{2})/g);const flag=macAddr.slice(-4);"C1A4"!=flag&&"C2A5"!=flag&&"C2A8"!=flag||arr.reverse(),macAddr=arr.join(":"),device.hasFound=!0;const moduleType=advHex.slice(12,16),socHex=advHex.slice(16,18),soc=socHex||0==socHex?BleDataProcess.hexToDecimal(socHex):"",productType=advHex.slice(18,20),protocolVersion=advHex.slice(20,22),appkeyStatus=advHex.slice(22,24),tempVoltage=advHex.slice(24,26),voltage=tempVoltage||0==tempVoltage?BleDataProcess.hexToDecimal(tempVoltage):"",tempCurrent=advHex.slice(26,28),current=tempCurrent||0==tempCurrent?BleDataProcess.hexToDecimal(tempCurrent):"",broadcastLen=advHex.length/2,isNewAppKey=advHex.length>=24;device={...device,macAddr:macAddr,moduleType:moduleType,soc:soc,productType:productType,advHex:advHex,protocolVersion:protocolVersion,appkeyStatus:appkeyStatus,broadcastLen:broadcastLen,isNewAppKey:isNewAppKey,voltage:voltage,current:current}}return device})(characteristic.devices[0]);device&&commonfun.eventBus.emit("setBluetoothDeviceFound",device)})},onFoundDevice=callback=>{commonfun.eventBus.on("setBluetoothDeviceFound",callback)},onBluetoothAdapterStateChange=async()=>{uni.onBluetoothAdapterStateChange(res=>{console.log("onBluetoothAdapterStateChange监听蓝牙适配器变化",res),bluetoothAdapterState.value=res})},onBLECharacteristicValueChange=async()=>{uni.onBLECharacteristicValueChange(characteristic=>{const decimalArr=BleDataProcess.ab2decimalArr(characteristic.value);console.warn("decimalArr: 监听到的回复-------------------",decimalArr),commonfun.eventBus.emit("setBleChangedCharacteristicValue",characteristic)})},onBLEConnectionStateChange=async()=>{uni.onBLEConnectionStateChange(characteristic=>{console.log("onBLEConnectionStateChange",characteristic),commonfun.eventBus.emit("setBleChangedConnectionState",characteristic)})},createBLEConnection=async(deviceId,timeout=1e4)=>new Promise((resolve,reject)=>{console.log(deviceId,"点击的设备信息"),uni.createBLEConnection({deviceId:deviceId,timeout:timeout,success:res=>{console.log(res,"连接成功"),resolve(!0)},fail:err=>{console.log(err,"Connection"),-1==(err.code||err.errCode)?resolve(!0):reject(err)}})}),withRetry=async(asyncOperation,maxRetries=20,retryInterval=100,type)=>new Promise((resolve,reject)=>{let retryCount=0;const attempt=async()=>{try{const result=await asyncOperation();resolve(result)}catch(error){if(retryCount>=maxRetries)return void reject(new Error(`${type}失败,${error.message} (已重试${maxRetries}次)`));retryCount++,console.warn(`${type}失败,第${retryCount}次重试:`,error.message),setTimeout(attempt,retryInterval)}};attempt()}),getBLEDeviceServices=deviceId=>withRetry(async()=>{const res=await new Promise((resolve,reject)=>{uni.getBLEDeviceServices({deviceId:deviceId,success:resolve,fail:reject})});if(console.log("获取蓝牙服务成功:",res),0===res.services.length)throw new Error("未找到蓝牙服务");return await getBLEDeviceCharacteristics(deviceId),res.services},20,100,"获取蓝牙服务"),getBLEDeviceCharacteristics=async deviceId=>withRetry(async()=>{const res=await new Promise((resolve,reject)=>{uni.getBLEDeviceCharacteristics({deviceId:deviceId,serviceId:serviceId,success:resolve,fail:reject})});return console.log("获取特征值成功:",res),res.characteristics},20,100,"获取蓝牙特征值"),notify=async deviceId=>new Promise((resolve,reject)=>{uni.notifyBLECharacteristicValueChange({deviceId:deviceId,serviceId:serviceId,characteristicId:"0000FF01-0000-1000-8000-00805F9B34FB",state:!0,success:res=>{console.log("订阅===========",res),resolve(res)},fail:reject})}),foundScanDevice=async(result,connectFn)=>{const deviceList=[];await startDevicesDiscovery(),onFoundDevice(device=>{deviceList.push(device);const findDevice=device.macAddr===result||device.name===result;findDevice?(scanTimeout&&(clearTimeout(scanTimeout),scanTimeout=null),uni.stopBluetoothDevicesDiscovery(),connectFn(findDevice)):console.log("未找到设备,继续搜索中...")});let scanTimeout=setTimeout(async()=>{try{console.log("stopBluetoothDevicesDiscovery",deviceList),clearInterval(scanTimer),scanTimer=null,uni.stopBluetoothDevicesDiscovery();const findDevice=deviceList.find(device=>device.macAddr===result||device.name===result);connectFn(findDevice)}finally{}},5e3)};exports.connectAsync=async(deviceId,timeout=1e4)=>new Promise(async(resolve,reject)=>{try{await createBLEConnection(deviceId,timeout),await getBLEDeviceServices(deviceId),await notify(deviceId),resolve(!0)}catch(error){console.log("error: ",error),reject(error)}}),exports.createBLEConnection=createBLEConnection,exports.disConnect=deviceId=>new Promise((resolve,reject)=>{uni.closeBLEConnection({deviceId:deviceId,success:res=>{resolve(res),console.log(res,"断开连接成功")},fail:err=>{reject(err),console.log(err,"err 断开连接")}})}),exports.foundScanDevice=foundScanDevice,exports.getBLEDeviceCharacteristics=getBLEDeviceCharacteristics,exports.getBLEDeviceServices=getBLEDeviceServices,exports.getBluetoothAdapterState=async()=>new Promise((resolve,reject)=>{uni.getBluetoothAdapterState({success:res=>{console.log("getBluetoothAdapterState success",res),resolve(res)},fail:err=>{console.log("getBluetoothAdapterState fail",err),reject(err)}})}),exports.initBle=async()=>{const checkBluetoothStatus=async()=>new Promise((resolve,reject)=>{uni.openBluetoothAdapter({success:async res=>{console.log("openBluetoothAdapter success",res),resolve(res);try{onBluetoothDeviceFound(),onBLECharacteristicValueChange(),onBLEConnectionStateChange(),onBluetoothAdapterStateChange()}catch(error){console.log("error: ",error),reject(error)}},fail:err=>{console.log("openBluetoothAdapter fail",err),reject(err)}})});try{const{isAndroid:isAndroid}=commonfun.getOS();isAndroid?(async()=>{const timeoutPromise=new Promise((resolve,reject)=>{setTimeout(()=>{reject(new Error("网络信号差或连接异常,请检查网络情况"))},1e4)}),locationPromise=new Promise((resolve,reject)=>{uni.getLocation({type:"wgs84",success:res=>{console.log("位置信息-----------",res),resolve(res)},fail:err=>{console.log("位置信息err",err),reject(err)}})});Promise.race([locationPromise,timeoutPromise]).then(res=>{checkBluetoothStatus()}).catch(err=>{console.log("位置获取失败或超时:",err),Promise.reject({code:1})})})():checkBluetoothStatus()}catch(error){console.error("初始化蓝牙失败:",error),Promise.reject({code:error.code||error.errCode||-1})}},exports.notify=notify,exports.onBLECharacteristicValueChange=onBLECharacteristicValueChange,exports.onBLEConnectionStateChange=onBLEConnectionStateChange,exports.onBleChangedConnectionState=callback=>{commonfun.eventBus.on("setBleChangedConnectionState",callback)},exports.onBluetoothAdapterStateChange=onBluetoothAdapterStateChange,exports.onBluetoothDeviceFound=onBluetoothDeviceFound,exports.onFoundDevice=onFoundDevice,exports.scanHandle=(historyConnectedList=[],connectFn=device=>{},failScanFn=err=>{})=>{uni.scanCode({scanType:["barCode","qrCode"],success:async({result:result})=>{console.log("扫描内容: "+result);let searchKey=result;try{const formatMacAddress=mac=>mac.replace(/(.{2})/g,"$1:").slice(0,-1).toUpperCase();let isMac=!1;result.includes("?qrCodeInfo=")?(searchKey=result.split("?qrCodeInfo=")[1],searchKey.includes(":")?(searchKey=searchKey.slice(-17).toUpperCase(),isMac=!0):(searchKey=searchKey.slice(-12),searchKey=formatMacAddress(searchKey),isMac=!0)):17===result.length&&result.includes(":")?(searchKey=result.toUpperCase(),isMac=!0):12===result.length&&(searchKey=formatMacAddress(result),isMac=!0);const{isAndroid:isAndroid}=commonfun.getOS(),matchedHistoryDevice=historyConnectedList.find(item=>item.macAddr==searchKey);if(matchedHistoryDevice)return void connectFn(matchedHistoryDevice);isAndroid&&isMac?connectFn({deviceId:searchKey,macAddr:searchKey,name:searchKey}):foundScanDevice(searchKey,connectFn)}catch(error){console.log(error)}},complete:err=>{console.log("scanCode err",err),failScanFn(err)}})},exports.startDevicesDiscovery=startDevicesDiscovery,exports.stopBluetoothDevicesDiscovery=async()=>new Promise((resolve,reject)=>{uni.stopBluetoothDevicesDiscovery({success:res=>{console.log("停止广播设备 success",res),resolve(res)},fail:err=>{console.log("停止广播设备 fail",err),reject(err)},complete:res=>{console.log("停止广播设备 取消订阅"),commonfun.eventBus.off("setBluetoothDeviceFound")}})});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var BleDataProcess=require("../BleDataProcess.js"),commonfun=require("../commonfun.js");async function _writeAsync(deviceId,value){return console.log("deviceId, value: ",deviceId,value),!(!deviceId||!value)&&new Promise(resolve=>{const{isAndroid:isAndroid,isIOS:isIOS}=commonfun.getOS();console.log("isAndroid, isIOS: ",isAndroid,isIOS);const writeType=isAndroid?"writeNoResponse":"write";uni.writeBLECharacteristicValue({deviceId:deviceId,serviceId:"0000FF00-0000-1000-8000-00805F9B34FB",characteristicId:"0000FF02-0000-1000-8000-00805F9B34FB",writeType:writeType,value:value,success:res=>{console.error("res: 写入成功",res),resolve(!0)},fail:e=>{console.error("写入失败",e),resolve(!1)}}),isIOS&&setTimeout(()=>resolve(!0),50)})}exports.getData=async(deviceId,{command:command,commandVerifyHandler:commandVerifyHandler=hexArr=>({verified:!1,pkgLen:null}),pkgVerifyHandler:pkgVerifyHandler=pkg=>({verified:!1}),maxRetries:maxRetries=2,retryInterval:retryInterval=300},tag="")=>{if(!deviceId)throw new Error("deviceId is required");if(!command||command.length<=0)throw new Error("command is required");return new Promise((resolve,reject)=>{let isCompleted=!1,timeoutId=null,responsed=!1,len=null,pkg=[];const cmdContent=BleDataProcess.hexArr2ab(command),cleanup=()=>{isCompleted||(isCompleted=!0,clearTimeout(timeoutId),commonfun.eventBus.off("setBleChangedCharacteristicValue",dataHandler))},dataHandler=payload=>{if(!payload||payload.deviceId!==deviceId||!payload.value)return;const hexArr=BleDataProcess.ab2decimalArr(payload.value);if(console.log("hexArr: ",hexArr),console.warn(tag,"接收到数据:",BleDataProcess.hexArr2string(hexArr)),0!==hexArr.length){if(null===len){const{verified:verified,pkgLen:pkgLen}=commandVerifyHandler(hexArr);console.log("指令验证结果:",{verified:verified,pkgLen:pkgLen}),verified&&(len=pkgLen)}if(len){if(pkg=[...pkg,...hexArr],console.log("当前数据包:",pkg,`长度: ${pkg.length}/${len}`),pkg.length>=len){pkg=pkg.slice(0,len);const{verified:verified}=pkgVerifyHandler(pkg);console.log("数据包验证结果:",{verified:verified}),verified?(responsed=!0,cleanup(),resolve([...pkg])):(len=null,pkg=[])}}else pkg=[]}},writeToDevice=async(attempt=1)=>{try{console.warn(tag,`第${attempt}次写入指令:`,command.join("").replace(/0x/g,"").toUpperCase());const writeSucceed=await async function(deviceId,value){return console.log("value: ",value),console.log("deviceId: ",deviceId),!(!deviceId||!value)&&new Promise(async resolve=>{const n=Math.ceil(value.byteLength/20);let res;for(let i=0;i<n;i++){const _value=value.slice(20*i,20*(i+1));if(console.log("分包写入_value: ",_value),await BleDataProcess.sleep(150),res=await _writeAsync(deviceId,_value),console.log(`分包写入结果 ${i+1}/${n} : ${res}`),!res)return resolve(!1)}resolve(res)})}(deviceId,cmdContent);if(console.warn(tag,`第${attempt}次写入结果:`,writeSucceed?"成功":"失败"),!writeSucceed)return void(attempt<maxRetries?setTimeout(()=>writeToDevice(attempt+1),retryInterval):(cleanup(),resolve(null)));await BleDataProcess.sleep(retryInterval),!responsed&&attempt<maxRetries?(console.log(tag,`未收到响应,准备第${attempt+1}次重试`),writeToDevice(attempt+1)):responsed||(console.warn(tag,`达到最大重试次数(${maxRetries}),未收到响应`),cleanup(),resolve(null))}catch(error){console.error(tag,"写入过程发生错误:",error),cleanup(),reject(error)}};timeoutId=setTimeout(()=>{console.warn(tag,"操作超时"),cleanup(),resolve(null)},(maxRetries+2)*retryInterval),commonfun.eventBus.on("setBleChangedCharacteristicValue",dataHandler),writeToDevice().catch(error=>{cleanup(),reject(error)})})},exports.setMTUAsync=(deviceId,mtu=512,delay=2500)=>new Promise((resolve,reject)=>{try{if(commonfun.getOS().isIOS)return resolve(!0);setTimeout(async()=>{await uni.setBLEMTU({deviceId:deviceId,mtu:mtu}),resolve(!0)},delay)}catch(error){console.error(error),reject(error)}});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var BleDataProcess=require("../BleDataProcess.js"),commonfun=require("../commonfun.js");async function _writeAsync(deviceId,value){return console.log("deviceId, value: ",deviceId,value),!(!deviceId||!value)&&new Promise(resolve=>{const{isAndroid:isAndroid,isIOS:isIOS}=commonfun.getOS(),platform=commonfun.getPlatform();console.log("platform: ",platform),console.log("isAndroid, isIOS: ",isAndroid,isIOS);const writeType="mp-weixin"===platform||isAndroid?"writeNoResponse":"write";uni.writeBLECharacteristicValue({deviceId:deviceId,serviceId:"0000FF00-0000-1000-8000-00805F9B34FB",characteristicId:"0000FF02-0000-1000-8000-00805F9B34FB",writeType:writeType,value:value,success:res=>{console.error("res: 写入成功",res),resolve(!0)},fail:e=>{console.error("写入失败",e),resolve(!1)}}),isIOS&&setTimeout(()=>resolve(!0),50)})}exports.getData=async(deviceId,{command:command,commandVerifyHandler:commandVerifyHandler=hexArr=>({verified:!1,pkgLen:null}),pkgVerifyHandler:pkgVerifyHandler=pkg=>({verified:!1}),maxRetries:maxRetries=2,retryInterval:retryInterval=300},tag="")=>{if(!deviceId)throw new Error("deviceId is required");if(!command||command.length<=0)throw new Error("command is required");return new Promise((resolve,reject)=>{let isCompleted=!1,timeoutId=null,responsed=!1,len=null,pkg=[];const cmdContent=BleDataProcess.hexArr2ab(command),cleanup=()=>{isCompleted||(isCompleted=!0,clearTimeout(timeoutId),commonfun.eventBus.off("setBleChangedCharacteristicValue",dataHandler))},dataHandler=payload=>{if(!payload||payload.deviceId!==deviceId||!payload.value)return;const hexArr=BleDataProcess.ab2decimalArr(payload.value);if(console.log("hexArr: ",hexArr),console.warn(tag,"接收到数据:",BleDataProcess.hexArr2string(hexArr)),0!==hexArr.length){if(null===len){const{verified:verified,pkgLen:pkgLen}=commandVerifyHandler(hexArr);console.log("指令验证结果:",{verified:verified,pkgLen:pkgLen}),verified&&(len=pkgLen)}if(len){if(pkg=[...pkg,...hexArr],console.log("当前数据包:",pkg,`长度: ${pkg.length}/${len}`),pkg.length>=len){pkg=pkg.slice(0,len);const{verified:verified}=pkgVerifyHandler(pkg);console.log("数据包验证结果:",{verified:verified}),verified?(responsed=!0,cleanup(),resolve([...pkg])):(len=null,pkg=[])}}else pkg=[]}},writeToDevice=async(attempt=1)=>{try{console.warn(tag,`第${attempt}次写入指令:`,command.join("").replace(/0x/g,"").toUpperCase());const writeSucceed=await async function(deviceId,value){return console.log("value: ",value),console.log("deviceId: ",deviceId),!(!deviceId||!value)&&new Promise(async resolve=>{const n=Math.ceil(value.byteLength/20);let res;for(let i=0;i<n;i++){const _value=value.slice(20*i,20*(i+1));if(console.log("分包写入_value: ",_value),await BleDataProcess.sleep(150),res=await _writeAsync(deviceId,_value),console.log(`分包写入结果 ${i+1}/${n} : ${res}`),!res)return resolve(!1)}resolve(res)})}(deviceId,cmdContent);if(console.warn(tag,`第${attempt}次写入结果:`,writeSucceed?"成功":"失败"),!writeSucceed)return void(attempt<maxRetries?setTimeout(()=>writeToDevice(attempt+1),retryInterval):(cleanup(),resolve(null)));await BleDataProcess.sleep(retryInterval),!responsed&&attempt<maxRetries?(console.log(tag,`未收到响应,准备第${attempt+1}次重试`),writeToDevice(attempt+1)):responsed||(console.warn(tag,`达到最大重试次数(${maxRetries}),未收到响应`),cleanup(),resolve(null))}catch(error){console.error(tag,"写入过程发生错误:",error),cleanup(),reject(error)}};timeoutId=setTimeout(()=>{console.warn(tag,"操作超时"),cleanup(),resolve(null)},(maxRetries+2)*retryInterval),commonfun.eventBus.on("setBleChangedCharacteristicValue",dataHandler),writeToDevice().catch(error=>{cleanup(),reject(error)})})},exports.setMTUAsync=(deviceId,mtu=512,delay=2500)=>new Promise((resolve,reject)=>{try{if(commonfun.getOS().isIOS)return resolve(!0);setTimeout(async()=>{await uni.setBLEMTU({deviceId:deviceId,mtu:mtu}),resolve(!0)},delay)}catch(error){console.error(error),reject(error)}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var BleCmdAnalysis=require("./BleCmdAnalysis.js"),BleDataProcess=require("../BleDataProcess.js"),BleCmdFFAA=require("./BleCmdFFAA.js");const set_PlanCMD_DD=async(deviceId,command)=>{"string"==typeof command&&(command=command.match(/(.{2})/g).map(o=>`0x${o}`));let result=null;try{const data=await BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"PlanCMD_DD");if(data){const dataStr=BleDataProcess.hexArr2string(data),content=data.slice(4,data.length-3);result={data:data,dataStr:dataStr,status:BleDataProcess.hex2string(data[2]),len:data[3],content:content}}else result={status:0,content:[]}}catch(error){console.error(error)}return result},get3B3CAsync=async deviceId=>{const addressCode=["0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00"],commandCode=["0x01"],data=[],dataLength=[`0x${BleDataProcess.decimalToHex(data.length,2)}`],check=BleDataProcess.generateCrc16modbusCheck([...addressCode,...commandCode,...dataLength,...data],!1),command=["0x3b","0x3c",...addressCode,...commandCode,...dataLength,...data,...check,"0x0d"];return BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:59==hexArr[0]&&60==hexArr[1],pkgLen:hexArr[11]+15}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=BleDataProcess.generateCrc16modbusCheck(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"3B3C")},resolve3B3C=data=>{if(!data)return null;let result={dataStr:BleDataProcess.hexArr2string(data),status:BleDataProcess.hex2string(data[10]),addr:BleDataProcess.hexArr2string(data.slice(2,10))};const content=data.slice(12,data.length-3);for(;content.length>0;){const[v1,v2,...v]=content.splice(0,content[1]+2);if(1==v1&&(result.productFlag=BleDataProcess.hex2string(v1),result.productLen=v2,v)){const[productType,frontType,protocolV,level]=v.map(o=>BleDataProcess.hex2string(o));Object.assign(result,{productType:productType,frontType:frontType,protocolV:protocolV,level:level})}2==v1&&(result.hardwareFlag=BleDataProcess.hex2string(v1),result.hardwareLen=v2,result.hardwareV=BleDataProcess.hexArr2Assic(v)),3==v1&&(result.sofewareFlag=BleDataProcess.hex2string(v1),result.sofewareLen=v2,result.sofewareV=BleDataProcess.hexArr2Assic(v)),4==v1&&(result.pcbFlag=BleDataProcess.hex2string(v1),result.pcbLen=v2,result.pcbContent=BleDataProcess.hexArr2Assic(v))}return result},getDDA503Async=async deviceId=>{const hex=await BleCmdAnalysis.getData(deviceId,{command:["0xdd","0xa5","0x03","0x00","0xff","0xfd","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&3==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=BleDataProcess.generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_03");return hex?resolveDDA503(hex):null},resolveDDA503=data=>{if(!data)return null;const cmdResp03=BleDataProcess.hexArr2string(data),content=data.slice(4,data.length-3),binArr=data[24].toString(2).padStart(8,"0").split("").reverse(),balances=data.slice(16,20).flatMap(byte=>byte.toString(2).padStart(8,"0").split("").reverse());console.warn("BC: ---------------",balances);const fet=data[24],chargeSwitch=!!Number(binArr[0]),dischargeSwitch=!!Number(binArr[1]),BMSVersion=BleDataProcess.decimalToHex(data[22]),humidityIndex=2*data[26]+27,humidity=data[humidityIndex],n=Number(binArr[7])||136==humidity?10:100,totalVoltage=Number((((data[4]<<8)+(255&data[5]))/100).toFixed(2));let current=(data[6]<<8)+(255&data[7]);current=current>32768?(current-65536)/n:current/n;const electricity=Number(current.toFixed(2)),power=Number((totalVoltage*electricity).toFixed(2)),soc=data[23]??0,seriesNum=data[25]??0,volumeHex=BleDataProcess.decimalToHex(data[8])+BleDataProcess.decimalToHex(data[9]),surplusCapacity=Number((BleDataProcess.hexToDecimal(volumeHex)/n).toFixed(2)),normCapHex=BleDataProcess.decimalToHex(data[10])+BleDataProcess.decimalToHex(data[11]),normCap=Number((BleDataProcess.hexToDecimal(normCapHex)/n).toFixed(2)),cycleHex=BleDataProcess.decimalToHex(data[12])+BleDataProcess.decimalToHex(data[13]),cycleIndex=BleDataProcess.hexToDecimal(cycleHex),fccHex=BleDataProcess.decimalToHex(data[humidityIndex+3])+BleDataProcess.decimalToHex(data[humidityIndex+4]),fullChargeCapacity=Number((BleDataProcess.hexToDecimal(fccHex)/n).toFixed(2)),SOH=cycleIndex<=100?100:Math.min(100,fullChargeCapacity/normCap*100),heatingState=!!Number(binArr[4])||!!Number(binArr[3]);let heatingCurrent=null;const hasHeatingCurrent=data[3]+7>=humidityIndex+9+4+1,hasEquilCurrent=data[3]+7>=humidityIndex+7+4+1;if(heatingState&&hasHeatingCurrent){const i=humidityIndex+9;heatingCurrent=heatingCurrent=((data[i]<<8|data[i+1])/100).toFixed(2)}let equilibriumCurrent=null;if(hasEquilCurrent){const i=humidityIndex+7;let equilCurrent=(data[i]<<8)+(255&data[i+1]);equilCurrent=equilCurrent>32768?(equilCurrent-65536)/1e3:equilCurrent/1e3,equilibriumCurrent=Number(equilCurrent.toFixed(2))}const isFactoryMode=!!Number(binArr[6]),equilibriumStatus=!(0===data[16]&&0===data[17]),protectStatus=!(0===data[20]&&0===data[21]),protectStateHex=BleDataProcess.decimalToHex(data[20])+BleDataProcess.decimalToHex(data[21]),protVal=BleDataProcess.hexToDecimal(protectStateHex);let alarmIndex=2*data[26]+28,alarmStateHex=BleDataProcess.decimalToHex(data[alarmIndex])+BleDataProcess.decimalToHex(data[alarmIndex+1]),alarmsState=BleDataProcess.hexToDecimal(alarmStateHex);const ntcNums=255&data[26],temperaturesList=Array.from({length:ntcNums},(_,i)=>((256*(255&data[26+2*i+1])+(255&data[26+2*i+2])-2731)/10).toFixed(1)),fahTempList=[];temperaturesList.forEach(el=>{const value=1.8*Number(el)+32;fahTempList.push(value.toFixed(1))});const temperatures=temperaturesList.map((item,index)=>({name:index+1,value:item}));return{cmdResp03:cmdResp03,status:BleDataProcess.hex2string(data[2]),len:data[3],softwareV:BleDataProcess.hex2string(content[18]),balances:balances,BMSVersion:BMSVersion,soc:soc,normCap:normCap,surplusCapacity:surplusCapacity,totalVoltage:totalVoltage,electricity:electricity,power:power,cycleIndex:cycleIndex,equilibriumStatus:equilibriumStatus,chargeSwitch:chargeSwitch,dischargeSwitch:dischargeSwitch,temperatures:temperatures,humidity:humidity,protectStatus:protectStatus,fullChargeCapacity:fullChargeCapacity,SOH:SOH,heatingState:heatingState,heatingCurrent:heatingCurrent,equilibriumCurrent:equilibriumCurrent,isFactoryMode:isFactoryMode,protVal:protVal,alarmsState:alarmsState,ntcNums:ntcNums,temperaturesList:temperaturesList,fahTempList:fahTempList,fet:fet,seriesNum:seriesNum}},resolveDDA504=(data,dataScope)=>{if(console.log("data: ",data),!data)return null;const cmdResp04=BleDataProcess.hexArr2string(data),voltageList=[];for(let index=4;index<parseInt(data[3])+4;index+=2){let voltageHex=BleDataProcess.decimalToHex(data[index])+BleDataProcess.decimalToHex(data[index+1]),voltage=BleDataProcess.hexToDecimal(voltageHex);voltageList.push(Number(voltage))}let highestVoltage=null,lowestVoltage=null,averageVoltage=null,dropoutVoltage=null;if(voltageList.length>0){highestVoltage=Math.max(...voltageList),lowestVoltage=Math.min(...voltageList);averageVoltage=voltageList.reduce((acc,cur)=>acc+cur,0)/voltageList.length;const dropout=highestVoltage-lowestVoltage,precision=dataScope?3:2;highestVoltage=Number((highestVoltage/1e3).toFixed(precision)),lowestVoltage=Number((lowestVoltage/1e3).toFixed(precision)),averageVoltage=Number((averageVoltage/1e3).toFixed(precision)),dropoutVoltage=Number((dropout/1e3).toFixed(precision))}voltageList.forEach((v,i)=>{let newV=v/1e3;voltageList[i]=Number(newV.toFixed(dataScope?3:2))});const voltageSeries=voltageList.map((item,index)=>({name:index+1,value:item}));return{cmdResp04:cmdResp04,voltageList:voltageList,voltageSeries:voltageSeries,highestVoltage:highestVoltage,lowestVoltage:lowestVoltage,averageVoltage:averageVoltage,dropoutVoltage:dropoutVoltage}},resolveDDA500=data=>{if(!data)return null;return{dataStr:BleDataProcess.hexArr2string(data),status:BleDataProcess.hex2string(data[2]),len:data[3],type:data[5]}},getDDA505Async=async deviceId=>BleCmdAnalysis.getData(deviceId,{command:["0xdd","0xa5","0x05","0x00","0xff","0xfb","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&5==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=BleDataProcess.generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_05"),resolveDDA505=data=>{if(!data)return null;return{dataStr:BleDataProcess.hexArr2string(data),status:BleDataProcess.hex2string(data[2]),len:data[3],hardwareV:BleDataProcess.hexArr2Assic(data.slice(4,data.length-3))}},resolveProtections=binary=>{const arr=binary.split("").reverse(),map=["device.0041","device.0042","device.0043","device.0044","device.0045","device.0046","device.0047","device.0048","device.0049","device.0050","device.0051","device.0052","device.0053","device.0054","device.0055","device.00551"];let _arr=[],_indexs=[];for(let i=0;i<arr.length;i++)1==arr[i]&&(_arr.push(map[i]),_indexs.push(i));return{_arr:_arr,_indexs:_indexs}};exports.enterFactory=async deviceId=>set_PlanCMD_DD(deviceId,"DD5A00025678FF3077"),exports.existFactory=async deviceId=>set_PlanCMD_DD(deviceId,"DD5A01022828ffad77"),exports.get3B3CAsync=get3B3CAsync,exports.get3B3CInfo=({deviceId:deviceId,macAddr:macAddr,moduleType:moduleType,productType:productType})=>new Promise(async(resolve,reject)=>{let reportData={macAddr:macAddr,moduleTypeKey:moduleType,productKey:productType},_3b3c=null,_dda5_03=null,_dda5_05=null,_ffaa_80=null;try{if(!deviceId)throw new Error("deviceId required");const _ffaa_80_hex=await BleCmdFFAA.getFFAA80Async(deviceId,"AT^VERSION?");_ffaa_80=BleCmdFFAA.resolveFFAA80(_ffaa_80_hex),console.warn("Report-3B3C _ffaa_80 ",{_ffaa_80_hex:_ffaa_80_hex,_ffaa_80:_ffaa_80}),_ffaa_80&&(reportData.moduleVersion=_ffaa_80?.moduleVersion);const _3b3c_hex=await get3B3CAsync(deviceId);if(_3b3c=resolve3B3C(_3b3c_hex),console.warn("Report-3B3C _3b3c ",{_3b3c_hex:_3b3c_hex,_3b3c:_3b3c}),_3b3c)reportData.cmdContent=_3b3c?.dataStr;else{const _dda5_03_hex=await getDDA503Async(deviceId);_dda5_03=resolveDDA503(_dda5_03_hex),console.warn("Report-3B3C _dda5_03 ",{_dda5_03_hex:_dda5_03_hex,_dda5_03:_dda5_03}),_dda5_03&&(reportData.bmsVersion=_dda5_03?.softwareV);const _dda5_05_hex=await getDDA505Async(deviceId);_dda5_05=resolveDDA505(_dda5_05_hex),console.warn("Report-3B3C _dda5_05 ",{_dda5_05_hex:_dda5_05_hex,_dda5_05:_dda5_05}),_dda5_05&&(reportData.bmsSn=_dda5_05?.hardwareV)}resolve({reportData:reportData,_3b3c:_3b3c,_dda5_03:_dda5_03,_dda5_05:_dda5_05,_ffaa_80:_ffaa_80})}catch(error){reject(error)}}),exports.getChipTypeAsync=async deviceId=>{const hex=await BleCmdAnalysis.getData(deviceId,{command:["0xdd","0xa5","0x00","0x00","0x00","0x00","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&0==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=BleDataProcess.generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_00");return hex?resolveDDA500(hex):null},exports.getDD5A0AAsync=async(deviceId,value)=>{const _command=["0x0A","0x02",...BleDataProcess.stringToTwoHexArray(value)],checks=BleDataProcess.generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return console.log("command: ",command),BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&10==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},`DD5A_0A_${value}`)},exports.getDD5A0EAsync=async deviceId=>BleCmdAnalysis.getData(deviceId,{command:["0xDD","0x5A","0x0E","0x02","0x81","0x18","0xFF","0x57","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&14==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_0E_复位"),exports.getDD5A17Async=async deviceId=>BleCmdAnalysis.getData(deviceId,{command:["0xDD","0x5A","0x17","0x02","0x00","0x01","0xFF","0xE6","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&23==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_17-清除电池循环次数"),exports.getDD5AAllAsync=async(deviceId,path,lengthHex,values,type)=>{const _command=[path,lengthHex,...values],checks=BleDataProcess.generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&hexArr[1]==path,pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},`DD5A_${path}_${type}`)},exports.getDD5AE0Async=async(deviceId,value)=>{const hex=100*value,hexStr=BleDataProcess.decimalToHex(hex,4),_values=[`0x${hexStr.slice(0,2)}`,`0x${hexStr.slice(2,4)}`],_command=["0xE0","0x02",..._values],checks=BleDataProcess.generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return console.warn("=======CCCCCCC=SET===",{value:value,hex:hex,hexStr:hexStr,_values:_values,_command:_command,checks:checks,command:command}),BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&224==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_E0")},exports.getDD5AE1Async=async(deviceId,value)=>{const _command=["0xE1","0x02","0x00",value],checks=BleDataProcess.generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&225==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_E1")},exports.getDD5AE4Async=async deviceId=>BleCmdAnalysis.getData(deviceId,{command:["0xdd","0x5a","0xe4","0x02","0x18","0x81","0xfe","0x81","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&228==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_E4"),exports.getDD5AFAAsync=async(deviceId,value)=>{const hex=100*value,hexStr=BleDataProcess.decimalToHex(hex,4),_command=["0xFA","0x05","0x00","0x70","0x01",...[`0x${hexStr.slice(0,2)}`,`0x${hexStr.slice(2,4)}`]],checks=BleDataProcess.generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&250==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_FA")},exports.getDD5AFBAsync=async(deviceId,type,value)=>{const _command=["0xFB","0x02",type,value],checks=BleDataProcess.generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return console.log("command: ",command),BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&251==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_FB")},exports.getDDA503Async=getDDA503Async,exports.getDDA504Async=async(deviceId,dataScope)=>{const hex=await BleCmdAnalysis.getData(deviceId,{command:["0xdd","0xa5","0x04","0x00","0xff","0xfc","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&4==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=BleDataProcess.generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_04");return hex?resolveDDA504(hex,dataScope):null},exports.getDDA505Async=getDDA505Async,exports.getDDA507Async=async deviceId=>BleCmdAnalysis.getData(deviceId,{command:["0xDD","0xA5","0x07","0x00","0xFF","0xF9","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&7==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=BleDataProcess.generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_07历史运行履历总数"),exports.getDDA508Async=async(deviceId,i=0)=>{const _command=["0x08",`0x${i.toString(16).padStart(2,0)}`],checks=BleDataProcess.generateCrcCheckSum(_command),command=["0xDD","0xA5",..._command,...checks,"0x77"];return BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&8==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=BleDataProcess.generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_08读取履历详情")},exports.getDDA5FAAsync=async(deviceId,paramNo,length)=>{const _values=[...paramNo,length],_command=["0xFA",BleDataProcess.decimalToHex(_values.length),..._values],checks=BleDataProcess.generateCrcCheckSum(_command),command=["0xDD","0xA5",..._command,...checks,"0x77"];return BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&250==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"READ_DDA5_FA")},exports.getDDA5OldAsync=async(deviceId,path)=>{const values=[path,"0x00"],checks=BleDataProcess.generateCrcCheckSum(values),command=["0xDD","0xa5",...values,...checks,"0x77"];return BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&hexArr[1]==path,pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=BleDataProcess.generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_读旧协议读参")},exports.getProtectCountCmd=async deviceId=>{const data=await BleCmdAnalysis.getData(deviceId,{command:["0xdd","0xa5","0xaa","0x00","0xff","0x56","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&170==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DDA5_AA保护次数"),arr=[];for(let i=4;i<data.length-4;i+=2){const offset=i;console.log("offset",offset);let value=((255&data[offset])<<8)+(255&data[offset+1]);arr.push(value)}return arr},exports.readExistFactory=async deviceId=>set_PlanCMD_DD(deviceId,"DD5A01020000FFFD77"),exports.resolve3B3C=resolve3B3C,exports.resolveBMSCmd=data=>{if(!data)return null;return{dataStr:BleDataProcess.hexArr2string(data),status:BleDataProcess.hex2string(data[2]),len:data[3]}},exports.resolveBaseDD=data=>{if(!data)return null;const dataStr=BleDataProcess.hexArr2string(data),content=data.slice(4,data.length-3);return{dataStr:dataStr,status:BleDataProcess.hex2string(data[2]),len:data[3],content:content}},exports.resolveDDA500=resolveDDA500,exports.resolveDDA503=resolveDDA503,exports.resolveDDA504=resolveDDA504,exports.resolveDDA505=resolveDDA505,exports.resolveDDA508=data=>{if(!data)return null;if(!data)return null;const hexArr=data.map(o=>o.toString(16).padStart(2,"0").toUpperCase()),f=s=>parseInt(s,16),fet=data[40].toString(2).padStart(8,"0").split("").reverse(),protection=f(hexArr[23]+hexArr[22]).toString(2).padStart(16,"0"),n=Number(fet[7])?10:100;let current=(hexArr[16]<<8)+(255&hexArr[17]);current=current>32768?(current-65536)/n:current/n;const electricity=Number(current.toFixed(2)),sysTime=65536*data[30]+256*data[31]+data[32];console.log("hexArr[30], hexArr[31], hexArr[32]",hexArr[30],hexArr[31],hexArr[32]),console.warn("sysTime: ",sysTime);const reportTime=65536*data[11]+256*data[12]+data[13];console.log("data[11], data[12], data[13]",data[11],data[12],data[13]),console.warn("reportTime: ",reportTime);const time=60*Math.abs(sysTime-reportTime)*1e3;console.warn("time: ",time);const timestamp=(new Date).getTime()-time;return console.warn("new Date().getTime(): ",(new Date).getTime()),{dataStr:hexArr.join(""),status:BleDataProcess.hex2string(data[2]),len:data[3],total:f(hexArr[4]+hexArr[5]),page:f(hexArr[6]+hexArr[7]),type:data[8],sysTime:sysTime,timestamp:timestamp,sumV:(f(hexArr[15]+hexArr[14])/100).toFixed(2),sumE:electricity,restC:(f(hexArr[19]+hexArr[18])/n).toFixed(2),designC:(f(hexArr[21]+hexArr[20])/n).toFixed(2),protections:resolveProtections(protection)._arr,protectionIndex:resolveProtections(protection)._indexs,tH:((f(hexArr[27]+hexArr[26])-2731)/10).toFixed(2),tL:((f(hexArr[29]+hexArr[28])-2731)/10).toFixed(2),vH:(f(hexArr[35]+hexArr[34])/1e3).toFixed(3),vL:(f(hexArr[37]+hexArr[36])/1e3).toFixed(3),nH:f(hexArr[38]),nL:f(hexArr[39]),fet:fet.join("")}},exports.resolveDDA5FA=data=>{if(!data)return null;return{dataStr:BleDataProcess.hexArr2string(data),status:BleDataProcess.hex2string(data[2]),len:data[3],type:data[5],value:data.slice(7,-3)}},exports.resolveProtections=resolveProtections,exports.sendBMSAsync=async(deviceId,values)=>{const command=values.match(/[0-9a-fA-F]{2}/g)?.map(item=>`0x${item}`)||[];return BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&hexArr[1]==command[2],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},`DD5A_${command[2]}`)},exports.setDDA5FAAsync=async(deviceId,paramNo,valueLength,content)=>{const _values=[...paramNo,valueLength,...content],_command=["0xFA",BleDataProcess.decimalToHex(_values.length),..._values],checks=BleDataProcess.generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&250==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"SET_DDA5_FA")},exports.setDDA5OldAsync=async(deviceId,path,value,type="")=>{const values=[path,"0x02",...value],checks=BleDataProcess.generateCrcCheckSum(values),command=["0xDD","0x5A",...values,...checks,"0x77"];return BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&hexArr[1]==path,pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DDA5_写旧协议读参"+type)},exports.set_PlanCMD_3B3C=async(deviceId,command)=>{"string"==typeof command&&(command=command.match(/(.{2})/g).map(o=>`0x${o}`));let result=null;try{const data=await BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:59==hexArr[0]&&60==hexArr[1],pkgLen:hexArr[11]+15}),pkgVerifyHandler:pkg=>({verified:!0})},"PlanCMD_3B3C");if(data){const dataStr=BleDataProcess.hexArr2string(data),content=data.slice(12,data.length-3);result={dataStr:dataStr,status:128==data[10]?1:0,addr:BleDataProcess.hexArr2string(data.slice(2,10)),content:content}}}catch(error){console.error(error)}return result},exports.set_PlanCMD_DD=set_PlanCMD_DD;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var BleDataProcess=require("../BleDataProcess.js"),BleCmdAnalysis=require("./BleCmdAnalysis.js"),BleCmdFFAA=require("./BleCmdFFAA.js");const set_PlanCMD_DD=async(deviceId,command)=>{"string"==typeof command&&(command=command.match(/(.{2})/g).map(o=>`0x${o}`));let result=null;try{const data=await BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"PlanCMD_DD");if(data){const dataStr=BleDataProcess.hexArr2string(data),content=data.slice(4,data.length-3);result={data:data,dataStr:dataStr,status:BleDataProcess.hex2string(data[2]),len:data[3],content:content}}else result={status:0,content:[]}}catch(error){console.error(error)}return result},get3B3CAsync=async deviceId=>{const addressCode=["0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00"],commandCode=["0x01"],data=[],dataLength=[`0x${BleDataProcess.decimalToHex(data.length,2)}`],check=BleDataProcess.generateCrc16modbusCheck([...addressCode,...commandCode,...dataLength,...data],!1),command=["0x3b","0x3c",...addressCode,...commandCode,...dataLength,...data,...check,"0x0d"];return BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:59==hexArr[0]&&60==hexArr[1],pkgLen:hexArr[11]+15}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=BleDataProcess.generateCrc16modbusCheck(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"3B3C")},resolve3B3C=data=>{if(!data)return null;let result={dataStr:BleDataProcess.hexArr2string(data),status:BleDataProcess.hex2string(data[10]),addr:BleDataProcess.hexArr2string(data.slice(2,10))};const content=data.slice(12,data.length-3);for(;content.length>0;){const[v1,v2,...v]=content.splice(0,content[1]+2);if(1==v1&&(result.productFlag=BleDataProcess.hex2string(v1),result.productLen=v2,v)){const[productType,frontType,protocolV,level]=v.map(o=>BleDataProcess.hex2string(o));Object.assign(result,{productType:productType,frontType:frontType,protocolV:protocolV,level:level})}2==v1&&(result.hardwareFlag=BleDataProcess.hex2string(v1),result.hardwareLen=v2,result.hardwareV=BleDataProcess.hexArr2Assic(v)),3==v1&&(result.sofewareFlag=BleDataProcess.hex2string(v1),result.sofewareLen=v2,result.sofewareV=BleDataProcess.hexArr2Assic(v)),4==v1&&(result.pcbFlag=BleDataProcess.hex2string(v1),result.pcbLen=v2,result.pcbContent=BleDataProcess.hexArr2Assic(v))}return result},getDDA503Async=async deviceId=>{const hex=await BleCmdAnalysis.getData(deviceId,{command:["0xdd","0xa5","0x03","0x00","0xff","0xfd","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&3==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=BleDataProcess.generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_03");return hex?resolveDDA503(hex):null},resolveDDA503=data=>{if(!data)return null;const cmdResp03=BleDataProcess.hexArr2string(data),content=data.slice(4,data.length-3),binArr=data[24].toString(2).padStart(8,"0").split("").reverse(),balances=data.slice(16,20).flatMap(byte=>byte.toString(2).padStart(8,"0").split("").reverse());console.warn("BC: ---------------",balances);const fet=data[24],chargeSwitch=!!Number(binArr[0]),dischargeSwitch=!!Number(binArr[1]),BMSVersion=BleDataProcess.decimalToHex(data[22]),humidityIndex=2*data[26]+27,humidity=data[humidityIndex],n=Number(binArr[7])||136==humidity?10:100,totalVoltage=Number((((data[4]<<8)+(255&data[5]))/100).toFixed(2));let current=(data[6]<<8)+(255&data[7]);current=current>32768?(current-65536)/n:current/n;const electricity=Number(current.toFixed(2)),power=Number((totalVoltage*electricity).toFixed(2)),soc=data[23]??0,seriesNum=data[25]??0,volumeHex=BleDataProcess.decimalToHex(data[8])+BleDataProcess.decimalToHex(data[9]),surplusCapacity=Number((BleDataProcess.hexToDecimal(volumeHex)/n).toFixed(2)),normCapHex=BleDataProcess.decimalToHex(data[10])+BleDataProcess.decimalToHex(data[11]),normCap=Number((BleDataProcess.hexToDecimal(normCapHex)/n).toFixed(2)),cycleHex=BleDataProcess.decimalToHex(data[12])+BleDataProcess.decimalToHex(data[13]),cycleIndex=BleDataProcess.hexToDecimal(cycleHex),fccHex=BleDataProcess.decimalToHex(data[humidityIndex+3])+BleDataProcess.decimalToHex(data[humidityIndex+4]),fullChargeCapacity=Number((BleDataProcess.hexToDecimal(fccHex)/n).toFixed(2)),SOH=cycleIndex<=100?100:Math.min(100,fullChargeCapacity/normCap*100),heatingState=!!Number(binArr[4])||!!Number(binArr[3]);let heatingCurrent=null;const hasHeatingCurrent=data[3]+7>=humidityIndex+9+4+1,hasEquilCurrent=data[3]+7>=humidityIndex+7+4+1;if(heatingState&&hasHeatingCurrent){const i=humidityIndex+9;heatingCurrent=heatingCurrent=((data[i]<<8|data[i+1])/100).toFixed(2)}let equilibriumCurrent=null;if(hasEquilCurrent){const i=humidityIndex+7;let equilCurrent=(data[i]<<8)+(255&data[i+1]);equilCurrent=equilCurrent>32768?(equilCurrent-65536)/1e3:equilCurrent/1e3,equilibriumCurrent=Number(equilCurrent.toFixed(2))}const isFactoryMode=!!Number(binArr[6]),equilibriumStatus=!(0===data[16]&&0===data[17]),protectStatus=!(0===data[20]&&0===data[21]),protectStateHex=BleDataProcess.decimalToHex(data[20])+BleDataProcess.decimalToHex(data[21]),protVal=BleDataProcess.hexToDecimal(protectStateHex);let alarmIndex=2*data[26]+28,alarmStateHex=BleDataProcess.decimalToHex(data[alarmIndex])+BleDataProcess.decimalToHex(data[alarmIndex+1]),alarmsState=BleDataProcess.hexToDecimal(alarmStateHex);const ntcNums=255&data[26],temperaturesList=Array.from({length:ntcNums},(_,i)=>((256*(255&data[26+2*i+1])+(255&data[26+2*i+2])-2731)/10).toFixed(1)),fahTempList=[];temperaturesList.forEach(el=>{const value=1.8*Number(el)+32;fahTempList.push(value.toFixed(1))});const temperatures=temperaturesList.map((item,index)=>({name:index+1,value:item}));return{cmdResp03:cmdResp03,status:BleDataProcess.hex2string(data[2]),len:data[3],softwareV:BleDataProcess.hex2string(content[18]),balances:balances,BMSVersion:BMSVersion,soc:soc,normCap:normCap,surplusCapacity:surplusCapacity,totalVoltage:totalVoltage,electricity:electricity,power:power,cycleIndex:cycleIndex,equilibriumStatus:equilibriumStatus,chargeSwitch:chargeSwitch,dischargeSwitch:dischargeSwitch,temperatures:temperatures,humidity:humidity,protectStatus:protectStatus,fullChargeCapacity:fullChargeCapacity,SOH:SOH,heatingState:heatingState,heatingCurrent:heatingCurrent,equilibriumCurrent:equilibriumCurrent,isFactoryMode:isFactoryMode,protVal:protVal,alarmsState:alarmsState,ntcNums:ntcNums,temperaturesList:temperaturesList,fahTempList:fahTempList,fet:fet,seriesNum:seriesNum}},getDDA504Async=async(deviceId,dataScope)=>{const hex=await BleCmdAnalysis.getData(deviceId,{command:["0xdd","0xa5","0x04","0x00","0xff","0xfc","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&4==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=BleDataProcess.generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_04");return hex?resolveDDA504(hex,dataScope):null},resolveDDA504=(data,dataScope)=>{if(console.log("data: ",data),!data)return null;const cmdResp04=BleDataProcess.hexArr2string(data),voltageList=[];for(let index=4;index<parseInt(data[3])+4;index+=2){let voltageHex=BleDataProcess.decimalToHex(data[index])+BleDataProcess.decimalToHex(data[index+1]),voltage=BleDataProcess.hexToDecimal(voltageHex);voltageList.push(Number(voltage))}let highestVoltage=null,lowestVoltage=null,averageVoltage=null,dropoutVoltage=null;if(voltageList.length>0){highestVoltage=Math.max(...voltageList),lowestVoltage=Math.min(...voltageList);averageVoltage=voltageList.reduce((acc,cur)=>acc+cur,0)/voltageList.length;const dropout=highestVoltage-lowestVoltage,precision=dataScope?3:2;highestVoltage=Number((highestVoltage/1e3).toFixed(precision)),lowestVoltage=Number((lowestVoltage/1e3).toFixed(precision)),averageVoltage=Number((averageVoltage/1e3).toFixed(precision)),dropoutVoltage=Number((dropout/1e3).toFixed(precision))}voltageList.forEach((v,i)=>{let newV=v/1e3;voltageList[i]=Number(newV.toFixed(dataScope?3:2))});const voltageSeries=voltageList.map((item,index)=>({name:index+1,value:item}));return{cmdResp04:cmdResp04,voltageList:voltageList,voltageSeries:voltageSeries,highestVoltage:highestVoltage,lowestVoltage:lowestVoltage,averageVoltage:averageVoltage,dropoutVoltage:dropoutVoltage}},resolveDDA500=data=>{if(!data)return null;return{dataStr:BleDataProcess.hexArr2string(data),status:BleDataProcess.hex2string(data[2]),len:data[3],type:data[5]}},getDD5AFBAsync=async(deviceId,type,value)=>{const _command=["0xFB","0x02",type,value],checks=BleDataProcess.generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return console.log("command: ",command),BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&251==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_FB")},resolveBaseDD=data=>{if(!data)return null;const dataStr=BleDataProcess.hexArr2string(data),content=data.slice(4,data.length-3);return{dataStr:dataStr,status:BleDataProcess.hex2string(data[2]),len:data[3],content:content}},getDDA505Async=async deviceId=>BleCmdAnalysis.getData(deviceId,{command:["0xdd","0xa5","0x05","0x00","0xff","0xfb","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&5==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=BleDataProcess.generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_05"),resolveDDA505=data=>{if(!data)return null;return{dataStr:BleDataProcess.hexArr2string(data),status:BleDataProcess.hex2string(data[2]),len:data[3],hardwareV:BleDataProcess.hexArr2Assic(data.slice(4,data.length-3))}},resolveProtections=binary=>{const arr=binary.split("").reverse(),map=["device.0041","device.0042","device.0043","device.0044","device.0045","device.0046","device.0047","device.0048","device.0049","device.0050","device.0051","device.0052","device.0053","device.0054","device.0055","device.00551"];let _arr=[],_indexs=[];for(let i=0;i<arr.length;i++)1==arr[i]&&(_arr.push(map[i]),_indexs.push(i));return{_arr:_arr,_indexs:_indexs}};exports.activateAsync=async deviceId=>{const startTime=+new Date,disChargMOSHex=await getDD5AFBAsync(deviceId,"0x00","0x00"),disChargMOSRes=resolveBaseDD(disChargMOSHex)?.dataStr,disChargEndTime=+new Date,activeHex=await getDD5AFBAsync(deviceId,"0x05","0x01"),activeRes=resolveBaseDD(disChargMOSHex)?.dataStr;let baseInfo=null;const endTime=+new Date;await BleDataProcess.sleep(300),baseInfo=await getDDA503Async(deviceId);return{disChargMOSHex:disChargMOSHex,disChargMOSRes:disChargMOSRes,activeHex:activeHex,activeRes:activeRes,baseInfo:baseInfo,voltageInfo:await getDDA504Async(deviceId),startTime:startTime,disChargEndTime:disChargEndTime,endTime:endTime}},exports.enterFactory=async deviceId=>set_PlanCMD_DD(deviceId,"DD5A00025678FF3077"),exports.existFactory=async deviceId=>set_PlanCMD_DD(deviceId,"DD5A01022828ffad77"),exports.get3B3CAsync=get3B3CAsync,exports.get3B3CInfo=({deviceId:deviceId,macAddr:macAddr,moduleType:moduleType,productType:productType})=>new Promise(async(resolve,reject)=>{let reportData={macAddr:macAddr,moduleTypeKey:moduleType,productKey:productType},_3b3c=null,_dda5_03=null,_dda5_05=null,_ffaa_80=null;try{if(!deviceId)throw new Error("deviceId required");const _ffaa_80_hex=await BleCmdFFAA.getFFAA80Async(deviceId,"AT^VERSION?");_ffaa_80=BleCmdFFAA.resolveFFAA80(_ffaa_80_hex),console.warn("Report-3B3C _ffaa_80 ",{_ffaa_80_hex:_ffaa_80_hex,_ffaa_80:_ffaa_80}),_ffaa_80&&(reportData.moduleVersion=_ffaa_80?.moduleVersion);const _3b3c_hex=await get3B3CAsync(deviceId);if(_3b3c=resolve3B3C(_3b3c_hex),console.warn("Report-3B3C _3b3c ",{_3b3c_hex:_3b3c_hex,_3b3c:_3b3c}),_3b3c)reportData.cmdContent=_3b3c?.dataStr;else{const _dda5_03_hex=await getDDA503Async(deviceId);_dda5_03=resolveDDA503(_dda5_03_hex),console.warn("Report-3B3C _dda5_03 ",{_dda5_03_hex:_dda5_03_hex,_dda5_03:_dda5_03}),_dda5_03&&(reportData.bmsVersion=_dda5_03?.softwareV);const _dda5_05_hex=await getDDA505Async(deviceId);_dda5_05=resolveDDA505(_dda5_05_hex),console.warn("Report-3B3C _dda5_05 ",{_dda5_05_hex:_dda5_05_hex,_dda5_05:_dda5_05}),_dda5_05&&(reportData.bmsSn=_dda5_05?.hardwareV)}resolve({reportData:reportData,_3b3c:_3b3c,_dda5_03:_dda5_03,_dda5_05:_dda5_05,_ffaa_80:_ffaa_80})}catch(error){reject(error)}}),exports.getChipTypeAsync=async deviceId=>{const hex=await BleCmdAnalysis.getData(deviceId,{command:["0xdd","0xa5","0x00","0x00","0x00","0x00","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&0==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=BleDataProcess.generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_00");return hex?resolveDDA500(hex):null},exports.getDD5A0AAsync=async(deviceId,value)=>{const _command=["0x0A","0x02",...BleDataProcess.stringToTwoHexArray(value)],checks=BleDataProcess.generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return console.log("command: ",command),BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&10==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},`DD5A_0A_${value}`)},exports.getDD5A0EAsync=async deviceId=>BleCmdAnalysis.getData(deviceId,{command:["0xDD","0x5A","0x0E","0x02","0x81","0x18","0xFF","0x57","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&14==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_0E_复位"),exports.getDD5A17Async=async deviceId=>BleCmdAnalysis.getData(deviceId,{command:["0xDD","0x5A","0x17","0x02","0x00","0x01","0xFF","0xE6","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&23==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_17-清除电池循环次数"),exports.getDD5AAllAsync=async(deviceId,path,lengthHex,values,type)=>{const _command=[path,lengthHex,...values],checks=BleDataProcess.generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&hexArr[1]==path,pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},`DD5A_${path}_${type}`)},exports.getDD5AE0Async=async(deviceId,value)=>{const hex=100*value,hexStr=BleDataProcess.decimalToHex(hex,4),_values=[`0x${hexStr.slice(0,2)}`,`0x${hexStr.slice(2,4)}`],_command=["0xE0","0x02",..._values],checks=BleDataProcess.generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return console.warn("=======CCCCCCC=SET===",{value:value,hex:hex,hexStr:hexStr,_values:_values,_command:_command,checks:checks,command:command}),BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&224==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_E0")},exports.getDD5AE1Async=async(deviceId,value)=>{const _command=["0xE1","0x02","0x00",value],checks=BleDataProcess.generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&225==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_E1")},exports.getDD5AE4Async=async deviceId=>BleCmdAnalysis.getData(deviceId,{command:["0xdd","0x5a","0xe4","0x02","0x18","0x81","0xfe","0x81","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&228==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_E4"),exports.getDD5AFAAsync=async(deviceId,value)=>{const hex=100*value,hexStr=BleDataProcess.decimalToHex(hex,4),_command=["0xFA","0x05","0x00","0x70","0x01",...[`0x${hexStr.slice(0,2)}`,`0x${hexStr.slice(2,4)}`]],checks=BleDataProcess.generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&250==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_FA")},exports.getDD5AFBAsync=getDD5AFBAsync,exports.getDDA503Async=getDDA503Async,exports.getDDA504Async=getDDA504Async,exports.getDDA505Async=getDDA505Async,exports.getDDA507Async=async deviceId=>BleCmdAnalysis.getData(deviceId,{command:["0xDD","0xA5","0x07","0x00","0xFF","0xF9","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&7==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=BleDataProcess.generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_07历史运行履历总数"),exports.getDDA508Async=async(deviceId,i=0)=>{const _command=["0x08",`0x${i.toString(16).padStart(2,0)}`],checks=BleDataProcess.generateCrcCheckSum(_command),command=["0xDD","0xA5",..._command,...checks,"0x77"];return BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&8==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=BleDataProcess.generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_08读取履历详情")},exports.getDDA5DCAsync=deviceId=>{const _command=["0xDE","0x00"],checks=BleDataProcess.generateCrcCheckSum(_command),command=["0xDD","0xA5",..._command,...checks,"0x77"];return BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&222==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=BleDataProcess.generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_DC")},exports.getDDA5FAAsync=async(deviceId,paramNo,length)=>{const _values=[...paramNo,length],_command=["0xFA",BleDataProcess.decimalToHex(_values.length),..._values],checks=BleDataProcess.generateCrcCheckSum(_command),command=["0xDD","0xA5",..._command,...checks,"0x77"];return BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&250==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"READ_DDA5_FA")},exports.getDDA5OldAsync=async(deviceId,path)=>{const values=[path,"0x00"],checks=BleDataProcess.generateCrcCheckSum(values),command=["0xDD","0xa5",...values,...checks,"0x77"];return BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&hexArr[1]==path,pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=BleDataProcess.generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_读旧协议读参")},exports.getProtectCountCmd=async deviceId=>{const data=await BleCmdAnalysis.getData(deviceId,{command:["0xdd","0xa5","0xaa","0x00","0xff","0x56","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&170==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DDA5_AA保护次数"),arr=[];for(let i=4;i<data.length-4;i+=2){const offset=i;console.log("offset",offset);let value=((255&data[offset])<<8)+(255&data[offset+1]);arr.push(value)}return arr},exports.readExistFactory=async deviceId=>set_PlanCMD_DD(deviceId,"DD5A01020000FFFD77"),exports.resetCapacity=deviceId=>BleCmdAnalysis.getData(deviceId,{command:["0xDD","0x5A","0x0A","0x02","0x01","0x00","0xFF","0xF3","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&10==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_0A"),exports.resolve3B3C=resolve3B3C,exports.resolveBMSCmd=data=>{if(!data)return null;return{dataStr:BleDataProcess.hexArr2string(data),status:BleDataProcess.hex2string(data[2]),len:data[3]}},exports.resolveBaseDD=resolveBaseDD,exports.resolveDD5A0A=data=>{if(!data)return null;const dataStr=BleDataProcess.hexArr2string(data),statusDec=data[2],len=data[3],succeeded=0===statusDec;return{dataStr:dataStr,status:BleDataProcess.hex2string(statusDec),len:len,succeeded:succeeded,message:succeeded?"CMD_EXEC_SUCCESS":"CMD_EXEC_FAIL"}},exports.resolveDDA500=resolveDDA500,exports.resolveDDA503=resolveDDA503,exports.resolveDDA504=resolveDDA504,exports.resolveDDA505=resolveDDA505,exports.resolveDDA508=data=>{if(!data)return null;if(!data)return null;const hexArr=data.map(o=>o.toString(16).padStart(2,"0").toUpperCase()),f=s=>parseInt(s,16),fet=data[40].toString(2).padStart(8,"0").split("").reverse(),protection=f(hexArr[23]+hexArr[22]).toString(2).padStart(16,"0"),n=Number(fet[7])?10:100;let current=(hexArr[16]<<8)+(255&hexArr[17]);current=current>32768?(current-65536)/n:current/n;const electricity=Number(current.toFixed(2)),sysTime=65536*data[30]+256*data[31]+data[32];console.log("hexArr[30], hexArr[31], hexArr[32]",hexArr[30],hexArr[31],hexArr[32]),console.warn("sysTime: ",sysTime);const reportTime=65536*data[11]+256*data[12]+data[13];console.log("data[11], data[12], data[13]",data[11],data[12],data[13]),console.warn("reportTime: ",reportTime);const time=60*Math.abs(sysTime-reportTime)*1e3;console.warn("time: ",time);const timestamp=(new Date).getTime()-time;return console.warn("new Date().getTime(): ",(new Date).getTime()),{dataStr:hexArr.join(""),status:BleDataProcess.hex2string(data[2]),len:data[3],total:f(hexArr[4]+hexArr[5]),page:f(hexArr[6]+hexArr[7]),type:data[8],sysTime:sysTime,timestamp:timestamp,sumV:(f(hexArr[15]+hexArr[14])/100).toFixed(2),sumE:electricity,restC:(f(hexArr[19]+hexArr[18])/n).toFixed(2),designC:(f(hexArr[21]+hexArr[20])/n).toFixed(2),protections:resolveProtections(protection)._arr,protectionIndex:resolveProtections(protection)._indexs,tH:((f(hexArr[27]+hexArr[26])-2731)/10).toFixed(2),tL:((f(hexArr[29]+hexArr[28])-2731)/10).toFixed(2),vH:(f(hexArr[35]+hexArr[34])/1e3).toFixed(3),vL:(f(hexArr[37]+hexArr[36])/1e3).toFixed(3),nH:f(hexArr[38]),nL:f(hexArr[39]),fet:fet.join("")}},exports.resolveDDA5DC=data=>{if(!data)return null;const dataStr=BleDataProcess.hexArr2string(data),status=BleDataProcess.hex2string(data[2]),len=255&data[3],resistances_milliohm=[];for(let i=4;i<4+len;i+=2){const value=((255&data[i])<<8)+(255&data[i+1]);resistances_milliohm.push(value)}console.log("均衡线电阻(mΩ): ",resistances_milliohm,data);let maxResistance=null,minResistance=null,avgResistance=null;resistances_milliohm.length&&(maxResistance=Math.max(...resistances_milliohm),minResistance=Math.min(...resistances_milliohm),avgResistance=resistances_milliohm.reduce((a,c)=>a+c,0)/resistances_milliohm.length);const resistances_ohm=resistances_milliohm.map(v=>Number((v/1e3).toFixed(3))),resistancesSeries=resistances_ohm.map((v,idx)=>({name:idx+1,value:v}));return{dataStr:dataStr,status:status,len:len,resistances_milliohm:resistances_milliohm,resistances_ohm:resistances_ohm,maxResistance_milliohm:maxResistance,minResistance_milliohm:minResistance,avgResistance_milliohm:avgResistance,maxResistance_ohm:null!=maxResistance?Number((maxResistance/1e3).toFixed(3)):null,minResistance_ohm:null!=minResistance?Number((minResistance/1e3).toFixed(3)):null,avgResistance_ohm:null!=avgResistance?Number((avgResistance/1e3).toFixed(3)):null,resistancesSeries:resistancesSeries}},exports.resolveDDA5FA=data=>{if(!data)return null;return{dataStr:BleDataProcess.hexArr2string(data),status:BleDataProcess.hex2string(data[2]),len:data[3],type:data[5],value:data.slice(7,-3)}},exports.resolveProtections=resolveProtections,exports.sendBMSAsync=async(deviceId,values)=>{const command=values.match(/[0-9a-fA-F]{2}/g)?.map(item=>`0x${item}`)||[];return BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&hexArr[1]==command[2],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},`DD5A_${command[2]}`)},exports.setDDA5FAAsync=async(deviceId,paramNo,valueLength,content)=>{const _values=[...paramNo,valueLength,...content],_command=["0xFA",BleDataProcess.decimalToHex(_values.length),..._values],checks=BleDataProcess.generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&250==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"SET_DDA5_FA")},exports.setDDA5OldAsync=async(deviceId,path,value,type="")=>{const values=[path,"0x02",...value],checks=BleDataProcess.generateCrcCheckSum(values),command=["0xDD","0x5A",...values,...checks,"0x77"];return BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&hexArr[1]==path,pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DDA5_写旧协议读参"+type)},exports.set_PlanCMD_3B3C=async(deviceId,command)=>{"string"==typeof command&&(command=command.match(/(.{2})/g).map(o=>`0x${o}`));let result=null;try{const data=await BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:59==hexArr[0]&&60==hexArr[1],pkgLen:hexArr[11]+15}),pkgVerifyHandler:pkg=>({verified:!0})},"PlanCMD_3B3C");if(data){const dataStr=BleDataProcess.hexArr2string(data),content=data.slice(12,data.length-3);result={dataStr:dataStr,status:128==data[10]?1:0,addr:BleDataProcess.hexArr2string(data.slice(2,10)),content:content}}}catch(error){console.error(error)}return result},exports.set_PlanCMD_DD=set_PlanCMD_DD;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var BleDataProcess=require("../BleDataProcess.js"),BleCmdDD=require("./BleCmdDD.js");const readParamCmd=(chipType,deviceId,paramInfo,needFactoryMode=!0)=>(console.log("chipType: ",chipType),new Promise(async(resolve,reject)=>{const{address:address=0,length:length=1,oldAddress:oldAddress="0x1f"}=paramInfo,hexAddress=BleDataProcess.decimalToTwoByteHexArray(address),hexLength=BleDataProcess.decimalToHex(length),handleRead=async(readFunction,index)=>{try{const hex=await readFunction();if(4==index&&needFactoryMode&&await BleCmdDD.readExistFactory(deviceId),!hex)return void resolve(null);const data=hex.slice(index,-3);console.log("data: 读参数",data),resolve(data||null)}catch(error){console.error("读取参数出错: ",error),reject(error)}};try{if(chipType)await handleRead(async()=>await BleCmdDD.getDDA5FAAsync(deviceId,hexAddress,hexLength),7);else{if(!oldAddress)return resolve(null);needFactoryMode&&await BleCmdDD.enterFactory(deviceId),await handleRead(async()=>await BleCmdDD.getDDA5OldAsync(deviceId,oldAddress),4)}}catch(error){console.error("读取参数出错---: ",error),reject(error)}})),setParamCmd=(chipType,deviceId,paramInfoArray)=>{console.log("chipType: 芯片",chipType);const paramsToProcess=Array.isArray(paramInfoArray)?paramInfoArray:[paramInfoArray];return new Promise(async(resolve,reject)=>{try{await BleCmdDD.enterFactory(deviceId);const results=[];for(let i=0;i<paramsToProcess.length;i++){const paramInfo=paramsToProcess[i],{address:address,length:length,values:values,oldAddress:oldAddress}=paramInfo,hexAddress=BleDataProcess.decimalToTwoByteHexArray(address),hexLength=BleDataProcess.decimalToHex(length);let hex;if(hex=chipType?await BleCmdDD.setDDA5FAAsync(deviceId,hexAddress,hexLength,values):await BleCmdDD.setDDA5OldAsync(deviceId,oldAddress,values),console.log(`data: 写入第${i+1}个参数结果`,hex),!hex)throw new Error(`设置第${i+1}个参数失败`);results.push(hex)}await BleCmdDD.existFactory(deviceId),resolve(results)}catch(error){console.error("设置参数出错: ",error);try{await BleCmdDD.existFactory(deviceId)}catch(exitError){console.error("退出工厂模式失败: ",exitError)}reject(error)}})};exports.getSysParamCmd=async(chipType,deviceId,paramInfo,needFactoryMode=!0)=>{try{console.log("paramInfo: ",paramInfo);const paramObj={address:paramInfo.paramNo,length:paramInfo.paramLength/2,oldAddress:paramInfo.oldParamNo};let data=await readParamCmd(chipType,deviceId,paramObj,needFactoryMode);return data||null}catch(error){throw console.error("error: 读系统参数报错 getSysParamCmd",error),error}},exports.readParamCmd=readParamCmd,exports.setCapacityParamCmd=(chipType,deviceId,paramInfo)=>(console.log("chipType: 芯片",chipType),new Promise(async(resolve,reject)=>{const{values:values}=paramInfo,circular={address:1,oldAddress:"0x11",values:.8*values,length:1},full={address:112,oldAddress:"0x10",values:values,length:1},handleSet=async(setFunction,index)=>{try{const hex=await setFunction();return console.log("data: 写入参数结果",hex),hex||void reject("设置参数失败")}catch(error){console.error("设置参数出错: ",error),reject(error)}},handleParam=async paramObj=>{const{
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var BleDataProcess=require("../BleDataProcess.js"),BleCmdDD=require("./BleCmdDD.js");const readParamCmd=(chipType,deviceId,paramInfo,needFactoryMode=!0)=>(console.log("chipType: ",chipType),new Promise(async(resolve,reject)=>{const{address:address=0,length:length=1,oldAddress:oldAddress="0x1f"}=paramInfo,hexAddress=BleDataProcess.decimalToTwoByteHexArray(address),hexLength=BleDataProcess.decimalToHex(length),handleRead=async(readFunction,index)=>{try{const hex=await readFunction();if(4==index&&needFactoryMode&&await BleCmdDD.readExistFactory(deviceId),!hex)return void resolve(null);const data=hex.slice(index,-3);console.log("data: 读参数",data),resolve(data||null)}catch(error){console.error("读取参数出错: ",error),reject(error)}};try{if(chipType)await handleRead(async()=>await BleCmdDD.getDDA5FAAsync(deviceId,hexAddress,hexLength),7);else{if(!oldAddress)return resolve(null);needFactoryMode&&await BleCmdDD.enterFactory(deviceId),await handleRead(async()=>await BleCmdDD.getDDA5OldAsync(deviceId,oldAddress),4)}}catch(error){console.error("读取参数出错---: ",error),reject(error)}})),setParamCmd=(chipType,deviceId,paramInfoArray)=>{console.log("chipType: 芯片",chipType);const paramsToProcess=Array.isArray(paramInfoArray)?paramInfoArray:[paramInfoArray];return new Promise(async(resolve,reject)=>{try{await BleCmdDD.enterFactory(deviceId);const results=[];for(let i=0;i<paramsToProcess.length;i++){const paramInfo=paramsToProcess[i],{address:address,length:length,values:values,oldAddress:oldAddress}=paramInfo,hexAddress=BleDataProcess.decimalToTwoByteHexArray(address),hexLength=BleDataProcess.decimalToHex(length);let hex;if(hex=chipType?await BleCmdDD.setDDA5FAAsync(deviceId,hexAddress,hexLength,values):await BleCmdDD.setDDA5OldAsync(deviceId,oldAddress,values),console.log(`data: 写入第${i+1}个参数结果`,hex),!hex)throw new Error(`设置第${i+1}个参数失败`);results.push(hex)}await BleCmdDD.existFactory(deviceId),resolve(results)}catch(error){console.error("设置参数出错: ",error);try{await BleCmdDD.existFactory(deviceId)}catch(exitError){console.error("退出工厂模式失败: ",exitError)}reject(error)}})};exports.getSysParamCmd=async(chipType,deviceId,paramInfo,needFactoryMode=!0)=>{try{console.log("paramInfo: ",paramInfo);const paramObj={address:paramInfo.paramNo,length:paramInfo.paramLength/2,oldAddress:paramInfo.oldParamNo};let data=await readParamCmd(chipType,deviceId,paramObj,needFactoryMode);return data||null}catch(error){throw console.error("error: 读系统参数报错 getSysParamCmd",error),error}},exports.readParamCmd=readParamCmd,exports.setCapacityParamCmd=(chipType,deviceId,paramInfo)=>(console.log("chipType: 芯片",chipType),new Promise(async(resolve,reject)=>{const{values:values}=paramInfo,circular={address:1,oldAddress:"0x11",values:.8*values,length:1},full={address:112,oldAddress:"0x10",values:values,length:1},handleSet=async(setFunction,index)=>{try{const hex=await setFunction();return console.log("data: 写入参数结果",hex),hex||void reject("设置参数失败")}catch(error){console.error("设置参数出错: ",error),reject(error)}},handleParam=async paramObj=>{const{paramNo:paramNo,oldParamNo:oldParamNo,paramLength:paramLength}=paramObj,value=Math.round(Number(paramObj.values)/paramInfo.divisor);console.log("value: ",value);const hexValues=BleDataProcess.decimalToTwoByteHexArray(value),hexAddress=BleDataProcess.decimalToTwoByteHexArray(paramNo),hexLength=BleDataProcess.decimalToHex(paramLength/2);return chipType?await handleSet(()=>BleCmdDD.setDDA5FAAsync(deviceId,hexAddress,hexLength,hexValues)):await handleSet(()=>BleCmdDD.setDDA5OldAsync(deviceId,oldParamNo,hexValues))};try{await BleCmdDD.enterFactory(deviceId);const paramInfoHex=await handleParam(paramInfo);await handleParam(circular);if(chipType){await handleParam(full)}await BleCmdDD.existFactory(deviceId),paramInfoHex&&resolve(paramInfoHex)}catch(error){reject(error)}})),exports.setParamCmd=setParamCmd,exports.setSysParamCmd=async(chipType,deviceId,paramInfoArray)=>{try{console.log("paramInfoArray: ",paramInfoArray);const paramsToProcess=Array.isArray(paramInfoArray)?paramInfoArray:[paramInfoArray],paramObjs=[];for(const paramInfo of paramsToProcess){let value=Math.round(Number(paramInfo?.paramValue||paramInfo.newValue)/Number(paramInfo?.divisor||1));console.log("value: ",value),paramInfo.isTemp&&(value=2731+10*Number(paramInfo.newValue));const valuesHexs=BleDataProcess.decimalToTwoByteHexArray(value);console.log("valuesHexs: ",valuesHexs),paramObjs.push({address:paramInfo.paramNo,length:paramInfo.paramLength/2,values:valuesHexs,oldAddress:paramInfo.oldParamNo})}await setParamCmd(chipType,deviceId,paramObjs)}catch(error){throw console.error("error: 写系统参数报错 setSysParamCmd",error),error}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function isEmpty(v){return null==v||""===v}Object.defineProperty(exports,"__esModule",{value:!0});const eventBus={events:{},on(event,callback){this.events[event]||(this.events[event]=[]),this.events[event].push(callback)},off(event,callback){this.events[event]&&(callback?(this.events[event]=this.events[event].filter(cb=>cb!==callback),0===this.events[event].length&&delete this.events[event]):delete this.events[event])},emit(event,...args){this.events[event]&&this.events[event].forEach(callback=>callback(...args))}};exports.eventBus=eventBus,exports.formatTimeHHmm=function(hours){const hour=Math.floor(hours),minute=Math.floor(60*(hours-hour));return console.log("H5环境"),`${hour}H:${minute}m`},exports.getOS=function(){const os=uni.getSystemInfoSync()?.osName;return{isIOS:"ios"==os,isAndroid:"android"==os}},exports.inArray=function(arr,key,val){for(let i=0;i<arr.length;i++)if(arr[i][key]===val)return i;return-1},exports.isEmpty=isEmpty,exports.isNotEmpty=function(v){return!isEmpty(v)};
|
|
1
|
+
"use strict";function isEmpty(v){return null==v||""===v}Object.defineProperty(exports,"__esModule",{value:!0});const eventBus={events:{},on(event,callback){this.events[event]||(this.events[event]=[]),this.events[event].push(callback)},off(event,callback){this.events[event]&&(callback?(this.events[event]=this.events[event].filter(cb=>cb!==callback),0===this.events[event].length&&delete this.events[event]):delete this.events[event])},emit(event,...args){this.events[event]&&this.events[event].forEach(callback=>callback(...args))}};exports.eventBus=eventBus,exports.formatTimeHHmm=function(hours){const hour=Math.floor(hours),minute=Math.floor(60*(hours-hour));return console.log("H5环境"),`${hour}H:${minute}m`},exports.getOS=function(){const os=uni.getSystemInfoSync()?.osName;return{isIOS:"ios"==os,isAndroid:"android"==os}},exports.getPlatform=function(){return uni.getSystemInfoSync()?.uniPlatform||""},exports.inArray=function(arr,key,val){for(let i=0;i<arr.length;i++)if(arr[i][key]===val)return i;return-1},exports.isEmpty=isEmpty,exports.isNotEmpty=function(v){return!isEmpty(v)};
|
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var array=require("./core/array.js"),BleApiManager=require("./core/BleApiManager.js"),commonfun=require("./core/commonfun.js"),keyAndPwdManager=require("./core/keyAndPwdManager.js"),OtaUpgrade=require("./core/OtaUpgrade.js"),TelinkApi=require("./core/TelinkApi.js"),Transfer=require("./core/Transfer.js"),BleDataProcess=require("./core/BleDataProcess.js"),BleCmdAnalysis=require("./core/BleCmdAnalysis/BleCmdAnalysis.js"),BleCmdFFAA=require("./core/BleCmdAnalysis/BleCmdFFAA.js"),BleCmdDD=require("./core/BleCmdAnalysis/BleCmdDD.js"),readAndSetParam=require("./core/BleCmdAnalysis/readAndSetParam.js"),BaseParamProtocol=require("./core/BleCmdAnalysis/BaseParamProtocol.js"),BleCmdHVES=require("./core/BleCmdAnalysis/BleCmdHVES.js"),ESHostProtocol=require("./core/BleCmdAnalysis/ESHostProtocol.js"),baseParamsJson=require("./core/dataJson/baseParamsJson.js");exports.chunk=array.chunk,exports.unique=array.unique,exports.connectAsync=BleApiManager.connectAsync,exports.createBLEConnection=BleApiManager.createBLEConnection,exports.disConnect=BleApiManager.disConnect,exports.foundScanDevice=BleApiManager.foundScanDevice,exports.getBLEDeviceCharacteristics=BleApiManager.getBLEDeviceCharacteristics,exports.getBLEDeviceServices=BleApiManager.getBLEDeviceServices,exports.getBluetoothAdapterState=BleApiManager.getBluetoothAdapterState,exports.initBle=BleApiManager.initBle,exports.notify=BleApiManager.notify,exports.onBLECharacteristicValueChange=BleApiManager.onBLECharacteristicValueChange,exports.onBLEConnectionStateChange=BleApiManager.onBLEConnectionStateChange,exports.onBleChangedConnectionState=BleApiManager.onBleChangedConnectionState,exports.onBluetoothAdapterStateChange=BleApiManager.onBluetoothAdapterStateChange,exports.onBluetoothDeviceFound=BleApiManager.onBluetoothDeviceFound,exports.onFoundDevice=BleApiManager.onFoundDevice,exports.scanHandle=BleApiManager.scanHandle,exports.startDevicesDiscovery=BleApiManager.startDevicesDiscovery,exports.stopBluetoothDevicesDiscovery=BleApiManager.stopBluetoothDevicesDiscovery,exports.eventBus=commonfun.eventBus,exports.formatTimeHHmm=commonfun.formatTimeHHmm,exports.getOS=commonfun.getOS,exports.inArray=commonfun.inArray,exports.isEmpty=commonfun.isEmpty,exports.isNotEmpty=commonfun.isNotEmpty,exports.ALLOWED_MAC_PREFIX=keyAndPwdManager.ALLOWED_MAC_PREFIX,exports.APP_KEY_STATUS=keyAndPwdManager.APP_KEY_STATUS,exports.extractModuleInfo=keyAndPwdManager.extractModuleInfo,exports.getRandomNum=keyAndPwdManager.getRandomNum,exports.getTypeBuyCmd=keyAndPwdManager.getTypeBuyCmd,exports.handleNewAppKey=keyAndPwdManager.handleNewAppKey,exports.handleOldAppKey=keyAndPwdManager.handleOldAppKey,exports.sendAppKey=keyAndPwdManager.sendAppKey,exports.sendEnableOrVerifyKey=keyAndPwdManager.sendEnableOrVerifyKey,exports.sendOldAppKey=keyAndPwdManager.sendOldAppKey,exports.sendVerifyPwd=keyAndPwdManager.sendVerifyPwd,exports.sendWrite1LevelPwd=keyAndPwdManager.sendWrite1LevelPwd,exports.verify3LevelPassword=keyAndPwdManager.verify3LevelPassword,exports.verifyMacAddrAndKey=keyAndPwdManager.verifyMacAddrAndKey,exports.OTAUpgrade=OtaUpgrade.OTAUpgrade,exports.TelinkApi=TelinkApi.TelinkApi,exports.BLE=Transfer.BLE,exports.Logger=Transfer.Logger,exports.Observer=Transfer.Observer,exports.Transfer=Transfer.Transfer,exports.ab2decimalArr=BleDataProcess.ab2decimalArr,exports.ab2hex=BleDataProcess.ab2hex,exports.arrayBufferToHexArray=BleDataProcess.arrayBufferToHexArray,exports.base64ToHexArray=BleDataProcess.base64ToHexArray,exports.checkSum=BleDataProcess.checkSum,exports.crc16modbus=BleDataProcess.crc16modbus,exports.crcCheckSum=BleDataProcess.crcCheckSum,exports.decimalToHex=BleDataProcess.decimalToHex,exports.decimalToHex0x=BleDataProcess.decimalToHex0x,exports.decimalToTwoByteHexArray=BleDataProcess.decimalToTwoByteHexArray,exports.extractBits=BleDataProcess.extractBits,exports.generateCheckSum=BleDataProcess.generateCheckSum,exports.generateCrc16modbusCheck=BleDataProcess.generateCrc16modbusCheck,exports.generateCrcCheckSum=BleDataProcess.generateCrcCheckSum,exports.getParamBaseValue=BleDataProcess.getParamBaseValue,exports.hex2Ascii=BleDataProcess.hex2Ascii,exports.hex2Binary=BleDataProcess.hex2Binary,exports.hex2string=BleDataProcess.hex2string,exports.hexArr2Assic=BleDataProcess.hexArr2Assic,exports.hexArr2ab=BleDataProcess.hexArr2ab,exports.hexArr2string=BleDataProcess.hexArr2string,exports.hexArrayToModuleArrayBuffer=BleDataProcess.hexArrayToModuleArrayBuffer,exports.hexStrAscii=BleDataProcess.hexStrAscii,exports.hexStringToBinary=BleDataProcess.hexStringToBinary,exports.hexToDecimal=BleDataProcess.hexToDecimal,exports.sleep=BleDataProcess.sleep,exports.string2hexArr=BleDataProcess.string2hexArr,exports.stringToTwoHexArray=BleDataProcess.stringToTwoHexArray,exports.getData=BleCmdAnalysis.getData,exports.setMTUAsync=BleCmdAnalysis.setMTUAsync,exports.clearPrimaryKey=BleCmdFFAA.clearPrimaryKey,exports.getBluetoothName=BleCmdFFAA.getBluetoothName,exports.getBroadcastDataCmd=BleCmdFFAA.getBroadcastDataCmd,exports.getFFAA03Async=BleCmdFFAA.getFFAA03Async,exports.getFFAA17Async=BleCmdFFAA.getFFAA17Async,exports.getFFAA25Async=BleCmdFFAA.getFFAA25Async,exports.getFFAA26Async=BleCmdFFAA.getFFAA26Async,exports.getFFAA80Async=BleCmdFFAA.getFFAA80Async,exports.getFFAAKeyAsync=BleCmdFFAA.getFFAAKeyAsync,exports.getWiFiIP=BleCmdFFAA.getWiFiIP,exports.resetFactoryData=BleCmdFFAA.resetFactoryData,exports.resetSecondaryKey=BleCmdFFAA.resetSecondaryKey,exports.resolveFFAA25=BleCmdFFAA.resolveFFAA25,exports.resolveFFAA26=BleCmdFFAA.resolveFFAA26,exports.resolveFFAA80=BleCmdFFAA.resolveFFAA80,exports.resolveFFAAKey=BleCmdFFAA.resolveFFAAKey,exports.setBluetoothName=BleCmdFFAA.setBluetoothName,exports.setWiFi=BleCmdFFAA.setWiFi,exports.setWiFiSta=BleCmdFFAA.setWiFiSta,exports.set_PlanCMD_FFAA=BleCmdFFAA.set_PlanCMD_FFAA,exports.set_PlanCMD_FFAA80=BleCmdFFAA.set_PlanCMD_FFAA80,exports.enterFactory=BleCmdDD.enterFactory,exports.existFactory=BleCmdDD.existFactory,exports.get3B3CAsync=BleCmdDD.get3B3CAsync,exports.get3B3CInfo=BleCmdDD.get3B3CInfo,exports.getChipTypeAsync=BleCmdDD.getChipTypeAsync,exports.getDD5A0AAsync=BleCmdDD.getDD5A0AAsync,exports.getDD5A0EAsync=BleCmdDD.getDD5A0EAsync,exports.getDD5A17Async=BleCmdDD.getDD5A17Async,exports.getDD5AAllAsync=BleCmdDD.getDD5AAllAsync,exports.getDD5AE0Async=BleCmdDD.getDD5AE0Async,exports.getDD5AE1Async=BleCmdDD.getDD5AE1Async,exports.getDD5AE4Async=BleCmdDD.getDD5AE4Async,exports.getDD5AFAAsync=BleCmdDD.getDD5AFAAsync,exports.getDD5AFBAsync=BleCmdDD.getDD5AFBAsync,exports.getDDA503Async=BleCmdDD.getDDA503Async,exports.getDDA504Async=BleCmdDD.getDDA504Async,exports.getDDA505Async=BleCmdDD.getDDA505Async,exports.getDDA507Async=BleCmdDD.getDDA507Async,exports.getDDA508Async=BleCmdDD.getDDA508Async,exports.getDDA5FAAsync=BleCmdDD.getDDA5FAAsync,exports.getDDA5OldAsync=BleCmdDD.getDDA5OldAsync,exports.getProtectCountCmd=BleCmdDD.getProtectCountCmd,exports.readExistFactory=BleCmdDD.readExistFactory,exports.resolve3B3C=BleCmdDD.resolve3B3C,exports.resolveBMSCmd=BleCmdDD.resolveBMSCmd,exports.resolveBaseDD=BleCmdDD.resolveBaseDD,exports.resolveDDA500=BleCmdDD.resolveDDA500,exports.resolveDDA503=BleCmdDD.resolveDDA503,exports.resolveDDA504=BleCmdDD.resolveDDA504,exports.resolveDDA505=BleCmdDD.resolveDDA505,exports.resolveDDA508=BleCmdDD.resolveDDA508,exports.resolveDDA5FA=BleCmdDD.resolveDDA5FA,exports.resolveProtections=BleCmdDD.resolveProtections,exports.sendBMSAsync=BleCmdDD.sendBMSAsync,exports.setDDA5FAAsync=BleCmdDD.setDDA5FAAsync,exports.setDDA5OldAsync=BleCmdDD.setDDA5OldAsync,exports.set_PlanCMD_3B3C=BleCmdDD.set_PlanCMD_3B3C,exports.set_PlanCMD_DD=BleCmdDD.set_PlanCMD_DD,exports.getSysParamCmd=readAndSetParam.getSysParamCmd,exports.readParamCmd=readAndSetParam.readParamCmd,exports.setCapacityParamCmd=readAndSetParam.setCapacityParamCmd,exports.setParamCmd=readAndSetParam.setParamCmd,exports.setSysParamCmd=readAndSetParam.setSysParamCmd,exports.getBaseInfo=BaseParamProtocol.getBaseInfo,exports.getBaseParams=BaseParamProtocol.getBaseParams,exports.getResistance=BaseParamProtocol.getResistance,exports.getCMDESInfoAsync=BleCmdHVES.getCMDESInfoAsync,exports.getHVESInfoAsync=BleCmdHVES.getHVESInfoAsync,exports.resolveHVESBMUInfo=BleCmdHVES.resolveHVESBMUInfo,exports.resolveHVESBaseInfo=BleCmdHVES.resolveHVESBaseInfo,exports.resolveHVESCalibrationC1Info=BleCmdHVES.resolveHVESCalibrationC1Info,exports.resolveHVESCalibrationC2Info=BleCmdHVES.resolveHVESCalibrationC2Info,exports.resolveHVESCalibrationConfigInfo=BleCmdHVES.resolveHVESCalibrationConfigInfo,exports.resolveHVESCalibrationInfo=BleCmdHVES.resolveHVESCalibrationInfo,exports.resolveHVESCtInfo=BleCmdHVES.resolveHVESCtInfo,exports.resolveHVESDisCtInfo=BleCmdHVES.resolveHVESDisCtInfo,exports.resolveHVESElectrodeHTInfo=BleCmdHVES.resolveHVESElectrodeHTInfo,exports.resolveHVESEtInfo=BleCmdHVES.resolveHVESEtInfo,exports.resolveHVESInsulationLRInfo=BleCmdHVES.resolveHVESInsulationLRInfo,exports.resolveHVESLSocInfo=BleCmdHVES.resolveHVESLSocInfo,exports.resolveHVESMonoVolInfo=BleCmdHVES.resolveHVESMonoVolInfo,exports.resolveHVESOeInfo=BleCmdHVES.resolveHVESOeInfo,exports.resolveHVESOtRisingInfo=BleCmdHVES.resolveHVESOtRisingInfo,exports.resolveHVESOtrInfo=BleCmdHVES.resolveHVESOtrInfo,exports.resolveHVESOvrInfo=BleCmdHVES.resolveHVESOvrInfo,exports.resolveHVESPackInfo=BleCmdHVES.resolveHVESPackInfo,exports.resolveHVESParamsInfo=BleCmdHVES.resolveHVESParamsInfo,exports.resolveHVESSumInfo=BleCmdHVES.resolveHVESSumInfo,exports.resolveHVESSumVolInfo=BleCmdHVES.resolveHVESSumVolInfo,exports.resolveHVESVersionInfo=BleCmdHVES.resolveHVESVersionInfo,exports.HostProtocol=ESHostProtocol.HostProtocol,exports.batteryInfoJson=baseParamsJson.batteryInfoJson,exports.capInfoJson=baseParamsJson.capInfoJson,exports.capVolInfoJson=baseParamsJson.capVolInfoJson,exports.currentInfoJson=baseParamsJson.currentInfoJson,exports.equalizerFunJson=baseParamsJson.equalizerFunJson,exports.funcAndTempFuncJson=baseParamsJson.funcAndTempFuncJson,exports.funcJson=baseParamsJson.funcJson,exports.systemJson=baseParamsJson.systemJson,exports.tempFuncJson=baseParamsJson.tempFuncJson,exports.tempInfoJson=baseParamsJson.tempInfoJson,exports.voltageInfoJson=baseParamsJson.voltageInfoJson;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var array=require("./core/array.js"),BleApiManager=require("./core/BleApiManager.js"),commonfun=require("./core/commonfun.js"),keyAndPwdManager=require("./core/keyAndPwdManager.js"),OtaUpgrade=require("./core/OtaUpgrade.js"),TelinkApi=require("./core/TelinkApi.js"),Transfer=require("./core/Transfer.js"),BleDataProcess=require("./core/BleDataProcess.js"),BleCmdAnalysis=require("./core/BleCmdAnalysis/BleCmdAnalysis.js"),BleCmdFFAA=require("./core/BleCmdAnalysis/BleCmdFFAA.js"),BleCmdDD=require("./core/BleCmdAnalysis/BleCmdDD.js"),readAndSetParam=require("./core/BleCmdAnalysis/readAndSetParam.js"),BaseParamProtocol=require("./core/BleCmdAnalysis/BaseParamProtocol.js"),BleCmdHVES=require("./core/BleCmdAnalysis/BleCmdHVES.js"),ESHostProtocol=require("./core/BleCmdAnalysis/ESHostProtocol.js"),baseParamsJson=require("./core/dataJson/baseParamsJson.js");exports.chunk=array.chunk,exports.unique=array.unique,exports.connectAsync=BleApiManager.connectAsync,exports.createBLEConnection=BleApiManager.createBLEConnection,exports.disConnect=BleApiManager.disConnect,exports.foundScanDevice=BleApiManager.foundScanDevice,exports.getBLEDeviceCharacteristics=BleApiManager.getBLEDeviceCharacteristics,exports.getBLEDeviceServices=BleApiManager.getBLEDeviceServices,exports.getBluetoothAdapterState=BleApiManager.getBluetoothAdapterState,exports.initBle=BleApiManager.initBle,exports.notify=BleApiManager.notify,exports.onBLECharacteristicValueChange=BleApiManager.onBLECharacteristicValueChange,exports.onBLEConnectionStateChange=BleApiManager.onBLEConnectionStateChange,exports.onBleChangedConnectionState=BleApiManager.onBleChangedConnectionState,exports.onBluetoothAdapterStateChange=BleApiManager.onBluetoothAdapterStateChange,exports.onBluetoothDeviceFound=BleApiManager.onBluetoothDeviceFound,exports.onFoundDevice=BleApiManager.onFoundDevice,exports.scanHandle=BleApiManager.scanHandle,exports.startDevicesDiscovery=BleApiManager.startDevicesDiscovery,exports.stopBluetoothDevicesDiscovery=BleApiManager.stopBluetoothDevicesDiscovery,exports.eventBus=commonfun.eventBus,exports.formatTimeHHmm=commonfun.formatTimeHHmm,exports.getOS=commonfun.getOS,exports.getPlatform=commonfun.getPlatform,exports.inArray=commonfun.inArray,exports.isEmpty=commonfun.isEmpty,exports.isNotEmpty=commonfun.isNotEmpty,exports.ALLOWED_MAC_PREFIX=keyAndPwdManager.ALLOWED_MAC_PREFIX,exports.APP_KEY_STATUS=keyAndPwdManager.APP_KEY_STATUS,exports.extractModuleInfo=keyAndPwdManager.extractModuleInfo,exports.getRandomNum=keyAndPwdManager.getRandomNum,exports.getTypeBuyCmd=keyAndPwdManager.getTypeBuyCmd,exports.handleNewAppKey=keyAndPwdManager.handleNewAppKey,exports.handleOldAppKey=keyAndPwdManager.handleOldAppKey,exports.sendAppKey=keyAndPwdManager.sendAppKey,exports.sendEnableOrVerifyKey=keyAndPwdManager.sendEnableOrVerifyKey,exports.sendOldAppKey=keyAndPwdManager.sendOldAppKey,exports.sendVerifyPwd=keyAndPwdManager.sendVerifyPwd,exports.sendWrite1LevelPwd=keyAndPwdManager.sendWrite1LevelPwd,exports.verify3LevelPassword=keyAndPwdManager.verify3LevelPassword,exports.verifyMacAddrAndKey=keyAndPwdManager.verifyMacAddrAndKey,exports.OTAUpgrade=OtaUpgrade.OTAUpgrade,exports.TelinkApi=TelinkApi.TelinkApi,exports.BLE=Transfer.BLE,exports.Logger=Transfer.Logger,exports.Observer=Transfer.Observer,exports.Transfer=Transfer.Transfer,exports.ab2decimalArr=BleDataProcess.ab2decimalArr,exports.ab2hex=BleDataProcess.ab2hex,exports.arrayBufferToHexArray=BleDataProcess.arrayBufferToHexArray,exports.base64ToHexArray=BleDataProcess.base64ToHexArray,exports.checkSum=BleDataProcess.checkSum,exports.crc16modbus=BleDataProcess.crc16modbus,exports.crcCheckSum=BleDataProcess.crcCheckSum,exports.decimalToHex=BleDataProcess.decimalToHex,exports.decimalToHex0x=BleDataProcess.decimalToHex0x,exports.decimalToTwoByteHexArray=BleDataProcess.decimalToTwoByteHexArray,exports.extractBits=BleDataProcess.extractBits,exports.generateCheckSum=BleDataProcess.generateCheckSum,exports.generateCrc16modbusCheck=BleDataProcess.generateCrc16modbusCheck,exports.generateCrcCheckSum=BleDataProcess.generateCrcCheckSum,exports.getParamBaseValue=BleDataProcess.getParamBaseValue,exports.hex2Ascii=BleDataProcess.hex2Ascii,exports.hex2Binary=BleDataProcess.hex2Binary,exports.hex2string=BleDataProcess.hex2string,exports.hexArr2Assic=BleDataProcess.hexArr2Assic,exports.hexArr2ab=BleDataProcess.hexArr2ab,exports.hexArr2string=BleDataProcess.hexArr2string,exports.hexArrayToModuleArrayBuffer=BleDataProcess.hexArrayToModuleArrayBuffer,exports.hexStrAscii=BleDataProcess.hexStrAscii,exports.hexStringToBinary=BleDataProcess.hexStringToBinary,exports.hexToDecimal=BleDataProcess.hexToDecimal,exports.sleep=BleDataProcess.sleep,exports.string2hexArr=BleDataProcess.string2hexArr,exports.stringToTwoHexArray=BleDataProcess.stringToTwoHexArray,exports.getData=BleCmdAnalysis.getData,exports.setMTUAsync=BleCmdAnalysis.setMTUAsync,exports.clearPrimaryKey=BleCmdFFAA.clearPrimaryKey,exports.getBluetoothName=BleCmdFFAA.getBluetoothName,exports.getBroadcastDataCmd=BleCmdFFAA.getBroadcastDataCmd,exports.getFFAA03Async=BleCmdFFAA.getFFAA03Async,exports.getFFAA17Async=BleCmdFFAA.getFFAA17Async,exports.getFFAA25Async=BleCmdFFAA.getFFAA25Async,exports.getFFAA26Async=BleCmdFFAA.getFFAA26Async,exports.getFFAA80Async=BleCmdFFAA.getFFAA80Async,exports.getFFAAKeyAsync=BleCmdFFAA.getFFAAKeyAsync,exports.getWiFiIP=BleCmdFFAA.getWiFiIP,exports.resetFactoryData=BleCmdFFAA.resetFactoryData,exports.resetSecondaryKey=BleCmdFFAA.resetSecondaryKey,exports.resolveFFAA25=BleCmdFFAA.resolveFFAA25,exports.resolveFFAA26=BleCmdFFAA.resolveFFAA26,exports.resolveFFAA80=BleCmdFFAA.resolveFFAA80,exports.resolveFFAAKey=BleCmdFFAA.resolveFFAAKey,exports.setBluetoothName=BleCmdFFAA.setBluetoothName,exports.setWiFi=BleCmdFFAA.setWiFi,exports.setWiFiSta=BleCmdFFAA.setWiFiSta,exports.set_PlanCMD_FFAA=BleCmdFFAA.set_PlanCMD_FFAA,exports.set_PlanCMD_FFAA80=BleCmdFFAA.set_PlanCMD_FFAA80,exports.activateAsync=BleCmdDD.activateAsync,exports.enterFactory=BleCmdDD.enterFactory,exports.existFactory=BleCmdDD.existFactory,exports.get3B3CAsync=BleCmdDD.get3B3CAsync,exports.get3B3CInfo=BleCmdDD.get3B3CInfo,exports.getChipTypeAsync=BleCmdDD.getChipTypeAsync,exports.getDD5A0AAsync=BleCmdDD.getDD5A0AAsync,exports.getDD5A0EAsync=BleCmdDD.getDD5A0EAsync,exports.getDD5A17Async=BleCmdDD.getDD5A17Async,exports.getDD5AAllAsync=BleCmdDD.getDD5AAllAsync,exports.getDD5AE0Async=BleCmdDD.getDD5AE0Async,exports.getDD5AE1Async=BleCmdDD.getDD5AE1Async,exports.getDD5AE4Async=BleCmdDD.getDD5AE4Async,exports.getDD5AFAAsync=BleCmdDD.getDD5AFAAsync,exports.getDD5AFBAsync=BleCmdDD.getDD5AFBAsync,exports.getDDA503Async=BleCmdDD.getDDA503Async,exports.getDDA504Async=BleCmdDD.getDDA504Async,exports.getDDA505Async=BleCmdDD.getDDA505Async,exports.getDDA507Async=BleCmdDD.getDDA507Async,exports.getDDA508Async=BleCmdDD.getDDA508Async,exports.getDDA5DCAsync=BleCmdDD.getDDA5DCAsync,exports.getDDA5FAAsync=BleCmdDD.getDDA5FAAsync,exports.getDDA5OldAsync=BleCmdDD.getDDA5OldAsync,exports.getProtectCountCmd=BleCmdDD.getProtectCountCmd,exports.readExistFactory=BleCmdDD.readExistFactory,exports.resetCapacity=BleCmdDD.resetCapacity,exports.resolve3B3C=BleCmdDD.resolve3B3C,exports.resolveBMSCmd=BleCmdDD.resolveBMSCmd,exports.resolveBaseDD=BleCmdDD.resolveBaseDD,exports.resolveDD5A0A=BleCmdDD.resolveDD5A0A,exports.resolveDDA500=BleCmdDD.resolveDDA500,exports.resolveDDA503=BleCmdDD.resolveDDA503,exports.resolveDDA504=BleCmdDD.resolveDDA504,exports.resolveDDA505=BleCmdDD.resolveDDA505,exports.resolveDDA508=BleCmdDD.resolveDDA508,exports.resolveDDA5DC=BleCmdDD.resolveDDA5DC,exports.resolveDDA5FA=BleCmdDD.resolveDDA5FA,exports.resolveProtections=BleCmdDD.resolveProtections,exports.sendBMSAsync=BleCmdDD.sendBMSAsync,exports.setDDA5FAAsync=BleCmdDD.setDDA5FAAsync,exports.setDDA5OldAsync=BleCmdDD.setDDA5OldAsync,exports.set_PlanCMD_3B3C=BleCmdDD.set_PlanCMD_3B3C,exports.set_PlanCMD_DD=BleCmdDD.set_PlanCMD_DD,exports.getSysParamCmd=readAndSetParam.getSysParamCmd,exports.readParamCmd=readAndSetParam.readParamCmd,exports.setCapacityParamCmd=readAndSetParam.setCapacityParamCmd,exports.setParamCmd=readAndSetParam.setParamCmd,exports.setSysParamCmd=readAndSetParam.setSysParamCmd,exports.getBaseInfo=BaseParamProtocol.getBaseInfo,exports.getBaseParams=BaseParamProtocol.getBaseParams,exports.getResistance=BaseParamProtocol.getResistance,exports.getCMDESInfoAsync=BleCmdHVES.getCMDESInfoAsync,exports.getHVESInfoAsync=BleCmdHVES.getHVESInfoAsync,exports.resolveHVESBMUInfo=BleCmdHVES.resolveHVESBMUInfo,exports.resolveHVESBaseInfo=BleCmdHVES.resolveHVESBaseInfo,exports.resolveHVESCalibrationC1Info=BleCmdHVES.resolveHVESCalibrationC1Info,exports.resolveHVESCalibrationC2Info=BleCmdHVES.resolveHVESCalibrationC2Info,exports.resolveHVESCalibrationConfigInfo=BleCmdHVES.resolveHVESCalibrationConfigInfo,exports.resolveHVESCalibrationInfo=BleCmdHVES.resolveHVESCalibrationInfo,exports.resolveHVESCtInfo=BleCmdHVES.resolveHVESCtInfo,exports.resolveHVESDisCtInfo=BleCmdHVES.resolveHVESDisCtInfo,exports.resolveHVESElectrodeHTInfo=BleCmdHVES.resolveHVESElectrodeHTInfo,exports.resolveHVESEtInfo=BleCmdHVES.resolveHVESEtInfo,exports.resolveHVESInsulationLRInfo=BleCmdHVES.resolveHVESInsulationLRInfo,exports.resolveHVESLSocInfo=BleCmdHVES.resolveHVESLSocInfo,exports.resolveHVESMonoVolInfo=BleCmdHVES.resolveHVESMonoVolInfo,exports.resolveHVESOeInfo=BleCmdHVES.resolveHVESOeInfo,exports.resolveHVESOtRisingInfo=BleCmdHVES.resolveHVESOtRisingInfo,exports.resolveHVESOtrInfo=BleCmdHVES.resolveHVESOtrInfo,exports.resolveHVESOvrInfo=BleCmdHVES.resolveHVESOvrInfo,exports.resolveHVESPackInfo=BleCmdHVES.resolveHVESPackInfo,exports.resolveHVESParamsInfo=BleCmdHVES.resolveHVESParamsInfo,exports.resolveHVESSumInfo=BleCmdHVES.resolveHVESSumInfo,exports.resolveHVESSumVolInfo=BleCmdHVES.resolveHVESSumVolInfo,exports.resolveHVESVersionInfo=BleCmdHVES.resolveHVESVersionInfo,exports.HostProtocol=ESHostProtocol.HostProtocol,exports.batteryInfoJson=baseParamsJson.batteryInfoJson,exports.capInfoJson=baseParamsJson.capInfoJson,exports.capVolInfoJson=baseParamsJson.capVolInfoJson,exports.currentInfoJson=baseParamsJson.currentInfoJson,exports.equalizerFunJson=baseParamsJson.equalizerFunJson,exports.funcAndTempFuncJson=baseParamsJson.funcAndTempFuncJson,exports.funcJson=baseParamsJson.funcJson,exports.systemJson=baseParamsJson.systemJson,exports.tempFuncJson=baseParamsJson.tempFuncJson,exports.tempInfoJson=baseParamsJson.tempInfoJson,exports.voltageInfoJson=baseParamsJson.voltageInfoJson;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{ref}from"vue";import{ab2decimalArr,hexToDecimal}from"./BleDataProcess.js";import{getOS,eventBus}from"./commonfun.js";const serviceId="0000FF00-0000-1000-8000-00805F9B34FB",bluetoothAdapterState=ref({available:!1,discovering:!1}),initBle=async()=>{const checkBluetoothStatus=async()=>new Promise((resolve,reject)=>{uni.openBluetoothAdapter({success:async res=>{console.log("openBluetoothAdapter success",res),resolve(res);try{onBluetoothDeviceFound(),onBLECharacteristicValueChange(),onBLEConnectionStateChange(),onBluetoothAdapterStateChange()}catch(error){console.log("error: ",error),reject(error)}},fail:err=>{console.log("openBluetoothAdapter fail",err),reject(err)}})});try{const{isAndroid:isAndroid}=getOS();isAndroid?(async()=>{const timeoutPromise=new Promise((resolve,reject)=>{setTimeout(()=>{reject(new Error("网络信号差或连接异常,请检查网络情况"))},1e4)}),locationPromise=new Promise((resolve,reject)=>{uni.getLocation({type:"wgs84",success:res=>{console.log("位置信息-----------",res),resolve(res)},fail:err=>{console.log("位置信息err",err),reject(err)}})});Promise.race([locationPromise,timeoutPromise]).then(res=>{checkBluetoothStatus()}).catch(err=>{console.log("位置获取失败或超时:",err),Promise.reject({code:1})})})():checkBluetoothStatus()}catch(error){console.error("初始化蓝牙失败:",error),Promise.reject({code:error.code||error.errCode||-1})}},getBluetoothAdapterState=async()=>new Promise((resolve,reject)=>{uni.getBluetoothAdapterState({success:res=>{console.log("getBluetoothAdapterState success",res),resolve(res)},fail:err=>{console.log("getBluetoothAdapterState fail",err),reject(err)}})}),startDevicesDiscovery=async(allowDuplicatesKey=!0)=>new Promise((resolve,reject)=>{bluetoothAdapterState.value.discovering?reject(new Error("蓝牙设备搜索已在进行中")):uni.startBluetoothDevicesDiscovery({services:[serviceId],allowDuplicatesKey:allowDuplicatesKey,success:async res=>{console.log("广播设备 success",res),resolve(res)},fail:err=>{console.log("广播设备 fail",err),reject(err)}})}),stopBluetoothDevicesDiscovery=async()=>new Promise((resolve,reject)=>{uni.stopBluetoothDevicesDiscovery({success:res=>{console.log("停止广播设备 success",res),resolve(res)},fail:err=>{console.log("停止广播设备 fail",err),reject(err)},complete:res=>{console.log("停止广播设备 取消订阅"),eventBus.off("setBluetoothDeviceFound")}})}),onBluetoothDeviceFound=async()=>{uni.onBluetoothDeviceFound(characteristic=>{console.log("setBluetoothDeviceFound",characteristic);const device=(device=>{const adv=device?.advertisData;if(!adv)return null;if(adv){const advHex=Array.prototype.map.call(new Uint8Array(adv),o=>("00"+o.toString(16)).slice(-2)).join("").toUpperCase();let macAddr=advHex.slice(0,12).toUpperCase(),arr=macAddr.match(/(.{2})/g);const flag=macAddr.slice(-4);"C1A4"!=flag&&"C2A5"!=flag&&"C2A8"!=flag||arr.reverse(),macAddr=arr.join(":"),device.hasFound=!0;const moduleType=advHex.slice(12,16),socHex=advHex.slice(16,18),soc=socHex||0==socHex?hexToDecimal(socHex):"",productType=advHex.slice(18,20),protocolVersion=advHex.slice(20,22),appkeyStatus=advHex.slice(22,24),tempVoltage=advHex.slice(24,26),voltage=tempVoltage||0==tempVoltage?hexToDecimal(tempVoltage):"",tempCurrent=advHex.slice(26,28),current=tempCurrent||0==tempCurrent?hexToDecimal(tempCurrent):"",broadcastLen=advHex.length/2,isNewAppKey=advHex.length>=24;device={...device,macAddr:macAddr,moduleType:moduleType,soc:soc,productType:productType,advHex:advHex,protocolVersion:protocolVersion,appkeyStatus:appkeyStatus,broadcastLen:broadcastLen,isNewAppKey:isNewAppKey,voltage:voltage,current:current}}return device})(characteristic.devices[0]);device&&eventBus.emit("setBluetoothDeviceFound",device)})},onFoundDevice=callback=>{eventBus.on("setBluetoothDeviceFound",callback)},onBluetoothAdapterStateChange=async()=>{uni.onBluetoothAdapterStateChange(res=>{console.log("onBluetoothAdapterStateChange监听蓝牙适配器变化",res),bluetoothAdapterState.value=res})},onBLECharacteristicValueChange=async()=>{uni.onBLECharacteristicValueChange(characteristic=>{const decimalArr=ab2decimalArr(characteristic.value);console.warn("decimalArr: 监听到的回复-------------------",decimalArr),eventBus.emit("setBleChangedCharacteristicValue",characteristic)})},onBLEConnectionStateChange=async()=>{uni.onBLEConnectionStateChange(characteristic=>{console.log("onBLEConnectionStateChange",characteristic),eventBus.emit("setBleChangedConnectionState",characteristic)})},onBleChangedConnectionState=callback=>{eventBus.on("setBleChangedConnectionState",callback)},createBLEConnection=async(deviceId,timeout=1e4)=>new Promise((resolve,reject)=>{console.log(deviceId,"点击的设备信息"),uni.createBLEConnection({deviceId:deviceId,timeout:timeout,success:res=>{console.log(res,"连接成功"),resolve(!0)},fail:err=>{console.log(err,"Connection"),-1==(err.code||err.errCode)?resolve(!0):reject(err)}})}),withRetry=async(asyncOperation,maxRetries=20,retryInterval=100,type)=>new Promise((resolve,reject)=>{let retryCount=0;const attempt=async()=>{try{const result=await asyncOperation();resolve(result)}catch(error){if(retryCount>=maxRetries)return void reject(new Error(`${type}失败,${error.message} (已重试${maxRetries}次)`));retryCount++,console.warn(`${type}失败,第${retryCount}次重试:`,error.message),setTimeout(attempt,retryInterval)}};attempt()}),getBLEDeviceServices=deviceId=>withRetry(async()=>{const res=await new Promise((resolve,reject)=>{uni.getBLEDeviceServices({deviceId:deviceId,success:resolve,fail:reject})});if(console.log("获取蓝牙服务成功:",res),0===res.services.length)throw new Error("未找到蓝牙服务");return await getBLEDeviceCharacteristics(deviceId),res.services},20,100,"获取蓝牙服务"),getBLEDeviceCharacteristics=async deviceId=>withRetry(async()=>{const res=await new Promise((resolve,reject)=>{uni.getBLEDeviceCharacteristics({deviceId:deviceId,serviceId:serviceId,success:resolve,fail:reject})});return console.log("获取特征值成功:",res),res.characteristics},20,100,"获取蓝牙特征值"),notify=async deviceId=>new Promise((resolve,reject)=>{uni.notifyBLECharacteristicValueChange({deviceId:deviceId,serviceId:serviceId,characteristicId:"0000FF01-0000-1000-8000-00805F9B34FB",state:!0,success:res=>{console.log("订阅===========",res),resolve(res)},fail:reject})}),disConnect=deviceId=>new Promise((resolve,reject)=>{uni.closeBLEConnection({deviceId:deviceId,success:res=>{resolve(res),console.log(res,"断开连接成功")},fail:err=>{reject(err),console.log(err,"err 断开连接")}})}),connectAsync=async(deviceId,timeout=1e4)=>new Promise(async(resolve,reject)=>{try{await createBLEConnection(deviceId,timeout),await getBLEDeviceServices(deviceId),await notify(deviceId),resolve(!0)}catch(error){console.log("error: ",error),reject(error)}}),scanHandle=(historyConnectedList=[],connectFn=device=>{},failScanFn=err=>{})=>{uni.scanCode({scanType:["barCode","qrCode"],success:async({result:result})=>{console.log("扫描内容: "+result);let searchKey=result;try{const formatMacAddress=mac=>mac.replace(/(.{2})/g,"$1:").slice(0,-1).toUpperCase();let isMac=!1;result.includes("?qrCodeInfo=")?(searchKey=result.split("?qrCodeInfo=")[1],searchKey.includes(":")?(searchKey=searchKey.slice(-17).toUpperCase(),isMac=!0):(searchKey=searchKey.slice(-12),searchKey=formatMacAddress(searchKey),isMac=!0)):17===result.length&&result.includes(":")?(searchKey=result.toUpperCase(),isMac=!0):12===result.length&&(searchKey=formatMacAddress(result),isMac=!0);const{isAndroid:isAndroid}=getOS(),matchedHistoryDevice=historyConnectedList.find(item=>item.macAddr==searchKey);if(matchedHistoryDevice)return void connectFn(matchedHistoryDevice);isAndroid&&isMac?connectFn({deviceId:searchKey,macAddr:searchKey,name:searchKey}):foundScanDevice(searchKey,connectFn)}catch(error){console.log(error)}},complete:err=>{console.log("scanCode err",err),failScanFn(err)}})},foundScanDevice=async(result,connectFn)=>{const deviceList=[];await startDevicesDiscovery(),onFoundDevice(device=>{deviceList.push(device);const findDevice=device.macAddr===result||device.name===result;findDevice?(scanTimeout&&(clearTimeout(scanTimeout),scanTimeout=null),uni.stopBluetoothDevicesDiscovery(),connectFn(findDevice)):console.log("未找到设备,继续搜索中...")});let scanTimeout=setTimeout(async()=>{try{console.log("stopBluetoothDevicesDiscovery",deviceList),clearInterval(scanTimer),scanTimer=null,uni.stopBluetoothDevicesDiscovery();const findDevice=deviceList.find(device=>device.macAddr===result||device.name===result);connectFn(findDevice)}finally{}},5e3)};export{connectAsync,createBLEConnection,disConnect,foundScanDevice,getBLEDeviceCharacteristics,getBLEDeviceServices,getBluetoothAdapterState,initBle,notify,onBLECharacteristicValueChange,onBLEConnectionStateChange,onBleChangedConnectionState,onBluetoothAdapterStateChange,onBluetoothDeviceFound,onFoundDevice,scanHandle,startDevicesDiscovery,stopBluetoothDevicesDiscovery};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{hexArr2ab,ab2decimalArr,hexArr2string,sleep}from"../BleDataProcess.js";import{eventBus,getOS}from"../commonfun.js";async function _writeAsync(deviceId,value){return console.log("deviceId, value: ",deviceId,value),!(!deviceId||!value)&&new Promise(resolve=>{const{isAndroid:isAndroid,isIOS:isIOS}=getOS();console.log("isAndroid, isIOS: ",isAndroid,isIOS);const writeType=isAndroid?"writeNoResponse":"write";uni.writeBLECharacteristicValue({deviceId:deviceId,serviceId:"0000FF00-0000-1000-8000-00805F9B34FB",characteristicId:"0000FF02-0000-1000-8000-00805F9B34FB",writeType:writeType,value:value,success:res=>{console.error("res: 写入成功",res),resolve(!0)},fail:e=>{console.error("写入失败",e),resolve(!1)}}),isIOS&&setTimeout(()=>resolve(!0),50)})}const getData=async(deviceId,{command:command,commandVerifyHandler:commandVerifyHandler=hexArr=>({verified:!1,pkgLen:null}),pkgVerifyHandler:pkgVerifyHandler=pkg=>({verified:!1}),maxRetries:maxRetries=2,retryInterval:retryInterval=300},tag="")=>{if(!deviceId)throw new Error("deviceId is required");if(!command||command.length<=0)throw new Error("command is required");return new Promise((resolve,reject)=>{let isCompleted=!1,timeoutId=null,responsed=!1,len=null,pkg=[];const cmdContent=hexArr2ab(command),cleanup=()=>{isCompleted||(isCompleted=!0,clearTimeout(timeoutId),eventBus.off("setBleChangedCharacteristicValue",dataHandler))},dataHandler=payload=>{if(!payload||payload.deviceId!==deviceId||!payload.value)return;const hexArr=ab2decimalArr(payload.value);if(console.log("hexArr: ",hexArr),console.warn(tag,"接收到数据:",hexArr2string(hexArr)),0!==hexArr.length){if(null===len){const{verified:verified,pkgLen:pkgLen}=commandVerifyHandler(hexArr);console.log("指令验证结果:",{verified:verified,pkgLen:pkgLen}),verified&&(len=pkgLen)}if(len){if(pkg=[...pkg,...hexArr],console.log("当前数据包:",pkg,`长度: ${pkg.length}/${len}`),pkg.length>=len){pkg=pkg.slice(0,len);const{verified:verified}=pkgVerifyHandler(pkg);console.log("数据包验证结果:",{verified:verified}),verified?(responsed=!0,cleanup(),resolve([...pkg])):(len=null,pkg=[])}}else pkg=[]}},writeToDevice=async(attempt=1)=>{try{console.warn(tag,`第${attempt}次写入指令:`,command.join("").replace(/0x/g,"").toUpperCase());const writeSucceed=await async function(deviceId,value){return console.log("value: ",value),console.log("deviceId: ",deviceId),!(!deviceId||!value)&&new Promise(async resolve=>{const n=Math.ceil(value.byteLength/20);let res;for(let i=0;i<n;i++){const _value=value.slice(20*i,20*(i+1));if(console.log("分包写入_value: ",_value),await sleep(150),res=await _writeAsync(deviceId,_value),console.log(`分包写入结果 ${i+1}/${n} : ${res}`),!res)return resolve(!1)}resolve(res)})}(deviceId,cmdContent);if(console.warn(tag,`第${attempt}次写入结果:`,writeSucceed?"成功":"失败"),!writeSucceed)return void(attempt<maxRetries?setTimeout(()=>writeToDevice(attempt+1),retryInterval):(cleanup(),resolve(null)));await sleep(retryInterval),!responsed&&attempt<maxRetries?(console.log(tag,`未收到响应,准备第${attempt+1}次重试`),writeToDevice(attempt+1)):responsed||(console.warn(tag,`达到最大重试次数(${maxRetries}),未收到响应`),cleanup(),resolve(null))}catch(error){console.error(tag,"写入过程发生错误:",error),cleanup(),reject(error)}};timeoutId=setTimeout(()=>{console.warn(tag,"操作超时"),cleanup(),resolve(null)},(maxRetries+2)*retryInterval),eventBus.on("setBleChangedCharacteristicValue",dataHandler),writeToDevice().catch(error=>{cleanup(),reject(error)})})},setMTUAsync=(deviceId,mtu=512,delay=2500)=>new Promise((resolve,reject)=>{try{if(getOS().isIOS)return resolve(!0);setTimeout(async()=>{await uni.setBLEMTU({deviceId:deviceId,mtu:mtu}),resolve(!0)},delay)}catch(error){console.error(error),reject(error)}});export{getData,setMTUAsync};
|
|
1
|
+
import{hexArr2ab,ab2decimalArr,hexArr2string,sleep}from"../BleDataProcess.js";import{eventBus,getOS,getPlatform}from"../commonfun.js";async function _writeAsync(deviceId,value){return console.log("deviceId, value: ",deviceId,value),!(!deviceId||!value)&&new Promise(resolve=>{const{isAndroid:isAndroid,isIOS:isIOS}=getOS(),platform=getPlatform();console.log("platform: ",platform),console.log("isAndroid, isIOS: ",isAndroid,isIOS);const writeType="mp-weixin"===platform||isAndroid?"writeNoResponse":"write";uni.writeBLECharacteristicValue({deviceId:deviceId,serviceId:"0000FF00-0000-1000-8000-00805F9B34FB",characteristicId:"0000FF02-0000-1000-8000-00805F9B34FB",writeType:writeType,value:value,success:res=>{console.error("res: 写入成功",res),resolve(!0)},fail:e=>{console.error("写入失败",e),resolve(!1)}}),isIOS&&setTimeout(()=>resolve(!0),50)})}const getData=async(deviceId,{command:command,commandVerifyHandler:commandVerifyHandler=hexArr=>({verified:!1,pkgLen:null}),pkgVerifyHandler:pkgVerifyHandler=pkg=>({verified:!1}),maxRetries:maxRetries=2,retryInterval:retryInterval=300},tag="")=>{if(!deviceId)throw new Error("deviceId is required");if(!command||command.length<=0)throw new Error("command is required");return new Promise((resolve,reject)=>{let isCompleted=!1,timeoutId=null,responsed=!1,len=null,pkg=[];const cmdContent=hexArr2ab(command),cleanup=()=>{isCompleted||(isCompleted=!0,clearTimeout(timeoutId),eventBus.off("setBleChangedCharacteristicValue",dataHandler))},dataHandler=payload=>{if(!payload||payload.deviceId!==deviceId||!payload.value)return;const hexArr=ab2decimalArr(payload.value);if(console.log("hexArr: ",hexArr),console.warn(tag,"接收到数据:",hexArr2string(hexArr)),0!==hexArr.length){if(null===len){const{verified:verified,pkgLen:pkgLen}=commandVerifyHandler(hexArr);console.log("指令验证结果:",{verified:verified,pkgLen:pkgLen}),verified&&(len=pkgLen)}if(len){if(pkg=[...pkg,...hexArr],console.log("当前数据包:",pkg,`长度: ${pkg.length}/${len}`),pkg.length>=len){pkg=pkg.slice(0,len);const{verified:verified}=pkgVerifyHandler(pkg);console.log("数据包验证结果:",{verified:verified}),verified?(responsed=!0,cleanup(),resolve([...pkg])):(len=null,pkg=[])}}else pkg=[]}},writeToDevice=async(attempt=1)=>{try{console.warn(tag,`第${attempt}次写入指令:`,command.join("").replace(/0x/g,"").toUpperCase());const writeSucceed=await async function(deviceId,value){return console.log("value: ",value),console.log("deviceId: ",deviceId),!(!deviceId||!value)&&new Promise(async resolve=>{const n=Math.ceil(value.byteLength/20);let res;for(let i=0;i<n;i++){const _value=value.slice(20*i,20*(i+1));if(console.log("分包写入_value: ",_value),await sleep(150),res=await _writeAsync(deviceId,_value),console.log(`分包写入结果 ${i+1}/${n} : ${res}`),!res)return resolve(!1)}resolve(res)})}(deviceId,cmdContent);if(console.warn(tag,`第${attempt}次写入结果:`,writeSucceed?"成功":"失败"),!writeSucceed)return void(attempt<maxRetries?setTimeout(()=>writeToDevice(attempt+1),retryInterval):(cleanup(),resolve(null)));await sleep(retryInterval),!responsed&&attempt<maxRetries?(console.log(tag,`未收到响应,准备第${attempt+1}次重试`),writeToDevice(attempt+1)):responsed||(console.warn(tag,`达到最大重试次数(${maxRetries}),未收到响应`),cleanup(),resolve(null))}catch(error){console.error(tag,"写入过程发生错误:",error),cleanup(),reject(error)}};timeoutId=setTimeout(()=>{console.warn(tag,"操作超时"),cleanup(),resolve(null)},(maxRetries+2)*retryInterval),eventBus.on("setBleChangedCharacteristicValue",dataHandler),writeToDevice().catch(error=>{cleanup(),reject(error)})})},setMTUAsync=(deviceId,mtu=512,delay=2500)=>new Promise((resolve,reject)=>{try{if(getOS().isIOS)return resolve(!0);setTimeout(async()=>{await uni.setBLEMTU({deviceId:deviceId,mtu:mtu}),resolve(!0)},delay)}catch(error){console.error(error),reject(error)}});export{getData,setMTUAsync};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getData}from"./BleCmdAnalysis.js";import{hexArr2string,hex2string,decimalToHex,generateCrc16modbusCheck,hexArr2Assic,generateCrcCheckSum,hexToDecimal,stringToTwoHexArray}from"../BleDataProcess.js";import{getFFAA80Async,resolveFFAA80}from"./BleCmdFFAA.js";const enterFactory=async deviceId=>set_PlanCMD_DD(deviceId,"DD5A00025678FF3077"),existFactory=async deviceId=>set_PlanCMD_DD(deviceId,"DD5A01022828ffad77"),readExistFactory=async deviceId=>set_PlanCMD_DD(deviceId,"DD5A01020000FFFD77"),set_PlanCMD_DD=async(deviceId,command)=>{"string"==typeof command&&(command=command.match(/(.{2})/g).map(o=>`0x${o}`));let result=null;try{const data=await getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"PlanCMD_DD");if(data){const dataStr=hexArr2string(data),content=data.slice(4,data.length-3);result={data:data,dataStr:dataStr,status:hex2string(data[2]),len:data[3],content:content}}else result={status:0,content:[]}}catch(error){console.error(error)}return result},set_PlanCMD_3B3C=async(deviceId,command)=>{"string"==typeof command&&(command=command.match(/(.{2})/g).map(o=>`0x${o}`));let result=null;try{const data=await getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:59==hexArr[0]&&60==hexArr[1],pkgLen:hexArr[11]+15}),pkgVerifyHandler:pkg=>({verified:!0})},"PlanCMD_3B3C");if(data){const dataStr=hexArr2string(data),content=data.slice(12,data.length-3);result={dataStr:dataStr,status:128==data[10]?1:0,addr:hexArr2string(data.slice(2,10)),content:content}}}catch(error){console.error(error)}return result},get3B3CAsync=async deviceId=>{const addressCode=["0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00"],commandCode=["0x01"],data=[],dataLength=[`0x${decimalToHex(data.length,2)}`],check=generateCrc16modbusCheck([...addressCode,...commandCode,...dataLength,...data],!1),command=["0x3b","0x3c",...addressCode,...commandCode,...dataLength,...data,...check,"0x0d"];return getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:59==hexArr[0]&&60==hexArr[1],pkgLen:hexArr[11]+15}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=generateCrc16modbusCheck(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"3B3C")},resolve3B3C=data=>{if(!data)return null;let result={dataStr:hexArr2string(data),status:hex2string(data[10]),addr:hexArr2string(data.slice(2,10))};const content=data.slice(12,data.length-3);for(;content.length>0;){const[v1,v2,...v]=content.splice(0,content[1]+2);if(1==v1&&(result.productFlag=hex2string(v1),result.productLen=v2,v)){const[productType,frontType,protocolV,level]=v.map(o=>hex2string(o));Object.assign(result,{productType:productType,frontType:frontType,protocolV:protocolV,level:level})}2==v1&&(result.hardwareFlag=hex2string(v1),result.hardwareLen=v2,result.hardwareV=hexArr2Assic(v)),3==v1&&(result.sofewareFlag=hex2string(v1),result.sofewareLen=v2,result.sofewareV=hexArr2Assic(v)),4==v1&&(result.pcbFlag=hex2string(v1),result.pcbLen=v2,result.pcbContent=hexArr2Assic(v))}return result},getDDA503Async=async deviceId=>{const hex=await getData(deviceId,{command:["0xdd","0xa5","0x03","0x00","0xff","0xfd","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&3==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_03");return hex?resolveDDA503(hex):null},resolveDDA503=data=>{if(!data)return null;const cmdResp03=hexArr2string(data),content=data.slice(4,data.length-3),binArr=data[24].toString(2).padStart(8,"0").split("").reverse(),balances=data.slice(16,20).flatMap(byte=>byte.toString(2).padStart(8,"0").split("").reverse());console.warn("BC: ---------------",balances);const fet=data[24],chargeSwitch=!!Number(binArr[0]),dischargeSwitch=!!Number(binArr[1]),BMSVersion=decimalToHex(data[22]),humidityIndex=2*data[26]+27,humidity=data[humidityIndex],n=Number(binArr[7])||136==humidity?10:100,totalVoltage=Number((((data[4]<<8)+(255&data[5]))/100).toFixed(2));let current=(data[6]<<8)+(255&data[7]);current=current>32768?(current-65536)/n:current/n;const electricity=Number(current.toFixed(2)),power=Number((totalVoltage*electricity).toFixed(2)),soc=data[23]??0,seriesNum=data[25]??0,volumeHex=decimalToHex(data[8])+decimalToHex(data[9]),surplusCapacity=Number((hexToDecimal(volumeHex)/n).toFixed(2)),normCapHex=decimalToHex(data[10])+decimalToHex(data[11]),normCap=Number((hexToDecimal(normCapHex)/n).toFixed(2)),cycleHex=decimalToHex(data[12])+decimalToHex(data[13]),cycleIndex=hexToDecimal(cycleHex),fccHex=decimalToHex(data[humidityIndex+3])+decimalToHex(data[humidityIndex+4]),fullChargeCapacity=Number((hexToDecimal(fccHex)/n).toFixed(2)),SOH=cycleIndex<=100?100:Math.min(100,fullChargeCapacity/normCap*100),heatingState=!!Number(binArr[4])||!!Number(binArr[3]);let heatingCurrent=null;const hasHeatingCurrent=data[3]+7>=humidityIndex+9+4+1,hasEquilCurrent=data[3]+7>=humidityIndex+7+4+1;if(heatingState&&hasHeatingCurrent){const i=humidityIndex+9;heatingCurrent=heatingCurrent=((data[i]<<8|data[i+1])/100).toFixed(2)}let equilibriumCurrent=null;if(hasEquilCurrent){const i=humidityIndex+7;let equilCurrent=(data[i]<<8)+(255&data[i+1]);equilCurrent=equilCurrent>32768?(equilCurrent-65536)/1e3:equilCurrent/1e3,equilibriumCurrent=Number(equilCurrent.toFixed(2))}const isFactoryMode=!!Number(binArr[6]),equilibriumStatus=!(0===data[16]&&0===data[17]),protectStatus=!(0===data[20]&&0===data[21]),protectStateHex=decimalToHex(data[20])+decimalToHex(data[21]),protVal=hexToDecimal(protectStateHex);let alarmIndex=2*data[26]+28,alarmStateHex=decimalToHex(data[alarmIndex])+decimalToHex(data[alarmIndex+1]),alarmsState=hexToDecimal(alarmStateHex);const ntcNums=255&data[26],temperaturesList=Array.from({length:ntcNums},(_,i)=>((256*(255&data[26+2*i+1])+(255&data[26+2*i+2])-2731)/10).toFixed(1)),fahTempList=[];temperaturesList.forEach(el=>{const value=1.8*Number(el)+32;fahTempList.push(value.toFixed(1))});const temperatures=temperaturesList.map((item,index)=>({name:index+1,value:item}));return{cmdResp03:cmdResp03,status:hex2string(data[2]),len:data[3],softwareV:hex2string(content[18]),balances:balances,BMSVersion:BMSVersion,soc:soc,normCap:normCap,surplusCapacity:surplusCapacity,totalVoltage:totalVoltage,electricity:electricity,power:power,cycleIndex:cycleIndex,equilibriumStatus:equilibriumStatus,chargeSwitch:chargeSwitch,dischargeSwitch:dischargeSwitch,temperatures:temperatures,humidity:humidity,protectStatus:protectStatus,fullChargeCapacity:fullChargeCapacity,SOH:SOH,heatingState:heatingState,heatingCurrent:heatingCurrent,equilibriumCurrent:equilibriumCurrent,isFactoryMode:isFactoryMode,protVal:protVal,alarmsState:alarmsState,ntcNums:ntcNums,temperaturesList:temperaturesList,fahTempList:fahTempList,fet:fet,seriesNum:seriesNum}},getDDA504Async=async(deviceId,dataScope)=>{const hex=await getData(deviceId,{command:["0xdd","0xa5","0x04","0x00","0xff","0xfc","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&4==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_04");return hex?resolveDDA504(hex,dataScope):null},resolveDDA504=(data,dataScope)=>{if(console.log("data: ",data),!data)return null;const cmdResp04=hexArr2string(data),voltageList=[];for(let index=4;index<parseInt(data[3])+4;index+=2){let voltageHex=decimalToHex(data[index])+decimalToHex(data[index+1]),voltage=hexToDecimal(voltageHex);voltageList.push(Number(voltage))}let highestVoltage=null,lowestVoltage=null,averageVoltage=null,dropoutVoltage=null;if(voltageList.length>0){highestVoltage=Math.max(...voltageList),lowestVoltage=Math.min(...voltageList);averageVoltage=voltageList.reduce((acc,cur)=>acc+cur,0)/voltageList.length;const dropout=highestVoltage-lowestVoltage,precision=dataScope?3:2;highestVoltage=Number((highestVoltage/1e3).toFixed(precision)),lowestVoltage=Number((lowestVoltage/1e3).toFixed(precision)),averageVoltage=Number((averageVoltage/1e3).toFixed(precision)),dropoutVoltage=Number((dropout/1e3).toFixed(precision))}voltageList.forEach((v,i)=>{let newV=v/1e3;voltageList[i]=Number(newV.toFixed(dataScope?3:2))});const voltageSeries=voltageList.map((item,index)=>({name:index+1,value:item}));return{cmdResp04:cmdResp04,voltageList:voltageList,voltageSeries:voltageSeries,highestVoltage:highestVoltage,lowestVoltage:lowestVoltage,averageVoltage:averageVoltage,dropoutVoltage:dropoutVoltage}},getChipTypeAsync=async deviceId=>{const hex=await getData(deviceId,{command:["0xdd","0xa5","0x00","0x00","0x00","0x00","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&0==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_00");return hex?resolveDDA500(hex):null},resolveDDA500=data=>{if(!data)return null;return{dataStr:hexArr2string(data),status:hex2string(data[2]),len:data[3],type:data[5]}},getDD5AE1Async=async(deviceId,value)=>{const _command=["0xE1","0x02","0x00",value],checks=generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&225==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_E1")},getDD5AFBAsync=async(deviceId,type,value)=>{const _command=["0xFB","0x02",type,value],checks=generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return console.log("command: ",command),getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&251==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_FB")},resolveBaseDD=data=>{if(!data)return null;const dataStr=hexArr2string(data),content=data.slice(4,data.length-3);return{dataStr:dataStr,status:hex2string(data[2]),len:data[3],content:content}},getDD5A0AAsync=async(deviceId,value)=>{const _command=["0x0A","0x02",...stringToTwoHexArray(value)],checks=generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return console.log("command: ",command),getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&10==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},`DD5A_0A_${value}`)},getDD5AFAAsync=async(deviceId,value)=>{const hexStr=decimalToHex(100*value,4),_command=["0xFA","0x05","0x00","0x70","0x01",...[`0x${hexStr.slice(0,2)}`,`0x${hexStr.slice(2,4)}`]],checks=generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&250==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_FA")},getDDA505Async=async deviceId=>getData(deviceId,{command:["0xdd","0xa5","0x05","0x00","0xff","0xfb","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&5==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_05"),resolveDDA505=data=>{if(!data)return null;return{dataStr:hexArr2string(data),status:hex2string(data[2]),len:data[3],hardwareV:hexArr2Assic(data.slice(4,data.length-3))}},getDDA5FAAsync=async(deviceId,paramNo,length)=>{const _values=[...paramNo,length],_command=["0xFA",decimalToHex(_values.length),..._values],checks=generateCrcCheckSum(_command),command=["0xDD","0xA5",..._command,...checks,"0x77"];return getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&250==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"READ_DDA5_FA")},setDDA5FAAsync=async(deviceId,paramNo,valueLength,content)=>{const _values=[...paramNo,valueLength,...content],_command=["0xFA",decimalToHex(_values.length),..._values],checks=generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&250==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"SET_DDA5_FA")},resolveDDA5FA=data=>{if(!data)return null;return{dataStr:hexArr2string(data),status:hex2string(data[2]),len:data[3],type:data[5],value:data.slice(7,-3)}},getDDA5OldAsync=async(deviceId,path)=>{const values=[path,"0x00"],checks=generateCrcCheckSum(values),command=["0xDD","0xa5",...values,...checks,"0x77"];return getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&hexArr[1]==path,pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_读旧协议读参")},setDDA5OldAsync=async(deviceId,path,value,type="")=>{const values=[path,"0x02",...value],checks=generateCrcCheckSum(values),command=["0xDD","0x5A",...values,...checks,"0x77"];return getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&hexArr[1]==path,pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DDA5_写旧协议读参"+type)},getDD5AE0Async=async(deviceId,value)=>{const hex=100*value,hexStr=decimalToHex(hex,4),_values=[`0x${hexStr.slice(0,2)}`,`0x${hexStr.slice(2,4)}`],_command=["0xE0","0x02",..._values],checks=generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return console.warn("=======CCCCCCC=SET===",{value:value,hex:hex,hexStr:hexStr,_values:_values,_command:_command,checks:checks,command:command}),getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&224==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_E0")},getDD5A0EAsync=async deviceId=>getData(deviceId,{command:["0xDD","0x5A","0x0E","0x02","0x81","0x18","0xFF","0x57","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&14==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_0E_复位"),getDD5AE4Async=async deviceId=>getData(deviceId,{command:["0xdd","0x5a","0xe4","0x02","0x18","0x81","0xfe","0x81","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&228==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_E4"),getDD5AAllAsync=async(deviceId,path,lengthHex,values,type)=>{const _command=[path,lengthHex,...values],checks=generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&hexArr[1]==path,pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},`DD5A_${path}_${type}`)},sendBMSAsync=async(deviceId,values)=>{const command=values.match(/[0-9a-fA-F]{2}/g)?.map(item=>`0x${item}`)||[];return getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&hexArr[1]==command[2],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},`DD5A_${command[2]}`)},resolveBMSCmd=data=>{if(!data)return null;return{dataStr:hexArr2string(data),status:hex2string(data[2]),len:data[3]}},getProtectCountCmd=async deviceId=>{const data=await getData(deviceId,{command:["0xdd","0xa5","0xaa","0x00","0xff","0x56","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&170==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DDA5_AA保护次数"),arr=[];for(let i=4;i<data.length-4;i+=2){const offset=i;console.log("offset",offset);let value=((255&data[offset])<<8)+(255&data[offset+1]);arr.push(value)}return arr},getDD5A17Async=async deviceId=>getData(deviceId,{command:["0xDD","0x5A","0x17","0x02","0x00","0x01","0xFF","0xE6","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&23==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_17-清除电池循环次数"),getDDA507Async=async deviceId=>getData(deviceId,{command:["0xDD","0xA5","0x07","0x00","0xFF","0xF9","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&7==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_07历史运行履历总数"),getDDA508Async=async(deviceId,i=0)=>{const _command=["0x08",`0x${i.toString(16).padStart(2,0)}`],checks=generateCrcCheckSum(_command),command=["0xDD","0xA5",..._command,...checks,"0x77"];return getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&8==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_08读取履历详情")},resolveProtections=binary=>{const arr=binary.split("").reverse(),map=["device.0041","device.0042","device.0043","device.0044","device.0045","device.0046","device.0047","device.0048","device.0049","device.0050","device.0051","device.0052","device.0053","device.0054","device.0055","device.00551"];let _arr=[],_indexs=[];for(let i=0;i<arr.length;i++)1==arr[i]&&(_arr.push(map[i]),_indexs.push(i));return{_arr:_arr,_indexs:_indexs}},resolveDDA508=data=>{if(!data)return null;if(!data)return null;const hexArr=data.map(o=>o.toString(16).padStart(2,"0").toUpperCase()),f=s=>parseInt(s,16),fet=data[40].toString(2).padStart(8,"0").split("").reverse(),protection=f(hexArr[23]+hexArr[22]).toString(2).padStart(16,"0"),n=Number(fet[7])?10:100;let current=(hexArr[16]<<8)+(255&hexArr[17]);current=current>32768?(current-65536)/n:current/n;const electricity=Number(current.toFixed(2)),sysTime=65536*data[30]+256*data[31]+data[32];console.log("hexArr[30], hexArr[31], hexArr[32]",hexArr[30],hexArr[31],hexArr[32]),console.warn("sysTime: ",sysTime);const reportTime=65536*data[11]+256*data[12]+data[13];console.log("data[11], data[12], data[13]",data[11],data[12],data[13]),console.warn("reportTime: ",reportTime);const time=60*Math.abs(sysTime-reportTime)*1e3;console.warn("time: ",time);const timestamp=(new Date).getTime()-time;return console.warn("new Date().getTime(): ",(new Date).getTime()),{dataStr:hexArr.join(""),status:hex2string(data[2]),len:data[3],total:f(hexArr[4]+hexArr[5]),page:f(hexArr[6]+hexArr[7]),type:data[8],sysTime:sysTime,timestamp:timestamp,sumV:(f(hexArr[15]+hexArr[14])/100).toFixed(2),sumE:electricity,restC:(f(hexArr[19]+hexArr[18])/n).toFixed(2),designC:(f(hexArr[21]+hexArr[20])/n).toFixed(2),protections:resolveProtections(protection)._arr,protectionIndex:resolveProtections(protection)._indexs,tH:((f(hexArr[27]+hexArr[26])-2731)/10).toFixed(2),tL:((f(hexArr[29]+hexArr[28])-2731)/10).toFixed(2),vH:(f(hexArr[35]+hexArr[34])/1e3).toFixed(3),vL:(f(hexArr[37]+hexArr[36])/1e3).toFixed(3),nH:f(hexArr[38]),nL:f(hexArr[39]),fet:fet.join("")}},get3B3CInfo=({deviceId:deviceId,macAddr:macAddr,moduleType:moduleType,productType:productType})=>new Promise(async(resolve,reject)=>{let reportData={macAddr:macAddr,moduleTypeKey:moduleType,productKey:productType},_3b3c=null,_dda5_03=null,_dda5_05=null,_ffaa_80=null;try{if(!deviceId)throw new Error("deviceId required");const _ffaa_80_hex=await getFFAA80Async(deviceId,"AT^VERSION?");_ffaa_80=resolveFFAA80(_ffaa_80_hex),console.warn("Report-3B3C _ffaa_80 ",{_ffaa_80_hex:_ffaa_80_hex,_ffaa_80:_ffaa_80}),_ffaa_80&&(reportData.moduleVersion=_ffaa_80?.moduleVersion);const _3b3c_hex=await get3B3CAsync(deviceId);if(_3b3c=resolve3B3C(_3b3c_hex),console.warn("Report-3B3C _3b3c ",{_3b3c_hex:_3b3c_hex,_3b3c:_3b3c}),_3b3c)reportData.cmdContent=_3b3c?.dataStr;else{const _dda5_03_hex=await getDDA503Async(deviceId);_dda5_03=resolveDDA503(_dda5_03_hex),console.warn("Report-3B3C _dda5_03 ",{_dda5_03_hex:_dda5_03_hex,_dda5_03:_dda5_03}),_dda5_03&&(reportData.bmsVersion=_dda5_03?.softwareV);const _dda5_05_hex=await getDDA505Async(deviceId);_dda5_05=resolveDDA505(_dda5_05_hex),console.warn("Report-3B3C _dda5_05 ",{_dda5_05_hex:_dda5_05_hex,_dda5_05:_dda5_05}),_dda5_05&&(reportData.bmsSn=_dda5_05?.hardwareV)}resolve({reportData:reportData,_3b3c:_3b3c,_dda5_03:_dda5_03,_dda5_05:_dda5_05,_ffaa_80:_ffaa_80})}catch(error){reject(error)}});export{enterFactory,existFactory,get3B3CAsync,get3B3CInfo,getChipTypeAsync,getDD5A0AAsync,getDD5A0EAsync,getDD5A17Async,getDD5AAllAsync,getDD5AE0Async,getDD5AE1Async,getDD5AE4Async,getDD5AFAAsync,getDD5AFBAsync,getDDA503Async,getDDA504Async,getDDA505Async,getDDA507Async,getDDA508Async,getDDA5FAAsync,getDDA5OldAsync,getProtectCountCmd,readExistFactory,resolve3B3C,resolveBMSCmd,resolveBaseDD,resolveDDA500,resolveDDA503,resolveDDA504,resolveDDA505,resolveDDA508,resolveDDA5FA,resolveProtections,sendBMSAsync,setDDA5FAAsync,setDDA5OldAsync,set_PlanCMD_3B3C,set_PlanCMD_DD};
|
|
1
|
+
import{hexArr2string,hex2string,decimalToHex,generateCrc16modbusCheck,hexArr2Assic,generateCrcCheckSum,hexToDecimal,stringToTwoHexArray,sleep}from"../BleDataProcess.js";import{getData}from"./BleCmdAnalysis.js";import{getFFAA80Async,resolveFFAA80}from"./BleCmdFFAA.js";const enterFactory=async deviceId=>set_PlanCMD_DD(deviceId,"DD5A00025678FF3077"),existFactory=async deviceId=>set_PlanCMD_DD(deviceId,"DD5A01022828ffad77"),readExistFactory=async deviceId=>set_PlanCMD_DD(deviceId,"DD5A01020000FFFD77"),set_PlanCMD_DD=async(deviceId,command)=>{"string"==typeof command&&(command=command.match(/(.{2})/g).map(o=>`0x${o}`));let result=null;try{const data=await getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"PlanCMD_DD");if(data){const dataStr=hexArr2string(data),content=data.slice(4,data.length-3);result={data:data,dataStr:dataStr,status:hex2string(data[2]),len:data[3],content:content}}else result={status:0,content:[]}}catch(error){console.error(error)}return result},set_PlanCMD_3B3C=async(deviceId,command)=>{"string"==typeof command&&(command=command.match(/(.{2})/g).map(o=>`0x${o}`));let result=null;try{const data=await getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:59==hexArr[0]&&60==hexArr[1],pkgLen:hexArr[11]+15}),pkgVerifyHandler:pkg=>({verified:!0})},"PlanCMD_3B3C");if(data){const dataStr=hexArr2string(data),content=data.slice(12,data.length-3);result={dataStr:dataStr,status:128==data[10]?1:0,addr:hexArr2string(data.slice(2,10)),content:content}}}catch(error){console.error(error)}return result},get3B3CAsync=async deviceId=>{const addressCode=["0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00"],commandCode=["0x01"],data=[],dataLength=[`0x${decimalToHex(data.length,2)}`],check=generateCrc16modbusCheck([...addressCode,...commandCode,...dataLength,...data],!1),command=["0x3b","0x3c",...addressCode,...commandCode,...dataLength,...data,...check,"0x0d"];return getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:59==hexArr[0]&&60==hexArr[1],pkgLen:hexArr[11]+15}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=generateCrc16modbusCheck(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"3B3C")},resolve3B3C=data=>{if(!data)return null;let result={dataStr:hexArr2string(data),status:hex2string(data[10]),addr:hexArr2string(data.slice(2,10))};const content=data.slice(12,data.length-3);for(;content.length>0;){const[v1,v2,...v]=content.splice(0,content[1]+2);if(1==v1&&(result.productFlag=hex2string(v1),result.productLen=v2,v)){const[productType,frontType,protocolV,level]=v.map(o=>hex2string(o));Object.assign(result,{productType:productType,frontType:frontType,protocolV:protocolV,level:level})}2==v1&&(result.hardwareFlag=hex2string(v1),result.hardwareLen=v2,result.hardwareV=hexArr2Assic(v)),3==v1&&(result.sofewareFlag=hex2string(v1),result.sofewareLen=v2,result.sofewareV=hexArr2Assic(v)),4==v1&&(result.pcbFlag=hex2string(v1),result.pcbLen=v2,result.pcbContent=hexArr2Assic(v))}return result},getDDA503Async=async deviceId=>{const hex=await getData(deviceId,{command:["0xdd","0xa5","0x03","0x00","0xff","0xfd","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&3==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_03");return hex?resolveDDA503(hex):null},resolveDDA503=data=>{if(!data)return null;const cmdResp03=hexArr2string(data),content=data.slice(4,data.length-3),binArr=data[24].toString(2).padStart(8,"0").split("").reverse(),balances=data.slice(16,20).flatMap(byte=>byte.toString(2).padStart(8,"0").split("").reverse());console.warn("BC: ---------------",balances);const fet=data[24],chargeSwitch=!!Number(binArr[0]),dischargeSwitch=!!Number(binArr[1]),BMSVersion=decimalToHex(data[22]),humidityIndex=2*data[26]+27,humidity=data[humidityIndex],n=Number(binArr[7])||136==humidity?10:100,totalVoltage=Number((((data[4]<<8)+(255&data[5]))/100).toFixed(2));let current=(data[6]<<8)+(255&data[7]);current=current>32768?(current-65536)/n:current/n;const electricity=Number(current.toFixed(2)),power=Number((totalVoltage*electricity).toFixed(2)),soc=data[23]??0,seriesNum=data[25]??0,volumeHex=decimalToHex(data[8])+decimalToHex(data[9]),surplusCapacity=Number((hexToDecimal(volumeHex)/n).toFixed(2)),normCapHex=decimalToHex(data[10])+decimalToHex(data[11]),normCap=Number((hexToDecimal(normCapHex)/n).toFixed(2)),cycleHex=decimalToHex(data[12])+decimalToHex(data[13]),cycleIndex=hexToDecimal(cycleHex),fccHex=decimalToHex(data[humidityIndex+3])+decimalToHex(data[humidityIndex+4]),fullChargeCapacity=Number((hexToDecimal(fccHex)/n).toFixed(2)),SOH=cycleIndex<=100?100:Math.min(100,fullChargeCapacity/normCap*100),heatingState=!!Number(binArr[4])||!!Number(binArr[3]);let heatingCurrent=null;const hasHeatingCurrent=data[3]+7>=humidityIndex+9+4+1,hasEquilCurrent=data[3]+7>=humidityIndex+7+4+1;if(heatingState&&hasHeatingCurrent){const i=humidityIndex+9;heatingCurrent=heatingCurrent=((data[i]<<8|data[i+1])/100).toFixed(2)}let equilibriumCurrent=null;if(hasEquilCurrent){const i=humidityIndex+7;let equilCurrent=(data[i]<<8)+(255&data[i+1]);equilCurrent=equilCurrent>32768?(equilCurrent-65536)/1e3:equilCurrent/1e3,equilibriumCurrent=Number(equilCurrent.toFixed(2))}const isFactoryMode=!!Number(binArr[6]),equilibriumStatus=!(0===data[16]&&0===data[17]),protectStatus=!(0===data[20]&&0===data[21]),protectStateHex=decimalToHex(data[20])+decimalToHex(data[21]),protVal=hexToDecimal(protectStateHex);let alarmIndex=2*data[26]+28,alarmStateHex=decimalToHex(data[alarmIndex])+decimalToHex(data[alarmIndex+1]),alarmsState=hexToDecimal(alarmStateHex);const ntcNums=255&data[26],temperaturesList=Array.from({length:ntcNums},(_,i)=>((256*(255&data[26+2*i+1])+(255&data[26+2*i+2])-2731)/10).toFixed(1)),fahTempList=[];temperaturesList.forEach(el=>{const value=1.8*Number(el)+32;fahTempList.push(value.toFixed(1))});const temperatures=temperaturesList.map((item,index)=>({name:index+1,value:item}));return{cmdResp03:cmdResp03,status:hex2string(data[2]),len:data[3],softwareV:hex2string(content[18]),balances:balances,BMSVersion:BMSVersion,soc:soc,normCap:normCap,surplusCapacity:surplusCapacity,totalVoltage:totalVoltage,electricity:electricity,power:power,cycleIndex:cycleIndex,equilibriumStatus:equilibriumStatus,chargeSwitch:chargeSwitch,dischargeSwitch:dischargeSwitch,temperatures:temperatures,humidity:humidity,protectStatus:protectStatus,fullChargeCapacity:fullChargeCapacity,SOH:SOH,heatingState:heatingState,heatingCurrent:heatingCurrent,equilibriumCurrent:equilibriumCurrent,isFactoryMode:isFactoryMode,protVal:protVal,alarmsState:alarmsState,ntcNums:ntcNums,temperaturesList:temperaturesList,fahTempList:fahTempList,fet:fet,seriesNum:seriesNum}},getDDA504Async=async(deviceId,dataScope)=>{const hex=await getData(deviceId,{command:["0xdd","0xa5","0x04","0x00","0xff","0xfc","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&4==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_04");return hex?resolveDDA504(hex,dataScope):null},resolveDDA504=(data,dataScope)=>{if(console.log("data: ",data),!data)return null;const cmdResp04=hexArr2string(data),voltageList=[];for(let index=4;index<parseInt(data[3])+4;index+=2){let voltageHex=decimalToHex(data[index])+decimalToHex(data[index+1]),voltage=hexToDecimal(voltageHex);voltageList.push(Number(voltage))}let highestVoltage=null,lowestVoltage=null,averageVoltage=null,dropoutVoltage=null;if(voltageList.length>0){highestVoltage=Math.max(...voltageList),lowestVoltage=Math.min(...voltageList);averageVoltage=voltageList.reduce((acc,cur)=>acc+cur,0)/voltageList.length;const dropout=highestVoltage-lowestVoltage,precision=dataScope?3:2;highestVoltage=Number((highestVoltage/1e3).toFixed(precision)),lowestVoltage=Number((lowestVoltage/1e3).toFixed(precision)),averageVoltage=Number((averageVoltage/1e3).toFixed(precision)),dropoutVoltage=Number((dropout/1e3).toFixed(precision))}voltageList.forEach((v,i)=>{let newV=v/1e3;voltageList[i]=Number(newV.toFixed(dataScope?3:2))});const voltageSeries=voltageList.map((item,index)=>({name:index+1,value:item}));return{cmdResp04:cmdResp04,voltageList:voltageList,voltageSeries:voltageSeries,highestVoltage:highestVoltage,lowestVoltage:lowestVoltage,averageVoltage:averageVoltage,dropoutVoltage:dropoutVoltage}},getChipTypeAsync=async deviceId=>{const hex=await getData(deviceId,{command:["0xdd","0xa5","0x00","0x00","0x00","0x00","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&0==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_00");return hex?resolveDDA500(hex):null},resolveDDA500=data=>{if(!data)return null;return{dataStr:hexArr2string(data),status:hex2string(data[2]),len:data[3],type:data[5]}},getDD5AE1Async=async(deviceId,value)=>{const _command=["0xE1","0x02","0x00",value],checks=generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&225==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_E1")},getDD5AFBAsync=async(deviceId,type,value)=>{const _command=["0xFB","0x02",type,value],checks=generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return console.log("command: ",command),getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&251==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_FB")},resolveBaseDD=data=>{if(!data)return null;const dataStr=hexArr2string(data),content=data.slice(4,data.length-3);return{dataStr:dataStr,status:hex2string(data[2]),len:data[3],content:content}},getDD5A0AAsync=async(deviceId,value)=>{const _command=["0x0A","0x02",...stringToTwoHexArray(value)],checks=generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return console.log("command: ",command),getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&10==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},`DD5A_0A_${value}`)},resolveDD5A0A=data=>{if(!data)return null;const dataStr=hexArr2string(data),statusDec=data[2],len=data[3],succeeded=0===statusDec;return{dataStr:dataStr,status:hex2string(statusDec),len:len,succeeded:succeeded,message:succeeded?"CMD_EXEC_SUCCESS":"CMD_EXEC_FAIL"}},getDD5AFAAsync=async(deviceId,value)=>{const hexStr=decimalToHex(100*value,4),_command=["0xFA","0x05","0x00","0x70","0x01",...[`0x${hexStr.slice(0,2)}`,`0x${hexStr.slice(2,4)}`]],checks=generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&250==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_FA")},getDDA505Async=async deviceId=>getData(deviceId,{command:["0xdd","0xa5","0x05","0x00","0xff","0xfb","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&5==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_05"),resolveDDA505=data=>{if(!data)return null;return{dataStr:hexArr2string(data),status:hex2string(data[2]),len:data[3],hardwareV:hexArr2Assic(data.slice(4,data.length-3))}},getDDA5FAAsync=async(deviceId,paramNo,length)=>{const _values=[...paramNo,length],_command=["0xFA",decimalToHex(_values.length),..._values],checks=generateCrcCheckSum(_command),command=["0xDD","0xA5",..._command,...checks,"0x77"];return getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&250==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"READ_DDA5_FA")},setDDA5FAAsync=async(deviceId,paramNo,valueLength,content)=>{const _values=[...paramNo,valueLength,...content],_command=["0xFA",decimalToHex(_values.length),..._values],checks=generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&250==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"SET_DDA5_FA")},resolveDDA5FA=data=>{if(!data)return null;return{dataStr:hexArr2string(data),status:hex2string(data[2]),len:data[3],type:data[5],value:data.slice(7,-3)}},getDDA5OldAsync=async(deviceId,path)=>{const values=[path,"0x00"],checks=generateCrcCheckSum(values),command=["0xDD","0xa5",...values,...checks,"0x77"];return getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&hexArr[1]==path,pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_读旧协议读参")},setDDA5OldAsync=async(deviceId,path,value,type="")=>{const values=[path,"0x02",...value],checks=generateCrcCheckSum(values),command=["0xDD","0x5A",...values,...checks,"0x77"];return getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&hexArr[1]==path,pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DDA5_写旧协议读参"+type)},getDD5AE0Async=async(deviceId,value)=>{const hex=100*value,hexStr=decimalToHex(hex,4),_values=[`0x${hexStr.slice(0,2)}`,`0x${hexStr.slice(2,4)}`],_command=["0xE0","0x02",..._values],checks=generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return console.warn("=======CCCCCCC=SET===",{value:value,hex:hex,hexStr:hexStr,_values:_values,_command:_command,checks:checks,command:command}),getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&224==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_E0")},getDD5A0EAsync=async deviceId=>getData(deviceId,{command:["0xDD","0x5A","0x0E","0x02","0x81","0x18","0xFF","0x57","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&14==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_0E_复位"),getDD5AE4Async=async deviceId=>getData(deviceId,{command:["0xdd","0x5a","0xe4","0x02","0x18","0x81","0xfe","0x81","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&228==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_E4"),getDD5AAllAsync=async(deviceId,path,lengthHex,values,type)=>{const _command=[path,lengthHex,...values],checks=generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&hexArr[1]==path,pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},`DD5A_${path}_${type}`)},sendBMSAsync=async(deviceId,values)=>{const command=values.match(/[0-9a-fA-F]{2}/g)?.map(item=>`0x${item}`)||[];return getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&hexArr[1]==command[2],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},`DD5A_${command[2]}`)},resolveBMSCmd=data=>{if(!data)return null;return{dataStr:hexArr2string(data),status:hex2string(data[2]),len:data[3]}},getProtectCountCmd=async deviceId=>{const data=await getData(deviceId,{command:["0xdd","0xa5","0xaa","0x00","0xff","0x56","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&170==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DDA5_AA保护次数"),arr=[];for(let i=4;i<data.length-4;i+=2){const offset=i;console.log("offset",offset);let value=((255&data[offset])<<8)+(255&data[offset+1]);arr.push(value)}return arr},getDD5A17Async=async deviceId=>getData(deviceId,{command:["0xDD","0x5A","0x17","0x02","0x00","0x01","0xFF","0xE6","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&23==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_17-清除电池循环次数"),getDDA507Async=async deviceId=>getData(deviceId,{command:["0xDD","0xA5","0x07","0x00","0xFF","0xF9","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&7==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_07历史运行履历总数"),getDDA508Async=async(deviceId,i=0)=>{const _command=["0x08",`0x${i.toString(16).padStart(2,0)}`],checks=generateCrcCheckSum(_command),command=["0xDD","0xA5",..._command,...checks,"0x77"];return getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&8==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_08读取履历详情")},resolveProtections=binary=>{const arr=binary.split("").reverse(),map=["device.0041","device.0042","device.0043","device.0044","device.0045","device.0046","device.0047","device.0048","device.0049","device.0050","device.0051","device.0052","device.0053","device.0054","device.0055","device.00551"];let _arr=[],_indexs=[];for(let i=0;i<arr.length;i++)1==arr[i]&&(_arr.push(map[i]),_indexs.push(i));return{_arr:_arr,_indexs:_indexs}},resolveDDA508=data=>{if(!data)return null;if(!data)return null;const hexArr=data.map(o=>o.toString(16).padStart(2,"0").toUpperCase()),f=s=>parseInt(s,16),fet=data[40].toString(2).padStart(8,"0").split("").reverse(),protection=f(hexArr[23]+hexArr[22]).toString(2).padStart(16,"0"),n=Number(fet[7])?10:100;let current=(hexArr[16]<<8)+(255&hexArr[17]);current=current>32768?(current-65536)/n:current/n;const electricity=Number(current.toFixed(2)),sysTime=65536*data[30]+256*data[31]+data[32];console.log("hexArr[30], hexArr[31], hexArr[32]",hexArr[30],hexArr[31],hexArr[32]),console.warn("sysTime: ",sysTime);const reportTime=65536*data[11]+256*data[12]+data[13];console.log("data[11], data[12], data[13]",data[11],data[12],data[13]),console.warn("reportTime: ",reportTime);const time=60*Math.abs(sysTime-reportTime)*1e3;console.warn("time: ",time);const timestamp=(new Date).getTime()-time;return console.warn("new Date().getTime(): ",(new Date).getTime()),{dataStr:hexArr.join(""),status:hex2string(data[2]),len:data[3],total:f(hexArr[4]+hexArr[5]),page:f(hexArr[6]+hexArr[7]),type:data[8],sysTime:sysTime,timestamp:timestamp,sumV:(f(hexArr[15]+hexArr[14])/100).toFixed(2),sumE:electricity,restC:(f(hexArr[19]+hexArr[18])/n).toFixed(2),designC:(f(hexArr[21]+hexArr[20])/n).toFixed(2),protections:resolveProtections(protection)._arr,protectionIndex:resolveProtections(protection)._indexs,tH:((f(hexArr[27]+hexArr[26])-2731)/10).toFixed(2),tL:((f(hexArr[29]+hexArr[28])-2731)/10).toFixed(2),vH:(f(hexArr[35]+hexArr[34])/1e3).toFixed(3),vL:(f(hexArr[37]+hexArr[36])/1e3).toFixed(3),nH:f(hexArr[38]),nL:f(hexArr[39]),fet:fet.join("")}},get3B3CInfo=({deviceId:deviceId,macAddr:macAddr,moduleType:moduleType,productType:productType})=>new Promise(async(resolve,reject)=>{let reportData={macAddr:macAddr,moduleTypeKey:moduleType,productKey:productType},_3b3c=null,_dda5_03=null,_dda5_05=null,_ffaa_80=null;try{if(!deviceId)throw new Error("deviceId required");const _ffaa_80_hex=await getFFAA80Async(deviceId,"AT^VERSION?");_ffaa_80=resolveFFAA80(_ffaa_80_hex),console.warn("Report-3B3C _ffaa_80 ",{_ffaa_80_hex:_ffaa_80_hex,_ffaa_80:_ffaa_80}),_ffaa_80&&(reportData.moduleVersion=_ffaa_80?.moduleVersion);const _3b3c_hex=await get3B3CAsync(deviceId);if(_3b3c=resolve3B3C(_3b3c_hex),console.warn("Report-3B3C _3b3c ",{_3b3c_hex:_3b3c_hex,_3b3c:_3b3c}),_3b3c)reportData.cmdContent=_3b3c?.dataStr;else{const _dda5_03_hex=await getDDA503Async(deviceId);_dda5_03=resolveDDA503(_dda5_03_hex),console.warn("Report-3B3C _dda5_03 ",{_dda5_03_hex:_dda5_03_hex,_dda5_03:_dda5_03}),_dda5_03&&(reportData.bmsVersion=_dda5_03?.softwareV);const _dda5_05_hex=await getDDA505Async(deviceId);_dda5_05=resolveDDA505(_dda5_05_hex),console.warn("Report-3B3C _dda5_05 ",{_dda5_05_hex:_dda5_05_hex,_dda5_05:_dda5_05}),_dda5_05&&(reportData.bmsSn=_dda5_05?.hardwareV)}resolve({reportData:reportData,_3b3c:_3b3c,_dda5_03:_dda5_03,_dda5_05:_dda5_05,_ffaa_80:_ffaa_80})}catch(error){reject(error)}}),activateAsync=async deviceId=>{const startTime=+new Date,disChargMOSHex=await getDD5AFBAsync(deviceId,"0x00","0x00"),disChargMOSRes=resolveBaseDD(disChargMOSHex)?.dataStr,disChargEndTime=+new Date,activeHex=await getDD5AFBAsync(deviceId,"0x05","0x01"),activeRes=resolveBaseDD(disChargMOSHex)?.dataStr;let baseInfo=null;const endTime=+new Date;await sleep(300),baseInfo=await getDDA503Async(deviceId);return{disChargMOSHex:disChargMOSHex,disChargMOSRes:disChargMOSRes,activeHex:activeHex,activeRes:activeRes,baseInfo:baseInfo,voltageInfo:await getDDA504Async(deviceId),startTime:startTime,disChargEndTime:disChargEndTime,endTime:endTime}},getDDA5DCAsync=deviceId=>{const _command=["0xDE","0x00"],checks=generateCrcCheckSum(_command),command=["0xDD","0xA5",..._command,...checks,"0x77"];return getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&222==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>{const len=pkg.length,[c1,c2]=generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_DC")},resolveDDA5DC=data=>{if(!data)return null;const dataStr=hexArr2string(data),status=hex2string(data[2]),len=255&data[3],resistances_milliohm=[];for(let i=4;i<4+len;i+=2){const value=((255&data[i])<<8)+(255&data[i+1]);resistances_milliohm.push(value)}console.log("均衡线电阻(mΩ): ",resistances_milliohm,data);let maxResistance=null,minResistance=null,avgResistance=null;resistances_milliohm.length&&(maxResistance=Math.max(...resistances_milliohm),minResistance=Math.min(...resistances_milliohm),avgResistance=resistances_milliohm.reduce((a,c)=>a+c,0)/resistances_milliohm.length);const resistances_ohm=resistances_milliohm.map(v=>Number((v/1e3).toFixed(3))),resistancesSeries=resistances_ohm.map((v,idx)=>({name:idx+1,value:v}));return{dataStr:dataStr,status:status,len:len,resistances_milliohm:resistances_milliohm,resistances_ohm:resistances_ohm,maxResistance_milliohm:maxResistance,minResistance_milliohm:minResistance,avgResistance_milliohm:avgResistance,maxResistance_ohm:null!=maxResistance?Number((maxResistance/1e3).toFixed(3)):null,minResistance_ohm:null!=minResistance?Number((minResistance/1e3).toFixed(3)):null,avgResistance_ohm:null!=avgResistance?Number((avgResistance/1e3).toFixed(3)):null,resistancesSeries:resistancesSeries}},resetCapacity=deviceId=>getData(deviceId,{command:["0xDD","0x5A","0x0A","0x02","0x01","0x00","0xFF","0xF3","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&10==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_0A");export{activateAsync,enterFactory,existFactory,get3B3CAsync,get3B3CInfo,getChipTypeAsync,getDD5A0AAsync,getDD5A0EAsync,getDD5A17Async,getDD5AAllAsync,getDD5AE0Async,getDD5AE1Async,getDD5AE4Async,getDD5AFAAsync,getDD5AFBAsync,getDDA503Async,getDDA504Async,getDDA505Async,getDDA507Async,getDDA508Async,getDDA5DCAsync,getDDA5FAAsync,getDDA5OldAsync,getProtectCountCmd,readExistFactory,resetCapacity,resolve3B3C,resolveBMSCmd,resolveBaseDD,resolveDD5A0A,resolveDDA500,resolveDDA503,resolveDDA504,resolveDDA505,resolveDDA508,resolveDDA5DC,resolveDDA5FA,resolveProtections,sendBMSAsync,setDDA5FAAsync,setDDA5OldAsync,set_PlanCMD_3B3C,set_PlanCMD_DD};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{decimalToTwoByteHexArray,decimalToHex}from"../BleDataProcess.js";import{getDDA5FAAsync,enterFactory,getDDA5OldAsync,setDDA5FAAsync,setDDA5OldAsync,existFactory,readExistFactory}from"./BleCmdDD.js";const readParamCmd=(chipType,deviceId,paramInfo,needFactoryMode=!0)=>(console.log("chipType: ",chipType),new Promise(async(resolve,reject)=>{const{address:address=0,length:length=1,oldAddress:oldAddress="0x1f"}=paramInfo,hexAddress=decimalToTwoByteHexArray(address),hexLength=decimalToHex(length),handleRead=async(readFunction,index)=>{try{const hex=await readFunction();if(4==index&&needFactoryMode&&await readExistFactory(deviceId),!hex)return void resolve(null);const data=hex.slice(index,-3);console.log("data: 读参数",data),resolve(data||null)}catch(error){console.error("读取参数出错: ",error),reject(error)}};try{if(chipType)await handleRead(async()=>await getDDA5FAAsync(deviceId,hexAddress,hexLength),7);else{if(!oldAddress)return resolve(null);needFactoryMode&&await enterFactory(deviceId),await handleRead(async()=>await getDDA5OldAsync(deviceId,oldAddress),4)}}catch(error){console.error("读取参数出错---: ",error),reject(error)}})),getSysParamCmd=async(chipType,deviceId,paramInfo,needFactoryMode=!0)=>{try{console.log("paramInfo: ",paramInfo);const paramObj={address:paramInfo.paramNo,length:paramInfo.paramLength/2,oldAddress:paramInfo.oldParamNo};let data=await readParamCmd(chipType,deviceId,paramObj,needFactoryMode);return data||null}catch(error){throw console.error("error: 读系统参数报错 getSysParamCmd",error),error}},setSysParamCmd=async(chipType,deviceId,paramInfoArray)=>{try{console.log("paramInfoArray: ",paramInfoArray);const paramsToProcess=Array.isArray(paramInfoArray)?paramInfoArray:[paramInfoArray],paramObjs=[];for(const paramInfo of paramsToProcess){let value=Math.round(Number(paramInfo?.paramValue||paramInfo.newValue)/Number(paramInfo?.divisor||1));console.log("value: ",value),paramInfo.isTemp&&(value=2731+10*Number(paramInfo.newValue));const valuesHexs=decimalToTwoByteHexArray(value);console.log("valuesHexs: ",valuesHexs),paramObjs.push({address:paramInfo.paramNo,length:paramInfo.paramLength/2,values:valuesHexs,oldAddress:paramInfo.oldParamNo})}await setParamCmd(chipType,deviceId,paramObjs)}catch(error){throw console.error("error: 写系统参数报错 setSysParamCmd",error),error}},setParamCmd=(chipType,deviceId,paramInfoArray)=>{console.log("chipType: 芯片",chipType);const paramsToProcess=Array.isArray(paramInfoArray)?paramInfoArray:[paramInfoArray];return new Promise(async(resolve,reject)=>{try{await enterFactory(deviceId);const results=[];for(let i=0;i<paramsToProcess.length;i++){const paramInfo=paramsToProcess[i],{address:address,length:length,values:values,oldAddress:oldAddress}=paramInfo,hexAddress=decimalToTwoByteHexArray(address),hexLength=decimalToHex(length);let hex;if(hex=chipType?await setDDA5FAAsync(deviceId,hexAddress,hexLength,values):await setDDA5OldAsync(deviceId,oldAddress,values),console.log(`data: 写入第${i+1}个参数结果`,hex),!hex)throw new Error(`设置第${i+1}个参数失败`);results.push(hex)}await existFactory(deviceId),resolve(results)}catch(error){console.error("设置参数出错: ",error);try{await existFactory(deviceId)}catch(exitError){console.error("退出工厂模式失败: ",exitError)}reject(error)}})},setCapacityParamCmd=(chipType,deviceId,paramInfo)=>(console.log("chipType: 芯片",chipType),new Promise(async(resolve,reject)=>{const{values:values}=paramInfo,circular={address:1,oldAddress:"0x11",values:.8*values,length:1},full={address:112,oldAddress:"0x10",values:values,length:1},handleSet=async(setFunction,index)=>{try{const hex=await setFunction();return console.log("data: 写入参数结果",hex),hex||void reject("设置参数失败")}catch(error){console.error("设置参数出错: ",error),reject(error)}},handleParam=async paramObj=>{const{
|
|
1
|
+
import{decimalToTwoByteHexArray,decimalToHex}from"../BleDataProcess.js";import{getDDA5FAAsync,enterFactory,getDDA5OldAsync,setDDA5FAAsync,setDDA5OldAsync,existFactory,readExistFactory}from"./BleCmdDD.js";const readParamCmd=(chipType,deviceId,paramInfo,needFactoryMode=!0)=>(console.log("chipType: ",chipType),new Promise(async(resolve,reject)=>{const{address:address=0,length:length=1,oldAddress:oldAddress="0x1f"}=paramInfo,hexAddress=decimalToTwoByteHexArray(address),hexLength=decimalToHex(length),handleRead=async(readFunction,index)=>{try{const hex=await readFunction();if(4==index&&needFactoryMode&&await readExistFactory(deviceId),!hex)return void resolve(null);const data=hex.slice(index,-3);console.log("data: 读参数",data),resolve(data||null)}catch(error){console.error("读取参数出错: ",error),reject(error)}};try{if(chipType)await handleRead(async()=>await getDDA5FAAsync(deviceId,hexAddress,hexLength),7);else{if(!oldAddress)return resolve(null);needFactoryMode&&await enterFactory(deviceId),await handleRead(async()=>await getDDA5OldAsync(deviceId,oldAddress),4)}}catch(error){console.error("读取参数出错---: ",error),reject(error)}})),getSysParamCmd=async(chipType,deviceId,paramInfo,needFactoryMode=!0)=>{try{console.log("paramInfo: ",paramInfo);const paramObj={address:paramInfo.paramNo,length:paramInfo.paramLength/2,oldAddress:paramInfo.oldParamNo};let data=await readParamCmd(chipType,deviceId,paramObj,needFactoryMode);return data||null}catch(error){throw console.error("error: 读系统参数报错 getSysParamCmd",error),error}},setSysParamCmd=async(chipType,deviceId,paramInfoArray)=>{try{console.log("paramInfoArray: ",paramInfoArray);const paramsToProcess=Array.isArray(paramInfoArray)?paramInfoArray:[paramInfoArray],paramObjs=[];for(const paramInfo of paramsToProcess){let value=Math.round(Number(paramInfo?.paramValue||paramInfo.newValue)/Number(paramInfo?.divisor||1));console.log("value: ",value),paramInfo.isTemp&&(value=2731+10*Number(paramInfo.newValue));const valuesHexs=decimalToTwoByteHexArray(value);console.log("valuesHexs: ",valuesHexs),paramObjs.push({address:paramInfo.paramNo,length:paramInfo.paramLength/2,values:valuesHexs,oldAddress:paramInfo.oldParamNo})}await setParamCmd(chipType,deviceId,paramObjs)}catch(error){throw console.error("error: 写系统参数报错 setSysParamCmd",error),error}},setParamCmd=(chipType,deviceId,paramInfoArray)=>{console.log("chipType: 芯片",chipType);const paramsToProcess=Array.isArray(paramInfoArray)?paramInfoArray:[paramInfoArray];return new Promise(async(resolve,reject)=>{try{await enterFactory(deviceId);const results=[];for(let i=0;i<paramsToProcess.length;i++){const paramInfo=paramsToProcess[i],{address:address,length:length,values:values,oldAddress:oldAddress}=paramInfo,hexAddress=decimalToTwoByteHexArray(address),hexLength=decimalToHex(length);let hex;if(hex=chipType?await setDDA5FAAsync(deviceId,hexAddress,hexLength,values):await setDDA5OldAsync(deviceId,oldAddress,values),console.log(`data: 写入第${i+1}个参数结果`,hex),!hex)throw new Error(`设置第${i+1}个参数失败`);results.push(hex)}await existFactory(deviceId),resolve(results)}catch(error){console.error("设置参数出错: ",error);try{await existFactory(deviceId)}catch(exitError){console.error("退出工厂模式失败: ",exitError)}reject(error)}})},setCapacityParamCmd=(chipType,deviceId,paramInfo)=>(console.log("chipType: 芯片",chipType),new Promise(async(resolve,reject)=>{const{values:values}=paramInfo,circular={address:1,oldAddress:"0x11",values:.8*values,length:1},full={address:112,oldAddress:"0x10",values:values,length:1},handleSet=async(setFunction,index)=>{try{const hex=await setFunction();return console.log("data: 写入参数结果",hex),hex||void reject("设置参数失败")}catch(error){console.error("设置参数出错: ",error),reject(error)}},handleParam=async paramObj=>{const{paramNo:paramNo,oldParamNo:oldParamNo,paramLength:paramLength}=paramObj,value=Math.round(Number(paramObj.values)/paramInfo.divisor);console.log("value: ",value);const hexValues=decimalToTwoByteHexArray(value),hexAddress=decimalToTwoByteHexArray(paramNo),hexLength=decimalToHex(paramLength/2);return chipType?await handleSet(()=>setDDA5FAAsync(deviceId,hexAddress,hexLength,hexValues)):await handleSet(()=>setDDA5OldAsync(deviceId,oldParamNo,hexValues))};try{await enterFactory(deviceId);const paramInfoHex=await handleParam(paramInfo);await handleParam(circular);if(chipType){await handleParam(full)}await existFactory(deviceId),paramInfoHex&&resolve(paramInfoHex)}catch(error){reject(error)}}));export{getSysParamCmd,readParamCmd,setCapacityParamCmd,setParamCmd,setSysParamCmd};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function isEmpty(v){return null==v||""===v}function isNotEmpty(v){return!isEmpty(v)}function inArray(arr,key,val){for(let i=0;i<arr.length;i++)if(arr[i][key]===val)return i;return-1}function formatTimeHHmm(hours){const hour=Math.floor(hours),minute=Math.floor(60*(hours-hour));return console.log("H5环境"),`${hour}H:${minute}m`}function getOS(){const os=uni.getSystemInfoSync()?.osName;return{isIOS:"ios"==os,isAndroid:"android"==os}}const eventBus={events:{},on(event,callback){this.events[event]||(this.events[event]=[]),this.events[event].push(callback)},off(event,callback){this.events[event]&&(callback?(this.events[event]=this.events[event].filter(cb=>cb!==callback),0===this.events[event].length&&delete this.events[event]):delete this.events[event])},emit(event,...args){this.events[event]&&this.events[event].forEach(callback=>callback(...args))}};export{eventBus,formatTimeHHmm,getOS,inArray,isEmpty,isNotEmpty};
|
|
1
|
+
function isEmpty(v){return null==v||""===v}function isNotEmpty(v){return!isEmpty(v)}function inArray(arr,key,val){for(let i=0;i<arr.length;i++)if(arr[i][key]===val)return i;return-1}function formatTimeHHmm(hours){const hour=Math.floor(hours),minute=Math.floor(60*(hours-hour));return console.log("H5环境"),`${hour}H:${minute}m`}function getOS(){const os=uni.getSystemInfoSync()?.osName;return{isIOS:"ios"==os,isAndroid:"android"==os}}function getPlatform(){return uni.getSystemInfoSync()?.uniPlatform||""}const eventBus={events:{},on(event,callback){this.events[event]||(this.events[event]=[]),this.events[event].push(callback)},off(event,callback){this.events[event]&&(callback?(this.events[event]=this.events[event].filter(cb=>cb!==callback),0===this.events[event].length&&delete this.events[event]):delete this.events[event])},emit(event,...args){this.events[event]&&this.events[event].forEach(callback=>callback(...args))}};export{eventBus,formatTimeHHmm,getOS,getPlatform,inArray,isEmpty,isNotEmpty};
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{chunk,unique}from"./core/array.js";export{connectAsync,createBLEConnection,disConnect,foundScanDevice,getBLEDeviceCharacteristics,getBLEDeviceServices,getBluetoothAdapterState,initBle,notify,onBLECharacteristicValueChange,onBLEConnectionStateChange,onBleChangedConnectionState,onBluetoothAdapterStateChange,onBluetoothDeviceFound,onFoundDevice,scanHandle,startDevicesDiscovery,stopBluetoothDevicesDiscovery}from"./core/BleApiManager.js";export{eventBus,formatTimeHHmm,getOS,inArray,isEmpty,isNotEmpty}from"./core/commonfun.js";export{ALLOWED_MAC_PREFIX,APP_KEY_STATUS,extractModuleInfo,getRandomNum,getTypeBuyCmd,handleNewAppKey,handleOldAppKey,sendAppKey,sendEnableOrVerifyKey,sendOldAppKey,sendVerifyPwd,sendWrite1LevelPwd,verify3LevelPassword,verifyMacAddrAndKey}from"./core/keyAndPwdManager.js";export{OTAUpgrade}from"./core/OtaUpgrade.js";export{TelinkApi}from"./core/TelinkApi.js";export{BLE,Logger,Observer,Transfer}from"./core/Transfer.js";export{ab2decimalArr,ab2hex,arrayBufferToHexArray,base64ToHexArray,checkSum,crc16modbus,crcCheckSum,decimalToHex,decimalToHex0x,decimalToTwoByteHexArray,extractBits,generateCheckSum,generateCrc16modbusCheck,generateCrcCheckSum,getParamBaseValue,hex2Ascii,hex2Binary,hex2string,hexArr2Assic,hexArr2ab,hexArr2string,hexArrayToModuleArrayBuffer,hexStrAscii,hexStringToBinary,hexToDecimal,sleep,string2hexArr,stringToTwoHexArray}from"./core/BleDataProcess.js";export{getData,setMTUAsync}from"./core/BleCmdAnalysis/BleCmdAnalysis.js";export{clearPrimaryKey,getBluetoothName,getBroadcastDataCmd,getFFAA03Async,getFFAA17Async,getFFAA25Async,getFFAA26Async,getFFAA80Async,getFFAAKeyAsync,getWiFiIP,resetFactoryData,resetSecondaryKey,resolveFFAA25,resolveFFAA26,resolveFFAA80,resolveFFAAKey,setBluetoothName,setWiFi,setWiFiSta,set_PlanCMD_FFAA,set_PlanCMD_FFAA80}from"./core/BleCmdAnalysis/BleCmdFFAA.js";export{enterFactory,existFactory,get3B3CAsync,get3B3CInfo,getChipTypeAsync,getDD5A0AAsync,getDD5A0EAsync,getDD5A17Async,getDD5AAllAsync,getDD5AE0Async,getDD5AE1Async,getDD5AE4Async,getDD5AFAAsync,getDD5AFBAsync,getDDA503Async,getDDA504Async,getDDA505Async,getDDA507Async,getDDA508Async,getDDA5FAAsync,getDDA5OldAsync,getProtectCountCmd,readExistFactory,resolve3B3C,resolveBMSCmd,resolveBaseDD,resolveDDA500,resolveDDA503,resolveDDA504,resolveDDA505,resolveDDA508,resolveDDA5FA,resolveProtections,sendBMSAsync,setDDA5FAAsync,setDDA5OldAsync,set_PlanCMD_3B3C,set_PlanCMD_DD}from"./core/BleCmdAnalysis/BleCmdDD.js";export{getSysParamCmd,readParamCmd,setCapacityParamCmd,setParamCmd,setSysParamCmd}from"./core/BleCmdAnalysis/readAndSetParam.js";export{getBaseInfo,getBaseParams,getResistance}from"./core/BleCmdAnalysis/BaseParamProtocol.js";export{getCMDESInfoAsync,getHVESInfoAsync,resolveHVESBMUInfo,resolveHVESBaseInfo,resolveHVESCalibrationC1Info,resolveHVESCalibrationC2Info,resolveHVESCalibrationConfigInfo,resolveHVESCalibrationInfo,resolveHVESCtInfo,resolveHVESDisCtInfo,resolveHVESElectrodeHTInfo,resolveHVESEtInfo,resolveHVESInsulationLRInfo,resolveHVESLSocInfo,resolveHVESMonoVolInfo,resolveHVESOeInfo,resolveHVESOtRisingInfo,resolveHVESOtrInfo,resolveHVESOvrInfo,resolveHVESPackInfo,resolveHVESParamsInfo,resolveHVESSumInfo,resolveHVESSumVolInfo,resolveHVESVersionInfo}from"./core/BleCmdAnalysis/BleCmdHVES.js";export{HostProtocol}from"./core/BleCmdAnalysis/ESHostProtocol.js";export{batteryInfoJson,capInfoJson,capVolInfoJson,currentInfoJson,equalizerFunJson,funcAndTempFuncJson,funcJson,systemJson,tempFuncJson,tempInfoJson,voltageInfoJson}from"./core/dataJson/baseParamsJson.js";
|
|
1
|
+
export{chunk,unique}from"./core/array.js";export{connectAsync,createBLEConnection,disConnect,foundScanDevice,getBLEDeviceCharacteristics,getBLEDeviceServices,getBluetoothAdapterState,initBle,notify,onBLECharacteristicValueChange,onBLEConnectionStateChange,onBleChangedConnectionState,onBluetoothAdapterStateChange,onBluetoothDeviceFound,onFoundDevice,scanHandle,startDevicesDiscovery,stopBluetoothDevicesDiscovery}from"./core/BleApiManager.js";export{eventBus,formatTimeHHmm,getOS,getPlatform,inArray,isEmpty,isNotEmpty}from"./core/commonfun.js";export{ALLOWED_MAC_PREFIX,APP_KEY_STATUS,extractModuleInfo,getRandomNum,getTypeBuyCmd,handleNewAppKey,handleOldAppKey,sendAppKey,sendEnableOrVerifyKey,sendOldAppKey,sendVerifyPwd,sendWrite1LevelPwd,verify3LevelPassword,verifyMacAddrAndKey}from"./core/keyAndPwdManager.js";export{OTAUpgrade}from"./core/OtaUpgrade.js";export{TelinkApi}from"./core/TelinkApi.js";export{BLE,Logger,Observer,Transfer}from"./core/Transfer.js";export{ab2decimalArr,ab2hex,arrayBufferToHexArray,base64ToHexArray,checkSum,crc16modbus,crcCheckSum,decimalToHex,decimalToHex0x,decimalToTwoByteHexArray,extractBits,generateCheckSum,generateCrc16modbusCheck,generateCrcCheckSum,getParamBaseValue,hex2Ascii,hex2Binary,hex2string,hexArr2Assic,hexArr2ab,hexArr2string,hexArrayToModuleArrayBuffer,hexStrAscii,hexStringToBinary,hexToDecimal,sleep,string2hexArr,stringToTwoHexArray}from"./core/BleDataProcess.js";export{getData,setMTUAsync}from"./core/BleCmdAnalysis/BleCmdAnalysis.js";export{clearPrimaryKey,getBluetoothName,getBroadcastDataCmd,getFFAA03Async,getFFAA17Async,getFFAA25Async,getFFAA26Async,getFFAA80Async,getFFAAKeyAsync,getWiFiIP,resetFactoryData,resetSecondaryKey,resolveFFAA25,resolveFFAA26,resolveFFAA80,resolveFFAAKey,setBluetoothName,setWiFi,setWiFiSta,set_PlanCMD_FFAA,set_PlanCMD_FFAA80}from"./core/BleCmdAnalysis/BleCmdFFAA.js";export{activateAsync,enterFactory,existFactory,get3B3CAsync,get3B3CInfo,getChipTypeAsync,getDD5A0AAsync,getDD5A0EAsync,getDD5A17Async,getDD5AAllAsync,getDD5AE0Async,getDD5AE1Async,getDD5AE4Async,getDD5AFAAsync,getDD5AFBAsync,getDDA503Async,getDDA504Async,getDDA505Async,getDDA507Async,getDDA508Async,getDDA5DCAsync,getDDA5FAAsync,getDDA5OldAsync,getProtectCountCmd,readExistFactory,resetCapacity,resolve3B3C,resolveBMSCmd,resolveBaseDD,resolveDD5A0A,resolveDDA500,resolveDDA503,resolveDDA504,resolveDDA505,resolveDDA508,resolveDDA5DC,resolveDDA5FA,resolveProtections,sendBMSAsync,setDDA5FAAsync,setDDA5OldAsync,set_PlanCMD_3B3C,set_PlanCMD_DD}from"./core/BleCmdAnalysis/BleCmdDD.js";export{getSysParamCmd,readParamCmd,setCapacityParamCmd,setParamCmd,setSysParamCmd}from"./core/BleCmdAnalysis/readAndSetParam.js";export{getBaseInfo,getBaseParams,getResistance}from"./core/BleCmdAnalysis/BaseParamProtocol.js";export{getCMDESInfoAsync,getHVESInfoAsync,resolveHVESBMUInfo,resolveHVESBaseInfo,resolveHVESCalibrationC1Info,resolveHVESCalibrationC2Info,resolveHVESCalibrationConfigInfo,resolveHVESCalibrationInfo,resolveHVESCtInfo,resolveHVESDisCtInfo,resolveHVESElectrodeHTInfo,resolveHVESEtInfo,resolveHVESInsulationLRInfo,resolveHVESLSocInfo,resolveHVESMonoVolInfo,resolveHVESOeInfo,resolveHVESOtRisingInfo,resolveHVESOtrInfo,resolveHVESOvrInfo,resolveHVESPackInfo,resolveHVESParamsInfo,resolveHVESSumInfo,resolveHVESSumVolInfo,resolveHVESVersionInfo}from"./core/BleCmdAnalysis/BleCmdHVES.js";export{HostProtocol}from"./core/BleCmdAnalysis/ESHostProtocol.js";export{batteryInfoJson,capInfoJson,capVolInfoJson,currentInfoJson,equalizerFunJson,funcAndTempFuncJson,funcJson,systemJson,tempFuncJson,tempInfoJson,voltageInfoJson}from"./core/dataJson/baseParamsJson.js";
|