123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- /********************************************************************************
- * File Name: ModemTcpComm.h
- * Function Describe: Header file for ModemTcpComm.c
- * Explain:
- * Writer:
- * Date:
- *******************************************************************************/
- #ifndef __MODEM_TCP_COMM_H
- #define __MODEM_TCP_COMM_H
- //-------------------------------------------------------------------------------
- #include <rtl.h>
- #include "MsgQueue.h"
- #include "Modem.h"
- #include "ProductPara.h"
- //-------------------------------------------------------------------------------
- #define TCP_SEND_BUF_LEN 1000
- //包头
- #define TCP_PACKET_HEAD 0xAB
- //以下CMD用于应用数据上行和下行命令
- #define CMD_LOGIN 0x1A
- #define CMD_LOGIN_ACK 0x1B
- #define CMD_LOGIN_REJECT 0x1C
- #define CMD_SEND_TEST 0x2A
- #define CMD_SEND_TEST_ACK 0x2B
- #define CMD_CONTROL 0x3B
- #define CMD_CONTROL_ACK 0x3A
- //以下CMD用于FOTA数据上行和下行命令
- #define CMD_GET_FILE_INFO 0x6A
- #define CMD_GET_FILE_INFO_ACK 0x6B
- #define CMD_GET_FILE_DATA 0x7A
- #define CMD_GET_FILE_DATA_ACK 0x7B
- #define TIMEOUT_10MS_FILE 500 //间隔5秒进行一次文件请求
- #define TIMEOUT_10MS_DATA 300 //间隔3秒进行一次数据请求
- #define MAX_TIME_GET_FILE 3 //最多请求文件3次[连续]
- #define MAX_TIME_GET_DATA 5 //最多请求数据5次[连续]
- #define DATA_DRAT_SIZE_PER_TIME 1024 //每一次数据请求包大小
- #define APP_FILE_DATA_ADDR EXFLASH_FILE_DATA_ADDR //保存在外部FLASH哪个位置开始
- typedef struct SUT_TCP_STATUS
- {
- M_STATUE FoTa;
- unsigned short LoginWaitTime;//0--不用等待即可登陆 >0 等待多少秒后登陆
- M_STATUE ServerStatus;
- M_STATUE ServerLoginOnce;//曾经登陆过服务器
- unsigned char NetMode;//0--未启动 1--4G Mode 2--LAN Mode
-
- }SUT_TCP_STATUS;
- extern SUT_TCP_STATUS sutTcpStatus;
- typedef struct SUT_LOGIN_ACK
- {
- //Interval(2) GNSSEnable(1) NetMode(1) NewVer(2) NewIP(4) NewPort(2)
- unsigned short Interval;
- unsigned char GNSSEnable;
- unsigned char NetMode;
- unsigned short NewVer;
- unsigned char NewIP[4];
- unsigned short NewPort;
- }SUT_LOGIN_ACK;
- extern SUT_LOGIN_ACK sutLoginAck;
- typedef struct SUT_LOGIN
- {
- char Model[8]; //产品型号 WP201
- unsigned short Ver;//版本号
- unsigned short Rand;//随机数 每次传输都会变,用来干扰
- unsigned long ASN; //ASN号 根据硬件ID生成,有可能重复
- unsigned long AKEY;//密码
- char IMEI[16];//IMEI实际只有15位,因此最后一位应填0
- char CCID[20];//SIM卡的CCID号
- }__attribute__((packed)) SUT_LOGIN;
- extern SUT_LOGIN sutLoginInfo;//size=56bytes
- typedef enum
- {
- FOTA_OFF=0,
- FOTA_ON
- }FOTA_TYPE;
- typedef enum
- {
- FOTA_END=0, //完成操作
- FOTA_GET_FILEINFO,//获取文件信息
- FOTA_GET_FILEDATA,//拉取文件内容
- }FOTA_STATUS;
- typedef struct SUT_FILE_INFO2
- {
- unsigned char encrypted; //文件数据是否已加密? 0--未加密 1--加密算法1:各字节和key直接异或运算; 2--加密算法2:将key转为key1后再与各字节异或运算; 3...其他
- unsigned char key; //加密用的key
- char FileName[20]; //文件名。一般情况下,文件名=ProductName_Vxxx 其中xxx为版本号
- unsigned int FileLength; //文件总长度
- unsigned char MD5[16]; //文件MD5码. 如果文件已加密,此MD5为加密后的文件的MD5
- }__attribute__((packed)) SUT_FILE_INFO;
- typedef struct
- {
- FOTA_STATUS fotaStatus;
-
- unsigned char tcpCnt;//不能间隔太快发连接TCP指令,这是间隔计数
- unsigned int time_10ms_cnt;
- unsigned char retryTime;
- unsigned short targetVersion;
- ////////////////////////////////////////////
-
- unsigned int fileLength;
- unsigned int lastOffset;//上一次 偏移
- unsigned int nextOffset;//下一次 偏移
- unsigned char encrypted;
- unsigned char key;
- unsigned char MD5[16];
-
- }__attribute__((packed)) SUT_FOTA_PARA;
- extern SUT_FOTA_PARA sutFotaPara;
- extern unsigned char g_ucUploadCode; //上传标志码,每次上传前先自动加1
- extern unsigned char g_ucUploadCodeAck;//上传标志码服务器回传码
- void TcpCommInit(void);
- unsigned short TcpPackingReg(unsigned char *pBuf);
- unsigned short TcpPackingSendTest(unsigned char *pBuf);
- unsigned short TcpPackingSendTick(unsigned char *pBuf);
- void TcpRecvData(unsigned char *pData,unsigned short DataLen);
- unsigned short PacketGetFileInfo(unsigned char *buf);
- void IapGetUpdateVersion(void);
- void FoTaGetFileData(void);
- //-------------------------------------------------------------------------------
- #endif
-
|