@jiabaida/tools 1.1.3 → 1.1.4
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/BleCmdAnalysis/BaseParamProtocol.js +1 -1
- package/dist/cjs/core/BleCmdAnalysis/BleCmdDD.js +1 -1
- package/dist/cjs/core/TelinkApi.js +1 -1
- package/dist/cjs/core/dataJson/baseParamsJson.js +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/esm/core/BleCmdAnalysis/BaseParamProtocol.js +1 -1
- package/dist/esm/core/BleCmdAnalysis/BleCmdDD.js +1 -1
- package/dist/esm/core/TelinkApi.js +1 -1
- package/dist/esm/core/dataJson/baseParamsJson.js +1 -1
- package/dist/esm/index.js +1 -1
- package/package.json +1 -1
- package/src/core/BleApiManager.js +2 -2
- package/src/core/BleCmdAnalysis/BaseParamProtocol.js +4 -2
- package/src/core/BleCmdAnalysis/BleCmdDD.js +48 -11
- package/src/core/TelinkApi.js +1 -2
- package/src/core/dataJson/baseParamsJson.js +13 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var BleDataProcess=require("../BleDataProcess.js"),baseParamsJson=require("../dataJson/baseParamsJson.js"),BleCmdDD=require("./BleCmdDD.js"),readAndSetParam=require("./readAndSetParam.js");function format(value,n=1,offset=0,scope=0){if(!value)return null;value=value.map(el=>{const hexValue=BleDataProcess.decimalToHex(el);return console.log("el: ------------",hexValue),hexValue});const v=parseInt(value.join(""),16)*n+offset;if(null==scope)return v;const formatted=v.toFixed(scope);return Number(formatted)}function formatTemp(arr){if(!arr)return null;let string="0x"+toHexString(arr),value=parseInt(string,16);return value=(value-2731)/10,Number(value)}function formatBinary(arr){if(!arr)return null;return arr.map(num=>num.toString(2).padStart(8,"0")).join("").split("").map(Number).reverse()}const sendCmdSeq=async(datasInfo,chipType,deviceId,params)=>{if(datasInfo&&deviceId&&Array.isArray(params)){chipType||await BleCmdDD.enterFactory(deviceId);for(const item of params)if(item?.key)try{const baseData=await readAndSetParam.getSysParamCmd(chipType,deviceId,item,!1);datasInfo[item.key]=baseData}catch(err){console.error(`获取参数失败 [${item.key}]:`,err)}chipType||await BleCmdDD.readExistFactory(deviceId)}else console.error("sendCmdSeq 参数异常")};let crsDivisor=.1;const getBaseInfo=async datas=>{try{console.log("datas: ",datas);const barCode=getCharCodeConnect(datas?.barCode),manufacturer=getCharCodeConnect(datas?.manufacturer),model=getCharCodeConnect(datas?.model),bmsModel=getCharCodeConnect(datas?.bmsModel,!0),producedDate=function(content){if(!content)return null;let arr=content.splice(0,2),string="0x";return arr.forEach(el=>{string+=BleDataProcess.decimalToHex(el)}),console.log(string,"string日期"),`${2e3+(string>>9)}-${string>>5&15}-${31&string}`}(datas?.producedDate);return{barCode:barCode,manufacturer:manufacturer,model:model,bmsModel:bmsModel,producedDate:producedDate,bmsAddr:function(content){if(!content)return null;return console.log(content,"content======"),toHexString(content.splice(0,12))}(datas?.bmsAddr)}}catch(error){console.error("error: ",error)}},getCharCodeConnect=(content,clearZero=!1)=>{if(console.log("content: ---------------",content),!content)return null;const length=content[0];let arr=content.splice(1,length);if(clearZero)for(;0===arr[arr.length-1];)arr.pop();return console.log("arr: -------------------",arr),String.fromCharCode(...arr)};function toHexString(arr){let string="";return arr.forEach(el=>{string+=BleDataProcess.decimalToHex(el)}),string}const getCapInfo=async datas=>{console.log("datas: ",datas);let normCap=null;if(datas.normCap&&datas.normCap.length>=4){console.log("normCap原始数据: ",datas.normCap);const lowBytes=datas.normCap.slice(0,2),lowValue=lowBytes[0]<<8|lowBytes[1];console.log("normCap lowValue: ",lowValue);const highBytes=datas.normCap.slice(2,4),highValue=highBytes[0]<<8|highBytes[1];console.log("normCap highValue: ",highValue);const totalValue=highValue<<16|lowValue;console.log("normCap totalValue: ",totalValue),normCap=Number((.01*totalValue).toFixed(2)),console.log("normCap最终值: ",normCap)}else if(datas.normCap&&datas.normCap.length>=2){const lowBytes=datas.normCap.slice(0,2),lowValue=lowBytes[0]<<8|lowBytes[1];normCap=Number((.01*lowValue).toFixed(2))}const cycleCap=format(datas.cycleCap,.01,0,2);let fullCap=null;if(datas.fullCap&&datas.fullCap.length>=4){console.log("fullCap原始数据: ",datas.fullCap);const lowBytes=datas.fullCap.slice(0,2),lowValue=lowBytes[0]<<8|lowBytes[1];console.log("fullCap lowValue: ",lowValue);const highBytes=datas.fullCap.slice(2,4),highValue=highBytes[0]<<8|highBytes[1];console.log("fullCap highValue: ",highValue);const totalValue=highValue<<16|lowValue;console.log("fullCap totalValue: ",totalValue),fullCap=Number((.01*totalValue).toFixed(2)),console.log("fullCap最终值: ",fullCap)}else if(datas.fullCap&&datas.fullCap.length>=2){const lowBytes=datas.fullCap.slice(0,2),lowValue=lowBytes[0]<<8|lowBytes[1];fullCap=Number((.01*lowValue).toFixed(2))}return{normCap:normCap,cycleCap:cycleCap,fullCap:fullCap}},getVoltageInfo=async(datas,chipType)=>{console.log("datas: ",datas);const allOvervoltageProtect=format(datas.allOvervoltageProtect,.01,0,3),allOverpressureRecovery=format(datas.allOverpressureRecovery,.01,0,3),allLowvoltageProtect=format(datas.allLowvoltageProtect,.01,0,3),allLowvoltageRecover=format(datas.allLowvoltageRecover,.01,0,3),singleOvervoltageProtect=format(datas.singleOvervoltageProtect,.001,0,3),singleOverpressureRecovery=format(datas.singleOverpressureRecovery,.001,0,3),singleLowvoltageProtect=format(datas.singleLowvoltageProtect,.001,0,3),singleLowvoltageRecover=format(datas.singleLowvoltageRecover,.001,0,3),hardwareOV=format(datas.hardwareOV,.001,0,3),hardwareUV=format(datas.hardwareUV,.001,0,3);let singleOverpressureDelay=null,singleLowvoltageDelayed=null,allLowvoltageDelay=null,allOverpressureDelay=null;return chipType?(singleOverpressureDelay=format(datas.singleOverpressureDelay,1),singleLowvoltageDelayed=format(datas.singleLowvoltageDelayed,1),allLowvoltageDelay=format(datas.allLowvoltageDelay,1),allOverpressureDelay=format(datas.allOverpressureDelay,1)):(singleLowvoltageDelayed=datas.singleLowvoltageDelayed[0],singleOverpressureDelay=datas.singleLowvoltageDelayed[1],allLowvoltageDelay=datas.allLowvoltageDelay[0],allOverpressureDelay=datas.allLowvoltageDelay[1]),{allOvervoltageProtect:allOvervoltageProtect,allOverpressureRecovery:allOverpressureRecovery,allLowvoltageProtect:allLowvoltageProtect,allLowvoltageRecover:allLowvoltageRecover,singleOvervoltageProtect:singleOvervoltageProtect,singleOverpressureRecovery:singleOverpressureRecovery,singleLowvoltageProtect:singleLowvoltageProtect,singleLowvoltageRecover:singleLowvoltageRecover,singleOverpressureDelay:singleOverpressureDelay,singleLowvoltageDelayed:singleLowvoltageDelayed,hardwareOV:hardwareOV,hardwareUV:hardwareUV,allLowvoltageDelay:allLowvoltageDelay,allOverpressureDelay:allOverpressureDelay}},getCurrentInfo=async(datas,chipType)=>{console.log("datas: ",datas);const occhg=format(datas.occhg,.01,0,3),dischargeOvercurrentProtect=(datas.dischargeOvercurrentProtect||0==datas.dischargeOvercurrentProtect)&&Number((.01*(format(datas.dischargeOvercurrentProtect,1,0,3)-65536)).toFixed(3));let chargeOvercurrentDelay=null,chargeOvercurrentRecoverDelay=null,dischargeOvercurrentDelay=null,dischargeOvercurrentRecoverDelay=null,shortcircuiProtectRecoverDelay=null,leve2OvercurrentDelay=0,level2OvercurrentProtect=0,shortcircuiProtect=0,shortcircuiProtectDelay=0,level2OvercurrentProtectV=null,overAndUnderDelay=0;return chipType?(chargeOvercurrentDelay=format(datas.chargeOvercurrentDelay,1),chargeOvercurrentRecoverDelay=format(datas.chargeOvercurrentRecoverDelay,1),dischargeOvercurrentDelay=format(datas.dischargeOvercurrentDelay,1),dischargeOvercurrentRecoverDelay=format(datas.dischargeOvercurrentRecoverDelay,1),shortcircuiProtectRecoverDelay=format(datas.shortcircuiProtectRecoverDelay,1),level2OvercurrentProtect=getNewProtectAndDelay(datas.level2OvercurrentProtect).value1,leve2OvercurrentDelay=getNewProtectAndDelay(datas.level2OvercurrentProtect).value2,shortcircuiProtect=getNewProtectAndDelay(datas.level2OvercurrentProtectV).value1,shortcircuiProtectDelay=getNewProtectAndDelay(datas.level2OvercurrentProtectV).value2):(chargeOvercurrentDelay=datas.chargeOvercurrentDelay[0],chargeOvercurrentRecoverDelay=datas.chargeOvercurrentDelay[1],dischargeOvercurrentDelay=datas.dischargeOvercurrentDelay[0],dischargeOvercurrentRecoverDelay=datas.dischargeOvercurrentDelay[1],overAndUnderDelay=datas.shortcircuiProtectRecoverDelay[0],shortcircuiProtectRecoverDelay=datas.shortcircuiProtectRecoverDelay[1],level2OvercurrentProtectV=getOldProtectAndDelay(datas.level2OvercurrentProtect).double,shortcircuiProtect=getOldProtectAndDelay(datas.level2OvercurrentProtect).value1,shortcircuiProtectDelay=getOldProtectAndDelay(datas.level2OvercurrentProtect).value2,level2OvercurrentProtect=getOldProtectAndDelay(datas.level2OvercurrentProtect).value3,leve2OvercurrentDelay=getOldProtectAndDelay(datas.level2OvercurrentProtect).value4),{occhg:occhg,dischargeOvercurrentProtect:dischargeOvercurrentProtect,chargeOvercurrentDelay:chargeOvercurrentDelay,chargeOvercurrentRecoverDelay:chargeOvercurrentRecoverDelay,dischargeOvercurrentDelay:dischargeOvercurrentDelay,dischargeOvercurrentRecoverDelay:dischargeOvercurrentRecoverDelay,leve2OvercurrentDelay:leve2OvercurrentDelay,level2OvercurrentProtectV:level2OvercurrentProtectV,shortcircuiProtectRecoverDelay:shortcircuiProtectRecoverDelay,shortcircuiProtect:shortcircuiProtect,shortcircuiProtectDelay:shortcircuiProtectDelay,level2OvercurrentProtect:level2OvercurrentProtect,overAndUnderDelay:overAndUnderDelay}};function getNewProtectAndDelay(arr){if(2!==arr?.length)return{value1:0,value2:0};let resultArray=arr.map(num=>num.toString(2).padStart(8,"0")).join("").split("").map(Number),arr1=resultArray.slice(8,12),arr2=resultArray.slice(12);return{value1:parseInt(arr1.join(""),2),value2:parseInt(arr2.join(""),2)}}function getOldProtectAndDelay(arr){if(2!==arr?.length)return{double:!1,value1:0,value2:0,value3:0,value4:0};const binaryString=arr.map(num=>num.toString(2).padStart(8,"0")).join("");console.log("【解析硬件过流及短路】",binaryString);const resultArray=binaryString.split("").map(Number),arr1=[0,...resultArray.slice(5,8)],arr2=resultArray.slice(1,5),arr3=resultArray.slice(12),arr4=resultArray.slice(8,12),value1=parseInt(arr1.join(""),2),value2=parseInt(arr2.join(""),2),value3=parseInt(arr3.join(""),2),value4=parseInt(arr4.join(""),2);return{double:1===resultArray[0],value1:value1,value2:value2,value3:value3,value4:value4}}const getTempInfo=(datas,chipType)=>{console.log("datas: ",datas);const chargeHightempProtect=formatTemp(datas.chargeHightempProtect),chargeHightempRecover=formatTemp(datas.chargeHightempRecover),chargeLowtempProtect=formatTemp(datas.chargeLowtempProtect),chargeLowtempRecover=formatTemp(datas.chargeLowtempRecover),dischargingHightempProtect=formatTemp(datas.dischargingHightempProtect),dischargingHightempRecover=formatTemp(datas.dischargingHightempRecover),dischargingLowtempProtect=formatTemp(datas.dischargingLowtempProtect),dischargingLowtempRecover=formatTemp(datas.dischargingLowtempRecover),overtempProtect=formatTemp(datas.overtempProtect),overtempRecover=formatTemp(datas.overtempRecover);let chargeHightempDelay=null,chargeLowtempDelay=null,dischargingHightempDelay=null,dischargingLowtempDelay=null;return chipType?(chargeHightempDelay=format(datas.chargeHightempDelay,1),chargeLowtempDelay=format(datas.chargeLowtempDelay,1),dischargingHightempDelay=format(datas.dischargingHightempDelay,1),dischargingLowtempDelay=format(datas.dischargingLowtempDelay,1)):(chargeHightempDelay=datas.chargeLowtempDelay[1],chargeLowtempDelay=datas.chargeLowtempDelay[0],dischargingHightempDelay=datas.dischargingLowtempDelay[1],dischargingLowtempDelay=datas.dischargingLowtempDelay[0]),{chargeHightempProtect:chargeHightempProtect,chargeHightempRecover:chargeHightempRecover,chargeLowtempProtect:chargeLowtempProtect,chargeLowtempRecover:chargeLowtempRecover,dischargingHightempProtect:dischargingHightempProtect,dischargingHightempRecover:dischargingHightempRecover,dischargingLowtempProtect:dischargingLowtempProtect,dischargingLowtempRecover:dischargingLowtempRecover,chargeHightempDelay:chargeHightempDelay,chargeLowtempDelay:chargeLowtempDelay,dischargingHightempDelay:dischargingHightempDelay,dischargingLowtempDelay:dischargingLowtempDelay,overtempProtect:overtempProtect,overtempRecover:overtempRecover}},getEqualizerFunInfo=datas=>({equalizingVoltage:format(datas.equalizingVoltage,.001,0,3),accuracyEqualization:format(datas.accuracyEqualization,1,0,2)}),getcapVolInfoInfo=datas=>({fullVolt:format(datas.fullVolt,.001,0,3),emptyVolt:format(datas.emptyVolt,.001,0,3),voltage10p:format(datas.voltage10p,.001,0,3),voltage20p:format(datas.voltage20p,.001,0,3),voltage30p:format(datas.voltage30p,.001,0,3),voltage40p:format(datas.voltage40p,.001,0,3),voltage50p:format(datas.voltage50p,.001,0,3),voltage60p:format(datas.voltage60p,.001,0,3),voltage70p:format(datas.voltage70p,.001,0,3),voltage80p:format(datas.voltage80p,.001,0,3),voltage90p:format(datas.voltage90p,.001,0,3),voltage100p:format(datas.voltage100p,.001,0,3)}),getFuncAndTempFuncInfo=datas=>{const binaryFuncArr=formatBinary(datas.func),binaryTempArr=formatBinary(datas.tempFunc),func={};baseParamsJson.funcJson.forEach((item,index)=>{item.key&&(func[item.key]=binaryFuncArr[index])});const tempFunc={};return baseParamsJson.tempFuncJson.forEach((item,index)=>{item.key&&(tempFunc[item.key]=binaryTempArr[index])}),{func:func,tempFunc:tempFunc}},splitNumberTo1Byte=(combined=0)=>({val1:255&(combined=Number(combined)),val2:combined>>8&255}),getSystemInfo=datas=>{const serialNumber=format(datas.serialNumber,1),cycleCount=format(datas.cycleCount,1),strCount=format(datas.strCount,1),rsnsValue=format(datas.rsnsValue,crsDivisor,0,2),param1911=splitNumberTo1Byte(format(datas.param1911)).val1,param1912=splitNumberTo1Byte(format(datas.param1911)).val2,param1981=splitNumberTo1Byte(format(datas.param1981)).val1,param1982=splitNumberTo1Byte(format(datas.param1981)).val2;return{serialNumber:serialNumber,cycleCount:cycleCount,strCount:strCount,rsnsValue:rsnsValue,param1911:param1911,param1912:param1912,param1951:splitNumberTo1Byte(format(datas.param1951)).val1,param1952:splitNumberTo1Byte(format(datas.param1951)).val2,param1981:param1981,param1982:param1982}};exports.getBaseInfo=getBaseInfo,exports.getBaseParams=async(chipType,deviceData,index,paramObj)=>{console.log("chipType: ",chipType);const deviceId=deviceData?.deviceId,protocolVersion=deviceData?.protocolVersion||"00";console.warn("protocolVersion: ",protocolVersion);const v=BleDataProcess.hexToDecimal(protocolVersion);(2==v||v>=20&&v<80)&&(crsDivisor=.01),console.log("v: ",v);try{let dataInfo={};switch(index){case 1:let datasInfo1={};return await sendCmdSeq(datasInfo1,chipType,deviceId,baseParamsJson.batteryInfoJson(crsDivisor)),dataInfo=getBaseInfo(datasInfo1),dataInfo;case 2:let datasInfo2={};const productType=deviceData.productType,isBalanceDevice="12"===productType;if(console.log("productType",productType,isBalanceDevice),chipType)if(isBalanceDevice){const normCapLow=await readAndSetParam.getSysParamCmd(chipType,deviceId,{paramNo:0,paramLength:2}),normCapHigh=await readAndSetParam.getSysParamCmd(chipType,deviceId,{paramNo:155,paramLength:2});console.log("normCapLow: ",normCapLow,"normCapHigh: ",normCapHigh),datasInfo2.normCap=[...normCapLow?.slice(0,2)||[],...normCapHigh?.slice(0,2)||[]];const cycleCapData=await readAndSetParam.getSysParamCmd(chipType,deviceId,baseParamsJson.capInfoJson[1]);datasInfo2.cycleCap=cycleCapData?.slice(0,2);const fullCapLow=await readAndSetParam.getSysParamCmd(chipType,deviceId,{paramNo:112,paramLength:2}),fullCapHigh=await readAndSetParam.getSysParamCmd(chipType,deviceId,{paramNo:156,paramLength:2});console.log("fullCapLow: ",fullCapLow,"fullCapHigh: ",fullCapHigh),datasInfo2.fullCap=[...fullCapLow?.slice(0,2)||[],...fullCapHigh?.slice(0,2)||[]]}else{const capData=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.capInfoJson[0],paramLength:4});console.warn("capData: ",capData),datasInfo2.normCap=capData?.slice(0,2),datasInfo2.cycleCap=capData?.slice(2,4);const capData2=await readAndSetParam.getSysParamCmd(chipType,deviceId,baseParamsJson.capInfoJson[2]);datasInfo2.fullCap=capData2?.slice(0,2)}else await sendCmdSeq(datasInfo2,chipType,deviceId,baseParamsJson.capInfoJson);return dataInfo=getCapInfo(datasInfo2),dataInfo;case 3:let datasInfo3={};if(chipType){let vindex=baseParamsJson.voltageInfoJson.findIndex(el=>16==el.paramNo);console.log("vindex: ------------",vindex);let vindex1=baseParamsJson.voltageInfoJson.findIndex(el=>48==el.paramNo),vindex2=baseParamsJson.voltageInfoJson.findIndex(el=>38==el.paramNo);const voltageData=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.voltageInfoJson[vindex],paramLength:16}),voltageData1=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.voltageInfoJson[vindex1],paramLength:8}),voltageData2=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.voltageInfoJson[vindex2],paramLength:4});console.log("voltageData: ",voltageData),datasInfo3.allOvervoltageProtect=voltageData?.slice(0,2),datasInfo3.allOverpressureRecovery=voltageData?.slice(2,4),datasInfo3.allLowvoltageProtect=voltageData?.slice(4,6),datasInfo3.allLowvoltageRecover=voltageData?.slice(6,8),datasInfo3.singleOvervoltageProtect=voltageData?.slice(8,10),datasInfo3.singleOverpressureRecovery=voltageData?.slice(10,12),datasInfo3.singleLowvoltageProtect=voltageData?.slice(12,14),datasInfo3.singleLowvoltageRecover=voltageData?.slice(14,16),datasInfo3.allLowvoltageDelay=voltageData1?.slice(0,2),datasInfo3.allOverpressureDelay=voltageData1?.slice(2,4),datasInfo3.singleLowvoltageDelayed=voltageData1?.slice(4,6),datasInfo3.singleOverpressureDelay=voltageData1?.slice(6,8),datasInfo3.hardwareOV=voltageData2?.slice(0,2),datasInfo3.hardwareUV=voltageData2?.slice(2,4)}else await sendCmdSeq(datasInfo3,chipType,deviceId,baseParamsJson.voltageInfoJson);return dataInfo=getVoltageInfo(datasInfo3,chipType),dataInfo;case 4:let datasInfo4={};if(chipType){let cindex=baseParamsJson.currentInfoJson.findIndex(el=>24==el.paramNo),cindex1=baseParamsJson.currentInfoJson.findIndex(el=>52==el.paramNo),cindex2=baseParamsJson.currentInfoJson.findIndex(el=>40==el.paramNo);const currentData=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.currentInfoJson[cindex],paramLength:4}),currentData1=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.currentInfoJson[cindex1],paramLength:8}),currentData2=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.currentInfoJson[cindex2],paramLength:8});console.log("currentData: ",currentData),datasInfo4.occhg=currentData?.slice(0,2),datasInfo4.dischargeOvercurrentProtect=currentData?.slice(2,4),datasInfo4.chargeOvercurrentDelay=currentData1?.slice(0,2),datasInfo4.chargeOvercurrentRecoverDelay=currentData1?.slice(2,4),datasInfo4.dischargeOvercurrentDelay=currentData1?.slice(4,6),datasInfo4.dischargeOvercurrentRecoverDelay=currentData1?.slice(6,8),datasInfo4.level2OvercurrentProtect=currentData2?.slice(0,2),datasInfo4.level2OvercurrentProtectV=currentData2?.slice(2,4),datasInfo4.shortcircuiProtectRecoverDelay=currentData2?.slice(6,8)}else await sendCmdSeq(datasInfo4,chipType,deviceId,baseParamsJson.currentInfoJson);return dataInfo=getCurrentInfo(datasInfo4,chipType),dataInfo;case 5:let datasInfo5={};if(chipType){let tindex=baseParamsJson.tempInfoJson.findIndex(el=>8==el.paramNo),tindex1=baseParamsJson.tempInfoJson.findIndex(el=>44==el.paramNo),tindex2=baseParamsJson.tempInfoJson.findIndex(el=>202==el.paramNo);const tempData=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.tempInfoJson[tindex],paramLength:16}),tempData1=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.tempInfoJson[tindex1],paramLength:8}),tempData2=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.tempInfoJson[tindex2],paramLength:4});console.log("tempData: ",tempData,tempData2),datasInfo5.chargeHightempProtect=tempData?.slice(0,2),datasInfo5.chargeHightempRecover=tempData?.slice(2,4),datasInfo5.chargeLowtempProtect=tempData?.slice(4,6),datasInfo5.chargeLowtempRecover=tempData?.slice(6,8),datasInfo5.dischargingHightempProtect=tempData?.slice(8,10),datasInfo5.dischargingHightempRecover=tempData?.slice(10,12),datasInfo5.dischargingLowtempProtect=tempData?.slice(12,14),datasInfo5.dischargingLowtempRecover=tempData?.slice(14,16),datasInfo5.chargeLowtempDelay=tempData1?.slice(0,2),datasInfo5.chargeHightempDelay=tempData1?.slice(2,4),datasInfo5.dischargingLowtempDelay=tempData1?.slice(4,6),datasInfo5.dischargingHightempDelay=tempData1?.slice(6,8),datasInfo5.overtempProtect=tempData2?.slice(0,2),datasInfo5.overtempRecover=tempData2?.slice(2,4)}else await sendCmdSeq(datasInfo5,chipType,deviceId,baseParamsJson.tempInfoJson);return dataInfo=getTempInfo(datasInfo5,chipType),dataInfo;case 6:let datasInfo6={};if(chipType){const equalizerFunData=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.equalizerFunJson[0],paramLength:4});console.log("equalizerFunData: ",equalizerFunData),datasInfo6.equalizingVoltage=equalizerFunData?.slice(0,2),datasInfo6.accuracyEqualization=equalizerFunData?.slice(2,4)}else await sendCmdSeq(datasInfo6,chipType,deviceId,baseParamsJson.equalizerFunJson);return dataInfo=getEqualizerFunInfo(datasInfo6),dataInfo;case 7:let datasInfo7={};if(chipType){let capVolIndex=baseParamsJson.capVolInfoJson.findIndex(el=>34==el.paramNo),capVolIndex1=baseParamsJson.capVolInfoJson.findIndex(el=>106==el.paramNo);const capVolInfoData=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.capVolInfoJson[0],paramLength:4}),capVolInfoData1=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.capVolInfoJson[capVolIndex],paramLength:8}),capVolInfoData2=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.capVolInfoJson[capVolIndex1],paramLength:12});console.log("capVolInfoData: ",capVolInfoData),datasInfo7.fullVolt=capVolInfoData?.slice(0,2),datasInfo7.emptyVolt=capVolInfoData?.slice(2,4),datasInfo7.voltage80p=capVolInfoData1?.slice(0,2),datasInfo7.voltage60p=capVolInfoData1?.slice(2,4),datasInfo7.voltage40p=capVolInfoData1?.slice(4,6),datasInfo7.voltage20p=capVolInfoData1?.slice(6,8),datasInfo7.voltage90p=capVolInfoData2?.slice(0,2),datasInfo7.voltage70p=capVolInfoData2?.slice(2,4),datasInfo7.voltage50p=capVolInfoData2?.slice(4,6),datasInfo7.voltage30p=capVolInfoData2?.slice(6,8),datasInfo7.voltage10p=capVolInfoData2?.slice(8,10),datasInfo7.voltage100p=capVolInfoData2?.slice(10,12)}else await sendCmdSeq(datasInfo7,chipType,deviceId,baseParamsJson.capVolInfoJson);return dataInfo=getcapVolInfoInfo(datasInfo7,chipType),dataInfo;case 9:let datasInfo9={};if(chipType){const funcAndTempFuncData=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.funcAndTempFuncJson[0],paramLength:4});console.log("funcAndTempFuncData: ",funcAndTempFuncData),datasInfo9.func=funcAndTempFuncData?.slice(0,2),datasInfo9.tempFunc=funcAndTempFuncData?.slice(2,4)}else await sendCmdSeq(datasInfo9,chipType,deviceId,baseParamsJson.funcAndTempFuncJson);return dataInfo=getFuncAndTempFuncInfo(datasInfo9),dataInfo;case 10:let datasInfo10={};return await sendCmdSeq(datasInfo10,chipType,deviceId,baseParamsJson.systemJson),dataInfo=getSystemInfo(datasInfo10),dataInfo;case 11:const counts=await BleCmdDD.getProtectCountCmd(deviceId);return console.log("counts: ",counts),counts;default:if(!paramObj)return null;let defaultDataInfo={};const onedata=await readAndSetParam.getSysParamCmd(chipType,deviceId,paramObj);return defaultDataInfo[paramObj.key]=onedata?.slice(0,2),defaultDataInfo}}catch(error){throw console.error("error: 读系统参数报错 getBaseParams",error),error}},exports.getResistance=async(chipType,deviceId)=>{try{const rsnsValue=await readAndSetParam.getSysParamCmd(chipType,deviceId,baseParamsJson.systemJson[2]);return format(rsnsValue,crsDivisor,0,2)}catch(error){throw console.error("error: 读检流阻值报错 getResistance",error),error}};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var BleDataProcess=require("../BleDataProcess.js"),baseParamsJson=require("../dataJson/baseParamsJson.js"),BleCmdDD=require("./BleCmdDD.js"),readAndSetParam=require("./readAndSetParam.js");function format(value,n=1,offset=0,scope=0){if(!value)return null;value=value.map(el=>{const hexValue=BleDataProcess.decimalToHex(el);return console.log("el: ------------",hexValue),hexValue});const v=parseInt(value.join(""),16)*n+offset;if(null==scope)return v;const formatted=v.toFixed(scope);return Number(formatted)}function formatTemp(arr){if(!arr)return null;let string="0x"+toHexString(arr),value=parseInt(string,16);return value=(value-2731)/10,Number(value)}function formatBinary(arr){if(!arr)return null;return arr.map(num=>num.toString(2).padStart(8,"0")).join("").split("").map(Number).reverse()}const sendCmdSeq=async(datasInfo,chipType,deviceId,params)=>{if(datasInfo&&deviceId&&Array.isArray(params)){chipType||await BleCmdDD.enterFactory(deviceId);for(const item of params)if(item?.key)try{const baseData=await readAndSetParam.getSysParamCmd(chipType,deviceId,item,!1);datasInfo[item.key]=baseData}catch(err){console.error(`获取参数失败 [${item.key}]:`,err)}chipType||await BleCmdDD.readExistFactory(deviceId)}else console.error("sendCmdSeq 参数异常")};let crsDivisor=.1;const getBaseInfo=async datas=>{try{console.log("datas: ",datas);const barCode=getCharCodeConnect(datas?.barCode),manufacturer=getCharCodeConnect(datas?.manufacturer),model=getCharCodeConnect(datas?.model),bmsModel=getCharCodeConnect(datas?.bmsModel,!0),producedDate=function(content){if(!content)return null;let arr=content.splice(0,2),string="0x";return arr.forEach(el=>{string+=BleDataProcess.decimalToHex(el)}),console.log(string,"string日期"),`${2e3+(string>>9)}-${string>>5&15}-${31&string}`}(datas?.producedDate);return{barCode:barCode,manufacturer:manufacturer,model:model,bmsModel:bmsModel,producedDate:producedDate,bmsAddr:function(content){if(!content)return null;return console.log(content,"content======"),toHexString(content.splice(0,12))}(datas?.bmsAddr)}}catch(error){console.error("error: ",error)}},getCharCodeConnect=(content,clearZero=!1)=>{if(console.log("content: ---------------",content),!content)return null;const length=content[0];let arr=content.splice(1,length);if(clearZero)for(;0===arr[arr.length-1];)arr.pop();return console.log("arr: -------------------",arr),String.fromCharCode(...arr)};function toHexString(arr){let string="";return arr.forEach(el=>{string+=BleDataProcess.decimalToHex(el)}),string}const getCapInfo=async datas=>{console.log("datas: ",datas);let normCap=null;if(datas.normCap&&datas.normCap.length>=4){console.log("normCap原始数据: ",datas.normCap);const lowBytes=datas.normCap.slice(0,2),lowValue=lowBytes[0]<<8|lowBytes[1];console.log("normCap lowValue: ",lowValue);const highBytes=datas.normCap.slice(2,4),highValue=highBytes[0]<<8|highBytes[1];console.log("normCap highValue: ",highValue);const totalValue=highValue<<16|lowValue;console.log("normCap totalValue: ",totalValue),normCap=Number((.01*totalValue).toFixed(2)),console.log("normCap最终值: ",normCap)}else if(datas.normCap&&datas.normCap.length>=2){const lowBytes=datas.normCap.slice(0,2),lowValue=lowBytes[0]<<8|lowBytes[1];normCap=Number((.01*lowValue).toFixed(2))}const cycleCap=format(datas.cycleCap,.01,0,2);let fullCap=null;if(datas.fullCap&&datas.fullCap.length>=4){console.log("fullCap原始数据: ",datas.fullCap);const lowBytes=datas.fullCap.slice(0,2),lowValue=lowBytes[0]<<8|lowBytes[1];console.log("fullCap lowValue: ",lowValue);const highBytes=datas.fullCap.slice(2,4),highValue=highBytes[0]<<8|highBytes[1];console.log("fullCap highValue: ",highValue);const totalValue=highValue<<16|lowValue;console.log("fullCap totalValue: ",totalValue),fullCap=Number((.01*totalValue).toFixed(2)),console.log("fullCap最终值: ",fullCap)}else if(datas.fullCap&&datas.fullCap.length>=2){const lowBytes=datas.fullCap.slice(0,2),lowValue=lowBytes[0]<<8|lowBytes[1];fullCap=Number((.01*lowValue).toFixed(2))}return{normCap:normCap,cycleCap:cycleCap,fullCap:fullCap}},getVoltageInfo=async(datas,chipType)=>{console.log("datas: ",datas);const allOvervoltageProtect=format(datas.allOvervoltageProtect,.01,0,3),allOverpressureRecovery=format(datas.allOverpressureRecovery,.01,0,3),allLowvoltageProtect=format(datas.allLowvoltageProtect,.01,0,3),allLowvoltageRecover=format(datas.allLowvoltageRecover,.01,0,3),singleOvervoltageProtect=format(datas.singleOvervoltageProtect,.001,0,3),singleOverpressureRecovery=format(datas.singleOverpressureRecovery,.001,0,3),singleLowvoltageProtect=format(datas.singleLowvoltageProtect,.001,0,3),singleLowvoltageRecover=format(datas.singleLowvoltageRecover,.001,0,3),hardwareOV=format(datas.hardwareOV,.001,0,3),hardwareUV=format(datas.hardwareUV,.001,0,3);let singleOverpressureDelay=null,singleLowvoltageDelayed=null,allLowvoltageDelay=null,allOverpressureDelay=null;return chipType?(singleOverpressureDelay=format(datas.singleOverpressureDelay,1),singleLowvoltageDelayed=format(datas.singleLowvoltageDelayed,1),allLowvoltageDelay=format(datas.allLowvoltageDelay,1),allOverpressureDelay=format(datas.allOverpressureDelay,1)):(singleLowvoltageDelayed=datas.singleLowvoltageDelayed[0],singleOverpressureDelay=datas.singleLowvoltageDelayed[1],allLowvoltageDelay=datas.allLowvoltageDelay[0],allOverpressureDelay=datas.allLowvoltageDelay[1]),{allOvervoltageProtect:allOvervoltageProtect,allOverpressureRecovery:allOverpressureRecovery,allLowvoltageProtect:allLowvoltageProtect,allLowvoltageRecover:allLowvoltageRecover,singleOvervoltageProtect:singleOvervoltageProtect,singleOverpressureRecovery:singleOverpressureRecovery,singleLowvoltageProtect:singleLowvoltageProtect,singleLowvoltageRecover:singleLowvoltageRecover,singleOverpressureDelay:singleOverpressureDelay,singleLowvoltageDelayed:singleLowvoltageDelayed,hardwareOV:hardwareOV,hardwareUV:hardwareUV,allLowvoltageDelay:allLowvoltageDelay,allOverpressureDelay:allOverpressureDelay}},getCurrentInfo=async(datas,chipType)=>{console.log("datas: ",datas);const occhg=format(datas.occhg,.01,0,3),dischargeOvercurrentProtect=(datas.dischargeOvercurrentProtect||0==datas.dischargeOvercurrentProtect)&&Number((.01*(format(datas.dischargeOvercurrentProtect,1,0,3)-65536)).toFixed(3));let chargeOvercurrentDelay=null,chargeOvercurrentRecoverDelay=null,dischargeOvercurrentDelay=null,dischargeOvercurrentRecoverDelay=null,shortcircuiProtectRecoverDelay=null,leve2OvercurrentDelay=0,level2OvercurrentProtect=0,shortcircuiProtect=0,shortcircuiProtectDelay=0,level2OvercurrentProtectV=null,overAndUnderDelay=0;return chipType?(chargeOvercurrentDelay=format(datas.chargeOvercurrentDelay,1),chargeOvercurrentRecoverDelay=format(datas.chargeOvercurrentRecoverDelay,1),dischargeOvercurrentDelay=format(datas.dischargeOvercurrentDelay,1),dischargeOvercurrentRecoverDelay=format(datas.dischargeOvercurrentRecoverDelay,1),shortcircuiProtectRecoverDelay=format(datas.shortcircuiProtectRecoverDelay,1),level2OvercurrentProtect=getNewProtectAndDelay(datas.level2OvercurrentProtect).value1,leve2OvercurrentDelay=getNewProtectAndDelay(datas.level2OvercurrentProtect).value2,shortcircuiProtect=getNewProtectAndDelay(datas.level2OvercurrentProtectV).value1,shortcircuiProtectDelay=getNewProtectAndDelay(datas.level2OvercurrentProtectV).value2):(chargeOvercurrentDelay=datas.chargeOvercurrentDelay[0],chargeOvercurrentRecoverDelay=datas.chargeOvercurrentDelay[1],dischargeOvercurrentDelay=datas.dischargeOvercurrentDelay[0],dischargeOvercurrentRecoverDelay=datas.dischargeOvercurrentDelay[1],overAndUnderDelay=datas.shortcircuiProtectRecoverDelay[0],shortcircuiProtectRecoverDelay=datas.shortcircuiProtectRecoverDelay[1],level2OvercurrentProtectV=getOldProtectAndDelay(datas.level2OvercurrentProtect).double,shortcircuiProtect=getOldProtectAndDelay(datas.level2OvercurrentProtect).value1,shortcircuiProtectDelay=getOldProtectAndDelay(datas.level2OvercurrentProtect).value2,level2OvercurrentProtect=getOldProtectAndDelay(datas.level2OvercurrentProtect).value3,leve2OvercurrentDelay=getOldProtectAndDelay(datas.level2OvercurrentProtect).value4),{occhg:occhg,dischargeOvercurrentProtect:dischargeOvercurrentProtect,chargeOvercurrentDelay:chargeOvercurrentDelay,chargeOvercurrentRecoverDelay:chargeOvercurrentRecoverDelay,dischargeOvercurrentDelay:dischargeOvercurrentDelay,dischargeOvercurrentRecoverDelay:dischargeOvercurrentRecoverDelay,leve2OvercurrentDelay:leve2OvercurrentDelay,level2OvercurrentProtectV:level2OvercurrentProtectV,shortcircuiProtectRecoverDelay:shortcircuiProtectRecoverDelay,shortcircuiProtect:shortcircuiProtect,shortcircuiProtectDelay:shortcircuiProtectDelay,level2OvercurrentProtect:level2OvercurrentProtect,overAndUnderDelay:overAndUnderDelay}};function getNewProtectAndDelay(arr){if(2!==arr?.length)return{value1:0,value2:0};let resultArray=arr.map(num=>num.toString(2).padStart(8,"0")).join("").split("").map(Number),arr1=resultArray.slice(8,12),arr2=resultArray.slice(12);return{value1:parseInt(arr1.join(""),2),value2:parseInt(arr2.join(""),2)}}function getOldProtectAndDelay(arr){if(2!==arr?.length)return{double:!1,value1:0,value2:0,value3:0,value4:0};const binaryString=arr.map(num=>num.toString(2).padStart(8,"0")).join("");console.log("【解析硬件过流及短路】",binaryString);const resultArray=binaryString.split("").map(Number),arr1=[0,...resultArray.slice(5,8)],arr2=resultArray.slice(1,5),arr3=resultArray.slice(12),arr4=resultArray.slice(8,12),value1=parseInt(arr1.join(""),2),value2=parseInt(arr2.join(""),2),value3=parseInt(arr3.join(""),2),value4=parseInt(arr4.join(""),2);return{double:1===resultArray[0],value1:value1,value2:value2,value3:value3,value4:value4}}const getTempInfo=(datas,chipType)=>{console.log("datas: ",datas);const chargeHightempProtect=formatTemp(datas.chargeHightempProtect),chargeHightempRecover=formatTemp(datas.chargeHightempRecover),chargeLowtempProtect=formatTemp(datas.chargeLowtempProtect),chargeLowtempRecover=formatTemp(datas.chargeLowtempRecover),dischargingHightempProtect=formatTemp(datas.dischargingHightempProtect),dischargingHightempRecover=formatTemp(datas.dischargingHightempRecover),dischargingLowtempProtect=formatTemp(datas.dischargingLowtempProtect),dischargingLowtempRecover=formatTemp(datas.dischargingLowtempRecover),overtempProtect=formatTemp(datas.overtempProtect),overtempRecover=formatTemp(datas.overtempRecover);let chargeHightempDelay=null,chargeLowtempDelay=null,dischargingHightempDelay=null,dischargingLowtempDelay=null;return chipType?(chargeHightempDelay=format(datas.chargeHightempDelay,1),chargeLowtempDelay=format(datas.chargeLowtempDelay,1),dischargingHightempDelay=format(datas.dischargingHightempDelay,1),dischargingLowtempDelay=format(datas.dischargingLowtempDelay,1)):(chargeHightempDelay=datas.chargeLowtempDelay[1],chargeLowtempDelay=datas.chargeLowtempDelay[0],dischargingHightempDelay=datas.dischargingLowtempDelay[1],dischargingLowtempDelay=datas.dischargingLowtempDelay[0]),{chargeHightempProtect:chargeHightempProtect,chargeHightempRecover:chargeHightempRecover,chargeLowtempProtect:chargeLowtempProtect,chargeLowtempRecover:chargeLowtempRecover,dischargingHightempProtect:dischargingHightempProtect,dischargingHightempRecover:dischargingHightempRecover,dischargingLowtempProtect:dischargingLowtempProtect,dischargingLowtempRecover:dischargingLowtempRecover,chargeHightempDelay:chargeHightempDelay,chargeLowtempDelay:chargeLowtempDelay,dischargingHightempDelay:dischargingHightempDelay,dischargingLowtempDelay:dischargingLowtempDelay,overtempProtect:overtempProtect,overtempRecover:overtempRecover}},getEqualizerFunInfo=datas=>({equalizingVoltage:format(datas.equalizingVoltage,.001,0,3),accuracyEqualization:format(datas.accuracyEqualization,1,0,2)}),getcapVolInfoInfo=datas=>({fullVolt:format(datas.fullVolt,.001,0,3),emptyVolt:format(datas.emptyVolt,.001,0,3),voltage10p:format(datas.voltage10p,.001,0,3),voltage20p:format(datas.voltage20p,.001,0,3),voltage30p:format(datas.voltage30p,.001,0,3),voltage40p:format(datas.voltage40p,.001,0,3),voltage50p:format(datas.voltage50p,.001,0,3),voltage60p:format(datas.voltage60p,.001,0,3),voltage70p:format(datas.voltage70p,.001,0,3),voltage80p:format(datas.voltage80p,.001,0,3),voltage90p:format(datas.voltage90p,.001,0,3),voltage100p:format(datas.voltage100p,.001,0,3)}),getFuncAndTempFuncInfo=datas=>{const binaryFuncArr=formatBinary(datas.func),binaryTempArr=formatBinary(datas.tempFunc),func={};baseParamsJson.funcJson.forEach((item,index)=>{item.key&&(func[item.key]=binaryFuncArr[index])});const tempFunc={};return baseParamsJson.tempFuncJson.forEach((item,index)=>{item.key&&(tempFunc[item.key]=binaryTempArr[index])}),{func:func,tempFunc:tempFunc}},splitNumberTo1Byte=(combined=0)=>({val1:255&(combined=Number(combined)),val2:combined>>8&255}),getSystemInfo=datas=>{const serialNumber=format(datas.serialNumber,1),cycleCount=format(datas.cycleCount,1),strCount=format(datas.strCount,1),rsnsValue=format(datas.rsnsValue,crsDivisor,0,2),forceUseTime=format(datas.forceUseTime,1),param1911=splitNumberTo1Byte(format(datas.param1911)).val1,param1912=splitNumberTo1Byte(format(datas.param1911)).val2,param1981=splitNumberTo1Byte(format(datas.param1981)).val1,param1982=splitNumberTo1Byte(format(datas.param1981)).val2;return{serialNumber:serialNumber,cycleCount:cycleCount,strCount:strCount,rsnsValue:rsnsValue,forceUseTime:forceUseTime,param1911:param1911,param1912:param1912,param1951:splitNumberTo1Byte(format(datas.param1951)).val1,param1952:splitNumberTo1Byte(format(datas.param1951)).val2,param1981:param1981,param1982:param1982}};exports.getBaseInfo=getBaseInfo,exports.getBaseParams=async(chipType,deviceData,index,paramObj)=>{console.log("chipType: ",chipType);const deviceId=deviceData?.deviceId,protocolVersion=deviceData?.protocolVersion||"00";console.warn("protocolVersion: ",protocolVersion);const v=BleDataProcess.hexToDecimal(protocolVersion);(2==v||v>=20&&v<80)&&(crsDivisor=.01),console.log("v: ",v);try{let dataInfo={};switch(index){case 1:let datasInfo1={};return await sendCmdSeq(datasInfo1,chipType,deviceId,baseParamsJson.batteryInfoJson(crsDivisor)),dataInfo=getBaseInfo(datasInfo1),dataInfo;case 2:let datasInfo2={};const productType=deviceData.productType,isBalanceDevice="12"===productType;if(console.log("productType",productType,isBalanceDevice),chipType)if(isBalanceDevice){const normCapLow=await readAndSetParam.getSysParamCmd(chipType,deviceId,{paramNo:0,paramLength:2}),normCapHigh=await readAndSetParam.getSysParamCmd(chipType,deviceId,{paramNo:155,paramLength:2});console.log("normCapLow: ",normCapLow,"normCapHigh: ",normCapHigh),datasInfo2.normCap=[...normCapLow?.slice(0,2)||[],...normCapHigh?.slice(0,2)||[]];const cycleCapData=await readAndSetParam.getSysParamCmd(chipType,deviceId,baseParamsJson.capInfoJson[1]);datasInfo2.cycleCap=cycleCapData?.slice(0,2);const fullCapLow=await readAndSetParam.getSysParamCmd(chipType,deviceId,{paramNo:112,paramLength:2}),fullCapHigh=await readAndSetParam.getSysParamCmd(chipType,deviceId,{paramNo:156,paramLength:2});console.log("fullCapLow: ",fullCapLow,"fullCapHigh: ",fullCapHigh),datasInfo2.fullCap=[...fullCapLow?.slice(0,2)||[],...fullCapHigh?.slice(0,2)||[]]}else{const capData=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.capInfoJson[0],paramLength:4});console.warn("capData: ",capData),datasInfo2.normCap=capData?.slice(0,2),datasInfo2.cycleCap=capData?.slice(2,4);const capData2=await readAndSetParam.getSysParamCmd(chipType,deviceId,baseParamsJson.capInfoJson[2]);datasInfo2.fullCap=capData2?.slice(0,2)}else await sendCmdSeq(datasInfo2,chipType,deviceId,baseParamsJson.capInfoJson);return dataInfo=getCapInfo(datasInfo2),dataInfo;case 3:let datasInfo3={};if(chipType){let vindex=baseParamsJson.voltageInfoJson.findIndex(el=>16==el.paramNo);console.log("vindex: ------------",vindex);let vindex1=baseParamsJson.voltageInfoJson.findIndex(el=>48==el.paramNo),vindex2=baseParamsJson.voltageInfoJson.findIndex(el=>38==el.paramNo);const voltageData=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.voltageInfoJson[vindex],paramLength:16}),voltageData1=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.voltageInfoJson[vindex1],paramLength:8}),voltageData2=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.voltageInfoJson[vindex2],paramLength:4});console.log("voltageData: ",voltageData),datasInfo3.allOvervoltageProtect=voltageData?.slice(0,2),datasInfo3.allOverpressureRecovery=voltageData?.slice(2,4),datasInfo3.allLowvoltageProtect=voltageData?.slice(4,6),datasInfo3.allLowvoltageRecover=voltageData?.slice(6,8),datasInfo3.singleOvervoltageProtect=voltageData?.slice(8,10),datasInfo3.singleOverpressureRecovery=voltageData?.slice(10,12),datasInfo3.singleLowvoltageProtect=voltageData?.slice(12,14),datasInfo3.singleLowvoltageRecover=voltageData?.slice(14,16),datasInfo3.allLowvoltageDelay=voltageData1?.slice(0,2),datasInfo3.allOverpressureDelay=voltageData1?.slice(2,4),datasInfo3.singleLowvoltageDelayed=voltageData1?.slice(4,6),datasInfo3.singleOverpressureDelay=voltageData1?.slice(6,8),datasInfo3.hardwareOV=voltageData2?.slice(0,2),datasInfo3.hardwareUV=voltageData2?.slice(2,4)}else await sendCmdSeq(datasInfo3,chipType,deviceId,baseParamsJson.voltageInfoJson);return dataInfo=getVoltageInfo(datasInfo3,chipType),dataInfo;case 4:let datasInfo4={};if(chipType){let cindex=baseParamsJson.currentInfoJson.findIndex(el=>24==el.paramNo),cindex1=baseParamsJson.currentInfoJson.findIndex(el=>52==el.paramNo),cindex2=baseParamsJson.currentInfoJson.findIndex(el=>40==el.paramNo);const currentData=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.currentInfoJson[cindex],paramLength:4}),currentData1=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.currentInfoJson[cindex1],paramLength:8}),currentData2=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.currentInfoJson[cindex2],paramLength:8});console.log("currentData: ",currentData),datasInfo4.occhg=currentData?.slice(0,2),datasInfo4.dischargeOvercurrentProtect=currentData?.slice(2,4),datasInfo4.chargeOvercurrentDelay=currentData1?.slice(0,2),datasInfo4.chargeOvercurrentRecoverDelay=currentData1?.slice(2,4),datasInfo4.dischargeOvercurrentDelay=currentData1?.slice(4,6),datasInfo4.dischargeOvercurrentRecoverDelay=currentData1?.slice(6,8),datasInfo4.level2OvercurrentProtect=currentData2?.slice(0,2),datasInfo4.level2OvercurrentProtectV=currentData2?.slice(2,4),datasInfo4.shortcircuiProtectRecoverDelay=currentData2?.slice(6,8)}else await sendCmdSeq(datasInfo4,chipType,deviceId,baseParamsJson.currentInfoJson);return dataInfo=getCurrentInfo(datasInfo4,chipType),dataInfo;case 5:let datasInfo5={};if(chipType){let tindex=baseParamsJson.tempInfoJson.findIndex(el=>8==el.paramNo),tindex1=baseParamsJson.tempInfoJson.findIndex(el=>44==el.paramNo),tindex2=baseParamsJson.tempInfoJson.findIndex(el=>202==el.paramNo);const tempData=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.tempInfoJson[tindex],paramLength:16}),tempData1=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.tempInfoJson[tindex1],paramLength:8}),tempData2=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.tempInfoJson[tindex2],paramLength:4});console.log("tempData: ",tempData,tempData2),datasInfo5.chargeHightempProtect=tempData?.slice(0,2),datasInfo5.chargeHightempRecover=tempData?.slice(2,4),datasInfo5.chargeLowtempProtect=tempData?.slice(4,6),datasInfo5.chargeLowtempRecover=tempData?.slice(6,8),datasInfo5.dischargingHightempProtect=tempData?.slice(8,10),datasInfo5.dischargingHightempRecover=tempData?.slice(10,12),datasInfo5.dischargingLowtempProtect=tempData?.slice(12,14),datasInfo5.dischargingLowtempRecover=tempData?.slice(14,16),datasInfo5.chargeLowtempDelay=tempData1?.slice(0,2),datasInfo5.chargeHightempDelay=tempData1?.slice(2,4),datasInfo5.dischargingLowtempDelay=tempData1?.slice(4,6),datasInfo5.dischargingHightempDelay=tempData1?.slice(6,8),datasInfo5.overtempProtect=tempData2?.slice(0,2),datasInfo5.overtempRecover=tempData2?.slice(2,4)}else await sendCmdSeq(datasInfo5,chipType,deviceId,baseParamsJson.tempInfoJson);return dataInfo=getTempInfo(datasInfo5,chipType),dataInfo;case 6:let datasInfo6={};if(chipType){const equalizerFunData=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.equalizerFunJson[0],paramLength:4});console.log("equalizerFunData: ",equalizerFunData),datasInfo6.equalizingVoltage=equalizerFunData?.slice(0,2),datasInfo6.accuracyEqualization=equalizerFunData?.slice(2,4)}else await sendCmdSeq(datasInfo6,chipType,deviceId,baseParamsJson.equalizerFunJson);return dataInfo=getEqualizerFunInfo(datasInfo6),dataInfo;case 7:let datasInfo7={};if(chipType){let capVolIndex=baseParamsJson.capVolInfoJson.findIndex(el=>34==el.paramNo),capVolIndex1=baseParamsJson.capVolInfoJson.findIndex(el=>106==el.paramNo);const capVolInfoData=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.capVolInfoJson[0],paramLength:4}),capVolInfoData1=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.capVolInfoJson[capVolIndex],paramLength:8}),capVolInfoData2=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.capVolInfoJson[capVolIndex1],paramLength:12});console.log("capVolInfoData: ",capVolInfoData),datasInfo7.fullVolt=capVolInfoData?.slice(0,2),datasInfo7.emptyVolt=capVolInfoData?.slice(2,4),datasInfo7.voltage80p=capVolInfoData1?.slice(0,2),datasInfo7.voltage60p=capVolInfoData1?.slice(2,4),datasInfo7.voltage40p=capVolInfoData1?.slice(4,6),datasInfo7.voltage20p=capVolInfoData1?.slice(6,8),datasInfo7.voltage90p=capVolInfoData2?.slice(0,2),datasInfo7.voltage70p=capVolInfoData2?.slice(2,4),datasInfo7.voltage50p=capVolInfoData2?.slice(4,6),datasInfo7.voltage30p=capVolInfoData2?.slice(6,8),datasInfo7.voltage10p=capVolInfoData2?.slice(8,10),datasInfo7.voltage100p=capVolInfoData2?.slice(10,12)}else await sendCmdSeq(datasInfo7,chipType,deviceId,baseParamsJson.capVolInfoJson);return dataInfo=getcapVolInfoInfo(datasInfo7,chipType),dataInfo;case 9:let datasInfo9={};if(chipType){const funcAndTempFuncData=await readAndSetParam.getSysParamCmd(chipType,deviceId,{...baseParamsJson.funcAndTempFuncJson[0],paramLength:4});console.log("funcAndTempFuncData: ",funcAndTempFuncData),datasInfo9.func=funcAndTempFuncData?.slice(0,2),datasInfo9.tempFunc=funcAndTempFuncData?.slice(2,4)}else await sendCmdSeq(datasInfo9,chipType,deviceId,baseParamsJson.funcAndTempFuncJson);return dataInfo=getFuncAndTempFuncInfo(datasInfo9),dataInfo;case 10:let datasInfo10={};return await sendCmdSeq(datasInfo10,chipType,deviceId,baseParamsJson.systemJson),dataInfo=getSystemInfo(datasInfo10),dataInfo;case 11:const counts=await BleCmdDD.getProtectCountCmd(deviceId);return console.log("counts: ",counts),counts;default:if(!paramObj)return null;let defaultDataInfo={};const onedata=await readAndSetParam.getSysParamCmd(chipType,deviceId,paramObj);return defaultDataInfo[paramObj.key]=onedata?.slice(0,2),defaultDataInfo}}catch(error){throw console.error("error: 读系统参数报错 getBaseParams",error),error}},exports.getResistance=async(chipType,deviceId)=>{try{const rsnsValue=await readAndSetParam.getSysParamCmd(chipType,deviceId,baseParamsJson.systemJson[2]);return format(rsnsValue,crsDivisor,0,2)}catch(error){throw console.error("error: 读检流阻值报错 getResistance",error),error}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var BleDataProcess=require("../BleDataProcess.js"),BleCmdAnalysis=require("./BleCmdAnalysis.js"),BleCmdFFAA=require("./BleCmdFFAA.js"),readAndSetParam=require("./readAndSetParam.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;){if(content.length<2){console.warn("Content too short to parse, remaining:",content);break}const len=Math.min(content[1]+2,content.length),[v1,v2,...v]=content.splice(0,len);if(v.length===v2){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))}else console.warn(`Data length mismatch for type ${v1}: expected ${v2}, got ${v.length}`)}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(),BC1=(data[16]<<8|data[17]).toString(2).padStart(16,"0").split("").reverse();console.log("BC1: ",BC1);const BC2=(data[18]<<8|data[19]).toString(2).padStart(16,"0").split("").reverse(),balances=BC1.concat(BC2);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})),hasProtocol=data[3]+7>=humidityIndex+11+3+1,protocolVersion=data[humidityIndex+11];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,hasProtocol:hasProtocol,protocolVersion:protocolVersion}},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=>{try{const startTime=+new Date;let acStatus=!1;const mosRes=await readAndSetParam.controlSwitch(deviceId,"0x00",!0,!0),disChargMOSRes=mosRes?.dataStr,disChargEndTime=+new Date,activeHex=await getDD5AFBAsync(deviceId,"0x05","0x01"),activeResult=resolveBaseDD(activeHex);console.log("激活指令结果: ",{activeHex:activeHex,activeResult:activeResult});const activeRes=activeResult?.dataStr;let endTime=+new Date,baseInfo=null,voltageInfo=null,steps=[];if("00"==activeResult?.status)steps.push(4),acStatus=!0;else if("81"==activeResult?.status||"84"==activeResult?.status)"00"==mosRes?.status?(acStatus=!0,steps.push(5)):(acStatus=!1,steps.push(10));else if("82"==activeResult?.status||"83"==activeResult?.status)acStatus=!1,steps.push(6);else if(!activeResult||null==activeResult){await BleDataProcess.sleep(300);const baseInfo=await getDDA503Async(deviceId);baseInfo?.dischargeSwitch?(acStatus=!0,steps.push(7)):(acStatus=!1,steps.push(8)),endTime=+new Date}return{disChargMOSRes:disChargMOSRes,activeHex:activeHex,activeRes:activeRes,baseInfo:baseInfo,voltageInfo:voltageInfo,startTime:startTime,disChargEndTime:disChargEndTime,endTime:endTime,acStatus:acStatus,steps:steps}}catch(error){return console.log("🚀 ~ BleApiManager ~ activateAsync ~ error:",error),null}},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;try{if(!deviceId)throw new Error("deviceId required");const _ffaa_80=await BleCmdFFAA.getFFAA80Async(deviceId,"AT^VERSION?");console.warn("Report-3B3C _ffaa_80 ",{_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,reportData.bmsVersion=_3b3c?.sofewareV;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.getDDA4F0Async=async deviceId=>{const command=["0xDD","0xA4","0xF0","0x00"],checks=BleDataProcess.generateCrcCheckSum(command.slice(2)),fullCommand=[...command,...checks,"0x77"];return BleCmdAnalysis.getData(deviceId,{command:fullCommand,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&240==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}}},"DDA4_F0")},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.getDDA506Async=async deviceId=>BleCmdAnalysis.getData(deviceId,{command:["0xdd","0xa5","0x06","0x00","0xff","0xfa","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&6==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_06"),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.decimalToHex0x(_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.resolveDDA4F0=data=>{if(!data)return null;if(240==data[1]&&4==data[3]){const runTime=data[4]<<24|data[5]<<16|data[6]<<8|data[7];return{runTime:runTime,runTimeHour:(runTime/3600).toFixed(2),raw:BleDataProcess.hexArr2string(data)}}return null},exports.resolveDDA500=resolveDDA500,exports.resolveDDA503=resolveDDA503,exports.resolveDDA504=resolveDDA504,exports.resolveDDA505=resolveDDA505,exports.resolveDDA506=data=>{if(!data)return null;if(6==data[1]&&0==data[2]&&6==data[3]){const seconds=BleDataProcess.fromBCD(data[4]),minutes=BleDataProcess.fromBCD(data[5]),hours=BleDataProcess.fromBCD(data[6]),day=BleDataProcess.fromBCD(data[7]),month=BleDataProcess.fromBCD(data[8]),timeStr=`${2e3+BleDataProcess.fromBCD(data[9])}-${String(month).padStart(2,0)}-${String(day).padStart(2,0)} ${String(hours).padStart(2,0)}:${String(minutes).padStart(2,0)}:${String(seconds).padStart(2,0)}`;return console.log("timeStr: ",timeStr,BleDataProcess.isWithin30Minutes(timeStr)),BleDataProcess.isWithin30Minutes(timeStr)}return!1},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.setDD5AE3sync=async deviceId=>{const now=new Date,year=now.getFullYear(),month=now.getMonth()+1,day=now.getDate(),hours=now.getHours(),minutes=now.getMinutes(),seconds=now.getSeconds(),content=["0xE3","0x07","0x06",...[BleDataProcess.toBCD(seconds),BleDataProcess.toBCD(minutes),128|BleDataProcess.toBCD(hours),BleDataProcess.toBCD(day),BleDataProcess.toBCD(month),BleDataProcess.toBCD(year-2e3)].map(b=>"0x"+b.toString(16).padStart(2,"0"))],checks=BleDataProcess.generateCrcCheckSum(content),command=["0xDD","0x5A",...content,...checks,"0x77"];return console.log("command: ",command),BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&227==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"SET_DDA5_E3")},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"),readAndSetParam=require("./readAndSetParam.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;){if(content.length<2){console.warn("Content too short to parse, remaining:",content);break}const len=Math.min(content[1]+2,content.length),[v1,v2,...v]=content.splice(0,len);if(v.length===v2){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))}else console.warn(`Data length mismatch for type ${v1}: expected ${v2}, got ${v.length}`)}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(),BC1=(data[16]<<8|data[17]).toString(2).padStart(16,"0").split("").reverse();console.log("BC1: ",BC1);const BC2=(data[18]<<8|data[19]).toString(2).padStart(16,"0").split("").reverse(),balances=BC1.concat(BC2);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})),hasProtocol=data[3]+7>=humidityIndex+11+3+1,protocolVersion=data[humidityIndex+11],dataUpdateTime=Date.now();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,hasProtocol:hasProtocol,protocolVersion:protocolVersion,dataUpdateTime:dataUpdateTime}},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=>{try{const startTime=+new Date;let acStatus=!1;const mosRes=await readAndSetParam.controlSwitch(deviceId,"0x00",!0,!0),disChargMOSRes=mosRes?.dataStr,disChargEndTime=+new Date,activeHex=await getDD5AFBAsync(deviceId,"0x05","0x01"),activeResult=resolveBaseDD(activeHex);console.log("激活指令结果: ",{activeHex:activeHex,activeResult:activeResult});const activeRes=activeResult?.dataStr;let endTime=+new Date,baseInfo=null,voltageInfo=null,steps=[];if("00"==activeResult?.status)steps.push(4),acStatus=!0;else if("81"==activeResult?.status||"84"==activeResult?.status)"00"==mosRes?.status?(acStatus=!0,steps.push(5)):(acStatus=!1,steps.push(10));else if("82"==activeResult?.status||"83"==activeResult?.status)acStatus=!1,steps.push(6);else if(!activeResult||null==activeResult){await BleDataProcess.sleep(300);const baseInfo=await getDDA503Async(deviceId);baseInfo?.dischargeSwitch?(acStatus=!0,steps.push(7)):(acStatus=!1,steps.push(8)),endTime=+new Date}return{disChargMOSRes:disChargMOSRes,activeHex:activeHex,activeRes:activeRes,baseInfo:baseInfo,voltageInfo:voltageInfo,startTime:startTime,disChargEndTime:disChargEndTime,endTime:endTime,acStatus:acStatus,steps:steps}}catch(error){return console.log("🚀 ~ BleApiManager ~ activateAsync ~ error:",error),null}},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_05=null;try{if(!deviceId)throw new Error("deviceId required");const _ffaa_80=await BleCmdFFAA.getFFAA80Async(deviceId,"AT^VERSION?");console.warn("Report-3B3C _ffaa_80 ",{_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,reportData.bmsVersion=_3b3c?.sofewareV;else{const _dda5_03=await getDDA503Async(deviceId);console.warn("Report-3B3C _dda5_03 ",{_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:null,_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.getDDA4F0Async=async deviceId=>{const command=["0xDD","0xA4","0xF0","0x00"],checks=BleDataProcess.generateCrcCheckSum(command.slice(2)),fullCommand=[...command,...checks,"0x77"];return BleCmdAnalysis.getData(deviceId,{command:fullCommand,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&240==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}}},"DDA4_F0")},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.getDDA506Async=async deviceId=>BleCmdAnalysis.getData(deviceId,{command:["0xdd","0xa5","0x06","0x00","0xff","0xfa","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&6==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_06"),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.decimalToHex0x(_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.resolveDDA4F0=data=>{if(!data)return null;if(240==data[1]&&4==data[3]){const runTime=data[4]<<24|data[5]<<16|data[6]<<8|data[7];return{runTime:runTime,runTimeHour:(runTime/3600).toFixed(2),raw:BleDataProcess.hexArr2string(data)}}return null},exports.resolveDDA500=resolveDDA500,exports.resolveDDA503=resolveDDA503,exports.resolveDDA504=resolveDDA504,exports.resolveDDA505=resolveDDA505,exports.resolveDDA506=(data,supportTimestamp=!1)=>{if(!data)return null;if(6!=data[1])return!1;if(supportTimestamp&&4==data[3]){const secondsSinceEpoch=(data[4]<<24|data[5]<<16|data[6]<<8|data[7])>>>0,bmsTimestampMs=1e3*secondsSinceEpoch,diff=Math.abs(Date.now()-bmsTimestampMs),thirtyMinutes=18e5,d=new Date(bmsTimestampMs),pad=n=>String(n).padStart(2,"0"),timeStr=`${d.getFullYear()}-${pad(d.getMonth()+1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;return console.log("BMS时间戳(秒):",secondsSinceEpoch,"系统时间:",timeStr,"误差(ms):",diff),{needCalibrate:diff>=thirtyMinutes,timeStr:timeStr}}if(6==data[3]){const seconds=BleDataProcess.fromBCD(data[4]),minutes=BleDataProcess.fromBCD(data[5]),hours=BleDataProcess.fromBCD(data[6]),day=BleDataProcess.fromBCD(data[7]),month=BleDataProcess.fromBCD(data[8]),timeStr=`${2e3+BleDataProcess.fromBCD(data[9])}-${String(month).padStart(2,"0")}-${String(day).padStart(2,"0")} ${String(hours).padStart(2,"0")}:${String(minutes).padStart(2,"0")}:${String(seconds).padStart(2,"0")}`;return console.log("timeStr: ",timeStr,BleDataProcess.isWithin30Minutes(timeStr)),{needCalibrate:!BleDataProcess.isWithin30Minutes(timeStr),timeStr:timeStr}}return!1},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.setDD5AE3TimestampSync=function(deviceId){const secondsSinceEpoch=Math.floor(Date.now()/1e3),content=["0xE3","0x04",`0x${(secondsSinceEpoch>>>24&255).toString(16).padStart(2,"0")}`,`0x${(secondsSinceEpoch>>>16&255).toString(16).padStart(2,"0")}`,`0x${(secondsSinceEpoch>>>8&255).toString(16).padStart(2,"0")}`,`0x${(255&secondsSinceEpoch).toString(16).padStart(2,"0")}`],checks=BleDataProcess.generateCrcCheckSum(content),command=["0xDD","0x5A",...content,...checks,"0x77"];return BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221===hexArr[0]&&227===hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:()=>({verified:!0})},"SET_DDA5_E3_TIMESTAMP")},exports.setDD5AE3sync=async deviceId=>{const now=new Date,year=now.getFullYear(),month=now.getMonth()+1,day=now.getDate(),hours=now.getHours(),minutes=now.getMinutes(),seconds=now.getSeconds(),content=["0xE3","0x07","0x06",...[BleDataProcess.toBCD(seconds),BleDataProcess.toBCD(minutes),128|BleDataProcess.toBCD(hours),BleDataProcess.toBCD(day),BleDataProcess.toBCD(month),BleDataProcess.toBCD(year-2e3)].map(b=>"0x"+b.toString(16).padStart(2,"0"))],checks=BleDataProcess.generateCrcCheckSum(content),command=["0xDD","0x5A",...content,...checks,"0x77"];return console.log("command: ",command),BleCmdAnalysis.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&227==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"SET_DDA5_E3")},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 BleCmdDD=require("./BleCmdAnalysis/BleCmdDD.js");exports.TelinkApi=class{static async checkOTAAvailable({deviceId:deviceId,macAddr:macAddr}){const prefix=macAddr.slice(0,8).toUpperCase();try{if("A5:C2:37"==prefix){const socRes=await BleCmdDD.getChipTypeAsync(deviceId);if(console.warn("芯片类型",socRes),socRes&&5==socRes?.type){const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var BleCmdDD=require("./BleCmdAnalysis/BleCmdDD.js");exports.TelinkApi=class{static async checkOTAAvailable({deviceId:deviceId,macAddr:macAddr}){const prefix=macAddr.slice(0,8).toUpperCase();try{if("A5:C2:37"==prefix){const socRes=await BleCmdDD.getChipTypeAsync(deviceId);if(console.warn("芯片类型",socRes),socRes&&5==socRes?.type){const versionRes=await BleCmdDD.getDDA503Async(deviceId);return console.warn("版本信息",versionRes),!0}}}catch(error){}return!1}static isTeLink({macAddr:macAddr=""}={macAddr:""}){const prefix1=macAddr.slice(0,2).toUpperCase(),prefix=macAddr.slice(0,8).toUpperCase();return"A5"==prefix1||"A4:C1:38"==prefix}static getIndexHexArr(i){return i.toString(16).padStart(4,"0").match(/(.{2})/g)?.reverse().map(o=>`0x${o.toUpperCase()}`)}static crc16modbus(data,swapNeed=!1){let crc=65535;for(let i=0;i<data.length;i++){crc^=data[i];for(let j=0;j<8;j++)1&crc?crc=crc>>1^40961:crc>>=1}return swapNeed&&(crc=(255&crc)<<8|crc>>8&255),65535&crc}static decimalToHex(decimal,padding=4){const hexDigits=[],hexMap={10:"A",11:"B",12:"C",13:"D",14:"E",15:"F"};for(;decimal>0;){const remainder=decimal%16;remainder>=10?hexDigits.unshift(hexMap[remainder]):hexDigits.unshift(`${remainder}`),decimal=Math.floor(decimal/16)}return hexDigits.join("").padStart(padding,"0")}static genCheck(data){const hex=this.crc16modbus(data,!0),hexStr=this.decimalToHex(hex);return[`0x${hexStr.slice(0,2)}`,`0x${hexStr.slice(2,4)}`]}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tempFuncJson=Array.from({length:8},(_,index)=>({name:""+(0===index?"保护板温度":`电池温度${index}`),value:"",newValue:"",checked:!1,unit:"",key:`tempera${index}`}));exports.batteryInfoJson=crsDivisor=>[{key:"barCode",paramNo:88,paramLength:32,oldParamNo:"0xA2"},{key:"manufacturer",paramNo:56,oldParamNo:"0xA0",paramLength:32},{key:"producedDate",paramNo:5,oldParamNo:"0x15",paramLength:2},{key:"model",paramNo:.1==crsDivisor?158:316,oldParamNo:"",paramLength:24},{key:"bmsModel",paramNo:.1==crsDivisor?176:72,oldParamNo:"",paramLength:.1==crsDivisor?16:32}],exports.capInfoJson=[{key:"normCap",paramNo:0,oldParamNo:"0x10",paramLength:2,divisor:10},{key:"cycleCap",paramNo:1,oldParamNo:"0x11",paramLength:2,divisor:10},{key:"fullCap",paramNo:112,oldParamNo:"",paramLength:2,divisor:10}],exports.capVolInfoJson=[{value:null,newValue:"",unit:"V",paramNo:2,oldParamNo:"0x12",paramLength:2,isHidden:!1,key:"fullVolt",divisor:1e3},{value:null,newValue:"",unit:"V",paramNo:3,oldParamNo:"0x13",paramLength:2,isHidden:!1,key:"emptyVolt",divisor:1e3},{name:"容量80%",value:"",newValue:"",unit:"V",paramNo:34,oldParamNo:"0x32",paramLength:2,key:"voltage80p",divisor:1e3},{name:"容量60%",value:"",newValue:"",unit:"V",paramNo:35,oldParamNo:"0x33",paramLength:2,key:"voltage60p",divisor:1e3},{name:"容量40%",value:"",newValue:"",unit:"V",paramNo:36,oldParamNo:"0x34",paramLength:2,key:"voltage40p",divisor:1e3},{name:"容量20%",value:"",newValue:"",unit:"V",paramNo:37,oldParamNo:"0x35",paramLength:2,key:"voltage20p",divisor:1e3},{name:"容量90%",value:"",newValue:"",unit:"V",paramNo:106,oldParamNo:"0x42",paramLength:2,key:"voltage90p",divisor:1e3},{name:"容量70%",value:"",newValue:"",unit:"V",paramNo:107,oldParamNo:"0x43",paramLength:2,key:"voltage70p",divisor:1e3},{name:"容量50%",value:"",newValue:"",unit:"V",paramNo:108,oldParamNo:"0x44",paramLength:2,key:"voltage50p",divisor:1e3},{name:"容量30%",value:"",newValue:"",unit:"V",paramNo:109,oldParamNo:"0x45",paramLength:2,key:"voltage30p",divisor:1e3},{name:"容量10%",value:"",newValue:"",unit:"V",paramNo:110,oldParamNo:"0x46",paramLength:2,key:"voltage10p",divisor:1e3},{name:"容量100%",value:"",newValue:"",unit:"V",paramNo:111,oldParamNo:"0x47",paramLength:2,key:"voltage100p",divisor:1e3}],exports.currentInfoJson=[{value:"",newValue:"",unit:"A",paramNo:24,oldParamNo:"0x28",paramLength:2,key:"occhg",divisor:100},{value:"",newValue:"",unit:"A",paramNo:25,oldParamNo:"0x29",paramLength:2,key:"dischargeOvercurrentProtect",divisor:1e3},{value:"",newValue:"",unit:"S",paramNo:52,oldParamNo:"0x3E",paramLength:2,key:"chargeOvercurrentDelay",divisor:1},{value:"",newValue:"",unit:"S",paramNo:53,oldParamNo:"",paramLength:2,key:"chargeOvercurrentRecoverDelay",divisor:1},{value:"",newValue:"",unit:"S",paramNo:54,oldParamNo:"0x3F",paramLength:2,key:"dischargeOvercurrentDelay",divisor:1},{value:"",newValue:"",unit:"S",paramNo:55,oldParamNo:"",paramLength:2,key:"dischargeOvercurrentRecoverDelay",divisor:1},{value:null,newValue:"",unit:"(mV)",paramNo2:"1012",paramNo:40,oldParamNo:"0x38",paramLength:2,method:!0,key:"level2OvercurrentProtect"},{value:null,newValue:"",unit:"(mS)",paramNo2:"1013",paramNo:40,oldParamNo:"",paramLength:2,method:!0,key:"leve2OvercurrentDelay"},{checked:!1,isSwitch:!0,paramNo2:"1016",paramNo:41,oldParamNo:"",paramLength:2,key:"level2OvercurrentProtectV"},{value:null,newValue:"",unit:"(mV)",paramNo2:"1014",paramNo:41,oldParamNo:"",paramLength:2,method:!0,key:"shortcircuiProtect"},{value:null,newValue:"",unit:"(uS)",paramNo2:"1015",paramNo:41,oldParamNo:"",paramLength:2,method:!0,key:"shortcircuiProtectDelay"},{value:"",newValue:"",unit:"S",paramNo:43,oldParamNo:"0x39",paramLength:2,key:"shortcircuiProtectRecoverDelay",divisor:1}],exports.equalizerFunJson=[{value:"",newValue:"",unit:"V",paramNo:26,oldParamNo:"0x2A",paramLength:2,key:"equalizingVoltage"},{value:"",newValue:"",unit:"V",paramNo:27,oldParamNo:"0x2B",paramLength:2,key:"accuracyEqualization"}],exports.funcAndTempFuncJson=[{paramNo:29,oldParamNo:"0x2D",paramLength:2,key:"func"},{paramNo:30,oldParamNo:"0x2E",paramLength:2,key:"tempFunc"}],exports.funcJson=[{paramNo2:"1001",value:"",newValue:"",checked:!1,unit:"mAH",key:"onOff"},{paramNo2:"1002",value:"",newValue:"",checked:!1,unit:"mAH",key:"loadCheck"},{paramNo2:"1003",value:"",newValue:"",checked:!1,unit:"mAH",key:"equalizerFun"},{paramNo2:"1004",value:"",newValue:"",checked:!1,method:!0,unit:"mAH",key:"equalization"},{paramNo2:"1005",value:"",newValue:"",checked:!1,unit:"mAH",key:"led"},{paramNo2:"1006",value:"",newValue:"",checked:!1,unit:"mAH",key:"ledCount"},{paramNo2:"1008",value:"",newValue:"",checked:!1,unit:"mAH",key:"rtc"},{paramNo2:"1007",value:"",newValue:"",checked:!1,unit:"mAH",key:"fccLimit"},{paramNo2:"1009",value:"",newValue:"",checked:!1,unit:"mAH",key:"charingHandle"},{paramNo2:"1010",value:"",newValue:"",checked:!1,unit:"mAH",key:"gps"},{paramNo2:"1011",value:"",newValue:"",checked:!1,unit:"mAH",key:"beepDevice"}],exports.systemJson=[{value:"",newValue:"",unit:"",paramNo:6,oldParamNo:"",paramLength:2,isHidden:!0,key:"serialNumber",divisor:1},{value:"",newValue:"",unit:"",paramNo:7,oldParamNo:"",paramLength:2,isHidden:!0,key:"cycleCount",divisor:1},{name:"检流阻值",value:"",newValue:"",unit:"mR",paramNo:28,oldParamNo:"0x2C",paramLength:2,isHidden:!1,key:"rsnsValue",divisor:1e3},{name:"串数设置",value:"",newValue:"",unit:"",paramNo:31,oldParamNo:"0x2F",paramLength:2,isHidden:!0,key:"strCount",divisor:1},{name:"自动关机",value:"",newValue:"",unit:"",paramNo:191,paramLength:2,notShow:!1,switch:!0,key:"param1911",divisor:1},{name:"低电保护功能",value:"",newValue:"",unit:"",paramNo:198,paramLength:2,notShow:!1,switch:!0,key:"param1981",divisor:1},{name:"UART协议设定",value:"",newValue:"",unit:"",paramNo:195,paramLength:2,notShow:!1,key:"param1951",divisor:1,method:!0}],exports.tempFuncJson=tempFuncJson,exports.tempInfoJson=[{value:"",newValue:"",unit:"℃",paramNo:8,oldParamNo:"0x18",paramLength:2,key:"chargeHightempProtect"},{value:"",newValue:"",unit:"℃",paramNo:9,oldParamNo:"0x19",paramLength:2,key:"chargeHightempRecover"},{value:"",newValue:"",unit:"℃",paramNo:10,oldParamNo:"0x1A",paramLength:2,key:"chargeLowtempProtect"},{value:"",newValue:"",unit:"℃",paramNo:11,oldParamNo:"0x1B",paramLength:2,key:"chargeLowtempRecover"},{value:"",newValue:"",unit:"℃",paramNo:12,oldParamNo:"0x1C",paramLength:2,key:"dischargingHightempProtect"},{value:"",newValue:"",unit:"℃",paramNo:13,oldParamNo:"0x1D",paramLength:2,key:"dischargingHightempRecover"},{value:"",newValue:"",unit:"℃",paramNo:14,oldParamNo:"0x1E",paramLength:2,key:"dischargingLowtempProtect"},{value:"",newValue:"",unit:"℃",paramNo:15,oldParamNo:"0x1F",paramLength:2,key:"dischargingLowtempRecover"},{value:"",newValue:"",unit:"S",paramNo:44,oldParamNo:"0x3A",paramLength:2,key:"chargeLowtempDelay"},{value:"",newValue:"",unit:"S",paramNo:45,oldParamNo:"",paramLength:2,key:"chargeHightempDelay"},{value:"",newValue:"",unit:"S",paramNo:46,oldParamNo:"0x3B",paramLength:2,key:"dischargingLowtempDelay"},{value:"",newValue:"",unit:"S",paramNo:47,oldParamNo:"",paramLength:2,key:"dischargingHightempDelay"},{name:"",value:"",newValue:"",unit:"℃",paramNo:202,oldParamNo:"0x2E",paramLength:2,key:"overtempProtect"},{name:"",value:"",newValue:"",unit:"℃",paramNo:203,oldParamNo:"0x2F",paramLength:2,key:"overtempRecover"}],exports.voltageInfoJson=[{key:"allOvervoltageProtect",value:"",newValue:"",unit:"V",paramNo:16,oldParamNo:"0x20",paramLength:2,divisor:100},{key:"allOverpressureRecovery",value:"",newValue:"",unit:"V",paramNo:17,oldParamNo:"0x21",paramLength:2,divisor:100},{key:"allLowvoltageProtect",value:"",newValue:"",unit:"V",paramNo:18,oldParamNo:"0x22",paramLength:2,divisor:100},{key:"allLowvoltageRecover",value:"",newValue:"",unit:"V",paramNo:19,oldParamNo:"0x23",paramLength:2,divisor:100},{key:"singleOvervoltageProtect",value:"",newValue:"",unit:"V",paramNo:20,oldParamNo:"0x24",paramLength:2,divisor:1e3},{key:"singleOverpressureRecovery",value:"",newValue:"",unit:"V",paramNo:21,oldParamNo:"0x25",paramLength:2,divisor:1e3},{key:"singleLowvoltageProtect",value:"",newValue:"",unit:"V",paramNo:22,oldParamNo:"0x26",paramLength:2,divisor:1e3},{key:"singleLowvoltageRecover",value:"",newValue:"",unit:"V",paramNo:23,oldParamNo:"0x27",paramLength:2,divisor:1e3},{key:"allLowvoltageDelay",value:"",newValue:"",unit:"S",paramNo:48,oldParamNo:"0x3C",paramLength:2,divisor:1},{key:"allOverpressureDelay",value:"",newValue:"",unit:"S",paramNo:49,oldParamNo:"",paramLength:2,divisor:1},{key:"singleLowvoltageDelayed",value:"",newValue:"",unit:"S",paramNo:50,oldParamNo:"0x3d",paramLength:2,divisor:1},{key:"singleOverpressureDelay",value:"",newValue:"",unit:"S",paramNo:51,oldParamNo:"",paramLength:2,divisor:1},{key:"hardwareOV",value:null,newValue:"",unit:"V",paramNo:38,oldParamNo:"0x36",paramLength:2,divisor:1e3},{key:"hardwareUV",value:null,newValue:"",unit:"V",paramNo:39,oldParamNo:"0x37",paramLength:2,divisor:1e3}];
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tempFuncJson=Array.from({length:8},(_,index)=>({name:""+(0===index?"保护板温度":`电池温度${index}`),value:"",newValue:"",checked:!1,unit:"",key:`tempera${index}`}));exports.batteryInfoJson=crsDivisor=>[{key:"barCode",paramNo:88,paramLength:32,oldParamNo:"0xA2"},{key:"manufacturer",paramNo:56,oldParamNo:"0xA0",paramLength:32},{key:"producedDate",paramNo:5,oldParamNo:"0x15",paramLength:2},{key:"model",paramNo:.1==crsDivisor?158:316,oldParamNo:"",paramLength:24},{key:"bmsModel",paramNo:.1==crsDivisor?176:72,oldParamNo:"",paramLength:.1==crsDivisor?16:32}],exports.capInfoJson=[{key:"normCap",paramNo:0,oldParamNo:"0x10",paramLength:2,divisor:10},{key:"cycleCap",paramNo:1,oldParamNo:"0x11",paramLength:2,divisor:10},{key:"fullCap",paramNo:112,oldParamNo:"",paramLength:2,divisor:10}],exports.capVolInfoJson=[{value:null,newValue:"",unit:"V",paramNo:2,oldParamNo:"0x12",paramLength:2,isHidden:!1,key:"fullVolt",divisor:1e3},{value:null,newValue:"",unit:"V",paramNo:3,oldParamNo:"0x13",paramLength:2,isHidden:!1,key:"emptyVolt",divisor:1e3},{name:"容量80%",value:"",newValue:"",unit:"V",paramNo:34,oldParamNo:"0x32",paramLength:2,key:"voltage80p",divisor:1e3},{name:"容量60%",value:"",newValue:"",unit:"V",paramNo:35,oldParamNo:"0x33",paramLength:2,key:"voltage60p",divisor:1e3},{name:"容量40%",value:"",newValue:"",unit:"V",paramNo:36,oldParamNo:"0x34",paramLength:2,key:"voltage40p",divisor:1e3},{name:"容量20%",value:"",newValue:"",unit:"V",paramNo:37,oldParamNo:"0x35",paramLength:2,key:"voltage20p",divisor:1e3},{name:"容量90%",value:"",newValue:"",unit:"V",paramNo:106,oldParamNo:"0x42",paramLength:2,key:"voltage90p",divisor:1e3},{name:"容量70%",value:"",newValue:"",unit:"V",paramNo:107,oldParamNo:"0x43",paramLength:2,key:"voltage70p",divisor:1e3},{name:"容量50%",value:"",newValue:"",unit:"V",paramNo:108,oldParamNo:"0x44",paramLength:2,key:"voltage50p",divisor:1e3},{name:"容量30%",value:"",newValue:"",unit:"V",paramNo:109,oldParamNo:"0x45",paramLength:2,key:"voltage30p",divisor:1e3},{name:"容量10%",value:"",newValue:"",unit:"V",paramNo:110,oldParamNo:"0x46",paramLength:2,key:"voltage10p",divisor:1e3},{name:"容量100%",value:"",newValue:"",unit:"V",paramNo:111,oldParamNo:"0x47",paramLength:2,key:"voltage100p",divisor:1e3}],exports.currentInfoJson=[{value:"",newValue:"",unit:"A",paramNo:24,oldParamNo:"0x28",paramLength:2,key:"occhg",divisor:100},{value:"",newValue:"",unit:"A",paramNo:25,oldParamNo:"0x29",paramLength:2,key:"dischargeOvercurrentProtect",divisor:1e3},{value:"",newValue:"",unit:"S",paramNo:52,oldParamNo:"0x3E",paramLength:2,key:"chargeOvercurrentDelay",divisor:1},{value:"",newValue:"",unit:"S",paramNo:53,oldParamNo:"",paramLength:2,key:"chargeOvercurrentRecoverDelay",divisor:1},{value:"",newValue:"",unit:"S",paramNo:54,oldParamNo:"0x3F",paramLength:2,key:"dischargeOvercurrentDelay",divisor:1},{value:"",newValue:"",unit:"S",paramNo:55,oldParamNo:"",paramLength:2,key:"dischargeOvercurrentRecoverDelay",divisor:1},{value:null,newValue:"",unit:"(mV)",paramNo2:"1012",paramNo:40,oldParamNo:"0x38",paramLength:2,method:!0,key:"level2OvercurrentProtect"},{value:null,newValue:"",unit:"(mS)",paramNo2:"1013",paramNo:40,oldParamNo:"",paramLength:2,method:!0,key:"leve2OvercurrentDelay"},{checked:!1,isSwitch:!0,paramNo2:"1016",paramNo:41,oldParamNo:"",paramLength:2,key:"level2OvercurrentProtectV"},{value:null,newValue:"",unit:"(mV)",paramNo2:"1014",paramNo:41,oldParamNo:"",paramLength:2,method:!0,key:"shortcircuiProtect"},{value:null,newValue:"",unit:"(uS)",paramNo2:"1015",paramNo:41,oldParamNo:"",paramLength:2,method:!0,key:"shortcircuiProtectDelay"},{value:"",newValue:"",unit:"S",paramNo:43,oldParamNo:"0x39",paramLength:2,key:"shortcircuiProtectRecoverDelay",divisor:1}],exports.equalizerFunJson=[{value:"",newValue:"",unit:"V",paramNo:26,oldParamNo:"0x2A",paramLength:2,key:"equalizingVoltage"},{value:"",newValue:"",unit:"V",paramNo:27,oldParamNo:"0x2B",paramLength:2,key:"accuracyEqualization"}],exports.funcAndTempFuncJson=[{paramNo:29,oldParamNo:"0x2D",paramLength:2,key:"func"},{paramNo:30,oldParamNo:"0x2E",paramLength:2,key:"tempFunc"}],exports.funcJson=[{paramNo2:"1001",value:"",newValue:"",checked:!1,unit:"mAH",key:"onOff"},{paramNo2:"1002",value:"",newValue:"",checked:!1,unit:"mAH",key:"loadCheck"},{paramNo2:"1003",value:"",newValue:"",checked:!1,unit:"mAH",key:"equalizerFun"},{paramNo2:"1004",value:"",newValue:"",checked:!1,method:!0,unit:"mAH",key:"equalization"},{paramNo2:"1005",value:"",newValue:"",checked:!1,unit:"mAH",key:"led"},{paramNo2:"1006",value:"",newValue:"",checked:!1,unit:"mAH",key:"ledCount"},{paramNo2:"1008",value:"",newValue:"",checked:!1,unit:"mAH",key:"rtc"},{paramNo2:"1007",value:"",newValue:"",checked:!1,unit:"mAH",key:"fccLimit"},{paramNo2:"1009",value:"",newValue:"",checked:!1,unit:"mAH",key:"charingHandle"},{paramNo2:"1010",value:"",newValue:"",checked:!1,unit:"mAH",key:"gps"},{paramNo2:"1011",value:"",newValue:"",checked:!1,unit:"mAH",key:"beepDevice"}],exports.systemJson=[{value:"",newValue:"",unit:"",paramNo:6,oldParamNo:"",paramLength:2,isHidden:!0,key:"serialNumber",divisor:1},{value:"",newValue:"",unit:"",paramNo:7,oldParamNo:"",paramLength:2,isHidden:!0,key:"cycleCount",divisor:1},{name:"检流阻值",value:"",newValue:"",unit:"mR",paramNo:28,oldParamNo:"0x2C",paramLength:2,isHidden:!1,key:"rsnsValue",divisor:1e3},{name:"串数设置",value:"",newValue:"",unit:"",paramNo:31,oldParamNo:"0x2F",paramLength:2,isHidden:!0,key:"strCount",divisor:1},{value:"",newValue:"",unit:"S",paramNo:154,oldParamNo:"",paramLength:2,isHidden:!1,key:"forceUseTime",divisor:1},{name:"自动关机",value:"",newValue:"",unit:"",paramNo:191,paramLength:2,notShow:!1,switch:!0,key:"param1911",divisor:1},{name:"低电保护功能",value:"",newValue:"",unit:"",paramNo:198,paramLength:2,notShow:!1,switch:!0,key:"param1981",divisor:1},{name:"UART协议设定",value:"",newValue:"",unit:"",paramNo:195,paramLength:2,notShow:!1,key:"param1951",divisor:1,method:!0}],exports.tempFuncJson=tempFuncJson,exports.tempInfoJson=[{value:"",newValue:"",unit:"℃",paramNo:8,oldParamNo:"0x18",paramLength:2,key:"chargeHightempProtect"},{value:"",newValue:"",unit:"℃",paramNo:9,oldParamNo:"0x19",paramLength:2,key:"chargeHightempRecover"},{value:"",newValue:"",unit:"℃",paramNo:10,oldParamNo:"0x1A",paramLength:2,key:"chargeLowtempProtect"},{value:"",newValue:"",unit:"℃",paramNo:11,oldParamNo:"0x1B",paramLength:2,key:"chargeLowtempRecover"},{value:"",newValue:"",unit:"℃",paramNo:12,oldParamNo:"0x1C",paramLength:2,key:"dischargingHightempProtect"},{value:"",newValue:"",unit:"℃",paramNo:13,oldParamNo:"0x1D",paramLength:2,key:"dischargingHightempRecover"},{value:"",newValue:"",unit:"℃",paramNo:14,oldParamNo:"0x1E",paramLength:2,key:"dischargingLowtempProtect"},{value:"",newValue:"",unit:"℃",paramNo:15,oldParamNo:"0x1F",paramLength:2,key:"dischargingLowtempRecover"},{value:"",newValue:"",unit:"S",paramNo:44,oldParamNo:"0x3A",paramLength:2,key:"chargeLowtempDelay"},{value:"",newValue:"",unit:"S",paramNo:45,oldParamNo:"",paramLength:2,key:"chargeHightempDelay"},{value:"",newValue:"",unit:"S",paramNo:46,oldParamNo:"0x3B",paramLength:2,key:"dischargingLowtempDelay"},{value:"",newValue:"",unit:"S",paramNo:47,oldParamNo:"",paramLength:2,key:"dischargingHightempDelay"},{name:"",value:"",newValue:"",unit:"℃",paramNo:202,oldParamNo:"0x2E",paramLength:2,key:"overtempProtect"},{name:"",value:"",newValue:"",unit:"℃",paramNo:203,oldParamNo:"0x2F",paramLength:2,key:"overtempRecover"}],exports.voltageInfoJson=[{key:"allOvervoltageProtect",value:"",newValue:"",unit:"V",paramNo:16,oldParamNo:"0x20",paramLength:2,divisor:100},{key:"allOverpressureRecovery",value:"",newValue:"",unit:"V",paramNo:17,oldParamNo:"0x21",paramLength:2,divisor:100},{key:"allLowvoltageProtect",value:"",newValue:"",unit:"V",paramNo:18,oldParamNo:"0x22",paramLength:2,divisor:100},{key:"allLowvoltageRecover",value:"",newValue:"",unit:"V",paramNo:19,oldParamNo:"0x23",paramLength:2,divisor:100},{key:"singleOvervoltageProtect",value:"",newValue:"",unit:"V",paramNo:20,oldParamNo:"0x24",paramLength:2,divisor:1e3},{key:"singleOverpressureRecovery",value:"",newValue:"",unit:"V",paramNo:21,oldParamNo:"0x25",paramLength:2,divisor:1e3},{key:"singleLowvoltageProtect",value:"",newValue:"",unit:"V",paramNo:22,oldParamNo:"0x26",paramLength:2,divisor:1e3},{key:"singleLowvoltageRecover",value:"",newValue:"",unit:"V",paramNo:23,oldParamNo:"0x27",paramLength:2,divisor:1e3},{key:"allLowvoltageDelay",value:"",newValue:"",unit:"S",paramNo:48,oldParamNo:"0x3C",paramLength:2,divisor:1},{key:"allOverpressureDelay",value:"",newValue:"",unit:"S",paramNo:49,oldParamNo:"",paramLength:2,divisor:1},{key:"singleLowvoltageDelayed",value:"",newValue:"",unit:"S",paramNo:50,oldParamNo:"0x3d",paramLength:2,divisor:1},{key:"singleOverpressureDelay",value:"",newValue:"",unit:"S",paramNo:51,oldParamNo:"",paramLength:2,divisor:1},{key:"hardwareOV",value:null,newValue:"",unit:"V",paramNo:38,oldParamNo:"0x36",paramLength:2,divisor:1e3},{key:"hardwareUV",value:null,newValue:"",unit:"V",paramNo:39,oldParamNo:"0x37",paramLength:2,divisor:1e3}];
|
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"),BleDataProcess=require("./core/BleDataProcess.js"),commonfun=require("./core/commonfun.js"),keyAndPwdManager=require("./core/keyAndPwdManager.js"),mqttServer=require("./core/mqttServer.js"),OtaUpgrade=require("./core/OtaUpgrade.js"),rsaEncrypt=require("./core/rsaEncrypt.js"),tcpServer=require("./core/tcpServer.js"),TelinkApi=require("./core/TelinkApi.js"),Transfer=require("./core/Transfer.js"),BaseParamProtocol=require("./core/BleCmdAnalysis/BaseParamProtocol.js"),BleCmdAnalysis=require("./core/BleCmdAnalysis/BleCmdAnalysis.js"),BleCmdDD=require("./core/BleCmdAnalysis/BleCmdDD.js"),BleCmdDDA4=require("./core/BleCmdAnalysis/BleCmdDDA4.js"),BleCmdFFAA=require("./core/BleCmdAnalysis/BleCmdFFAA.js"),BleCmdHVES=require("./core/BleCmdAnalysis/BleCmdHVES.js"),ESHostProtocol=require("./core/BleCmdAnalysis/ESHostProtocol.js"),readAndSetParam=require("./core/BleCmdAnalysis/readAndSetParam.js"),baseParamsJson=require("./core/dataJson/baseParamsJson.js");exports.chunk=array.chunk,exports.unique=array.unique,exports.bluetoothScanHandle=BleApiManager.bluetoothScanHandle,exports.checkBluetoothStatus=BleApiManager.checkBluetoothStatus,exports.checkLocationStatus=BleApiManager.checkLocationStatus,exports.connectAsync=BleApiManager.connectAsync,exports.createBLEConnection=BleApiManager.createBLEConnection,exports.disConnect=BleApiManager.disConnect,exports.enhanceDevice=BleApiManager.enhanceDevice,exports.foundScanDevice=BleApiManager.foundScanDevice,exports.getBLEDeviceCharacteristics=BleApiManager.getBLEDeviceCharacteristics,exports.getBLEDeviceServices=BleApiManager.getBLEDeviceServices,exports.getBluetoothAdapterState=BleApiManager.getBluetoothAdapterState,exports.getBluetoothPermission=BleApiManager.getBluetoothPermission,exports.initBle=BleApiManager.initBle,Object.defineProperty(exports,"isInit",{enumerable:!0,get:function(){return BleApiManager.isInit}}),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.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.fromBCD=BleDataProcess.fromBCD,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.isWithin30Minutes=BleDataProcess.isWithin30Minutes,exports.parseDateTime=BleDataProcess.parseDateTime,exports.sleep=BleDataProcess.sleep,exports.string2hexArr=BleDataProcess.string2hexArr,exports.stringToTwoHexArray=BleDataProcess.stringToTwoHexArray,exports.toBCD=BleDataProcess.toBCD,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.MqttServer=mqttServer.MqttServer,exports.mqttServer=mqttServer.mqttServer,exports.OTAUpgrade=OtaUpgrade.OTAUpgrade,exports.decrypt=rsaEncrypt.decrypt,exports.decrypt2=rsaEncrypt.decrypt2,exports.decryptUsername=rsaEncrypt.decryptUsername,exports.encrypt=rsaEncrypt.encrypt,exports.tcpSend=tcpServer.tcpSend,exports.tcpServer=tcpServer.tcpServer,exports.TelinkApi=TelinkApi.TelinkApi,exports.BLE=Transfer.BLE,exports.Logger=Transfer.Logger,exports.Observer=Transfer.Observer,exports.Transfer=Transfer.Transfer,exports.getBaseInfo=BaseParamProtocol.getBaseInfo,exports.getBaseParams=BaseParamProtocol.getBaseParams,exports.getResistance=BaseParamProtocol.getResistance,exports.getData=BleCmdAnalysis.getData,exports.setMTUAsync=BleCmdAnalysis.setMTUAsync,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.getDDA4F0Async=BleCmdDD.getDDA4F0Async,exports.getDDA503Async=BleCmdDD.getDDA503Async,exports.getDDA504Async=BleCmdDD.getDDA504Async,exports.getDDA505Async=BleCmdDD.getDDA505Async,exports.getDDA506Async=BleCmdDD.getDDA506Async,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.resolveDDA4F0=BleCmdDD.resolveDDA4F0,exports.resolveDDA500=BleCmdDD.resolveDDA500,exports.resolveDDA503=BleCmdDD.resolveDDA503,exports.resolveDDA504=BleCmdDD.resolveDDA504,exports.resolveDDA505=BleCmdDD.resolveDDA505,exports.resolveDDA506=BleCmdDD.resolveDDA506,exports.resolveDDA508=BleCmdDD.resolveDDA508,exports.resolveDDA5DC=BleCmdDD.resolveDDA5DC,exports.resolveDDA5FA=BleCmdDD.resolveDDA5FA,exports.resolveProtections=BleCmdDD.resolveProtections,exports.sendBMSAsync=BleCmdDD.sendBMSAsync,exports.setDD5AE3sync=BleCmdDD.setDD5AE3sync,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.getDDA420Async=BleCmdDDA4.getDDA420Async,exports.getDDA421Async=BleCmdDDA4.getDDA421Async,exports.getDDA422Async=BleCmdDDA4.getDDA422Async,exports.getDDA423Async=BleCmdDDA4.getDDA423Async,exports.getDDA425Async=BleCmdDDA4.getDDA425Async,exports.getDDA426Async=BleCmdDDA4.getDDA426Async,exports.getDDA427Async=BleCmdDDA4.getDDA427Async,exports.getDDA429Async=BleCmdDDA4.getDDA429Async,exports.resolveDDA420=BleCmdDDA4.resolveDDA420,exports.resolveDDA421=BleCmdDDA4.resolveDDA421,exports.resolveDDA422=BleCmdDDA4.resolveDDA422,exports.resolveDDA423=BleCmdDDA4.resolveDDA423,exports.resolveDDA425=BleCmdDDA4.resolveDDA425,exports.resolveDDA426=BleCmdDDA4.resolveDDA426,exports.resolveDDA427=BleCmdDDA4.resolveDDA427,exports.resolveDDA429=BleCmdDDA4.resolveDDA429,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.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.controlSwitch=readAndSetParam.controlSwitch,exports.getE1Cmd=readAndSetParam.getE1Cmd,exports.getSysParamCmd=readAndSetParam.getSysParamCmd,exports.readParamCmd=readAndSetParam.readParamCmd,exports.setCapacityParamCmd=readAndSetParam.setCapacityParamCmd,exports.setParamCmd=readAndSetParam.setParamCmd,exports.setSysParamCmd=readAndSetParam.setSysParamCmd,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"),BleDataProcess=require("./core/BleDataProcess.js"),commonfun=require("./core/commonfun.js"),keyAndPwdManager=require("./core/keyAndPwdManager.js"),mqttServer=require("./core/mqttServer.js"),OtaUpgrade=require("./core/OtaUpgrade.js"),rsaEncrypt=require("./core/rsaEncrypt.js"),tcpServer=require("./core/tcpServer.js"),TelinkApi=require("./core/TelinkApi.js"),Transfer=require("./core/Transfer.js"),BaseParamProtocol=require("./core/BleCmdAnalysis/BaseParamProtocol.js"),BleCmdAnalysis=require("./core/BleCmdAnalysis/BleCmdAnalysis.js"),BleCmdDD=require("./core/BleCmdAnalysis/BleCmdDD.js"),BleCmdDDA4=require("./core/BleCmdAnalysis/BleCmdDDA4.js"),BleCmdFFAA=require("./core/BleCmdAnalysis/BleCmdFFAA.js"),BleCmdHVES=require("./core/BleCmdAnalysis/BleCmdHVES.js"),ESHostProtocol=require("./core/BleCmdAnalysis/ESHostProtocol.js"),readAndSetParam=require("./core/BleCmdAnalysis/readAndSetParam.js"),baseParamsJson=require("./core/dataJson/baseParamsJson.js");exports.chunk=array.chunk,exports.unique=array.unique,exports.bluetoothScanHandle=BleApiManager.bluetoothScanHandle,exports.checkBluetoothStatus=BleApiManager.checkBluetoothStatus,exports.checkLocationStatus=BleApiManager.checkLocationStatus,exports.connectAsync=BleApiManager.connectAsync,exports.createBLEConnection=BleApiManager.createBLEConnection,exports.disConnect=BleApiManager.disConnect,exports.enhanceDevice=BleApiManager.enhanceDevice,exports.foundScanDevice=BleApiManager.foundScanDevice,exports.getBLEDeviceCharacteristics=BleApiManager.getBLEDeviceCharacteristics,exports.getBLEDeviceServices=BleApiManager.getBLEDeviceServices,exports.getBluetoothAdapterState=BleApiManager.getBluetoothAdapterState,exports.getBluetoothPermission=BleApiManager.getBluetoothPermission,exports.initBle=BleApiManager.initBle,Object.defineProperty(exports,"isInit",{enumerable:!0,get:function(){return BleApiManager.isInit}}),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.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.fromBCD=BleDataProcess.fromBCD,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.isWithin30Minutes=BleDataProcess.isWithin30Minutes,exports.parseDateTime=BleDataProcess.parseDateTime,exports.sleep=BleDataProcess.sleep,exports.string2hexArr=BleDataProcess.string2hexArr,exports.stringToTwoHexArray=BleDataProcess.stringToTwoHexArray,exports.toBCD=BleDataProcess.toBCD,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.MqttServer=mqttServer.MqttServer,exports.mqttServer=mqttServer.mqttServer,exports.OTAUpgrade=OtaUpgrade.OTAUpgrade,exports.decrypt=rsaEncrypt.decrypt,exports.decrypt2=rsaEncrypt.decrypt2,exports.decryptUsername=rsaEncrypt.decryptUsername,exports.encrypt=rsaEncrypt.encrypt,exports.tcpSend=tcpServer.tcpSend,exports.tcpServer=tcpServer.tcpServer,exports.TelinkApi=TelinkApi.TelinkApi,exports.BLE=Transfer.BLE,exports.Logger=Transfer.Logger,exports.Observer=Transfer.Observer,exports.Transfer=Transfer.Transfer,exports.getBaseInfo=BaseParamProtocol.getBaseInfo,exports.getBaseParams=BaseParamProtocol.getBaseParams,exports.getResistance=BaseParamProtocol.getResistance,exports.getData=BleCmdAnalysis.getData,exports.setMTUAsync=BleCmdAnalysis.setMTUAsync,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.getDDA4F0Async=BleCmdDD.getDDA4F0Async,exports.getDDA503Async=BleCmdDD.getDDA503Async,exports.getDDA504Async=BleCmdDD.getDDA504Async,exports.getDDA505Async=BleCmdDD.getDDA505Async,exports.getDDA506Async=BleCmdDD.getDDA506Async,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.resolveDDA4F0=BleCmdDD.resolveDDA4F0,exports.resolveDDA500=BleCmdDD.resolveDDA500,exports.resolveDDA503=BleCmdDD.resolveDDA503,exports.resolveDDA504=BleCmdDD.resolveDDA504,exports.resolveDDA505=BleCmdDD.resolveDDA505,exports.resolveDDA506=BleCmdDD.resolveDDA506,exports.resolveDDA508=BleCmdDD.resolveDDA508,exports.resolveDDA5DC=BleCmdDD.resolveDDA5DC,exports.resolveDDA5FA=BleCmdDD.resolveDDA5FA,exports.resolveProtections=BleCmdDD.resolveProtections,exports.sendBMSAsync=BleCmdDD.sendBMSAsync,exports.setDD5AE3TimestampSync=BleCmdDD.setDD5AE3TimestampSync,exports.setDD5AE3sync=BleCmdDD.setDD5AE3sync,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.getDDA420Async=BleCmdDDA4.getDDA420Async,exports.getDDA421Async=BleCmdDDA4.getDDA421Async,exports.getDDA422Async=BleCmdDDA4.getDDA422Async,exports.getDDA423Async=BleCmdDDA4.getDDA423Async,exports.getDDA425Async=BleCmdDDA4.getDDA425Async,exports.getDDA426Async=BleCmdDDA4.getDDA426Async,exports.getDDA427Async=BleCmdDDA4.getDDA427Async,exports.getDDA429Async=BleCmdDDA4.getDDA429Async,exports.resolveDDA420=BleCmdDDA4.resolveDDA420,exports.resolveDDA421=BleCmdDDA4.resolveDDA421,exports.resolveDDA422=BleCmdDDA4.resolveDDA422,exports.resolveDDA423=BleCmdDDA4.resolveDDA423,exports.resolveDDA425=BleCmdDDA4.resolveDDA425,exports.resolveDDA426=BleCmdDDA4.resolveDDA426,exports.resolveDDA427=BleCmdDDA4.resolveDDA427,exports.resolveDDA429=BleCmdDDA4.resolveDDA429,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.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.controlSwitch=readAndSetParam.controlSwitch,exports.getE1Cmd=readAndSetParam.getE1Cmd,exports.getSysParamCmd=readAndSetParam.getSysParamCmd,exports.readParamCmd=readAndSetParam.readParamCmd,exports.setCapacityParamCmd=readAndSetParam.setCapacityParamCmd,exports.setParamCmd=readAndSetParam.setParamCmd,exports.setSysParamCmd=readAndSetParam.setSysParamCmd,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{decimalToHex,hexToDecimal}from"../BleDataProcess.js";import{systemJson,funcAndTempFuncJson,capVolInfoJson,equalizerFunJson,tempInfoJson,currentInfoJson,voltageInfoJson,capInfoJson,batteryInfoJson,funcJson,tempFuncJson}from"../dataJson/baseParamsJson.js";import{getProtectCountCmd,enterFactory,readExistFactory}from"./BleCmdDD.js";import{getSysParamCmd}from"./readAndSetParam.js";function format(value,n=1,offset=0,scope=0){if(!value)return null;value=value.map(el=>{const hexValue=decimalToHex(el);return console.log("el: ------------",hexValue),hexValue});const v=parseInt(value.join(""),16)*n+offset;if(null==scope)return v;const formatted=v.toFixed(scope);return Number(formatted)}function formatTemp(arr){if(!arr)return null;let string="0x"+toHexString(arr),value=parseInt(string,16);return value=(value-2731)/10,Number(value)}function formatBinary(arr){if(!arr)return null;return arr.map(num=>num.toString(2).padStart(8,"0")).join("").split("").map(Number).reverse()}const sendCmdSeq=async(datasInfo,chipType,deviceId,params)=>{if(datasInfo&&deviceId&&Array.isArray(params)){chipType||await enterFactory(deviceId);for(const item of params)if(item?.key)try{const baseData=await getSysParamCmd(chipType,deviceId,item,!1);datasInfo[item.key]=baseData}catch(err){console.error(`获取参数失败 [${item.key}]:`,err)}chipType||await readExistFactory(deviceId)}else console.error("sendCmdSeq 参数异常")};let crsDivisor=.1;const getBaseParams=async(chipType,deviceData,index,paramObj)=>{console.log("chipType: ",chipType);const deviceId=deviceData?.deviceId,protocolVersion=deviceData?.protocolVersion||"00";console.warn("protocolVersion: ",protocolVersion);const v=hexToDecimal(protocolVersion);(2==v||v>=20&&v<80)&&(crsDivisor=.01),console.log("v: ",v);try{let dataInfo={};switch(index){case 1:let datasInfo1={};return await sendCmdSeq(datasInfo1,chipType,deviceId,batteryInfoJson(crsDivisor)),dataInfo=getBaseInfo(datasInfo1),dataInfo;case 2:let datasInfo2={};const productType=deviceData.productType,isBalanceDevice="12"===productType;if(console.log("productType",productType,isBalanceDevice),chipType)if(isBalanceDevice){const normCapLow=await getSysParamCmd(chipType,deviceId,{paramNo:0,paramLength:2}),normCapHigh=await getSysParamCmd(chipType,deviceId,{paramNo:155,paramLength:2});console.log("normCapLow: ",normCapLow,"normCapHigh: ",normCapHigh),datasInfo2.normCap=[...normCapLow?.slice(0,2)||[],...normCapHigh?.slice(0,2)||[]];const cycleCapData=await getSysParamCmd(chipType,deviceId,capInfoJson[1]);datasInfo2.cycleCap=cycleCapData?.slice(0,2);const fullCapLow=await getSysParamCmd(chipType,deviceId,{paramNo:112,paramLength:2}),fullCapHigh=await getSysParamCmd(chipType,deviceId,{paramNo:156,paramLength:2});console.log("fullCapLow: ",fullCapLow,"fullCapHigh: ",fullCapHigh),datasInfo2.fullCap=[...fullCapLow?.slice(0,2)||[],...fullCapHigh?.slice(0,2)||[]]}else{const capData=await getSysParamCmd(chipType,deviceId,{...capInfoJson[0],paramLength:4});console.warn("capData: ",capData),datasInfo2.normCap=capData?.slice(0,2),datasInfo2.cycleCap=capData?.slice(2,4);const capData2=await getSysParamCmd(chipType,deviceId,capInfoJson[2]);datasInfo2.fullCap=capData2?.slice(0,2)}else await sendCmdSeq(datasInfo2,chipType,deviceId,capInfoJson);return dataInfo=getCapInfo(datasInfo2),dataInfo;case 3:let datasInfo3={};if(chipType){let vindex=voltageInfoJson.findIndex(el=>16==el.paramNo);console.log("vindex: ------------",vindex);let vindex1=voltageInfoJson.findIndex(el=>48==el.paramNo),vindex2=voltageInfoJson.findIndex(el=>38==el.paramNo);const voltageData=await getSysParamCmd(chipType,deviceId,{...voltageInfoJson[vindex],paramLength:16}),voltageData1=await getSysParamCmd(chipType,deviceId,{...voltageInfoJson[vindex1],paramLength:8}),voltageData2=await getSysParamCmd(chipType,deviceId,{...voltageInfoJson[vindex2],paramLength:4});console.log("voltageData: ",voltageData),datasInfo3.allOvervoltageProtect=voltageData?.slice(0,2),datasInfo3.allOverpressureRecovery=voltageData?.slice(2,4),datasInfo3.allLowvoltageProtect=voltageData?.slice(4,6),datasInfo3.allLowvoltageRecover=voltageData?.slice(6,8),datasInfo3.singleOvervoltageProtect=voltageData?.slice(8,10),datasInfo3.singleOverpressureRecovery=voltageData?.slice(10,12),datasInfo3.singleLowvoltageProtect=voltageData?.slice(12,14),datasInfo3.singleLowvoltageRecover=voltageData?.slice(14,16),datasInfo3.allLowvoltageDelay=voltageData1?.slice(0,2),datasInfo3.allOverpressureDelay=voltageData1?.slice(2,4),datasInfo3.singleLowvoltageDelayed=voltageData1?.slice(4,6),datasInfo3.singleOverpressureDelay=voltageData1?.slice(6,8),datasInfo3.hardwareOV=voltageData2?.slice(0,2),datasInfo3.hardwareUV=voltageData2?.slice(2,4)}else await sendCmdSeq(datasInfo3,chipType,deviceId,voltageInfoJson);return dataInfo=getVoltageInfo(datasInfo3,chipType),dataInfo;case 4:let datasInfo4={};if(chipType){let cindex=currentInfoJson.findIndex(el=>24==el.paramNo),cindex1=currentInfoJson.findIndex(el=>52==el.paramNo),cindex2=currentInfoJson.findIndex(el=>40==el.paramNo);const currentData=await getSysParamCmd(chipType,deviceId,{...currentInfoJson[cindex],paramLength:4}),currentData1=await getSysParamCmd(chipType,deviceId,{...currentInfoJson[cindex1],paramLength:8}),currentData2=await getSysParamCmd(chipType,deviceId,{...currentInfoJson[cindex2],paramLength:8});console.log("currentData: ",currentData),datasInfo4.occhg=currentData?.slice(0,2),datasInfo4.dischargeOvercurrentProtect=currentData?.slice(2,4),datasInfo4.chargeOvercurrentDelay=currentData1?.slice(0,2),datasInfo4.chargeOvercurrentRecoverDelay=currentData1?.slice(2,4),datasInfo4.dischargeOvercurrentDelay=currentData1?.slice(4,6),datasInfo4.dischargeOvercurrentRecoverDelay=currentData1?.slice(6,8),datasInfo4.level2OvercurrentProtect=currentData2?.slice(0,2),datasInfo4.level2OvercurrentProtectV=currentData2?.slice(2,4),datasInfo4.shortcircuiProtectRecoverDelay=currentData2?.slice(6,8)}else await sendCmdSeq(datasInfo4,chipType,deviceId,currentInfoJson);return dataInfo=getCurrentInfo(datasInfo4,chipType),dataInfo;case 5:let datasInfo5={};if(chipType){let tindex=tempInfoJson.findIndex(el=>8==el.paramNo),tindex1=tempInfoJson.findIndex(el=>44==el.paramNo),tindex2=tempInfoJson.findIndex(el=>202==el.paramNo);const tempData=await getSysParamCmd(chipType,deviceId,{...tempInfoJson[tindex],paramLength:16}),tempData1=await getSysParamCmd(chipType,deviceId,{...tempInfoJson[tindex1],paramLength:8}),tempData2=await getSysParamCmd(chipType,deviceId,{...tempInfoJson[tindex2],paramLength:4});console.log("tempData: ",tempData,tempData2),datasInfo5.chargeHightempProtect=tempData?.slice(0,2),datasInfo5.chargeHightempRecover=tempData?.slice(2,4),datasInfo5.chargeLowtempProtect=tempData?.slice(4,6),datasInfo5.chargeLowtempRecover=tempData?.slice(6,8),datasInfo5.dischargingHightempProtect=tempData?.slice(8,10),datasInfo5.dischargingHightempRecover=tempData?.slice(10,12),datasInfo5.dischargingLowtempProtect=tempData?.slice(12,14),datasInfo5.dischargingLowtempRecover=tempData?.slice(14,16),datasInfo5.chargeLowtempDelay=tempData1?.slice(0,2),datasInfo5.chargeHightempDelay=tempData1?.slice(2,4),datasInfo5.dischargingLowtempDelay=tempData1?.slice(4,6),datasInfo5.dischargingHightempDelay=tempData1?.slice(6,8),datasInfo5.overtempProtect=tempData2?.slice(0,2),datasInfo5.overtempRecover=tempData2?.slice(2,4)}else await sendCmdSeq(datasInfo5,chipType,deviceId,tempInfoJson);return dataInfo=getTempInfo(datasInfo5,chipType),dataInfo;case 6:let datasInfo6={};if(chipType){const equalizerFunData=await getSysParamCmd(chipType,deviceId,{...equalizerFunJson[0],paramLength:4});console.log("equalizerFunData: ",equalizerFunData),datasInfo6.equalizingVoltage=equalizerFunData?.slice(0,2),datasInfo6.accuracyEqualization=equalizerFunData?.slice(2,4)}else await sendCmdSeq(datasInfo6,chipType,deviceId,equalizerFunJson);return dataInfo=getEqualizerFunInfo(datasInfo6),dataInfo;case 7:let datasInfo7={};if(chipType){let capVolIndex=capVolInfoJson.findIndex(el=>34==el.paramNo),capVolIndex1=capVolInfoJson.findIndex(el=>106==el.paramNo);const capVolInfoData=await getSysParamCmd(chipType,deviceId,{...capVolInfoJson[0],paramLength:4}),capVolInfoData1=await getSysParamCmd(chipType,deviceId,{...capVolInfoJson[capVolIndex],paramLength:8}),capVolInfoData2=await getSysParamCmd(chipType,deviceId,{...capVolInfoJson[capVolIndex1],paramLength:12});console.log("capVolInfoData: ",capVolInfoData),datasInfo7.fullVolt=capVolInfoData?.slice(0,2),datasInfo7.emptyVolt=capVolInfoData?.slice(2,4),datasInfo7.voltage80p=capVolInfoData1?.slice(0,2),datasInfo7.voltage60p=capVolInfoData1?.slice(2,4),datasInfo7.voltage40p=capVolInfoData1?.slice(4,6),datasInfo7.voltage20p=capVolInfoData1?.slice(6,8),datasInfo7.voltage90p=capVolInfoData2?.slice(0,2),datasInfo7.voltage70p=capVolInfoData2?.slice(2,4),datasInfo7.voltage50p=capVolInfoData2?.slice(4,6),datasInfo7.voltage30p=capVolInfoData2?.slice(6,8),datasInfo7.voltage10p=capVolInfoData2?.slice(8,10),datasInfo7.voltage100p=capVolInfoData2?.slice(10,12)}else await sendCmdSeq(datasInfo7,chipType,deviceId,capVolInfoJson);return dataInfo=getcapVolInfoInfo(datasInfo7,chipType),dataInfo;case 9:let datasInfo9={};if(chipType){const funcAndTempFuncData=await getSysParamCmd(chipType,deviceId,{...funcAndTempFuncJson[0],paramLength:4});console.log("funcAndTempFuncData: ",funcAndTempFuncData),datasInfo9.func=funcAndTempFuncData?.slice(0,2),datasInfo9.tempFunc=funcAndTempFuncData?.slice(2,4)}else await sendCmdSeq(datasInfo9,chipType,deviceId,funcAndTempFuncJson);return dataInfo=getFuncAndTempFuncInfo(datasInfo9),dataInfo;case 10:let datasInfo10={};return await sendCmdSeq(datasInfo10,chipType,deviceId,systemJson),dataInfo=getSystemInfo(datasInfo10),dataInfo;case 11:const counts=await getProtectCountCmd(deviceId);return console.log("counts: ",counts),counts;default:if(!paramObj)return null;let defaultDataInfo={};const onedata=await getSysParamCmd(chipType,deviceId,paramObj);return defaultDataInfo[paramObj.key]=onedata?.slice(0,2),defaultDataInfo}}catch(error){throw console.error("error: 读系统参数报错 getBaseParams",error),error}},getResistance=async(chipType,deviceId)=>{try{const rsnsValue=await getSysParamCmd(chipType,deviceId,systemJson[2]);return format(rsnsValue,crsDivisor,0,2)}catch(error){throw console.error("error: 读检流阻值报错 getResistance",error),error}},getBaseInfo=async datas=>{try{console.log("datas: ",datas);const barCode=getCharCodeConnect(datas?.barCode),manufacturer=getCharCodeConnect(datas?.manufacturer),model=getCharCodeConnect(datas?.model),bmsModel=getCharCodeConnect(datas?.bmsModel,!0),producedDate=function(content){if(!content)return null;let arr=content.splice(0,2),string="0x";return arr.forEach(el=>{string+=decimalToHex(el)}),console.log(string,"string日期"),`${2e3+(string>>9)}-${string>>5&15}-${31&string}`}(datas?.producedDate);return{barCode:barCode,manufacturer:manufacturer,model:model,bmsModel:bmsModel,producedDate:producedDate,bmsAddr:function(content){if(!content)return null;return console.log(content,"content======"),toHexString(content.splice(0,12))}(datas?.bmsAddr)}}catch(error){console.error("error: ",error)}},getCharCodeConnect=(content,clearZero=!1)=>{if(console.log("content: ---------------",content),!content)return null;const length=content[0];let arr=content.splice(1,length);if(clearZero)for(;0===arr[arr.length-1];)arr.pop();return console.log("arr: -------------------",arr),String.fromCharCode(...arr)};function toHexString(arr){let string="";return arr.forEach(el=>{string+=decimalToHex(el)}),string}const getCapInfo=async datas=>{console.log("datas: ",datas);let normCap=null;if(datas.normCap&&datas.normCap.length>=4){console.log("normCap原始数据: ",datas.normCap);const lowBytes=datas.normCap.slice(0,2),lowValue=lowBytes[0]<<8|lowBytes[1];console.log("normCap lowValue: ",lowValue);const highBytes=datas.normCap.slice(2,4),highValue=highBytes[0]<<8|highBytes[1];console.log("normCap highValue: ",highValue);const totalValue=highValue<<16|lowValue;console.log("normCap totalValue: ",totalValue),normCap=Number((.01*totalValue).toFixed(2)),console.log("normCap最终值: ",normCap)}else if(datas.normCap&&datas.normCap.length>=2){const lowBytes=datas.normCap.slice(0,2),lowValue=lowBytes[0]<<8|lowBytes[1];normCap=Number((.01*lowValue).toFixed(2))}const cycleCap=format(datas.cycleCap,.01,0,2);let fullCap=null;if(datas.fullCap&&datas.fullCap.length>=4){console.log("fullCap原始数据: ",datas.fullCap);const lowBytes=datas.fullCap.slice(0,2),lowValue=lowBytes[0]<<8|lowBytes[1];console.log("fullCap lowValue: ",lowValue);const highBytes=datas.fullCap.slice(2,4),highValue=highBytes[0]<<8|highBytes[1];console.log("fullCap highValue: ",highValue);const totalValue=highValue<<16|lowValue;console.log("fullCap totalValue: ",totalValue),fullCap=Number((.01*totalValue).toFixed(2)),console.log("fullCap最终值: ",fullCap)}else if(datas.fullCap&&datas.fullCap.length>=2){const lowBytes=datas.fullCap.slice(0,2),lowValue=lowBytes[0]<<8|lowBytes[1];fullCap=Number((.01*lowValue).toFixed(2))}return{normCap:normCap,cycleCap:cycleCap,fullCap:fullCap}},getVoltageInfo=async(datas,chipType)=>{console.log("datas: ",datas);const allOvervoltageProtect=format(datas.allOvervoltageProtect,.01,0,3),allOverpressureRecovery=format(datas.allOverpressureRecovery,.01,0,3),allLowvoltageProtect=format(datas.allLowvoltageProtect,.01,0,3),allLowvoltageRecover=format(datas.allLowvoltageRecover,.01,0,3),singleOvervoltageProtect=format(datas.singleOvervoltageProtect,.001,0,3),singleOverpressureRecovery=format(datas.singleOverpressureRecovery,.001,0,3),singleLowvoltageProtect=format(datas.singleLowvoltageProtect,.001,0,3),singleLowvoltageRecover=format(datas.singleLowvoltageRecover,.001,0,3),hardwareOV=format(datas.hardwareOV,.001,0,3),hardwareUV=format(datas.hardwareUV,.001,0,3);let singleOverpressureDelay=null,singleLowvoltageDelayed=null,allLowvoltageDelay=null,allOverpressureDelay=null;return chipType?(singleOverpressureDelay=format(datas.singleOverpressureDelay,1),singleLowvoltageDelayed=format(datas.singleLowvoltageDelayed,1),allLowvoltageDelay=format(datas.allLowvoltageDelay,1),allOverpressureDelay=format(datas.allOverpressureDelay,1)):(singleLowvoltageDelayed=datas.singleLowvoltageDelayed[0],singleOverpressureDelay=datas.singleLowvoltageDelayed[1],allLowvoltageDelay=datas.allLowvoltageDelay[0],allOverpressureDelay=datas.allLowvoltageDelay[1]),{allOvervoltageProtect:allOvervoltageProtect,allOverpressureRecovery:allOverpressureRecovery,allLowvoltageProtect:allLowvoltageProtect,allLowvoltageRecover:allLowvoltageRecover,singleOvervoltageProtect:singleOvervoltageProtect,singleOverpressureRecovery:singleOverpressureRecovery,singleLowvoltageProtect:singleLowvoltageProtect,singleLowvoltageRecover:singleLowvoltageRecover,singleOverpressureDelay:singleOverpressureDelay,singleLowvoltageDelayed:singleLowvoltageDelayed,hardwareOV:hardwareOV,hardwareUV:hardwareUV,allLowvoltageDelay:allLowvoltageDelay,allOverpressureDelay:allOverpressureDelay}},getCurrentInfo=async(datas,chipType)=>{console.log("datas: ",datas);const occhg=format(datas.occhg,.01,0,3),dischargeOvercurrentProtect=(datas.dischargeOvercurrentProtect||0==datas.dischargeOvercurrentProtect)&&Number((.01*(format(datas.dischargeOvercurrentProtect,1,0,3)-65536)).toFixed(3));let chargeOvercurrentDelay=null,chargeOvercurrentRecoverDelay=null,dischargeOvercurrentDelay=null,dischargeOvercurrentRecoverDelay=null,shortcircuiProtectRecoverDelay=null,leve2OvercurrentDelay=0,level2OvercurrentProtect=0,shortcircuiProtect=0,shortcircuiProtectDelay=0,level2OvercurrentProtectV=null,overAndUnderDelay=0;return chipType?(chargeOvercurrentDelay=format(datas.chargeOvercurrentDelay,1),chargeOvercurrentRecoverDelay=format(datas.chargeOvercurrentRecoverDelay,1),dischargeOvercurrentDelay=format(datas.dischargeOvercurrentDelay,1),dischargeOvercurrentRecoverDelay=format(datas.dischargeOvercurrentRecoverDelay,1),shortcircuiProtectRecoverDelay=format(datas.shortcircuiProtectRecoverDelay,1),level2OvercurrentProtect=getNewProtectAndDelay(datas.level2OvercurrentProtect).value1,leve2OvercurrentDelay=getNewProtectAndDelay(datas.level2OvercurrentProtect).value2,shortcircuiProtect=getNewProtectAndDelay(datas.level2OvercurrentProtectV).value1,shortcircuiProtectDelay=getNewProtectAndDelay(datas.level2OvercurrentProtectV).value2):(chargeOvercurrentDelay=datas.chargeOvercurrentDelay[0],chargeOvercurrentRecoverDelay=datas.chargeOvercurrentDelay[1],dischargeOvercurrentDelay=datas.dischargeOvercurrentDelay[0],dischargeOvercurrentRecoverDelay=datas.dischargeOvercurrentDelay[1],overAndUnderDelay=datas.shortcircuiProtectRecoverDelay[0],shortcircuiProtectRecoverDelay=datas.shortcircuiProtectRecoverDelay[1],level2OvercurrentProtectV=getOldProtectAndDelay(datas.level2OvercurrentProtect).double,shortcircuiProtect=getOldProtectAndDelay(datas.level2OvercurrentProtect).value1,shortcircuiProtectDelay=getOldProtectAndDelay(datas.level2OvercurrentProtect).value2,level2OvercurrentProtect=getOldProtectAndDelay(datas.level2OvercurrentProtect).value3,leve2OvercurrentDelay=getOldProtectAndDelay(datas.level2OvercurrentProtect).value4),{occhg:occhg,dischargeOvercurrentProtect:dischargeOvercurrentProtect,chargeOvercurrentDelay:chargeOvercurrentDelay,chargeOvercurrentRecoverDelay:chargeOvercurrentRecoverDelay,dischargeOvercurrentDelay:dischargeOvercurrentDelay,dischargeOvercurrentRecoverDelay:dischargeOvercurrentRecoverDelay,leve2OvercurrentDelay:leve2OvercurrentDelay,level2OvercurrentProtectV:level2OvercurrentProtectV,shortcircuiProtectRecoverDelay:shortcircuiProtectRecoverDelay,shortcircuiProtect:shortcircuiProtect,shortcircuiProtectDelay:shortcircuiProtectDelay,level2OvercurrentProtect:level2OvercurrentProtect,overAndUnderDelay:overAndUnderDelay}};function getNewProtectAndDelay(arr){if(2!==arr?.length)return{value1:0,value2:0};let resultArray=arr.map(num=>num.toString(2).padStart(8,"0")).join("").split("").map(Number),arr1=resultArray.slice(8,12),arr2=resultArray.slice(12);return{value1:parseInt(arr1.join(""),2),value2:parseInt(arr2.join(""),2)}}function getOldProtectAndDelay(arr){if(2!==arr?.length)return{double:!1,value1:0,value2:0,value3:0,value4:0};const binaryString=arr.map(num=>num.toString(2).padStart(8,"0")).join("");console.log("【解析硬件过流及短路】",binaryString);const resultArray=binaryString.split("").map(Number),arr1=[0,...resultArray.slice(5,8)],arr2=resultArray.slice(1,5),arr3=resultArray.slice(12),arr4=resultArray.slice(8,12),value1=parseInt(arr1.join(""),2),value2=parseInt(arr2.join(""),2),value3=parseInt(arr3.join(""),2),value4=parseInt(arr4.join(""),2);return{double:1===resultArray[0],value1:value1,value2:value2,value3:value3,value4:value4}}const getTempInfo=(datas,chipType)=>{console.log("datas: ",datas);const chargeHightempProtect=formatTemp(datas.chargeHightempProtect),chargeHightempRecover=formatTemp(datas.chargeHightempRecover),chargeLowtempProtect=formatTemp(datas.chargeLowtempProtect),chargeLowtempRecover=formatTemp(datas.chargeLowtempRecover),dischargingHightempProtect=formatTemp(datas.dischargingHightempProtect),dischargingHightempRecover=formatTemp(datas.dischargingHightempRecover),dischargingLowtempProtect=formatTemp(datas.dischargingLowtempProtect),dischargingLowtempRecover=formatTemp(datas.dischargingLowtempRecover),overtempProtect=formatTemp(datas.overtempProtect),overtempRecover=formatTemp(datas.overtempRecover);let chargeHightempDelay=null,chargeLowtempDelay=null,dischargingHightempDelay=null,dischargingLowtempDelay=null;return chipType?(chargeHightempDelay=format(datas.chargeHightempDelay,1),chargeLowtempDelay=format(datas.chargeLowtempDelay,1),dischargingHightempDelay=format(datas.dischargingHightempDelay,1),dischargingLowtempDelay=format(datas.dischargingLowtempDelay,1)):(chargeHightempDelay=datas.chargeLowtempDelay[1],chargeLowtempDelay=datas.chargeLowtempDelay[0],dischargingHightempDelay=datas.dischargingLowtempDelay[1],dischargingLowtempDelay=datas.dischargingLowtempDelay[0]),{chargeHightempProtect:chargeHightempProtect,chargeHightempRecover:chargeHightempRecover,chargeLowtempProtect:chargeLowtempProtect,chargeLowtempRecover:chargeLowtempRecover,dischargingHightempProtect:dischargingHightempProtect,dischargingHightempRecover:dischargingHightempRecover,dischargingLowtempProtect:dischargingLowtempProtect,dischargingLowtempRecover:dischargingLowtempRecover,chargeHightempDelay:chargeHightempDelay,chargeLowtempDelay:chargeLowtempDelay,dischargingHightempDelay:dischargingHightempDelay,dischargingLowtempDelay:dischargingLowtempDelay,overtempProtect:overtempProtect,overtempRecover:overtempRecover}},getEqualizerFunInfo=datas=>({equalizingVoltage:format(datas.equalizingVoltage,.001,0,3),accuracyEqualization:format(datas.accuracyEqualization,1,0,2)}),getcapVolInfoInfo=datas=>({fullVolt:format(datas.fullVolt,.001,0,3),emptyVolt:format(datas.emptyVolt,.001,0,3),voltage10p:format(datas.voltage10p,.001,0,3),voltage20p:format(datas.voltage20p,.001,0,3),voltage30p:format(datas.voltage30p,.001,0,3),voltage40p:format(datas.voltage40p,.001,0,3),voltage50p:format(datas.voltage50p,.001,0,3),voltage60p:format(datas.voltage60p,.001,0,3),voltage70p:format(datas.voltage70p,.001,0,3),voltage80p:format(datas.voltage80p,.001,0,3),voltage90p:format(datas.voltage90p,.001,0,3),voltage100p:format(datas.voltage100p,.001,0,3)}),getFuncAndTempFuncInfo=datas=>{const binaryFuncArr=formatBinary(datas.func),binaryTempArr=formatBinary(datas.tempFunc),func={};funcJson.forEach((item,index)=>{item.key&&(func[item.key]=binaryFuncArr[index])});const tempFunc={};return tempFuncJson.forEach((item,index)=>{item.key&&(tempFunc[item.key]=binaryTempArr[index])}),{func:func,tempFunc:tempFunc}},splitNumberTo1Byte=(combined=0)=>({val1:255&(combined=Number(combined)),val2:combined>>8&255}),getSystemInfo=datas=>{const serialNumber=format(datas.serialNumber,1),cycleCount=format(datas.cycleCount,1),strCount=format(datas.strCount,1),rsnsValue=format(datas.rsnsValue,crsDivisor,0,2),param1911=splitNumberTo1Byte(format(datas.param1911)).val1,param1912=splitNumberTo1Byte(format(datas.param1911)).val2,param1981=splitNumberTo1Byte(format(datas.param1981)).val1,param1982=splitNumberTo1Byte(format(datas.param1981)).val2;return{serialNumber:serialNumber,cycleCount:cycleCount,strCount:strCount,rsnsValue:rsnsValue,param1911:param1911,param1912:param1912,param1951:splitNumberTo1Byte(format(datas.param1951)).val1,param1952:splitNumberTo1Byte(format(datas.param1951)).val2,param1981:param1981,param1982:param1982}};export{getBaseInfo,getBaseParams,getResistance};
|
|
1
|
+
import{decimalToHex,hexToDecimal}from"../BleDataProcess.js";import{systemJson,funcAndTempFuncJson,capVolInfoJson,equalizerFunJson,tempInfoJson,currentInfoJson,voltageInfoJson,capInfoJson,batteryInfoJson,funcJson,tempFuncJson}from"../dataJson/baseParamsJson.js";import{getProtectCountCmd,enterFactory,readExistFactory}from"./BleCmdDD.js";import{getSysParamCmd}from"./readAndSetParam.js";function format(value,n=1,offset=0,scope=0){if(!value)return null;value=value.map(el=>{const hexValue=decimalToHex(el);return console.log("el: ------------",hexValue),hexValue});const v=parseInt(value.join(""),16)*n+offset;if(null==scope)return v;const formatted=v.toFixed(scope);return Number(formatted)}function formatTemp(arr){if(!arr)return null;let string="0x"+toHexString(arr),value=parseInt(string,16);return value=(value-2731)/10,Number(value)}function formatBinary(arr){if(!arr)return null;return arr.map(num=>num.toString(2).padStart(8,"0")).join("").split("").map(Number).reverse()}const sendCmdSeq=async(datasInfo,chipType,deviceId,params)=>{if(datasInfo&&deviceId&&Array.isArray(params)){chipType||await enterFactory(deviceId);for(const item of params)if(item?.key)try{const baseData=await getSysParamCmd(chipType,deviceId,item,!1);datasInfo[item.key]=baseData}catch(err){console.error(`获取参数失败 [${item.key}]:`,err)}chipType||await readExistFactory(deviceId)}else console.error("sendCmdSeq 参数异常")};let crsDivisor=.1;const getBaseParams=async(chipType,deviceData,index,paramObj)=>{console.log("chipType: ",chipType);const deviceId=deviceData?.deviceId,protocolVersion=deviceData?.protocolVersion||"00";console.warn("protocolVersion: ",protocolVersion);const v=hexToDecimal(protocolVersion);(2==v||v>=20&&v<80)&&(crsDivisor=.01),console.log("v: ",v);try{let dataInfo={};switch(index){case 1:let datasInfo1={};return await sendCmdSeq(datasInfo1,chipType,deviceId,batteryInfoJson(crsDivisor)),dataInfo=getBaseInfo(datasInfo1),dataInfo;case 2:let datasInfo2={};const productType=deviceData.productType,isBalanceDevice="12"===productType;if(console.log("productType",productType,isBalanceDevice),chipType)if(isBalanceDevice){const normCapLow=await getSysParamCmd(chipType,deviceId,{paramNo:0,paramLength:2}),normCapHigh=await getSysParamCmd(chipType,deviceId,{paramNo:155,paramLength:2});console.log("normCapLow: ",normCapLow,"normCapHigh: ",normCapHigh),datasInfo2.normCap=[...normCapLow?.slice(0,2)||[],...normCapHigh?.slice(0,2)||[]];const cycleCapData=await getSysParamCmd(chipType,deviceId,capInfoJson[1]);datasInfo2.cycleCap=cycleCapData?.slice(0,2);const fullCapLow=await getSysParamCmd(chipType,deviceId,{paramNo:112,paramLength:2}),fullCapHigh=await getSysParamCmd(chipType,deviceId,{paramNo:156,paramLength:2});console.log("fullCapLow: ",fullCapLow,"fullCapHigh: ",fullCapHigh),datasInfo2.fullCap=[...fullCapLow?.slice(0,2)||[],...fullCapHigh?.slice(0,2)||[]]}else{const capData=await getSysParamCmd(chipType,deviceId,{...capInfoJson[0],paramLength:4});console.warn("capData: ",capData),datasInfo2.normCap=capData?.slice(0,2),datasInfo2.cycleCap=capData?.slice(2,4);const capData2=await getSysParamCmd(chipType,deviceId,capInfoJson[2]);datasInfo2.fullCap=capData2?.slice(0,2)}else await sendCmdSeq(datasInfo2,chipType,deviceId,capInfoJson);return dataInfo=getCapInfo(datasInfo2),dataInfo;case 3:let datasInfo3={};if(chipType){let vindex=voltageInfoJson.findIndex(el=>16==el.paramNo);console.log("vindex: ------------",vindex);let vindex1=voltageInfoJson.findIndex(el=>48==el.paramNo),vindex2=voltageInfoJson.findIndex(el=>38==el.paramNo);const voltageData=await getSysParamCmd(chipType,deviceId,{...voltageInfoJson[vindex],paramLength:16}),voltageData1=await getSysParamCmd(chipType,deviceId,{...voltageInfoJson[vindex1],paramLength:8}),voltageData2=await getSysParamCmd(chipType,deviceId,{...voltageInfoJson[vindex2],paramLength:4});console.log("voltageData: ",voltageData),datasInfo3.allOvervoltageProtect=voltageData?.slice(0,2),datasInfo3.allOverpressureRecovery=voltageData?.slice(2,4),datasInfo3.allLowvoltageProtect=voltageData?.slice(4,6),datasInfo3.allLowvoltageRecover=voltageData?.slice(6,8),datasInfo3.singleOvervoltageProtect=voltageData?.slice(8,10),datasInfo3.singleOverpressureRecovery=voltageData?.slice(10,12),datasInfo3.singleLowvoltageProtect=voltageData?.slice(12,14),datasInfo3.singleLowvoltageRecover=voltageData?.slice(14,16),datasInfo3.allLowvoltageDelay=voltageData1?.slice(0,2),datasInfo3.allOverpressureDelay=voltageData1?.slice(2,4),datasInfo3.singleLowvoltageDelayed=voltageData1?.slice(4,6),datasInfo3.singleOverpressureDelay=voltageData1?.slice(6,8),datasInfo3.hardwareOV=voltageData2?.slice(0,2),datasInfo3.hardwareUV=voltageData2?.slice(2,4)}else await sendCmdSeq(datasInfo3,chipType,deviceId,voltageInfoJson);return dataInfo=getVoltageInfo(datasInfo3,chipType),dataInfo;case 4:let datasInfo4={};if(chipType){let cindex=currentInfoJson.findIndex(el=>24==el.paramNo),cindex1=currentInfoJson.findIndex(el=>52==el.paramNo),cindex2=currentInfoJson.findIndex(el=>40==el.paramNo);const currentData=await getSysParamCmd(chipType,deviceId,{...currentInfoJson[cindex],paramLength:4}),currentData1=await getSysParamCmd(chipType,deviceId,{...currentInfoJson[cindex1],paramLength:8}),currentData2=await getSysParamCmd(chipType,deviceId,{...currentInfoJson[cindex2],paramLength:8});console.log("currentData: ",currentData),datasInfo4.occhg=currentData?.slice(0,2),datasInfo4.dischargeOvercurrentProtect=currentData?.slice(2,4),datasInfo4.chargeOvercurrentDelay=currentData1?.slice(0,2),datasInfo4.chargeOvercurrentRecoverDelay=currentData1?.slice(2,4),datasInfo4.dischargeOvercurrentDelay=currentData1?.slice(4,6),datasInfo4.dischargeOvercurrentRecoverDelay=currentData1?.slice(6,8),datasInfo4.level2OvercurrentProtect=currentData2?.slice(0,2),datasInfo4.level2OvercurrentProtectV=currentData2?.slice(2,4),datasInfo4.shortcircuiProtectRecoverDelay=currentData2?.slice(6,8)}else await sendCmdSeq(datasInfo4,chipType,deviceId,currentInfoJson);return dataInfo=getCurrentInfo(datasInfo4,chipType),dataInfo;case 5:let datasInfo5={};if(chipType){let tindex=tempInfoJson.findIndex(el=>8==el.paramNo),tindex1=tempInfoJson.findIndex(el=>44==el.paramNo),tindex2=tempInfoJson.findIndex(el=>202==el.paramNo);const tempData=await getSysParamCmd(chipType,deviceId,{...tempInfoJson[tindex],paramLength:16}),tempData1=await getSysParamCmd(chipType,deviceId,{...tempInfoJson[tindex1],paramLength:8}),tempData2=await getSysParamCmd(chipType,deviceId,{...tempInfoJson[tindex2],paramLength:4});console.log("tempData: ",tempData,tempData2),datasInfo5.chargeHightempProtect=tempData?.slice(0,2),datasInfo5.chargeHightempRecover=tempData?.slice(2,4),datasInfo5.chargeLowtempProtect=tempData?.slice(4,6),datasInfo5.chargeLowtempRecover=tempData?.slice(6,8),datasInfo5.dischargingHightempProtect=tempData?.slice(8,10),datasInfo5.dischargingHightempRecover=tempData?.slice(10,12),datasInfo5.dischargingLowtempProtect=tempData?.slice(12,14),datasInfo5.dischargingLowtempRecover=tempData?.slice(14,16),datasInfo5.chargeLowtempDelay=tempData1?.slice(0,2),datasInfo5.chargeHightempDelay=tempData1?.slice(2,4),datasInfo5.dischargingLowtempDelay=tempData1?.slice(4,6),datasInfo5.dischargingHightempDelay=tempData1?.slice(6,8),datasInfo5.overtempProtect=tempData2?.slice(0,2),datasInfo5.overtempRecover=tempData2?.slice(2,4)}else await sendCmdSeq(datasInfo5,chipType,deviceId,tempInfoJson);return dataInfo=getTempInfo(datasInfo5,chipType),dataInfo;case 6:let datasInfo6={};if(chipType){const equalizerFunData=await getSysParamCmd(chipType,deviceId,{...equalizerFunJson[0],paramLength:4});console.log("equalizerFunData: ",equalizerFunData),datasInfo6.equalizingVoltage=equalizerFunData?.slice(0,2),datasInfo6.accuracyEqualization=equalizerFunData?.slice(2,4)}else await sendCmdSeq(datasInfo6,chipType,deviceId,equalizerFunJson);return dataInfo=getEqualizerFunInfo(datasInfo6),dataInfo;case 7:let datasInfo7={};if(chipType){let capVolIndex=capVolInfoJson.findIndex(el=>34==el.paramNo),capVolIndex1=capVolInfoJson.findIndex(el=>106==el.paramNo);const capVolInfoData=await getSysParamCmd(chipType,deviceId,{...capVolInfoJson[0],paramLength:4}),capVolInfoData1=await getSysParamCmd(chipType,deviceId,{...capVolInfoJson[capVolIndex],paramLength:8}),capVolInfoData2=await getSysParamCmd(chipType,deviceId,{...capVolInfoJson[capVolIndex1],paramLength:12});console.log("capVolInfoData: ",capVolInfoData),datasInfo7.fullVolt=capVolInfoData?.slice(0,2),datasInfo7.emptyVolt=capVolInfoData?.slice(2,4),datasInfo7.voltage80p=capVolInfoData1?.slice(0,2),datasInfo7.voltage60p=capVolInfoData1?.slice(2,4),datasInfo7.voltage40p=capVolInfoData1?.slice(4,6),datasInfo7.voltage20p=capVolInfoData1?.slice(6,8),datasInfo7.voltage90p=capVolInfoData2?.slice(0,2),datasInfo7.voltage70p=capVolInfoData2?.slice(2,4),datasInfo7.voltage50p=capVolInfoData2?.slice(4,6),datasInfo7.voltage30p=capVolInfoData2?.slice(6,8),datasInfo7.voltage10p=capVolInfoData2?.slice(8,10),datasInfo7.voltage100p=capVolInfoData2?.slice(10,12)}else await sendCmdSeq(datasInfo7,chipType,deviceId,capVolInfoJson);return dataInfo=getcapVolInfoInfo(datasInfo7,chipType),dataInfo;case 9:let datasInfo9={};if(chipType){const funcAndTempFuncData=await getSysParamCmd(chipType,deviceId,{...funcAndTempFuncJson[0],paramLength:4});console.log("funcAndTempFuncData: ",funcAndTempFuncData),datasInfo9.func=funcAndTempFuncData?.slice(0,2),datasInfo9.tempFunc=funcAndTempFuncData?.slice(2,4)}else await sendCmdSeq(datasInfo9,chipType,deviceId,funcAndTempFuncJson);return dataInfo=getFuncAndTempFuncInfo(datasInfo9),dataInfo;case 10:let datasInfo10={};return await sendCmdSeq(datasInfo10,chipType,deviceId,systemJson),dataInfo=getSystemInfo(datasInfo10),dataInfo;case 11:const counts=await getProtectCountCmd(deviceId);return console.log("counts: ",counts),counts;default:if(!paramObj)return null;let defaultDataInfo={};const onedata=await getSysParamCmd(chipType,deviceId,paramObj);return defaultDataInfo[paramObj.key]=onedata?.slice(0,2),defaultDataInfo}}catch(error){throw console.error("error: 读系统参数报错 getBaseParams",error),error}},getResistance=async(chipType,deviceId)=>{try{const rsnsValue=await getSysParamCmd(chipType,deviceId,systemJson[2]);return format(rsnsValue,crsDivisor,0,2)}catch(error){throw console.error("error: 读检流阻值报错 getResistance",error),error}},getBaseInfo=async datas=>{try{console.log("datas: ",datas);const barCode=getCharCodeConnect(datas?.barCode),manufacturer=getCharCodeConnect(datas?.manufacturer),model=getCharCodeConnect(datas?.model),bmsModel=getCharCodeConnect(datas?.bmsModel,!0),producedDate=function(content){if(!content)return null;let arr=content.splice(0,2),string="0x";return arr.forEach(el=>{string+=decimalToHex(el)}),console.log(string,"string日期"),`${2e3+(string>>9)}-${string>>5&15}-${31&string}`}(datas?.producedDate);return{barCode:barCode,manufacturer:manufacturer,model:model,bmsModel:bmsModel,producedDate:producedDate,bmsAddr:function(content){if(!content)return null;return console.log(content,"content======"),toHexString(content.splice(0,12))}(datas?.bmsAddr)}}catch(error){console.error("error: ",error)}},getCharCodeConnect=(content,clearZero=!1)=>{if(console.log("content: ---------------",content),!content)return null;const length=content[0];let arr=content.splice(1,length);if(clearZero)for(;0===arr[arr.length-1];)arr.pop();return console.log("arr: -------------------",arr),String.fromCharCode(...arr)};function toHexString(arr){let string="";return arr.forEach(el=>{string+=decimalToHex(el)}),string}const getCapInfo=async datas=>{console.log("datas: ",datas);let normCap=null;if(datas.normCap&&datas.normCap.length>=4){console.log("normCap原始数据: ",datas.normCap);const lowBytes=datas.normCap.slice(0,2),lowValue=lowBytes[0]<<8|lowBytes[1];console.log("normCap lowValue: ",lowValue);const highBytes=datas.normCap.slice(2,4),highValue=highBytes[0]<<8|highBytes[1];console.log("normCap highValue: ",highValue);const totalValue=highValue<<16|lowValue;console.log("normCap totalValue: ",totalValue),normCap=Number((.01*totalValue).toFixed(2)),console.log("normCap最终值: ",normCap)}else if(datas.normCap&&datas.normCap.length>=2){const lowBytes=datas.normCap.slice(0,2),lowValue=lowBytes[0]<<8|lowBytes[1];normCap=Number((.01*lowValue).toFixed(2))}const cycleCap=format(datas.cycleCap,.01,0,2);let fullCap=null;if(datas.fullCap&&datas.fullCap.length>=4){console.log("fullCap原始数据: ",datas.fullCap);const lowBytes=datas.fullCap.slice(0,2),lowValue=lowBytes[0]<<8|lowBytes[1];console.log("fullCap lowValue: ",lowValue);const highBytes=datas.fullCap.slice(2,4),highValue=highBytes[0]<<8|highBytes[1];console.log("fullCap highValue: ",highValue);const totalValue=highValue<<16|lowValue;console.log("fullCap totalValue: ",totalValue),fullCap=Number((.01*totalValue).toFixed(2)),console.log("fullCap最终值: ",fullCap)}else if(datas.fullCap&&datas.fullCap.length>=2){const lowBytes=datas.fullCap.slice(0,2),lowValue=lowBytes[0]<<8|lowBytes[1];fullCap=Number((.01*lowValue).toFixed(2))}return{normCap:normCap,cycleCap:cycleCap,fullCap:fullCap}},getVoltageInfo=async(datas,chipType)=>{console.log("datas: ",datas);const allOvervoltageProtect=format(datas.allOvervoltageProtect,.01,0,3),allOverpressureRecovery=format(datas.allOverpressureRecovery,.01,0,3),allLowvoltageProtect=format(datas.allLowvoltageProtect,.01,0,3),allLowvoltageRecover=format(datas.allLowvoltageRecover,.01,0,3),singleOvervoltageProtect=format(datas.singleOvervoltageProtect,.001,0,3),singleOverpressureRecovery=format(datas.singleOverpressureRecovery,.001,0,3),singleLowvoltageProtect=format(datas.singleLowvoltageProtect,.001,0,3),singleLowvoltageRecover=format(datas.singleLowvoltageRecover,.001,0,3),hardwareOV=format(datas.hardwareOV,.001,0,3),hardwareUV=format(datas.hardwareUV,.001,0,3);let singleOverpressureDelay=null,singleLowvoltageDelayed=null,allLowvoltageDelay=null,allOverpressureDelay=null;return chipType?(singleOverpressureDelay=format(datas.singleOverpressureDelay,1),singleLowvoltageDelayed=format(datas.singleLowvoltageDelayed,1),allLowvoltageDelay=format(datas.allLowvoltageDelay,1),allOverpressureDelay=format(datas.allOverpressureDelay,1)):(singleLowvoltageDelayed=datas.singleLowvoltageDelayed[0],singleOverpressureDelay=datas.singleLowvoltageDelayed[1],allLowvoltageDelay=datas.allLowvoltageDelay[0],allOverpressureDelay=datas.allLowvoltageDelay[1]),{allOvervoltageProtect:allOvervoltageProtect,allOverpressureRecovery:allOverpressureRecovery,allLowvoltageProtect:allLowvoltageProtect,allLowvoltageRecover:allLowvoltageRecover,singleOvervoltageProtect:singleOvervoltageProtect,singleOverpressureRecovery:singleOverpressureRecovery,singleLowvoltageProtect:singleLowvoltageProtect,singleLowvoltageRecover:singleLowvoltageRecover,singleOverpressureDelay:singleOverpressureDelay,singleLowvoltageDelayed:singleLowvoltageDelayed,hardwareOV:hardwareOV,hardwareUV:hardwareUV,allLowvoltageDelay:allLowvoltageDelay,allOverpressureDelay:allOverpressureDelay}},getCurrentInfo=async(datas,chipType)=>{console.log("datas: ",datas);const occhg=format(datas.occhg,.01,0,3),dischargeOvercurrentProtect=(datas.dischargeOvercurrentProtect||0==datas.dischargeOvercurrentProtect)&&Number((.01*(format(datas.dischargeOvercurrentProtect,1,0,3)-65536)).toFixed(3));let chargeOvercurrentDelay=null,chargeOvercurrentRecoverDelay=null,dischargeOvercurrentDelay=null,dischargeOvercurrentRecoverDelay=null,shortcircuiProtectRecoverDelay=null,leve2OvercurrentDelay=0,level2OvercurrentProtect=0,shortcircuiProtect=0,shortcircuiProtectDelay=0,level2OvercurrentProtectV=null,overAndUnderDelay=0;return chipType?(chargeOvercurrentDelay=format(datas.chargeOvercurrentDelay,1),chargeOvercurrentRecoverDelay=format(datas.chargeOvercurrentRecoverDelay,1),dischargeOvercurrentDelay=format(datas.dischargeOvercurrentDelay,1),dischargeOvercurrentRecoverDelay=format(datas.dischargeOvercurrentRecoverDelay,1),shortcircuiProtectRecoverDelay=format(datas.shortcircuiProtectRecoverDelay,1),level2OvercurrentProtect=getNewProtectAndDelay(datas.level2OvercurrentProtect).value1,leve2OvercurrentDelay=getNewProtectAndDelay(datas.level2OvercurrentProtect).value2,shortcircuiProtect=getNewProtectAndDelay(datas.level2OvercurrentProtectV).value1,shortcircuiProtectDelay=getNewProtectAndDelay(datas.level2OvercurrentProtectV).value2):(chargeOvercurrentDelay=datas.chargeOvercurrentDelay[0],chargeOvercurrentRecoverDelay=datas.chargeOvercurrentDelay[1],dischargeOvercurrentDelay=datas.dischargeOvercurrentDelay[0],dischargeOvercurrentRecoverDelay=datas.dischargeOvercurrentDelay[1],overAndUnderDelay=datas.shortcircuiProtectRecoverDelay[0],shortcircuiProtectRecoverDelay=datas.shortcircuiProtectRecoverDelay[1],level2OvercurrentProtectV=getOldProtectAndDelay(datas.level2OvercurrentProtect).double,shortcircuiProtect=getOldProtectAndDelay(datas.level2OvercurrentProtect).value1,shortcircuiProtectDelay=getOldProtectAndDelay(datas.level2OvercurrentProtect).value2,level2OvercurrentProtect=getOldProtectAndDelay(datas.level2OvercurrentProtect).value3,leve2OvercurrentDelay=getOldProtectAndDelay(datas.level2OvercurrentProtect).value4),{occhg:occhg,dischargeOvercurrentProtect:dischargeOvercurrentProtect,chargeOvercurrentDelay:chargeOvercurrentDelay,chargeOvercurrentRecoverDelay:chargeOvercurrentRecoverDelay,dischargeOvercurrentDelay:dischargeOvercurrentDelay,dischargeOvercurrentRecoverDelay:dischargeOvercurrentRecoverDelay,leve2OvercurrentDelay:leve2OvercurrentDelay,level2OvercurrentProtectV:level2OvercurrentProtectV,shortcircuiProtectRecoverDelay:shortcircuiProtectRecoverDelay,shortcircuiProtect:shortcircuiProtect,shortcircuiProtectDelay:shortcircuiProtectDelay,level2OvercurrentProtect:level2OvercurrentProtect,overAndUnderDelay:overAndUnderDelay}};function getNewProtectAndDelay(arr){if(2!==arr?.length)return{value1:0,value2:0};let resultArray=arr.map(num=>num.toString(2).padStart(8,"0")).join("").split("").map(Number),arr1=resultArray.slice(8,12),arr2=resultArray.slice(12);return{value1:parseInt(arr1.join(""),2),value2:parseInt(arr2.join(""),2)}}function getOldProtectAndDelay(arr){if(2!==arr?.length)return{double:!1,value1:0,value2:0,value3:0,value4:0};const binaryString=arr.map(num=>num.toString(2).padStart(8,"0")).join("");console.log("【解析硬件过流及短路】",binaryString);const resultArray=binaryString.split("").map(Number),arr1=[0,...resultArray.slice(5,8)],arr2=resultArray.slice(1,5),arr3=resultArray.slice(12),arr4=resultArray.slice(8,12),value1=parseInt(arr1.join(""),2),value2=parseInt(arr2.join(""),2),value3=parseInt(arr3.join(""),2),value4=parseInt(arr4.join(""),2);return{double:1===resultArray[0],value1:value1,value2:value2,value3:value3,value4:value4}}const getTempInfo=(datas,chipType)=>{console.log("datas: ",datas);const chargeHightempProtect=formatTemp(datas.chargeHightempProtect),chargeHightempRecover=formatTemp(datas.chargeHightempRecover),chargeLowtempProtect=formatTemp(datas.chargeLowtempProtect),chargeLowtempRecover=formatTemp(datas.chargeLowtempRecover),dischargingHightempProtect=formatTemp(datas.dischargingHightempProtect),dischargingHightempRecover=formatTemp(datas.dischargingHightempRecover),dischargingLowtempProtect=formatTemp(datas.dischargingLowtempProtect),dischargingLowtempRecover=formatTemp(datas.dischargingLowtempRecover),overtempProtect=formatTemp(datas.overtempProtect),overtempRecover=formatTemp(datas.overtempRecover);let chargeHightempDelay=null,chargeLowtempDelay=null,dischargingHightempDelay=null,dischargingLowtempDelay=null;return chipType?(chargeHightempDelay=format(datas.chargeHightempDelay,1),chargeLowtempDelay=format(datas.chargeLowtempDelay,1),dischargingHightempDelay=format(datas.dischargingHightempDelay,1),dischargingLowtempDelay=format(datas.dischargingLowtempDelay,1)):(chargeHightempDelay=datas.chargeLowtempDelay[1],chargeLowtempDelay=datas.chargeLowtempDelay[0],dischargingHightempDelay=datas.dischargingLowtempDelay[1],dischargingLowtempDelay=datas.dischargingLowtempDelay[0]),{chargeHightempProtect:chargeHightempProtect,chargeHightempRecover:chargeHightempRecover,chargeLowtempProtect:chargeLowtempProtect,chargeLowtempRecover:chargeLowtempRecover,dischargingHightempProtect:dischargingHightempProtect,dischargingHightempRecover:dischargingHightempRecover,dischargingLowtempProtect:dischargingLowtempProtect,dischargingLowtempRecover:dischargingLowtempRecover,chargeHightempDelay:chargeHightempDelay,chargeLowtempDelay:chargeLowtempDelay,dischargingHightempDelay:dischargingHightempDelay,dischargingLowtempDelay:dischargingLowtempDelay,overtempProtect:overtempProtect,overtempRecover:overtempRecover}},getEqualizerFunInfo=datas=>({equalizingVoltage:format(datas.equalizingVoltage,.001,0,3),accuracyEqualization:format(datas.accuracyEqualization,1,0,2)}),getcapVolInfoInfo=datas=>({fullVolt:format(datas.fullVolt,.001,0,3),emptyVolt:format(datas.emptyVolt,.001,0,3),voltage10p:format(datas.voltage10p,.001,0,3),voltage20p:format(datas.voltage20p,.001,0,3),voltage30p:format(datas.voltage30p,.001,0,3),voltage40p:format(datas.voltage40p,.001,0,3),voltage50p:format(datas.voltage50p,.001,0,3),voltage60p:format(datas.voltage60p,.001,0,3),voltage70p:format(datas.voltage70p,.001,0,3),voltage80p:format(datas.voltage80p,.001,0,3),voltage90p:format(datas.voltage90p,.001,0,3),voltage100p:format(datas.voltage100p,.001,0,3)}),getFuncAndTempFuncInfo=datas=>{const binaryFuncArr=formatBinary(datas.func),binaryTempArr=formatBinary(datas.tempFunc),func={};funcJson.forEach((item,index)=>{item.key&&(func[item.key]=binaryFuncArr[index])});const tempFunc={};return tempFuncJson.forEach((item,index)=>{item.key&&(tempFunc[item.key]=binaryTempArr[index])}),{func:func,tempFunc:tempFunc}},splitNumberTo1Byte=(combined=0)=>({val1:255&(combined=Number(combined)),val2:combined>>8&255}),getSystemInfo=datas=>{const serialNumber=format(datas.serialNumber,1),cycleCount=format(datas.cycleCount,1),strCount=format(datas.strCount,1),rsnsValue=format(datas.rsnsValue,crsDivisor,0,2),forceUseTime=format(datas.forceUseTime,1),param1911=splitNumberTo1Byte(format(datas.param1911)).val1,param1912=splitNumberTo1Byte(format(datas.param1911)).val2,param1981=splitNumberTo1Byte(format(datas.param1981)).val1,param1982=splitNumberTo1Byte(format(datas.param1981)).val2;return{serialNumber:serialNumber,cycleCount:cycleCount,strCount:strCount,rsnsValue:rsnsValue,forceUseTime:forceUseTime,param1911:param1911,param1912:param1912,param1951:splitNumberTo1Byte(format(datas.param1951)).val1,param1952:splitNumberTo1Byte(format(datas.param1951)).val2,param1981:param1981,param1982:param1982}};export{getBaseInfo,getBaseParams,getResistance};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{hexArr2string,hex2string,decimalToHex,generateCrc16modbusCheck,hexArr2Assic,generateCrcCheckSum,hexToDecimal,stringToTwoHexArray,decimalToHex0x,sleep,fromBCD,isWithin30Minutes,toBCD}from"../BleDataProcess.js";import{getData}from"./BleCmdAnalysis.js";import{getFFAA80Async}from"./BleCmdFFAA.js";import{controlSwitch}from"./readAndSetParam.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;){if(content.length<2){console.warn("Content too short to parse, remaining:",content);break}const len=Math.min(content[1]+2,content.length),[v1,v2,...v]=content.splice(0,len);if(v.length===v2){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))}else console.warn(`Data length mismatch for type ${v1}: expected ${v2}, got ${v.length}`)}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(),BC1=(data[16]<<8|data[17]).toString(2).padStart(16,"0").split("").reverse();console.log("BC1: ",BC1);const BC2=(data[18]<<8|data[19]).toString(2).padStart(16,"0").split("").reverse(),balances=BC1.concat(BC2);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})),hasProtocol=data[3]+7>=humidityIndex+11+3+1,protocolVersion=data[humidityIndex+11];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,hasProtocol:hasProtocol,protocolVersion:protocolVersion}},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",decimalToHex0x(_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;try{if(!deviceId)throw new Error("deviceId required");const _ffaa_80=await getFFAA80Async(deviceId,"AT^VERSION?");console.warn("Report-3B3C _ffaa_80 ",{_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,reportData.bmsVersion=_3b3c?.sofewareV;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=>{try{const startTime=+new Date;let acStatus=!1;const mosRes=await controlSwitch(deviceId,"0x00",!0,!0),disChargMOSRes=mosRes?.dataStr,disChargEndTime=+new Date,activeHex=await getDD5AFBAsync(deviceId,"0x05","0x01"),activeResult=resolveBaseDD(activeHex);console.log("激活指令结果: ",{activeHex:activeHex,activeResult:activeResult});const activeRes=activeResult?.dataStr;let endTime=+new Date,baseInfo=null,voltageInfo=null,steps=[];if("00"==activeResult?.status)steps.push(4),acStatus=!0;else if("81"==activeResult?.status||"84"==activeResult?.status)"00"==mosRes?.status?(acStatus=!0,steps.push(5)):(acStatus=!1,steps.push(10));else if("82"==activeResult?.status||"83"==activeResult?.status)acStatus=!1,steps.push(6);else if(!activeResult||null==activeResult){await sleep(300);const baseInfo=await getDDA503Async(deviceId);baseInfo?.dischargeSwitch?(acStatus=!0,steps.push(7)):(acStatus=!1,steps.push(8)),endTime=+new Date}return{disChargMOSRes:disChargMOSRes,activeHex:activeHex,activeRes:activeRes,baseInfo:baseInfo,voltageInfo:voltageInfo,startTime:startTime,disChargEndTime:disChargEndTime,endTime:endTime,acStatus:acStatus,steps:steps}}catch(error){return console.log("🚀 ~ BleApiManager ~ activateAsync ~ error:",error),null}},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"),getDDA506Async=async deviceId=>getData(deviceId,{command:["0xdd","0xa5","0x06","0x00","0xff","0xfa","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&6==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_06"),resolveDDA506=data=>{if(!data)return null;if(6==data[1]&&0==data[2]&&6==data[3]){const seconds=fromBCD(data[4]),minutes=fromBCD(data[5]),hours=fromBCD(data[6]),day=fromBCD(data[7]),month=fromBCD(data[8]),timeStr=`${2e3+fromBCD(data[9])}-${String(month).padStart(2,0)}-${String(day).padStart(2,0)} ${String(hours).padStart(2,0)}:${String(minutes).padStart(2,0)}:${String(seconds).padStart(2,0)}`;return console.log("timeStr: ",timeStr,isWithin30Minutes(timeStr)),isWithin30Minutes(timeStr)}return!1},setDD5AE3sync=async deviceId=>{const now=new Date,year=now.getFullYear(),month=now.getMonth()+1,day=now.getDate(),hours=now.getHours(),minutes=now.getMinutes(),seconds=now.getSeconds(),content=["0xE3","0x07","0x06",...[toBCD(seconds),toBCD(minutes),128|toBCD(hours),toBCD(day),toBCD(month),toBCD(year-2e3)].map(b=>"0x"+b.toString(16).padStart(2,"0"))],checks=generateCrcCheckSum(content),command=["0xDD","0x5A",...content,...checks,"0x77"];return console.log("command: ",command),getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&227==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"SET_DDA5_E3")},getDDA4F0Async=async deviceId=>{const command=["0xDD","0xA4","0xF0","0x00"],checks=generateCrcCheckSum(command.slice(2)),fullCommand=[...command,...checks,"0x77"];return getData(deviceId,{command:fullCommand,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&240==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}}},"DDA4_F0")},resolveDDA4F0=data=>{if(!data)return null;if(240==data[1]&&4==data[3]){const runTime=data[4]<<24|data[5]<<16|data[6]<<8|data[7];return{runTime:runTime,runTimeHour:(runTime/3600).toFixed(2),raw:hexArr2string(data)}}return null};export{activateAsync,enterFactory,existFactory,get3B3CAsync,get3B3CInfo,getChipTypeAsync,getDD5A0AAsync,getDD5A0EAsync,getDD5A17Async,getDD5AAllAsync,getDD5AE0Async,getDD5AE1Async,getDD5AE4Async,getDD5AFAAsync,getDD5AFBAsync,getDDA4F0Async,getDDA503Async,getDDA504Async,getDDA505Async,getDDA506Async,getDDA507Async,getDDA508Async,getDDA5DCAsync,getDDA5FAAsync,getDDA5OldAsync,getProtectCountCmd,readExistFactory,resetCapacity,resolve3B3C,resolveBMSCmd,resolveBaseDD,resolveDD5A0A,resolveDDA4F0,resolveDDA500,resolveDDA503,resolveDDA504,resolveDDA505,resolveDDA506,resolveDDA508,resolveDDA5DC,resolveDDA5FA,resolveProtections,sendBMSAsync,setDD5AE3sync,setDDA5FAAsync,setDDA5OldAsync,set_PlanCMD_3B3C,set_PlanCMD_DD};
|
|
1
|
+
import{hexArr2string,hex2string,decimalToHex,generateCrc16modbusCheck,hexArr2Assic,generateCrcCheckSum,hexToDecimal,stringToTwoHexArray,decimalToHex0x,sleep,fromBCD,isWithin30Minutes,toBCD}from"../BleDataProcess.js";import{getData}from"./BleCmdAnalysis.js";import{getFFAA80Async}from"./BleCmdFFAA.js";import{controlSwitch}from"./readAndSetParam.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;){if(content.length<2){console.warn("Content too short to parse, remaining:",content);break}const len=Math.min(content[1]+2,content.length),[v1,v2,...v]=content.splice(0,len);if(v.length===v2){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))}else console.warn(`Data length mismatch for type ${v1}: expected ${v2}, got ${v.length}`)}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(),BC1=(data[16]<<8|data[17]).toString(2).padStart(16,"0").split("").reverse();console.log("BC1: ",BC1);const BC2=(data[18]<<8|data[19]).toString(2).padStart(16,"0").split("").reverse(),balances=BC1.concat(BC2);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})),hasProtocol=data[3]+7>=humidityIndex+11+3+1,protocolVersion=data[humidityIndex+11],dataUpdateTime=Date.now();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,hasProtocol:hasProtocol,protocolVersion:protocolVersion,dataUpdateTime:dataUpdateTime}},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",decimalToHex0x(_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_05=null;try{if(!deviceId)throw new Error("deviceId required");const _ffaa_80=await getFFAA80Async(deviceId,"AT^VERSION?");console.warn("Report-3B3C _ffaa_80 ",{_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,reportData.bmsVersion=_3b3c?.sofewareV;else{const _dda5_03=await getDDA503Async(deviceId);console.warn("Report-3B3C _dda5_03 ",{_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:null,_dda5_05:_dda5_05,_ffaa_80:_ffaa_80})}catch(error){reject(error)}}),activateAsync=async deviceId=>{try{const startTime=+new Date;let acStatus=!1;const mosRes=await controlSwitch(deviceId,"0x00",!0,!0),disChargMOSRes=mosRes?.dataStr,disChargEndTime=+new Date,activeHex=await getDD5AFBAsync(deviceId,"0x05","0x01"),activeResult=resolveBaseDD(activeHex);console.log("激活指令结果: ",{activeHex:activeHex,activeResult:activeResult});const activeRes=activeResult?.dataStr;let endTime=+new Date,baseInfo=null,voltageInfo=null,steps=[];if("00"==activeResult?.status)steps.push(4),acStatus=!0;else if("81"==activeResult?.status||"84"==activeResult?.status)"00"==mosRes?.status?(acStatus=!0,steps.push(5)):(acStatus=!1,steps.push(10));else if("82"==activeResult?.status||"83"==activeResult?.status)acStatus=!1,steps.push(6);else if(!activeResult||null==activeResult){await sleep(300);const baseInfo=await getDDA503Async(deviceId);baseInfo?.dischargeSwitch?(acStatus=!0,steps.push(7)):(acStatus=!1,steps.push(8)),endTime=+new Date}return{disChargMOSRes:disChargMOSRes,activeHex:activeHex,activeRes:activeRes,baseInfo:baseInfo,voltageInfo:voltageInfo,startTime:startTime,disChargEndTime:disChargEndTime,endTime:endTime,acStatus:acStatus,steps:steps}}catch(error){return console.log("🚀 ~ BleApiManager ~ activateAsync ~ error:",error),null}},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"),getDDA506Async=async deviceId=>getData(deviceId,{command:["0xdd","0xa5","0x06","0x00","0xff","0xfa","0x77"],commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&6==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_06"),resolveDDA506=(data,supportTimestamp=!1)=>{if(!data)return null;if(6!=data[1])return!1;if(supportTimestamp&&4==data[3]){const secondsSinceEpoch=(data[4]<<24|data[5]<<16|data[6]<<8|data[7])>>>0,bmsTimestampMs=1e3*secondsSinceEpoch,diff=Math.abs(Date.now()-bmsTimestampMs),thirtyMinutes=18e5,d=new Date(bmsTimestampMs),pad=n=>String(n).padStart(2,"0"),timeStr=`${d.getFullYear()}-${pad(d.getMonth()+1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;return console.log("BMS时间戳(秒):",secondsSinceEpoch,"系统时间:",timeStr,"误差(ms):",diff),{needCalibrate:diff>=thirtyMinutes,timeStr:timeStr}}if(6==data[3]){const seconds=fromBCD(data[4]),minutes=fromBCD(data[5]),hours=fromBCD(data[6]),day=fromBCD(data[7]),month=fromBCD(data[8]),timeStr=`${2e3+fromBCD(data[9])}-${String(month).padStart(2,"0")}-${String(day).padStart(2,"0")} ${String(hours).padStart(2,"0")}:${String(minutes).padStart(2,"0")}:${String(seconds).padStart(2,"0")}`;return console.log("timeStr: ",timeStr,isWithin30Minutes(timeStr)),{needCalibrate:!isWithin30Minutes(timeStr),timeStr:timeStr}}return!1},setDD5AE3sync=async deviceId=>{const now=new Date,year=now.getFullYear(),month=now.getMonth()+1,day=now.getDate(),hours=now.getHours(),minutes=now.getMinutes(),seconds=now.getSeconds(),content=["0xE3","0x07","0x06",...[toBCD(seconds),toBCD(minutes),128|toBCD(hours),toBCD(day),toBCD(month),toBCD(year-2e3)].map(b=>"0x"+b.toString(16).padStart(2,"0"))],checks=generateCrcCheckSum(content),command=["0xDD","0x5A",...content,...checks,"0x77"];return console.log("command: ",command),getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&227==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"SET_DDA5_E3")};function setDD5AE3TimestampSync(deviceId){const secondsSinceEpoch=Math.floor(Date.now()/1e3),content=["0xE3","0x04",`0x${(secondsSinceEpoch>>>24&255).toString(16).padStart(2,"0")}`,`0x${(secondsSinceEpoch>>>16&255).toString(16).padStart(2,"0")}`,`0x${(secondsSinceEpoch>>>8&255).toString(16).padStart(2,"0")}`,`0x${(255&secondsSinceEpoch).toString(16).padStart(2,"0")}`],checks=generateCrcCheckSum(content),command=["0xDD","0x5A",...content,...checks,"0x77"];return getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221===hexArr[0]&&227===hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:()=>({verified:!0})},"SET_DDA5_E3_TIMESTAMP")}const getDDA4F0Async=async deviceId=>{const command=["0xDD","0xA4","0xF0","0x00"],checks=generateCrcCheckSum(command.slice(2)),fullCommand=[...command,...checks,"0x77"];return getData(deviceId,{command:fullCommand,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&240==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}}},"DDA4_F0")},resolveDDA4F0=data=>{if(!data)return null;if(240==data[1]&&4==data[3]){const runTime=data[4]<<24|data[5]<<16|data[6]<<8|data[7];return{runTime:runTime,runTimeHour:(runTime/3600).toFixed(2),raw:hexArr2string(data)}}return null};export{activateAsync,enterFactory,existFactory,get3B3CAsync,get3B3CInfo,getChipTypeAsync,getDD5A0AAsync,getDD5A0EAsync,getDD5A17Async,getDD5AAllAsync,getDD5AE0Async,getDD5AE1Async,getDD5AE4Async,getDD5AFAAsync,getDD5AFBAsync,getDDA4F0Async,getDDA503Async,getDDA504Async,getDDA505Async,getDDA506Async,getDDA507Async,getDDA508Async,getDDA5DCAsync,getDDA5FAAsync,getDDA5OldAsync,getProtectCountCmd,readExistFactory,resetCapacity,resolve3B3C,resolveBMSCmd,resolveBaseDD,resolveDD5A0A,resolveDDA4F0,resolveDDA500,resolveDDA503,resolveDDA504,resolveDDA505,resolveDDA506,resolveDDA508,resolveDDA5DC,resolveDDA5FA,resolveProtections,sendBMSAsync,setDD5AE3TimestampSync,setDD5AE3sync,setDDA5FAAsync,setDDA5OldAsync,set_PlanCMD_3B3C,set_PlanCMD_DD};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getChipTypeAsync,getDDA503Async
|
|
1
|
+
import{getChipTypeAsync,getDDA503Async}from"./BleCmdAnalysis/BleCmdDD.js";class TelinkApi{static async checkOTAAvailable({deviceId:deviceId,macAddr:macAddr}){const prefix=macAddr.slice(0,8).toUpperCase();try{if("A5:C2:37"==prefix){const socRes=await getChipTypeAsync(deviceId);if(console.warn("芯片类型",socRes),socRes&&5==socRes?.type){const versionRes=await getDDA503Async(deviceId);return console.warn("版本信息",versionRes),!0}}}catch(error){}return!1}static isTeLink({macAddr:macAddr=""}={macAddr:""}){const prefix1=macAddr.slice(0,2).toUpperCase(),prefix=macAddr.slice(0,8).toUpperCase();return"A5"==prefix1||"A4:C1:38"==prefix}static getIndexHexArr(i){return i.toString(16).padStart(4,"0").match(/(.{2})/g)?.reverse().map(o=>`0x${o.toUpperCase()}`)}static crc16modbus(data,swapNeed=!1){let crc=65535;for(let i=0;i<data.length;i++){crc^=data[i];for(let j=0;j<8;j++)1&crc?crc=crc>>1^40961:crc>>=1}return swapNeed&&(crc=(255&crc)<<8|crc>>8&255),65535&crc}static decimalToHex(decimal,padding=4){const hexDigits=[],hexMap={10:"A",11:"B",12:"C",13:"D",14:"E",15:"F"};for(;decimal>0;){const remainder=decimal%16;remainder>=10?hexDigits.unshift(hexMap[remainder]):hexDigits.unshift(`${remainder}`),decimal=Math.floor(decimal/16)}return hexDigits.join("").padStart(padding,"0")}static genCheck(data){const hex=this.crc16modbus(data,!0),hexStr=this.decimalToHex(hex);return[`0x${hexStr.slice(0,2)}`,`0x${hexStr.slice(2,4)}`]}}export{TelinkApi};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const batteryInfoJson=crsDivisor=>[{key:"barCode",paramNo:88,paramLength:32,oldParamNo:"0xA2"},{key:"manufacturer",paramNo:56,oldParamNo:"0xA0",paramLength:32},{key:"producedDate",paramNo:5,oldParamNo:"0x15",paramLength:2},{key:"model",paramNo:.1==crsDivisor?158:316,oldParamNo:"",paramLength:24},{key:"bmsModel",paramNo:.1==crsDivisor?176:72,oldParamNo:"",paramLength:.1==crsDivisor?16:32}],capInfoJson=[{key:"normCap",paramNo:0,oldParamNo:"0x10",paramLength:2,divisor:10},{key:"cycleCap",paramNo:1,oldParamNo:"0x11",paramLength:2,divisor:10},{key:"fullCap",paramNo:112,oldParamNo:"",paramLength:2,divisor:10}],voltageInfoJson=[{key:"allOvervoltageProtect",value:"",newValue:"",unit:"V",paramNo:16,oldParamNo:"0x20",paramLength:2,divisor:100},{key:"allOverpressureRecovery",value:"",newValue:"",unit:"V",paramNo:17,oldParamNo:"0x21",paramLength:2,divisor:100},{key:"allLowvoltageProtect",value:"",newValue:"",unit:"V",paramNo:18,oldParamNo:"0x22",paramLength:2,divisor:100},{key:"allLowvoltageRecover",value:"",newValue:"",unit:"V",paramNo:19,oldParamNo:"0x23",paramLength:2,divisor:100},{key:"singleOvervoltageProtect",value:"",newValue:"",unit:"V",paramNo:20,oldParamNo:"0x24",paramLength:2,divisor:1e3},{key:"singleOverpressureRecovery",value:"",newValue:"",unit:"V",paramNo:21,oldParamNo:"0x25",paramLength:2,divisor:1e3},{key:"singleLowvoltageProtect",value:"",newValue:"",unit:"V",paramNo:22,oldParamNo:"0x26",paramLength:2,divisor:1e3},{key:"singleLowvoltageRecover",value:"",newValue:"",unit:"V",paramNo:23,oldParamNo:"0x27",paramLength:2,divisor:1e3},{key:"allLowvoltageDelay",value:"",newValue:"",unit:"S",paramNo:48,oldParamNo:"0x3C",paramLength:2,divisor:1},{key:"allOverpressureDelay",value:"",newValue:"",unit:"S",paramNo:49,oldParamNo:"",paramLength:2,divisor:1},{key:"singleLowvoltageDelayed",value:"",newValue:"",unit:"S",paramNo:50,oldParamNo:"0x3d",paramLength:2,divisor:1},{key:"singleOverpressureDelay",value:"",newValue:"",unit:"S",paramNo:51,oldParamNo:"",paramLength:2,divisor:1},{key:"hardwareOV",value:null,newValue:"",unit:"V",paramNo:38,oldParamNo:"0x36",paramLength:2,divisor:1e3},{key:"hardwareUV",value:null,newValue:"",unit:"V",paramNo:39,oldParamNo:"0x37",paramLength:2,divisor:1e3}],currentInfoJson=[{value:"",newValue:"",unit:"A",paramNo:24,oldParamNo:"0x28",paramLength:2,key:"occhg",divisor:100},{value:"",newValue:"",unit:"A",paramNo:25,oldParamNo:"0x29",paramLength:2,key:"dischargeOvercurrentProtect",divisor:1e3},{value:"",newValue:"",unit:"S",paramNo:52,oldParamNo:"0x3E",paramLength:2,key:"chargeOvercurrentDelay",divisor:1},{value:"",newValue:"",unit:"S",paramNo:53,oldParamNo:"",paramLength:2,key:"chargeOvercurrentRecoverDelay",divisor:1},{value:"",newValue:"",unit:"S",paramNo:54,oldParamNo:"0x3F",paramLength:2,key:"dischargeOvercurrentDelay",divisor:1},{value:"",newValue:"",unit:"S",paramNo:55,oldParamNo:"",paramLength:2,key:"dischargeOvercurrentRecoverDelay",divisor:1},{value:null,newValue:"",unit:"(mV)",paramNo2:"1012",paramNo:40,oldParamNo:"0x38",paramLength:2,method:!0,key:"level2OvercurrentProtect"},{value:null,newValue:"",unit:"(mS)",paramNo2:"1013",paramNo:40,oldParamNo:"",paramLength:2,method:!0,key:"leve2OvercurrentDelay"},{checked:!1,isSwitch:!0,paramNo2:"1016",paramNo:41,oldParamNo:"",paramLength:2,key:"level2OvercurrentProtectV"},{value:null,newValue:"",unit:"(mV)",paramNo2:"1014",paramNo:41,oldParamNo:"",paramLength:2,method:!0,key:"shortcircuiProtect"},{value:null,newValue:"",unit:"(uS)",paramNo2:"1015",paramNo:41,oldParamNo:"",paramLength:2,method:!0,key:"shortcircuiProtectDelay"},{value:"",newValue:"",unit:"S",paramNo:43,oldParamNo:"0x39",paramLength:2,key:"shortcircuiProtectRecoverDelay",divisor:1}],tempInfoJson=[{value:"",newValue:"",unit:"℃",paramNo:8,oldParamNo:"0x18",paramLength:2,key:"chargeHightempProtect"},{value:"",newValue:"",unit:"℃",paramNo:9,oldParamNo:"0x19",paramLength:2,key:"chargeHightempRecover"},{value:"",newValue:"",unit:"℃",paramNo:10,oldParamNo:"0x1A",paramLength:2,key:"chargeLowtempProtect"},{value:"",newValue:"",unit:"℃",paramNo:11,oldParamNo:"0x1B",paramLength:2,key:"chargeLowtempRecover"},{value:"",newValue:"",unit:"℃",paramNo:12,oldParamNo:"0x1C",paramLength:2,key:"dischargingHightempProtect"},{value:"",newValue:"",unit:"℃",paramNo:13,oldParamNo:"0x1D",paramLength:2,key:"dischargingHightempRecover"},{value:"",newValue:"",unit:"℃",paramNo:14,oldParamNo:"0x1E",paramLength:2,key:"dischargingLowtempProtect"},{value:"",newValue:"",unit:"℃",paramNo:15,oldParamNo:"0x1F",paramLength:2,key:"dischargingLowtempRecover"},{value:"",newValue:"",unit:"S",paramNo:44,oldParamNo:"0x3A",paramLength:2,key:"chargeLowtempDelay"},{value:"",newValue:"",unit:"S",paramNo:45,oldParamNo:"",paramLength:2,key:"chargeHightempDelay"},{value:"",newValue:"",unit:"S",paramNo:46,oldParamNo:"0x3B",paramLength:2,key:"dischargingLowtempDelay"},{value:"",newValue:"",unit:"S",paramNo:47,oldParamNo:"",paramLength:2,key:"dischargingHightempDelay"},{name:"",value:"",newValue:"",unit:"℃",paramNo:202,oldParamNo:"0x2E",paramLength:2,key:"overtempProtect"},{name:"",value:"",newValue:"",unit:"℃",paramNo:203,oldParamNo:"0x2F",paramLength:2,key:"overtempRecover"}],equalizerFunJson=[{value:"",newValue:"",unit:"V",paramNo:26,oldParamNo:"0x2A",paramLength:2,key:"equalizingVoltage"},{value:"",newValue:"",unit:"V",paramNo:27,oldParamNo:"0x2B",paramLength:2,key:"accuracyEqualization"}],capVolInfoJson=[{value:null,newValue:"",unit:"V",paramNo:2,oldParamNo:"0x12",paramLength:2,isHidden:!1,key:"fullVolt",divisor:1e3},{value:null,newValue:"",unit:"V",paramNo:3,oldParamNo:"0x13",paramLength:2,isHidden:!1,key:"emptyVolt",divisor:1e3},{name:"容量80%",value:"",newValue:"",unit:"V",paramNo:34,oldParamNo:"0x32",paramLength:2,key:"voltage80p",divisor:1e3},{name:"容量60%",value:"",newValue:"",unit:"V",paramNo:35,oldParamNo:"0x33",paramLength:2,key:"voltage60p",divisor:1e3},{name:"容量40%",value:"",newValue:"",unit:"V",paramNo:36,oldParamNo:"0x34",paramLength:2,key:"voltage40p",divisor:1e3},{name:"容量20%",value:"",newValue:"",unit:"V",paramNo:37,oldParamNo:"0x35",paramLength:2,key:"voltage20p",divisor:1e3},{name:"容量90%",value:"",newValue:"",unit:"V",paramNo:106,oldParamNo:"0x42",paramLength:2,key:"voltage90p",divisor:1e3},{name:"容量70%",value:"",newValue:"",unit:"V",paramNo:107,oldParamNo:"0x43",paramLength:2,key:"voltage70p",divisor:1e3},{name:"容量50%",value:"",newValue:"",unit:"V",paramNo:108,oldParamNo:"0x44",paramLength:2,key:"voltage50p",divisor:1e3},{name:"容量30%",value:"",newValue:"",unit:"V",paramNo:109,oldParamNo:"0x45",paramLength:2,key:"voltage30p",divisor:1e3},{name:"容量10%",value:"",newValue:"",unit:"V",paramNo:110,oldParamNo:"0x46",paramLength:2,key:"voltage10p",divisor:1e3},{name:"容量100%",value:"",newValue:"",unit:"V",paramNo:111,oldParamNo:"0x47",paramLength:2,key:"voltage100p",divisor:1e3}],funcAndTempFuncJson=[{paramNo:29,oldParamNo:"0x2D",paramLength:2,key:"func"},{paramNo:30,oldParamNo:"0x2E",paramLength:2,key:"tempFunc"}],funcJson=[{paramNo2:"1001",value:"",newValue:"",checked:!1,unit:"mAH",key:"onOff"},{paramNo2:"1002",value:"",newValue:"",checked:!1,unit:"mAH",key:"loadCheck"},{paramNo2:"1003",value:"",newValue:"",checked:!1,unit:"mAH",key:"equalizerFun"},{paramNo2:"1004",value:"",newValue:"",checked:!1,method:!0,unit:"mAH",key:"equalization"},{paramNo2:"1005",value:"",newValue:"",checked:!1,unit:"mAH",key:"led"},{paramNo2:"1006",value:"",newValue:"",checked:!1,unit:"mAH",key:"ledCount"},{paramNo2:"1008",value:"",newValue:"",checked:!1,unit:"mAH",key:"rtc"},{paramNo2:"1007",value:"",newValue:"",checked:!1,unit:"mAH",key:"fccLimit"},{paramNo2:"1009",value:"",newValue:"",checked:!1,unit:"mAH",key:"charingHandle"},{paramNo2:"1010",value:"",newValue:"",checked:!1,unit:"mAH",key:"gps"},{paramNo2:"1011",value:"",newValue:"",checked:!1,unit:"mAH",key:"beepDevice"}],tempFuncJson=Array.from({length:8},(_,index)=>({name:""+(0===index?"保护板温度":`电池温度${index}`),value:"",newValue:"",checked:!1,unit:"",key:`tempera${index}`})),systemJson=[{value:"",newValue:"",unit:"",paramNo:6,oldParamNo:"",paramLength:2,isHidden:!0,key:"serialNumber",divisor:1},{value:"",newValue:"",unit:"",paramNo:7,oldParamNo:"",paramLength:2,isHidden:!0,key:"cycleCount",divisor:1},{name:"检流阻值",value:"",newValue:"",unit:"mR",paramNo:28,oldParamNo:"0x2C",paramLength:2,isHidden:!1,key:"rsnsValue",divisor:1e3},{name:"串数设置",value:"",newValue:"",unit:"",paramNo:31,oldParamNo:"0x2F",paramLength:2,isHidden:!0,key:"strCount",divisor:1},{name:"自动关机",value:"",newValue:"",unit:"",paramNo:191,paramLength:2,notShow:!1,switch:!0,key:"param1911",divisor:1},{name:"低电保护功能",value:"",newValue:"",unit:"",paramNo:198,paramLength:2,notShow:!1,switch:!0,key:"param1981",divisor:1},{name:"UART协议设定",value:"",newValue:"",unit:"",paramNo:195,paramLength:2,notShow:!1,key:"param1951",divisor:1,method:!0}];export{batteryInfoJson,capInfoJson,capVolInfoJson,currentInfoJson,equalizerFunJson,funcAndTempFuncJson,funcJson,systemJson,tempFuncJson,tempInfoJson,voltageInfoJson};
|
|
1
|
+
const batteryInfoJson=crsDivisor=>[{key:"barCode",paramNo:88,paramLength:32,oldParamNo:"0xA2"},{key:"manufacturer",paramNo:56,oldParamNo:"0xA0",paramLength:32},{key:"producedDate",paramNo:5,oldParamNo:"0x15",paramLength:2},{key:"model",paramNo:.1==crsDivisor?158:316,oldParamNo:"",paramLength:24},{key:"bmsModel",paramNo:.1==crsDivisor?176:72,oldParamNo:"",paramLength:.1==crsDivisor?16:32}],capInfoJson=[{key:"normCap",paramNo:0,oldParamNo:"0x10",paramLength:2,divisor:10},{key:"cycleCap",paramNo:1,oldParamNo:"0x11",paramLength:2,divisor:10},{key:"fullCap",paramNo:112,oldParamNo:"",paramLength:2,divisor:10}],voltageInfoJson=[{key:"allOvervoltageProtect",value:"",newValue:"",unit:"V",paramNo:16,oldParamNo:"0x20",paramLength:2,divisor:100},{key:"allOverpressureRecovery",value:"",newValue:"",unit:"V",paramNo:17,oldParamNo:"0x21",paramLength:2,divisor:100},{key:"allLowvoltageProtect",value:"",newValue:"",unit:"V",paramNo:18,oldParamNo:"0x22",paramLength:2,divisor:100},{key:"allLowvoltageRecover",value:"",newValue:"",unit:"V",paramNo:19,oldParamNo:"0x23",paramLength:2,divisor:100},{key:"singleOvervoltageProtect",value:"",newValue:"",unit:"V",paramNo:20,oldParamNo:"0x24",paramLength:2,divisor:1e3},{key:"singleOverpressureRecovery",value:"",newValue:"",unit:"V",paramNo:21,oldParamNo:"0x25",paramLength:2,divisor:1e3},{key:"singleLowvoltageProtect",value:"",newValue:"",unit:"V",paramNo:22,oldParamNo:"0x26",paramLength:2,divisor:1e3},{key:"singleLowvoltageRecover",value:"",newValue:"",unit:"V",paramNo:23,oldParamNo:"0x27",paramLength:2,divisor:1e3},{key:"allLowvoltageDelay",value:"",newValue:"",unit:"S",paramNo:48,oldParamNo:"0x3C",paramLength:2,divisor:1},{key:"allOverpressureDelay",value:"",newValue:"",unit:"S",paramNo:49,oldParamNo:"",paramLength:2,divisor:1},{key:"singleLowvoltageDelayed",value:"",newValue:"",unit:"S",paramNo:50,oldParamNo:"0x3d",paramLength:2,divisor:1},{key:"singleOverpressureDelay",value:"",newValue:"",unit:"S",paramNo:51,oldParamNo:"",paramLength:2,divisor:1},{key:"hardwareOV",value:null,newValue:"",unit:"V",paramNo:38,oldParamNo:"0x36",paramLength:2,divisor:1e3},{key:"hardwareUV",value:null,newValue:"",unit:"V",paramNo:39,oldParamNo:"0x37",paramLength:2,divisor:1e3}],currentInfoJson=[{value:"",newValue:"",unit:"A",paramNo:24,oldParamNo:"0x28",paramLength:2,key:"occhg",divisor:100},{value:"",newValue:"",unit:"A",paramNo:25,oldParamNo:"0x29",paramLength:2,key:"dischargeOvercurrentProtect",divisor:1e3},{value:"",newValue:"",unit:"S",paramNo:52,oldParamNo:"0x3E",paramLength:2,key:"chargeOvercurrentDelay",divisor:1},{value:"",newValue:"",unit:"S",paramNo:53,oldParamNo:"",paramLength:2,key:"chargeOvercurrentRecoverDelay",divisor:1},{value:"",newValue:"",unit:"S",paramNo:54,oldParamNo:"0x3F",paramLength:2,key:"dischargeOvercurrentDelay",divisor:1},{value:"",newValue:"",unit:"S",paramNo:55,oldParamNo:"",paramLength:2,key:"dischargeOvercurrentRecoverDelay",divisor:1},{value:null,newValue:"",unit:"(mV)",paramNo2:"1012",paramNo:40,oldParamNo:"0x38",paramLength:2,method:!0,key:"level2OvercurrentProtect"},{value:null,newValue:"",unit:"(mS)",paramNo2:"1013",paramNo:40,oldParamNo:"",paramLength:2,method:!0,key:"leve2OvercurrentDelay"},{checked:!1,isSwitch:!0,paramNo2:"1016",paramNo:41,oldParamNo:"",paramLength:2,key:"level2OvercurrentProtectV"},{value:null,newValue:"",unit:"(mV)",paramNo2:"1014",paramNo:41,oldParamNo:"",paramLength:2,method:!0,key:"shortcircuiProtect"},{value:null,newValue:"",unit:"(uS)",paramNo2:"1015",paramNo:41,oldParamNo:"",paramLength:2,method:!0,key:"shortcircuiProtectDelay"},{value:"",newValue:"",unit:"S",paramNo:43,oldParamNo:"0x39",paramLength:2,key:"shortcircuiProtectRecoverDelay",divisor:1}],tempInfoJson=[{value:"",newValue:"",unit:"℃",paramNo:8,oldParamNo:"0x18",paramLength:2,key:"chargeHightempProtect"},{value:"",newValue:"",unit:"℃",paramNo:9,oldParamNo:"0x19",paramLength:2,key:"chargeHightempRecover"},{value:"",newValue:"",unit:"℃",paramNo:10,oldParamNo:"0x1A",paramLength:2,key:"chargeLowtempProtect"},{value:"",newValue:"",unit:"℃",paramNo:11,oldParamNo:"0x1B",paramLength:2,key:"chargeLowtempRecover"},{value:"",newValue:"",unit:"℃",paramNo:12,oldParamNo:"0x1C",paramLength:2,key:"dischargingHightempProtect"},{value:"",newValue:"",unit:"℃",paramNo:13,oldParamNo:"0x1D",paramLength:2,key:"dischargingHightempRecover"},{value:"",newValue:"",unit:"℃",paramNo:14,oldParamNo:"0x1E",paramLength:2,key:"dischargingLowtempProtect"},{value:"",newValue:"",unit:"℃",paramNo:15,oldParamNo:"0x1F",paramLength:2,key:"dischargingLowtempRecover"},{value:"",newValue:"",unit:"S",paramNo:44,oldParamNo:"0x3A",paramLength:2,key:"chargeLowtempDelay"},{value:"",newValue:"",unit:"S",paramNo:45,oldParamNo:"",paramLength:2,key:"chargeHightempDelay"},{value:"",newValue:"",unit:"S",paramNo:46,oldParamNo:"0x3B",paramLength:2,key:"dischargingLowtempDelay"},{value:"",newValue:"",unit:"S",paramNo:47,oldParamNo:"",paramLength:2,key:"dischargingHightempDelay"},{name:"",value:"",newValue:"",unit:"℃",paramNo:202,oldParamNo:"0x2E",paramLength:2,key:"overtempProtect"},{name:"",value:"",newValue:"",unit:"℃",paramNo:203,oldParamNo:"0x2F",paramLength:2,key:"overtempRecover"}],equalizerFunJson=[{value:"",newValue:"",unit:"V",paramNo:26,oldParamNo:"0x2A",paramLength:2,key:"equalizingVoltage"},{value:"",newValue:"",unit:"V",paramNo:27,oldParamNo:"0x2B",paramLength:2,key:"accuracyEqualization"}],capVolInfoJson=[{value:null,newValue:"",unit:"V",paramNo:2,oldParamNo:"0x12",paramLength:2,isHidden:!1,key:"fullVolt",divisor:1e3},{value:null,newValue:"",unit:"V",paramNo:3,oldParamNo:"0x13",paramLength:2,isHidden:!1,key:"emptyVolt",divisor:1e3},{name:"容量80%",value:"",newValue:"",unit:"V",paramNo:34,oldParamNo:"0x32",paramLength:2,key:"voltage80p",divisor:1e3},{name:"容量60%",value:"",newValue:"",unit:"V",paramNo:35,oldParamNo:"0x33",paramLength:2,key:"voltage60p",divisor:1e3},{name:"容量40%",value:"",newValue:"",unit:"V",paramNo:36,oldParamNo:"0x34",paramLength:2,key:"voltage40p",divisor:1e3},{name:"容量20%",value:"",newValue:"",unit:"V",paramNo:37,oldParamNo:"0x35",paramLength:2,key:"voltage20p",divisor:1e3},{name:"容量90%",value:"",newValue:"",unit:"V",paramNo:106,oldParamNo:"0x42",paramLength:2,key:"voltage90p",divisor:1e3},{name:"容量70%",value:"",newValue:"",unit:"V",paramNo:107,oldParamNo:"0x43",paramLength:2,key:"voltage70p",divisor:1e3},{name:"容量50%",value:"",newValue:"",unit:"V",paramNo:108,oldParamNo:"0x44",paramLength:2,key:"voltage50p",divisor:1e3},{name:"容量30%",value:"",newValue:"",unit:"V",paramNo:109,oldParamNo:"0x45",paramLength:2,key:"voltage30p",divisor:1e3},{name:"容量10%",value:"",newValue:"",unit:"V",paramNo:110,oldParamNo:"0x46",paramLength:2,key:"voltage10p",divisor:1e3},{name:"容量100%",value:"",newValue:"",unit:"V",paramNo:111,oldParamNo:"0x47",paramLength:2,key:"voltage100p",divisor:1e3}],funcAndTempFuncJson=[{paramNo:29,oldParamNo:"0x2D",paramLength:2,key:"func"},{paramNo:30,oldParamNo:"0x2E",paramLength:2,key:"tempFunc"}],funcJson=[{paramNo2:"1001",value:"",newValue:"",checked:!1,unit:"mAH",key:"onOff"},{paramNo2:"1002",value:"",newValue:"",checked:!1,unit:"mAH",key:"loadCheck"},{paramNo2:"1003",value:"",newValue:"",checked:!1,unit:"mAH",key:"equalizerFun"},{paramNo2:"1004",value:"",newValue:"",checked:!1,method:!0,unit:"mAH",key:"equalization"},{paramNo2:"1005",value:"",newValue:"",checked:!1,unit:"mAH",key:"led"},{paramNo2:"1006",value:"",newValue:"",checked:!1,unit:"mAH",key:"ledCount"},{paramNo2:"1008",value:"",newValue:"",checked:!1,unit:"mAH",key:"rtc"},{paramNo2:"1007",value:"",newValue:"",checked:!1,unit:"mAH",key:"fccLimit"},{paramNo2:"1009",value:"",newValue:"",checked:!1,unit:"mAH",key:"charingHandle"},{paramNo2:"1010",value:"",newValue:"",checked:!1,unit:"mAH",key:"gps"},{paramNo2:"1011",value:"",newValue:"",checked:!1,unit:"mAH",key:"beepDevice"}],tempFuncJson=Array.from({length:8},(_,index)=>({name:""+(0===index?"保护板温度":`电池温度${index}`),value:"",newValue:"",checked:!1,unit:"",key:`tempera${index}`})),systemJson=[{value:"",newValue:"",unit:"",paramNo:6,oldParamNo:"",paramLength:2,isHidden:!0,key:"serialNumber",divisor:1},{value:"",newValue:"",unit:"",paramNo:7,oldParamNo:"",paramLength:2,isHidden:!0,key:"cycleCount",divisor:1},{name:"检流阻值",value:"",newValue:"",unit:"mR",paramNo:28,oldParamNo:"0x2C",paramLength:2,isHidden:!1,key:"rsnsValue",divisor:1e3},{name:"串数设置",value:"",newValue:"",unit:"",paramNo:31,oldParamNo:"0x2F",paramLength:2,isHidden:!0,key:"strCount",divisor:1},{value:"",newValue:"",unit:"S",paramNo:154,oldParamNo:"",paramLength:2,isHidden:!1,key:"forceUseTime",divisor:1},{name:"自动关机",value:"",newValue:"",unit:"",paramNo:191,paramLength:2,notShow:!1,switch:!0,key:"param1911",divisor:1},{name:"低电保护功能",value:"",newValue:"",unit:"",paramNo:198,paramLength:2,notShow:!1,switch:!0,key:"param1981",divisor:1},{name:"UART协议设定",value:"",newValue:"",unit:"",paramNo:195,paramLength:2,notShow:!1,key:"param1951",divisor:1,method:!0}];export{batteryInfoJson,capInfoJson,capVolInfoJson,currentInfoJson,equalizerFunJson,funcAndTempFuncJson,funcJson,systemJson,tempFuncJson,tempInfoJson,voltageInfoJson};
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{chunk,unique}from"./core/array.js";export{bluetoothScanHandle,checkBluetoothStatus,checkLocationStatus,connectAsync,createBLEConnection,disConnect,enhanceDevice,foundScanDevice,getBLEDeviceCharacteristics,getBLEDeviceServices,getBluetoothAdapterState,getBluetoothPermission,initBle,isInit,notify,onBLECharacteristicValueChange,onBLEConnectionStateChange,onBleChangedConnectionState,onBluetoothAdapterStateChange,onBluetoothDeviceFound,onFoundDevice,scanHandle,startDevicesDiscovery,stopBluetoothDevicesDiscovery}from"./core/BleApiManager.js";export{ab2decimalArr,ab2hex,arrayBufferToHexArray,base64ToHexArray,checkSum,crc16modbus,crcCheckSum,decimalToHex,decimalToHex0x,decimalToTwoByteHexArray,extractBits,fromBCD,generateCheckSum,generateCrc16modbusCheck,generateCrcCheckSum,getParamBaseValue,hex2Ascii,hex2Binary,hex2string,hexArr2Assic,hexArr2ab,hexArr2string,hexArrayToModuleArrayBuffer,hexStrAscii,hexStringToBinary,hexToDecimal,isWithin30Minutes,parseDateTime,sleep,string2hexArr,stringToTwoHexArray,toBCD}from"./core/BleDataProcess.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{MqttServer,mqttServer}from"./core/mqttServer.js";export{OTAUpgrade}from"./core/OtaUpgrade.js";export{decrypt,decrypt2,decryptUsername,encrypt}from"./core/rsaEncrypt.js";export{tcpSend,tcpServer}from"./core/tcpServer.js";export{TelinkApi}from"./core/TelinkApi.js";export{BLE,Logger,Observer,Transfer}from"./core/Transfer.js";export{getBaseInfo,getBaseParams,getResistance}from"./core/BleCmdAnalysis/BaseParamProtocol.js";export{getData,setMTUAsync}from"./core/BleCmdAnalysis/BleCmdAnalysis.js";export{activateAsync,enterFactory,existFactory,get3B3CAsync,get3B3CInfo,getChipTypeAsync,getDD5A0AAsync,getDD5A0EAsync,getDD5A17Async,getDD5AAllAsync,getDD5AE0Async,getDD5AE1Async,getDD5AE4Async,getDD5AFAAsync,getDD5AFBAsync,getDDA4F0Async,getDDA503Async,getDDA504Async,getDDA505Async,getDDA506Async,getDDA507Async,getDDA508Async,getDDA5DCAsync,getDDA5FAAsync,getDDA5OldAsync,getProtectCountCmd,readExistFactory,resetCapacity,resolve3B3C,resolveBMSCmd,resolveBaseDD,resolveDD5A0A,resolveDDA4F0,resolveDDA500,resolveDDA503,resolveDDA504,resolveDDA505,resolveDDA506,resolveDDA508,resolveDDA5DC,resolveDDA5FA,resolveProtections,sendBMSAsync,setDD5AE3sync,setDDA5FAAsync,setDDA5OldAsync,set_PlanCMD_3B3C,set_PlanCMD_DD}from"./core/BleCmdAnalysis/BleCmdDD.js";export{getDDA420Async,getDDA421Async,getDDA422Async,getDDA423Async,getDDA425Async,getDDA426Async,getDDA427Async,getDDA429Async,resolveDDA420,resolveDDA421,resolveDDA422,resolveDDA423,resolveDDA425,resolveDDA426,resolveDDA427,resolveDDA429}from"./core/BleCmdAnalysis/BleCmdDDA4.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{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{controlSwitch,getE1Cmd,getSysParamCmd,readParamCmd,setCapacityParamCmd,setParamCmd,setSysParamCmd}from"./core/BleCmdAnalysis/readAndSetParam.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{bluetoothScanHandle,checkBluetoothStatus,checkLocationStatus,connectAsync,createBLEConnection,disConnect,enhanceDevice,foundScanDevice,getBLEDeviceCharacteristics,getBLEDeviceServices,getBluetoothAdapterState,getBluetoothPermission,initBle,isInit,notify,onBLECharacteristicValueChange,onBLEConnectionStateChange,onBleChangedConnectionState,onBluetoothAdapterStateChange,onBluetoothDeviceFound,onFoundDevice,scanHandle,startDevicesDiscovery,stopBluetoothDevicesDiscovery}from"./core/BleApiManager.js";export{ab2decimalArr,ab2hex,arrayBufferToHexArray,base64ToHexArray,checkSum,crc16modbus,crcCheckSum,decimalToHex,decimalToHex0x,decimalToTwoByteHexArray,extractBits,fromBCD,generateCheckSum,generateCrc16modbusCheck,generateCrcCheckSum,getParamBaseValue,hex2Ascii,hex2Binary,hex2string,hexArr2Assic,hexArr2ab,hexArr2string,hexArrayToModuleArrayBuffer,hexStrAscii,hexStringToBinary,hexToDecimal,isWithin30Minutes,parseDateTime,sleep,string2hexArr,stringToTwoHexArray,toBCD}from"./core/BleDataProcess.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{MqttServer,mqttServer}from"./core/mqttServer.js";export{OTAUpgrade}from"./core/OtaUpgrade.js";export{decrypt,decrypt2,decryptUsername,encrypt}from"./core/rsaEncrypt.js";export{tcpSend,tcpServer}from"./core/tcpServer.js";export{TelinkApi}from"./core/TelinkApi.js";export{BLE,Logger,Observer,Transfer}from"./core/Transfer.js";export{getBaseInfo,getBaseParams,getResistance}from"./core/BleCmdAnalysis/BaseParamProtocol.js";export{getData,setMTUAsync}from"./core/BleCmdAnalysis/BleCmdAnalysis.js";export{activateAsync,enterFactory,existFactory,get3B3CAsync,get3B3CInfo,getChipTypeAsync,getDD5A0AAsync,getDD5A0EAsync,getDD5A17Async,getDD5AAllAsync,getDD5AE0Async,getDD5AE1Async,getDD5AE4Async,getDD5AFAAsync,getDD5AFBAsync,getDDA4F0Async,getDDA503Async,getDDA504Async,getDDA505Async,getDDA506Async,getDDA507Async,getDDA508Async,getDDA5DCAsync,getDDA5FAAsync,getDDA5OldAsync,getProtectCountCmd,readExistFactory,resetCapacity,resolve3B3C,resolveBMSCmd,resolveBaseDD,resolveDD5A0A,resolveDDA4F0,resolveDDA500,resolveDDA503,resolveDDA504,resolveDDA505,resolveDDA506,resolveDDA508,resolveDDA5DC,resolveDDA5FA,resolveProtections,sendBMSAsync,setDD5AE3TimestampSync,setDD5AE3sync,setDDA5FAAsync,setDDA5OldAsync,set_PlanCMD_3B3C,set_PlanCMD_DD}from"./core/BleCmdAnalysis/BleCmdDD.js";export{getDDA420Async,getDDA421Async,getDDA422Async,getDDA423Async,getDDA425Async,getDDA426Async,getDDA427Async,getDDA429Async,resolveDDA420,resolveDDA421,resolveDDA422,resolveDDA423,resolveDDA425,resolveDDA426,resolveDDA427,resolveDDA429}from"./core/BleCmdAnalysis/BleCmdDDA4.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{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{controlSwitch,getE1Cmd,getSysParamCmd,readParamCmd,setCapacityParamCmd,setParamCmd,setSysParamCmd}from"./core/BleCmdAnalysis/readAndSetParam.js";export{batteryInfoJson,capInfoJson,capVolInfoJson,currentInfoJson,equalizerFunJson,funcAndTempFuncJson,funcJson,systemJson,tempFuncJson,tempInfoJson,voltageInfoJson}from"./core/dataJson/baseParamsJson.js";
|
package/package.json
CHANGED
|
@@ -304,8 +304,8 @@ export const onBLEConnectionStateChange = async () => {
|
|
|
304
304
|
});
|
|
305
305
|
};
|
|
306
306
|
|
|
307
|
-
// #region
|
|
308
|
-
/**
|
|
307
|
+
// #region 处理蓝牙设备连接状态变化
|
|
308
|
+
/** 处理蓝牙设备连接状态变化 */
|
|
309
309
|
export const onBleChangedConnectionState = (callback) => {
|
|
310
310
|
eventBus.on('setBleChangedConnectionState', callback);
|
|
311
311
|
};
|
|
@@ -736,7 +736,8 @@ const getSystemInfo = (datas) => {
|
|
|
736
736
|
const serialNumber = format(datas.serialNumber, 1)
|
|
737
737
|
const cycleCount = format(datas.cycleCount, 1)
|
|
738
738
|
const strCount = format(datas.strCount, 1)
|
|
739
|
-
const rsnsValue = format(datas.rsnsValue, crsDivisor, 0, 2)
|
|
739
|
+
const rsnsValue = format(datas.rsnsValue, crsDivisor, 0, 2)
|
|
740
|
+
const forceUseTime = format(datas.forceUseTime, 1)
|
|
740
741
|
const param1911 = splitNumberTo1Byte(format(datas.param1911)).val1
|
|
741
742
|
const param1912 = splitNumberTo1Byte(format(datas.param1911)).val2
|
|
742
743
|
const param1981 = splitNumberTo1Byte(format(datas.param1981)).val1
|
|
@@ -750,7 +751,8 @@ const getSystemInfo = (datas) => {
|
|
|
750
751
|
serialNumber,
|
|
751
752
|
cycleCount,
|
|
752
753
|
strCount,
|
|
753
|
-
rsnsValue,
|
|
754
|
+
rsnsValue,
|
|
755
|
+
forceUseTime,
|
|
754
756
|
param1911,
|
|
755
757
|
param1912,
|
|
756
758
|
param1951,
|
|
@@ -371,6 +371,7 @@ export const resolveDDA503 = (data) => {
|
|
|
371
371
|
const hasProtocol =
|
|
372
372
|
data[3] + 7 >= humidityIndex + 11 + 3 + 1;
|
|
373
373
|
const protocolVersion = data[humidityIndex + 11];
|
|
374
|
+
const dataUpdateTime = Date.now();
|
|
374
375
|
return {
|
|
375
376
|
cmdResp03,
|
|
376
377
|
status: hex2string(data[2]),
|
|
@@ -405,7 +406,8 @@ export const resolveDDA503 = (data) => {
|
|
|
405
406
|
fet,
|
|
406
407
|
seriesNum,
|
|
407
408
|
hasProtocol,
|
|
408
|
-
protocolVersion
|
|
409
|
+
protocolVersion,
|
|
410
|
+
dataUpdateTime,
|
|
409
411
|
};
|
|
410
412
|
}
|
|
411
413
|
|
|
@@ -1234,9 +1236,8 @@ export const get3B3CInfo = ({ deviceId, macAddr, moduleType, productType }) => {
|
|
|
1234
1236
|
reportData['bmsVersion'] = _3b3c?.sofewareV;
|
|
1235
1237
|
} /*3B3C超时 or 不支持3B3C*/ else {
|
|
1236
1238
|
// 发送DDA5_03
|
|
1237
|
-
const
|
|
1238
|
-
_dda5_03
|
|
1239
|
-
console.warn('Report-3B3C _dda5_03 ', { _dda5_03_hex, _dda5_03 });
|
|
1239
|
+
const _dda5_03 = await getDDA503Async(deviceId);
|
|
1240
|
+
console.warn('Report-3B3C _dda5_03 ', { _dda5_03 });
|
|
1240
1241
|
if (_dda5_03) reportData['bmsVersion'] = _dda5_03?.softwareV;
|
|
1241
1242
|
|
|
1242
1243
|
// 发送DDA5_05
|
|
@@ -1435,22 +1436,34 @@ export const getDDA506Async = async (deviceId) => {
|
|
|
1435
1436
|
}
|
|
1436
1437
|
|
|
1437
1438
|
/**解析BMS系统时间*/
|
|
1438
|
-
export const resolveDDA506 = (data) => {
|
|
1439
|
+
export const resolveDDA506 = (data, supportTimestamp = false) => {
|
|
1439
1440
|
if (!data) return null;
|
|
1440
|
-
if (data[1]
|
|
1441
|
-
|
|
1441
|
+
if (data[1] != 0x06) return false;
|
|
1442
|
+
|
|
1443
|
+
if (supportTimestamp && data[3] == 4) {
|
|
1444
|
+
// 时间戳模式:4字节,单位秒,高位在前
|
|
1445
|
+
const secondsSinceEpoch = ((data[4] << 24) | (data[5] << 16) | (data[6] << 8) | data[7]) >>> 0;
|
|
1446
|
+
const bmsTimestampMs = secondsSinceEpoch * 1000;
|
|
1447
|
+
const diff = Math.abs(Date.now() - bmsTimestampMs);
|
|
1448
|
+
const thirtyMinutes = 30 * 60 * 1000;
|
|
1449
|
+
const d = new Date(bmsTimestampMs);
|
|
1450
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
1451
|
+
const timeStr = `${d.getFullYear()}-${pad(d.getMonth()+1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
|
|
1452
|
+
console.log('BMS时间戳(秒):', secondsSinceEpoch, '系统时间:', timeStr, '误差(ms):', diff);
|
|
1453
|
+
return { needCalibrate: diff >= thirtyMinutes, timeStr };
|
|
1454
|
+
} else if (data[3] == 6) {
|
|
1455
|
+
// BCD时间模式:6字节
|
|
1442
1456
|
const seconds = fromBCD(data[4]);
|
|
1443
1457
|
const minutes = fromBCD(data[5]);
|
|
1444
1458
|
const hours = fromBCD(data[6]);
|
|
1445
1459
|
const day = fromBCD(data[7]);
|
|
1446
1460
|
const month = fromBCD(data[8]);
|
|
1447
1461
|
const year = 2000 + fromBCD(data[9]);
|
|
1448
|
-
const timeStr = `${year}-${String(month).padStart(2, 0)}-${String(day).padStart(2, 0)} ${String(hours).padStart(2, 0)}:${String(minutes).padStart(2, 0)}:${String(seconds).padStart(2, 0)}`;
|
|
1462
|
+
const timeStr = `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')} ${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
|
|
1449
1463
|
console.log('timeStr: ', timeStr, isWithin30Minutes(timeStr));
|
|
1450
|
-
return isWithin30Minutes(timeStr);
|
|
1451
|
-
} else {
|
|
1452
|
-
return false;
|
|
1464
|
+
return { needCalibrate: !isWithin30Minutes(timeStr), timeStr };
|
|
1453
1465
|
}
|
|
1466
|
+
return false;
|
|
1454
1467
|
}
|
|
1455
1468
|
|
|
1456
1469
|
/**设置BMS系统时间*/
|
|
@@ -1482,6 +1495,30 @@ export const resolveDDA506 = (data) => {
|
|
|
1482
1495
|
'SET_DDA5_E3'
|
|
1483
1496
|
);
|
|
1484
1497
|
}
|
|
1498
|
+
|
|
1499
|
+
export function setDD5AE3TimestampSync(deviceId) {
|
|
1500
|
+
const secondsSinceEpoch = Math.floor(Date.now() / 1000);
|
|
1501
|
+
const content = [
|
|
1502
|
+
'0xE3',
|
|
1503
|
+
'0x04',
|
|
1504
|
+
`0x${((secondsSinceEpoch >>> 24) & 0xff).toString(16).padStart(2, '0')}`,
|
|
1505
|
+
`0x${((secondsSinceEpoch >>> 16) & 0xff).toString(16).padStart(2, '0')}`,
|
|
1506
|
+
`0x${((secondsSinceEpoch >>> 8) & 0xff).toString(16).padStart(2, '0')}`,
|
|
1507
|
+
`0x${(secondsSinceEpoch & 0xff).toString(16).padStart(2, '0')}`,
|
|
1508
|
+
];
|
|
1509
|
+
const checks = generateCrcCheckSum(content);
|
|
1510
|
+
const command = ['0xDD', '0x5A', ...content, ...checks, '0x77'];
|
|
1511
|
+
|
|
1512
|
+
return getData(
|
|
1513
|
+
deviceId,
|
|
1514
|
+
{
|
|
1515
|
+
command,
|
|
1516
|
+
commandVerifyHandler: (hexArr) => ({ verified: hexArr[0] === 0xdd && hexArr[1] === 0xe3, pkgLen: hexArr[3] + 7 }),
|
|
1517
|
+
pkgVerifyHandler: () => ({ verified: true }),
|
|
1518
|
+
},
|
|
1519
|
+
'SET_DDA5_E3_TIMESTAMP'
|
|
1520
|
+
);
|
|
1521
|
+
}
|
|
1485
1522
|
|
|
1486
1523
|
/** 读取BMS运行时长 */
|
|
1487
1524
|
export const getDDA4F0Async = async (deviceId) => {
|
package/src/core/TelinkApi.js
CHANGED
|
@@ -9,8 +9,7 @@ export class TelinkApi {
|
|
|
9
9
|
const socRes = await getChipTypeAsync(deviceId);
|
|
10
10
|
console.warn('芯片类型', socRes);
|
|
11
11
|
if (socRes && socRes?.type == 5) {
|
|
12
|
-
const
|
|
13
|
-
const versionRes = resolveDDA503(versionHex);
|
|
12
|
+
const versionRes = await getDDA503Async(deviceId);
|
|
14
13
|
console.warn('版本信息', versionRes);
|
|
15
14
|
return true;
|
|
16
15
|
}
|
|
@@ -779,8 +779,19 @@ export const systemJson = [
|
|
|
779
779
|
oldParamNo: "0x2F",
|
|
780
780
|
paramLength: 2,
|
|
781
781
|
isHidden: true,
|
|
782
|
-
key: "strCount",
|
|
783
|
-
divisor: 1,
|
|
782
|
+
key: "strCount",
|
|
783
|
+
divisor: 1,
|
|
784
|
+
},
|
|
785
|
+
{
|
|
786
|
+
value: "",
|
|
787
|
+
newValue: "",
|
|
788
|
+
unit: "S",
|
|
789
|
+
paramNo: 154,
|
|
790
|
+
oldParamNo: "",
|
|
791
|
+
paramLength: 2,
|
|
792
|
+
isHidden: false,
|
|
793
|
+
key: "forceUseTime",
|
|
794
|
+
divisor: 1,
|
|
784
795
|
},
|
|
785
796
|
{
|
|
786
797
|
name: "自动关机", // 强制使用时间
|