@jiabaida/tools 1.0.2 → 1.0.6
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 -1
- package/dist/cjs/core/BleCmdAnalysis/BleCmdDD.js +1 -1
- package/dist/cjs/core/BleCmdAnalysis/readAndSetParam.js +1 -1
- package/dist/cjs/core/BleDataProcess.js +1 -1
- package/dist/cjs/core/OtaUpgrade.js +1 -1
- package/dist/cjs/core/Transfer.js +1 -1
- package/dist/cjs/core/commonfun.js +1 -1
- package/dist/cjs/core/dataJson/baseParamsJson.js +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/esm/core/BleApiManager.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/BleCmdAnalysis/readAndSetParam.js +1 -1
- package/dist/esm/core/BleDataProcess.js +1 -1
- package/dist/esm/core/OtaUpgrade.js +1 -1
- package/dist/esm/core/Transfer.js +1 -1
- package/dist/esm/core/commonfun.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 +126 -80
- package/src/core/BleCmdAnalysis/BaseParamProtocol.js +35 -6
- package/src/core/BleCmdAnalysis/BleCmdDD.js +254 -6
- package/src/core/BleCmdAnalysis/BleCmdDDA4.js +761 -761
- package/src/core/BleCmdAnalysis/readAndSetParam.js +9 -7
- package/src/core/BleDataProcess.js +40 -0
- package/src/core/OtaUpgrade.js +16 -4
- package/src/core/Transfer.js +1 -1
- package/src/core/commonfun.js +2 -1
- package/src/core/dataJson/baseParamsJson.js +135 -33
- package/dist/cjs/core/BleCmdAnalysis.js +0 -1
- package/dist/esm/core/BleCmdAnalysis.js +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { decimalToHex, decimalToTwoByteHexArray } from '../BleDataProcess.js';
|
|
2
|
+
import { enterFactory, existFactory, getDDA5FAAsync, getDDA5OldAsync, readExistFactory, setDDA5FAAsync, setDDA5OldAsync } from './BleCmdDD.js';
|
|
3
3
|
|
|
4
4
|
// #region 发指令读取参数
|
|
5
5
|
/**
|
|
@@ -258,16 +258,18 @@ export const setCapacityParamCmd = (chipType, deviceId, paramInfo) => {
|
|
|
258
258
|
}
|
|
259
259
|
};
|
|
260
260
|
const handleParam = async (paramObj) => {
|
|
261
|
-
const {
|
|
262
|
-
const
|
|
261
|
+
const { paramNo, oldParamNo, paramLength } = paramObj;
|
|
262
|
+
const value = Math.round(Number(paramObj.values) / paramInfo.divisor);
|
|
263
|
+
console.log('value: ', value);
|
|
264
|
+
const hexValues = decimalToTwoByteHexArray(value);
|
|
263
265
|
/** 地址转换为16进制 */
|
|
264
|
-
const hexAddress = decimalToTwoByteHexArray(
|
|
266
|
+
const hexAddress = decimalToTwoByteHexArray(paramNo);
|
|
265
267
|
// 长度转换为16进制
|
|
266
|
-
const hexLength = decimalToHex(
|
|
268
|
+
const hexLength = decimalToHex(paramLength / 2);
|
|
267
269
|
if (chipType) {
|
|
268
270
|
return await handleSet(() => setDDA5FAAsync(deviceId, hexAddress, hexLength, hexValues), 7);
|
|
269
271
|
} else {
|
|
270
|
-
return await handleSet(() => setDDA5OldAsync(deviceId,
|
|
272
|
+
return await handleSet(() => setDDA5OldAsync(deviceId, oldParamNo, hexValues), 4);
|
|
271
273
|
}
|
|
272
274
|
};
|
|
273
275
|
try {
|
|
@@ -353,3 +353,43 @@
|
|
|
353
353
|
return binaryString;
|
|
354
354
|
}
|
|
355
355
|
|
|
356
|
+
|
|
357
|
+
/**转BCD*/
|
|
358
|
+
export const fromBCD = (bcd) => {
|
|
359
|
+
// 确保只取低 8 位(安全)
|
|
360
|
+
bcd = bcd & 0xFF;
|
|
361
|
+
const tens = (bcd >> 4) & 0x0F; // 高4位
|
|
362
|
+
const units = bcd & 0x0F; // 低4位
|
|
363
|
+
return tens * 10 + units;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export const parseDateTime = (str) => {
|
|
367
|
+
const reg = /^(\d{4})-(\d{1,2})-(\d{1,2})\s+(\d{1,2}):(\d{1,2}):(\d{1,2})$/;
|
|
368
|
+
const match = str.match(reg);
|
|
369
|
+
if (!match) return null;
|
|
370
|
+
const [, y, m, d, h, i, s] = match.map(Number);
|
|
371
|
+
return new Date(y, m - 1, d, h, i, s).getTime();
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// 判断是否在30分钟内
|
|
375
|
+
export const isWithin30Minutes = (timeStr) => {
|
|
376
|
+
const now = Date.now(); // 手机当前时间(毫秒)
|
|
377
|
+
const targetTime = parseDateTime(timeStr);
|
|
378
|
+
// console.log('targetTime: ', targetTime);
|
|
379
|
+
if (targetTime === null) {
|
|
380
|
+
console.error('时间字符串格式错误:', timeStr);
|
|
381
|
+
return false;
|
|
382
|
+
}
|
|
383
|
+
const diff = Math.abs(now - targetTime); // 毫秒差
|
|
384
|
+
const thirtyMinutes = 30 * 60 * 1000; // 30分钟对应的毫秒数
|
|
385
|
+
return diff >= thirtyMinutes;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
export const toBCD = (num) => {
|
|
389
|
+
if (num < 0 || num > 99) {
|
|
390
|
+
throw new Error('BCD only supports 0-99');
|
|
391
|
+
}
|
|
392
|
+
const tens = Math.floor(num / 10); // 十位(0~9)
|
|
393
|
+
const units = num % 10; // 个位(0~9)
|
|
394
|
+
return (tens << 4) | units; // 高4位 + 低4位
|
|
395
|
+
}
|
package/src/core/OtaUpgrade.js
CHANGED
|
@@ -40,7 +40,9 @@ export class OTAUpgrade {
|
|
|
40
40
|
this.macAddr = macAddr;
|
|
41
41
|
this.platform = platform; // 'APP' | 'MP' | 'H5'
|
|
42
42
|
// 自动判断是否Telink,入参为macAddr
|
|
43
|
-
this.isTeLink = TelinkApi.isTeLink ? TelinkApi.isTeLink(
|
|
43
|
+
this.isTeLink = TelinkApi.isTeLink ? TelinkApi.isTeLink({
|
|
44
|
+
macAddr
|
|
45
|
+
}) : false;
|
|
44
46
|
this.onProgress = onProgress;
|
|
45
47
|
this.onSuccess = onSuccess;
|
|
46
48
|
this.onError = onError;
|
|
@@ -52,6 +54,7 @@ export class OTAUpgrade {
|
|
|
52
54
|
this.ready = true;
|
|
53
55
|
this.timer = null;
|
|
54
56
|
this.s_progress = 0;
|
|
57
|
+
this.otaStarting = false;
|
|
55
58
|
this.progressType = 'download'; // 当前进度类型: 'download' | 'upgrade'
|
|
56
59
|
}
|
|
57
60
|
|
|
@@ -70,6 +73,7 @@ export class OTAUpgrade {
|
|
|
70
73
|
const downloadTask = uni.downloadFile({
|
|
71
74
|
url: that.filePath,
|
|
72
75
|
success: ({ tempFilePath }) => {
|
|
76
|
+
this.addBLECharValueChangeListener();
|
|
73
77
|
that.resolve(tempFilePath).then(resolve).catch(reject);
|
|
74
78
|
},
|
|
75
79
|
fail: (res) => {
|
|
@@ -158,7 +162,6 @@ export class OTAUpgrade {
|
|
|
158
162
|
normalUpgrade() {
|
|
159
163
|
setTimeout(() => {
|
|
160
164
|
BLE.writeATCmd(this.otaInfo, this.deviceId, this.fail.bind(this));
|
|
161
|
-
this.addBLECharValueChangeListener();
|
|
162
165
|
}, 2600);
|
|
163
166
|
}
|
|
164
167
|
|
|
@@ -236,6 +239,7 @@ export class OTAUpgrade {
|
|
|
236
239
|
}
|
|
237
240
|
|
|
238
241
|
addBLECharValueChangeListener() {
|
|
242
|
+
console.log('添加蓝牙特征值变化监听');
|
|
239
243
|
const that = this;
|
|
240
244
|
uni.notifyBLECharacteristicValueChange({
|
|
241
245
|
deviceId: that.deviceId,
|
|
@@ -273,13 +277,19 @@ export class OTAUpgrade {
|
|
|
273
277
|
}
|
|
274
278
|
|
|
275
279
|
async doWithResponse(intArr) {
|
|
280
|
+
console.log('收到设备响应: ', intArr[2]);
|
|
276
281
|
if (intArr[2] == 0x80) {
|
|
277
282
|
let str = String.fromCharCode(...intArr.slice(4, -1));
|
|
283
|
+
console.log('doWithResponse otaStart1', str);
|
|
278
284
|
if (str.indexOf(this.otaInfo) > -1) {
|
|
279
285
|
this.finishedTimes = 0;
|
|
280
286
|
this.transferFirmwareFile();
|
|
281
287
|
}
|
|
282
|
-
if (str.indexOf(this.otaStart) > -1) {
|
|
288
|
+
if (str.indexOf(this.otaStart) > -1 || this.otaStarting) {
|
|
289
|
+
if (str.indexOf(this.otaStart) > -1) {
|
|
290
|
+
this.otaStarting = true;
|
|
291
|
+
}
|
|
292
|
+
console.log('doWithResponse otaStart2', str);
|
|
283
293
|
if (str.toUpperCase().includes('ERROR')) {
|
|
284
294
|
this.fail(str);
|
|
285
295
|
return;
|
|
@@ -313,10 +323,12 @@ export class OTAUpgrade {
|
|
|
313
323
|
if (timeFor51) {
|
|
314
324
|
const pkg = [0x00];
|
|
315
325
|
BLE.transferFirmwareFileCmd(this.deviceId, pkg, true, this.fail.bind(this));
|
|
326
|
+
console.log('[OTA]', '=== Send 51 ===', this.finishedTimes, this.totalTimes, pkg);
|
|
316
327
|
} else {
|
|
317
328
|
const pkg = this.fileHexArray.slice(this.finishedTimes * max, nextTime * max);
|
|
318
|
-
const index = Transfer.decimalToTwoByteHexArray(
|
|
329
|
+
const index = Transfer.decimalToTwoByteHexArray(this.finishedTimes);
|
|
319
330
|
BLE.transferFirmwareFileCmd(this.deviceId, index.concat(pkg), false, this.fail.bind(this));
|
|
331
|
+
console.log('[OTA]', `S50-${this.finishedTimes}/${this.totalTimes}`);
|
|
320
332
|
}
|
|
321
333
|
this.onProgress && this.onProgress({ type: 'upgrade', percent: Math.floor((this.finishedTimes * 100) / this.totalTimes) });
|
|
322
334
|
}
|
package/src/core/Transfer.js
CHANGED
|
@@ -252,7 +252,7 @@ export const BLE = {
|
|
|
252
252
|
readUUID: '0000FF01-0000-1000-8000-00805F9B34FB',
|
|
253
253
|
TAG: '[BLE_OTA]',
|
|
254
254
|
WRITE_DELAY: 25,
|
|
255
|
-
PACKAGE_MAX_LENGTH:
|
|
255
|
+
PACKAGE_MAX_LENGTH: 237,
|
|
256
256
|
// 分包发送
|
|
257
257
|
sendMsgToKey(buffer, deviceId, fail) {
|
|
258
258
|
const { isAndroid, isIOS } = getOS();
|
package/src/core/commonfun.js
CHANGED
|
@@ -34,7 +34,8 @@ export function getOS() {
|
|
|
34
34
|
const os = uni.getSystemInfoSync()?.osName;
|
|
35
35
|
return {
|
|
36
36
|
isIOS: os == 'ios',
|
|
37
|
-
isAndroid: os == 'android',
|
|
37
|
+
isAndroid: os == 'android' || os == 'openharmonyos',
|
|
38
|
+
isHarmony: os === 'harmony' || os === 'openharmonyos',
|
|
38
39
|
};
|
|
39
40
|
}
|
|
40
41
|
export function getPlatform() {
|
|
@@ -3,38 +3,42 @@ import { func } from '@/uni_modules/uv-ui-tools/libs/function/test.js';
|
|
|
3
3
|
import { funcJson } from './baseParamsJson';
|
|
4
4
|
* 电池基础信息参数
|
|
5
5
|
*/
|
|
6
|
-
export const batteryInfoJson =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
6
|
+
export const batteryInfoJson = (crsDivisor) => {
|
|
7
|
+
return [{
|
|
8
|
+
key: 'barCode',
|
|
9
|
+
paramNo: 88,
|
|
10
|
+
paramLength: 32,
|
|
11
|
+
oldParamNo: '0xA2',
|
|
12
|
+
}, {
|
|
13
|
+
key: 'manufacturer',
|
|
14
|
+
paramNo: 56,
|
|
15
|
+
oldParamNo: '0xA0',
|
|
16
|
+
paramLength: 32,
|
|
17
|
+
}, {
|
|
18
|
+
key: 'producedDate',
|
|
19
|
+
paramNo: 5,
|
|
20
|
+
oldParamNo: '0x15',
|
|
21
|
+
paramLength: 2,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
key: 'model',//电池型号
|
|
25
|
+
paramNo: crsDivisor == 0.1 ? 158 : 316,
|
|
26
|
+
oldParamNo: '',
|
|
27
|
+
paramLength: 24,
|
|
28
|
+
}, {
|
|
29
|
+
key: 'bmsModel',
|
|
30
|
+
paramNo: crsDivisor == 0.1 ? 176 : 72,
|
|
31
|
+
oldParamNo: '',
|
|
32
|
+
paramLength: crsDivisor == 0.1 ? 16 : 32,
|
|
33
|
+
},
|
|
34
|
+
// {
|
|
35
|
+
// key: 'bmsAddr',
|
|
36
|
+
// paramNo: 170,
|
|
37
|
+
// oldParamNo: '',
|
|
38
|
+
// paramLength: 12,
|
|
39
|
+
// }
|
|
40
|
+
]
|
|
41
|
+
}
|
|
38
42
|
/**
|
|
39
43
|
* 电池容量信息参数
|
|
40
44
|
*/
|
|
@@ -43,16 +47,19 @@ export const capInfoJson = [{
|
|
|
43
47
|
paramNo: 0,
|
|
44
48
|
oldParamNo: '0x10',
|
|
45
49
|
paramLength: 2,
|
|
50
|
+
divisor: 10
|
|
46
51
|
}, {
|
|
47
52
|
key: 'cycleCap',
|
|
48
53
|
paramNo: 1,
|
|
49
54
|
oldParamNo: '0x11',
|
|
50
55
|
paramLength: 2,
|
|
56
|
+
divisor: 10
|
|
51
57
|
}, {
|
|
52
58
|
key: 'fullCap',
|
|
53
59
|
paramNo: 112,
|
|
54
60
|
oldParamNo: '',
|
|
55
61
|
paramLength: 2,
|
|
62
|
+
divisor: 10
|
|
56
63
|
}]
|
|
57
64
|
/**
|
|
58
65
|
* 电池电压保护参数
|
|
@@ -66,6 +73,7 @@ export const voltageInfoJson = [
|
|
|
66
73
|
paramNo: 16,
|
|
67
74
|
oldParamNo: "0x20",
|
|
68
75
|
paramLength: 2,
|
|
76
|
+
divisor: 100
|
|
69
77
|
},
|
|
70
78
|
{
|
|
71
79
|
key: "allOverpressureRecovery",
|
|
@@ -75,6 +83,7 @@ export const voltageInfoJson = [
|
|
|
75
83
|
paramNo: 17,
|
|
76
84
|
oldParamNo: "0x21",
|
|
77
85
|
paramLength: 2,
|
|
86
|
+
divisor: 100
|
|
78
87
|
},
|
|
79
88
|
{
|
|
80
89
|
key: "allLowvoltageProtect",
|
|
@@ -84,6 +93,7 @@ export const voltageInfoJson = [
|
|
|
84
93
|
paramNo: 18,
|
|
85
94
|
oldParamNo: "0x22",
|
|
86
95
|
paramLength: 2,
|
|
96
|
+
divisor: 100
|
|
87
97
|
},
|
|
88
98
|
{
|
|
89
99
|
key: "allLowvoltageRecover",
|
|
@@ -93,6 +103,7 @@ export const voltageInfoJson = [
|
|
|
93
103
|
paramNo: 19,
|
|
94
104
|
oldParamNo: "0x23",
|
|
95
105
|
paramLength: 2,
|
|
106
|
+
divisor: 100
|
|
96
107
|
},
|
|
97
108
|
{
|
|
98
109
|
key: "singleOvervoltageProtect",
|
|
@@ -102,6 +113,7 @@ export const voltageInfoJson = [
|
|
|
102
113
|
paramNo: 20,
|
|
103
114
|
oldParamNo: "0x24",
|
|
104
115
|
paramLength: 2,
|
|
116
|
+
divisor: 1000
|
|
105
117
|
},
|
|
106
118
|
{
|
|
107
119
|
key: "singleOverpressureRecovery",
|
|
@@ -111,6 +123,7 @@ export const voltageInfoJson = [
|
|
|
111
123
|
paramNo: 21,
|
|
112
124
|
oldParamNo: "0x25",
|
|
113
125
|
paramLength: 2,
|
|
126
|
+
divisor: 1000
|
|
114
127
|
},
|
|
115
128
|
{
|
|
116
129
|
key: "singleLowvoltageProtect",
|
|
@@ -120,6 +133,7 @@ export const voltageInfoJson = [
|
|
|
120
133
|
paramNo: 22,
|
|
121
134
|
oldParamNo: "0x26",
|
|
122
135
|
paramLength: 2,
|
|
136
|
+
divisor: 1000
|
|
123
137
|
},
|
|
124
138
|
{
|
|
125
139
|
key: "singleLowvoltageRecover",
|
|
@@ -129,6 +143,7 @@ export const voltageInfoJson = [
|
|
|
129
143
|
paramNo: 23,
|
|
130
144
|
oldParamNo: "0x27",
|
|
131
145
|
paramLength: 2,
|
|
146
|
+
divisor: 1000
|
|
132
147
|
},
|
|
133
148
|
{
|
|
134
149
|
key: "allLowvoltageDelay",
|
|
@@ -138,6 +153,7 @@ export const voltageInfoJson = [
|
|
|
138
153
|
paramNo: 48,
|
|
139
154
|
oldParamNo: "0x3C",
|
|
140
155
|
paramLength: 2,
|
|
156
|
+
divisor: 1
|
|
141
157
|
},
|
|
142
158
|
{
|
|
143
159
|
key: "allOverpressureDelay",
|
|
@@ -147,6 +163,7 @@ export const voltageInfoJson = [
|
|
|
147
163
|
paramNo: 49,
|
|
148
164
|
oldParamNo: "", // 0x3C 旧协议相同的只读一个
|
|
149
165
|
paramLength: 2,
|
|
166
|
+
divisor: 1
|
|
150
167
|
},
|
|
151
168
|
{
|
|
152
169
|
key: "singleLowvoltageDelayed",
|
|
@@ -156,6 +173,7 @@ export const voltageInfoJson = [
|
|
|
156
173
|
paramNo: 50,
|
|
157
174
|
oldParamNo: "0x3d",
|
|
158
175
|
paramLength: 2,
|
|
176
|
+
divisor: 1
|
|
159
177
|
},
|
|
160
178
|
{
|
|
161
179
|
key: "singleOverpressureDelay",
|
|
@@ -165,6 +183,7 @@ export const voltageInfoJson = [
|
|
|
165
183
|
paramNo: 51,
|
|
166
184
|
oldParamNo: "", // 0x3d 旧协议相同的只读一个
|
|
167
185
|
paramLength: 2,
|
|
186
|
+
divisor: 1
|
|
168
187
|
},
|
|
169
188
|
{
|
|
170
189
|
key: "hardwareOV",
|
|
@@ -174,6 +193,7 @@ export const voltageInfoJson = [
|
|
|
174
193
|
paramNo: 38,
|
|
175
194
|
oldParamNo: "0x36",
|
|
176
195
|
paramLength: 2,
|
|
196
|
+
divisor: 1000
|
|
177
197
|
},
|
|
178
198
|
{
|
|
179
199
|
key: "hardwareUV",
|
|
@@ -183,6 +203,7 @@ export const voltageInfoJson = [
|
|
|
183
203
|
paramNo: 39,
|
|
184
204
|
oldParamNo: "0x37",
|
|
185
205
|
paramLength: 2,
|
|
206
|
+
divisor: 1000
|
|
186
207
|
},
|
|
187
208
|
]
|
|
188
209
|
export const currentInfoJson = [
|
|
@@ -194,6 +215,7 @@ export const currentInfoJson = [
|
|
|
194
215
|
oldParamNo: "0x28",
|
|
195
216
|
paramLength: 2,
|
|
196
217
|
key: "occhg",
|
|
218
|
+
divisor: 100,
|
|
197
219
|
},
|
|
198
220
|
{
|
|
199
221
|
value: "",
|
|
@@ -203,6 +225,7 @@ export const currentInfoJson = [
|
|
|
203
225
|
oldParamNo: "0x29",
|
|
204
226
|
paramLength: 2,
|
|
205
227
|
key: "dischargeOvercurrentProtect",
|
|
228
|
+
divisor: 1000,
|
|
206
229
|
},
|
|
207
230
|
{
|
|
208
231
|
value: "",
|
|
@@ -212,6 +235,7 @@ export const currentInfoJson = [
|
|
|
212
235
|
oldParamNo: "0x3E",
|
|
213
236
|
paramLength: 2,
|
|
214
237
|
key: "chargeOvercurrentDelay",
|
|
238
|
+
divisor: 1,
|
|
215
239
|
},
|
|
216
240
|
{
|
|
217
241
|
value: "",
|
|
@@ -221,6 +245,7 @@ export const currentInfoJson = [
|
|
|
221
245
|
oldParamNo: "", // 0x3E 旧协议相同的只读一个
|
|
222
246
|
paramLength: 2,
|
|
223
247
|
key: "chargeOvercurrentRecoverDelay",
|
|
248
|
+
divisor: 1,
|
|
224
249
|
},
|
|
225
250
|
|
|
226
251
|
{
|
|
@@ -231,6 +256,7 @@ export const currentInfoJson = [
|
|
|
231
256
|
oldParamNo: "0x3F",
|
|
232
257
|
paramLength: 2,
|
|
233
258
|
key: "dischargeOvercurrentDelay",
|
|
259
|
+
divisor: 1,
|
|
234
260
|
},
|
|
235
261
|
{
|
|
236
262
|
value: "",
|
|
@@ -240,6 +266,7 @@ export const currentInfoJson = [
|
|
|
240
266
|
oldParamNo: "", // 0x3F 旧协议相同的只读一个
|
|
241
267
|
paramLength: 2,
|
|
242
268
|
key: "dischargeOvercurrentRecoverDelay",
|
|
269
|
+
divisor: 1,
|
|
243
270
|
},
|
|
244
271
|
|
|
245
272
|
{
|
|
@@ -414,7 +441,27 @@ export const tempInfoJson = [
|
|
|
414
441
|
oldParamNo: "", //0x3B
|
|
415
442
|
paramLength: 2,
|
|
416
443
|
key: "dischargingHightempDelay",
|
|
417
|
-
}
|
|
444
|
+
},
|
|
445
|
+
{
|
|
446
|
+
name: "",
|
|
447
|
+
value: "",
|
|
448
|
+
newValue: "",
|
|
449
|
+
unit: "℃",
|
|
450
|
+
paramNo: 202,
|
|
451
|
+
oldParamNo: "0x2E",
|
|
452
|
+
paramLength: 2,
|
|
453
|
+
key: "overtempProtect",
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
name: "",
|
|
457
|
+
value: "",
|
|
458
|
+
newValue: "",
|
|
459
|
+
unit: "℃",
|
|
460
|
+
paramNo: 203,
|
|
461
|
+
oldParamNo: "0x2F",
|
|
462
|
+
paramLength: 2,
|
|
463
|
+
key: "overtempRecover",
|
|
464
|
+
},
|
|
418
465
|
]
|
|
419
466
|
export const equalizerFunJson = [
|
|
420
467
|
{
|
|
@@ -447,6 +494,7 @@ export const capVolInfoJson = [
|
|
|
447
494
|
paramLength: 2,
|
|
448
495
|
isHidden: false,
|
|
449
496
|
key: "fullVolt",
|
|
497
|
+
divisor: 1000,
|
|
450
498
|
},
|
|
451
499
|
{
|
|
452
500
|
value: null,
|
|
@@ -457,6 +505,7 @@ export const capVolInfoJson = [
|
|
|
457
505
|
paramLength: 2,
|
|
458
506
|
isHidden: false,
|
|
459
507
|
key: "emptyVolt",
|
|
508
|
+
divisor: 1000,
|
|
460
509
|
},
|
|
461
510
|
{
|
|
462
511
|
name: "容量80%",
|
|
@@ -467,6 +516,7 @@ export const capVolInfoJson = [
|
|
|
467
516
|
oldParamNo: "0x32",
|
|
468
517
|
paramLength: 2,
|
|
469
518
|
key: "voltage80p",
|
|
519
|
+
divisor: 1000,
|
|
470
520
|
},
|
|
471
521
|
{
|
|
472
522
|
name: "容量60%",
|
|
@@ -477,6 +527,7 @@ export const capVolInfoJson = [
|
|
|
477
527
|
oldParamNo: "0x33",
|
|
478
528
|
paramLength: 2,
|
|
479
529
|
key: "voltage60p",
|
|
530
|
+
divisor: 1000,
|
|
480
531
|
},
|
|
481
532
|
{
|
|
482
533
|
name: "容量40%",
|
|
@@ -487,6 +538,7 @@ export const capVolInfoJson = [
|
|
|
487
538
|
oldParamNo: "0x34",
|
|
488
539
|
paramLength: 2,
|
|
489
540
|
key: "voltage40p",
|
|
541
|
+
divisor: 1000,
|
|
490
542
|
},
|
|
491
543
|
{
|
|
492
544
|
name: "容量20%",
|
|
@@ -497,6 +549,7 @@ export const capVolInfoJson = [
|
|
|
497
549
|
oldParamNo: "0x35",
|
|
498
550
|
paramLength: 2,
|
|
499
551
|
key: "voltage20p",
|
|
552
|
+
divisor: 1000,
|
|
500
553
|
},
|
|
501
554
|
{
|
|
502
555
|
name: "容量90%",
|
|
@@ -507,6 +560,7 @@ export const capVolInfoJson = [
|
|
|
507
560
|
oldParamNo: "0x42",
|
|
508
561
|
paramLength: 2,
|
|
509
562
|
key: "voltage90p",
|
|
563
|
+
divisor: 1000,
|
|
510
564
|
},
|
|
511
565
|
{
|
|
512
566
|
name: "容量70%",
|
|
@@ -517,6 +571,7 @@ export const capVolInfoJson = [
|
|
|
517
571
|
oldParamNo: "0x43",
|
|
518
572
|
paramLength: 2,
|
|
519
573
|
key: "voltage70p",
|
|
574
|
+
divisor: 1000,
|
|
520
575
|
},
|
|
521
576
|
{
|
|
522
577
|
name: "容量50%",
|
|
@@ -527,6 +582,7 @@ export const capVolInfoJson = [
|
|
|
527
582
|
oldParamNo: "0x44",
|
|
528
583
|
paramLength: 2,
|
|
529
584
|
key: "voltage50p",
|
|
585
|
+
divisor: 1000,
|
|
530
586
|
},
|
|
531
587
|
{
|
|
532
588
|
name: "容量30%",
|
|
@@ -537,6 +593,7 @@ export const capVolInfoJson = [
|
|
|
537
593
|
oldParamNo: "0x45",
|
|
538
594
|
paramLength: 2,
|
|
539
595
|
key: "voltage30p",
|
|
596
|
+
divisor: 1000,
|
|
540
597
|
},
|
|
541
598
|
{
|
|
542
599
|
name: "容量10%",
|
|
@@ -547,6 +604,7 @@ export const capVolInfoJson = [
|
|
|
547
604
|
oldParamNo: "0x46",
|
|
548
605
|
paramLength: 2,
|
|
549
606
|
key: "voltage10p",
|
|
607
|
+
divisor: 1000,
|
|
550
608
|
},
|
|
551
609
|
{
|
|
552
610
|
name: "容量100%",
|
|
@@ -557,6 +615,7 @@ export const capVolInfoJson = [
|
|
|
557
615
|
oldParamNo: "0x47",
|
|
558
616
|
paramLength: 2,
|
|
559
617
|
key: "voltage100p",
|
|
618
|
+
divisor: 1000,
|
|
560
619
|
},
|
|
561
620
|
]
|
|
562
621
|
export const funcAndTempFuncJson = [{
|
|
@@ -685,6 +744,7 @@ export const systemJson = [
|
|
|
685
744
|
paramLength: 2,
|
|
686
745
|
isHidden: true,
|
|
687
746
|
key: "serialNumber",
|
|
747
|
+
divisor: 1,
|
|
688
748
|
},
|
|
689
749
|
{
|
|
690
750
|
// 循环次数
|
|
@@ -696,6 +756,7 @@ export const systemJson = [
|
|
|
696
756
|
paramLength: 2,
|
|
697
757
|
isHidden: true,
|
|
698
758
|
key: "cycleCount",
|
|
759
|
+
divisor: 1,
|
|
699
760
|
},
|
|
700
761
|
{
|
|
701
762
|
name: "检流阻值",
|
|
@@ -707,6 +768,7 @@ export const systemJson = [
|
|
|
707
768
|
paramLength: 2,
|
|
708
769
|
isHidden: false,
|
|
709
770
|
key: "rsnsValue",
|
|
771
|
+
divisor: 1000,
|
|
710
772
|
},
|
|
711
773
|
{
|
|
712
774
|
name: "串数设置",
|
|
@@ -718,6 +780,43 @@ export const systemJson = [
|
|
|
718
780
|
paramLength: 2,
|
|
719
781
|
isHidden: true,
|
|
720
782
|
key: "strCount",
|
|
783
|
+
divisor: 1,
|
|
784
|
+
},
|
|
785
|
+
{
|
|
786
|
+
name: "自动关机", // 强制使用时间
|
|
787
|
+
value: "",
|
|
788
|
+
newValue: "",
|
|
789
|
+
unit: "",
|
|
790
|
+
paramNo: 191,
|
|
791
|
+
paramLength: 2,
|
|
792
|
+
notShow: false,
|
|
793
|
+
switch: true,
|
|
794
|
+
key: "param1911",
|
|
795
|
+
divisor: 1,
|
|
796
|
+
},
|
|
797
|
+
{
|
|
798
|
+
name: "低电保护功能", // 强制使用时间
|
|
799
|
+
value: "",
|
|
800
|
+
newValue: "",
|
|
801
|
+
unit: "",
|
|
802
|
+
paramNo: 198,
|
|
803
|
+
paramLength: 2,
|
|
804
|
+
notShow: false,
|
|
805
|
+
switch: true,
|
|
806
|
+
key: "param1981",
|
|
807
|
+
divisor: 1,
|
|
808
|
+
},
|
|
809
|
+
{
|
|
810
|
+
name: "UART协议设定",
|
|
811
|
+
value: "",
|
|
812
|
+
newValue: "",
|
|
813
|
+
unit: "",
|
|
814
|
+
paramNo: 195,
|
|
815
|
+
paramLength: 2,
|
|
816
|
+
notShow: false,
|
|
817
|
+
key: "param1951",
|
|
818
|
+
divisor: 1,
|
|
819
|
+
method: true,
|
|
721
820
|
},
|
|
722
821
|
|
|
723
822
|
// {
|
|
@@ -729,6 +828,7 @@ export const systemJson = [
|
|
|
729
828
|
// paramLength: 2,
|
|
730
829
|
// isHidden: false,
|
|
731
830
|
// key: "identifyCurrent",
|
|
831
|
+
// divisor: 1000,
|
|
732
832
|
// },
|
|
733
833
|
// {
|
|
734
834
|
// value: "",
|
|
@@ -739,6 +839,7 @@ export const systemJson = [
|
|
|
739
839
|
// paramLength: 2,
|
|
740
840
|
// isHidden: false,
|
|
741
841
|
// key: "sleepTime",
|
|
842
|
+
// divisor: 1,
|
|
742
843
|
// },
|
|
743
844
|
// {
|
|
744
845
|
// value: "",
|
|
@@ -749,6 +850,7 @@ export const systemJson = [
|
|
|
749
850
|
// paramLength: 2,
|
|
750
851
|
// isHidden: false,
|
|
751
852
|
// key: "capacityInterval",
|
|
853
|
+
// divisor: 1,
|
|
752
854
|
// },
|
|
753
855
|
|
|
754
856
|
]
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var BleDataProcess=require("./BleDataProcess.js"),commonfun=require("./commonfun.js");class BleCmdAnalysis extends BleDataProcess.default{static async _writeAsync(deviceId,value){return console.log("deviceId, value: ",deviceId,value),!(!deviceId||!value)&&new Promise(resolve=>{const characteristicId=this.UUID_WRITE,{isAndroid:isAndroid,isIOS:isIOS}=commonfun.getOS();console.log("isAndroid, isIOS: ",isAndroid,isIOS);const writeType=isAndroid?"writeNoResponse":"write";uni.writeBLECharacteristicValue({deviceId:deviceId,serviceId:this.serviceId,characteristicId:characteristicId,writeType:writeType,value:value,success:res=>{console.error("res: 写入成功",res),resolve(!0)},fail:e=>{console.error("写入失败",e),resolve(!1)}}),isIOS&&setTimeout(()=>resolve(!0),50)})}static async writeAsync(deviceId,value){return console.log("value: ",value),console.log("deviceId: ",deviceId),!(!deviceId||!value)&&new Promise(async resolve=>{const n=Math.ceil(value.byteLength/20);let res;for(let i=0;i<n;i++){const _value=value.slice(20*i,20*(i+1));if(console.log("分包写入_value: ",_value),await this.sleep(150),res=await this._writeAsync(deviceId,_value),console.log(`分包写入结果 ${i+1}/${n} : ${res}`),!res)return resolve(!1)}resolve(res)})}static async getData(deviceId,{command:command,commandVerifyHandler:commandVerifyHandler=hexArr=>({verified:!1,pkgLen:null}),pkgVerifyHandler:pkgVerifyHandler=pkg=>({verified:!1}),maxRetries:maxRetries=2,retryInterval:retryInterval=300},tag=""){if(!deviceId)throw new Error("deviceId is required");if(!command||command.length<=0)throw new Error("command is required");return new Promise((resolve,reject)=>{let isCompleted=!1,timeoutId=null,responsed=!1,len=null,pkg=[];const cmdContent=this.hexArr2ab(command),cleanup=()=>{isCompleted||(isCompleted=!0,clearTimeout(timeoutId),commonfun.eventBus.off("setBleChangedCharacteristicValue",dataHandler))},dataHandler=payload=>{if(!payload||payload.deviceId!==deviceId||!payload.value)return;const hexArr=this.ab2decimalArr(payload.value);if(console.warn(tag,"接收到数据:",this.hexArr2string(hexArr)),0!==hexArr.length){if(null===len){const{verified:verified,pkgLen:pkgLen}=commandVerifyHandler(hexArr);console.log("指令验证结果:",{verified:verified,pkgLen:pkgLen}),verified&&(len=pkgLen)}if(len){if(pkg=[...pkg,...hexArr],console.log("当前数据包:",pkg,`长度: ${pkg.length}/${len}`),pkg.length>=len){pkg=pkg.slice(0,len);const{verified:verified}=pkgVerifyHandler(pkg);console.log("数据包验证结果:",{verified:verified}),verified?(responsed=!0,cleanup(),resolve([...pkg])):(len=null,pkg=[])}}else pkg=[]}},writeToDevice=async(attempt=1)=>{try{console.warn(tag,`第${attempt}次写入指令:`,command.join("").replace(/0x/g,"").toUpperCase());const writeSucceed=await this.writeAsync(deviceId,cmdContent);if(console.warn(tag,`第${attempt}次写入结果:`,writeSucceed?"成功":"失败"),!writeSucceed)return void(attempt<maxRetries?setTimeout(()=>writeToDevice(attempt+1),retryInterval):(cleanup(),resolve(null)));await this.sleep(retryInterval),!responsed&&attempt<maxRetries?(console.log(tag,`未收到响应,准备第${attempt+1}次重试`),writeToDevice(attempt+1)):responsed||(console.warn(tag,`达到最大重试次数(${maxRetries}),未收到响应`),cleanup(),resolve(null))}catch(error){console.error(tag,"写入过程发生错误:",error),cleanup(),reject(error)}};timeoutId=setTimeout(()=>{console.warn(tag,"操作超时"),cleanup(),resolve(null)},(maxRetries+2)*retryInterval),commonfun.eventBus.on("setBleChangedCharacteristicValue",dataHandler),writeToDevice().catch(error=>{cleanup(),reject(error)})})}static async getDDA503Async(deviceId){const hex=await this.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]=this.generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_03");return hex?this.resolveDDA503(hex):null}static resolveDDA503(data){if(!data)return null;const dataStr=this.hexArr2string(data),content=data.slice(4,data.length-3),binArr=data[24].toString(2).padStart(8,"0").split("").reverse(),n=Number(binArr[7])?10:100,fet=data[24],chargeSwitch=1==fet||3==fet,dischargeSwitch=2==fet||3==fet,BMSVersion=this.decimalToHex(data[22]),totalVoltage=(((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=(parseFloat(totalVoltage)*electricity).toFixed(2),soc=data[23]??0,volumeHex=this.decimalToHex(data[8])+this.decimalToHex(data[9]),seriesNum=data[25]??0,surplusCapacity=Number((this.hexToDecimal(volumeHex)/n).toFixed(2)),normCapHex=this.decimalToHex(data[10])+this.decimalToHex(data[11]),normCap=Number((this.hexToDecimal(normCapHex)/n).toFixed(2)),humidityIndex=2*data[26]+27,humidity=data[humidityIndex],cycleHex=this.decimalToHex(data[12])+this.decimalToHex(data[13]),cycleIndex=this.hexToDecimal(cycleHex),fccHex=this.decimalToHex(data[humidityIndex+3])+this.decimalToHex(data[humidityIndex+4]),fullChargeCapacity=10*this.hexToDecimal(fccHex)/1e3,SOH=cycleIndex<=100?100:Math.min(100,fullChargeCapacity/normCap*100),isHeating=!!Number(binArr[4]);let heatingCurrent=0;if(isHeating){const i=humidityIndex+9;heatingCurrent=10*parseInt([data[i],data[i+1]].map(o=>o.toString(16)).join(""),16)}const isFactoryMode=!!Number(binArr[6]),equilibriumStatus=!(0===data[16]&&0===data[17]),protectStatus=!(0===data[20]&&0===data[21]),protectStateHex=this.decimalToHex(data[20])+this.decimalToHex(data[21]),protectState=this.hexToDecimal(protectStateHex);let protectStatusIndexs=[];for(let i=0;i<16;i++)protectState&1<<i&&protectStatusIndexs.push(i);const protectStatusIndex=protectStatusIndexs.join(","),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=[];return temperaturesList.forEach(el=>{const value=1.8*Number(el)+32;fahTempList.push(value.toFixed(1))}),{dataStr:dataStr,status:this.hex2string(data[2]),len:data[3],softwareV:this.hex2string(content[18]),chargeSwitch:chargeSwitch,dischargeSwitch:dischargeSwitch,BMSVersion:BMSVersion,totalVoltage:totalVoltage,electricity:electricity,power:power,soc:soc,surplusCapacity:surplusCapacity,normCap:normCap,humidity:humidity,cycleIndex:cycleIndex,fullChargeCapacity:fullChargeCapacity,SOH:SOH,isHeating:isHeating,heatingCurrent:heatingCurrent,isFactoryMode:isFactoryMode,equilibriumStatus:equilibriumStatus,protectStatus:protectStatus,protectStatusIndex:protectStatusIndex,ntcNums:ntcNums,temperaturesList:temperaturesList,fahTempList:fahTempList,fet:fet,seriesNum:seriesNum}}static getFFAA17Async(deviceId){return this.getData(deviceId,{command:["0xFF","0xAA","0x17","0x00","0x17"],commandVerifyHandler:hexArr=>({verified:255==hexArr[0]&&170==hexArr[1]&&23==hexArr[2],pkgLen:hexArr[3]+5}),pkgVerifyHandler:pkg=>{const _pkg=pkg.map(o=>this.hex2string(o)),len=pkg.length,[c1]=this.generateCheckSum(_pkg.slice(2,len-1));return{verified:c1==pkg[len-1]}}},"FFAA_17(获取随机数)")}static getFFAAKeyAsync(deviceId,code,content,type){const commandCode=[code],data=[...content],dataLength=[`0x${this.decimalToHex(data.length,2)}`],check=this.generateCheckSum([...commandCode,...dataLength,...data]),command=["0xff","0xaa",...commandCode,...dataLength,...data,...check];return console.log("command: ---------------",command),this.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:255==hexArr[0]&&170==hexArr[1]&&hexArr[2]==this.hexToDecimal(code),pkgLen:hexArr[3]+5}),pkgVerifyHandler:pkg=>{const _pkg=pkg.map(o=>this.hex2string(o)),len=pkg.length,[c1]=this.generateCheckSum(_pkg.slice(2,len-1));return{verified:c1==pkg[len-1]}}},`FFAA_${code}(${type})`)}static resolveFFAAKey(data){if(!data)return null;const dataStr=this.hexArr2string(data),response=data[data.length-2];return{dataStr:dataStr,response:response,status:response}}static getBroadcastDataCmd(deviceId){return this.getFFAAKeyAsync(deviceId,"0x19",["0x01"],"广播数据")}static getDD5AE1Async(deviceId,value){const _command=["0xE1","0x02","0x00",value],checks=this.generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return this.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&225==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_E1")}}exports.BleCmdAnalysis=BleCmdAnalysis,exports.default=BleCmdAnalysis;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import BleDataProcess from"./BleDataProcess.js";import{getOS,eventBus}from"./commonfun.js";class BleCmdAnalysis extends BleDataProcess{static async _writeAsync(deviceId,value){return console.log("deviceId, value: ",deviceId,value),!(!deviceId||!value)&&new Promise(resolve=>{const characteristicId=this.UUID_WRITE,{isAndroid:isAndroid,isIOS:isIOS}=getOS();console.log("isAndroid, isIOS: ",isAndroid,isIOS);const writeType=isAndroid?"writeNoResponse":"write";uni.writeBLECharacteristicValue({deviceId:deviceId,serviceId:this.serviceId,characteristicId:characteristicId,writeType:writeType,value:value,success:res=>{console.error("res: 写入成功",res),resolve(!0)},fail:e=>{console.error("写入失败",e),resolve(!1)}}),isIOS&&setTimeout(()=>resolve(!0),50)})}static async writeAsync(deviceId,value){return console.log("value: ",value),console.log("deviceId: ",deviceId),!(!deviceId||!value)&&new Promise(async resolve=>{const n=Math.ceil(value.byteLength/20);let res;for(let i=0;i<n;i++){const _value=value.slice(20*i,20*(i+1));if(console.log("分包写入_value: ",_value),await this.sleep(150),res=await this._writeAsync(deviceId,_value),console.log(`分包写入结果 ${i+1}/${n} : ${res}`),!res)return resolve(!1)}resolve(res)})}static async getData(deviceId,{command:command,commandVerifyHandler:commandVerifyHandler=hexArr=>({verified:!1,pkgLen:null}),pkgVerifyHandler:pkgVerifyHandler=pkg=>({verified:!1}),maxRetries:maxRetries=2,retryInterval:retryInterval=300},tag=""){if(!deviceId)throw new Error("deviceId is required");if(!command||command.length<=0)throw new Error("command is required");return new Promise((resolve,reject)=>{let isCompleted=!1,timeoutId=null,responsed=!1,len=null,pkg=[];const cmdContent=this.hexArr2ab(command),cleanup=()=>{isCompleted||(isCompleted=!0,clearTimeout(timeoutId),eventBus.off("setBleChangedCharacteristicValue",dataHandler))},dataHandler=payload=>{if(!payload||payload.deviceId!==deviceId||!payload.value)return;const hexArr=this.ab2decimalArr(payload.value);if(console.warn(tag,"接收到数据:",this.hexArr2string(hexArr)),0!==hexArr.length){if(null===len){const{verified:verified,pkgLen:pkgLen}=commandVerifyHandler(hexArr);console.log("指令验证结果:",{verified:verified,pkgLen:pkgLen}),verified&&(len=pkgLen)}if(len){if(pkg=[...pkg,...hexArr],console.log("当前数据包:",pkg,`长度: ${pkg.length}/${len}`),pkg.length>=len){pkg=pkg.slice(0,len);const{verified:verified}=pkgVerifyHandler(pkg);console.log("数据包验证结果:",{verified:verified}),verified?(responsed=!0,cleanup(),resolve([...pkg])):(len=null,pkg=[])}}else pkg=[]}},writeToDevice=async(attempt=1)=>{try{console.warn(tag,`第${attempt}次写入指令:`,command.join("").replace(/0x/g,"").toUpperCase());const writeSucceed=await this.writeAsync(deviceId,cmdContent);if(console.warn(tag,`第${attempt}次写入结果:`,writeSucceed?"成功":"失败"),!writeSucceed)return void(attempt<maxRetries?setTimeout(()=>writeToDevice(attempt+1),retryInterval):(cleanup(),resolve(null)));await this.sleep(retryInterval),!responsed&&attempt<maxRetries?(console.log(tag,`未收到响应,准备第${attempt+1}次重试`),writeToDevice(attempt+1)):responsed||(console.warn(tag,`达到最大重试次数(${maxRetries}),未收到响应`),cleanup(),resolve(null))}catch(error){console.error(tag,"写入过程发生错误:",error),cleanup(),reject(error)}};timeoutId=setTimeout(()=>{console.warn(tag,"操作超时"),cleanup(),resolve(null)},(maxRetries+2)*retryInterval),eventBus.on("setBleChangedCharacteristicValue",dataHandler),writeToDevice().catch(error=>{cleanup(),reject(error)})})}static async getDDA503Async(deviceId){const hex=await this.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]=this.generateCrcCheckSum(pkg.slice(2,len-3)),[_c1,_c2]=[pkg[len-3],pkg[len-2]];return{verified:c1==_c1&&c2==_c2}}},"DDA5_03");return hex?this.resolveDDA503(hex):null}static resolveDDA503(data){if(!data)return null;const dataStr=this.hexArr2string(data),content=data.slice(4,data.length-3),binArr=data[24].toString(2).padStart(8,"0").split("").reverse(),n=Number(binArr[7])?10:100,fet=data[24],chargeSwitch=1==fet||3==fet,dischargeSwitch=2==fet||3==fet,BMSVersion=this.decimalToHex(data[22]),totalVoltage=(((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=(parseFloat(totalVoltage)*electricity).toFixed(2),soc=data[23]??0,volumeHex=this.decimalToHex(data[8])+this.decimalToHex(data[9]),seriesNum=data[25]??0,surplusCapacity=Number((this.hexToDecimal(volumeHex)/n).toFixed(2)),normCapHex=this.decimalToHex(data[10])+this.decimalToHex(data[11]),normCap=Number((this.hexToDecimal(normCapHex)/n).toFixed(2)),humidityIndex=2*data[26]+27,humidity=data[humidityIndex],cycleHex=this.decimalToHex(data[12])+this.decimalToHex(data[13]),cycleIndex=this.hexToDecimal(cycleHex),fccHex=this.decimalToHex(data[humidityIndex+3])+this.decimalToHex(data[humidityIndex+4]),fullChargeCapacity=10*this.hexToDecimal(fccHex)/1e3,SOH=cycleIndex<=100?100:Math.min(100,fullChargeCapacity/normCap*100),isHeating=!!Number(binArr[4]);let heatingCurrent=0;if(isHeating){const i=humidityIndex+9;heatingCurrent=10*parseInt([data[i],data[i+1]].map(o=>o.toString(16)).join(""),16)}const isFactoryMode=!!Number(binArr[6]),equilibriumStatus=!(0===data[16]&&0===data[17]),protectStatus=!(0===data[20]&&0===data[21]),protectStateHex=this.decimalToHex(data[20])+this.decimalToHex(data[21]),protectState=this.hexToDecimal(protectStateHex);let protectStatusIndexs=[];for(let i=0;i<16;i++)protectState&1<<i&&protectStatusIndexs.push(i);const protectStatusIndex=protectStatusIndexs.join(","),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=[];return temperaturesList.forEach(el=>{const value=1.8*Number(el)+32;fahTempList.push(value.toFixed(1))}),{dataStr:dataStr,status:this.hex2string(data[2]),len:data[3],softwareV:this.hex2string(content[18]),chargeSwitch:chargeSwitch,dischargeSwitch:dischargeSwitch,BMSVersion:BMSVersion,totalVoltage:totalVoltage,electricity:electricity,power:power,soc:soc,surplusCapacity:surplusCapacity,normCap:normCap,humidity:humidity,cycleIndex:cycleIndex,fullChargeCapacity:fullChargeCapacity,SOH:SOH,isHeating:isHeating,heatingCurrent:heatingCurrent,isFactoryMode:isFactoryMode,equilibriumStatus:equilibriumStatus,protectStatus:protectStatus,protectStatusIndex:protectStatusIndex,ntcNums:ntcNums,temperaturesList:temperaturesList,fahTempList:fahTempList,fet:fet,seriesNum:seriesNum}}static getFFAA17Async(deviceId){return this.getData(deviceId,{command:["0xFF","0xAA","0x17","0x00","0x17"],commandVerifyHandler:hexArr=>({verified:255==hexArr[0]&&170==hexArr[1]&&23==hexArr[2],pkgLen:hexArr[3]+5}),pkgVerifyHandler:pkg=>{const _pkg=pkg.map(o=>this.hex2string(o)),len=pkg.length,[c1]=this.generateCheckSum(_pkg.slice(2,len-1));return{verified:c1==pkg[len-1]}}},"FFAA_17(获取随机数)")}static getFFAAKeyAsync(deviceId,code,content,type){const commandCode=[code],data=[...content],dataLength=[`0x${this.decimalToHex(data.length,2)}`],check=this.generateCheckSum([...commandCode,...dataLength,...data]),command=["0xff","0xaa",...commandCode,...dataLength,...data,...check];return console.log("command: ---------------",command),this.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:255==hexArr[0]&&170==hexArr[1]&&hexArr[2]==this.hexToDecimal(code),pkgLen:hexArr[3]+5}),pkgVerifyHandler:pkg=>{const _pkg=pkg.map(o=>this.hex2string(o)),len=pkg.length,[c1]=this.generateCheckSum(_pkg.slice(2,len-1));return{verified:c1==pkg[len-1]}}},`FFAA_${code}(${type})`)}static resolveFFAAKey(data){if(!data)return null;const dataStr=this.hexArr2string(data),response=data[data.length-2];return{dataStr:dataStr,response:response,status:response}}static getBroadcastDataCmd(deviceId){return this.getFFAAKeyAsync(deviceId,"0x19",["0x01"],"广播数据")}static getDD5AE1Async(deviceId,value){const _command=["0xE1","0x02","0x00",value],checks=this.generateCrcCheckSum(_command),command=["0xDD","0x5A",..._command,...checks,"0x77"];return this.getData(deviceId,{command:command,commandVerifyHandler:hexArr=>({verified:221==hexArr[0]&&225==hexArr[1],pkgLen:hexArr[3]+7}),pkgVerifyHandler:pkg=>({verified:!0})},"DD5A_E1")}}export{BleCmdAnalysis,BleCmdAnalysis as default};
|