960 lines
31 KiB
C
960 lines
31 KiB
C
#include "EC20.h"
|
||
|
||
extern uint32_t appRunTime ;
|
||
extern Application app ;
|
||
extern MonthUserStruct monthUserInfo ;
|
||
extern NetParameter ec20NetParameter ;
|
||
extern uint8_t ec20ReceBuffer[MAX_UART_BUFFER_LEN*2] ;
|
||
extern uint8_t userDataReceBuffer[MAX_UART_BUFFER_LEN*4] ;
|
||
extern void CleanUpBuffer(uint8_t *buf ,uint8_t len) ;
|
||
extern uint8_t uart3RecBufferIndex ;
|
||
extern uint8_t bleHasConfigFrame ;
|
||
extern uint8_t ec20RecBufferIndex;
|
||
extern volatile uint8_t userDataRecBufferIndex;
|
||
extern uint8_t EC20HasSendData ;
|
||
extern void SystemSoftReset( void ) ;
|
||
extern void UserDataBufferReset(void) ;
|
||
extern void EC20BufferReset(void) ;
|
||
extern ErrorStatus UpDataToTcpSrver(enum UPDATATYPE updataType, const char* Title, uint8_t* loadBuf) ;
|
||
extern volatile uint8_t serveReturnSucceedFlag ;
|
||
/**************************************************************************
|
||
EC20接收到数据后,显示如下数据:/r/n +QIURC:"recv",0,5 /r/n payload
|
||
|
||
+QIURC: "recv",0,5
|
||
Hello
|
||
|
||
远程服务器关闭后,收到: /r/n +QIURC: "closed",0
|
||
*********************************************************************************/
|
||
void EC20_GPIO_Init( void )
|
||
{
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
|
||
GPIO_InitStructure.GPIO_Pin = EC20_POW_PIN; //稳压片使能
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_Init(GPIOE, &GPIO_InitStructure);
|
||
GPIO_ResetBits( EC20_POW_PORT, EC20_POW_PIN ) ; //初始化EC20处于断电状态,后面再给模块上电
|
||
|
||
|
||
GPIO_InitStructure.GPIO_Pin = EC20_RST_PIN; //PERST上拉 = PE15拉低
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_Init(GPIOE, &GPIO_InitStructure);
|
||
GPIO_ResetBits( EC20_RST_PORT, EC20_RST_PIN ) ;
|
||
|
||
GPIO_InitStructure.GPIO_Pin = EC20_RFEN_PIN; //W_DISABLE上拉使能RF = PB13拉低使能RF
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_Init(GPIOE, &GPIO_InitStructure);
|
||
GPIO_ResetBits( EC20_RFEN_PORT, EC20_RFEN_PIN ) ;
|
||
|
||
GPIO_InitStructure.GPIO_Pin = EC20_WAKEUPIN_PIN; //WAKEUP_IN需要拉低即PB12拉高
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||
GPIO_SetBits( EC20_WAKEUPIN_PORT, EC20_WAKEUPIN_PIN ) ;
|
||
|
||
GPIO_InitStructure.GPIO_Pin = EC20_UARTDTR_PIN; //UART_DTR拉低将唤醒模块 == PE13拉高唤醒
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //UART_DTR作为唤醒的时候,WAKEUP_IN需要保持低电平。
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_Init(GPIOE, &GPIO_InitStructure);
|
||
GPIO_ResetBits( EC20_UARTDTR_PORT, EC20_UARTDTR_PIN ) ; //初始化先不唤醒
|
||
|
||
|
||
GPIO_InitStructure.GPIO_Pin = EC20_WAKEUPSTATE_PIN; //WAKEUP_OUT指示模块休眠状态;WAKEUP=0=注册网络成功
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_Init(EC20_WAKEUPSTATE_PORT, &GPIO_InitStructure);
|
||
|
||
}
|
||
/****************************************************************************
|
||
* 名 称:void EC20_Module_SendCmd(char * cmd)
|
||
* 功 能:EC20模块发送命令并查看返回值
|
||
* 说 明:这个函数本质上是变参函数调用变参函数,归根到底是如何拿到可变的参数而已
|
||
* 内部调EC20BufferReset()函数,进行接收缓冲区的清空操作;
|
||
* 内部为了保证发送的命令能正确执行,都需要延时1秒钟;保险起见;
|
||
* 调用方法:
|
||
****************************************************************************/
|
||
void EC20_Module_SendCmd(uint8_t *format,...)
|
||
{
|
||
uint8_t temp[64] = {0};
|
||
va_list ap;
|
||
va_start (ap, format);
|
||
//vsprintf (temp, format, ap); //到此为止,所有的参数情况已经汇总到temp了
|
||
vsnprintf(temp, 63, format, ap);
|
||
EC20BufferReset() ;
|
||
USART_OUT(EC20_UART,"%s",temp);
|
||
va_end (ap);
|
||
//WaitForNMilSeconds(4); //发送完指令后,需要等400ms
|
||
Watchdog_Feed();
|
||
}
|
||
|
||
ErrorStatus EC20_SendCmdAndWaitForResp(uint8_t *logTitle, const char *wantReturn, uint16_t timesout, uint8_t *cmd,... ) // uint8_t *wantReturn,
|
||
{
|
||
uint16_t times = 0 ;
|
||
ErrorStatus status = TIMEOUT ;
|
||
uint8_t temp[400] = {0};
|
||
va_list ap;
|
||
va_start (ap, cmd);
|
||
//vsprintf (temp, cmd, ap); //到此为止,所有的参数情况已经汇总到temp了
|
||
vsnprintf(temp, 399, cmd, ap);
|
||
//Uart_Print_Debug_Info(UART_LOG, logTitle) ;
|
||
EC20BufferReset() ;
|
||
USART_OUT(EC20_UART, "%s", temp);
|
||
va_end (ap);
|
||
while( times++ < timesout )
|
||
{
|
||
WaitForNMilSeconds(1) ;
|
||
if( strstr( (const char*)ec20ReceBuffer, wantReturn) > 0 )
|
||
{
|
||
status = SUCCESS ;
|
||
Uart_Print_Debug_Info( UART_LOG, "%s %s", logTitle, ec20ReceBuffer ) ;
|
||
return (status) ;
|
||
}
|
||
else if( strstr( (const char*)ec20ReceBuffer, "ERROR" ) )
|
||
{
|
||
status = ERROR ;
|
||
Uart_Print_Debug_Info( UART_LOG, "%s %s", logTitle, ec20ReceBuffer ) ;
|
||
return (status) ;
|
||
}
|
||
}
|
||
Uart_Print_Debug_Info( UART_LOG, "%s %s", logTitle,(uint8_t*)"CMD Respond TimeOut!") ;
|
||
return (status) ;
|
||
}
|
||
|
||
void EC20_POWON(void)
|
||
{
|
||
uint8_t findCount = 0 ;
|
||
GPIO_SetBits( EC20_POW_PORT, EC20_POW_PIN ) ;
|
||
while( findCount < 20)
|
||
{
|
||
findCount++ ;
|
||
WaitForNSeconds(1) ;
|
||
if(strstr(ec20ReceBuffer, "RDY"))
|
||
{
|
||
USART_OUT( USART1, "Power on wait:%d S\r\n", findCount ) ;
|
||
break ;
|
||
}
|
||
}
|
||
}
|
||
|
||
void EC20_POWOFF(void)
|
||
{
|
||
GPIO_ResetBits( EC20_POW_PORT, EC20_POW_PIN ) ;
|
||
WaitForNSeconds(2) ;
|
||
}
|
||
|
||
ErrorStatus EC20_ShutDown(void)
|
||
{
|
||
EC20_SendCmdAndWaitForResp((uint8_t*)"\r\nClose Socket::", "OK", 100, (uint8_t*)EC20_CMD_CLOSESOCKET, ec20NetParameter.tcpConnectID0) ;
|
||
EC20_SendCmdAndWaitForResp((uint8_t*)"\r\nClose Socket::", "OK", 100, (uint8_t*)EC20_CMD_CLOSESOCKET, ec20NetParameter.tcpConnectID1) ;
|
||
EC20_SendCmdAndWaitForResp((uint8_t*)"\r\nDeactive TcpContext:", "OK", 20, (uint8_t*)EC20_CMD_DEACTCONTEXT, ec20NetParameter.tcpContextID ) ;
|
||
EC20_SendCmdAndWaitForResp((uint8_t*)"\r\nDeactive HttpContext:", "OK", 20, (uint8_t*)EC20_CMD_DEACTCONTEXT, ec20NetParameter.httpContextID ) ;
|
||
EC20_POWOFF() ;
|
||
}
|
||
|
||
void EC20_WAKEUP(void)
|
||
{
|
||
GPIO_SetBits( EC20_UARTDTR_PORT, EC20_UARTDTR_PIN ) ;
|
||
Wait_For_N_10ms(20) ; //UART_DTR拉低200ms
|
||
GPIO_ResetBits( EC20_UARTDTR_PORT, EC20_UARTDTR_PIN ) ;
|
||
WaitForNSeconds(3) ;
|
||
}
|
||
|
||
|
||
void EC20_Net_Init(void)
|
||
{
|
||
ec20NetParameter.tcpContextID = 1 ; //用于TCP
|
||
ec20NetParameter.tcpConnectID0 = 0 ; //出入口
|
||
ec20NetParameter.tcpConnectID1 = 1 ; //诱导牌
|
||
ec20NetParameter.tcpLocalPort = 0 ;
|
||
ec20NetParameter.httpContextID = 2 ; //用于HTTP
|
||
}
|
||
|
||
ErrorStatus EC20_Handshake( void )
|
||
{
|
||
uint8_t waitTimes = 0, retryTimes = CMD_RETRY_TIMES ;
|
||
ErrorStatus HandshakeStatus = ERROR ;
|
||
while( 0 < retryTimes-- )
|
||
{
|
||
EC20_Module_SendCmd(EC20_CMD_HANDSHAKE);
|
||
Wait_For_N_10ms( 10+( CMD_RETRY_TIMES-retryTimes)*10 );
|
||
Watchdog_Feed() ;
|
||
while( waitTimes++ < 4 )
|
||
{
|
||
if( strstr( (const char*)ec20ReceBuffer,"OK") )
|
||
{
|
||
Uart_Print_String( USART1, (uint8_t*)"EC20 Handshake OK!\r\n" ) ;
|
||
HandshakeStatus = SUCCESS ;
|
||
return (HandshakeStatus) ;
|
||
}
|
||
Wait_For_N_10ms( 10+( CMD_RETRY_TIMES-retryTimes)*10 ) ;
|
||
Watchdog_Feed() ;
|
||
}
|
||
}
|
||
Uart_Print_String(USART1, (uint8_t*)"\r\nEC20 Handshake error!\r\n") ;
|
||
USART_OUT( UART_LOG, "模块握手失败,请检查模块安装。") ;
|
||
return (HandshakeStatus) ;
|
||
}
|
||
|
||
uint8_t* EC20_Voltage(void)
|
||
{
|
||
uint8_t *start ;
|
||
uint8_t *end ;
|
||
EC20_Module_SendCmd( EC20_QUERY_VOLTAGE ) ;
|
||
WaitForNMilSeconds(3) ;
|
||
if( strstr((const char*)ec20ReceBuffer, "+CBC") )
|
||
{
|
||
start = strrchr( (const char*)ec20ReceBuffer, ',' ) ;
|
||
end = strchr( (const char*)start, 0x0D ) ;
|
||
*end = 0x00 ;
|
||
//CopyValues(ec20ReceBuffer, start, 0x0D, 50) ;
|
||
return (start+1) ;
|
||
}
|
||
return 0 ;
|
||
}
|
||
|
||
ErrorStatus EC20_CloseEcho(void)
|
||
{
|
||
uint8_t retryTimes = 3 ;
|
||
//EC20_SendCmdAndWaitForResp( (uint8_t*)"\r\nOpen EC20 AtEcho:", "OK", 30, (uint8_t*)EC20_CMD_OPENECHO) ;
|
||
//EC20_SendCmdAndWaitForResp( (uint8_t*)"\r\nSave Close AtEcho:", "OK", 30, (uint8_t*)EC20_SAVE_CONFIG) ;
|
||
EC20_Module_SendCmd( EC20_QUERY_CONFIG ) ;
|
||
WaitForNMilSeconds(3) ;
|
||
if( kmp(ec20ReceBuffer,"E: 0") > 0)
|
||
return (SUCCESS) ;
|
||
else
|
||
{
|
||
while( 0 < retryTimes-- )
|
||
{
|
||
if( (SUCCESS == EC20_SendCmdAndWaitForResp( (uint8_t*)"\r\nClose EC20 AtEcho:", "OK", 30, (uint8_t*)EC20_CMD_CLOSEECHO))
|
||
&&(SUCCESS == EC20_SendCmdAndWaitForResp( (uint8_t*)"\r\nQuery EC20 AtEcho:", "E: 0", 30, (uint8_t*)EC20_QUERY_CONFIG) ))
|
||
{
|
||
// EC20_SendCmdAndWaitForResp( (uint8_t*)"\r\nSave Close AtEcho:", "OK", 30, (uint8_t*)EC20_SAVE_CONFIG) ;
|
||
//为了兼容前面版本,不保存
|
||
return (SUCCESS) ;
|
||
}
|
||
}
|
||
}
|
||
return (ERROR) ;
|
||
}
|
||
|
||
char* EC20_Query_NetInfo(void)
|
||
{
|
||
uint8_t *start, *end ;
|
||
EC20_Module_SendCmd( EC20_QUERY_NETINFO ) ;
|
||
WaitForNMilSeconds(3) ;
|
||
if( strstr((const char*)ec20ReceBuffer, "+QNWINFO") )
|
||
{
|
||
start = strchr( (const char*)ec20ReceBuffer, ':' ) ;
|
||
end = strchr((const char*)start, 0x0D) ;
|
||
*end = 0x00 ;
|
||
//CopyValues(ec20ReceBuffer, start, 0x0D, 50) ;
|
||
return (start+3) ;
|
||
}
|
||
return 0 ;
|
||
}
|
||
|
||
ErrorStatus EC20_ActivateTcpPDP(void)
|
||
{
|
||
ErrorStatus status = ERROR ;
|
||
if( SUCCESS != EC20_SendCmdAndWaitForResp( (uint8_t*)"\r\nConfigure TCPContext:", "OK", 10, (uint8_t*)EC20_SET_CFGCONTEXT, ec20NetParameter.tcpContextID ) )
|
||
{
|
||
return ERROR ;
|
||
}
|
||
status = EC20_SendCmdAndWaitForResp( (uint8_t*)"\r\nActivate TcpContext:", "OK", 1500, (uint8_t*)EC20_CMD_ACTCONTEXT, ec20NetParameter.tcpContextID ) ;
|
||
if( SUCCESS == status )
|
||
{
|
||
USART_OUT( UART_LOG, "Activate TcpContextt Success!") ;
|
||
}
|
||
else if( ERROR == status ) //1500*100ms
|
||
{
|
||
USART_OUT( UART_LOG, "Activate TcpContextt Fail!") ;
|
||
return ERROR ;
|
||
}
|
||
else if( TIMEOUT == status )
|
||
{
|
||
USART_OUT( UART_LOG, "Activate TcpContextt TimeOut!") ;
|
||
return TIMEOUT ;
|
||
}
|
||
status = EC20_SendCmdAndWaitForResp((uint8_t*)"\r\nActivate TcpContext STATE:", "+QIACT: 1,1", 10 ,(uint8_t*)EC20_QUERYSTATE_CONTEXE) ;
|
||
return (status) ;
|
||
}
|
||
|
||
ErrorStatus EC20_ActivateHttpPDP(void)
|
||
{
|
||
ErrorStatus status = ERROR ;
|
||
if( SUCCESS != EC20_SendCmdAndWaitForResp( (uint8_t*)"\r\nConfigure HttpContext:", "OK", 20, (uint8_t*)EC20_SET_CFGCONTEXT, ec20NetParameter.httpContextID ) )
|
||
{
|
||
return ERROR ;
|
||
}
|
||
status = EC20_SendCmdAndWaitForResp( (uint8_t*)"\r\nActivate Context:", "OK", 1500, (uint8_t*)EC20_CMD_ACTCONTEXT, ec20NetParameter.httpContextID ) ;
|
||
if( ERROR == status ) //1500*100ms
|
||
{
|
||
USART_OUT( UART_LOG, "Activate HttpContextt Fail!") ;
|
||
return ERROR ;
|
||
}
|
||
else if( TIMEOUT == status )
|
||
{
|
||
USART_OUT( UART_LOG, "Activate HttpContextt TimeOut!") ;
|
||
return TIMEOUT ;
|
||
}
|
||
status = EC20_SendCmdAndWaitForResp((uint8_t*)"\r\nQuery HttpContext STATE:", "+QIACT: 2,1", 10 ,(uint8_t*)EC20_QUERYSTATE_CONTEXE) ;
|
||
return (status) ;
|
||
}
|
||
|
||
ErrorStatus EC20_OpenSocket( uint8_t *ipAddress, uint16_t portNum, uint8_t connectID)
|
||
{
|
||
uint8_t times = 0 ;
|
||
uint16_t index = 0 ;
|
||
ErrorStatus status = TIMEOUT ;
|
||
/*次命令回码已经超过64字节导致在strstr比对时前面会出现0X00,所以将ec20ReceBuffer空间增加到128bytes*/
|
||
EC20_SendCmdAndWaitForResp((uint8_t*)"打开Socket:", "+QIOPEN:", 200, (uint8_t*)EC20_CMD_OPENSOCKET, ec20NetParameter.tcpContextID, connectID, "TCP", ipAddress, portNum, ec20NetParameter.tcpLocalPort, 1 ) ;
|
||
if(strstr((const char*)ec20ReceBuffer, "+QIOPEN: 0,0") > 0 )
|
||
{
|
||
return (SUCCESS) ;
|
||
}
|
||
else
|
||
{
|
||
return (ERROR) ;
|
||
}
|
||
}
|
||
|
||
void EC20_Query_CSQ(uint8_t* csq)
|
||
{
|
||
uint8_t times = 0 ;
|
||
char* start ;
|
||
memset(csq, 0, CSQ_LEN+1);
|
||
EC20_Module_SendCmd( (uint8_t *)EC20_QUERY_CSQ ) ;
|
||
Wait_For_N_10ms(5) ; ;
|
||
while( times < 10 )
|
||
{
|
||
WaitForNMilSeconds(1) ;
|
||
if( strstr((const char*)ec20ReceBuffer, "+CSQ") )
|
||
{
|
||
start = strchr( (const char*)ec20ReceBuffer, ':' ) ;
|
||
//end = strcpy( ec20ReceBuffer,',' ) ;
|
||
strncpy( (char*)csq, (start+1),CSQ_LEN ) ;
|
||
break ;
|
||
}
|
||
times++ ;
|
||
}
|
||
csq[CSQ_LEN] = 0x00 ;
|
||
}
|
||
|
||
ErrorStatus EC20_Query_SimImsi(char* simIMSI)
|
||
{
|
||
uint8_t times = 0 ;
|
||
ErrorStatus result = ERROR ;
|
||
char* start ;
|
||
memset(simIMSI, 0, SIMID_LEN+1);
|
||
EC20_Module_SendCmd( (uint8_t *)EC20_QUERY_IMSI ) ;
|
||
WaitForNMilSeconds(1) ;
|
||
while( times++ < 20)
|
||
{
|
||
WaitForNMilSeconds(1) ;
|
||
if( strstr((const char*)ec20ReceBuffer, "OK") )
|
||
{
|
||
start = strrchr( (const char*)ec20ReceBuffer, 'I' ) ;
|
||
strncpy( (char*)simIMSI, (start+4),SIMID_LEN ) ;
|
||
simIMSI[SIMID_LEN] = 0x00 ;
|
||
return SUCCESS ;
|
||
}
|
||
Watchdog_Feed();
|
||
}
|
||
return result ;
|
||
}
|
||
|
||
ErrorStatus EC20_Query_SimIccid(char* simICCID)
|
||
{
|
||
uint8_t times = 0 ;
|
||
ErrorStatus result = ERROR ;
|
||
char* start ;
|
||
memset(simICCID, 0, ICCID_LEN+1);
|
||
EC20_Module_SendCmd( (uint8_t *)EC20_QUERY_ICCID ) ;
|
||
WaitForNMilSeconds(1) ;
|
||
while( times++ < 20)
|
||
{
|
||
WaitForNMilSeconds(1) ;
|
||
if( strstr((const char*)ec20ReceBuffer, "OK") )
|
||
{
|
||
start = strrchr( (const char*)ec20ReceBuffer, 'I' ) ;
|
||
CopyValues((start+4), (char*)simICCID, 0x0D, 25) ;
|
||
//strncpy( (char*)simICCID, (start+4),ICCID_LEN ) ;
|
||
simICCID[ICCID_LEN] = 0x00 ;
|
||
return SUCCESS ;
|
||
}
|
||
Watchdog_Feed();
|
||
}
|
||
return result ;
|
||
}
|
||
|
||
ErrorStatus EC20_Query_SoftRelese(char* moduleSoftVer)
|
||
{
|
||
uint8_t times = 0 ;
|
||
ErrorStatus result = ERROR ;
|
||
char* start ;
|
||
memset(moduleSoftVer, 0, EC20VERLEN+1);
|
||
EC20_Module_SendCmd( (uint8_t *)EC20_QUERY_SOFTRELEASE ) ;
|
||
WaitForNMilSeconds(1) ;
|
||
while( times++ < 3)
|
||
{
|
||
WaitForNMilSeconds(1) ;
|
||
if( strstr((const char*)ec20ReceBuffer, "OK") )
|
||
{
|
||
start = strchr( (const char*)ec20ReceBuffer, 0x0D) ;
|
||
CopyValues((start+2), (char*)moduleSoftVer, 0x0D, EC20VERLEN) ;
|
||
moduleSoftVer[EC20VERLEN] = 0x00 ;
|
||
return SUCCESS ;
|
||
}
|
||
}
|
||
return result ;
|
||
}
|
||
|
||
ErrorStatus EC20_SendData( uint8_t connectID, uint8_t* sendDataBuf, uint16_t len)
|
||
{
|
||
uint8_t times = 0, enableSendData = 0;
|
||
ErrorStatus status = ERROR;
|
||
if( len > 260 ) //强制数据长度要小于260bytes
|
||
len = 260 ;
|
||
EC20_Module_SendCmd((uint8_t*)EC20_CMD_QISEND, connectID, len);
|
||
while( times++ < 70 )
|
||
{
|
||
Wait_For_N_10ms(2) ;
|
||
Watchdog_Feed();
|
||
if( strstr((const char*)ec20ReceBuffer, ">") )
|
||
{
|
||
enableSendData = 1 ;
|
||
break ;
|
||
}
|
||
}
|
||
Uart_Print_Debug_Info( UART_LOG, (uint8_t *)"\r\nTcp Start Send Data!\r\n") ;
|
||
EC20BufferReset() ;
|
||
if( enableSendData == 1 )
|
||
{
|
||
EC20Uart_Send_Package(EC20_UART,sendDataBuf,len);
|
||
times = 0 ;
|
||
enableSendData = 0 ;
|
||
while( times < 100 ) //80*40MS左右
|
||
{
|
||
Watchdog_Feed() ;
|
||
Wait_For_N_10ms(5) ;
|
||
if( strstr( (const char*)ec20ReceBuffer, "SEND OK"))
|
||
{
|
||
status = SUCCESS ;
|
||
app.tcpFailCounter = 0 ;
|
||
Uart_Print_Debug_Info( UART_LOG, (uint8_t *)"\r\nTcp Succeed Send Data!\r\n") ;
|
||
break ;
|
||
}
|
||
else if( strstr( (const char*)ec20ReceBuffer, "ERROR"))
|
||
{
|
||
SaveLogToFlash( "EC20 ERROR Send Data!/" ) ;
|
||
Uart_Print_Debug_Info( UART_LOG, (uint8_t *)"Tcp ERROR Send Data!\r\n") ;
|
||
break ;
|
||
}
|
||
times++ ;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Uart_Print_Debug_Info( UART_LOG, (uint8_t *)"\r\nTcp No \">\" Flag!\r\n") ;
|
||
SaveLogToFlash( "EC20 No \">\" Flag!/" ) ;
|
||
Uart_Print_Debug_Info(UART_LOG, (uint8_t *)"\r\nec20RecBufferIndex is %d\r\n",ec20RecBufferIndex);
|
||
Uart_Print_Debug_Info(UART_LOG, ec20ReceBuffer);
|
||
}
|
||
if((status == ERROR)&&(connectID == 0)) //只对出入口功能的socket进行维护,诱导牌socket不维护
|
||
{
|
||
app.tcpFailCounter++ ;
|
||
if( (app.tcpFailCounter != 0)&&(app.tcpFailCounter != 1 ))
|
||
{
|
||
app.tcpFailCounter = 0 ;
|
||
SetTcpNetState(&app, DISCONNECT ); //表示数据发送失败,服务器socket关闭了
|
||
}
|
||
Uart_Print_Debug_Info( UART_LOG, (uint8_t *)"\r\nec20RecBufferIndex is %d 4G Fail Send Data!\r\n",ec20RecBufferIndex) ;
|
||
Uart_Print_Debug_Info(UART_LOG,ec20ReceBuffer);
|
||
}
|
||
if( connectID == 0)
|
||
{
|
||
EC20HasSendData = 1 ;//标志EC20已经发送过数据了,影响心跳包发送
|
||
}
|
||
return (status) ;
|
||
}
|
||
|
||
void EC20Uart_Send_Package(USART_TypeDef* USARTx, const uint8_t *Data, uint16_t len)
|
||
{
|
||
uint16_t index = 0;
|
||
const uint8_t *pos = Data;
|
||
for(index = 0; index < len; index++)
|
||
{
|
||
USART_SendData(USARTx, *(pos+index));
|
||
while(USART_GetFlagStatus(USARTx, USART_FLAG_TC)==RESET);
|
||
}
|
||
}
|
||
|
||
ErrorStatus EC20_QueryCsServiceStatus(void)
|
||
{
|
||
uint8_t times = 0 ;
|
||
int index = 0 ;
|
||
ErrorStatus result = ERROR ;
|
||
EC20_SendCmdAndWaitForResp( (uint8_t*)"\r\nSet CSsever:", "OK", 2, (uint8_t*)EC20_SET_CSSERVICE );
|
||
while( times < 30 )
|
||
{
|
||
EC20_Module_SendCmd( (uint8_t *)EC20_QUERY_CSSERVICE ) ;
|
||
WaitForNSeconds(3) ;
|
||
index = kmp(ec20ReceBuffer,(const uint8_t *)"+CREG:") ;
|
||
if( (index > 0)&&( (ec20ReceBuffer[index+9] == 0x31)||( ec20ReceBuffer[index+9] == 0x35) ) )
|
||
{
|
||
result = SUCCESS ;
|
||
USART_OUT(USART1,(uint8_t*)"\r\nReg CS Succeed!") ;
|
||
return (result) ;
|
||
}
|
||
times++ ;
|
||
}
|
||
return (result) ;
|
||
}
|
||
|
||
ErrorStatus EC20_QueryPsServiceStatus(void)
|
||
{
|
||
uint8_t times = 0 ;
|
||
ErrorStatus result = ERROR ;
|
||
int index = 0 ;
|
||
EC20_SendCmdAndWaitForResp((uint8_t*)"\r\nSet PSsever:", "OK", 2, (uint8_t*)EC20_SET_PSSERVICE);
|
||
while( times++ < 20 )
|
||
{
|
||
EC20_Module_SendCmd( (uint8_t *)EC20_QUERY_PSSERVICE ) ;
|
||
WaitForNSeconds(3) ;
|
||
index = kmp(ec20ReceBuffer,(const uint8_t *)"+CGREG:") ;
|
||
if( (index > 0)&&(( ec20ReceBuffer[index+10] == 0x31)||( ec20ReceBuffer[index+10] == 0x35) ))
|
||
{
|
||
result = SUCCESS ;
|
||
USART_OUT(USART1,(uint8_t*)"\r\nReg PS Succeed!") ;
|
||
return (result) ;
|
||
}
|
||
}
|
||
Uart_Print_Debug_Info(USART1,(uint8_t*)"\r\nReg PS Fail!") ;
|
||
return (result) ;
|
||
}
|
||
|
||
ErrorStatus EC20_Module_Init( void )
|
||
{
|
||
ErrorStatus result = ERROR ;
|
||
EC20_Net_Init() ;
|
||
#if defined APP0_CODE
|
||
uint8_t screenBufICCID[ICCID_LEN+11] = {0};
|
||
EC20_GPIO_Init() ;
|
||
EC20_POWON() ;
|
||
DisplaySystemInfo("握手中:") ;
|
||
if( SUCCESS != EC20_Handshake() )
|
||
{
|
||
DisplaySystemStatus("请检查模块安装") ;
|
||
return ERROR ;
|
||
}
|
||
if( SUCCESS == EC20_Query_SimIccid((char*)app.simICCID) ) //获取SIMID
|
||
{
|
||
snprintf(screenBufICCID, ICCID_LEN+10, "SIM ICCID:%s", app.simICCID) ;
|
||
DisplaySystemStatus(screenBufICCID) ;
|
||
USART_OUT(UART_LOG, screenBufICCID ) ;
|
||
}
|
||
else
|
||
{
|
||
USART_OUT( UART_LOG, "获取SIM卡号失败!") ;
|
||
}
|
||
USART_OUT(UART_LOG, "\r\n") ;
|
||
#endif
|
||
if( SUCCESS != EC20_CloseEcho())
|
||
{
|
||
DisplaySystemStatus("关闭回显错误") ;
|
||
WaitForNSeconds(3) ;
|
||
EC20_POWOFF() ;
|
||
SystemSoftReset() ;
|
||
}
|
||
if( SUCCESS == EC20_Query_SoftRelese((char *)app.ec20SoftVer) )
|
||
{
|
||
USART_OUT(UART_LOG, (uint8_t *)"EC20 Module SoftVersion:%s", app.ec20SoftVer ) ;
|
||
}
|
||
else
|
||
{
|
||
USART_OUT(UART_LOG, (uint8_t *)"EC20 Query Module SoftVersion Failed" ) ;
|
||
}
|
||
return (SUCCESS) ;
|
||
}
|
||
|
||
ErrorStatus EC20_TCPInit( void )
|
||
{
|
||
ErrorStatus result = SUCCESS ;
|
||
uint8_t times = 0 , screenBufCsq[13] = {0};
|
||
#if defined APP0_CODE
|
||
DisplaySystemInfo("入网中:") ;
|
||
EC20_QueryCsServiceStatus() ;
|
||
EC20_QueryPsServiceStatus() ;
|
||
if( SUCCESS != EC20_ActivateTcpPDP() )
|
||
{
|
||
if( SUCCESS == EC20_SendCmdAndWaitForResp((uint8_t*)"\r\nDeactive TcpContext:", "OK", 20, (uint8_t*)EC20_CMD_DEACTCONTEXT, ec20NetParameter.tcpContextID ) )
|
||
{
|
||
WaitForNSeconds(1) ;
|
||
if( SUCCESS != EC20_ActivateTcpPDP() )
|
||
{
|
||
SaveLogToFlash("TCP Restart ActPDP Failed!/") ;
|
||
EC20_POWOFF() ;
|
||
SystemSoftReset() ;
|
||
return ERROR ;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
SaveLogToFlash("TCP Restart DeactPDP Failed!/") ;
|
||
DisplaySystemStatus("请检查SIM卡资费,天线安装") ;
|
||
EC20_POWOFF() ;
|
||
SystemSoftReset() ;
|
||
return ERROR ;
|
||
}
|
||
}
|
||
DisplaySystemStatus("SIM卡OK") ;
|
||
#endif
|
||
DisplaySystemInfo("连接中:") ;
|
||
|
||
for( int i = 0; i<SEVER1_PORT_SUM; i++ )
|
||
{
|
||
result = ERROR ;
|
||
EC20_SendCmdAndWaitForResp((uint8_t*)"\r\nClose Socket:", "OK", 100, (uint8_t*)EC20_CMD_CLOSESOCKET, ec20NetParameter.tcpConnectID0) ; //关闭主服务器Socket
|
||
result = EC20_OpenSocket(app.server1IpAddress, app.server1PortNum[i], ec20NetParameter.tcpConnectID0) ; //打开备用服务器Socket server2PortNum[n]
|
||
if( result == SUCCESS )
|
||
{
|
||
break ;
|
||
}
|
||
else //if( ERROR == result)
|
||
{
|
||
Uart_Print_Debug_Info( UART_LOG, "%s %d", "接入主服务器失败:", i ) ;
|
||
}
|
||
}
|
||
|
||
if( SUCCESS == result) //打开主服务器Socket成功
|
||
{
|
||
DisplaySystemStatus("接入主服") ;
|
||
}
|
||
else //if(ERROR == result)
|
||
{
|
||
result = ERROR ;
|
||
SaveLogToFlash("Open Server1 Socket Error!/") ;
|
||
for( int n = 0; n<SEVER2_PORT_SUM; n++ )
|
||
{
|
||
EC20_SendCmdAndWaitForResp((uint8_t*)"\r\nClose Socket:", "OK", 100, (uint8_t*)EC20_CMD_CLOSESOCKET, ec20NetParameter.tcpConnectID0) ; //关闭主服务器Socket
|
||
result = EC20_OpenSocket(app.server2IpAddress, app.server2PortNum[n], ec20NetParameter.tcpConnectID0) ; //打开备用服务器Socket server2PortNum[n]
|
||
if( result == SUCCESS )
|
||
{
|
||
DisplaySystemStatus("接入备服") ;
|
||
break ;
|
||
}
|
||
else
|
||
{
|
||
Uart_Print_Debug_Info( UART_LOG, "%s %d", "接入备用服务器失败:", n ) ;
|
||
}
|
||
}
|
||
}
|
||
|
||
if( SUCCESS != result )
|
||
{
|
||
SaveLogToFlash("TCP Open Socket Timeout!/") ;
|
||
DisplaySystemStatus("请检查服务器") ;
|
||
EC20_POWOFF() ;
|
||
SystemSoftReset() ;
|
||
}
|
||
|
||
EC20_OpenSocket(app.server1IpAddress, app.server1GuidePortNum, ec20NetParameter.tcpConnectID1) ; //打开诱导系统Socket
|
||
EC20_Query_CSQ( app.csq ) ;
|
||
snprintf( screenBufCsq, 12, "LTE CSQ:%s",app.csq) ;
|
||
DisplaySystemStatus(screenBufCsq) ;
|
||
USART_OUT(UART_LOG, screenBufCsq) ;
|
||
return (result) ;
|
||
}
|
||
|
||
ErrorStatus EC20_HTTPInit( void )
|
||
{
|
||
uint8_t failTimes = 0 ;
|
||
ErrorStatus status = ERROR ;
|
||
while( failTimes++ < 3 )
|
||
{
|
||
if( SUCCESS != EC20_SendCmdAndWaitForResp((uint8_t*)"\r\nSet HttpContextID:", "OK", 20, (uint8_t*)EC20_SET_HTTPCONTEXT, ec20NetParameter.httpContextID ))
|
||
continue ;
|
||
if( SUCCESS != EC20_SendCmdAndWaitForResp((uint8_t*)"\r\nSet HttpSetReqHeader:", "OK", 20, (uint8_t*)EC20_SET_HTTPREQHEADER ))
|
||
continue ;
|
||
if( SUCCESS != EC20_SendCmdAndWaitForResp((uint8_t*)"\r\nSet HttpSetResHeader:", "OK", 10, (uint8_t*)EC20_SET_HTTPRESHEADER ))
|
||
continue ;
|
||
if( kmp(app.ec20SoftVer, (const uint8_t *)"EC20CEFDKGR06A05M2G") >= 0 ) //EC20该版本需要增加下面指令
|
||
{
|
||
if( SUCCESS != EC20_SendCmdAndWaitForResp( (uint8_t*)"\r\nSet Http WaitTime:", "OK", 2, (uint8_t*)EC20_SET_HTTPCLOSETIME) )
|
||
continue ;
|
||
}
|
||
if( failTimes >= 2 )
|
||
return ERROR ;
|
||
else
|
||
break ;
|
||
}
|
||
//EC20_SendCmdAndWaitForResp((uint8_t*)"\r\nDeactive HttpContext:", "OK", 10, (uint8_t*)EC20_CMD_DEACTCONTEXT, ec20NetParameter.httpContextID ) ;
|
||
if( SUCCESS != EC20_ActivateHttpPDP() )
|
||
{
|
||
if( SUCCESS == EC20_SendCmdAndWaitForResp((uint8_t*)"\r\nDeactive HttpContext:", "OK", 10, (uint8_t*)EC20_CMD_DEACTCONTEXT, ec20NetParameter.httpContextID ) )
|
||
{
|
||
WaitForNSeconds(1) ;
|
||
if( SUCCESS != EC20_ActivateHttpPDP() )
|
||
{
|
||
SaveLogToFlash("HTTP ActPDP Failed!/") ;
|
||
EC20_ShutDown() ;
|
||
SystemSoftReset() ;
|
||
return ERROR ;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
SaveLogToFlash("HTTP DeactPDP Failed!/") ;
|
||
DisplaySystemStatus("请检查SIM卡资费,天线安装") ;
|
||
EC20_ShutDown() ;
|
||
SystemSoftReset() ;
|
||
return ERROR ;
|
||
}
|
||
}
|
||
failTimes = 0 ;
|
||
while( failTimes++ < 2 )
|
||
{
|
||
status = EC20_SendCmdAndWaitForResp((uint8_t *)"\r\nSet Post Url:", "CONNECT", 80, (uint8_t*)EC20_CMD_HTTPURL,32 ) ;
|
||
if( SUCCESS == status )
|
||
{
|
||
status = EC20_SendCmdAndWaitForResp((uint8_t*)"\r\nHttpURL:", "OK", 50, (uint8_t*)CARNUM_HTTPPOST_URL) ;
|
||
if( SUCCESS == status )
|
||
{
|
||
Uart_Print_Debug_Info( UART_LOG, (uint8_t *)"\r\nSet Post Url Succeed!") ;
|
||
break ;
|
||
}
|
||
}
|
||
WaitForNSeconds(1) ;
|
||
}
|
||
return status ;
|
||
}
|
||
|
||
ErrorStatus EC20_CarNumPostRequest( bool lacalCar, const uint8_t *carNum, const uint8_t carNumType )
|
||
{
|
||
uint8_t timeOut = 0, carType[6] = {0} ;
|
||
char *postPos ;
|
||
ErrorStatus status = ERROR ;
|
||
uint16_t requestLen = 238 ; //Heard+Body的总长度,0X0D 0X0A也算在内
|
||
uint8_t bodyLen = 62, addLen = 0 ;
|
||
uint8_t macAddress24Bytes[25] = {0} ;
|
||
if( carNumType == 0x02 ) strncpy( carType, "true" , 4) ; //面包车
|
||
else strncpy( carType, "false" , 5) ; //其余车辆作为小车处理
|
||
GetDeviceMacAddress(macAddress24Bytes, 24) ; macAddress24Bytes[24] = 0x00 ;
|
||
addLen = strlen(carNum) + strlen(carType) ;
|
||
requestLen = requestLen + addLen ;
|
||
bodyLen = bodyLen + addLen ;
|
||
if( lacalCar == true ) //本地包月车请求
|
||
{
|
||
requestLen += 9 ;
|
||
}
|
||
status = EC20_SendCmdAndWaitForResp((uint8_t *)"\r\n Start Send PostReq:", "CONNECT", 40, (uint8_t*)EC20_CMD_HTTPPOSTLEN, requestLen) ;
|
||
if( SUCCESS == status)
|
||
{
|
||
if( lacalCar == false ) //非本地包月车请求
|
||
{
|
||
status = EC20_SendCmdAndWaitForResp((uint8_t *)"\r\nSend Post Json:", "+QHTTPPOST: 0,200", 80, (uint8_t*)CARNUM_HTTPPOST_HEADERBODY, bodyLen, carNum, macAddress24Bytes, carType ) ;
|
||
}
|
||
else //本地包月车请求
|
||
{
|
||
status = EC20_SendCmdAndWaitForResp((uint8_t *)"\r\nSend Post Json:", "+QHTTPPOST: 0,200", 80, (uint8_t*)LOCALCARNUM_HTTPPOST_HEADERBODY, bodyLen, carNum, macAddress24Bytes, carType ) ;
|
||
}
|
||
|
||
if( SUCCESS == status )
|
||
{
|
||
return SUCCESS ;
|
||
}
|
||
else
|
||
{
|
||
return (status) ;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Uart_Print_Debug_Info( UART_LOG, (uint8_t *)"\r\nFailed Send PostReq!") ;
|
||
return (status) ;
|
||
}
|
||
}
|
||
|
||
ErrorStatus EC20_MonthUserPostRequest(void)
|
||
{
|
||
uint8_t timeOut = 0 ;
|
||
char *postPos ;
|
||
ErrorStatus status = ERROR ;
|
||
uint8_t n = 0 ;
|
||
uint8_t groupCounter[2] = {0} ;
|
||
monthUserInfo.carNumAddr = VIP_FLASH_CARNUM_ADDR ;
|
||
monthUserInfo.flashOffset = 0 ;
|
||
memset(monthUserInfo.carNumBuf, 0, CARNUMBUFLEN*20) ;
|
||
uint8_t macAddress24Bytes[25] = {0} ;
|
||
GetDeviceMacAddress(macAddress24Bytes, 24) ; macAddress24Bytes[24] = 0x00 ;
|
||
|
||
if( SUCCESS == EC20_SendCmdAndWaitForResp((uint8_t *)"\r\n Start Send PostReq:", "CONNECT", 40, (uint8_t*)EC20_CMD_HTTPPOSTLEN, 215))
|
||
{
|
||
status = EC20_SendCmdAndWaitForResp((uint8_t *)"\r\nSend Post Json:", "+QHTTPPOST: 0,200", 80, (uint8_t*)MONTHUSERSUM_HTTPPOST_HEADERBODY, macAddress24Bytes ) ;
|
||
if( SUCCESS == status )
|
||
{
|
||
WaitForNSeconds(1) ;
|
||
if( SUCCESS == EC20_PostReadData())
|
||
{
|
||
postPos = strstr(userDataReceBuffer, "body") ;
|
||
CopyValues((postPos+6), groupCounter,'.', 2);
|
||
monthUserInfo.groupSum = atoi(groupCounter) ;
|
||
if( monthUserInfo.groupSum > 20) //最多20*200=4000bytes 堆大小需要大于4K
|
||
{
|
||
monthUserInfo.groupSum = 20 ;
|
||
UpDataToTcpSrver(WARNINGFRAME, (const char*)"MonthUser:", (uint8_t *)"Sum Overflow!") ;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Uart_Print_Debug_Info( UART_LOG, (uint8_t *)"\r\nReq MonthUser Sum Failed!") ;
|
||
SaveLogToFlash("Req MonthUser Sum Failed!!/") ;
|
||
return (ERROR) ;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Uart_Print_Debug_Info( UART_LOG, (uint8_t *)"\r\nnRead MonthUser Sum Failed!") ;
|
||
SaveLogToFlash("nRead MonthUser Sum Failed!!/") ;
|
||
return (status) ;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Uart_Print_Debug_Info( UART_LOG, (uint8_t *)"\r\nReq MonthUser Sum Failed!") ;
|
||
SaveLogToFlash("Req MonthUser Sum Failed!!/") ;
|
||
return ERROR ;
|
||
}
|
||
|
||
for( n = 0; n<=monthUserInfo.groupSum; n++)
|
||
{
|
||
if( SUCCESS == EC20_SendCmdAndWaitForResp((uint8_t *)"\r\n Start Send PostReq:", "CONNECT", 40, (uint8_t*)EC20_CMD_HTTPPOSTLEN, 223))
|
||
{
|
||
status = EC20_SendCmdAndWaitForResp((uint8_t *)"\r\nSend Post Json:", "+QHTTPPOST: 0,200", 60, (uint8_t*)MONTHUSERLIST_HTTPPOST_HEADERBODY, macAddress24Bytes, n ) ;
|
||
if( SUCCESS == status )
|
||
{
|
||
WaitForNSeconds(1) ;
|
||
if( SUCCESS == EC20_PostReadData())
|
||
{
|
||
postPos = strstr(userDataReceBuffer, "body") ;
|
||
CopyValues((postPos+7), monthUserInfo.carNumBuf+monthUserInfo.flashOffset,',', CARNUMBUFLEN-1);
|
||
monthUserInfo.flashOffset = strlen( monthUserInfo.carNumBuf) ;
|
||
//monthUserInfo.flashOffset = monthUserInfo.flashOffset+strlen( monthUserInfo.carNumBuf ) ;
|
||
}
|
||
else
|
||
{
|
||
Uart_Print_Debug_Info( UART_LOG, (uint8_t *)"\r\nRead MonthUser CarNum Failed!") ;
|
||
SaveLogToFlash("Read MonthUser CarNum Failed!!/") ;
|
||
return (ERROR) ;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Uart_Print_Debug_Info( UART_LOG, (uint8_t *)"\r\nReq MonthUser CarNum Failed!") ;
|
||
SaveLogToFlash("Req MonthUser CarNum Failed!!/") ;
|
||
return (status) ;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Uart_Print_Debug_Info( UART_LOG, (uint8_t *)"\r\nReq MonthUser CarNum Failed!") ;
|
||
SaveLogToFlash("Req MonthUser CarNum Failed!!/") ;
|
||
return (ERROR) ;
|
||
}
|
||
}
|
||
FLASH_ErasePage( monthUserInfo.carNumAddr ) ;
|
||
FLASH_ErasePage( monthUserInfo.carNumAddr + 2048) ; //擦除相邻两页 一共4K存储包月车牌空间
|
||
Save_to_Flash( monthUserInfo.carNumAddr, monthUserInfo.carNumBuf, monthUserInfo.flashOffset) ;
|
||
FLASH_Lock() ;
|
||
UpDataToTcpSrver( LOGFRAME, "MonthUser:", (uint8_t*)"本地包月车同步成功" ) ;
|
||
return (SUCCESS) ;
|
||
}
|
||
|
||
ErrorStatus EC20_RegPostRequest(void)
|
||
{
|
||
uint8_t times = 0, timeOut = 0 ;
|
||
ErrorStatus status = ERROR ;
|
||
uint16_t requestLen = 191 ; //Heard+Body的总长度,0X0D 0X0A也算在内
|
||
uint8_t bodyLen = 10, addlen = 0 ;
|
||
uint8_t macAddress24Bytes[25] = {0} ;
|
||
char *postPos ;
|
||
GetDeviceMacAddress(macAddress24Bytes, 24) ;
|
||
macAddress24Bytes[24] = 0x00 ;
|
||
addlen = strlen(macAddress24Bytes) ;
|
||
requestLen = requestLen + addlen ;
|
||
bodyLen = bodyLen + addlen ;
|
||
status = EC20_SendCmdAndWaitForResp("\r\n Start Send PostReq:", "CONNECT", 40, (uint8_t*)EC20_CMD_HTTPPOSTLEN, requestLen) ;
|
||
if( SUCCESS == status )
|
||
{
|
||
status = EC20_SendCmdAndWaitForResp("\r\nSend Post Req:", "+QHTTPPOST: 0,200", 70, (uint8_t*)REG_HTTPPOST_HEADERBODY, bodyLen, macAddress24Bytes ) ;
|
||
if( SUCCESS == status)
|
||
{
|
||
return SUCCESS ;
|
||
}
|
||
else
|
||
{
|
||
return (status) ;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Uart_Print_Debug_Info( UART_LOG, (uint8_t *)"\r\nFailed Send PostReq!") ;
|
||
return (status) ;
|
||
}
|
||
}
|
||
|
||
ErrorStatus EC20_PostReadData( void )
|
||
{
|
||
uint8_t timeOut = 0 ;
|
||
ErrorStatus status = TIMEOUT ;
|
||
SetEC20WorkMode( &app, USER_MODE ) ;
|
||
UserDataBufferReset() ;
|
||
serveReturnSucceedFlag = 0x00 ;
|
||
EC20_Module_SendCmd((uint8_t*)EC20_QUERY_HTTPPOSTDATA);
|
||
for( timeOut = 0; timeOut < 70; timeOut++ ) //入口实际160MS--720MS之间;出口1920ms,根据网路情况
|
||
{
|
||
if( serveReturnSucceedFlag == 0x01 )
|
||
{
|
||
serveReturnSucceedFlag = 0x00 ;
|
||
status = SUCCESS ;
|
||
break ;
|
||
}
|
||
Wait_For_N_10ms(2) ;
|
||
Watchdog_Feed();
|
||
}
|
||
SetEC20WorkMode( &app, AT_MODE ) ;
|
||
return status ;
|
||
}
|
||
|
||
/**************************************************************************
|
||
EC20初始化流程:
|
||
1、IO初始化。
|
||
2、4G模块上电。等待上电完成,统计上电时间。 最多20S 。
|
||
3、网络参数初始化。
|
||
4、显示屏显示“设备入网中<EFBFBD> ”。
|
||
5、MCU与4G模块 AT握手,返回是否成功。
|
||
6、获取SIM卡状态,返回结果。
|
||
7、获取网络状态。
|
||
8、开启RF 。
|
||
9、获取CS Sever状态,返回结果。
|
||
10、获取PS Sever状态,返回结果。
|
||
*********************************************************************************/
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|