@jiabaida/tools 1.0.3 → 1.0.7

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.
Files changed (41) hide show
  1. package/dist/cjs/core/BleApiManager.js +1 -1
  2. package/dist/cjs/core/BleCmdAnalysis/BaseParamProtocol.js +1 -1
  3. package/dist/cjs/core/BleCmdAnalysis/BleCmdAnalysis.js +1 -1
  4. package/dist/cjs/core/BleCmdAnalysis/BleCmdDD.js +1 -1
  5. package/dist/cjs/core/BleCmdAnalysis/BleCmdDDA4.js +1 -0
  6. package/dist/cjs/core/BleDataProcess.js +1 -1
  7. package/dist/cjs/core/OtaUpgrade.js +1 -1
  8. package/dist/cjs/core/Transfer.js +1 -1
  9. package/dist/cjs/core/commonfun.js +1 -1
  10. package/dist/cjs/core/dataJson/baseParamsJson.js +1 -1
  11. package/dist/cjs/core/mqttServer.js +1 -0
  12. package/dist/cjs/core/rsaEncrypt.js +1 -0
  13. package/dist/cjs/index.js +1 -1
  14. package/dist/esm/core/BleApiManager.js +1 -1
  15. package/dist/esm/core/BleCmdAnalysis/BaseParamProtocol.js +1 -1
  16. package/dist/esm/core/BleCmdAnalysis/BleCmdAnalysis.js +1 -1
  17. package/dist/esm/core/BleCmdAnalysis/BleCmdDD.js +1 -1
  18. package/dist/esm/core/BleCmdAnalysis/BleCmdDDA4.js +1 -0
  19. package/dist/esm/core/BleDataProcess.js +1 -1
  20. package/dist/esm/core/OtaUpgrade.js +1 -1
  21. package/dist/esm/core/Transfer.js +1 -1
  22. package/dist/esm/core/commonfun.js +1 -1
  23. package/dist/esm/core/dataJson/baseParamsJson.js +1 -1
  24. package/dist/esm/core/mqttServer.js +1 -0
  25. package/dist/esm/core/rsaEncrypt.js +1 -0
  26. package/dist/esm/index.js +1 -1
  27. package/package.json +4 -3
  28. package/src/core/BleApiManager.js +113 -75
  29. package/src/core/BleCmdAnalysis/BaseParamProtocol.js +35 -6
  30. package/src/core/BleCmdAnalysis/BleCmdAnalysis.js +3 -2
  31. package/src/core/BleCmdAnalysis/BleCmdDD.js +132 -5
  32. package/src/core/BleCmdAnalysis/BleCmdDDA4.js +74 -11
  33. package/src/core/BleCmdAnalysis/index.js +6 -5
  34. package/src/core/BleDataProcess.js +40 -0
  35. package/src/core/OtaUpgrade.js +16 -4
  36. package/src/core/Transfer.js +1 -1
  37. package/src/core/commonfun.js +2 -1
  38. package/src/core/dataJson/baseParamsJson.js +135 -33
  39. package/src/core/mqttServer.js +9 -9
  40. package/src/core/rsaEncrypt.js +1 -1
  41. package/src/index.js +4 -2
