yc_protocol.h 8.5 KB

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