AppTaskTcp.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /****************************************************************************
  2. *
  3. * Copy right: Qx.Chen Jie
  4. * File name: TcpTask.h
  5. * Description: 网络发送接收任务
  6. * History: 2021-03-07
  7. *
  8. ****************************************************************************/
  9. #include "commontypedef.h"
  10. #include "bsp.h"
  11. #include "bsp_custom.h"
  12. #include "osasys.h"
  13. #include "ostask.h"
  14. #include "queue.h"
  15. #include "ps_event_callback.h"
  16. #include "cmisim.h"
  17. #include "cmimm.h"
  18. #include "cmips.h"
  19. #include "sockets.h"
  20. #include "psifevent.h"
  21. #include "ps_lib_api.h"
  22. #include "lwip/netdb.h"
  23. #include "debug_log.h"
  24. #include "slpman_ec616.h"
  25. #include "plat_config.h"
  26. #include "ec_tcpip_api.h"
  27. #include "hal_module_adapter.h"
  28. #include "timers.h"
  29. #include "Signal.h"
  30. #define PROC_TCP_TASK_STACK_SIZE (2048)
  31. #define QMSG_ID_BASE (0x160)
  32. #define QMSG_ID_NW_IP_READY (QMSG_ID_BASE)
  33. #define QMSG_ID_NW_IP_SUSPEND (QMSG_ID_BASE + 1)
  34. #define QMSG_ID_NW_IP_NOREACHABLE (QMSG_ID_BASE + 2)
  35. #define QMSG_ID_SOCK_SENDPKG (QMSG_ID_BASE + 4)
  36. #define QMSG_ID_SOCK_RECVPKG (QMSG_ID_BASE + 5)
  37. #define QMSG_ID_SOCK_EXIT (QMSG_ID_BASE + 6)
  38. #define APP_EVENT_QUEUE_SIZE (10)
  39. /*---------------测试IP地址-----------------------------------*/
  40. // #define QX_TCP_ADD "rpi.it5000.com"
  41. // #define QX_TCP_PORT 8812
  42. /*---------------测试IP地址END-----------------------------------*/
  43. #define TCP_START_SYM1 0x23
  44. #define TCP_START_SYM2 0x23
  45. #define TCP_CMD_SYM 0x02 //实时信息上报是0x02
  46. #define TCP_ANS_SYM 0xFE
  47. /*-------以下为下行指令定义区----------*/
  48. #define TCP_QUERY_SYM 0x80
  49. #define TCP_SETCMD_SYM 0x81
  50. #define TCP_CONCMD_SYM 0x82
  51. /*----------------end----------------*/
  52. //encrypt methord
  53. #define TCP_ENCPT_ENABLE 0x00
  54. #define TCP_ENCPT_DISABLE 0x01
  55. //message type mark 0x02上报数据单元定义区
  56. #define BATTMSG 0x80
  57. #define GPSMSG 0x82
  58. #define STATESMSG 0x85
  59. #define VERSIONMSG 0x86
  60. #define DEBUGMSG 0x8C
  61. typedef struct BattInfoType
  62. {
  63. UINT8 sendTimeUTC[6];
  64. UINT8 msgMark;
  65. UINT8 msgCollectionTimeUTC[6];
  66. UINT8 signalStrength;
  67. UINT8 errClass;
  68. UINT8 errCode[2];
  69. UINT8 battI[2];
  70. UINT8 battLinkVol[2];
  71. UINT8 battPackVol[2];
  72. UINT8 switchState;
  73. UINT8 battSOC;
  74. UINT8 battSOH;
  75. UINT8 batCellBalenceState[4]; //uint32 should change to uint8[]: each bit stand for 1 cell, up to 1024
  76. UINT8 battCellNum; //uint8 should change to uint16 (0~65535) //zhengchao
  77. UINT8 battCellU[BATT_CELL_VOL_NUM_2];
  78. UINT8 battTempNum; //uint8 should change to uint16 (0~65535)
  79. UINT8 battCellTemp[BATT_TEMP_NUM];
  80. UINT8 battWorkState;
  81. UINT8 battHeatEnableState;
  82. UINT8 battotherTempNum;
  83. UINT8 battotherTemp[BATT_OTHER_TEMP_NUM+NB_OTHER_TEMP_NUM];
  84. }BattInfoType;
  85. typedef struct BattMsgtoTcpType
  86. {
  87. UINT8 startSymbol[2];
  88. UINT8 cmdSymbol;
  89. UINT8 ansSymbol;
  90. UINT8 SN[BATT_SN_LEN];
  91. UINT8 encryptMethod;
  92. UINT8 dataLength[2];
  93. BattInfoType battInfo;
  94. UINT8 CRC;
  95. }BattMsgtoTcpType;
  96. /*---------------------------------------------------------------------------*/
  97. typedef struct _GPSInfoType
  98. {
  99. UINT8 sendTimeUTC[6];
  100. UINT8 msgMark;
  101. UINT8 msgCollectionTimeUTC[6];
  102. UINT8 locateMark;
  103. UINT8 satelliteNum;
  104. UINT8 direction[2];
  105. UINT8 speed[2];
  106. UINT8 altitude[2];
  107. UINT8 latitude[4];
  108. UINT8 longitude[4];
  109. UINT8 AccMileage[4];
  110. }GPSInfoType;
  111. typedef struct GPSMsgtoTcpType
  112. {
  113. UINT8 startSymbol[2];
  114. UINT8 cmdSymbol;
  115. UINT8 ansSymbol;
  116. UINT8 SN[BATT_SN_LEN];
  117. UINT8 encryptMethod;
  118. UINT8 dataLength[2];
  119. GPSInfoType gpsInfo;
  120. UINT8 CRC;
  121. }GPSMsgtoTcpType;
  122. /*---------------------------------------------------------------------------*/
  123. typedef struct _VerInfoType
  124. {
  125. UINT8 sendTimeUTC[6];
  126. UINT8 msgMark;
  127. UINT8 msgCollectionTimeUTC[6];
  128. UINT8 ICCID[20];
  129. UINT8 IMEI[15];
  130. UINT8 BMSHwVersion[2];
  131. UINT8 BMSSwVersion[4];
  132. UINT8 NBHwVersion[2];
  133. UINT8 BLVersion[4];
  134. UINT8 DRVVersion[4];
  135. UINT8 APPVersion[4];
  136. UINT8 BmsType;
  137. UINT8 BmsInfo;
  138. UINT8 DataModuleType;
  139. }VerInfoType;
  140. typedef struct VersionMsgtoTcpType
  141. {
  142. UINT8 startSymbol[2];
  143. UINT8 cmdSymbol;
  144. UINT8 ansSymbol;
  145. UINT8 SN[BATT_SN_LEN];
  146. UINT8 encryptMethod;
  147. UINT8 dataLength[2];
  148. VerInfoType VerInfo;
  149. UINT8 CRC;
  150. }VersionMsgtoTcpType;
  151. typedef struct _DebugInfoType
  152. {
  153. UINT8 sendTimeUTC[6];
  154. UINT8 msgMark;
  155. UINT8 DebugLen[2];
  156. }DebugInfoType;
  157. typedef struct DebugMsgtoTcp_Type
  158. {
  159. UINT8 startSymbol[2];
  160. UINT8 cmdSymbol;
  161. UINT8 ansSymbol;
  162. UINT8 SN[BATT_SN_LEN];
  163. UINT8 encryptMethod;
  164. UINT8 dataLength[2];
  165. DebugInfoType DebugInfo;
  166. UINT8 CRC;
  167. }DebugMsgtoTcpType;
  168. /*---------------------------------------------------------------------------*/
  169. typedef enum
  170. {
  171. APP_SOCKET_CONNECTION_CLOSED = 0,
  172. APP_SOCKET_CONNECTION_CONNECTING,
  173. APP_SOCKET_CONNECTION_CONNECTED,
  174. }AppSocketConnectionStatus;
  175. typedef enum
  176. {
  177. PROCESS_TCP_STATE_IDLE = 0,
  178. PROCESS_TCP_STATE_SEND,
  179. PROCESS_TCP_STATE_RECV,
  180. PROCESS_TCP_STATE_SLEEP
  181. }process_TCP;
  182. void TcpTaskInit(void *arg);
  183. void TcpTaskDeInit(void *arg);