yc_protocol.h 8.7 KB

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