ModemTcpComm.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /********************************************************************************
  2. * File Name: ModemTcpComm.h
  3. * Function Describe: Header file for ModemTcpComm.c
  4. * Explain:
  5. * Writer:
  6. * Date:
  7. *******************************************************************************/
  8. #ifndef __MODEM_TCP_COMM_H
  9. #define __MODEM_TCP_COMM_H
  10. //-------------------------------------------------------------------------------
  11. #include <rtl.h>
  12. #include "MsgQueue.h"
  13. #include "Modem.h"
  14. #include "ProductPara.h"
  15. //-------------------------------------------------------------------------------
  16. #define TCP_SEND_BUF_LEN 1000
  17. //包头
  18. #define TCP_PACKET_HEAD 0xAB
  19. //以下CMD用于应用数据上行和下行命令
  20. #define CMD_LOGIN 0x1A
  21. #define CMD_LOGIN_ACK 0x1B
  22. #define CMD_LOGIN_REJECT 0x1C
  23. #define CMD_SEND_TEST 0x2A
  24. #define CMD_SEND_TEST_ACK 0x2B
  25. #define CMD_CONTROL 0x3B
  26. #define CMD_CONTROL_ACK 0x3A
  27. //以下CMD用于FOTA数据上行和下行命令
  28. #define CMD_GET_FILE_INFO 0x6A
  29. #define CMD_GET_FILE_INFO_ACK 0x6B
  30. #define CMD_GET_FILE_DATA 0x7A
  31. #define CMD_GET_FILE_DATA_ACK 0x7B
  32. #define TIMEOUT_10MS_FILE 500 //间隔5秒进行一次文件请求
  33. #define TIMEOUT_10MS_DATA 300 //间隔3秒进行一次数据请求
  34. #define MAX_TIME_GET_FILE 3 //最多请求文件3次[连续]
  35. #define MAX_TIME_GET_DATA 5 //最多请求数据5次[连续]
  36. #define DATA_DRAT_SIZE_PER_TIME 1024 //每一次数据请求包大小
  37. #define APP_FILE_DATA_ADDR EXFLASH_FILE_DATA_ADDR //保存在外部FLASH哪个位置开始
  38. typedef struct SUT_TCP_STATUS
  39. {
  40. M_STATUE FoTa;
  41. unsigned short LoginWaitTime;//0--不用等待即可登陆 >0 等待多少秒后登陆
  42. M_STATUE ServerStatus;
  43. M_STATUE ServerLoginOnce;//曾经登陆过服务器
  44. unsigned char NetMode;//0--未启动 1--4G Mode 2--LAN Mode
  45. }SUT_TCP_STATUS;
  46. extern SUT_TCP_STATUS sutTcpStatus;
  47. typedef struct SUT_LOGIN_ACK
  48. {
  49. //Interval(2) GNSSEnable(1) NetMode(1) NewVer(2) NewIP(4) NewPort(2)
  50. unsigned short Interval;
  51. unsigned char GNSSEnable;
  52. unsigned char NetMode;
  53. unsigned short NewVer;
  54. unsigned char NewIP[4];
  55. unsigned short NewPort;
  56. }SUT_LOGIN_ACK;
  57. extern SUT_LOGIN_ACK sutLoginAck;
  58. typedef struct SUT_LOGIN
  59. {
  60. char Model[8]; //产品型号 WP201
  61. unsigned short Ver;//版本号
  62. unsigned short Rand;//随机数 每次传输都会变,用来干扰
  63. unsigned long ASN; //ASN号 根据硬件ID生成,有可能重复
  64. unsigned long AKEY;//密码
  65. char IMEI[16];//IMEI实际只有15位,因此最后一位应填0
  66. char CCID[20];//SIM卡的CCID号
  67. }__attribute__((packed)) SUT_LOGIN;
  68. extern SUT_LOGIN sutLoginInfo;//size=56bytes
  69. typedef enum
  70. {
  71. FOTA_OFF=0,
  72. FOTA_ON
  73. }FOTA_TYPE;
  74. typedef enum
  75. {
  76. FOTA_END=0, //完成操作
  77. FOTA_GET_FILEINFO,//获取文件信息
  78. FOTA_GET_FILEDATA,//拉取文件内容
  79. }FOTA_STATUS;
  80. typedef struct SUT_FILE_INFO2
  81. {
  82. unsigned char encrypted; //文件数据是否已加密? 0--未加密 1--加密算法1:各字节和key直接异或运算; 2--加密算法2:将key转为key1后再与各字节异或运算; 3...其他
  83. unsigned char key; //加密用的key
  84. char FileName[20]; //文件名。一般情况下,文件名=ProductName_Vxxx 其中xxx为版本号
  85. unsigned int FileLength; //文件总长度
  86. unsigned char MD5[16]; //文件MD5码. 如果文件已加密,此MD5为加密后的文件的MD5
  87. }__attribute__((packed)) SUT_FILE_INFO;
  88. typedef struct
  89. {
  90. FOTA_STATUS fotaStatus;
  91. unsigned char tcpCnt;//不能间隔太快发连接TCP指令,这是间隔计数
  92. unsigned int time_10ms_cnt;
  93. unsigned char retryTime;
  94. unsigned short targetVersion;
  95. ////////////////////////////////////////////
  96. unsigned int fileLength;
  97. unsigned int lastOffset;//上一次 偏移
  98. unsigned int nextOffset;//下一次 偏移
  99. unsigned char encrypted;
  100. unsigned char key;
  101. unsigned char MD5[16];
  102. }__attribute__((packed)) SUT_FOTA_PARA;
  103. extern SUT_FOTA_PARA sutFotaPara;
  104. extern unsigned char g_ucUploadCode; //上传标志码,每次上传前先自动加1
  105. extern unsigned char g_ucUploadCodeAck;//上传标志码服务器回传码
  106. void TcpCommInit(void);
  107. unsigned short TcpPackingReg(unsigned char *pBuf);
  108. unsigned short TcpPackingSendTest(unsigned char *pBuf);
  109. unsigned short TcpPackingSendTick(unsigned char *pBuf);
  110. void TcpRecvData(unsigned char *pData,unsigned short DataLen);
  111. unsigned short PacketGetFileInfo(unsigned char *buf);
  112. void IapGetUpdateVersion(void);
  113. void FoTaGetFileData(void);
  114. //-------------------------------------------------------------------------------
  115. #endif