TcpTask.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /****************************************************************************
  2. *
  3. * Copy right: Qx.Chen Jie
  4. * File name: TcpTask.h
  5. * Description: 网络发送接收任务
  6. * History: 2021-03-07
  7. *
  8. ****************************************************************************/
  9. #define PROC_TCP_TASK_STACK_SIZE (2048)
  10. #define QMSG_ID_BASE (0x160)
  11. #define QMSG_ID_NW_IP_READY (QMSG_ID_BASE)
  12. #define QMSG_ID_NW_IP_SUSPEND (QMSG_ID_BASE + 1)
  13. #define QMSG_ID_NW_IP_NOREACHABLE (QMSG_ID_BASE + 2)
  14. #define QMSG_ID_SOCK_SENDPKG (QMSG_ID_BASE + 4)
  15. #define QMSG_ID_SOCK_RECVPKG (QMSG_ID_BASE + 5)
  16. #define QMSG_ID_SOCK_EXIT (QMSG_ID_BASE + 6)
  17. #define APP_EVENT_QUEUE_SIZE (10)
  18. #define QX_TCP_IPADRRES "120.26.68.165"
  19. #define QX_TCP_PORT 14319
  20. // #define QX_TCP_IPADRRES "47.97.127.222"
  21. // #define QX_TCP_PORT 8712
  22. #define BATT_SN_LEN 17
  23. #define TCP_START_SYM1 0x23
  24. #define TCP_START_SYM2 0x23
  25. #define TCP_CMD_SYM 0x02
  26. #define TCP_ANS_SYM 0xFE
  27. //encrypt methord
  28. #define TCP_ENCPT_ENABLE 0x00
  29. #define TCP_ENCPT_DISABLE 0x01
  30. //message type mark
  31. #define BATTMSG 0x80
  32. #define GPSMSG 0x82
  33. #define VERSIONMSG 0x86
  34. typedef struct BattInfoType
  35. {
  36. UINT8 sendTimeUTC[6];
  37. UINT8 msgMark;
  38. UINT8 msgCollectionTimeUTC[6];
  39. UINT8 signalStrength;
  40. UINT8 errClass;
  41. UINT8 errCode[2];
  42. UINT8 battI[2];
  43. UINT8 battLinkVol[2];
  44. UINT8 battPackVol[2];
  45. UINT8 chrgState;
  46. UINT8 battSOC;
  47. UINT8 battSOH;
  48. UINT8 batCellBalenceState[4]; //uint32 should change to uint8[]: each bit stand for 1 cell, up to 1024
  49. UINT8 battCellNum; //uint8 should change to uint16 (0~65535) //zhengchao
  50. UINT8 battCellU[BATT_CELL_VOL_NUM_2];
  51. UINT8 battTempNum; //uint8 should change to uint16 (0~65535)
  52. UINT8 battCellTemp[BATT_TEMP_NUM];
  53. UINT8 battWorkState;
  54. UINT8 battHeatState;
  55. UINT8 battMosTemp;
  56. UINT8 battEnvTemp;
  57. }BattInfoType;
  58. typedef struct BattMsgtoTcpType
  59. {
  60. UINT8 startSymbol[2];
  61. UINT8 cmdSymbol;
  62. UINT8 ansSymbol;
  63. UINT8 SN[BATT_SN_LEN];
  64. UINT8 encryptMethod;
  65. UINT8 dataLength[2];
  66. BattInfoType battInfo;
  67. UINT8 CRC;
  68. }BattMsgtoTcpType;
  69. /*---------------------------------------------------------------------------*/
  70. typedef struct _GPSInfoType
  71. {
  72. UINT8 sendTimeUTC[6];
  73. UINT8 msgMark;
  74. UINT8 msgCollectionTimeUTC[6];
  75. UINT8 locateMark;
  76. UINT8 satelliteNum;
  77. UINT8 direction[2];
  78. UINT8 speed[2];
  79. UINT8 altitude[2];
  80. UINT8 latitude[4];
  81. UINT8 longitude[4];
  82. }GPSInfoType;
  83. typedef struct GPSMsgtoTcpType
  84. {
  85. UINT8 startSymbol[2];
  86. UINT8 cmdSymbol;
  87. UINT8 ansSymbol;
  88. UINT8 SN[BATT_SN_LEN];
  89. UINT8 encryptMethod;
  90. UINT8 dataLength[2];
  91. GPSInfoType gpsInfo;
  92. UINT8 CRC;
  93. }GPSMsgtoTcpType;
  94. /*---------------------------------------------------------------------------*/
  95. typedef struct _VerInfoType
  96. {
  97. UINT8 sendTimeUTC[6];
  98. UINT8 msgMark;
  99. UINT8 msgCollectionTimeUTC[6];
  100. UINT8 ICCID[20];
  101. UINT8 IMEI[15];
  102. UINT8 BMSHwVersion;
  103. UINT8 BMSSwVersion;
  104. UINT8 NBHwVersion[2];
  105. UINT8 BLVersion[4];
  106. UINT8 DRVVersion[4];
  107. UINT8 APPVersion[4];
  108. }VerInfoType;
  109. typedef struct VersionMsgtoTcpType
  110. {
  111. UINT8 startSymbol[2];
  112. UINT8 cmdSymbol;
  113. UINT8 ansSymbol;
  114. UINT8 SN[BATT_SN_LEN];
  115. UINT8 encryptMethod;
  116. UINT8 dataLength[2];
  117. VerInfoType VerInfo;
  118. UINT8 CRC;
  119. }VersionMsgtoTcpType;
  120. /*---------------------------------------------------------------------------*/
  121. typedef enum
  122. {
  123. APP_SOCKET_CONNECTION_CLOSED,
  124. APP_SOCKET_CONNECTION_CONNECTING,
  125. APP_SOCKET_CONNECTION_CONNECTED,
  126. }AppSocketConnectionStatus;
  127. typedef struct AppSocketConnectionContext_Tag
  128. {
  129. INT32 id;
  130. INT32 status;
  131. }AppSocketConnectionContext;
  132. typedef struct Fota_Type
  133. {
  134. bool Fota_update_flag ;
  135. bool Fota_update_error ;
  136. UINT32 Fota_All_Data_Len ;
  137. UINT32 Fota_Current_Addres ;
  138. UINT8 Fota_Recv_Data_Len ;
  139. UINT8 Fota_Recv_Data[100] ;
  140. UINT32 Fota_Flash_Addres;
  141. UINT8 Fota_CRC ;
  142. }Fota_Type;
  143. typedef enum
  144. {
  145. PROCESS_TCP_STATE_IDLE = 0,
  146. PROCESS_TCP_STATE_SEND,
  147. PROCESS_TCP_STATE_RECV,
  148. PROCESS_TCP_STATE_SLEEP
  149. }process_TCP;
  150. void TcpTaskInit(void *arg);
  151. void TcpTaskDeInit(void *arg);