@jiabaida/tools 1.0.6 → 1.0.8
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 -0
- package/dist/cjs/core/BleCmdAnalysis/readAndSetParam.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 -0
- package/dist/cjs/core/rsaEncrypt.js +1 -0
- 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 -0
- package/dist/esm/core/BleCmdAnalysis/readAndSetParam.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 -0
- package/dist/esm/core/rsaEncrypt.js +1 -0
- package/dist/esm/core/tcpServer.js +1 -0
- package/dist/esm/index.js +1 -1
- package/package.json +4 -3
- package/src/core/BleApiManager.js +3 -1
- package/src/core/BleCmdAnalysis/BaseParamProtocol.js +71 -12
- package/src/core/BleCmdAnalysis/BleCmdAnalysis.js +3 -2
- package/src/core/BleCmdAnalysis/BleCmdDD.js +72 -13
- package/src/core/BleCmdAnalysis/BleCmdDDA4.js +74 -11
- package/src/core/BleCmdAnalysis/index.js +6 -5
- package/src/core/BleCmdAnalysis/readAndSetParam.js +97 -8
- package/src/core/OtaUpgrade.js +8 -2
- package/src/core/Queue.js +34 -0
- package/src/core/mqttServer.js +28 -9
- package/src/core/rsaEncrypt.js +1 -1
- package/src/core/tcpServer.js +303 -0
- package/src/index.js +5 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { getSysParamCmd } from './readAndSetParam'
|
|
2
1
|
import { decimalToHex, hexToDecimal } from '../BleDataProcess';
|
|
3
|
-
import { batteryInfoJson, capInfoJson,
|
|
4
|
-
import {
|
|
2
|
+
import { batteryInfoJson, capInfoJson, capVolInfoJson, currentInfoJson, equalizerFunJson, funcAndTempFuncJson, funcJson, systemJson, tempFuncJson, tempInfoJson, voltageInfoJson } from '../dataJson/baseParamsJson.js';
|
|
3
|
+
import { enterFactory, getProtectCountCmd, readExistFactory } from './BleCmdDD.js';
|
|
4
|
+
import { getSysParamCmd } from './readAndSetParam';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
*
|
|
@@ -117,13 +117,22 @@ export const getBaseParams = async (chipType, deviceData, index, paramObj) => {
|
|
|
117
117
|
case 2:
|
|
118
118
|
let datasInfo2 = {}
|
|
119
119
|
if (chipType) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
datasInfo2['
|
|
120
|
+
|
|
121
|
+
/**读取标称容量:需要读取paramNo 0(低16位)和155(高16位) */
|
|
122
|
+
const normCapLow = await getSysParamCmd(chipType, deviceId, { paramNo: 0, paramLength: 2 })
|
|
123
|
+
const normCapHigh = await getSysParamCmd(chipType, deviceId, { paramNo: 155, paramLength: 2 })
|
|
124
|
+
console.log('normCapLow: ', normCapLow, 'normCapHigh: ', normCapHigh);
|
|
125
|
+
// 合并高低位,每个都只取前2个字节
|
|
126
|
+
datasInfo2['normCap'] = [...(normCapLow?.slice(0, 2) || []), ...(normCapHigh?.slice(0, 2) || [])]
|
|
127
|
+
|
|
128
|
+
const cycleCapData = await getSysParamCmd(chipType, deviceId, capInfoJson[1])
|
|
129
|
+
datasInfo2['cycleCap'] = cycleCapData?.slice(0, 2)
|
|
130
|
+
|
|
131
|
+
/**读取满充容量:需要读取paramNo 112(低16位)和156(高16位) */
|
|
132
|
+
const fullCapLow = await getSysParamCmd(chipType, deviceId, { paramNo: 112, paramLength: 2 })
|
|
133
|
+
const fullCapHigh = await getSysParamCmd(chipType, deviceId, { paramNo: 156, paramLength: 2 })
|
|
134
|
+
console.log('fullCapLow: ', fullCapLow, 'fullCapHigh: ', fullCapHigh);
|
|
135
|
+
datasInfo2['fullCap'] = [...(fullCapLow?.slice(0, 2) || []), ...(fullCapHigh?.slice(0, 2) || [])]
|
|
127
136
|
} else {
|
|
128
137
|
await sendCmdSeq(datasInfo2, chipType, deviceId, capInfoJson)
|
|
129
138
|
}
|
|
@@ -378,9 +387,59 @@ function toHexString(arr) {
|
|
|
378
387
|
}
|
|
379
388
|
const getCapInfo = async (datas) => {
|
|
380
389
|
console.log('datas: ', datas);
|
|
381
|
-
|
|
390
|
+
// 标称容量:低16位(前2字节)+ 高16位(后2字节),单位是0.01AH
|
|
391
|
+
let normCap = null;
|
|
392
|
+
if (datas.normCap && datas.normCap.length >= 4) {
|
|
393
|
+
console.log('normCap原始数据: ', datas.normCap);
|
|
394
|
+
// 读取低16位(前两个字节)- 大端序
|
|
395
|
+
const lowBytes = datas.normCap.slice(0, 2);
|
|
396
|
+
const lowValue = (lowBytes[0] << 8) | lowBytes[1];
|
|
397
|
+
console.log('normCap lowValue: ', lowValue);
|
|
398
|
+
|
|
399
|
+
// 读取高16位(后两个字节)- 大端序
|
|
400
|
+
const highBytes = datas.normCap.slice(2, 4);
|
|
401
|
+
const highValue = (highBytes[0] << 8) | highBytes[1];
|
|
402
|
+
console.log('normCap highValue: ', highValue);
|
|
403
|
+
|
|
404
|
+
// 合并高低位:(高位 << 16) | 低位
|
|
405
|
+
const totalValue = (highValue << 16) | lowValue;
|
|
406
|
+
console.log('normCap totalValue: ', totalValue);
|
|
407
|
+
normCap = Number((totalValue * 0.01).toFixed(2));
|
|
408
|
+
console.log('normCap最终值: ', normCap);
|
|
409
|
+
} else if (datas.normCap && datas.normCap.length >= 2) {
|
|
410
|
+
// 兼容旧协议,只有低16位 - 大端序
|
|
411
|
+
const lowBytes = datas.normCap.slice(0, 2);
|
|
412
|
+
const lowValue = (lowBytes[0] << 8) | lowBytes[1];
|
|
413
|
+
normCap = Number((lowValue * 0.01).toFixed(2));
|
|
414
|
+
}
|
|
415
|
+
|
|
382
416
|
const cycleCap = format(datas.cycleCap, 0.01, 0, 2)
|
|
383
|
-
|
|
417
|
+
|
|
418
|
+
// 满充容量:低16位(前2字节)+ 高16位(后2字节),单位是0.01AH
|
|
419
|
+
let fullCap = null;
|
|
420
|
+
if (datas.fullCap && datas.fullCap.length >= 4) {
|
|
421
|
+
console.log('fullCap原始数据: ', datas.fullCap);
|
|
422
|
+
// 读取低16位(前两个字节)- 大端序
|
|
423
|
+
const lowBytes = datas.fullCap.slice(0, 2);
|
|
424
|
+
const lowValue = (lowBytes[0] << 8) | lowBytes[1];
|
|
425
|
+
console.log('fullCap lowValue: ', lowValue);
|
|
426
|
+
|
|
427
|
+
// 读取高16位(后两个字节)- 大端序
|
|
428
|
+
const highBytes = datas.fullCap.slice(2, 4);
|
|
429
|
+
const highValue = (highBytes[0] << 8) | highBytes[1];
|
|
430
|
+
console.log('fullCap highValue: ', highValue);
|
|
431
|
+
|
|
432
|
+
// 合并高低位:(高位 << 16) | 低位
|
|
433
|
+
const totalValue = (highValue << 16) | lowValue;
|
|
434
|
+
console.log('fullCap totalValue: ', totalValue);
|
|
435
|
+
fullCap = Number((totalValue * 0.01).toFixed(2));
|
|
436
|
+
console.log('fullCap最终值: ', fullCap);
|
|
437
|
+
} else if (datas.fullCap && datas.fullCap.length >= 2) {
|
|
438
|
+
// 兼容旧协议,只有低16位 - 大端序
|
|
439
|
+
const lowBytes = datas.fullCap.slice(0, 2);
|
|
440
|
+
const lowValue = (lowBytes[0] << 8) | lowBytes[1];
|
|
441
|
+
fullCap = Number((lowValue * 0.01).toFixed(2));
|
|
442
|
+
}
|
|
384
443
|
return {
|
|
385
444
|
normCap,
|
|
386
445
|
cycleCap,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ab2decimalArr, hexArr2ab, hexArr2string, sleep } from '../BleDataProcess';
|
|
2
|
+
import { eventBus, getOS, getPlatform } from '../commonfun';
|
|
3
3
|
|
|
4
4
|
const BLE_RESPONSE_TIMEOUT = 300; // 蓝牙指令响应超时
|
|
5
5
|
const STORE_MUTATION_NAME = 'setBleChangedCharacteristicValue';
|
|
@@ -21,6 +21,7 @@ async function _writeAsync(deviceId, value) {
|
|
|
21
21
|
console.log('platform: ', platform);
|
|
22
22
|
console.log('isAndroid, isIOS: ', isAndroid, isIOS);
|
|
23
23
|
const writeType = platform === 'mp-weixin' ? 'writeNoResponse' : isAndroid ? 'writeNoResponse' : 'write';
|
|
24
|
+
console.log('writeType: ', writeType);
|
|
24
25
|
uni.writeBLECharacteristicValue({
|
|
25
26
|
deviceId,
|
|
26
27
|
serviceId,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { decimalToHex, fromBCD, generateCrc16modbusCheck, generateCrcCheckSum, hex2string, hexArr2Assic, hexArr2string, hexToDecimal, isWithin30Minutes, sleep, stringToTwoHexArray, toBCD } from '../BleDataProcess';
|
|
2
2
|
import { getData } from './BleCmdAnalysis.js';
|
|
3
3
|
import { getFFAA80Async, resolveFFAA80 } from './BleCmdFFAA.js';
|
|
4
|
-
|
|
4
|
+
import { controlSwitch } from './readAndSetParam.js';
|
|
5
|
+
|
|
5
6
|
// #region 进出工厂
|
|
6
7
|
/**进工厂 */
|
|
7
8
|
export const enterFactory = async (deviceId) => {
|
|
@@ -358,6 +359,9 @@ export const resolveDDA503 = (data) => {
|
|
|
358
359
|
name: index + 1,
|
|
359
360
|
value: item,
|
|
360
361
|
}));
|
|
362
|
+
const hasProtocol =
|
|
363
|
+
data[3] + 7 >= humidityIndex + 11 + 3 + 1;
|
|
364
|
+
const protocolVersion = data[humidityIndex + 11];
|
|
361
365
|
return {
|
|
362
366
|
cmdResp03,
|
|
363
367
|
status: hex2string(data[2]),
|
|
@@ -391,6 +395,8 @@ export const resolveDDA503 = (data) => {
|
|
|
391
395
|
fahTempList,
|
|
392
396
|
fet,
|
|
393
397
|
seriesNum,
|
|
398
|
+
hasProtocol,
|
|
399
|
+
protocolVersion
|
|
394
400
|
};
|
|
395
401
|
}
|
|
396
402
|
|
|
@@ -1245,18 +1251,71 @@ export const get3B3CInfo = ({ deviceId, macAddr, moduleType, productType }) => {
|
|
|
1245
1251
|
|
|
1246
1252
|
// #region 发送设备激活指令
|
|
1247
1253
|
export const activateAsync = async (deviceId) => {
|
|
1248
|
-
const startTime = +new Date();
|
|
1249
|
-
const disChargMOSHex = await getDD5AFBAsync(deviceId, '0x00', '0x00');
|
|
1250
|
-
const disChargMOSRes = resolveBaseDD(disChargMOSHex)?.dataStr;
|
|
1251
|
-
const disChargEndTime = +new Date();
|
|
1252
|
-
const activeHex = await getDD5AFBAsync(deviceId, '0x05', '0x01');
|
|
1253
|
-
const activeRes = resolveBaseDD(disChargMOSHex)?.dataStr;
|
|
1254
|
-
let baseInfo = null
|
|
1255
|
-
const endTime = +new Date();
|
|
1256
|
-
await sleep(300)
|
|
1257
|
-
baseInfo = await getDDA503Async(deviceId);
|
|
1258
|
-
const voltageInfo = await getDDA504Async(deviceId);
|
|
1259
|
-
return { disChargMOSHex, disChargMOSRes, activeHex, activeRes, baseInfo, voltageInfo, startTime, disChargEndTime, endTime };
|
|
1254
|
+
// const startTime = +new Date();
|
|
1255
|
+
// const disChargMOSHex = await getDD5AFBAsync(deviceId, '0x00', '0x00');
|
|
1256
|
+
// const disChargMOSRes = resolveBaseDD(disChargMOSHex)?.dataStr;
|
|
1257
|
+
// const disChargEndTime = +new Date();
|
|
1258
|
+
// const activeHex = await getDD5AFBAsync(deviceId, '0x05', '0x01');
|
|
1259
|
+
// const activeRes = resolveBaseDD(disChargMOSHex)?.dataStr;
|
|
1260
|
+
// let baseInfo = null
|
|
1261
|
+
// const endTime = +new Date();
|
|
1262
|
+
// await sleep(300)
|
|
1263
|
+
// baseInfo = await getDDA503Async(deviceId);
|
|
1264
|
+
// const voltageInfo = await getDDA504Async(deviceId);
|
|
1265
|
+
// return { disChargMOSHex, disChargMOSRes, activeHex, activeRes, baseInfo, voltageInfo, startTime, disChargEndTime, endTime };
|
|
1266
|
+
try {
|
|
1267
|
+
const startTime = +new Date();
|
|
1268
|
+
let acStatus = false // 激活结果
|
|
1269
|
+
// 发送打开放电MOS指令
|
|
1270
|
+
const mosRes = await controlSwitch(
|
|
1271
|
+
deviceId,
|
|
1272
|
+
'0x00',
|
|
1273
|
+
true,
|
|
1274
|
+
true,
|
|
1275
|
+
);
|
|
1276
|
+
const disChargMOSRes = mosRes?.dataStr;
|
|
1277
|
+
const disChargEndTime = +new Date();
|
|
1278
|
+
// 发送激活指令
|
|
1279
|
+
const activeHex = await getDD5AFBAsync(deviceId, '0x05', '0x01');
|
|
1280
|
+
const activeResult = resolveBaseDD(activeHex);
|
|
1281
|
+
console.log('激活指令结果: ', { activeHex, activeResult });
|
|
1282
|
+
const activeRes = activeResult?.dataStr;
|
|
1283
|
+
let endTime = +new Date();
|
|
1284
|
+
let baseInfo = null
|
|
1285
|
+
let voltageInfo = null
|
|
1286
|
+
let steps = []
|
|
1287
|
+
if (activeResult?.status == '00') {
|
|
1288
|
+
steps.push(4)
|
|
1289
|
+
acStatus = true
|
|
1290
|
+
} else if (activeResult?.status == '81' || activeResult?.status == '84') {//不支持激活指令,判断开关执行结果
|
|
1291
|
+
if (mosRes?.status == '00') {
|
|
1292
|
+
acStatus = true
|
|
1293
|
+
steps.push(5)
|
|
1294
|
+
} else {
|
|
1295
|
+
acStatus = false
|
|
1296
|
+
steps.push(10)
|
|
1297
|
+
}
|
|
1298
|
+
} else if (activeResult?.status == '82' || activeResult?.status == '83') { // 激活指令执行失败
|
|
1299
|
+
acStatus = false
|
|
1300
|
+
steps.push(6)
|
|
1301
|
+
} else if (!activeResult || activeResult == null) { //激活无响应
|
|
1302
|
+
await sleep(300)
|
|
1303
|
+
const baseInfo = await getDDA503Async(deviceId);
|
|
1304
|
+
// 读取03指令后判断放电MOS是否打开,若打开则激活成功
|
|
1305
|
+
if (baseInfo?.dischargeSwitch) {
|
|
1306
|
+
acStatus = true
|
|
1307
|
+
steps.push(7)
|
|
1308
|
+
} else {
|
|
1309
|
+
acStatus = false
|
|
1310
|
+
steps.push(8)
|
|
1311
|
+
}
|
|
1312
|
+
endTime = +new Date()
|
|
1313
|
+
}
|
|
1314
|
+
return { disChargMOSRes, activeHex, activeRes, baseInfo, voltageInfo, startTime, disChargEndTime, endTime, acStatus, steps };
|
|
1315
|
+
} catch (error) {
|
|
1316
|
+
console.log("🚀 ~ BleApiManager ~ activateAsync ~ error:", error)
|
|
1317
|
+
return null
|
|
1318
|
+
}
|
|
1260
1319
|
}
|
|
1261
1320
|
|
|
1262
1321
|
// #region 获取均衡线电阻 DC 指令
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { decimalToHex,
|
|
1
|
+
import { decimalToHex, generateCrcCheckSum, hex2string, hexArr2string, hexToDecimal } from '../BleDataProcess';
|
|
2
2
|
import { getData } from './BleCmdAnalysis.js';
|
|
3
3
|
|
|
4
4
|
export const getDDA420Async = async (deviceId) => {
|
|
5
5
|
const _command = ['0x20', '0x00'];
|
|
6
|
-
const checks =
|
|
6
|
+
const checks = generateCrcCheckSum(_command);
|
|
7
7
|
const command = ['0xdd', '0xa4', ..._command, ...checks, '0x77'];
|
|
8
8
|
|
|
9
9
|
const response = 'DD03002313E10000199D27100000310F00000000000014410310060BB60BC60BC10BBA0BBD0BC1F89777';
|
|
@@ -15,7 +15,7 @@ export const getDDA420Async = async (deviceId) => {
|
|
|
15
15
|
commandVerifyHandler: (hexArr) => ({ verified: hexArr[0] == 0xdd && hexArr[1] == 0x20, pkgLen: hexArr[3] + 7 }),
|
|
16
16
|
pkgVerifyHandler: (pkg) => {
|
|
17
17
|
const len = pkg.length;
|
|
18
|
-
const [c1, c2] =
|
|
18
|
+
const [c1, c2] = generateCrcCheckSum(pkg.slice(2, len - 3));
|
|
19
19
|
const [_c1, _c2] = [pkg[len - 3], pkg[len - 2]];
|
|
20
20
|
return { verified: c1 == _c1 && c2 == _c2 };
|
|
21
21
|
},
|
|
@@ -29,7 +29,7 @@ export const getDDA420Async = async (deviceId) => {
|
|
|
29
29
|
* @param {number[]} data DDA420十六进制数据数组
|
|
30
30
|
* @returns {Object} 解析后的充电器工作信息对象
|
|
31
31
|
* @returns {string} dataStr 十六进制数据数组转换后的字符串
|
|
32
|
-
* @returns {number} workStatus 工作状态:1=待机,2=就绪,3=激活电池中,4=通讯充电中,5=调试充电中,6=盲充中,7=结束充电
|
|
32
|
+
* @returns {number} workStatus 工作状态:1=待机,2=就绪,3=激活电池中,4=通讯充电中,5=调试充电中,6=盲充中,7=结束充电 8=停止充电(异常) 9=充电比对中 10=校准中 11=老化中 12=握手充电中 13=小电流充电中
|
|
33
33
|
* @returns {number} chargeStatus 充电状态:1=恒流,2=恒压,3=涓流
|
|
34
34
|
* @returns {number} chargeVoltage 充电电压,单位毫伏(mV)
|
|
35
35
|
* @returns {number} chargeElectricity 充电电流,单位毫安(mA)
|
|
@@ -51,7 +51,7 @@ export const getDDA420Async = async (deviceId) => {
|
|
|
51
51
|
* @returns {number} ratedPower 充电器额定功率,单位瓦特(W)
|
|
52
52
|
* @returns {number} inputVoltage 输入电压,单位毫伏(mV)
|
|
53
53
|
*/
|
|
54
|
-
export const resolveDDA420 =
|
|
54
|
+
export const resolveDDA420 = (data) => {
|
|
55
55
|
if (!data) return null;
|
|
56
56
|
const dataStr = hexArr2string(data);
|
|
57
57
|
let n = 4; // 起始偏移
|
|
@@ -251,7 +251,7 @@ export const getDDA420Async = async (deviceId) => {
|
|
|
251
251
|
* @param {number[]} data DDA421十六进制数据数组
|
|
252
252
|
* @returns {Object} 解析后的充电电池信息对象
|
|
253
253
|
*/
|
|
254
|
-
export const resolveDDA421 =
|
|
254
|
+
export const resolveDDA421 = (data) => {
|
|
255
255
|
if (!data) return null;
|
|
256
256
|
const dataStr = hexArr2string(data);
|
|
257
257
|
// 电池电压 4BYTE [4,5,6,7]
|
|
@@ -335,7 +335,7 @@ export const getDDA420Async = async (deviceId) => {
|
|
|
335
335
|
'DDA425'
|
|
336
336
|
);
|
|
337
337
|
}
|
|
338
|
-
export const resolveDDA425 =
|
|
338
|
+
export const resolveDDA425 = (data) => {
|
|
339
339
|
if (!data) return null;
|
|
340
340
|
const dataStr = hexArr2string(data);
|
|
341
341
|
return {
|
|
@@ -384,7 +384,7 @@ export const getDDA420Async = async (deviceId) => {
|
|
|
384
384
|
* @param {number[]} data DDA422响应数据
|
|
385
385
|
* @returns {Object} 解析结果
|
|
386
386
|
*/
|
|
387
|
-
export const resolveDDA422 =
|
|
387
|
+
export const resolveDDA422 = (data) => {
|
|
388
388
|
if (!data) return null;
|
|
389
389
|
const dataStr = hexArr2string(data);
|
|
390
390
|
// 起始地址 2BYTE [4,5]
|
|
@@ -447,14 +447,77 @@ export const getDDA420Async = async (deviceId) => {
|
|
|
447
447
|
'DDA423'
|
|
448
448
|
);
|
|
449
449
|
}
|
|
450
|
-
export const resolveDDA423 =
|
|
450
|
+
export const resolveDDA423 = (data) => {
|
|
451
451
|
if (!data) return null;
|
|
452
452
|
const dataStr = hexArr2string(data);
|
|
453
453
|
return {
|
|
454
454
|
dataStr,
|
|
455
455
|
status: hex2string(data[2])
|
|
456
456
|
};
|
|
457
|
+
}
|
|
458
|
+
/** 充电器充电测试 26 指令
|
|
459
|
+
* 发送: DD A4 26 09 <测试模式1B> <输出电压4B mV> <输出电流4B mA> CRC_H CRC_L 77
|
|
460
|
+
* 响应: DD 26 <状态位1B> 00 CRC_H CRC_L 77 (或: DD 26 <状态位> 00 ...)
|
|
461
|
+
* @param {string} deviceId 设备ID
|
|
462
|
+
* @param {number} testMode 测试模式 1=调试模式 2=老化模式
|
|
463
|
+
* @param {number} outputVoltage 输出目标电压(mV) 0~4294967295
|
|
464
|
+
* @param {number} outputCurrent 输出目标电流(mA) 0~4294967295
|
|
465
|
+
* @returns {Promise<number[]|null>} 原始响应数据数组; 失败返回 null
|
|
466
|
+
*/
|
|
467
|
+
export const getDDA426Async = async (deviceId, testMode = 0, outputVoltage = 0, outputCurrent = 0) => {
|
|
468
|
+
// 保护参数范围(简单防御,防止生成溢出字节/异常写入)
|
|
469
|
+
const clamp32 = (v) => {
|
|
470
|
+
v = Number(v) || 0; if (v < 0) v = 0; if (v > 0xFFFFFFFF) v = 0xFFFFFFFF; return v;
|
|
471
|
+
};
|
|
472
|
+
testMode = testMode === 2 ? 2 : 0; // 只允许 0 / 2
|
|
473
|
+
outputVoltage = clamp32(outputVoltage);
|
|
474
|
+
outputCurrent = clamp32(outputCurrent);
|
|
475
|
+
|
|
476
|
+
// 转 4 字节 (大端) 十六进制 -> 数组
|
|
477
|
+
const to4Bytes = (val) => {
|
|
478
|
+
const hex = commonfun.decimalToHex(val, 8); // 8位十六进制字符串
|
|
479
|
+
return [0, 2, 4, 6].map(i => parseInt(hex.slice(i, i + 2), 16));
|
|
480
|
+
};
|
|
481
|
+
const voltageArr = to4Bytes(outputVoltage);
|
|
482
|
+
const currentArr = to4Bytes(outputCurrent);
|
|
483
|
+
|
|
484
|
+
// 长度 = 1(模式) +4(电压)+4(电流) = 9
|
|
485
|
+
const lengthHex = commonfun.decimalToHex(9, 2); // '09'
|
|
486
|
+
const _command = ['0x26', `0x${lengthHex}`, testMode & 0xFF, ...voltageArr, ...currentArr].map(o => typeof o === 'number' ? `0x${('00' + o.toString(16)).slice(-2)}` : o);
|
|
487
|
+
// 去掉 0x 前缀转成数值数组生成 CRC
|
|
488
|
+
const _commandNums = _command.map(h => parseInt(h, 16));
|
|
489
|
+
const checks = generateCrcCheckSum(_commandNums);
|
|
490
|
+
const command = ['0xDD', '0xA4', ..._command, ...checks, '0x77'];
|
|
491
|
+
|
|
492
|
+
return getData(
|
|
493
|
+
deviceId,
|
|
494
|
+
{
|
|
495
|
+
command,
|
|
496
|
+
commandVerifyHandler: (hexArr) => ({ verified: hexArr[0] == 0xdd && hexArr[1] == 0x26, pkgLen: hexArr[3] + 7 }),
|
|
497
|
+
pkgVerifyHandler: (pkg) => {
|
|
498
|
+
// const len = pkg.length;
|
|
499
|
+
// const [c1, c2] = this.generateCrcCheckSum(pkg.slice(2, len - 3));
|
|
500
|
+
// const [_c1, _c2] = [pkg[len - 3], pkg[len - 2]];
|
|
501
|
+
// return { verified: c1 == _c1 && c2 == _c2 };
|
|
502
|
+
return { verified: true }
|
|
503
|
+
},
|
|
504
|
+
},
|
|
505
|
+
'DDA426(充电测试)',
|
|
506
|
+
3000
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/** 解析充电器充电测试 26 指令响应
|
|
511
|
+
* @param {number[]} data
|
|
512
|
+
* @returns {{dataStr:string,status:string}|null}
|
|
513
|
+
*/
|
|
514
|
+
|
|
515
|
+
export const resolveDDA426 = (data) => {
|
|
516
|
+
if (!data) return null;
|
|
517
|
+
const dataStr = hexArr2string(data);
|
|
518
|
+
return { dataStr, status: hex2string(data[2]) };
|
|
457
519
|
}
|
|
520
|
+
|
|
458
521
|
/** 查询充电历史数据27指令
|
|
459
522
|
* @param {*} deviceId
|
|
460
523
|
* @param {number} startTime 充电起始时间(秒,4字节)
|
|
@@ -509,7 +572,7 @@ export const getDDA420Async = async (deviceId) => {
|
|
|
509
572
|
* @param {number[]} data DDA427响应数据
|
|
510
573
|
* @returns {Object} 解析结果
|
|
511
574
|
*/
|
|
512
|
-
export const resolveDDA427 =
|
|
575
|
+
export const resolveDDA427 = (data) => {
|
|
513
576
|
if (!data) return null;
|
|
514
577
|
const dataStr = hexArr2string(data);
|
|
515
578
|
// 充电起始时间 4BYTE [4,5,6,7]
|
|
@@ -605,7 +668,7 @@ export const getDDA420Async = async (deviceId) => {
|
|
|
605
668
|
'DDA429'
|
|
606
669
|
);
|
|
607
670
|
}
|
|
608
|
-
export const resolveDDA429 =
|
|
671
|
+
export const resolveDDA429 = (data) => {
|
|
609
672
|
if (!data) return null;
|
|
610
673
|
const dataStr = hexArr2string(data);
|
|
611
674
|
let n = 4; // 起始偏移
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
export * from './BaseParamProtocol';
|
|
1
2
|
export * from './BleCmdAnalysis';
|
|
2
|
-
export * from './BleCmdFFAA';
|
|
3
3
|
export * from './BleCmdDD';
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './BleCmdHVES'
|
|
7
|
-
export * from './ESHostProtocol'
|
|
4
|
+
export * from './BleCmdDDA4';
|
|
5
|
+
export * from './BleCmdFFAA';
|
|
6
|
+
export * from './BleCmdHVES';
|
|
7
|
+
export * from './ESHostProtocol';
|
|
8
|
+
export * from './readAndSetParam';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { decimalToHex, decimalToTwoByteHexArray } from '../BleDataProcess.js';
|
|
2
|
-
import { enterFactory, existFactory, getDDA5FAAsync, getDDA5OldAsync, readExistFactory, setDDA5FAAsync, setDDA5OldAsync } from './BleCmdDD.js';
|
|
2
|
+
import { enterFactory, existFactory, getDD5AE1Async, getDD5AFBAsync, getDDA5FAAsync, getDDA5OldAsync, readExistFactory, resolveBaseDD, setDDA5FAAsync, setDDA5OldAsync } from './BleCmdDD.js';
|
|
3
3
|
|
|
4
4
|
// #region 发指令读取参数
|
|
5
5
|
/**
|
|
@@ -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 新设置的参数值十进制值 部分参数输入的值需单独处理
|
|
@@ -102,7 +104,7 @@ export const getSysParamCmd = async (chipType, deviceId, paramInfo, needFactoryM
|
|
|
102
104
|
* @param {*} paramInfoArray[].divisor 缩放系数(十进制)如 10
|
|
103
105
|
* @param {*} paramInfoArray[].isTemp 是否是温度参数
|
|
104
106
|
*/
|
|
105
|
-
export const setSysParamCmd = async (chipType, deviceId, paramInfoArray) => {
|
|
107
|
+
export const setSysParamCmd = async (chipType, deviceId, paramInfoArray, macAddr, blueConnect = true) => {
|
|
106
108
|
try {
|
|
107
109
|
console.log('paramInfoArray: ', paramInfoArray);
|
|
108
110
|
|
|
@@ -113,13 +115,18 @@ 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
|
-
if (paramInfo.isTemp) {
|
|
121
|
+
if (paramInfo.isTemp && blueConnect) {
|
|
119
122
|
value = 2731 + (Number(paramInfo.newValue) * 10)
|
|
120
123
|
}
|
|
121
|
-
|
|
122
|
-
|
|
124
|
+
value = Math.round(value);
|
|
125
|
+
let valuesHexs = [];
|
|
126
|
+
if(blueConnect) {
|
|
127
|
+
valuesHexs = decimalToTwoByteHexArray(value);
|
|
128
|
+
console.log('valuesHexs: ', valuesHexs);
|
|
129
|
+
}
|
|
123
130
|
|
|
124
131
|
// 将处理后的参数对象添加到数组中
|
|
125
132
|
paramObjs.push({
|
|
@@ -127,11 +134,14 @@ export const setSysParamCmd = async (chipType, deviceId, paramInfoArray) => {
|
|
|
127
134
|
length: paramInfo.paramLength / 2,
|
|
128
135
|
values: valuesHexs,
|
|
129
136
|
oldAddress: paramInfo.oldParamNo,
|
|
137
|
+
newValue: value,
|
|
130
138
|
});
|
|
131
139
|
}
|
|
132
140
|
|
|
133
141
|
// 一次性将所有参数对象数组传递给setParamCmd函数
|
|
142
|
+
console.log("chipType: 芯片", chipType);
|
|
134
143
|
await setParamCmd(chipType, deviceId, paramObjs);
|
|
144
|
+
|
|
135
145
|
} catch (error) {
|
|
136
146
|
console.error('error: 写系统参数报错 setSysParamCmd', error);
|
|
137
147
|
throw error
|
|
@@ -143,6 +153,7 @@ export const setSysParamCmd = async (chipType, deviceId, paramInfoArray) => {
|
|
|
143
153
|
* 发指令设置参数
|
|
144
154
|
* @param {*} chipType 芯片类型
|
|
145
155
|
* @param {*} deviceId 设备deviceId
|
|
156
|
+
* @param {*} macAddr 设备macAddr
|
|
146
157
|
* @param {Array} paramInfoArray 参数信息数组 或单个对象
|
|
147
158
|
* @param {*} paramInfoArray[].address 新协议开始写入地址(十进制)如 31
|
|
148
159
|
* @param {*} paramInfoArray[].length 新协议写参数内容长度(写几个)(十进制)如 1
|
|
@@ -150,7 +161,7 @@ export const setSysParamCmd = async (chipType, deviceId, paramInfoArray) => {
|
|
|
150
161
|
* @param {*} paramInfoArray[].oldAddress 旧协议写入地址 默认一个(十六进制字符串)如 '0x1f'
|
|
151
162
|
* @returns {Promise<Array>} 包含所有参数设置结果的数组
|
|
152
163
|
*/
|
|
153
|
-
export const setParamCmd = (chipType, deviceId, paramInfoArray) => {
|
|
164
|
+
export const setParamCmd = async (chipType, deviceId, paramInfoArray) => {
|
|
154
165
|
console.log("chipType: 芯片", chipType);
|
|
155
166
|
|
|
156
167
|
// 确保paramInfoArray是数组
|
|
@@ -212,6 +223,84 @@ export const setParamCmd = (chipType, deviceId, paramInfoArray) => {
|
|
|
212
223
|
});
|
|
213
224
|
}
|
|
214
225
|
|
|
226
|
+
/** 控制开关
|
|
227
|
+
* @param {*} deviceId
|
|
228
|
+
* @param {*} typeCmd 0x00 - 放电MOS 0x01 - 充电MOS
|
|
229
|
+
* @param {*} currentSwitch 当前修改开关状态 true - 打开 false - 关闭
|
|
230
|
+
* @param {*} anotherSwitch 另一个开关状态
|
|
231
|
+
* @returns 指令结果 Ooj.status: 00 - 成功 81/84 不支持 82/83 失败
|
|
232
|
+
*/
|
|
233
|
+
export const controlSwitch = async (deviceId, typeCmd, currentSwitch, anotherSwitch) => {
|
|
234
|
+
//充放电开关
|
|
235
|
+
const hex = await getDD5AFBAsync(
|
|
236
|
+
deviceId,
|
|
237
|
+
typeCmd,
|
|
238
|
+
currentSwitch ? "0x00" : "0x01",
|
|
239
|
+
);
|
|
240
|
+
const mosRes = resolveBaseDD(hex);
|
|
241
|
+
console.log("hex: ", hex);
|
|
242
|
+
let dataRes = mosRes
|
|
243
|
+
//FB指令控制mos失败或无响应,发送E1指令
|
|
244
|
+
if (!mosRes || mosRes?.status != '00') {
|
|
245
|
+
const cmd = getE1Cmd(typeCmd, currentSwitch, anotherSwitch);
|
|
246
|
+
const e1hex = await getDD5AE1Async(
|
|
247
|
+
deviceId,
|
|
248
|
+
cmd
|
|
249
|
+
);
|
|
250
|
+
dataRes = resolveBaseDD(e1hex);
|
|
251
|
+
}
|
|
252
|
+
return dataRes
|
|
253
|
+
}
|
|
254
|
+
/** 计算E1指令
|
|
255
|
+
* @param {*} typeCmd 0x00 - 放电MOS 0x01 - 充电MOS
|
|
256
|
+
* @param {*} currentSwitch 当前修改开关状态 true - 打开 false - 关闭
|
|
257
|
+
* @param {*} anotherSwitch 另一个开关状态 true - 打开 false - 关闭
|
|
258
|
+
* @returns 0x00 - 充电MOS打开 放电MOS打开
|
|
259
|
+
* 0x01 - 充电MOS关闭 放电MOS打开
|
|
260
|
+
* 0x02 - 充电MOS打开 放电MOS关闭
|
|
261
|
+
* 0x03 - 充电MOS关闭 放电MOS关闭
|
|
262
|
+
*/
|
|
263
|
+
export const getE1Cmd = (typeCmd, currentSwitch, anotherSwitch) => {
|
|
264
|
+
let cmd = '0x00'
|
|
265
|
+
// 根据E1指令码定义计算:
|
|
266
|
+
// 0x00 - 充电MOS打开 放电MOS打开
|
|
267
|
+
// 0x01 - 充电MOS关闭 放电MOS打开
|
|
268
|
+
// 0x02 - 充电MOS打开 放电MOS关闭
|
|
269
|
+
// 0x03 - 充电MOS关闭 放电MOS关闭
|
|
270
|
+
if (typeCmd === '0x00') {
|
|
271
|
+
// 当前是放电操作
|
|
272
|
+
if (currentSwitch && anotherSwitch) {
|
|
273
|
+
// 放电MOS打开,充电MOS打开
|
|
274
|
+
cmd = '0x00'
|
|
275
|
+
} else if (currentSwitch && !anotherSwitch) {
|
|
276
|
+
// 放电MOS打开,充电MOS关闭
|
|
277
|
+
cmd = '0x01'
|
|
278
|
+
} else if (!currentSwitch && anotherSwitch) {
|
|
279
|
+
// 放电MOS关闭,充电MOS打开
|
|
280
|
+
cmd = '0x02'
|
|
281
|
+
} else {
|
|
282
|
+
// 放电MOS关闭,充电MOS关闭
|
|
283
|
+
cmd = '0x03'
|
|
284
|
+
}
|
|
285
|
+
} else if (typeCmd === '0x01') {
|
|
286
|
+
// 当前是充电操作
|
|
287
|
+
if (currentSwitch && anotherSwitch) {
|
|
288
|
+
// 充电MOS打开,放电MOS打开
|
|
289
|
+
cmd = '0x00'
|
|
290
|
+
} else if (!currentSwitch && anotherSwitch) {
|
|
291
|
+
// 充电MOS关闭,放电MOS打开
|
|
292
|
+
cmd = '0x01'
|
|
293
|
+
} else if (currentSwitch && !anotherSwitch) {
|
|
294
|
+
// 充电MOS打开,放电MOS关闭
|
|
295
|
+
cmd = '0x02'
|
|
296
|
+
} else {
|
|
297
|
+
// 充电MOS关闭,放电MOS关闭
|
|
298
|
+
cmd = '0x03'
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return cmd
|
|
302
|
+
}
|
|
303
|
+
|
|
215
304
|
// #region 写入标称容量
|
|
216
305
|
/**写入标称容量 同步写入满充及循环
|
|
217
306
|
* @param {*} chipType 芯片类型
|
package/src/core/OtaUpgrade.js
CHANGED
|
@@ -184,7 +184,11 @@ export class OTAUpgrade {
|
|
|
184
184
|
...opt,
|
|
185
185
|
fail: async () => {
|
|
186
186
|
await this.sleep(this.delay * 2);
|
|
187
|
-
uni.writeBLECharacteristicValue({
|
|
187
|
+
uni.writeBLECharacteristicValue({
|
|
188
|
+
...opt, fail: () => {
|
|
189
|
+
console.error('写入失败: ', pkg);
|
|
190
|
+
this.fail('写入失败');
|
|
191
|
+
} });
|
|
188
192
|
},
|
|
189
193
|
});
|
|
190
194
|
},
|
|
@@ -317,16 +321,18 @@ export class OTAUpgrade {
|
|
|
317
321
|
}
|
|
318
322
|
}
|
|
319
323
|
|
|
320
|
-
transferFirmwareFile() {
|
|
324
|
+
async transferFirmwareFile() {
|
|
321
325
|
let nextTime = this.finishedTimes + 1;
|
|
322
326
|
const timeFor51 = nextTime > this.totalTimes;
|
|
323
327
|
if (timeFor51) {
|
|
324
328
|
const pkg = [0x00];
|
|
329
|
+
await BLE.sendDelay(20);
|
|
325
330
|
BLE.transferFirmwareFileCmd(this.deviceId, pkg, true, this.fail.bind(this));
|
|
326
331
|
console.log('[OTA]', '=== Send 51 ===', this.finishedTimes, this.totalTimes, pkg);
|
|
327
332
|
} else {
|
|
328
333
|
const pkg = this.fileHexArray.slice(this.finishedTimes * max, nextTime * max);
|
|
329
334
|
const index = Transfer.decimalToTwoByteHexArray(this.finishedTimes);
|
|
335
|
+
await BLE.sendDelay(20);
|
|
330
336
|
BLE.transferFirmwareFileCmd(this.deviceId, index.concat(pkg), false, this.fail.bind(this));
|
|
331
337
|
console.log('[OTA]', `S50-${this.finishedTimes}/${this.totalTimes}`);
|
|
332
338
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
class Queue {
|
|
2
|
+
constructor() {
|
|
3
|
+
this._items = [];
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
enqueue(item) {
|
|
7
|
+
this._items.push(item);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
dequeue() {
|
|
11
|
+
return this._items.shift();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
head() {
|
|
15
|
+
return this._items[0];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
tail() {
|
|
19
|
+
return this._items[this._items.length - 1];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
isEmpty() {
|
|
23
|
+
return !this._items.length;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
size() {
|
|
27
|
+
return this._items.length;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
clear() {
|
|
31
|
+
this._items = [];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export default Queue
|