yc_protocol.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. #ifndef _YC_PROTOCOL_H_
  2. #define _YC_PROTOCOL_H_
  3. #include <stdio.h>
  4. #include <stdint.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <stdbool.h>
  8. #include "user_config.h"
  9. #include "LORA.h"
  10. #include "SPIFFS.h"
  11. #include "GUI_Paint.h"
  12. #include "../components/USER_SPIFFS/include/SPIFFS.h"
  13. extern LORA_DATA_T lora_data;
  14. //睡眠时间
  15. #define SLEEP_TIMES 3000 //3s
  16. //工作时间
  17. #define WORK_TIMES 100 //100ms
  18. typedef unsigned char u8;
  19. #define DEVOP_TEST 0
  20. #define VERSION_X 3
  21. #define VERSION_Y 2
  22. #define VERSION_Z 1
  23. // //------right char 3---------
  24. // extern uint32_t num_goodProducts[8];
  25. // extern uint32_t num_badProducts[8];
  26. // extern uint8_t scale_UR_int[8];
  27. // extern uint8_t scale_UR_dec[8];
  28. // extern uint8_t scale_YR_int[8];
  29. // extern uint8_t scale_YR_dec[8];
  30. // extern uint16_t num_manHour[8];
  31. // extern uint16_t num_people[8];
  32. // extern uint16_t num_production[8];
  33. // extern uint16_t num_repair[8];
  34. // extern uint16_t num_inspection[8];
  35. // extern uint16_t num_upkeep[8];
  36. // //-----------------------------
  37. typedef enum
  38. {
  39. KEY_CURRENT_STATUS_CMD = 0,
  40. KEY_NEW_STATUS_CMD = 1,
  41. };
  42. typedef enum
  43. {
  44. PROTOCOL_NONE = 0x00,
  45. PROTOCOL_TIME_SYNCHRONIZATION = 0x01,
  46. PROTOCOL_TERMINAL_NAME = 0x02,
  47. PROTOCOL_TERMINAL_NUMBER = 0x03,
  48. PROTOCOL_ELECTRIC_QUANTITY = 0x04,
  49. PROTOCOL_SIGNAL_STRENGTH = 0x05,
  50. PROTOCOL_SCREEN_REFRESH_CYCLE = 0x06,
  51. PROTOCOL_SCREEN_LEFT = 0x07,
  52. PROTOCOL_SCREEN_RIGHT = 0x08,
  53. PROTOCOL_RSPONSIBLE_PERSON_CHANGE = 0x09,
  54. PROTOCOL_RSPONSIBLE_PERSON_DELETE = 0x0A,
  55. PROTOCOL_PERSONNEL_CHECK_IN = 0x0C,
  56. PROTOCOL_PRODUCTION_PUNCH_CARD = 0x0B,
  57. PROTOCOL_STATUS_SETTING = 0x0D,
  58. PROTOCOL_STATUS_DURATION = 0x0E,
  59. PROTOCOL_UPDATE_AND_DURATION = 0x0F,
  60. PROTOCOL_ANNOUNCEMENT = 0x10,
  61. PROTOCOL_CAPACITY_STATISTICS = 0x11,
  62. PROTOCOL_RESPONSIBLE_PERSON_SYNCHRONIZE_INFO = 0x12,
  63. PROTOCOL_STATUS_LED = 0x13,
  64. PROTOCOL_LOG_LED =0x14,
  65. PROTOCOL_BATTERY_TEMPERATURE = 0x15,
  66. PROTOCOL_STATION_NAME = 0X16,
  67. PROTOCOL_STATION_NUMBER = 0X17,
  68. PROTOCOL_RESPONSIBLE_PERSON_SETUP= 0X18,
  69. PROTOCOL_SYSTEM_BULLETIN = 0X19,
  70. PROTOCOL_HARDWARE_UPDATE = 0x27,
  71. PROTOCOL_HARDWARE_GWPAIRED = 0x80, //硬件配网
  72. PROTOCOL_HARDWARE_UNGWPAIRED = 0x81, //硬件取消配网
  73. PROTOCOL_RSPONSIBLE_ACK = 0x99, //ACK
  74. PROTOCOL_END,
  75. }COMMUNICATION_PROTOCOL_T;
  76. typedef struct {
  77. uint8_t time_synchronization[8];
  78. uint8_t terminal_name[32];//unicode
  79. uint8_t terminal_number[16];
  80. uint8_t station_name[32];
  81. uint8_t station_number[16];
  82. uint8_t batt_percent;
  83. uint8_t rssi;
  84. uint8_t refresh_cycle;
  85. uint8_t left_epd;
  86. uint8_t right_epd;
  87. uint8_t rsponsible_person_change[32];
  88. uint8_t rsponsible_person_delete[32];
  89. uint8_t production_punch[16];
  90. uint8_t personnel_check_in[32];
  91. uint8_t status_setting[10];//别名最多2个汉字
  92. uint8_t status_duration[32];
  93. uint8_t update_and_duration[32];
  94. uint8_t announcement[120];
  95. uint8_t systemMessage[120];
  96. uint8_t capacity_statistics[200];
  97. uint8_t responsible_person_synchronize_info[32];
  98. uint8_t states_led;
  99. uint8_t logo_led;
  100. uint8_t batt_temperature[2];
  101. }TERMINAL_INFO_T;
  102. typedef enum
  103. {
  104. CHARGE_administrator =0, //
  105. CHARGE_product = 1, //生产责任人
  106. CHARGE_repair = 2, //维修责任人
  107. CHARGE_maintenance = 3, //保养责任人
  108. CHARGE_check = 4, //巡检责任人
  109. CHARGE_END,
  110. }PERSON_CHARGE_TYPE_T;
  111. #if 0
  112. typedef struct
  113. {
  114. PERSON_CHARGE_TYPE_T person_type; //人员类型
  115. uint8_t person_serial_number;
  116. uint32_t person_total;
  117. uint8_t person_name[20];
  118. }Person_t;
  119. #endif
  120. typedef enum
  121. {
  122. checkIn_product = 0, //生产
  123. checkIn_repair = 1, //维修
  124. checkIn_maintenance = 2, //保养
  125. checkIn_check = 3, //巡检
  126. }PERSON_CHECK_IN_TYPE_T;
  127. typedef struct
  128. {
  129. PERSON_CHARGE_TYPE_T person_type; //人员类型
  130. uint8_t person_serial_number[17];
  131. PAINT_TIME cur_time;
  132. }CHECK_IN_T;
  133. #if 1
  134. // #define PERSON_MAX_NAME 5
  135. // #define PERSON_NAME_MAX_LEN 20
  136. // typedef enum
  137. // {
  138. // Administrator = 0, //管理员
  139. // product_person = 1, //生产责任人
  140. // repair_person = 2, //维修责任人
  141. // Maintenance_person = 3, //保养责任人
  142. // check_person = 4, //巡检责任人
  143. // }Person_type_t;
  144. // typedef struct
  145. // {
  146. // uint16_t person_num; //序号
  147. // uint8_t person_name[PERSON_NAME_MAX_LEN]; //人员名称
  148. // }Person_Name_t;
  149. // ///////////////////////////////////////////
  150. // typedef struct
  151. // {
  152. // uint8_t person_type; //人员类型
  153. // Person_Name_t person_name[PERSON_MAX_NAME];
  154. // char string_name[100];
  155. // }Person_t;
  156. // // extern Person_t;
  157. // // extern Person_Name_t;
  158. // // extern Person_type_t;
  159. void selectionSort(int arr[], int n, int indices[]);
  160. int person_get_num_is_exist(uint8_t type,uint16_t num);
  161. int person_get_num(uint8_t type);
  162. void person_add(uint8_t type,uint8_t num,char* in,char *out);
  163. void person_del(uint8_t type,uint8_t num,char* in,char *out);
  164. #endif
  165. typedef struct
  166. {
  167. uint8_t cmd;
  168. uint8_t len;
  169. uint16_t Year;
  170. uint8_t Month;
  171. uint8_t Day;
  172. uint8_t Hour;
  173. uint8_t Minute;
  174. uint8_t Second;
  175. uint8_t time[20];
  176. }Current_Time_t;
  177. typedef struct
  178. {
  179. uint8_t cmd;
  180. uint8_t len;
  181. uint8_t mac_addr[20]; //16进制mac地址 中间: 分割 0x3A
  182. }Mac_t;
  183. typedef struct
  184. {
  185. uint8_t cmd;
  186. uint8_t len;
  187. uint8_t client_id[20]; //设备id
  188. }Client_t;
  189. typedef struct
  190. {
  191. uint8_t cmd;
  192. uint8_t len;
  193. uint8_t product[20]; //产品型号设备
  194. }Product_Device_t;
  195. typedef struct
  196. {
  197. uint8_t head[2];
  198. uint8_t CRC;
  199. Mac_t mac ; //0x03
  200. Client_t client; //0x04
  201. Product_Device_t product; //0x05
  202. Current_Time_t time; //0x61
  203. }Qrcode_protocol_t;
  204. typedef struct
  205. {
  206. bool is_complete;
  207. uint8_t *data;
  208. // uint8_t data[1024];
  209. int len;
  210. int index;
  211. }YC_DATA_T;
  212. #define USE_DATA_LEN_INDEX 15
  213. #define USE_CMD_LEN_INDEX 12
  214. #define USELESS_DATA_LEN 17
  215. #define DATA_START_LEN (USELESS_DATA_LEN)
  216. void timer_init(void);
  217. void lora_timer_start(void);
  218. void lora_timer_restart(void);
  219. void lora_tiemr_stop(void);
  220. void adc1_init(void);
  221. void print_systenInfo(void);
  222. void yc_timer_restart(void);
  223. // void periodic_timer_callback(void* arg);
  224. void print_yc_data(const LORA_DATA_T* buf);
  225. void business_logic_func(const LORA_DATA_T* buf,uint8_t cmd_index,int msg);
  226. void screen_display(void);
  227. bool filtered_data(const LORA_DATA_T* buf);
  228. void uincode2gbk(char *str,uint16_t len,char *out_buffer);
  229. void qrcode_protocol_create(char *result,Machine_info_t info);
  230. bool subcontract(YC_DATA_T* data);
  231. void send_rssi(void);
  232. void send_status(void);
  233. void send_ACK(char cmd,bool flag);
  234. void loro_gwpair_ack(int destaddr,int sourceaddr,int cmd,int st,char *strd);
  235. //typedef unsigned char u8;
  236. int findByteSequence(const u8* array, int arraySize, const u8* sequence, int sequenceSize, int** positions);
  237. void analysis_protocol(char *result,int len);
  238. int reply_ack_func(int cmd,int msg_id,bool is_send,uint8_t *result);
  239. void send_can_I_receive();
  240. void send_pair_ack();
  241. void terminal_send_data(void);
  242. void update_last_button_info(uint8_t btn);
  243. void f_send_version(void);
  244. void f_send_get_chart_data(void);
  245. void f_send_lora_rssi(int rssi);
  246. void f_send_battary_vaule(int battry);
  247. void f_send_reply_status(int status);
  248. void set_status_heights(void);
  249. void user_compare(int last,int now);
  250. void user_compare_power_off(int last,int now);//这个函数用来比较关机状态时电量变化 刷右屏//
  251. void right_screen_send();
  252. // /* 链表节点结构体 */
  253. // struct ListNode {
  254. // uint16_t number; // 节点值
  255. // uint8_t type;
  256. // char* name;
  257. // struct ListNode *next; // 指向下一节点的引用
  258. // };
  259. // typedef struct ListNode ListNode;
  260. // ListNode *newListHead(void);
  261. // void printList(ListNode *head);
  262. #endif/*_YC_PROTOCOL_H_*/