TcpTask.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. typedef struct BattInfoType
  34. {
  35. UINT8 sendTimeUTC[6];
  36. UINT8 msgMark;
  37. UINT8 msgCollectionTimeUTC[6];
  38. UINT8 signalStrength;
  39. UINT8 errClass;
  40. UINT8 errCode[2];
  41. UINT8 battI[2];
  42. UINT8 battLinkVol[2];
  43. UINT8 battPackVol[2];
  44. UINT8 chrgState;
  45. UINT8 battSOC;
  46. UINT8 battSOH;
  47. UINT8 batCellBalenceState[4]; //uint32 should change to uint8[]: each bit stand for 1 cell, up to 1024
  48. UINT8 battCellNum; //uint8 should change to uint16 (0~65535) //zhengchao
  49. UINT8 battCellU[BATT_CELL_VOL_NUM_2];
  50. UINT8 battTempNum; //uint8 should change to uint16 (0~65535)
  51. UINT8 battCellTemp[BATT_TEMP_NUM];
  52. UINT8 battWorkState;
  53. UINT8 battHeatState;
  54. UINT8 battMosTemp;
  55. UINT8 battEnvTemp;
  56. }BattInfoType;
  57. typedef struct BattMsgtoTcpType
  58. {
  59. UINT8 startSymbol[2];
  60. UINT8 cmdSymbol;
  61. UINT8 ansSymbol;
  62. UINT8 SN[BATT_SN_LEN];
  63. UINT8 encryptMethod;
  64. UINT8 dataLength[2];
  65. BattInfoType battInfo;
  66. UINT8 CRC;
  67. }BattMsgtoTcpType;
  68. typedef struct _GPSInfoType
  69. {
  70. UINT8 sendTimeUTC[6];
  71. UINT8 msgMark;
  72. UINT8 msgCollectionTimeUTC[6];
  73. UINT8 locateMark;
  74. UINT8 satelliteNum;
  75. UINT8 direction[2];
  76. UINT8 speed[2];
  77. UINT8 altitude[2];
  78. UINT8 latitude[4];
  79. UINT8 longitude[4];
  80. }GPSInfoType;
  81. typedef struct GPSMsgtoTcpType
  82. {
  83. UINT8 startSymbol[2];
  84. UINT8 cmdSymbol;
  85. UINT8 ansSymbol;
  86. UINT8 SN[BATT_SN_LEN];
  87. UINT8 encryptMethod;
  88. UINT8 dataLength[2];
  89. GPSInfoType gpsInfo;
  90. UINT8 CRC;
  91. }GPSMsgtoTcpType;
  92. typedef enum
  93. {
  94. APP_SOCKET_CONNECTION_CLOSED,
  95. APP_SOCKET_CONNECTION_CONNECTING,
  96. APP_SOCKET_CONNECTION_CONNECTED,
  97. }AppSocketConnectionStatus;
  98. typedef struct AppSocketConnectionContext_Tag
  99. {
  100. INT32 id;
  101. INT32 status;
  102. }AppSocketConnectionContext;
  103. typedef struct Fota_Type
  104. {
  105. bool Fota_update_flag ;
  106. bool Fota_update_error ;
  107. UINT32 Fota_All_Data_Len ;
  108. UINT32 Fota_Current_Addres ;
  109. UINT8 Fota_Recv_Data_Len ;
  110. UINT8 Fota_Recv_Data[100] ;
  111. UINT32 Fota_Flash_Addres;
  112. UINT8 Fota_CRC ;
  113. }Fota_Type;
  114. typedef enum
  115. {
  116. PROCESS_TCP_STATE_IDLE = 0,
  117. PROCESS_TCP_STATE_SEND,
  118. PROCESS_TCP_STATE_RECV,
  119. PROCESS_TCP_STATE_SLEEP
  120. }process_TCP;
  121. void TcpTaskInit(void *arg);
  122. void TcpTaskDeInit(void *arg);