TcpTask.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 QX_TCP_IPADRRES "120.26.68.165"
  21. #define QX_TCP_PORT 14319
  22. // #define QX_TCP_IPADRRES "47.97.127.222"
  23. // #define QX_TCP_PORT 8712
  24. #define BATT_SN_LEN 17
  25. #define TCP_START_SYM1 0x23
  26. #define TCP_START_SYM2 0x23
  27. #define TCP_CMD_SYM 0x02 //实时信息上报是0x02
  28. #define TCP_ANS_SYM 0xFE
  29. /*-------以下为下行指令定义区----------*/
  30. #define TCP_QUERY_SYM 0x80
  31. #define TCP_SETCMD_SYM 0x81
  32. #define TCP_CONCMD_SYM 0x82
  33. /*----------------end----------------*/
  34. //encrypt methord
  35. #define TCP_ENCPT_ENABLE 0x00
  36. #define TCP_ENCPT_DISABLE 0x01
  37. //message type mark 0x02上报数据单元定义区
  38. #define BATTMSG 0x80
  39. #define GPSMSG 0x82
  40. #define VERSIONMSG 0x86
  41. typedef struct BattInfoType
  42. {
  43. UINT8 sendTimeUTC[6];
  44. UINT8 msgMark;
  45. UINT8 msgCollectionTimeUTC[6];
  46. UINT8 signalStrength;
  47. UINT8 errClass;
  48. UINT8 errCode[2];
  49. UINT8 battI[2];
  50. UINT8 battLinkVol[2];
  51. UINT8 battPackVol[2];
  52. UINT8 chrgState;
  53. UINT8 battSOC;
  54. UINT8 battSOH;
  55. UINT8 batCellBalenceState[4]; //uint32 should change to uint8[]: each bit stand for 1 cell, up to 1024
  56. UINT8 battCellNum; //uint8 should change to uint16 (0~65535) //zhengchao
  57. UINT8 battCellU[BATT_CELL_VOL_NUM_2];
  58. UINT8 battTempNum; //uint8 should change to uint16 (0~65535)
  59. UINT8 battCellTemp[BATT_TEMP_NUM];
  60. UINT8 battWorkState;
  61. UINT8 battHeatState;
  62. UINT8 battotherTempNum;
  63. UINT8 battotherTemp[BATT_OTHER_TEMP_NUM];
  64. }BattInfoType;
  65. typedef struct BattMsgtoTcpType
  66. {
  67. UINT8 startSymbol[2];
  68. UINT8 cmdSymbol;
  69. UINT8 ansSymbol;
  70. UINT8 SN[BATT_SN_LEN];
  71. UINT8 encryptMethod;
  72. UINT8 dataLength[2];
  73. BattInfoType battInfo;
  74. UINT8 CRC;
  75. }BattMsgtoTcpType;
  76. /*---------------------------------------------------------------------------*/
  77. typedef struct _GPSInfoType
  78. {
  79. UINT8 sendTimeUTC[6];
  80. UINT8 msgMark;
  81. UINT8 msgCollectionTimeUTC[6];
  82. UINT8 locateMark;
  83. UINT8 satelliteNum;
  84. UINT8 direction[2];
  85. UINT8 speed[2];
  86. UINT8 altitude[2];
  87. UINT8 latitude[4];
  88. UINT8 longitude[4];
  89. }GPSInfoType;
  90. typedef struct GPSMsgtoTcpType
  91. {
  92. UINT8 startSymbol[2];
  93. UINT8 cmdSymbol;
  94. UINT8 ansSymbol;
  95. UINT8 SN[BATT_SN_LEN];
  96. UINT8 encryptMethod;
  97. UINT8 dataLength[2];
  98. GPSInfoType gpsInfo;
  99. UINT8 CRC;
  100. }GPSMsgtoTcpType;
  101. /*---------------------------------------------------------------------------*/
  102. typedef struct _VerInfoType
  103. {
  104. UINT8 sendTimeUTC[6];
  105. UINT8 msgMark;
  106. UINT8 msgCollectionTimeUTC[6];
  107. UINT8 ICCID[20];
  108. UINT8 IMEI[15];
  109. UINT8 BMSHwVersion[2];
  110. UINT8 BMSSwVersion[4];
  111. UINT8 NBHwVersion[2];
  112. UINT8 BLVersion[4];
  113. UINT8 DRVVersion[4];
  114. UINT8 APPVersion[4];
  115. CHAR BmsType;
  116. CHAR BmsInfo;
  117. }VerInfoType;
  118. typedef struct VersionMsgtoTcpType
  119. {
  120. UINT8 startSymbol[2];
  121. UINT8 cmdSymbol;
  122. UINT8 ansSymbol;
  123. UINT8 SN[BATT_SN_LEN];
  124. UINT8 encryptMethod;
  125. UINT8 dataLength[2];
  126. VerInfoType VerInfo;
  127. UINT8 CRC;
  128. }VersionMsgtoTcpType;
  129. /*---------------------------------------------------------------------------*/
  130. typedef enum
  131. {
  132. APP_SOCKET_CONNECTION_CLOSED,
  133. APP_SOCKET_CONNECTION_CONNECTING,
  134. APP_SOCKET_CONNECTION_CONNECTED,
  135. }AppSocketConnectionStatus;
  136. typedef struct AppSocketConnectionContext_Tag
  137. {
  138. INT32 id;
  139. INT32 status;
  140. }AppSocketConnectionContext;
  141. typedef enum
  142. {
  143. PROCESS_TCP_STATE_IDLE = 0,
  144. PROCESS_TCP_STATE_SEND,
  145. PROCESS_TCP_STATE_RECV,
  146. PROCESS_TCP_STATE_SLEEP
  147. }process_TCP;
  148. void TcpTaskInit(void *arg);
  149. void TcpTaskDeInit(void *arg);