12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- const common = require('../../common.js');
- function bmsParameterTypeSetValue(device) {
- var cmd = '';
- switch (device.name) {
- case '0xAF': //电池类型
- case '0x9D': //主动均衡控制开关
- case '0xB8':
- //是否启动电流校准
- var value = device.name.slice(2) + common.dec2hex(device.value, 2);
- cmd = setBMSParams(value);
- break;
- case '0xBC':
- //恢复出厂设置
- var value = device.name.slice(2) + common.dec2hex(1, 2);
- cmd = setBMSParams(value);
- break;
- case '0xAA': //电池标称容量
- case '0xB9':
- //电池实际容量
- var value = device.name.slice(2) + common.dec2hex(device.value, 8);
- cmd = setBMSParams(value);
- break;
- case '0xB0': //休眠等待时间
- case '0x92': //单体过压保护延时
- case '0x95': //单体欠压保护延时
- case '0x99': //充电过流保护
- case '0x97': //放电过流保护
- case '0xA3': //充电高温保护
- case '0xA6': //充电低温保护恢复值
- case '0xA4': //放电高温保护
- case '0xA2': //温差保护
- case '0x9E': //功率管温度保护
- case '0x9F': //功率管温度保护恢复值
- case '0xA0': //电池箱内温度保护
- case '0xA1': //电池箱内温度保护恢复值
- case '0xAD':
- //电流校准
- var value = device.name.slice(2) + common.dec2hex(device.value, 4);
- cmd = setBMSParams(value);
- break;
- case '0x90': //单体过压保护
- case '0x91': //单体过压恢复电压
- case '0x93': //单体欠压保护
- case '0x94': //单体欠压恢复电压
- case '0x96': //压差保护
- case '0x9B': //均衡开启电压
- case '0x9C':
- //均衡开启压差
- var value = device.name.slice(2) + common.dec2hex((device.value - 0) * 1000, 4);
- cmd = setBMSParams(value);
- break;
- case '0x8E': //总压过压保护
- case '0x8F':
- //总压欠压保护
- var value = device.name.slice(2) + common.dec2hex((device.value - 0) * 100, 4);
- cmd = setBMSParams(value);
- break;
- case '0xA5': //充电低温保护
- case '0xA7': //放电低温保护
- case '0xA8':
- //放电低温保护恢复值
- var value = device.name.slice(2) + common.neInt2hex(device.value, 4);
- cmd = setBMSParams(value);
- break;
- case '0xCE':
- //应急启动
- var value = device.name.slice(2) + common.dec2hex(1, 2);
- cmd = setBMSParams(value);
- break;
- default:
- cmd = '';
- }
- // console.log(cmd);
- return cmd;
- }
- function setBMSParams(value) {
- var header = '4E57';
- // var midType = "00000000020100"
- var midType = '00000000020300';
- var end = '0000000068';
- //内容部分
- const cmdLength = (midType + value + end).length / 2 + 6;
- var cmdLenHex = common.dec2hex(cmdLength, 4); //长度
- var cmdList = common.hexToList(header + cmdLenHex + midType + value + end);
- //校检
- var CRCHex = common.arrayToIntHex(cmdList); //CRC校检位
- //下发整体内容
- var cmdHex = header + cmdLenHex + midType + value + end + CRCHex;
- return cmdHex;
- }
- module.exports = {
- setBMSParams: setBMSParams,
- bmsParameterTypeSetValue: bmsParameterTypeSetValue
- };
|