@jiabaida/tools 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/core/BleApiManager.js +1 -1
- package/dist/cjs/core/BleCmdAnalysis/BaseParamProtocol.js +1 -0
- package/dist/cjs/core/BleCmdAnalysis/BleCmdAnalysis.js +1 -0
- package/dist/cjs/core/BleCmdAnalysis/BleCmdDD.js +1 -0
- package/dist/cjs/core/BleCmdAnalysis/BleCmdFFAA.js +1 -0
- package/dist/cjs/core/BleCmdAnalysis/BleCmdHVES.js +1 -0
- package/dist/cjs/core/BleCmdAnalysis/ESHostProtocol.js +1 -0
- package/dist/cjs/core/BleCmdAnalysis/readAndSetParam.js +1 -0
- package/dist/cjs/core/BleCmdAnalysis.js +1 -0
- package/dist/cjs/core/BleDataProcess.js +1 -0
- package/dist/cjs/core/OtaUpgrade.js +1 -0
- package/dist/cjs/core/TelinkApi.js +1 -0
- package/dist/cjs/core/Transfer.js +1 -0
- package/dist/cjs/core/commonfun.js +1 -1
- package/dist/cjs/core/dataJson/baseParamsJson.js +1 -0
- package/dist/cjs/core/keyAndPwdManager.js +1 -0
- package/dist/cjs/index.js +1 -1
- package/dist/esm/core/BleApiManager.js +1 -1
- package/dist/esm/core/BleCmdAnalysis/BaseParamProtocol.js +1 -0
- package/dist/esm/core/BleCmdAnalysis/BleCmdAnalysis.js +1 -0
- package/dist/esm/core/BleCmdAnalysis/BleCmdDD.js +1 -0
- package/dist/esm/core/BleCmdAnalysis/BleCmdFFAA.js +1 -0
- package/dist/esm/core/BleCmdAnalysis/BleCmdHVES.js +1 -0
- package/dist/esm/core/BleCmdAnalysis/ESHostProtocol.js +1 -0
- package/dist/esm/core/BleCmdAnalysis/readAndSetParam.js +1 -0
- package/dist/esm/core/BleCmdAnalysis.js +1 -0
- package/dist/esm/core/BleDataProcess.js +1 -0
- package/dist/esm/core/OtaUpgrade.js +1 -0
- package/dist/esm/core/TelinkApi.js +1 -0
- package/dist/esm/core/Transfer.js +1 -0
- package/dist/esm/core/commonfun.js +1 -1
- package/dist/esm/core/dataJson/baseParamsJson.js +1 -0
- package/dist/esm/core/keyAndPwdManager.js +1 -0
- package/dist/esm/index.js +1 -1
- package/package.json +13 -3
- package/src/core/BleApiManager.js +487 -0
- package/src/core/BleCmdAnalysis/BaseParamProtocol.js +651 -0
- package/src/core/BleCmdAnalysis/BleCmdAnalysis.js +222 -0
- package/src/core/BleCmdAnalysis/BleCmdDD.js +1214 -0
- package/src/core/BleCmdAnalysis/BleCmdDDA4.js +762 -0
- package/src/core/BleCmdAnalysis/BleCmdFFAA.js +407 -0
- package/src/core/BleCmdAnalysis/BleCmdHVES.js +1222 -0
- package/src/core/BleCmdAnalysis/ESHostProtocol.js +829 -0
- package/src/core/BleCmdAnalysis/index.js +7 -0
- package/src/core/BleCmdAnalysis/readAndSetParam.js +288 -0
- package/src/core/BleDataProcess.js +355 -0
- package/src/core/OtaUpgrade.js +338 -0
- package/src/core/TelinkApi.js +73 -0
- package/src/core/Transfer.js +516 -0
- package/src/core/array.js +10 -0
- package/src/core/commonfun.js +87 -0
- package/src/core/dataJson/baseParamsJson.js +754 -0
- package/src/core/dataJson/index.js +1 -0
- package/src/core/keyAndPwdManager.js +346 -0
- package/src/core/mqttServer.js +296 -0
- package/src/core/rsaEncrypt.js +45 -0
- package/src/index.js +11 -0
|
@@ -0,0 +1,651 @@
|
|
|
1
|
+
|
|
2
|
+
import { getSysParamCmd } from './readAndSetParam'
|
|
3
|
+
import { decimalToHex, hexToDecimal } from '../BleDataProcess';
|
|
4
|
+
import { batteryInfoJson, capInfoJson, voltageInfoJson, currentInfoJson, tempInfoJson, equalizerFunJson, capVolInfoJson, funcJson, tempFuncJson, systemJson, funcAndTempFuncJson } from '../dataJson/baseParamsJson.js'
|
|
5
|
+
import { readExistFactory, getProtectCountCmd, enterFactory } from './BleCmdDD.js'
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param {*} value 原始十进制值字数组
|
|
9
|
+
* @param {*} n 缩放因子
|
|
10
|
+
* @param {*} offset 偏移量
|
|
11
|
+
* @param {*} scope 保留小数位数
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
function format(value, n = 1, offset = 0, scope = 0) {
|
|
15
|
+
if (!value) return null;
|
|
16
|
+
// 将十进制值的数组合并为一个十六进制值
|
|
17
|
+
value = value.map((el) => {
|
|
18
|
+
const hexValue = decimalToHex(el)
|
|
19
|
+
console.log('el: ------------', hexValue);
|
|
20
|
+
return hexValue;
|
|
21
|
+
})
|
|
22
|
+
const v = parseInt(value.join(''), 16) * n + offset;
|
|
23
|
+
if (scope == undefined) return v;
|
|
24
|
+
const formatted = v.toFixed(scope);
|
|
25
|
+
|
|
26
|
+
// 格式化数字
|
|
27
|
+
return Number(formatted);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 温度解析
|
|
31
|
+
* @param {*} arr 十进制数组
|
|
32
|
+
* @returns 温度摄氏度值
|
|
33
|
+
*/
|
|
34
|
+
function formatTemp(arr) {
|
|
35
|
+
if (!arr) return null;
|
|
36
|
+
let string = '0x' + toHexString(arr)
|
|
37
|
+
let value = parseInt(string, 16); // 转换为十进制数
|
|
38
|
+
// 写入 2731+(实际温度*10)
|
|
39
|
+
// 读 (绝对温度 - 2731) / 10
|
|
40
|
+
value = ((value - 2731) / 10)
|
|
41
|
+
return Number(value)
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
* @param {*} arr 十进制数组
|
|
46
|
+
* @returns 8位二进制数组
|
|
47
|
+
*/
|
|
48
|
+
function formatBinary(arr) {
|
|
49
|
+
if (!arr) return null;
|
|
50
|
+
// 处理读出来的数据
|
|
51
|
+
// 将数组元素转换为二进制字符串
|
|
52
|
+
let binaryString = arr.map(num => num.toString(2).padStart(8, '0')).join('');
|
|
53
|
+
// 将二进制字符串转换为数组并翻转
|
|
54
|
+
let resultArray = binaryString.split('').map(Number).reverse();
|
|
55
|
+
return resultArray
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 发送命令序列
|
|
59
|
+
* @param {Object} datasInfo 存储数据的对象
|
|
60
|
+
* @param {string} chipType 芯片类型
|
|
61
|
+
* @param {string} deviceId 设备ID
|
|
62
|
+
* @param {Array<any>} params 参数数组
|
|
63
|
+
*/
|
|
64
|
+
const sendCmdSeq = async (datasInfo, chipType, deviceId, params) => {
|
|
65
|
+
let index = 0;
|
|
66
|
+
// 读多个参数时统一进出工厂
|
|
67
|
+
if(!chipType) await enterFactory(deviceId);
|
|
68
|
+
while (index < params.length) {
|
|
69
|
+
const item = params[index];
|
|
70
|
+
try {
|
|
71
|
+
const basedata = await getSysParamCmd(chipType, deviceId, item, false);
|
|
72
|
+
datasInfo[item.key] = basedata;
|
|
73
|
+
index++; // 只有当前操作成功完成后才增加索引
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.error(`获取参数 ${item.key} 失败:`, error);
|
|
76
|
+
// 可以选择继续执行下一个,或者中断执行
|
|
77
|
+
// break; // 如果要在失败时中断
|
|
78
|
+
index++; // 如果希望失败时也继续下一个
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if(!chipType) await readExistFactory(deviceId);
|
|
82
|
+
}
|
|
83
|
+
let crsDivisor = 0.1;
|
|
84
|
+
/**
|
|
85
|
+
* 解析FA基础参数
|
|
86
|
+
* @param {string} chipType 芯片类型
|
|
87
|
+
* @param {string} deviceId 设备ID
|
|
88
|
+
* @param {number} index 菜单索引
|
|
89
|
+
* index-1 基本信息
|
|
90
|
+
* index-2 初始设置
|
|
91
|
+
* index-3 电压保护参数
|
|
92
|
+
* index-4 电流设置
|
|
93
|
+
* index-5 温度设置
|
|
94
|
+
* index-6 均衡设置
|
|
95
|
+
* index-7 电容电压
|
|
96
|
+
* index-8 连接内阻
|
|
97
|
+
* index-9 温控及功能配置
|
|
98
|
+
* index-10 系统设置
|
|
99
|
+
* index-11 保护次数
|
|
100
|
+
*/
|
|
101
|
+
export const getBaseParams = async (chipType, deviceData, index, paramObj) => {
|
|
102
|
+
console.log('chipType: ', chipType);
|
|
103
|
+
const deviceId = deviceData?.deviceId;
|
|
104
|
+
const protocolVersion = deviceData?.protocolVersion || "00";
|
|
105
|
+
console.warn('protocolVersion: ', protocolVersion);
|
|
106
|
+
const v = hexToDecimal(protocolVersion)
|
|
107
|
+
if(v == 2 || (v >= 20 && v < 80)) crsDivisor = 0.01;
|
|
108
|
+
console.log('v: ', v);
|
|
109
|
+
try {
|
|
110
|
+
let dataInfo = {}
|
|
111
|
+
switch (index) {
|
|
112
|
+
case 1:
|
|
113
|
+
let datasInfo1 = {};
|
|
114
|
+
await sendCmdSeq(datasInfo1, chipType, deviceId, batteryInfoJson)
|
|
115
|
+
dataInfo = getBaseInfo(datasInfo1)
|
|
116
|
+
return dataInfo
|
|
117
|
+
case 2:
|
|
118
|
+
let datasInfo2 = {}
|
|
119
|
+
if (chipType) {
|
|
120
|
+
/**连续读两个参数 */
|
|
121
|
+
const capData = await getSysParamCmd(chipType, deviceId, { ...capInfoJson[0], paramLength: 4 })
|
|
122
|
+
console.warn('capData: ', capData);
|
|
123
|
+
datasInfo2['normCap'] = capData?.slice(0, 2)
|
|
124
|
+
datasInfo2['cycleCap'] = capData?.slice(2, 4)
|
|
125
|
+
const capData2 = await getSysParamCmd(chipType, deviceId, capInfoJson[2])
|
|
126
|
+
datasInfo2['fullCap'] = capData2?.slice(0, 2)
|
|
127
|
+
} else {
|
|
128
|
+
await sendCmdSeq(datasInfo2, chipType, deviceId, capInfoJson)
|
|
129
|
+
}
|
|
130
|
+
dataInfo = getCapInfo(datasInfo2)
|
|
131
|
+
return dataInfo
|
|
132
|
+
case 3:
|
|
133
|
+
let datasInfo3 = {}
|
|
134
|
+
if (chipType) {
|
|
135
|
+
let vindex = voltageInfoJson.findIndex((el) => el.paramNo == 16)
|
|
136
|
+
console.log('vindex: ------------', vindex);
|
|
137
|
+
let vindex1 = voltageInfoJson.findIndex((el) => el.paramNo == 48)
|
|
138
|
+
let vindex2 = voltageInfoJson.findIndex((el) => el.paramNo == 38)
|
|
139
|
+
const voltageData = await getSysParamCmd(chipType, deviceId, { ...voltageInfoJson[vindex], paramLength: 16 })
|
|
140
|
+
const voltageData1 = await getSysParamCmd(chipType, deviceId, { ...voltageInfoJson[vindex1], paramLength: 8 })
|
|
141
|
+
const voltageData2 = await getSysParamCmd(chipType, deviceId, { ...voltageInfoJson[vindex2], paramLength: 4 })
|
|
142
|
+
console.log('voltageData: ', voltageData);
|
|
143
|
+
datasInfo3['allOvervoltageProtect'] = voltageData?.slice(0, 2)
|
|
144
|
+
datasInfo3['allOverpressureRecovery'] = voltageData?.slice(2, 4)
|
|
145
|
+
datasInfo3['allLowvoltageProtect'] = voltageData?.slice(4, 6)
|
|
146
|
+
datasInfo3['allLowvoltageRecover'] = voltageData?.slice(6, 8)
|
|
147
|
+
datasInfo3['singleOvervoltageProtect'] = voltageData?.slice(8, 10)
|
|
148
|
+
datasInfo3['singleOverpressureRecovery'] = voltageData?.slice(10, 12)
|
|
149
|
+
datasInfo3['singleLowvoltageProtect'] = voltageData?.slice(12, 14)
|
|
150
|
+
datasInfo3['singleLowvoltageRecover'] = voltageData?.slice(14, 16)
|
|
151
|
+
datasInfo3['allLowvoltageDelay'] = voltageData1?.slice(0, 2)
|
|
152
|
+
datasInfo3['allOverpressureDelay'] = voltageData1?.slice(2, 4)
|
|
153
|
+
datasInfo3['singleLowvoltageDelayed'] = voltageData1?.slice(4, 6)
|
|
154
|
+
datasInfo3['singleOverpressureDelay'] = voltageData1?.slice(6, 8)
|
|
155
|
+
datasInfo3['hardwareOV'] = voltageData2?.slice(0, 2)
|
|
156
|
+
datasInfo3['hardwareUV'] = voltageData2?.slice(2, 4)
|
|
157
|
+
} else {
|
|
158
|
+
await sendCmdSeq(datasInfo3, chipType, deviceId, voltageInfoJson)
|
|
159
|
+
}
|
|
160
|
+
dataInfo = getVoltageInfo(datasInfo3, chipType)
|
|
161
|
+
return dataInfo
|
|
162
|
+
case 4:
|
|
163
|
+
let datasInfo4 = {}
|
|
164
|
+
if (chipType) {
|
|
165
|
+
let cindex = currentInfoJson.findIndex((el) => el.paramNo == 24)
|
|
166
|
+
let cindex1 = currentInfoJson.findIndex((el) => el.paramNo == 52)
|
|
167
|
+
let cindex2 = currentInfoJson.findIndex((el) => el.paramNo == 40)
|
|
168
|
+
const currentData = await getSysParamCmd(chipType, deviceId, { ...currentInfoJson[cindex], paramLength: 4 })
|
|
169
|
+
const currentData1 = await getSysParamCmd(chipType, deviceId, { ...currentInfoJson[cindex1], paramLength: 8 })
|
|
170
|
+
const currentData2 = await getSysParamCmd(chipType, deviceId, { ...currentInfoJson[cindex2], paramLength: 8 })
|
|
171
|
+
console.log('currentData: ', currentData);
|
|
172
|
+
datasInfo4['occhg'] = currentData?.slice(0, 2)
|
|
173
|
+
datasInfo4['dischargeOvercurrentProtect'] = currentData?.slice(2, 4)
|
|
174
|
+
datasInfo4['chargeOvercurrentDelay'] = currentData1?.slice(0, 2)
|
|
175
|
+
datasInfo4['chargeOvercurrentRecoverDelay'] = currentData1?.slice(2, 4)
|
|
176
|
+
datasInfo4['dischargeOvercurrentDelay'] = currentData1?.slice(4, 6)
|
|
177
|
+
datasInfo4['dischargeOvercurrentRecoverDelay'] = currentData1?.slice(6, 8)
|
|
178
|
+
datasInfo4['level2OvercurrentProtect'] = currentData2?.slice(0, 2)
|
|
179
|
+
datasInfo4['level2OvercurrentProtectV'] = currentData2?.slice(2, 4)
|
|
180
|
+
datasInfo4['shortcircuiProtectRecoverDelay'] = currentData2?.slice(6, 8)
|
|
181
|
+
} else {
|
|
182
|
+
await sendCmdSeq(datasInfo4, chipType, deviceId, currentInfoJson)
|
|
183
|
+
}
|
|
184
|
+
dataInfo = getCurrentInfo(datasInfo4, chipType)
|
|
185
|
+
return dataInfo
|
|
186
|
+
case 5:
|
|
187
|
+
let datasInfo5 = {}
|
|
188
|
+
if (chipType) {
|
|
189
|
+
let tindex = tempInfoJson.findIndex((el) => el.paramNo == 8)
|
|
190
|
+
let tindex1 = tempInfoJson.findIndex((el) => el.paramNo == 44)
|
|
191
|
+
const tempData = await getSysParamCmd(chipType, deviceId, { ...tempInfoJson[tindex], paramLength: 16 })
|
|
192
|
+
const tempData1 = await getSysParamCmd(chipType, deviceId, { ...tempInfoJson[tindex1], paramLength: 8 })
|
|
193
|
+
console.log('tempData: ', tempData);
|
|
194
|
+
datasInfo5['chargeHightempProtect'] = tempData?.slice(0, 2)
|
|
195
|
+
datasInfo5['chargeHightempRecover'] = tempData?.slice(2, 4)
|
|
196
|
+
datasInfo5['chargeLowtempProtect'] = tempData?.slice(4, 6)
|
|
197
|
+
datasInfo5['chargeLowtempRecover'] = tempData?.slice(6, 8)
|
|
198
|
+
datasInfo5['dischargingHightempProtect'] = tempData?.slice(8, 10)
|
|
199
|
+
datasInfo5['dischargingHightempRecover'] = tempData?.slice(10, 12)
|
|
200
|
+
datasInfo5['dischargingLowtempProtect'] = tempData?.slice(12, 14)
|
|
201
|
+
datasInfo5['dischargingLowtempRecover'] = tempData?.slice(14, 16)
|
|
202
|
+
datasInfo5['chargeLowtempDelay'] = tempData1?.slice(0, 2)
|
|
203
|
+
datasInfo5['chargeHightempDelay'] = tempData1?.slice(2, 4)
|
|
204
|
+
datasInfo5['dischargingLowtempDelay'] = tempData1?.slice(4, 6)
|
|
205
|
+
datasInfo5['dischargingHightempDelay'] = tempData1?.slice(6, 8)
|
|
206
|
+
} else {
|
|
207
|
+
await sendCmdSeq(datasInfo5, chipType, deviceId, tempInfoJson)
|
|
208
|
+
}
|
|
209
|
+
dataInfo = getTempInfo(datasInfo5, chipType)
|
|
210
|
+
return dataInfo
|
|
211
|
+
case 6:
|
|
212
|
+
let datasInfo6 = {}
|
|
213
|
+
if (chipType) {
|
|
214
|
+
const equalizerFunData = await getSysParamCmd(chipType, deviceId, { ...equalizerFunJson[0], paramLength: 4 })
|
|
215
|
+
console.log('equalizerFunData: ', equalizerFunData);
|
|
216
|
+
datasInfo6['equalizingVoltage'] = equalizerFunData?.slice(0, 2)
|
|
217
|
+
datasInfo6['accuracyEqualization'] = equalizerFunData?.slice(2, 4)
|
|
218
|
+
} else {
|
|
219
|
+
await sendCmdSeq(datasInfo6, chipType, deviceId, equalizerFunJson)
|
|
220
|
+
}
|
|
221
|
+
dataInfo = getEqualizerFunInfo(datasInfo6)
|
|
222
|
+
return dataInfo
|
|
223
|
+
case 7:
|
|
224
|
+
let datasInfo7 = {}
|
|
225
|
+
if (chipType) {
|
|
226
|
+
let capVolIndex = capVolInfoJson.findIndex((el) => el.paramNo == 34)
|
|
227
|
+
let capVolIndex1 = capVolInfoJson.findIndex((el) => el.paramNo == 106)
|
|
228
|
+
const capVolInfoData = await getSysParamCmd(chipType, deviceId, { ...capVolInfoJson[0], paramLength: 4 })
|
|
229
|
+
const capVolInfoData1 = await getSysParamCmd(chipType, deviceId, { ...capVolInfoJson[capVolIndex], paramLength: 8 })
|
|
230
|
+
const capVolInfoData2 = await getSysParamCmd(chipType, deviceId, { ...capVolInfoJson[capVolIndex1], paramLength: 12 })
|
|
231
|
+
console.log('capVolInfoData: ', capVolInfoData);
|
|
232
|
+
datasInfo7['fullVolt'] = capVolInfoData?.slice(0, 2)
|
|
233
|
+
datasInfo7['emptyVolt'] = capVolInfoData?.slice(2, 4)
|
|
234
|
+
datasInfo7['voltage80p'] = capVolInfoData1?.slice(0, 2)
|
|
235
|
+
datasInfo7['voltage60p'] = capVolInfoData1?.slice(2, 4)
|
|
236
|
+
datasInfo7['voltage40p'] = capVolInfoData1?.slice(4, 6)
|
|
237
|
+
datasInfo7['voltage20p'] = capVolInfoData1?.slice(6, 8)
|
|
238
|
+
datasInfo7['voltage90p'] = capVolInfoData2?.slice(0, 2)
|
|
239
|
+
datasInfo7['voltage70p'] = capVolInfoData2?.slice(2, 4)
|
|
240
|
+
datasInfo7['voltage50p'] = capVolInfoData2?.slice(4, 6)
|
|
241
|
+
datasInfo7['voltage30p'] = capVolInfoData2?.slice(6, 8)
|
|
242
|
+
datasInfo7['voltage10p'] = capVolInfoData2?.slice(8, 10)
|
|
243
|
+
datasInfo7['voltage100p'] = capVolInfoData2?.slice(10, 12)
|
|
244
|
+
|
|
245
|
+
} else {
|
|
246
|
+
await sendCmdSeq(datasInfo7, chipType, deviceId, capVolInfoJson)
|
|
247
|
+
}
|
|
248
|
+
dataInfo = getcapVolInfoInfo(datasInfo7, chipType)
|
|
249
|
+
return dataInfo
|
|
250
|
+
case 9:
|
|
251
|
+
let datasInfo9 = {}
|
|
252
|
+
if (chipType) {
|
|
253
|
+
const funcAndTempFuncData = await getSysParamCmd(chipType, deviceId, { ...funcAndTempFuncJson[0], paramLength: 4 })
|
|
254
|
+
console.log('funcAndTempFuncData: ', funcAndTempFuncData);
|
|
255
|
+
datasInfo9['func'] = funcAndTempFuncData?.slice(0, 2)
|
|
256
|
+
datasInfo9['tempFunc'] = funcAndTempFuncData?.slice(2, 4)
|
|
257
|
+
} else {
|
|
258
|
+
await sendCmdSeq(datasInfo9, chipType, deviceId, funcAndTempFuncJson)
|
|
259
|
+
}
|
|
260
|
+
dataInfo = getFuncAndTempFuncInfo(datasInfo9)
|
|
261
|
+
return dataInfo
|
|
262
|
+
case 10:
|
|
263
|
+
let datasInfo10 = {}
|
|
264
|
+
await sendCmdSeq(datasInfo10, chipType, deviceId, systemJson)
|
|
265
|
+
dataInfo = getSystemInfo(datasInfo10)
|
|
266
|
+
return dataInfo
|
|
267
|
+
case 11:
|
|
268
|
+
const counts = await getProtectCountCmd(deviceId)
|
|
269
|
+
console.log('counts: ', counts);
|
|
270
|
+
return counts
|
|
271
|
+
default:
|
|
272
|
+
if(!paramObj) return null
|
|
273
|
+
let defaultDataInfo = {}
|
|
274
|
+
const onedata = await getSysParamCmd(chipType, deviceId, paramObj)
|
|
275
|
+
defaultDataInfo[paramObj.key] = onedata?.slice(0, 2)
|
|
276
|
+
return defaultDataInfo
|
|
277
|
+
}
|
|
278
|
+
} catch (error) {
|
|
279
|
+
console.error('error: 读系统参数报错 getBaseParams', error);
|
|
280
|
+
throw error
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
/**读取检流阻值 */
|
|
286
|
+
/**
|
|
287
|
+
* 读取检流阻值
|
|
288
|
+
* @param {*} chipType 芯片类型
|
|
289
|
+
* @param {*} deviceId 设备id
|
|
290
|
+
* @returns 检流阻值
|
|
291
|
+
*/
|
|
292
|
+
export const getResistance = async (chipType, deviceId) => {
|
|
293
|
+
try {
|
|
294
|
+
const rsnsValue = await getSysParamCmd(chipType, deviceId, systemJson[2])
|
|
295
|
+
const CSR = format(rsnsValue, crsDivisor, 0, 2)
|
|
296
|
+
return CSR
|
|
297
|
+
} catch (error) {
|
|
298
|
+
console.error('error: 读检流阻值报错 getResistance', error);
|
|
299
|
+
throw error
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
*
|
|
305
|
+
* @param {*} datas 读取到的参数对象,对应属性名为所取字段名,值为读取到的原始十六进制值数组
|
|
306
|
+
* @returns
|
|
307
|
+
*/
|
|
308
|
+
export const getBaseInfo = async (datas) => {
|
|
309
|
+
try {
|
|
310
|
+
console.log('datas: ', datas);
|
|
311
|
+
const barCode = getCharCodeConnect(datas?.barCode)
|
|
312
|
+
const manufacturer = getCharCodeConnect(datas?.manufacturer)
|
|
313
|
+
const model = getCharCodeConnect(datas?.model)
|
|
314
|
+
const bmsModel = getCharCodeConnect(datas?.bmsModel, true)
|
|
315
|
+
const producedDate = getProductDate(datas?.producedDate)
|
|
316
|
+
const bmsAddr = getBmsAddress(datas?.bmsAddr)
|
|
317
|
+
return {
|
|
318
|
+
barCode,
|
|
319
|
+
manufacturer,
|
|
320
|
+
model,
|
|
321
|
+
bmsModel,
|
|
322
|
+
producedDate,
|
|
323
|
+
bmsAddr,
|
|
324
|
+
}
|
|
325
|
+
} catch (error) {
|
|
326
|
+
console.error('error: ', error);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
const getCharCodeConnect = (content, clearZero = false) => {
|
|
330
|
+
console.log('content: ---------------', content);
|
|
331
|
+
if (!content) return null;
|
|
332
|
+
const length = content[0]
|
|
333
|
+
let arr = content.splice(1, length)
|
|
334
|
+
if (clearZero) {
|
|
335
|
+
// 去掉数组末尾的0,防止转码后存在空格
|
|
336
|
+
while (arr[arr.length - 1] === 0) {
|
|
337
|
+
arr.pop();
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
console.log('arr: -------------------', arr);
|
|
341
|
+
return String.fromCharCode(...arr)
|
|
342
|
+
}
|
|
343
|
+
function getProductDate(content) {
|
|
344
|
+
if (!content) return null;
|
|
345
|
+
let arr = content.splice(0, 2)
|
|
346
|
+
let string = '0x'
|
|
347
|
+
arr.forEach((el) => {
|
|
348
|
+
string += decimalToHex(el)
|
|
349
|
+
})
|
|
350
|
+
console.log(string, 'string日期');
|
|
351
|
+
let day = string & 0x1f
|
|
352
|
+
let month = (string >> 5) & 0x0f
|
|
353
|
+
let year = 2000 + (string >> 9)
|
|
354
|
+
return `${year}-${month}-${day}`
|
|
355
|
+
}
|
|
356
|
+
function getBmsAddress(content) { //12个16进制数
|
|
357
|
+
if (!content) return null;
|
|
358
|
+
console.log(content, 'content======');
|
|
359
|
+
let arr = content.splice(0, 12)
|
|
360
|
+
let string = toHexString(arr)
|
|
361
|
+
return string
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* 数组转换为16进制字符串
|
|
365
|
+
* @param {*} arr 数组
|
|
366
|
+
* @returns 16进制字符串
|
|
367
|
+
*/
|
|
368
|
+
function toHexString(arr) {
|
|
369
|
+
let string = ''
|
|
370
|
+
arr.forEach((el) => {
|
|
371
|
+
string += decimalToHex(el)
|
|
372
|
+
})
|
|
373
|
+
return string
|
|
374
|
+
}
|
|
375
|
+
const getCapInfo = async (datas) => {
|
|
376
|
+
console.log('datas: ', datas);
|
|
377
|
+
const normCap = format(datas.normCap, 0.01, 0, 2)
|
|
378
|
+
const cycleCap = format(datas.cycleCap, 0.01, 0, 2)
|
|
379
|
+
const fullCap = format(datas.fullCap, 0.01, 0, 2)
|
|
380
|
+
return {
|
|
381
|
+
normCap,
|
|
382
|
+
cycleCap,
|
|
383
|
+
fullCap
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const getVoltageInfo = async (datas, chipType) => {
|
|
388
|
+
console.log('datas: ', datas);
|
|
389
|
+
const allOvervoltageProtect = format(datas.allOvervoltageProtect, 0.01, 0, 3)
|
|
390
|
+
const allOverpressureRecovery = format(datas.allOverpressureRecovery, 0.01, 0, 3)
|
|
391
|
+
const allLowvoltageProtect = format(datas.allLowvoltageProtect, 0.01, 0, 3)
|
|
392
|
+
const allLowvoltageRecover = format(datas.allLowvoltageRecover, 0.01, 0, 3)
|
|
393
|
+
const singleOvervoltageProtect = format(datas.singleOvervoltageProtect, 0.001, 0, 3)
|
|
394
|
+
const singleOverpressureRecovery = format(datas.singleOverpressureRecovery, 0.001, 0, 3)
|
|
395
|
+
const singleLowvoltageProtect = format(datas.singleLowvoltageProtect, 0.001, 0, 3)
|
|
396
|
+
const singleLowvoltageRecover = format(datas.singleLowvoltageRecover, 0.001, 0, 3)
|
|
397
|
+
const hardwareOV = format(datas.hardwareOV, 0.001, 0, 3)
|
|
398
|
+
const hardwareUV = format(datas.hardwareUV, 0.001, 0, 3)
|
|
399
|
+
let singleOverpressureDelay = null
|
|
400
|
+
let singleLowvoltageDelayed = null
|
|
401
|
+
let allLowvoltageDelay = null
|
|
402
|
+
let allOverpressureDelay = null
|
|
403
|
+
if (chipType) {
|
|
404
|
+
singleOverpressureDelay = format(datas.singleOverpressureDelay, 1)
|
|
405
|
+
singleLowvoltageDelayed = format(datas.singleLowvoltageDelayed, 1)
|
|
406
|
+
allLowvoltageDelay = format(datas.allLowvoltageDelay, 1)
|
|
407
|
+
allOverpressureDelay = format(datas.allOverpressureDelay, 1)
|
|
408
|
+
} else {
|
|
409
|
+
// 高字节欠压延时,低字节过压延时,单位是S
|
|
410
|
+
singleLowvoltageDelayed = datas.singleLowvoltageDelayed[0]
|
|
411
|
+
singleOverpressureDelay = datas.singleLowvoltageDelayed[1]
|
|
412
|
+
allLowvoltageDelay = datas.allLowvoltageDelay[0]
|
|
413
|
+
allOverpressureDelay = datas.allLowvoltageDelay[1]
|
|
414
|
+
}
|
|
415
|
+
return {
|
|
416
|
+
allOvervoltageProtect,
|
|
417
|
+
allOverpressureRecovery,
|
|
418
|
+
allLowvoltageProtect,
|
|
419
|
+
allLowvoltageRecover,
|
|
420
|
+
singleOvervoltageProtect,
|
|
421
|
+
singleOverpressureRecovery,
|
|
422
|
+
singleLowvoltageProtect,
|
|
423
|
+
singleLowvoltageRecover,
|
|
424
|
+
singleOverpressureDelay,
|
|
425
|
+
singleLowvoltageDelayed,
|
|
426
|
+
hardwareOV,
|
|
427
|
+
hardwareUV,
|
|
428
|
+
allLowvoltageDelay,
|
|
429
|
+
allOverpressureDelay,
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
const getCurrentInfo = async (datas, chipType) => {
|
|
433
|
+
console.log('datas: ', datas);
|
|
434
|
+
const occhg = format(datas.occhg, 0.01, 0, 3)
|
|
435
|
+
// 采用补码形式传送
|
|
436
|
+
const dischargeOvercurrentProtect = (datas.dischargeOvercurrentProtect || datas.dischargeOvercurrentProtect == 0) && (format(datas.dischargeOvercurrentProtect, 1, 0, 3) - 0x10000) * 0.01
|
|
437
|
+
|
|
438
|
+
let chargeOvercurrentDelay = null
|
|
439
|
+
let chargeOvercurrentRecoverDelay = null
|
|
440
|
+
let dischargeOvercurrentDelay = null
|
|
441
|
+
let dischargeOvercurrentRecoverDelay = null
|
|
442
|
+
let shortcircuiProtectRecoverDelay = null
|
|
443
|
+
let leve2OvercurrentDelay = 0
|
|
444
|
+
let level2OvercurrentProtect = 0
|
|
445
|
+
let shortcircuiProtect = 0
|
|
446
|
+
let shortcircuiProtectDelay = 0
|
|
447
|
+
let level2OvercurrentProtectV = null
|
|
448
|
+
let overAndUnderDelay = 0
|
|
449
|
+
if (chipType) {
|
|
450
|
+
chargeOvercurrentDelay = format(datas.chargeOvercurrentDelay, 1)
|
|
451
|
+
chargeOvercurrentRecoverDelay = format(datas.chargeOvercurrentRecoverDelay, 1)
|
|
452
|
+
dischargeOvercurrentDelay = format(datas.dischargeOvercurrentDelay, 1)
|
|
453
|
+
dischargeOvercurrentRecoverDelay = format(datas.dischargeOvercurrentRecoverDelay, 1)
|
|
454
|
+
shortcircuiProtectRecoverDelay = format(datas.shortcircuiProtectRecoverDelay, 1)
|
|
455
|
+
level2OvercurrentProtect = getNewProtectAndDelay(datas.level2OvercurrentProtect).value1
|
|
456
|
+
leve2OvercurrentDelay = getNewProtectAndDelay(datas.level2OvercurrentProtect).value2
|
|
457
|
+
shortcircuiProtect = getNewProtectAndDelay(datas.level2OvercurrentProtectV).value1
|
|
458
|
+
shortcircuiProtectDelay = getNewProtectAndDelay(datas.level2OvercurrentProtectV).value2
|
|
459
|
+
} else {
|
|
460
|
+
chargeOvercurrentDelay = datas.chargeOvercurrentDelay[0]
|
|
461
|
+
chargeOvercurrentRecoverDelay = datas.chargeOvercurrentDelay[1]
|
|
462
|
+
dischargeOvercurrentDelay = datas.dischargeOvercurrentDelay[0]
|
|
463
|
+
dischargeOvercurrentRecoverDelay = datas.dischargeOvercurrentDelay[1]
|
|
464
|
+
overAndUnderDelay = datas.shortcircuiProtectRecoverDelay[0] //存储硬件过欠压延时信息 写入短路释放延时时需传
|
|
465
|
+
shortcircuiProtectRecoverDelay = datas.shortcircuiProtectRecoverDelay[1]
|
|
466
|
+
level2OvercurrentProtectV = getOldProtectAndDelay(datas.level2OvercurrentProtect).double
|
|
467
|
+
shortcircuiProtect = getOldProtectAndDelay(datas.level2OvercurrentProtect).value1
|
|
468
|
+
shortcircuiProtectDelay = getOldProtectAndDelay(datas.level2OvercurrentProtect).value2
|
|
469
|
+
level2OvercurrentProtect = getOldProtectAndDelay(datas.level2OvercurrentProtect).value3
|
|
470
|
+
leve2OvercurrentDelay = getOldProtectAndDelay(datas.level2OvercurrentProtect).value4
|
|
471
|
+
}
|
|
472
|
+
return {
|
|
473
|
+
occhg,
|
|
474
|
+
dischargeOvercurrentProtect,
|
|
475
|
+
chargeOvercurrentDelay,
|
|
476
|
+
chargeOvercurrentRecoverDelay,
|
|
477
|
+
dischargeOvercurrentDelay,
|
|
478
|
+
dischargeOvercurrentRecoverDelay,
|
|
479
|
+
leve2OvercurrentDelay,
|
|
480
|
+
level2OvercurrentProtectV,
|
|
481
|
+
shortcircuiProtectRecoverDelay,
|
|
482
|
+
shortcircuiProtect,
|
|
483
|
+
shortcircuiProtectDelay,
|
|
484
|
+
level2OvercurrentProtect,
|
|
485
|
+
overAndUnderDelay
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
function getNewProtectAndDelay(arr) {
|
|
489
|
+
if(arr?.length !== 2) return {
|
|
490
|
+
value1: 0,
|
|
491
|
+
value2: 0
|
|
492
|
+
}
|
|
493
|
+
// 根据协议文档说明计算
|
|
494
|
+
// 读取出来的是两个字节的十进制,分别转为8位二进制,再拼接
|
|
495
|
+
// 将数组元素转换为二进制字符串
|
|
496
|
+
let binaryString = arr.map(num => num.toString(2).padStart(8, '0')).join('');
|
|
497
|
+
// 将二进制字符串转换为数组
|
|
498
|
+
let resultArray = binaryString.split('').map(Number)
|
|
499
|
+
let arr1 = resultArray.slice(8, 12)
|
|
500
|
+
let arr2 = resultArray.slice(12)
|
|
501
|
+
const value1 = parseInt(arr1.join(''), 2);
|
|
502
|
+
const value2 = parseInt(arr2.join(''), 2);
|
|
503
|
+
return {
|
|
504
|
+
value1,
|
|
505
|
+
value2
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
// 获取旧协议的过流和短路数据
|
|
509
|
+
function getOldProtectAndDelay(arr) {
|
|
510
|
+
if(arr?.length !== 2) return {
|
|
511
|
+
double: false,
|
|
512
|
+
value1: 0,
|
|
513
|
+
value2: 0,
|
|
514
|
+
value3: 0,
|
|
515
|
+
value4: 0
|
|
516
|
+
}
|
|
517
|
+
// 根据协议文档说明计算
|
|
518
|
+
const binaryString = arr.map(num => num.toString(2).padStart(8, '0')).join('');
|
|
519
|
+
console.log('【解析硬件过流及短路】', binaryString);
|
|
520
|
+
const resultArray = binaryString.split('').map(Number);
|
|
521
|
+
const arr1 = [0, ...resultArray.slice(5, 8)]
|
|
522
|
+
const arr2 = resultArray.slice(1, 5)
|
|
523
|
+
const arr3 = resultArray.slice(12)
|
|
524
|
+
const arr4 = resultArray.slice(8, 12)
|
|
525
|
+
const value1 = parseInt(arr1.join(''), 2);
|
|
526
|
+
const value2 = parseInt(arr2.join(''), 2);
|
|
527
|
+
const value3 = parseInt(arr3.join(''), 2);
|
|
528
|
+
const value4 = parseInt(arr4.join(''), 2);
|
|
529
|
+
|
|
530
|
+
return {
|
|
531
|
+
double: resultArray[0] === 1, // 双倍值判断
|
|
532
|
+
value1,
|
|
533
|
+
value2,
|
|
534
|
+
value3,
|
|
535
|
+
value4
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
const getTempInfo = (datas, chipType) => {
|
|
540
|
+
console.log('datas: ', datas);
|
|
541
|
+
const chargeHightempProtect = formatTemp(datas.chargeHightempProtect)
|
|
542
|
+
const chargeHightempRecover = formatTemp(datas.chargeHightempRecover)
|
|
543
|
+
const chargeLowtempProtect = formatTemp(datas.chargeLowtempProtect)
|
|
544
|
+
const chargeLowtempRecover = formatTemp(datas.chargeLowtempRecover)
|
|
545
|
+
const dischargingHightempProtect = formatTemp(datas.dischargingHightempProtect)
|
|
546
|
+
const dischargingHightempRecover = formatTemp(datas.dischargingHightempRecover)
|
|
547
|
+
const dischargingLowtempProtect = formatTemp(datas.dischargingLowtempProtect)
|
|
548
|
+
const dischargingLowtempRecover = formatTemp(datas.dischargingLowtempRecover)
|
|
549
|
+
let chargeHightempDelay = null
|
|
550
|
+
let chargeLowtempDelay = null
|
|
551
|
+
let dischargingHightempDelay = null
|
|
552
|
+
let dischargingLowtempDelay = null
|
|
553
|
+
if (chipType) {
|
|
554
|
+
chargeHightempDelay = format(datas.chargeHightempDelay, 1)
|
|
555
|
+
chargeLowtempDelay = format(datas.chargeLowtempDelay, 1)
|
|
556
|
+
dischargingHightempDelay = format(datas.dischargingHightempDelay, 1)
|
|
557
|
+
dischargingLowtempDelay = format(datas.dischargingLowtempDelay, 1)
|
|
558
|
+
} else {
|
|
559
|
+
chargeHightempDelay = datas.chargeLowtempDelay[1]
|
|
560
|
+
chargeLowtempDelay = datas.chargeLowtempDelay[0]
|
|
561
|
+
dischargingHightempDelay = datas.dischargingLowtempDelay[1]
|
|
562
|
+
dischargingLowtempDelay = datas.dischargingLowtempDelay[0]
|
|
563
|
+
}
|
|
564
|
+
return {
|
|
565
|
+
chargeHightempProtect,
|
|
566
|
+
chargeHightempRecover,
|
|
567
|
+
chargeLowtempProtect,
|
|
568
|
+
chargeLowtempRecover,
|
|
569
|
+
dischargingHightempProtect,
|
|
570
|
+
dischargingHightempRecover,
|
|
571
|
+
dischargingLowtempProtect,
|
|
572
|
+
dischargingLowtempRecover,
|
|
573
|
+
chargeHightempDelay,
|
|
574
|
+
chargeLowtempDelay,
|
|
575
|
+
dischargingHightempDelay,
|
|
576
|
+
dischargingLowtempDelay
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
const getEqualizerFunInfo = (datas) => {
|
|
581
|
+
const equalizingVoltage = format(datas.equalizingVoltage, 0.001, 0, 3)
|
|
582
|
+
const accuracyEqualization = format(datas.accuracyEqualization, 1, 0, 2)
|
|
583
|
+
return {
|
|
584
|
+
equalizingVoltage,
|
|
585
|
+
accuracyEqualization
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
const getcapVolInfoInfo = (datas) => {
|
|
589
|
+
const fullVolt = format(datas.fullVolt, 0.001, 0, 3)
|
|
590
|
+
const emptyVolt = format(datas.emptyVolt, 0.001, 0, 3)
|
|
591
|
+
const voltage10p = format(datas.voltage10p, 0.001, 0, 3)
|
|
592
|
+
const voltage20p = format(datas.voltage20p, 0.001, 0, 3)
|
|
593
|
+
const voltage30p = format(datas.voltage30p, 0.001, 0, 3)
|
|
594
|
+
const voltage40p = format(datas.voltage40p, 0.001, 0, 3)
|
|
595
|
+
const voltage50p = format(datas.voltage50p, 0.001, 0, 3)
|
|
596
|
+
const voltage60p = format(datas.voltage60p, 0.001, 0, 3)
|
|
597
|
+
const voltage70p = format(datas.voltage70p, 0.001, 0, 3)
|
|
598
|
+
const voltage80p = format(datas.voltage80p, 0.001, 0, 3)
|
|
599
|
+
const voltage90p = format(datas.voltage90p, 0.001, 0, 3)
|
|
600
|
+
const voltage100p = format(datas.voltage100p, 0.001, 0, 3)
|
|
601
|
+
return {
|
|
602
|
+
fullVolt,
|
|
603
|
+
emptyVolt,
|
|
604
|
+
voltage10p,
|
|
605
|
+
voltage20p,
|
|
606
|
+
voltage30p,
|
|
607
|
+
voltage40p,
|
|
608
|
+
voltage50p,
|
|
609
|
+
voltage60p,
|
|
610
|
+
voltage70p,
|
|
611
|
+
voltage80p,
|
|
612
|
+
voltage90p,
|
|
613
|
+
voltage100p,
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
const getFuncAndTempFuncInfo = (datas) => {
|
|
617
|
+
const binaryFuncArr = formatBinary(datas.func)
|
|
618
|
+
const binaryTempArr = formatBinary(datas.tempFunc)
|
|
619
|
+
const func = {}
|
|
620
|
+
// 遍历funcJson数组,将每个对象的key属性作为funcObj的属性名,值设为binaryFuncArr对应值
|
|
621
|
+
funcJson.forEach((item, index) => {
|
|
622
|
+
if (item.key) {
|
|
623
|
+
func[item.key] = binaryFuncArr[index]
|
|
624
|
+
}
|
|
625
|
+
})
|
|
626
|
+
const tempFunc = {}
|
|
627
|
+
tempFuncJson.forEach((item, index) => {
|
|
628
|
+
if (item.key) {
|
|
629
|
+
tempFunc[item.key] = binaryTempArr[index]
|
|
630
|
+
}
|
|
631
|
+
})
|
|
632
|
+
return { func, tempFunc }
|
|
633
|
+
}
|
|
634
|
+
const getSystemInfo = (datas) => {
|
|
635
|
+
const serialNumber = format(datas.serialNumber, 1)
|
|
636
|
+
const cycleCount = format(datas.cycleCount, 1)
|
|
637
|
+
const strCount = format(datas.strCount, 1)
|
|
638
|
+
const rsnsValue = format(datas.rsnsValue, crsDivisor, 0, 2)
|
|
639
|
+
// const identifyCurrent = format(datas.identifyCurrent, 1)
|
|
640
|
+
// const sleepTime = format(datas.sleepTime, 1)
|
|
641
|
+
// const capacityInterval = format(datas.capacityInterval, 1)
|
|
642
|
+
return {
|
|
643
|
+
serialNumber,
|
|
644
|
+
cycleCount,
|
|
645
|
+
strCount,
|
|
646
|
+
rsnsValue,
|
|
647
|
+
// identifyCurrent,
|
|
648
|
+
// sleepTime,
|
|
649
|
+
// capacityInterval
|
|
650
|
+
}
|
|
651
|
+
}
|