@@ -1 +1 @@
1
- const batteryInfoJson=[{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:158,oldParamNo:"",paramLength:24},{key:"bmsModel",paramNo:176,oldParamNo:"",paramLength:16},{key:"bmsAddr",paramNo:170,oldParamNo:"",paramLength:12}],capInfoJson=[{key:"normCap",paramNo:0,oldParamNo:"0x10",paramLength:2},{key:"cycleCap",paramNo:1,oldParamNo:"0x11",paramLength:2},{key:"fullCap",paramNo:112,oldParamNo:"",paramLength:2}],voltageInfoJson=[{key:"allOvervoltageProtect",value:"",newValue:"",unit:"V",paramNo:16,oldParamNo:"0x20",paramLength:2},{key:"allOverpressureRecovery",value:"",newValue:"",unit:"V",paramNo:17,oldParamNo:"0x21",paramLength:2},{key:"allLowvoltageProtect",value:"",newValue:"",unit:"V",paramNo:18,oldParamNo:"0x22",paramLength:2},{key:"allLowvoltageRecover",value:"",newValue:"",unit:"V",paramNo:19,oldParamNo:"0x23",paramLength:2},{key:"singleOvervoltageProtect",value:"",newValue:"",unit:"V",paramNo:20,oldParamNo:"0x24",paramLength:2},{key:"singleOverpressureRecovery",value:"",newValue:"",unit:"V",paramNo:21,oldParamNo:"0x25",paramLength:2},{key:"singleLowvoltageProtect",value:"",newValue:"",unit:"V",paramNo:22,oldParamNo:"0x26",paramLength:2},{key:"singleLowvoltageRecover",value:"",newValue:"",unit:"V",paramNo:23,oldParamNo:"0x27",paramLength:2},{key:"allLowvoltageDelay",value:"",newValue:"",unit:"S",paramNo:48,oldParamNo:"0x3C",paramLength:2},{key:"allOverpressureDelay",value:"",newValue:"",unit:"S",paramNo:49,oldParamNo:"",paramLength:2},{key:"singleLowvoltageDelayed",value:"",newValue:"",unit:"S",paramNo:50,oldParamNo:"0x3d",paramLength:2},{key:"singleOverpressureDelay",value:"",newValue:"",unit:"S",paramNo:51,oldParamNo:"",paramLength:2},{key:"hardwareOV",value:null,newValue:"",unit:"V",paramNo:38,oldParamNo:"0x36",paramLength:2},{key:"hardwareUV",value:null,newValue:"",unit:"V",paramNo:39,oldParamNo:"0x37",paramLength:2}],currentInfoJson=[{value:"",newValue:"",unit:"A",paramNo:24,oldParamNo:"0x28",paramLength:2,key:"occhg"},{value:"",newValue:"",unit:"A",paramNo:25,oldParamNo:"0x29",paramLength:2,key:"dischargeOvercurrentProtect"},{value:"",newValue:"",unit:"S",paramNo:52,oldParamNo:"0x3E",paramLength:2,key:"chargeOvercurrentDelay"},{value:"",newValue:"",unit:"S",paramNo:53,oldParamNo:"",paramLength:2,key:"chargeOvercurrentRecoverDelay"},{value:"",newValue:"",unit:"S",paramNo:54,oldParamNo:"0x3F",paramLength:2,key:"dischargeOvercurrentDelay"},{value:"",newValue:"",unit:"S",paramNo:55,oldParamNo:"",paramLength:2,key:"dischargeOvercurrentRecoverDelay"},{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"}],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"},{value:null,newValue:"",unit:"V",paramNo:3,oldParamNo:"0x13",paramLength:2,isHidden:!1,key:"emptyVolt"},{name:"容量80%",value:"",newValue:"",unit:"V",paramNo:34,oldParamNo:"0x32",paramLength:2,key:"voltage80p"},{name:"容量60%",value:"",newValue:"",unit:"V",paramNo:35,oldParamNo:"0x33",paramLength:2,key:"voltage60p"},{name:"容量40%",value:"",newValue:"",unit:"V",paramNo:36,oldParamNo:"0x34",paramLength:2,key:"voltage40p"},{name:"容量20%",value:"",newValue:"",unit:"V",paramNo:37,oldParamNo:"0x35",paramLength:2,key:"voltage20p"},{name:"容量90%",value:"",newValue:"",unit:"V",paramNo:106,oldParamNo:"0x42",paramLength:2,key:"voltage90p"},{name:"容量70%",value:"",newValue:"",unit:"V",paramNo:107,oldParamNo:"0x43",paramLength:2,key:"voltage70p"},{name:"容量50%",value:"",newValue:"",unit:"V",paramNo:108,oldParamNo:"0x44",paramLength:2,key:"voltage50p"},{name:"容量30%",value:"",newValue:"",unit:"V",paramNo:109,oldParamNo:"0x45",paramLength:2,key:"voltage30p"},{name:"容量10%",value:"",newValue:"",unit:"V",paramNo:110,oldParamNo:"0x46",paramLength:2,key:"voltage10p"},{name:"容量100%",value:"",newValue:"",unit:"V",paramNo:111,oldParamNo:"0x47",paramLength:2,key:"voltage100p"}],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"},{value:"",newValue:"",unit:"",paramNo:7,oldParamNo:"",paramLength:2,isHidden:!0,key:"cycleCount"},{name:"检流阻值",value:"",newValue:"",unit:"mR",paramNo:28,oldParamNo:"0x2C",paramLength:2,isHidden:!1,key:"rsnsValue"},{name:"串数设置",value:"",newValue:"",unit:"",paramNo:31,oldParamNo:"0x2F",paramLength:2,isHidden:!0,key:"strCount"}];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},{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};
@@ -0,0 +1 @@
1
+ import SHA256 from"crypto-js/sha256";import mqtt from"mqtt/dist/mqtt.min.js";import{set_PlanCMD_DD}from"./BleCmdAnalysis/BleCmdDD.js";import{getFFAA80Async,resolveFFAA80,set_PlanCMD_FFAA}from"./BleCmdAnalysis/BleCmdFFAA.js";import{getCMDESInfoAsync}from"./BleCmdAnalysis/BleCmdHVES.js";import{sleep}from"./BleDataProcess.js";import{decrypt}from"./rsaEncrypt.js";import{Transfer}from"./Transfer.js";class MqttServer{constructor({mqttClient:mqttClient={},MQTT_HOST:MQTT_HOST="wxs://mqtt.jiabaida.com/mqtt",DELAY_TIME:DELAY_TIME=300,networkModelUrl:networkModelUrl="https://cloud.jiabaida.com/bluetooth/server/device/networkModel",request:request}){this.timer=null,this.productKey="bms_wifi",this.is0f=!1,this.publishObj={},this.cmdCode="",this.callbackId="",this.mqttCode="",this.mqttPublish=!1,this.mqttClient=mqttClient,this.MQTT_HOST=MQTT_HOST,this.DELAY_TIME=DELAY_TIME,this.networkModelUrl=networkModelUrl,this.request=request}async getParams(item){try{return await this.request({url:`${this.networkModelUrl}?macAddr=${item.macAddr}`,method:"get"})}catch(error){throw console.error("getnetworkModel-error",error),error}}async connectMqtt(deviceObj){try{const modalData=await this.getParams(deviceObj);if(!modalData||200!==modalData.data.code)return;const mqttParam=modalData.data.data,clientId=decrypt(mqttParam.clientId),username=mqttParam.mqttUsername,password=decrypt(mqttParam.mqttSecret);console.log("连接 MQTT...");const options={clean:!0,connectTimeout:4e3,clientId:clientId,username:username,password:SHA256(password).toString(),deviceId:deviceObj.deviceId},client=mqtt.connect(this.MQTT_HOST,options);console.log("MQTT 客户端创建成功:",client),client.on("connect",res=>{console.log("res连接成功",res),client.productKey=this.productKey,this.handleMqttConnect(client,deviceObj)}),client.on("message",(topic,message)=>{this.handleMqttMessage(topic,message,client)}),client.on("reconnect",res=>console.log("MQTT 重连中...",res,client)),client.on("close",res=>this.handleMqttClose(client,res)),client.on("offline",res=>console.log("MQTT 脱机状态",res,client)),client.on("error",res=>console.error("MQTT 连接错误",res,client)),client.on("disconnect",res=>console.log("MQTT 断开连接",res,client))}catch(e){console.error("MQTT 连接异常:",e)}}handleMqttConnect(client,deviceObj){console.log("MQTT 连接成功 client",client),console.log("MQTT 连接成功 deviceObj",deviceObj),this.storeMqttClient(client),this.publishInOrder(client,deviceObj).then(()=>this.subscribeInOrder(client))}storeMqttClient(client){this.mqttClient[`${client.options.deviceId}_mqtt`]=client,console.log("存储的 MQTT 客户端:",this.mqttClient)}getTopicsAndMessages(client,deviceObj){const{productType:productType,soc:soc,moduleType:moduleType,macAddr:macAddr}=deviceObj,message=JSON.stringify({productKey:productType,soc:soc,moduleTypeKey:moduleType,macAddr:macAddr});return[{topic:`/${client.productKey}/${client.options.clientId}/device/login`,message:message}]}async publishInOrder(client,deviceObj){const topicsAndMessages=this.getTopicsAndMessages(client,deviceObj);try{for(const item of topicsAndMessages)await new Promise(resolve=>{client.publish(item.topic,item.message,()=>{resolve()})})}catch(error){console.error(`处理发布时出现错误: ${error}`)}}getSubscribeTopics(client){const{productKey:productKey}=client,clientId=client.options.clientId;return[`/${productKey}/${clientId}/device/login/reply`,`/${productKey}/${clientId}/device/passthrough/reply`,`/${productKey}/${clientId}/plat/cmd`,`/${productKey}/${clientId}/plat/passthrough`]}async subscribeInOrder(client){const subscribeTopics=this.getSubscribeTopics(client);try{for(const topic of subscribeTopics)await new Promise((resolve,reject)=>{client.subscribe(topic,err=>{err?reject(err):resolve()})})}catch(error){console.error(`订阅主题时出现错误: ${error}`)}}handleMqttMessage(topic,message,client){const clientId=topic.split("/")[2];topic!==`/${(client=Object.values(this.mqttClient).find(c=>c?.options?.clientId===clientId)||client).productKey}/${client.options.clientId}/plat/passthrough`&&topic!==`/${client.productKey}/${client.options.clientId}/plat/cmd`||this.processMessageAsync(client,message.toString())}async processMessageAsync(client,message){const msg=JSON.parse(message);this.callbackId=msg.callbackId,this.cmdCode=msg.cmdCode;let resultArray=[],codeValue=[];if("jbdPWD"===this.cmdCode){const cmdContent={2:"FFAA23010125",3:"FFAA1F010121",4:"FFAA20010122",5:"FFAA23010226"}[msg.value];codeValue=cmdContent?cmdContent.split(","):[]}else codeValue=msg.value?msg.value.split(","):[],this.is0f=2===codeValue.length;resultArray=codeValue[0]?codeValue[0].match(/.{1,2}/g):[];try{"FF"===resultArray[0]?.toUpperCase()&&"AA"===resultArray[1]?.toUpperCase()||"78"===resultArray[1]?.toUpperCase()||resultArray[1]?.toUpperCase();const publishObj={deviceId:client.options.deviceId,clientId:client.options.clientId,productKey:client.productKey,callbackId:this.callbackId,cmdCode:this.cmdCode,is0f:this.is0f,isLast:msg.isLast};this.publishObj=publishObj,this.cmdCode.toLowerCase().includes("wifi_")?await this.publishATHandle(msg.value):(this.writePublishInfoCmd(resultArray),await sleep(this.DELAY_TIME))}catch(error){console.error("error: 处理后台发指令错误",error)}}async publishATHandle(ATvalue){const{deviceId:deviceId,cmdCode:cmdCode,callbackId:callbackId,productKey:productKey,clientId:clientId,isLast:isLast}=this.publishObj,client=this.mqttClient[`${deviceId}_mqtt`];try{if(client){const hex=await getFFAA80Async(deviceId,ATvalue),res=resolveFFAA80(hex);if(res&&res.moduleVersion){const value=res.moduleVersion;client.publish(`/${productKey}/${clientId}/plat/cmd/reply`,JSON.stringify({value:value,cmdCode:cmdCode,callbackId:callbackId}),()=>{})}}isLast&&(await sleep(300),this.mqttPublish=!1,uni.removeStorageSync&&uni.removeStorageSync(`${deviceId}_mqttPublish`))}catch(error){console.error(error)}}handleMqttClose(client,res){console.log("MQTT 连接关闭",res,client),client.end(()=>{this.mqttClient[`${client.options.deviceId}_mqtt`]=null})}async publishHandle(value,baseValue,voltageValue){const client=this.mqttClient[`${this.publishObj.deviceId}_mqtt`];this.publishObj.is0f&&(value=baseValue+","+voltageValue);const msg=JSON.stringify({value:value,cmdCode:this.publishObj.cmdCode,callbackId:this.publishObj.callbackId});client&&client.publish(`/${this.publishObj.productKey}/${this.publishObj.clientId}/plat/passthrough/reply`,msg,()=>{}),this.publishObj.isLast&&(await sleep(300),this.mqttPublish=!1,uni.removeStorageSync&&uni.removeStorageSync(`${this.publishObj.deviceId}_mqttPublish`))}publishPassthroughHandle({value:value,cmdCode:cmdCode},deviceId,timeOffset=3e4){const client=this.mqttClient[`${deviceId}_mqtt`];if(client){const clientTime=(new Date).getTime(),{laseCmdCode:laseCmdCode,lastPassthroughTime:lastPassthroughTime,clientId:clientId}=client?.options;if(laseCmdCode!=cmdCode||!(lastPassthroughTime&&clientTime-lastPassthroughTime<timeOffset)){const topic=`/${client?.productKey}/${clientId}/device/passthrough`,payload=JSON.stringify({value:value,cmdCode:cmdCode,clientTime:clientTime});client.publish(topic,payload,()=>{client.options.lastPassthroughTime=clientTime,client.options.laseCmdCode=cmdCode})}}}async writePublishInfoCmd(values){clearTimeout(this.timer),this.mqttPublish=!0,this.mqttCode=values[2];let res=null;res="FF"===values[0]?.toUpperCase()&&"AA"===values[1]?.toUpperCase()?await set_PlanCMD_FFAA(this.publishObj.deviceId,values.join("")):"78"===values[1]?.toUpperCase()||"50"===values[1]?.toUpperCase()?await getCMDESInfoAsync(this.publishObj.deviceId,values.join("")):await set_PlanCMD_DD(this.publishObj.deviceId,values.join(""));const content=res?.data||[];let code=Transfer.decimalToHex(content[1]);255==content[0]&&170==content[1]&&(code=Transfer.decimalToHex(content[2])),console.log("code: 回复的code",code),code.toUpperCase()==this.mqttCode.toUpperCase()&&this.publishHandle(res?.dataStr),this.timer=setTimeout(()=>{this.mqttPublish=!1},3e4)}}export{MqttServer};
@@ -0,0 +1 @@
1
+ import JSEncrypt from"jsencrypt";const publicKey="MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANL378k3RiZHWx5AfJqdH9xRNBmD9wGD\n2iRe41HdTNF8RUhNnHit5NpMNtGL0NPTSSpPjjI1kJfVorRvaQerUgkCAwEAAQ==";function encrypt(txt){const encryptor=new JSEncrypt;return encryptor.setPublicKey(publicKey),encryptor.encrypt(txt)}function decrypt(txt){const encryptor=new JSEncrypt;return encryptor.setPrivateKey("MIIBVgIBADANBgkqhkiG9w0BAQEFAASCAUAwggE8AgEAAkEA4cWDRXldfRIqc2Mg\nJSAiKqvRGa0v7a4fC0j3YjzpxcIArm1Ui5d9DN8Ly7vGdUnltPuy7yC9nVQuW89+\nJ6PnowIDAQABAkEApgP1/l07KJ/2BTkrxwD0/smvDaFzL+QswcCa4GsIP7iBvPna\n003yp3UGSXfEZWiQzHfehW2UHB5DIh5YbghaqQIhAPkB8LWgJlsaC8WP90ztg0nl\n+6VBLiunF6dV0Q7eJzMlAiEA6ByIpg2ZvT+X8Zzmkw32Si/Aw5VZ/ulJ5D6/MKuS\nmScCIAjcRNBxrmu3dYvGH6qhGPbcNCQhOZ9cBr9xkkrRJNvxAiEAvVapUWs+wdWi\nSIFIxSRah+G0SNcH9pyunfVhWH5cs3kCIQDGArpiAGQ4WOO+tFDqUVaDXwhQnx2H\n5OGt/FZJpmDnUw=="),encryptor.decrypt(txt)}function decrypt2(txt){const encryptor=new JSEncrypt;return encryptor.setPrivateKey(publicKey),encryptor.decrypt(txt)}const decryptUsername=txt=>{const text=decrypt(txt);if(text)return text.substring(0,text.length-13)};export{decrypt,decrypt2,decryptUsername,encrypt};
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- export{chunk,unique}from"./core/array.js";export{connectAsync,createBLEConnection,disConnect,foundScanDevice,getBLEDeviceCharacteristics,getBLEDeviceServices,getBluetoothAdapterState,initBle,notify,onBLECharacteristicValueChange,onBLEConnectionStateChange,onBleChangedConnectionState,onBluetoothAdapterStateChange,onBluetoothDeviceFound,onFoundDevice,scanHandle,startDevicesDiscovery,stopBluetoothDevicesDiscovery}from"./core/BleApiManager.js";export{eventBus,formatTimeHHmm,getOS,getPlatform,inArray,isEmpty,isNotEmpty}from"./core/commonfun.js";export{ALLOWED_MAC_PREFIX,APP_KEY_STATUS,extractModuleInfo,getRandomNum,getTypeBuyCmd,handleNewAppKey,handleOldAppKey,sendAppKey,sendEnableOrVerifyKey,sendOldAppKey,sendVerifyPwd,sendWrite1LevelPwd,verify3LevelPassword,verifyMacAddrAndKey}from"./core/keyAndPwdManager.js";export{OTAUpgrade}from"./core/OtaUpgrade.js";export{TelinkApi}from"./core/TelinkApi.js";export{BLE,Logger,Observer,Transfer}from"./core/Transfer.js";export{ab2decimalArr,ab2hex,arrayBufferToHexArray,base64ToHexArray,checkSum,crc16modbus,crcCheckSum,decimalToHex,decimalToHex0x,decimalToTwoByteHexArray,extractBits,generateCheckSum,generateCrc16modbusCheck,generateCrcCheckSum,getParamBaseValue,hex2Ascii,hex2Binary,hex2string,hexArr2Assic,hexArr2ab,hexArr2string,hexArrayToModuleArrayBuffer,hexStrAscii,hexStringToBinary,hexToDecimal,sleep,string2hexArr,stringToTwoHexArray}from"./core/BleDataProcess.js";export{getData,setMTUAsync}from"./core/BleCmdAnalysis/BleCmdAnalysis.js";export{clearPrimaryKey,getBluetoothName,getBroadcastDataCmd,getFFAA03Async,getFFAA17Async,getFFAA25Async,getFFAA26Async,getFFAA80Async,getFFAAKeyAsync,getWiFiIP,resetFactoryData,resetSecondaryKey,resolveFFAA25,resolveFFAA26,resolveFFAA80,resolveFFAAKey,setBluetoothName,setWiFi,setWiFiSta,set_PlanCMD_FFAA,set_PlanCMD_FFAA80}from"./core/BleCmdAnalysis/BleCmdFFAA.js";export{activateAsync,enterFactory,existFactory,get3B3CAsync,get3B3CInfo,getChipTypeAsync,getDD5A0AAsync,getDD5A0EAsync,getDD5A17Async,getDD5AAllAsync,getDD5AE0Async,getDD5AE1Async,getDD5AE4Async,getDD5AFAAsync,getDD5AFBAsync,getDDA503Async,getDDA504Async,getDDA505Async,getDDA507Async,getDDA508Async,getDDA5DCAsync,getDDA5FAAsync,getDDA5OldAsync,getProtectCountCmd,readExistFactory,resetCapacity,resolve3B3C,resolveBMSCmd,resolveBaseDD,resolveDD5A0A,resolveDDA500,resolveDDA503,resolveDDA504,resolveDDA505,resolveDDA508,resolveDDA5DC,resolveDDA5FA,resolveProtections,sendBMSAsync,setDDA5FAAsync,setDDA5OldAsync,set_PlanCMD_3B3C,set_PlanCMD_DD}from"./core/BleCmdAnalysis/BleCmdDD.js";export{getSysParamCmd,readParamCmd,setCapacityParamCmd,setParamCmd,setSysParamCmd}from"./core/BleCmdAnalysis/readAndSetParam.js";export{getBaseInfo,getBaseParams,getResistance}from"./core/BleCmdAnalysis/BaseParamProtocol.js";export{getCMDESInfoAsync,getHVESInfoAsync,resolveHVESBMUInfo,resolveHVESBaseInfo,resolveHVESCalibrationC1Info,resolveHVESCalibrationC2Info,resolveHVESCalibrationConfigInfo,resolveHVESCalibrationInfo,resolveHVESCtInfo,resolveHVESDisCtInfo,resolveHVESElectrodeHTInfo,resolveHVESEtInfo,resolveHVESInsulationLRInfo,resolveHVESLSocInfo,resolveHVESMonoVolInfo,resolveHVESOeInfo,resolveHVESOtRisingInfo,resolveHVESOtrInfo,resolveHVESOvrInfo,resolveHVESPackInfo,resolveHVESParamsInfo,resolveHVESSumInfo,resolveHVESSumVolInfo,resolveHVESVersionInfo}from"./core/BleCmdAnalysis/BleCmdHVES.js";export{HostProtocol}from"./core/BleCmdAnalysis/ESHostProtocol.js";export{batteryInfoJson,capInfoJson,capVolInfoJson,currentInfoJson,equalizerFunJson,funcAndTempFuncJson,funcJson,systemJson,tempFuncJson,tempInfoJson,voltageInfoJson}from"./core/dataJson/baseParamsJson.js";
1
+ export{chunk,unique}from"./core/array.js";export{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}from"./core/mqttServer.js";export{OTAUpgrade}from"./core/OtaUpgrade.js";export{decrypt,decrypt2,decryptUsername,encrypt}from"./core/rsaEncrypt.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{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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jiabaida/tools",
3
- "version": "1.0.3",
3
+ "version": "1.0.7",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "exports": {
@@ -15,6 +15,7 @@
15
15
  "./OtaUpgrade": "./dist/esm/core/OtaUpgrade.js",
16
16
  "./TelinkApi": "./dist/esm/core/TelinkApi.js",
17
17
  "./Transfer": "./dist/esm/core/Transfer.js",
18
+ "./mqttServer": "./dist/esm/core/mqttServer.js",
18
19
  "./index": "./src/index.js"
19
20
  },
