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