dtu_uart2.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (c) 2006-2020, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-05-28 Administrator the first version
  9. */
  10. #ifndef APPLICATIONS_INC_DTU_UART2_H_
  11. #define APPLICATIONS_INC_DTU_UART2_H_
  12. #include <cJSON.h>
  13. #define DTU_UART_NAME "uart2" /*串口设备名称*/
  14. #define MAX_DTU_SIZE 512
  15. typedef struct{
  16. char msg_pool[MAX_DTU_SIZE];
  17. }DataTemp;
  18. extern rt_device_t dtuserial; /*串口设备句柄*/
  19. /* 串口5(485)句柄。定义同时存在于 dtu_uart2.c 和 sht30_collect.c,
  20. 靠 -fcommon 合并成同一个符号 —— 两边赋值的是同一个指针, 行为正确,
  21. 但这里必须 extern 出来给 control.c 的 uart_stop_for_ota() 用。 */
  22. extern rt_device_t serial_485;
  23. //enum B_2
  24. //{
  25. // "STATUS_UNACTIVE",
  26. // "STATUS_OFFLINE",
  27. // "STATUS_UNUSUAL",
  28. // |STATUS_ONLINE""
  29. //};
  30. //5.0测报灯数据上报结构体
  31. typedef struct {
  32. char DEVICE_SERIAL_NUMBER[32];
  33. char SIM[32];
  34. char SIGNAL[16];
  35. char LOCATION[32];
  36. double VOLTAGE;
  37. double CURRENT;
  38. double TEMPERATURE;
  39. double HUMIDITY;
  40. char UPDATE_DATE[64];
  41. char STATUS[32];
  42. char STATUS_DESCRIPTION[64];
  43. char START_TIME[64];
  44. char END_TIME[64];
  45. char VERSION[16];
  46. uint8_t DATT;
  47. uint8_t TPS;
  48. uint8_t LPS;
  49. uint8_t RPS;
  50. uint8_t WS;
  51. uint8_t TT;
  52. }WS_CBDV5;
  53. void dtu_send_data_start(void);
  54. //查询数据---{"cmd": "read"}
  55. //重启-------{"cmd": "reboot"}
  56. //升级-------{"cmd": "update"}
  57. //拍照-------{"cmd": "takephoto"}
  58. //{"cmd":"paramconf","ext":{"hst":110,"collt":10,"et":6,"datt":2,"shake_sec":1,"tpl":5,"shake":1,"tph":70,"ts":1,"st":20,"imgres":2,"htim":20,"tt":8}}
  59. //{"cmd":"synchronization","ext":{"year":1,"month":1,"day":0,"hour":25,"min":0,"sec":0,"lat":"113.2056","lng":"21.0596","csq",31,"net",0,"iccid","123135453","imei":"895864646464464"}}
  60. void DTU_Write(char *fmt, ...);
  61. /* ★ 发送"堆上分配的 JSON 串"并自动释放(一步到位, 防止漏 free 把堆吃光)。
  62. 传进来的必须是 cJSON_PrintUnformatted / malloc 的产物, 不能是栈/静态缓冲。 */
  63. void dtu_write_json(char *json);
  64. /* ★ 安全停掉 DTU 发送线程(删完会重建 dtu_write_mutex, 防止后续 DTU_Write 永久挂起) */
  65. void dtu_stop_send_thread(void);
  66. void dtu_request_report(void); /* 请求尽快执行一次数据上报(屏幕设置时间后更新RTU时间等) */
  67. void Uart5_Write(char *fmt, ...);
  68. void Uart5_Write_Bin(const uint8_t *data, uint16_t len);
  69. extern volatile uint8_t uart5_rx_flag; /* 485收到数据标志 */
  70. int dtu_data_play(void);
  71. int parseDtu(char *json_string);
  72. char *makeJson(void);
  73. char *makeJson_platform(char *plt);
  74. char *makeJson_Rtutakephoto();
  75. char *makeJson_ReadInfo();
  76. char *makeJson_takephoto();
  77. char *makeJson_Warn(char * s,char *t);
  78. void UpLoad_Data(void);
  79. char *uint8tostring(uint8_t dat);
  80. char *makeJson_Config_Reset(void);
  81. char *makeJson_Config_BDH(char * deviceId);
  82. char *makeJson_selfCheck_(uint8_t sta);
  83. char *makeJson_Cam(char * s,char *t);
  84. char *makeJson_C01_Warn(uint16_t code,double process);
  85. char *makeJson_record_read(char *type);
  86. char *makeJson_record_write(char *mqtt_num,char *photo_num);
  87. char* makeJsonRpc2_0(const char* method, cJSON* params, int id);
  88. void backup_param_to_rtu(void);
  89. void recover_param_from_rtu(void);
  90. /* 参数内容发生变更时请求备份到 RTU(同步 master 2026-10-15)。
  91. * 仅置待办标志、不阻塞调用者;实际发送由 DTU 发送线程在 RTU 通信正常后执行
  92. * (见 dtu_param_pending_service)。唯一调用点:param_mirror.c 的 param_mirror_sync()。 */
  93. void dtu_request_param_backup(void);
  94. void dtu_uart2_reinit_rx(void);
  95. #endif /* APPLICATIONS_INC_DTU_UART2_H_ */