app_protocol.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #ifndef __APP_PROTOCOL__
  2. #define __APP_PROTOCOL__
  3. #include "stdbool.h"
  4. #include "hc32_ll_fcg.h"
  5. #include "string.h"
  6. #define APP_A_ADDR (0x8000)
  7. #define APP_B_ADDR (0x22000)
  8. #define BOOT_INFO_ADDR (0x3c000)
  9. #define DATA_LENTH (512)
  10. #define FRAME_HEAD (0X5A)
  11. #define DATA_HEAD (0X5A)
  12. #define FRAME_TAIL (0XA5)
  13. #define MPU_ADDR (0X10)
  14. #define MCU_ADDR (0X20)
  15. #define MASTER_CMD (0X50)
  16. #define SLAVE_CMD_ACK (0X5C)
  17. #define SLAVE_CMD_NACK (0X5F)
  18. #define MASTER_CTR (0X60)
  19. #define SLAVE_CTR_ACK (0X6C)
  20. #define SLAVE_CTR_NACK (0X6F)
  21. /* PWM控制路数 PWM_NUM * 3 */
  22. #define PWM_NUM_CONFIG (2)
  23. /*
  24. *帧协议控制
  25. */
  26. #define FRAME_MAX_LENGTH (256)
  27. #define SPI_BUF_LEN (FRAME_MAX_LENGTH + FRAME_MAX_LENGTH)
  28. typedef struct
  29. {
  30. uint16_t default_init;
  31. uint16_t is_ota_flag;
  32. uint16_t is_can_write_flag;
  33. uint32_t destination_address;
  34. }sys_paratemer_info_t;
  35. #pragma pack(1)
  36. /* 固定开头帧 */
  37. typedef struct
  38. {
  39. uint8_t frame_head;
  40. uint16_t data_lenth;
  41. uint8_t source_addr;
  42. uint8_t destination_addr;
  43. uint8_t cmd;
  44. uint8_t cmd_type;
  45. }frame_pack_t;
  46. /* 固定帧各字节顺序*/
  47. enum
  48. {
  49. FRAME_HEAD_INDEX = 0,
  50. FRAME_LEN_INDEX,
  51. FRAME_SOUADDR_INDEX = 3,
  52. FRAME_DETADDR_INDEX,
  53. FRAME_CMD_INDEX,
  54. FRAME_CMD_TYPE_INDEX,
  55. };
  56. /* SLAVE_CMD_ACK 0X50 */
  57. #define TEMP_NUMBER 15
  58. /***********-- --- --0X01 查询-- --- --***********/
  59. /*设备状态*/
  60. typedef struct
  61. {
  62. uint8_t work_status;
  63. uint8_t temperatures_number;
  64. int8_t temperatures_data[TEMP_NUMBER];
  65. uint8_t backup_voltage;
  66. uint8_t backup_temperature;
  67. uint8_t high_driver_number;
  68. uint8_t high_driver_status;//最大8路 bit
  69. uint8_t low_driver_number;
  70. uint8_t low_driver_status; //最大8路 bit
  71. uint8_t last_wake_up_source;
  72. uint8_t location_status;
  73. }cmd_05_01_device_status_t;
  74. /***********-- --- --0X03 查询-- --- --***********/
  75. /*通讯数据*/
  76. typedef struct
  77. {
  78. uint16_t x_data;
  79. uint16_t y_data;
  80. uint16_t z_data;
  81. uint8_t can0_data_status;
  82. uint8_t can0_fault_status;
  83. uint16_t can0_data_lenth;
  84. uint8_t can0_data[16];
  85. uint8_t can1_data_status;
  86. uint8_t can1_fault_status;
  87. uint16_t can1_data_lenth;
  88. uint8_t can1_data[16];
  89. uint8_t rs485_data_status;
  90. uint16_t rs485_data_lenth;
  91. uint8_t rs485_data[128];
  92. }communication_data_t;
  93. /*数据包基础结构*/
  94. typedef struct
  95. {
  96. uint8_t frame_head;
  97. uint8_t source_addr;
  98. uint8_t destination_addr;
  99. uint8_t data_head;
  100. uint8_t cmd;
  101. uint8_t cmd_type;
  102. uint16_t data_lenth;
  103. int8_t *data;
  104. uint16_t crc;
  105. uint8_t frame_tail;
  106. }pack_t;
  107. /*定位信息*/
  108. typedef struct
  109. {
  110. uint8_t locate_mark; //֨定位标志
  111. uint8_t satellite_num;//卫星数量
  112. uint8_t direction[2]; //方位
  113. uint8_t speed[2]; //̙速度
  114. uint8_t altitude[2]; //海拔
  115. uint8_t latitude[4]; //纬度
  116. uint8_t longitude[4]; //经度
  117. uint8_t accmileage[4];//
  118. } gps_info_t;
  119. /***********控制****************/
  120. /*输出控制*/
  121. typedef struct
  122. {
  123. uint8_t output_number;//最大8路
  124. uint8_t output_control;//bit
  125. uint16_t pwm_number;
  126. uint8_t pwm_data[PWM_NUM_CONFIG][3];//PWM_NUM_CONFIG路PWM 频率2bytes,占空比1byte
  127. }output_control_t;
  128. /*休眠控制*/
  129. typedef struct
  130. {
  131. uint8_t control_type;
  132. uint16_t sleep_time; //s
  133. }sleep_control_t;
  134. /*FLASH控制*/
  135. typedef struct
  136. {
  137. uint8_t data_type;
  138. uint16_t write_data_index;
  139. }flash_write_t;
  140. /*通讯控制*/
  141. typedef struct
  142. {
  143. uint8_t can_send_data_type;
  144. uint32_t can_send_data_lenth;
  145. uint8_t can_send_data[13];
  146. uint8_t rs485_send_data_type;
  147. uint32_t rs485_send_data_lenth;
  148. uint8_t rs485_send_data[512];
  149. }communication_control_t;
  150. void mcu_to_mpu_task(void *arg);
  151. #pragma pack()
  152. //inline unsigned short crc16_modbus(unsigned char *pdata, int len);
  153. #endif