@jiabaida/tools 1.0.7 → 1.0.10
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/BleCmdAnalysis.js +1 -1
- package/dist/cjs/core/BleCmdAnalysis/BleCmdDD.js +1 -1
- package/dist/cjs/core/BleCmdAnalysis/BleCmdDDA4.js +1 -1
- package/dist/cjs/core/BleCmdAnalysis/BleCmdFFAA.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/Queue.js +1 -0
- package/dist/cjs/core/mqttServer.js +1 -1
- package/dist/cjs/core/tcpServer.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 -1
- package/dist/esm/core/BleCmdAnalysis/BleCmdAnalysis.js +1 -1
- package/dist/esm/core/BleCmdAnalysis/BleCmdDD.js +1 -1
- package/dist/esm/core/BleCmdAnalysis/BleCmdDDA4.js +1 -1
- package/dist/esm/core/BleCmdAnalysis/BleCmdFFAA.js +1 -1
- package/dist/esm/core/BleCmdAnalysis/BleCmdHVES.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/Queue.js +1 -0
- package/dist/esm/core/mqttServer.js +1 -1
- package/dist/esm/core/tcpServer.js +1 -0
- package/dist/esm/index.js +1 -1
- package/package.json +1 -1
- package/src/core/BleApiManager.js +33 -15
- package/src/core/BleCmdAnalysis/BaseParamProtocol.js +116 -32
- package/src/core/BleCmdAnalysis/BleCmdAnalysis.js +58 -2
- package/src/core/BleCmdAnalysis/BleCmdDD.js +88 -19
- package/src/core/BleCmdAnalysis/BleCmdDDA4.js +154 -227
- package/src/core/BleCmdAnalysis/BleCmdFFAA.js +1 -0
- package/src/core/BleCmdAnalysis/readAndSetParam.js +133 -16
- package/src/core/BleDataProcess.js +15 -11
- package/src/core/OtaUpgrade.js +356 -350
- package/src/core/Queue.js +34 -0
- package/src/core/mqttServer.js +75 -5
- package/src/core/tcpServer.js +341 -0
- package/src/index.js +1 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { decimalToHex, decimalToTwoByteHexArray } from '../BleDataProcess.js';
|
|
2
|
-
import { enterFactory, existFactory, getDDA5FAAsync, getDDA5OldAsync, readExistFactory, setDDA5FAAsync, setDDA5OldAsync } from './BleCmdDD.js';
|
|
1
|
+
import { decimalToHex, decimalToTwoByteHexArray, sleep, decimalToHex0x } from '../BleDataProcess.js';
|
|
2
|
+
import { enterFactory, existFactory, getDD5AE1Async, getDD5AFBAsync, getDDA5FAAsync, getDDA5OldAsync, readExistFactory, resolveBaseDD, setDDA5FAAsync, setDDA5OldAsync } from './BleCmdDD.js';
|
|
3
3
|
|
|
4
4
|
// #region 发指令读取参数
|
|
5
5
|
/**
|
|
@@ -20,7 +20,7 @@ export const readParamCmd = (chipType, deviceId, paramInfo, needFactoryMode = tr
|
|
|
20
20
|
/** 地址转换为16进制 */
|
|
21
21
|
const hexAddress = decimalToTwoByteHexArray(address);
|
|
22
22
|
// 长度转换为16进制
|
|
23
|
-
const hexLength =
|
|
23
|
+
const hexLength = decimalToHex0x(length);
|
|
24
24
|
const handleRead = async (readFunction, index) => {
|
|
25
25
|
try {
|
|
26
26
|
const hex = await readFunction();
|
|
@@ -68,7 +68,7 @@ export const readParamCmd = (chipType, deviceId, paramInfo, needFactoryMode = tr
|
|
|
68
68
|
*/
|
|
69
69
|
export const getSysParamCmd = async (chipType, deviceId, paramInfo, needFactoryMode = true) => {
|
|
70
70
|
try {
|
|
71
|
-
console.
|
|
71
|
+
console.warn('paramInfo:参数信息', paramInfo);
|
|
72
72
|
const paramObj = {
|
|
73
73
|
address: paramInfo.paramNo,
|
|
74
74
|
length: paramInfo.paramLength / 2,
|
|
@@ -89,10 +89,12 @@ export const getSysParamCmd = async (chipType, deviceId, paramInfo, needFactoryM
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
// #region 系统写参数处理
|
|
92
|
+
// #region 系统写参数处理 判断wifi或蓝牙
|
|
93
93
|
/**
|
|
94
94
|
* @param {*} chipType 芯片类型
|
|
95
95
|
* @param {*} deviceId 设备deviceId
|
|
96
|
+
* @param {*} macAddr 设备macAddr
|
|
97
|
+
* @param {*} blueConnect 是否通过蓝牙连接 默认true
|
|
96
98
|
* @param {Array|Object} paramInfoArray 包含多个参数信息的数组或单个参数信息对象
|
|
97
99
|
* @param {*} paramInfoArray[].newValue 新设置的参数输入值十进制值
|
|
98
100
|
* @param {*} paramInfoArray[].paramValue 新设置的参数值十进制值 部分参数输入的值需单独处理
|
|
@@ -113,12 +115,15 @@ export const setSysParamCmd = async (chipType, deviceId, paramInfoArray) => {
|
|
|
113
115
|
const paramObjs = [];
|
|
114
116
|
|
|
115
117
|
for (const paramInfo of paramsToProcess) {
|
|
116
|
-
|
|
118
|
+
// 根据系数处理参数值
|
|
119
|
+
let value = Number(paramInfo?.paramValue || paramInfo.newValue) / Number(paramInfo?.divisor || 1);
|
|
117
120
|
console.log('value: ', value);
|
|
118
121
|
if (paramInfo.isTemp) {
|
|
119
122
|
value = 2731 + (Number(paramInfo.newValue) * 10)
|
|
120
123
|
}
|
|
121
|
-
|
|
124
|
+
value = Math.round(value);
|
|
125
|
+
let valuesHexs = [];
|
|
126
|
+
valuesHexs = decimalToTwoByteHexArray(value);
|
|
122
127
|
console.log('valuesHexs: ', valuesHexs);
|
|
123
128
|
|
|
124
129
|
// 将处理后的参数对象添加到数组中
|
|
@@ -127,11 +132,14 @@ export const setSysParamCmd = async (chipType, deviceId, paramInfoArray) => {
|
|
|
127
132
|
length: paramInfo.paramLength / 2,
|
|
128
133
|
values: valuesHexs,
|
|
129
134
|
oldAddress: paramInfo.oldParamNo,
|
|
135
|
+
newValue: value,
|
|
130
136
|
});
|
|
131
137
|
}
|
|
132
138
|
|
|
133
139
|
// 一次性将所有参数对象数组传递给setParamCmd函数
|
|
140
|
+
console.log("chipType: 芯片", chipType);
|
|
134
141
|
await setParamCmd(chipType, deviceId, paramObjs);
|
|
142
|
+
|
|
135
143
|
} catch (error) {
|
|
136
144
|
console.error('error: 写系统参数报错 setSysParamCmd', error);
|
|
137
145
|
throw error
|
|
@@ -143,6 +151,7 @@ export const setSysParamCmd = async (chipType, deviceId, paramInfoArray) => {
|
|
|
143
151
|
* 发指令设置参数
|
|
144
152
|
* @param {*} chipType 芯片类型
|
|
145
153
|
* @param {*} deviceId 设备deviceId
|
|
154
|
+
* @param {*} macAddr 设备macAddr
|
|
146
155
|
* @param {Array} paramInfoArray 参数信息数组 或单个对象
|
|
147
156
|
* @param {*} paramInfoArray[].address 新协议开始写入地址(十进制)如 31
|
|
148
157
|
* @param {*} paramInfoArray[].length 新协议写参数内容长度(写几个)(十进制)如 1
|
|
@@ -150,7 +159,7 @@ export const setSysParamCmd = async (chipType, deviceId, paramInfoArray) => {
|
|
|
150
159
|
* @param {*} paramInfoArray[].oldAddress 旧协议写入地址 默认一个(十六进制字符串)如 '0x1f'
|
|
151
160
|
* @returns {Promise<Array>} 包含所有参数设置结果的数组
|
|
152
161
|
*/
|
|
153
|
-
export const setParamCmd = (chipType, deviceId, paramInfoArray) => {
|
|
162
|
+
export const setParamCmd = async (chipType, deviceId, paramInfoArray) => {
|
|
154
163
|
console.log("chipType: 芯片", chipType);
|
|
155
164
|
|
|
156
165
|
// 确保paramInfoArray是数组
|
|
@@ -212,6 +221,84 @@ export const setParamCmd = (chipType, deviceId, paramInfoArray) => {
|
|
|
212
221
|
});
|
|
213
222
|
}
|
|
214
223
|
|
|
224
|
+
/** 控制开关
|
|
225
|
+
* @param {*} deviceId
|
|
226
|
+
* @param {*} typeCmd 0x00 - 放电MOS 0x01 - 充电MOS
|
|
227
|
+
* @param {*} currentSwitch 当前修改开关状态 true - 打开 false - 关闭
|
|
228
|
+
* @param {*} anotherSwitch 另一个开关状态
|
|
229
|
+
* @returns 指令结果 Ooj.status: 00 - 成功 81/84 不支持 82/83 失败
|
|
230
|
+
*/
|
|
231
|
+
export const controlSwitch = async (deviceId, typeCmd, currentSwitch, anotherSwitch) => {
|
|
232
|
+
//充放电开关
|
|
233
|
+
const hex = await getDD5AFBAsync(
|
|
234
|
+
deviceId,
|
|
235
|
+
typeCmd,
|
|
236
|
+
currentSwitch ? "0x00" : "0x01",
|
|
237
|
+
);
|
|
238
|
+
const mosRes = resolveBaseDD(hex);
|
|
239
|
+
console.log("hex: ", hex);
|
|
240
|
+
let dataRes = mosRes
|
|
241
|
+
//FB指令控制mos失败或无响应,发送E1指令
|
|
242
|
+
if (!mosRes || mosRes?.status != '00') {
|
|
243
|
+
const cmd = getE1Cmd(typeCmd, currentSwitch, anotherSwitch);
|
|
244
|
+
const e1hex = await getDD5AE1Async(
|
|
245
|
+
deviceId,
|
|
246
|
+
cmd
|
|
247
|
+
);
|
|
248
|
+
dataRes = resolveBaseDD(e1hex);
|
|
249
|
+
}
|
|
250
|
+
return dataRes
|
|
251
|
+
}
|
|
252
|
+
/** 计算E1指令
|
|
253
|
+
* @param {*} typeCmd 0x00 - 放电MOS 0x01 - 充电MOS
|
|
254
|
+
* @param {*} currentSwitch 当前修改开关状态 true - 打开 false - 关闭
|
|
255
|
+
* @param {*} anotherSwitch 另一个开关状态 true - 打开 false - 关闭
|
|
256
|
+
* @returns 0x00 - 充电MOS打开 放电MOS打开
|
|
257
|
+
* 0x01 - 充电MOS关闭 放电MOS打开
|
|
258
|
+
* 0x02 - 充电MOS打开 放电MOS关闭
|
|
259
|
+
* 0x03 - 充电MOS关闭 放电MOS关闭
|
|
260
|
+
*/
|
|
261
|
+
export const getE1Cmd = (typeCmd, currentSwitch, anotherSwitch) => {
|
|
262
|
+
let cmd = '0x00'
|
|
263
|
+
// 根据E1指令码定义计算:
|
|
264
|
+
// 0x00 - 充电MOS打开 放电MOS打开
|
|
265
|
+
// 0x01 - 充电MOS关闭 放电MOS打开
|
|
266
|
+
// 0x02 - 充电MOS打开 放电MOS关闭
|
|
267
|
+
// 0x03 - 充电MOS关闭 放电MOS关闭
|
|
268
|
+
if (typeCmd === '0x00') {
|
|
269
|
+
// 当前是放电操作
|
|
270
|
+
if (currentSwitch && anotherSwitch) {
|
|
271
|
+
// 放电MOS打开,充电MOS打开
|
|
272
|
+
cmd = '0x00'
|
|
273
|
+
} else if (currentSwitch && !anotherSwitch) {
|
|
274
|
+
// 放电MOS打开,充电MOS关闭
|
|
275
|
+
cmd = '0x01'
|
|
276
|
+
} else if (!currentSwitch && anotherSwitch) {
|
|
277
|
+
// 放电MOS关闭,充电MOS打开
|
|
278
|
+
cmd = '0x02'
|
|
279
|
+
} else {
|
|
280
|
+
// 放电MOS关闭,充电MOS关闭
|
|
281
|
+
cmd = '0x03'
|
|
282
|
+
}
|
|
283
|
+
} else if (typeCmd === '0x01') {
|
|
284
|
+
// 当前是充电操作
|
|
285
|
+
if (currentSwitch && anotherSwitch) {
|
|
286
|
+
// 充电MOS打开,放电MOS打开
|
|
287
|
+
cmd = '0x00'
|
|
288
|
+
} else if (!currentSwitch && anotherSwitch) {
|
|
289
|
+
// 充电MOS关闭,放电MOS打开
|
|
290
|
+
cmd = '0x01'
|
|
291
|
+
} else if (currentSwitch && !anotherSwitch) {
|
|
292
|
+
// 充电MOS打开,放电MOS关闭
|
|
293
|
+
cmd = '0x02'
|
|
294
|
+
} else {
|
|
295
|
+
// 充电MOS关闭,放电MOS关闭
|
|
296
|
+
cmd = '0x03'
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return cmd
|
|
300
|
+
}
|
|
301
|
+
|
|
215
302
|
// #region 写入标称容量
|
|
216
303
|
/**写入标称容量 同步写入满充及循环
|
|
217
304
|
* @param {*} chipType 芯片类型
|
|
@@ -230,17 +317,17 @@ export const setCapacityParamCmd = (chipType, deviceId, paramInfo) => {
|
|
|
230
317
|
const { values } = paramInfo;
|
|
231
318
|
// 循环 循环是标称的80%
|
|
232
319
|
const circular = {
|
|
233
|
-
|
|
234
|
-
|
|
320
|
+
paramNo: 1,
|
|
321
|
+
oldParamNo: "0x11",
|
|
235
322
|
values: values * 0.8,
|
|
236
|
-
|
|
323
|
+
paramLength: 2,
|
|
237
324
|
};
|
|
238
325
|
// 满充 满充等于标称 旧协议没有满充
|
|
239
326
|
const full = {
|
|
240
|
-
|
|
241
|
-
|
|
327
|
+
paramNo: 112,
|
|
328
|
+
oldParamNo: "0x10",
|
|
242
329
|
values: values,
|
|
243
|
-
|
|
330
|
+
paramLength: 2,
|
|
244
331
|
};
|
|
245
332
|
|
|
246
333
|
const handleSet = async (setFunction, index) => {
|
|
@@ -272,12 +359,42 @@ export const setCapacityParamCmd = (chipType, deviceId, paramInfo) => {
|
|
|
272
359
|
return await handleSet(() => setDDA5OldAsync(deviceId, oldParamNo, hexValues), 4);
|
|
273
360
|
}
|
|
274
361
|
};
|
|
362
|
+
|
|
363
|
+
// 写入容量参数的高低位(标称容量、满充容量)
|
|
364
|
+
const handleCapacityParam = async (paramObj, lowParamNo, highParamNo) => {
|
|
365
|
+
const value = Math.round(Number(paramObj.values) / paramInfo.divisor);
|
|
366
|
+
console.log(`容量参数value (paramNo ${lowParamNo}):`, value);
|
|
367
|
+
|
|
368
|
+
// 拆分成高低16位
|
|
369
|
+
const lowValue = value & 0xFFFF; // 低16位
|
|
370
|
+
const highValue = (value >> 16) & 0xFFFF; // 高16位
|
|
371
|
+
|
|
372
|
+
// 写入低16位
|
|
373
|
+
const lowBytes = decimalToTwoByteHexArray(lowValue);
|
|
374
|
+
const lowAddress = decimalToTwoByteHexArray(lowParamNo);
|
|
375
|
+
const hexLength = decimalToHex(1);
|
|
376
|
+
const lowHex = await handleSet(async () => await setDDA5FAAsync(deviceId, lowAddress, hexLength, lowBytes), 7);
|
|
377
|
+
|
|
378
|
+
// 写入高16位
|
|
379
|
+
const highBytes = decimalToTwoByteHexArray(highValue);
|
|
380
|
+
const highAddress = decimalToTwoByteHexArray(highParamNo);
|
|
381
|
+
const highHex = await handleSet(async () => await setDDA5FAAsync(deviceId, highAddress, hexLength, highBytes), 7);
|
|
382
|
+
|
|
383
|
+
return lowHex && highHex;
|
|
384
|
+
};
|
|
275
385
|
try {
|
|
276
386
|
await enterFactory(deviceId);
|
|
277
|
-
|
|
387
|
+
let paramInfoHex;
|
|
388
|
+
if (chipType) {
|
|
389
|
+
// 新协议:标称容量需要写入两个参数(paramNo 0和155)
|
|
390
|
+
paramInfoHex = await handleCapacityParam(paramInfo, 0, 155);
|
|
391
|
+
} else {
|
|
392
|
+
// 旧协议:直接写入
|
|
393
|
+
paramInfoHex = await handleParam(paramInfo);
|
|
394
|
+
}
|
|
278
395
|
const circularHex = await handleParam(circular);
|
|
279
396
|
if (chipType) {
|
|
280
|
-
const fullHex = await
|
|
397
|
+
const fullHex = await handleCapacityParam(full, 112, 156);
|
|
281
398
|
}
|
|
282
399
|
await existFactory(deviceId);
|
|
283
400
|
if (paramInfoHex) {
|
|
@@ -312,22 +312,26 @@
|
|
|
312
312
|
return new Promise((r) => setTimeout(() => r(true), n));
|
|
313
313
|
}
|
|
314
314
|
/**
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
315
|
+
* 将一个十进制数转换为两个字节的十六进制数组。
|
|
316
|
+
* @param {number} decimal - 要转换的十进制数。
|
|
317
|
+
* @returns {Array<string>} 包含两个十六进制字符串的数组,每个字符串表示一个字节。
|
|
318
|
+
*/
|
|
319
319
|
export const decimalToTwoByteHexArray = (decimal) => {
|
|
320
|
-
//
|
|
321
|
-
if (
|
|
322
|
-
throw new Error('
|
|
320
|
+
// 范围检查(支持有符号和无符号)
|
|
321
|
+
if (decimal < -32768 || decimal > 65535) {
|
|
322
|
+
throw new Error('输入超出范围(-32768 到 65535)');
|
|
323
323
|
}
|
|
324
|
-
|
|
325
|
-
|
|
324
|
+
|
|
325
|
+
// 负数转为无符号 16 位表示
|
|
326
|
+
if (decimal < 0) {
|
|
327
|
+
decimal = decimal & 0xFFFF;
|
|
326
328
|
}
|
|
327
|
-
|
|
328
|
-
let
|
|
329
|
+
|
|
330
|
+
let f = `00${(decimal >> 8).toString(16).toUpperCase()}`.slice(-2);
|
|
331
|
+
let e = `00${(decimal & 0xff).toString(16).toUpperCase()}`.slice(-2);
|
|
329
332
|
return [`0x${f}`, `0x${e}`];
|
|
330
333
|
}
|
|
334
|
+
|
|
331
335
|
|
|
332
336
|
/**
|
|
333
337
|
* 将十六进制字符串转换为两个十六进制的数组
|