TcpTask.h 4.8 KB

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