modbus.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef __MODBUS_H
  2. #define __MODBUS_H
  3. // #include "bms_config.h"
  4. #include "fly_param.h"
  5. // #include "bmu_param.h"
  6. #include "includes.h"
  7. #include "iwdg.h"
  8. #include "uart1.h"
  9. #include "uart3.h"
  10. typedef unsigned char MODBUS_INT8U;
  11. typedef signed char MODBUS_INT8S;
  12. typedef unsigned short MODBUS_INT16U;
  13. typedef signed short MODBUS_INT16S;
  14. typedef unsigned int MODBUS_INT32U;
  15. typedef signed int MODBUS_INT32S;
  16. typedef void (*txfun_p)(const INT8U *buf, INT16U len);
  17. #define MODBUS_GAIN(VALUE1, VALUE2) ((MODBUS_INT32U)(VALUE1) * (VALUE2))
  18. #define MODBUS_SUBTRACT(VALUE1, VALUE2) ((MODBUS_INT32U)(VALUE1) - (VALUE2))
  19. #define MODBUS_DIVISION(DIVISOR, DIVIDEND) (((MODBUS_INT32U)(DIVISOR) + (DIVIDEND) / 2) / (DIVIDEND))
  20. #define MODBUS_ABS(VALUE1) (((VALUE1) < 0) ? (-(VALUE1)) : (VALUE1))
  21. #define BUF_LEN_128 128
  22. #define BUF_LEN_256 256
  23. #define BUF_LEN_512 512
  24. #define RACK_NUM 1u
  25. #define BUF_LEN_768 768
  26. #define GROUP_NUMBER_MAX 15
  27. #define VOL_TMP_PAGE_NUM 32
  28. #define BUF_LEN_256 256
  29. #define BUF_LEN_512 512
  30. #define RACK_NUM 1u
  31. #define BUF_LEN_768 768
  32. #define GROUP_NUMBER_MAX 15
  33. #define VOL_TMP_PAGE_NUM 32
  34. #define FUNC_03 3
  35. #define FUNC_05 5
  36. #define FUNC_06 6
  37. #define FUNC_10 16
  38. // samkoon COM def
  39. #define COUNT_INDEX_H 4
  40. #define COUNT_INDEX_L 5
  41. #define REGISTER_ADDR_H 2
  42. #define REGISTER_ADDR_L 3
  43. #define FUNCTION_CODE_INDEX 1
  44. // samkoon address def
  45. #define MODBUS_ADDR_SOC 0x4101 // 电池簇SOC寄存器地址
  46. #define MODBUS_ADDR_CELL 0x4301 // 单体电压寄存器地址
  47. #define MODBUS_ADDR_TEMP 0x55c1 // 单体温度寄存器地址
  48. #define MODBUS_ADDR_READ_KA 0x1001 // 继电器状态读地址
  49. #define MODBUS_ADDR_RACK_REMOTE 0xC9 //
  50. #define MODBUS_RACK_END 0x4120 // 电池簇SOC寄存器地址
  51. #define MODBUS_CELL_END 0x4490
  52. #define MODBUS_TEMP_END 0x5750
  53. #define MODBUS_KA_END 0x1009
  54. #define MODBUS_ADDR_RACK_REMOTE_END 0xE7
  55. void modbus_master_task(void);
  56. void modbus_slave_task(void);
  57. #endif