20
21
  "files": [
@@ -36,6 +37,7 @@
36
37
  "@babel/core": "^7.28.0",
37
38
  "@babel/preset-env": "^7.28.0",
38
39
  "@rollup/plugin-babel": "^6.0.4",
40
+ "@rollup/plugin-commonjs": "^25.0.8",
39
41
  "@rollup/plugin-node-resolve": "^16.0.1",
40
42
  "babel-jest": "^30.0.5",
41
43
  "jest": "^30.0.5",
@@ -43,7 +45,6 @@
43
45
  "rollup-plugin-terser": "^7.0.2"
44
46
  },
45
47
  "dependencies": {
46
- "crypto-js": "^4.2.0",
47
- "mqtt": "^5.14.1"
48
+
48
49
  }
49
50
  }
@@ -4,18 +4,22 @@ import { eventBus, getOS } from './commonfun'; // 导入eventBus
4
4
  const serviceId = '0000FF00-0000-1000-8000-00805F9B34FB';
5
5
  const UUID_READ = '0000FF01-0000-1000-8000-00805F9B34FB';
6
6
  const UUID_WRITE = '0000FF02-0000-1000-8000-00805F9B34FB';
7
-
7
+ const { isAndroid, isIOS } = getOS();
8
8
  const bluetoothAdapterState = ref({
9
9
  available: false,
10
10
  discovering: false,
11
11
  });
