app_protocol.h 3.6 KB

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