tools.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * @Description:
  3. * @Version: 2.0
  4. * @Author: Seven
  5. * @Date: 2022-03-22 10:09:08
  6. * @LastEditors: Seven
  7. * @LastEditTime: 2022-12-03 16:11:03
  8. */
  9. #ifndef __TOOLS_H__
  10. #define __TOOLS_H__
  11. #include "stm32f10x.h"
  12. extern volatile uint32_t TickCounter;
  13. //printf打印
  14. #define INIT_DEBUG 1 //初始化打印
  15. #define MSG_DISPLAY_DOWN_TYPE1 1 //显示屏命令打印sn和消息类型
  16. #define MSG_DISPLAY_DOWN_TYPE2 0 //显示屏和报税口打印设备类型和加密状态
  17. #define MSG_DISPLAY_DOWN_TYPE3 1 //显示屏命令打印串口号、报税口号、枪号
  18. #define MSG_DISPLAY_DOWN_TYPE4 1 //
  19. #define MSG_DISPLAY_DOWN_TYPE5 1 //
  20. #define MSG_HEARTBEAT_DOWN_TYPE1 1 //心跳包命令打印sn和消息类型
  21. #define MSG_HEARTBEAT_DOWN_TYPE2 1 //
  22. #define MSG_HEARTBEAT_DOWN_TYPE3 1 //
  23. #define MSG_HEARTBEAT_DOWN_TYPE4 1 //
  24. #define MSG_HEARTBEAT_DOWN_TYPE5 1 //
  25. #define MSG_TAX_DOWN_TYPE1 1 //报税口命令打印sn和消息类型
  26. #define MSG_TAX_DOWN_TYPE2 1 //
  27. #define MSG_TAX_DOWN_TYPE3 1 //报税口打印串口号、报税口号、枪号
  28. #define MSG_TAX_DOWN_TYPE4 1 //
  29. #define MSG_TAX_DOWN_TYPE5 1 //
  30. #define MSG_HART_DOWN_TYPE1 1 //固件信息打印sn和消息类型
  31. #define MSG_HART_DOWN_TYPE2 1 //固件信息打印运行时长
  32. #define MSG_HART_DOWN_TYPE3 1 //
  33. #define MSG_HART_DOWN_TYPE4 1 //
  34. #define MSG_HART_DOWN_TYPE5 1 //
  35. #define MSG_REBOOT_DOWN_TYPE1 1 //重启指令打印sn和消息类型
  36. #define MSG_REBOOT_DOWN_TYPE2 1 //
  37. #define MSG_REBOOT_DOWN_TYPE3 1 //
  38. #define MSG_REBOOT_DOWN_TYPE4 1 //
  39. #define MSG_REBOOT_DOWN_TYPE5 1 //
  40. #define MSG_TIMESYNC_DOWN_TYPE1 1 //时间同步指令打印sn和消息类型
  41. #define MSG_TIMESYNC_DOWN_TYPE2 1 //
  42. #define MSG_TIMESYNC_DOWN_TYPE3 1 //
  43. #define MSG_TIMESYNC_DOWN_TYPE4 1 //
  44. #define MSG_TIMESYNC_DOWN_TYPE5 1 //
  45. #define MSG_LORA_DOWN_TYPE1 1 //lora配置信道指令打印sn和消息类型
  46. #define MSG_LORA_DOWN_TYPE2 1 //打印Lora配置的信道索引号
  47. #define MSG_LORA_DOWN_TYPE3 1 //
  48. #define MSG_LORA_DOWN_TYPE4 1 //
  49. #define MSG_LORA_DOWN_TYPE5 1 //
  50. #define MSG_ENCODER_DOWN_TYPE1 1 //编码器指令打印sn和消息类型
  51. #define MSG_ENCODER_DOWN_TYPE2 1 //编码器指令打印报税口号和枪号和指令
  52. #define MSG_ENCODER_DOWN_TYPE3 1 //编码器指令打印读取的组号和新纪录标识
  53. #define MSG_ENCODER_DOWN_TYPE4 1 //编码器打印指令的设备类型
  54. #define MSG_ENCODER_DOWN_TYPE5 1 //
  55. #define MSG_REBOOT_TYPE_DOWN_TYPE1 1 //根据设备类型复位
  56. #define UART_RCV_DEBUG 1 //串口接收打印
  57. #define UART_SEND_DEBUG 1 //
  58. #define LORA_RCV_DEBUG 0 //lora接收打印snr和rssi
  59. #define LORA_SEND_DEBUG 1 //
  60. #define LORA_TASK_DEBUG 1 //
  61. #define ENCODER_INIT_DEBUG 1 //编码器初始化打印
  62. #define ENCODER_GUN_DEBUG 1 //编码器抬枪信号中断打印
  63. #define ENCODER_NEW_DEBUG 1 //编码器产生新数据打印
  64. #define ENCODER_EEPROM_DEBUG 0 //编码器写eeprom打印
  65. ///////////////////////////////////
  66. //十六进制打印(data_dump)
  67. #define MSG_DISPLAY_DATA_TYPE1 1 //显示屏发送数据
  68. #define MSG_DISPLAY_DATA_TYPE2 0 //显示屏命令正常返回数据
  69. #define MSG_DISPLAY_DATA_TYPE3 1 //显示屏命令执行错误返回数据
  70. #define MSG_DISPLAY_DATA_TYPE4 1 //
  71. #define MSG_DISPLAY_DATA_TYPE5 1 //
  72. #define MSG_HEARTBEAT_DATA_TYPE1 0 //心跳包返回数据
  73. #define MSG_HEARTBEAT_DATA_TYPE2 1 //
  74. #define MSG_HEARTBEAT_DATA_TYPE3 1 //
  75. #define MSG_HEARTBEAT_DATA_TYPE4 1 //
  76. #define MSG_HEARTBEAT_DATA_TYPE5 1 //
  77. #define MSG_TAX_DATA_TYPE1 1 //报税口发送数据
  78. #define MSG_TAX_DATA_TYPE2 0 //报税口正常返回数据
  79. #define MSG_TAX_DATA_TYPE3 1 //报税口执行错误返回数据
  80. #define MSG_TAX_DATA_TYPE4 1 //
  81. #define MSG_TAX_DATA_TYPE5 1 //
  82. #define MSG_HART_DATA_TYPE1 0 //固件信息返回数据
  83. #define MSG_HART_DATA_TYPE2 1 //
  84. #define MSG_HART_DATA_TYPE3 1 //
  85. #define MSG_HART_DATA_TYPE4 1 //
  86. #define MSG_HART_DATA_TYPE5 1 //
  87. #define MSG_REBOOT_DATA_TYPE1 1 //
  88. #define MSG_REBOOT_DATA_TYPE2 1 //
  89. #define MSG_REBOOT_DATA_TYPE3 1 //
  90. #define MSG_REBOOT_DATA_TYPE4 1 //
  91. #define MSG_REBOOT_DATA_TYPE5 1 //
  92. #define MSG_TIMESYNC_DATA_TYPE1 1 //
  93. #define MSG_TIMESYNC_DATA_TYPE2 1 //
  94. #define MSG_TIMESYNC_DATA_TYPE3 1 //
  95. #define MSG_TIMESYNC_DATA_TYPE4 1 //
  96. #define MSG_TIMESYNC_DATA_TYPE5 1 //
  97. #define MSG_LORA_DATA_TYPE1 1 //
  98. #define MSG_LORA_DATA_TYPE2 1 //
  99. #define MSG_LORA_DATA_TYPE3 1 //
  100. #define MSG_LORA_DATA_TYPE4 1 //
  101. #define MSG_LORA_DATA_TYPE5 1 //
  102. #define MSG_ENCODER_DATA_TYPE1 1 //编码器返回数据
  103. #define MSG_ENCODER_DATA_TYPE2 1 //编码器返回执行错误数据
  104. #define MSG_ENCODER_DATA_TYPE3 1 //
  105. #define MSG_ENCODER_DATA_TYPE4 1 //
  106. #define MSG_ENCODER_DATA_TYPE5 1 //
  107. #define MSG_ERR_DATA_TYPE1 1 //业务查询执行错误数据返回
  108. #define UART_RCV_DATA_DEBUG 1 //串口接收数据
  109. #define UART_SEND_DATA_DEBUG 1 //
  110. #define LORA_RCV_DATA_DEBUG 0 //Lora接收数据
  111. #define LORA_SEND_DATA_DEBUG 0 //Lora发送数据
  112. #define LORA_TASK_DATA_DEBUG 1 //
  113. #define LORA_BUSINESS_DEBUG 1 //业务数据返回
  114. #define ENCODER_INIT_DATA_DEBUG 0 //编码器初始化数据
  115. #define ENCODER_NEW_DATA_DEBUG 1 //
  116. #define ENCODER_EEPROM_DATA_DEBUG 0 //编码器写eeprom数据
  117. #ifndef INIT_DEBUG
  118. #define INIT_DEBUG 0
  119. #endif
  120. typedef struct timeout_
  121. {
  122. uint8_t flag;
  123. uint32_t count;
  124. uint32_t timeout;
  125. }__attribute__((packed)) timeout_t;
  126. void GetCodeVerify(uint32_t _start,uint32_t _len,uint32_t * _verify);
  127. void GetCodeVerify_t(uint32_t _start,uint32_t _len,uint32_t * _verify);
  128. uint16_t CRC16_get(uint8_t *_buff,uint32_t _len);
  129. uint16_t CRC16_get_flash(uint32_t addr, uint32_t len);
  130. int _ytsf_data_code(uint8_t *buff, uint8_t *len);
  131. int _ytsf_data_decode(uint8_t *buff, uint8_t *len);
  132. long HextoDec(char *s);
  133. unsigned char HexToChar(unsigned char bChar);
  134. int asciitohex(char *data, uint8_t *out_data, int len);
  135. int decimal_bcd_code(int decimal);
  136. void timeout_setValue(timeout_t *tt,uint32_t val,uint8_t flg);
  137. void timeout_start(timeout_t *tt,uint8_t flg);
  138. void timeout_stop(timeout_t *tt);
  139. uint8_t timeout_isOut(timeout_t *tt);
  140. void timeout_setValue_us(timeout_t *tt,uint32_t val,uint8_t flg);
  141. void timeout_start_us(timeout_t *tt,uint8_t flg);
  142. void timeout_stop_us(timeout_t *tt);
  143. uint8_t timeout_isOut_us(timeout_t *tt);
  144. uint8_t uart_baud_judge(uint32_t baud);
  145. uint8_t buf_is_zero(uint8_t *buf, uint16_t size);
  146. uint8_t buff_compare(uint8_t *buf1, uint8_t *buf2, uint16_t len);
  147. uint8_t get_xor(uint8_t *buf, uint16_t len);
  148. uint8_t _crc_get_gw(uint8_t *data, uint8_t size);
  149. uint32_t strtohex(char *data, uint8_t len);
  150. void printf_debug(uint8_t cmd1, const char *fmt, ...);
  151. void data_dump_debug(uint8_t cmd1, const char *name, uint8_t *data, uint16_t len);
  152. #endif