FMBMS.js 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. const common = require('../../common.js');
  2. function bmsParameterTypeSetValue(device) {
  3. var cmd = '';
  4. switch (device.name) {
  5. case '0xAF': //电池类型
  6. case '0x9D': //主动均衡控制开关
  7. case '0xB8':
  8. //是否启动电流校准
  9. var value = device.name.slice(2) + common.dec2hex(device.value, 2);
  10. cmd = setBMSParams(value);
  11. break;
  12. case '0xBC':
  13. //恢复出厂设置
  14. var value = device.name.slice(2) + common.dec2hex(1, 2);
  15. cmd = setBMSParams(value);
  16. break;
  17. case '0xAA': //电池标称容量
  18. case '0xB9':
  19. //电池实际容量
  20. var value = device.name.slice(2) + common.dec2hex(device.value, 8);
  21. cmd = setBMSParams(value);
  22. break;
  23. case '0xB0': //休眠等待时间
  24. case '0x92': //单体过压保护延时
  25. case '0x95': //单体欠压保护延时
  26. case '0x99': //充电过流保护
  27. case '0x97': //放电过流保护
  28. case '0xA3': //充电高温保护
  29. case '0xA6': //充电低温保护恢复值
  30. case '0xA4': //放电高温保护
  31. case '0xA2': //温差保护
  32. case '0x9E': //功率管温度保护
  33. case '0x9F': //功率管温度保护恢复值
  34. case '0xA0': //电池箱内温度保护
  35. case '0xA1': //电池箱内温度保护恢复值
  36. case '0xAD':
  37. //电流校准
  38. var value = device.name.slice(2) + common.dec2hex(device.value, 4);
  39. cmd = setBMSParams(value);
  40. break;
  41. case '0x90': //单体过压保护
  42. case '0x91': //单体过压恢复电压
  43. case '0x93': //单体欠压保护
  44. case '0x94': //单体欠压恢复电压
  45. case '0x96': //压差保护
  46. case '0x9B': //均衡开启电压
  47. case '0x9C':
  48. //均衡开启压差
  49. var value = device.name.slice(2) + common.dec2hex((device.value - 0) * 1000, 4);
  50. cmd = setBMSParams(value);
  51. break;
  52. case '0x8E': //总压过压保护
  53. case '0x8F':
  54. //总压欠压保护
  55. var value = device.name.slice(2) + common.dec2hex((device.value - 0) * 100, 4);
  56. cmd = setBMSParams(value);
  57. break;
  58. case '0xA5': //充电低温保护
  59. case '0xA7': //放电低温保护
  60. case '0xA8':
  61. //放电低温保护恢复值
  62. var value = device.name.slice(2) + common.neInt2hex(device.value, 4);
  63. cmd = setBMSParams(value);
  64. break;
  65. case '0xCE':
  66. //应急启动
  67. var value = device.name.slice(2) + common.dec2hex(1, 2);
  68. cmd = setBMSParams(value);
  69. break;
  70. default:
  71. cmd = '';
  72. }
  73. // console.log(cmd);
  74. return cmd;
  75. }
  76. function setBMSParams(value) {
  77. var header = '4E57';
  78. // var midType = "00000000020100"
  79. var midType = '00000000020300';
  80. var end = '0000000068';
  81. //内容部分
  82. const cmdLength = (midType + value + end).length / 2 + 6;
  83. var cmdLenHex = common.dec2hex(cmdLength, 4); //长度
  84. var cmdList = common.hexToList(header + cmdLenHex + midType + value + end);
  85. //校检
  86. var CRCHex = common.arrayToIntHex(cmdList); //CRC校检位
  87. //下发整体内容
  88. var cmdHex = header + cmdLenHex + midType + value + end + CRCHex;
  89. return cmdHex;
  90. }
  91. module.exports = {
  92. setBMSParams: setBMSParams,
  93. bmsParameterTypeSetValue: bmsParameterTypeSetValue
  94. };