@jiabaida/tools 1.0.2 → 1.0.3
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/BleCmdDD.js +1 -1
- package/dist/cjs/core/BleCmdAnalysis/readAndSetParam.js +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/esm/core/BleApiManager.js +1 -1
- package/dist/esm/core/BleCmdAnalysis/BleCmdDD.js +1 -1
- package/dist/esm/core/BleCmdAnalysis/readAndSetParam.js +1 -1
- package/dist/esm/index.js +1 -1
- package/package.json +1 -1
- package/src/core/BleApiManager.js +16 -6
- package/src/core/BleCmdAnalysis/BleCmdDD.js +123 -2
- package/src/core/BleCmdAnalysis/BleCmdDDA4.js +761 -761
- package/src/core/BleCmdAnalysis/readAndSetParam.js +9 -7
- package/dist/cjs/core/BleCmdAnalysis.js +0 -1
- package/dist/esm/core/BleCmdAnalysis.js +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { decimalToHex, generateCrc16modbusCheck, generateCrcCheckSum, hex2string, hexArr2Assic, hexArr2string, hexToDecimal, sleep, stringToTwoHexArray } from '../BleDataProcess';
|
|
2
|
+
import { getData } from './BleCmdAnalysis.js';
|
|
3
3
|
import { getFFAA80Async, resolveFFAA80 } from './BleCmdFFAA.js';
|
|
4
|
+
|
|
4
5
|
// #region 进出工厂
|
|
5
6
|
/**进工厂 */
|
|
6
7
|
export const enterFactory = async (deviceId) => {
|
|
@@ -658,6 +659,23 @@ export const getDD5A0AAsync = async (deviceId, value) => {
|
|
|
658
659
|
);
|
|
659
660
|
}
|
|
660
661
|
|
|
662
|
+
export const resolveDD5A0A = (data) => {
|
|
663
|
+
if (!data) return null;
|
|
664
|
+
// 示例回复: DD 0A 00 00 00 00 77
|
|
665
|
+
const dataStr = hexArr2string(data);
|
|
666
|
+
const statusDec = data[2];
|
|
667
|
+
const len = data[3];
|
|
668
|
+
const succeeded = statusDec === 0x00; // 0 成功, 其它失败/异常
|
|
669
|
+
// 校验位为最后倒数第三、倒数第二字节, 这里可按其他DD指令算法校验 (长度极短可忽略)
|
|
670
|
+
return {
|
|
671
|
+
dataStr,
|
|
672
|
+
status: hex2string(statusDec),
|
|
673
|
+
len,
|
|
674
|
+
succeeded,
|
|
675
|
+
message: succeeded ? 'CMD_EXEC_SUCCESS' : 'CMD_EXEC_FAIL',
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
|
|
661
679
|
// #region 设置满充容量
|
|
662
680
|
/**设置满充容量
|
|
663
681
|
*
|
|
@@ -1211,4 +1229,107 @@ export const get3B3CInfo = ({ deviceId, macAddr, moduleType, productType }) => {
|
|
|
1211
1229
|
reject(error);
|
|
1212
1230
|
}
|
|
1213
1231
|
});
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
// #region 发送设备激活指令
|
|
1235
|
+
export const activateAsync = async (deviceId) => {
|
|
1236
|
+
const startTime = +new Date();
|
|
1237
|
+
const disChargMOSHex = await getDD5AFBAsync(deviceId, '0x00', '0x00');
|
|
1238
|
+
const disChargMOSRes = resolveBaseDD(disChargMOSHex)?.dataStr;
|
|
1239
|
+
const disChargEndTime = +new Date();
|
|
1240
|
+
const activeHex = await getDD5AFBAsync(deviceId, '0x05', '0x01');
|
|
1241
|
+
const activeRes = resolveBaseDD(disChargMOSHex)?.dataStr;
|
|
1242
|
+
let baseInfo = null
|
|
1243
|
+
const endTime = +new Date();
|
|
1244
|
+
await sleep(300)
|
|
1245
|
+
baseInfo = await getDDA503Async(deviceId);
|
|
1246
|
+
const voltageInfo = await getDDA504Async(deviceId);
|
|
1247
|
+
return { disChargMOSHex, disChargMOSRes, activeHex, activeRes, baseInfo, voltageInfo, startTime, disChargEndTime, endTime };
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
// #region 获取均衡线电阻 DC 指令
|
|
1251
|
+
/** 获取均衡线电阻 DC 指令
|
|
1252
|
+
* 协议: 主机发送 DD A5 DC 00 CS1 CS2 77, BMS响应: DD DC STATUS LEN Data.. CS1 CS2 77
|
|
1253
|
+
* Data: 每个电芯占2字节, 小端(uint16), 单位 mΩ
|
|
1254
|
+
* @param {*} deviceId
|
|
1255
|
+
* @returns Promise<number[]|null>
|
|
1256
|
+
*/
|
|
1257
|
+
export const getDDA5DCAsync = (deviceId) => {
|
|
1258
|
+
// 组成指令: 帧头0xDD 0xA5, 命令码0xDC, 数据长度0x00, 校验和(命令码+长度), 结束位0x77
|
|
1259
|
+
const _command = ['0xDE', '0x00'];
|
|
1260
|
+
const checks = generateCrcCheckSum(_command); // 计算校验和
|
|
1261
|
+
const command = ['0xDD', '0xA5', ..._command, ...checks, '0x77'];
|
|
1262
|
+
return getData(
|
|
1263
|
+
deviceId,
|
|
1264
|
+
{
|
|
1265
|
+
command,
|
|
1266
|
+
commandVerifyHandler: (hexArr) => ({ verified: hexArr[0] == 0xdd && hexArr[1] == 0xde, pkgLen: hexArr[3] + 7 }),
|
|
1267
|
+
pkgVerifyHandler: (pkg) => {
|
|
1268
|
+
const len = pkg.length;
|
|
1269
|
+
// 校验范围: status(索引2) ~ data 末尾
|
|
1270
|
+
const [c1, c2] = generateCrcCheckSum(pkg.slice(2, len - 3));
|
|
1271
|
+
const [_c1, _c2] = [pkg[len - 3], pkg[len - 2]];
|
|
1272
|
+
return { verified: c1 == _c1 && c2 == _c2 };
|
|
1273
|
+
},
|
|
1274
|
+
},
|
|
1275
|
+
'DDA5_DC'
|
|
1276
|
+
);
|
|
1277
|
+
}
|
|
1278
|
+
/** 解析均衡线电阻 DC 指令
|
|
1279
|
+
* @param {number[]} data 响应数据
|
|
1280
|
+
* @returns {Object|null}
|
|
1281
|
+
*/
|
|
1282
|
+
export const resolveDDA5DC = (data) => {
|
|
1283
|
+
if (!data) return null;
|
|
1284
|
+
const dataStr = hexArr2string(data);
|
|
1285
|
+
const status = hex2string(data[2]);
|
|
1286
|
+
const len = data[3] & 0xff;
|
|
1287
|
+
// 大端: 高字节在前, 低字节在后
|
|
1288
|
+
const resistances_milliohm = [];
|
|
1289
|
+
for (let i = 4; i < 4 + len; i += 2) {
|
|
1290
|
+
const high = data[i] & 0xff;
|
|
1291
|
+
const low = data[i + 1] & 0xff;
|
|
1292
|
+
const value = (high << 8) + low; // uint16 mΩ
|
|
1293
|
+
resistances_milliohm.push(value);
|
|
1294
|
+
}
|
|
1295
|
+
console.log('均衡线电阻(mΩ): ', resistances_milliohm, data);
|
|
1296
|
+
let maxResistance = null, minResistance = null, avgResistance = null;
|
|
1297
|
+
if (resistances_milliohm.length) {
|
|
1298
|
+
maxResistance = Math.max(...resistances_milliohm);
|
|
1299
|
+
minResistance = Math.min(...resistances_milliohm);
|
|
1300
|
+
avgResistance = resistances_milliohm.reduce((a, c) => a + c, 0) / resistances_milliohm.length;
|
|
1301
|
+
}
|
|
1302
|
+
const resistances_ohm = resistances_milliohm.map(v => Number((v / 1000).toFixed(3)));
|
|
1303
|
+
const resistancesSeries = resistances_ohm.map((v, idx) => ({ name: idx + 1, value: v }));
|
|
1304
|
+
return {
|
|
1305
|
+
dataStr,
|
|
1306
|
+
status,
|
|
1307
|
+
len,
|
|
1308
|
+
resistances_milliohm,
|
|
1309
|
+
resistances_ohm,
|
|
1310
|
+
maxResistance_milliohm: maxResistance,
|
|
1311
|
+
minResistance_milliohm: minResistance,
|
|
1312
|
+
avgResistance_milliohm: avgResistance,
|
|
1313
|
+
maxResistance_ohm: maxResistance != null ? Number((maxResistance / 1000).toFixed(3)) : null,
|
|
1314
|
+
minResistance_ohm: minResistance != null ? Number((minResistance / 1000).toFixed(3)) : null,
|
|
1315
|
+
avgResistance_ohm: avgResistance != null ? Number((avgResistance / 1000).toFixed(3)) : null,
|
|
1316
|
+
resistancesSeries,
|
|
1317
|
+
};
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
/**重置容量
|
|
1321
|
+
*/
|
|
1322
|
+
export const resetCapacity = (deviceId) => {
|
|
1323
|
+
const command = ['0xDD', '0x5A', '0x0A', '0x02', '0x01', '0x00', '0xFF', '0xF3', '0x77'];
|
|
1324
|
+
return getData(
|
|
1325
|
+
deviceId,
|
|
1326
|
+
{
|
|
1327
|
+
command,
|
|
1328
|
+
commandVerifyHandler: (hexArr) => ({ verified: hexArr[0] == 0xdd && hexArr[1] == 0x0A, pkgLen: hexArr[3] + 7 }),
|
|
1329
|
+
pkgVerifyHandler: (pkg) => {
|
|
1330
|
+
return { verified: true };
|
|
1331
|
+
},
|
|
1332
|
+
},
|
|
1333
|
+
'DD5A_0A'
|
|
1334
|
+
);
|
|
1214
1335
|
}
|