12
+
13
+
14
+ export var isInit = false;
15
+
12
16
  // #region 处理广播的设备信息
13
17
  /**
14
18
  * 处理广播的设备信息
15
19
  * @param {*} device
16
20
  * @returns 处理后的设备信息
17
21
  */
18
- const enhanceDevice = (device) => {
22
+ export const enhanceDevice = (device) => {
19
23
  const adv = device?.advertisData;
20
24
  if (!adv) return null;
21
25
  if (adv) {
@@ -34,7 +38,13 @@ const enhanceDevice = (device) => {
34
38
  const socHex = advHex.slice(16, 18);
35
39
  const soc = socHex || socHex == 0 ? hexToDecimal(socHex) : '';
36
40
  const productType = advHex.slice(18, 20);
37
- const protocolVersion = advHex.slice(20, 22);
41
+ let protocolVersion = advHex.slice(20, 22);
42
+ if (protocolVersion) {
43
+ const v = hexToDecimal(protocolVersion)
44
+ if (macAddr.startsWith("A5:C2") && v <= 0x23) {
45
+ protocolVersion = '01';
46
+ }
47
+ }
38
48
  const appkeyStatus = advHex.slice(22, 24);
39
49
  const tempVoltage = advHex.slice(24, 26);
40
50
  const voltage = tempVoltage || tempVoltage == 0 ? hexToDecimal(tempVoltage) : '';
@@ -46,82 +56,108 @@ const enhanceDevice = (device) => {
46
56
  }
47
57
  return device;
48
58
  }
49
- // #region 初始化蓝牙
50
- /** 初始化蓝牙 */
51
- export const initBle = async () => {
52
- const checkBluetoothStatus = async () => {
53
- return new Promise((resolve, reject) => {
54
- uni.openBluetoothAdapter({
55
- success: async (res) => {
56
- console.log('openBluetoothAdapter success', res);
57
- resolve(res);
58
- try {
59
- // await startDevicesDiscovery(false);
60
- // stopBluetoothDevicesDiscovery();
61
- onBluetoothDeviceFound();
62
- onBLECharacteristicValueChange();
63
- onBLEConnectionStateChange();
64
- onBluetoothAdapterStateChange()
65
- } catch (error) {
66
- console.log('error: ', error);
67
- reject(error);
68
- }
69
- },
70
- fail: (err) => {
71
- console.log('openBluetoothAdapter fail', err);
72
- reject(err);
73
- },
74
- });
75
- });
76
- };
77
- const checkLocationStatus = async () => {
78
- // 创建超时Promise
79
- const timeoutPromise = new Promise((resolve, reject) => {
80
- setTimeout(() => {
81
- reject(new Error('网络信号差或连接异常,请检查网络情况'));
82
- }, 10000); // 10秒超时
59
+
60
+ /**
61
+ * 状态码:
62
+ * 101:网络信号差或连接异常,请检查网络情况 --- 打开定位开关
63
+ * 102:当前手机蓝牙不可用,请检查手机蓝牙状态 --- 打开蓝牙开关 openSystemBluetoothSetting
64
+ * 103:请授权小程序位置信息权限, 并重启小程序。--- 打开小程序设置页面 openSetting
65
+ * 104:请授权微信位置信息权限, 并重启小程序。 --- 打开手机内微信权限设置页面 openAppAuthorizeSetting
66
+ * 105:请授权微信位置信息和蓝牙权限 --- 打开手机内微信权限设置页面 openAppAuthorizeSetting
67
+ * 106:请授权蓝牙和位置权限,并重启小程序 --- 打开小程序设置页面 openSetting
68
+ */
69
+ export const checkBluetoothStatus = async (successCallback = () => {}) => {
70
+ return new Promise((resolve, reject) => {
71
+ uni.openBluetoothAdapter({
72
+ success: async (res) => {
73
+ if (successCallback) {
74
+ successCallback(res);
75
+ }
76
+ resolve(res);
77
+ },
78
+ fail: (err) => {
79
+ console.log('openBluetoothAdapter fail4-----', err);
80
+ if (err && err?.errno == 3) {
81
+ reject({ code: 105, message: '请授权微信位置信息和蓝牙权限' });
82
+ }
83
+ if (err && err?.errno == 103) {
84
+ reject({ code: 106, message: '请授权蓝牙和位置权限,并重启小程序' });
85
+ }
86
+ reject({ code: 102, message: '当前手机蓝牙不可用,请检查手机蓝牙状态' });
87
+ },
83
88
  });
84
- // 创建位置获取Promise
85
- const locationPromise = new Promise((resolve, reject) => {
86
- uni.getLocation({
87
- type: 'wgs84',
88
- success: (res) => {
89
- console.log('位置信息-----------', res);
90
- resolve(res);
91
- },
92
- fail: (err) => {
93
- console.log('位置信息err', err);
94
- reject(err);
95
- },
96
- });
89
+ });
90
+ }
91
+
92
+ export const checkLocationStatus = async (successCallback = () => {}) => {
93
+ // 创建超时Promise
94
+ const timeoutPromise = new Promise((resolve, reject) => {
95
+ setTimeout(() => {
96
+ reject({ code: 101, message: '网络信号差或连接异常,请检查网络情况' });
97
+ }, 10000); // 10秒超时
98
+ });
99
+ // 创建位置获取Promise
100
+ const locationPromise = new Promise((resolve, reject) => {
101
+ uni.getLocation({
102
+ type: 'wgs84',
103
+ success: (res) => {
104
+ console.log('位置信息-----------', res);
105
+ resolve(res);
106
+ },
107
+ fail: (err) => {
108
+ console.log('位置信息err', err);
109
+ if (err && err?.errno == 103) {
110
+ reject({ code: 103, message: '请授权小程序位置信息权限, 并重启小程序。' });
111
+ }
112
+ if (err && err?.errCode == 2) {
113
+ reject({ code: 101, message: '网络信号差或连接异常,请检查网络情况' });
114
+ }
115
+ reject({ code: 104, message: '请授权微信位置信息权限, 并重启小程序。' });
116
+ },
97
117
  });
98
- // 使用Promise.race实现超时控制
99
- Promise.race([locationPromise, timeoutPromise])
100
- .then((res) => {
101
- // 成功获取位置信息
102
- checkBluetoothStatus();
103
- })
104
- .catch((err) => {
105
- console.log('位置获取失败或超时:', err);
106
- Promise.reject({
107
- code: 1,
108
- // message: '请检查手机位置是否开启',
109
- });
110
- });
111
- };
118
+ });
119
+ // 使用Promise.race实现超时控制
120
+ return Promise.race([locationPromise, timeoutPromise])
121
+ .then(async (res) => {
122
+ // 成功获取位置信息
123
+ return await checkBluetoothStatus(successCallback);
124
+ })
125
+ }
126
+
127
+ export const getBluetoothPermission = async (successCallback = () => {}) => {
112
128
  try {
113
- const { isAndroid } = getOS();
114
129
  if (isAndroid) {
115
- checkLocationStatus();
130
+ return await checkLocationStatus(successCallback);
116
131
  } else {
117
- checkBluetoothStatus();
132
+ return await checkBluetoothStatus(successCallback);
118
133
  }
119
134
  } catch (error) {
120
135
  console.error('初始化蓝牙失败:', error);
121
- Promise.reject({
122
- code: error.code || error.errCode || -1,
123
- });
136
+ throw (error);
124
137
  }
138
+ }
139
+
140
+ // #region 初始化蓝牙
141
+ /** 初始化蓝牙
142
+ * 错误码:
143
+ * 101:网络信号差或连接异常,请检查网络情况
144
+ * 102:当前手机蓝牙不可用,请检查手机蓝牙状态
145
+ */
146
+ export const initBle = async () => {
147
+ const initBluetoothSuccessCb = () => {
148
+ console.log('初始化蓝牙成功initBluetoothSuccessCb1');
149
+ try {
150
+ if(isInit) return;
151
+ onBluetoothDeviceFound();
152
+ onBLECharacteristicValueChange();
153
+ onBLEConnectionStateChange();
154
+ onBluetoothAdapterStateChange()
155
+ isInit = true;
156
+ } catch (error) {
157
+ throw error;
158
+ }
159
+ }
160
+ return await getBluetoothPermission(initBluetoothSuccessCb);
125
161
  };
126
162
  // #region 获取蓝牙适配器状态
127
163
  /** 获取蓝牙适配器状态 */
@@ -171,6 +207,10 @@ export const startDevicesDiscovery = async (allowDuplicatesKey = true) => {
171
207
  // #region 停止搜索蓝牙设备
172
208
  /**停止搜索蓝牙设备 */
173
209
  export const stopBluetoothDevicesDiscovery = async () => {
210
+ bluetoothAdapterState.value = {
211
+ available: bluetoothAdapterState.value.available,
212
+ discovering: false,
213
+ }
174
214
  return new Promise((resolve, reject) => {
175
215
  uni.stopBluetoothDevicesDiscovery({
176
216
  success: (res) => {
@@ -435,8 +475,6 @@ export const scanHandle = (historyConnectedList = [], connectFn = (device) => {
435
475
  isMac = true;
436
476
  }
437
477
  }
438
-
439
- const { isAndroid } = getOS();
440
478
  // 检查历史连接列表是否已包含该设备
441
479
  const matchedHistoryDevice = historyConnectedList.find((item) => item.macAddr == searchKey);
442
480
  if (matchedHistoryDevice) {
@@ -458,6 +496,8 @@ export const scanHandle = (historyConnectedList = [], connectFn = (device) => {
458
496
  }
459
497
  },
460
498
  complete: (err) => {
499
+ },
500
+ fail: (err) => {
461
501
  console.log('scanCode err', err);
462
502
  failScanFn(err)
463
503
  }
@@ -466,7 +506,7 @@ export const scanHandle = (historyConnectedList = [], connectFn = (device) => {
466
506
  // #region 广播5秒
467
507
  export const foundScanDevice = async (result, connectFn) => {
468
508
  const deviceList = [];
469
- await startDevicesDiscovery();
509
+ await startDevicesDiscovery(isIOS);
470
510
  onFoundDevice((device) => {
471
511
  deviceList.push(device)
472
512
  const findDevice = device.macAddr === result || device.name === result;
@@ -485,8 +525,6 @@ export const foundScanDevice = async (result, connectFn) => {
485
525
  try {
486
526
  // 五秒后停止搜索且关闭轮询器
487
527
  console.log('stopBluetoothDevicesDiscovery', deviceList);
488
- clearInterval(scanTimer);
489
- scanTimer = null;
490
528
  uni.stopBluetoothDevicesDiscovery();
491
529
  const findDevice = deviceList.find((device) => device.macAddr === result || device.name === result);
492
530
  connectFn(findDevice);
@@ -1,8 +1,8 @@
1
-
2
1
  import { getSysParamCmd } from './readAndSetParam'
3
2
  import { decimalToHex, hexToDecimal } from '../BleDataProcess';
4
- import { batteryInfoJson, capInfoJson, voltageInfoJson, currentInfoJson, tempInfoJson, equalizerFunJson, capVolInfoJson, funcJson, tempFuncJson, systemJson, funcAndTempFuncJson } from '../dataJson/baseParamsJson.js'
3
+ import { batteryInfoJson, capInfoJson, voltageInfoJson,currentInfoJson, tempInfoJson, equalizerFunJson, capVolInfoJson, funcJson, tempFuncJson, systemJson, funcAndTempFuncJson } from '../dataJson/baseParamsJson.js';
5
4
  import { readExistFactory, getProtectCountCmd, enterFactory } from './BleCmdDD.js'
5
+
6
6
  /**
7
7
  *
8
8
  * @param {*} value 原始十进制值字数组
@@ -111,7 +111,7 @@ export const getBaseParams = async (chipType, deviceData, index, paramObj) => {
111
111
  switch (index) {
112
112
  case 1:
113
113
  let datasInfo1 = {};
114
- await sendCmdSeq(datasInfo1, chipType, deviceId, batteryInfoJson)
114
+ await sendCmdSeq(datasInfo1, chipType, deviceId, batteryInfoJson(crsDivisor))
115
115
  dataInfo = getBaseInfo(datasInfo1)
116
116
  return dataInfo
117
117
  case 2:
@@ -188,9 +188,11 @@ export const getBaseParams = async (chipType, deviceData, index, paramObj) => {
188
188
  if (chipType) {
189
189
  let tindex = tempInfoJson.findIndex((el) => el.paramNo == 8)
190
190
  let tindex1 = tempInfoJson.findIndex((el) => el.paramNo == 44)
191
+ let tindex2 = tempInfoJson.findIndex((el) => el.paramNo == 202)
191
192
  const tempData = await getSysParamCmd(chipType, deviceId, { ...tempInfoJson[tindex], paramLength: 16 })
192
193
  const tempData1 = await getSysParamCmd(chipType, deviceId, { ...tempInfoJson[tindex1], paramLength: 8 })
193
- console.log('tempData: ', tempData);
194
+ const tempData2 = await getSysParamCmd(chipType, deviceId, { ...tempInfoJson[tindex2], paramLength: 4 })
195
+ console.log('tempData: ', tempData, tempData2);
194
196
  datasInfo5['chargeHightempProtect'] = tempData?.slice(0, 2)
195
197
  datasInfo5['chargeHightempRecover'] = tempData?.slice(2, 4)
196
198
  datasInfo5['chargeLowtempProtect'] = tempData?.slice(4, 6)
@@ -203,6 +205,8 @@ export const getBaseParams = async (chipType, deviceData, index, paramObj) => {
203
205
  datasInfo5['chargeHightempDelay'] = tempData1?.slice(2, 4)
204
206
  datasInfo5['dischargingLowtempDelay'] = tempData1?.slice(4, 6)
205
207
  datasInfo5['dischargingHightempDelay'] = tempData1?.slice(6, 8)
208
+ datasInfo5['overtempProtect'] = tempData2?.slice(0, 2)
209
+ datasInfo5['overtempRecover'] = tempData2?.slice(2, 4)
206
210
  } else {
207
211
  await sendCmdSeq(datasInfo5, chipType, deviceId, tempInfoJson)
208
212
  }
@@ -433,7 +437,7 @@ const getCurrentInfo = async (datas, chipType) => {
433
437
  console.log('datas: ', datas);
434
438
  const occhg = format(datas.occhg, 0.01, 0, 3)
435
439
  // 采用补码形式传送
436
- const dischargeOvercurrentProtect = (datas.dischargeOvercurrentProtect || datas.dischargeOvercurrentProtect == 0) && (format(datas.dischargeOvercurrentProtect, 1, 0, 3) - 0x10000) * 0.01
440
+ const dischargeOvercurrentProtect = (datas.dischargeOvercurrentProtect || datas.dischargeOvercurrentProtect == 0) && Number(((format(datas.dischargeOvercurrentProtect, 1, 0, 3) - 0x10000) * 0.01).toFixed(3))
437
441
 
438
442
  let chargeOvercurrentDelay = null
439
443
  let chargeOvercurrentRecoverDelay = null
@@ -546,6 +550,8 @@ const getTempInfo = (datas, chipType) => {
546
550
  const dischargingHightempRecover = formatTemp(datas.dischargingHightempRecover)
547
551
  const dischargingLowtempProtect = formatTemp(datas.dischargingLowtempProtect)
548
552
  const dischargingLowtempRecover = formatTemp(datas.dischargingLowtempRecover)
553
+ const overtempProtect = formatTemp(datas.overtempProtect)
554
+ const overtempRecover = formatTemp(datas.overtempRecover)
549
555
  let chargeHightempDelay = null
550
556
  let chargeLowtempDelay = null
551
557
  let dischargingHightempDelay = null
@@ -573,7 +579,9 @@ const getTempInfo = (datas, chipType) => {
573
579
  chargeHightempDelay,
574
580
  chargeLowtempDelay,
575
581
  dischargingHightempDelay,
576
- dischargingLowtempDelay
582
+ dischargingLowtempDelay,
583
+ overtempProtect,
584
+ overtempRecover
577
585
  }
578
586
  }
579
587
 
@@ -631,11 +639,26 @@ const getFuncAndTempFuncInfo = (datas) => {
631
639
  })
632
640
  return { func, tempFunc }
633
641
  }
642
+
643
+ const splitNumberTo1Byte = (combined = 0) => {
644
+ combined = Number(combined);
645
+ return {
646
+ val1: combined & 0xFF,
647
+ val2: (combined >> 8) & 0xFF
648
+ };
649
+ }
650
+
634
651
  const getSystemInfo = (datas) => {
635
652
  const serialNumber = format(datas.serialNumber, 1)
636
653
  const cycleCount = format(datas.cycleCount, 1)
637
654
  const strCount = format(datas.strCount, 1)
638
655
  const rsnsValue = format(datas.rsnsValue, crsDivisor, 0, 2)
656
+ const param1911 = splitNumberTo1Byte(format(datas.param1911)).val1
657
+ const param1912 = splitNumberTo1Byte(format(datas.param1911)).val2
658
+ const param1981 = splitNumberTo1Byte(format(datas.param1981)).val1
659
+ const param1982 = splitNumberTo1Byte(format(datas.param1981)).val2
660
+ const param1951 = splitNumberTo1Byte(format(datas.param1951)).val1
661
+ const param1952 = splitNumberTo1Byte(format(datas.param1951)).val2
639
662
  // const identifyCurrent = format(datas.identifyCurrent, 1)
640
663
  // const sleepTime = format(datas.sleepTime, 1)
641
664
  // const capacityInterval = format(datas.capacityInterval, 1)
@@ -644,6 +667,12 @@ const getSystemInfo = (datas) => {
644
667
  cycleCount,
645
668
  strCount,
646
669
  rsnsValue,
670
+ param1911,
671
+ param1912,
672
+ param1951,
673
+ param1952,
674
+ param1981,
675
+ param1982,
647
676
  // identifyCurrent,
648
677
  // sleepTime,
649
678
  // capacityInterval
@@ -1,5 +1,5 @@
1
- import { hexArr2ab, ab2decimalArr, hexArr2string, sleep } from '../BleDataProcess';
2
- import { getOS, eventBus, getPlatform } from '../commonfun';
1
+ import { ab2decimalArr, hexArr2ab, hexArr2string, sleep } from '../BleDataProcess';
2
+ import { eventBus, getOS, getPlatform } from '../commonfun';
3
3
 
4
4
  const BLE_RESPONSE_TIMEOUT = 300; // 蓝牙指令响应超时
5
5
  const STORE_MUTATION_NAME = 'setBleChangedCharacteristicValue';
@@ -21,6 +21,7 @@ async function _writeAsync(deviceId, value) {
21
21
  console.log('platform: ', platform);
22
22
  console.log('isAndroid, isIOS: ', isAndroid, isIOS);
23
23
  const writeType = platform === 'mp-weixin' ? 'writeNoResponse' : isAndroid ? 'writeNoResponse' : 'write';
24
+ console.log('writeType: ', writeType);
24
25
  uni.writeBLECharacteristicValue({
25
26
  deviceId,
26
27
  serviceId,