做了个物联网项目,需要做个OTA升级,程序分为两部分,一部分是BOOT引导程序,一部是主程序,在BOOT引导程序里面实现了和EC200 4G模块通讯,和FTP服务器通讯,获取OTA升级BIN文件。主程序里有和服务器通讯并获取服务器下发的OTA升级指令功能。
记录了STM32F0系统单片机 BOOT引导程序通过4G模块进行OTA升级的实操过程 ?
使用EC200 4G物联网模块,使用MD5算法校验OTA升级文件正确性。BOOT实现了FTP服务器OTA bin文件获取,跳转APP主程序的功能。
硬件环境 | STM32F091CBT6 J-LINK? V11 |
软件开发环境 | IAR 8.32.1? VSCODE? STM32 CUBE |
软件支持包 | ST HAL库 |
4G模块???????? | EC200N-CN |
BOOT程序读取EEPROM芯片中存储的OTA结构体变量信息。
需要OTA的话,则连接OTA信息结构体中读取FTP服务器URL和用户名和密码
访问FTP服务器,读取升级BIN文件到本地EEPROM,然后计算MD5值,判断MD5值是否和OTA信息结构体中的一样,如果一样则将BIN文件写入到STM32内部FLASH中,然后执行IAP跳转,程序跳转到主程序执行。
OTA信息包是在主程序中,由服务器下发给单片机的,校验后存储在EEPROM芯片中
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2023 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "dma.h"
#include "iwdg.h"
#include "usart.h"
#include "gpio.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "stm32f0xx_hal.h"
#include "EC200N.h"
// #include "RN8302_Drv.h"
// #include "SEGGER_RTT.h"
// #include "CloudDataProtocol.h"
#include "publics.h"
#include "data.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
uint16_t g_u16_CMD = 0xff;
float g_f_tempvalue = 30.0f;
float g_f_test = 220.0f;
uint8_t gu8_Sta =0;
uint8_t gu8_temp=0;
uint8_t gu8_index=0;
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_IWDG_Init();
MX_USART1_UART_Init();
MX_USART4_UART_Init();
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
//HAL_GPIO_WritePin(GPIOB,MCU_RST_8302B_Pin,GPIO_PIN_RESET);
HAL_GPIO_WritePin(RESET_4G_GPIO_Port,RESET_4G_Pin,GPIO_PIN_RESET);
HAL_GPIO_WritePin(POWERKEY_4G_GPIO_Port,POWERKEY_4G_Pin,GPIO_PIN_RESET);
HAL_GPIO_WritePin(POWERKEY_4G_GPIO_Port,POWERKEY_4G_Pin,GPIO_PIN_SET);
HAL_Delay(500);
MX_FEED_IWDG();
HAL_Delay(500);
MX_FEED_IWDG();
HAL_Delay(500);
MX_FEED_IWDG();
HAL_Delay(500);
MX_FEED_IWDG();
SEGGER_RTT_Init();
Sys_BaseTimeInit();
DEBUG_printf(DEBUG_UART,"BOOT starting\r\n");
DEBUG_printf(DEBUG_UART,"BOOT read stBoot2\r\n");
DEBUG_printf(DEBUG_UART,"BOOT _SystemParameters_TypeDef size = %d\r\n",sizeof(_SystemParameters_TypeDef));
DEBUG_printf(DEBUG_UART,"BOOT _MTRInitParmType_Def size = %d\r\n",sizeof(_MTRInitParmType_Def));
DEBUG_printf(DEBUG_UART,"BOOT _Boot2StatusType_Def size = %d\r\n",sizeof(_Boot2StatusType_Def));
// gs_TCPRecInfoOTA.u16_FLG = M_SYS_OTA_FLA;
// FRAM_Write(Sys_OTAParmAddr,&gs_TCPRecInfoOTA,sizeof(_TcpRecvCMDInfo_OTA));
FRAM_Read(&stBoot2, Sys_BOOT2ParmAddr, sizeof(_Boot2StatusType_Def));
FRAM_Read(&stBoot2_temp, Sys_BOOT2ParmAddr, sizeof(_Boot2StatusType_Def));
gu8_Sta = F_CMP_DATA(&stBoot2,&stBoot2_temp,sizeof(_Boot2StatusType_Def));
if( SUCCESS!=gu8_Sta)
{
DEBUG_printf(DEBUG_UART,"BOOT stBoot2 != stBoot2_temp \r\n");
}
if( M_SYS_OTA_FLA == stBoot2.u16_FLG)
{
DEBUG_printf(DEBUG_UART,"BOOT stBoot2 u16_FLG %x\r\n",stBoot2.u16_FLG);
DEBUG_printf(DEBUG_UART,"BOOT stBoot2 is valid\r\n");
DEBUG_printf(DEBUG_UART,"BOOT stBoot2 FilePath %s\r\n",stBoot2.FilePath);
DEBUG_printf(DEBUG_UART,"BOOT stBoot2 ServerDMN %s\r\n",stBoot2.ServerDMN);
DEBUG_printf(DEBUG_UART,"BOOT stBoot2 FileName %s\r\n",stBoot2.FileName);
DEBUG_printf(DEBUG_UART,"BOOT stBoot2 UserName %s\r\n",stBoot2.UserName);
DEBUG_printf(DEBUG_UART,"BOOT stBoot2 PassWord %s\r\n",stBoot2.PassWord);
DEBUG_printf(DEBUG_UART,"BOOT stBoot2 Md5Value %s\r\n",stBoot2.Md5Value);
// DEBUG_printf(DEBUG_UART,"BOOT stBoot2 u16_OTA_URL_LEN %d\r\n",gs_TCPRecInfoOTA.u16_OTA_URL_LEN);
// DEBUG_printf(DEBUG_UART,"BOOT stBoot2 ucA_OTA_URL %s\r\n",gs_TCPRecInfoOTA.ucA_OTA_URL);
// DEBUG_printf(DEBUG_UART,"BOOT stBoot2 u16_OTA_MD5_LEN %d\r\n",gs_TCPRecInfoOTA.u16_OTA_URL_LEN);
// DEBUG_printf(DEBUG_UART,"BOOT stBoot2 ucA_FILE_MD5 %s\r\n",gs_TCPRecInfoOTA.ucA_FILE_MD5);
APP_EC20Link_Init();
gs_DecCmd.SysCmd = M_OTA_NEED_UP;
}
else
{
DEBUG_printf(DEBUG_UART,"BOOT stBoot2 u16_FLG %x\r\n",stBoot2.u16_FLG);
DEBUG_printf(DEBUG_UART,"BOOT stBoot2 is invalid\r\n");
gs_DecCmd.SysCmd = M_OTA_JUMP;
}
//QUEUE_StructCreate(&UpMachComCmdQue,(uint8_t *)UpMachComBuffer,sizeof(UpMachComBuffer),sizeof(_UpComCmdDataPacket));
// F_DataSYNInit();
// ReadRn8002CalREGData();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
//HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 2);//huart1��?������������?�?
Sys_BaseTimeUpdate();
if(gu8_debug)
{
MX_FEED_IWDG();
}
if( g_SysBaseTime.f200ms ==1 )
{
HAL_GPIO_TogglePin(GPIOB,LED_PCB_Pin);
//(DEBUG_RTT,"DEBUG_printf %d\r\n",Sys_GetSec());
}
if( M_OTA_NEED_UP == gs_DecCmd.SysCmd)
{
if( g_SysBaseTime.f200ms ==1 )
{
F_EC200N_RecvDatStaHandle(&g_u16_EC20CMD,&g_u16_EC20_STA);
F_APP_EC200N(&g_u16_EC20CMD,&g_u16_EC20_STA);
}
}
else if( M_OTA_JUMP == gs_DecCmd.SysCmd)
{
APP_UpGrade_JumpOut();
}
else
{
}
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL4;
RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
{
Error_Handler();
}
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_USART2;
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1;
PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
}
/* USER CODE BEGIN 4 */
int fputc(int ch, FILE *f)
{
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 2);//huart1
return ch;
}
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
#include "Upgrade.h"
_IapFunc_Def Jump2Sector;
/******************************************************************************
* Name : APP_UpGrade_JumpOut
* brief : This function is used to quit the boot.
* param : None
* retval : BSP status
*******************************************************************************/
FuncState APP_UpGrade_JumpOut(void)
{
FuncState ret = FAIL;
static uint32_t u32UPDTiming = 0;
// if((TRUE == stUPDJumpFlag)
// && (TRUE == InitFlag)
// && (0 == stBoot.UPD_ATRB.ErrCode)
// &&((1 == u8WifiUpdataInit)
// ||(0xff == u8WifiUpdataInit))
// &&(1 == g_u8SendFlag)
// )
{
u32UPDTiming++;
if(UPGRADE_REBOOT_CNTDOWN <= u32UPDTiming)
{
//APP_UpGrade_StartUpBeep(0x000FFFFF);
//BSP_DeInit();
BSP_UART_DeInit();
MX_FEED_IWDG();
/* 屏蔽所有中断,防止在跳转过程中,中断干扰出现异常 */
__disable_irq();
Jump2Sector = (_IapFunc_Def)*(uint32_t*)(APP_ADDR + 4);
__set_MSP(*(__IO uint32_t*)(APP_ADDR));
Jump2Sector();
while(1)
{
u32UPDTiming++;
}
}
}
// else
// {
// u32UPDTiming = 0;
// }
return ret;
}
#ifndef _UPGRADE_H_
#define _UPGRADE_H_
//#include "data.h"
#include "publics.h"
#define UPGRADE_REBOOT_CNTDOWN 200
typedef void(*_IapFunc_Def)(void);
FuncState APP_UpGrade_JumpOut(void);
#endif
#include "publics.h"
//#include "EC200N.H"
#include "usart.h"
#include "iwdg.h"
static ValueState st_EC20RecvCmd;
static ValueState st_EC20RestCmd;
static ValueState st_EC20DownloadCmd;
static uint32_t m_u8_EC20SendLenth;
static uint32_t m_u8_EC20RecvLenth;
_ProcVariableAllType_Def st_EC20LinkVar;
uint16_t gu16_SendLen =0;
char Sendbuf[EC20_SEND_BUFF_SIZE];
//uint8_t RecvBuf[EC20_SEND_BUFF_SIZE];
uint32_t g32_NowSec = 0;
uint32_t g32_LastSec = 0;
uint32_t g32_DiffSec = 0;
_TcpRecvCMDInfo_OTA gs_TCPRecInfoOTA;
_Boot2StatusType_Def stBoot2;
_Boot2StatusType_Def stBoot2_temp;
ErrorStatus F_OpenEC200N(void)
{
//GPIO操作
return 0;
}
// char PalodTest[50] ="{"type":"variant_data","version":"1.0","time":1638766638000,"params":{"Reg1":19.5}}";
// ErrorStatus F_TestEC200N(uint8_t *cmd)
// {
// // scanf("%s",buf);
// uint8_t lu8_cmd =0;
// lu8_cmd = (uint8_t)(*cmd);
// memset(&Sendbuf[0],0x00,sizeof(Sendbuf));
// // sprintf((char*)&Sendbuf[0],"%s\r\n","AT+CPIN?");
// switch (lu8_cmd)
// {
// case 0:
// return 1;
// break;
// case 1:
// /* code */
// sprintf((char*)&Sendbuf[0],"%s\r\n","AT");
// break;
// case 2:
// /* code */
// sprintf((char*)&Sendbuf[0],"%s\r\n","ATI");
// break;
// case 3://查询SIM卡
// /* code */
// sprintf((char*)&Sendbuf[0],"%s\r\n","AT+CPIN?");
// break;
// case 4://查询信号,31最大,小于10证明信号超级不好
// /* code */
// sprintf((char*)&Sendbuf[0],"%s\r\n","AT+CSQ");
// break;
// case 5://查询PS注册情况,注册则返回1,证明获取IP,可以进行网络使用啦
// /* code */
// sprintf((char*)&Sendbuf[0],"%s\r\n","AT+CGREG?");
// break;
// case 6://附着网络是否成功
// /* code */
// sprintf((char*)&Sendbuf[0],"%s\r\n","AT+CGATT?");
// break;
// case 7://设置数据格式
// /* code */
// sprintf((char*)&Sendbuf[0],"%s\r\n","AT+QMTCFG=\"recv/mode\",0,0,1");
// break;
// case 8://打开工业物联网云端口
// /* code */
// sprintf((char*)&Sendbuf[0],"%s\r\n","AT+QMTOPEN=0,\"www.sukon-cloud.com\",9006");
// break;
// case 9://这步执行成功后,设备应该在线了。
// /* code */
// sprintf((char*)&Sendbuf[0],"%s\r\n","AT+QMTCONN=0,\"SMETTest\",\"SMETTest\",\"123456\"");
// break;
// case 10://发送数据命令
// /* code */
// sprintf((char*)&Sendbuf[0],"%s\r\n","AT+QMTPUBEX=0,0,0,0,\"sys/device/SMETTest/variant_data\",85");
// gu16_SendLen = strlen(Sendbuf);
// MX_FEED_IWDG();
// HAL_UART_Transmit(&hUART_4G, (uint8_t *)&Sendbuf,61, 0xffff);//huart1需要根据你的配置修改
// MX_FEED_IWDG();
// MX_FEED_IWDG();
// HAL_Delay(800);
// memset(&Sendbuf[0],0x00,sizeof(Sendbuf));
// sprintf((char*)&Sendbuf[0],"%s\r\n","{\"type\":\"variant_data\",\"version\":\"1.0\",\"time\":1638766638000,\"params\":{\"UAV\":220.5}}");
// gu16_SendLen = strlen(Sendbuf);
// HAL_UART_Transmit(&hUART_4G, (uint8_t *)&Sendbuf,87, 0xffff);//huart1需要根据你的配置修改
// (*cmd) = 0;
// return 1;
// break;
// case 11://Paload数据
// /* code */
// sprintf((char*)&Sendbuf[0],"%s\r\n","{\"type\":\"variant_data\",\"version\":\"1.0\",\"time\":1638766638000,\"params\":{\"UAV\":220.5}}");
// break;
// case 20://清除链接
// /* code */
// sprintf((char*)&Sendbuf[0],"%s\r\n"," AT+QMTDISC=0");
// break;
// case 21://清除链接
// /* code */
// sprintf((char*)&Sendbuf[0],"%s\r\n"," AT+QMTDISC=1");
// break;
// case 22://清除链接
// /* code */
// sprintf((char*)&Sendbuf[0],"%s\r\n"," AT+QMTDISC=2");
// break;
// case 23://清除链接
// /* code */
// sprintf((char*)&Sendbuf[0],"%s\r\n"," AT+QMTDISC=3");
// break;
// case 24://清除链接
// /* code */
// sprintf((char*)&Sendbuf[0],"%s\r\n"," AT+QMTDISC=4");
// break;
// case 25://清除链接
// /* code */
// sprintf((char*)&Sendbuf[0],"%s\r\n"," AT+QMTDISC=5");
// break;
// case 26://清除链接
// /* code */
// // F_DataPacking_SUNKUN_1();
// break;
// default:
// break;
// }
// MX_FEED_IWDG();
// HAL_UART_Transmit(&hUART_4G, (uint8_t *)&Sendbuf,86, 0xffff);//huart1需要根据你的配置修改
// (*cmd) = 0;
// }
/*
M_4G_IDLE
M_AT_TESTING
M_AT_TEST_OK
M_AT_TEST_ERR
M_SIM_CHECKING
M_SIM_CHECK_OK
M_SIM_CHECK_ERR
M_CSQ_CHECKING
M_CSQ_CHECK_OK
M_CGREG_CHECKING
M_CGREG_CHECK_OK
M_CGREG_CHECK_ERR
M_CGATT_CHECKING
M_CGATT_CHECK_OK
M_CGATT_CHECK_ERR
M_QMTCFG_SETTING
M_QMTCFG_SET_OK
M_QMTCFG_SET_ERR
M_QMTOPEN_OPENING
M_QMTOPEN_OPEN_OK
M_QMTOPEN_OPEN_ERR
M_QMTCONN_CONNING
M_QMTCONN_CONN_OK
M_QMTCONN_CONN_ERR
M_QMTPUBEX_PUBING
M_QMTPUBEX_PUB_OK
M_QMTPUBEX_PUB_ERR
*/
#define M_MIN_TCP_DP_LEN 20
#define M_CommSecRecvBufLen 1024
uint32_t u32cnt= 0;
// m_u8_EC20RecvBuff 替换位 ArryBuf
uint8_t m_u8_EC20RecvBuff[EC20_RECV_BUFF_SIZE]= {0};
enum_4G_CMD gLastCMD = 0;
enum_4G_CMD gSavedLastCMD = 0; //可手动保存一下CMD状态 等着跳回时使用
enum_4G_CMD gLastSTA = 0;
enum_4G_CMD gSavedLastSTA = 0; //可手动保存一下STA状态 等着跳回时使用
uint8_t gu8_TCPDirTransfMode = 0; //1为透传模式
// typedef struct
// {
// uint32_t u32_RcvLen ; // 总的TCP len长度
// uint32_t u32_RcvIdleLen; // TCP 接收二级缓存 空余的长度
// uint32_t u32_UsedLen ; //有效的TCP DP len 长度 从HEADER头开始的长度
// int i32_HeaderIndex ; //查找到的TCP通讯header的索引ID
// uint32_t gu32_EndIndex ; //查找到的TCP通讯末尾+1的索引ID
// uint8_t gu8ParseSta; //1 第一阶段 寻找到了包头 接下来找
// }_CommRecvVar;
_CommRecvVar gs_TCPCOMM;
// uint32_t gu32_TCPRcvLen =0; // 总的TCP len长度
// uint32_t gu32_TCPRcvIdleLen =0; // TCP 接收二级缓存 空余的长度
// uint32_t gu32_TCPUsedLen =0; //有效的TCP DP len 长度 从HEADER头开始的长度
// int g32_TCPHeaderIndex =0; //查找到的TCP通讯header的索引ID
// uint32_t gu32_TCPEndIndex =0; //查找到的TCP通讯末尾+1的索引ID
// uint8_t gu8TCPRecvSta = 0; //1 第一阶段 寻找到了包头 接下来找
LUnion LU_TCP_LEN;
ErrorStatus F_EC200N_RecvDatStaHandle(enum_4G_CMD *cmd,enum_4G_CMD *status)
{
char str_OK[] = "OK";
char *pch =NULL;
ErrorStatus lerr = SUCCESS;
uint32_t lu32_cmd =0 ,lu32_status = 0;
lu32_cmd = (uint32_t)(*cmd);
lu32_status = (uint32_t)(*status);
u32cnt = UART_4G_fifo_cnt();
{
memset(&m_u8_EC20RecvBuff,0,sizeof(m_u8_EC20RecvBuff));
if( u32cnt > (sizeof(m_u8_EC20RecvBuff)-2))
{
UART_4G_read(&m_u8_EC20RecvBuff,sizeof(m_u8_EC20RecvBuff));
m_u8_EC20RecvLenth = sizeof(m_u8_EC20RecvBuff);
//ERR
DEBUG_printf(DEBUG_UART,"EC200 ERR %s%d \r\n",__FILE__,__LINE__);
return ERROR;
}
else if(u32cnt>0)
{
m_u8_EC20RecvLenth = u32cnt;
UART_4G_read(&m_u8_EC20RecvBuff,u32cnt);
DEBUG_printf(DEBUG_UART,"EC200_UART_RECV :%s\r\n",m_u8_EC20RecvBuff);
st_EC20RecvCmd = TRUE;
}
else if( 0 == u32cnt)
{
// if( 1 == g_SysBaseTime.f2s)
// {
// (*status) += 2;
// }
}
}
}
ErrorStatus F_APP_EC200N(enum_4G_CMD *cmd,enum_4G_CMD *status)
{
// _ProcJumpType_Def ret = PROC_JUMP_HOLD;
// _ProcParmType_Def tempProcParm = *pProcParm;
static char *retStr = NULL;
static char *retStr1 = NULL;
static char *retHeader = NULL;
static char *retTail = NULL;
char *retStrHead = NULL;
char *retStrTail = NULL;
uint16_t tempLenth = 0;
uint32_t u32FileLenth = 0;
FuncState retFunc;
//static uint16_t s_u16_recvKeepFlag = 0;
static uint16_t s_u16_recvFirstFlag = 0;
static uint32_t s_u32_Revclenth = 0;
static uint32_t s_u32_PutBufferlenth = 0;
static uint8_t m_u8_FileRecvBuffer[EC20_RECV_BUFF_SIZE] = {0};
ErrorStatus l_err = SUCCESS;
char str_OK[] = "OK";
char *pch =NULL;
ErrorStatus lerr = SUCCESS;
uint32_t lu32_cmd =0 ,lu32_status = 0;
lu32_cmd = (uint32_t)(*cmd);
lu32_status = (uint32_t)(*status);
memset(&Sendbuf,0,sizeof(Sendbuf));
// sprintf((char*)&Sendbuf[0],"%s\r\n","AT+CPIN?");
switch (lu32_cmd)
{
case M_EC20_HARD_RESET_START:
gu8_TCPDirTransfMode =0; //开启透传模式
//DO IT
DEBUG_printf(DEBUG_UART,"EC20 RESET_4G_Pin = GPIO_PIN_SET \r\n");
HAL_GPIO_WritePin(RESET_4G_GPIO_Port,RESET_4G_Pin,GPIO_PIN_SET);
HAL_Delay(1000);
MX_FEED_IWDG();
HAL_Delay(1000);
MX_FEED_IWDG();
HAL_GPIO_WritePin(RESET_4G_GPIO_Port,RESET_4G_Pin,GPIO_PIN_RESET);
DEBUG_printf(DEBUG_UART,"EC20 RESET_4G_Pin = GPIO_PIN_RESET \r\n");
MX_FEED_IWDG();
(*status) = M_EC20_HARD_RESET_ING;
break;
case M_4G_IDLE:
//DEBUG_printf(0,"M_4G_IDLE\r\n");
//gu16_SendLen = strlen(Sendbuf);
//(*status) = M_4G_IDLE;
//(*cmd) = 0;
goto JUMP_STA_ING_HANDLE;
break;
case M_AT_TEST_START:
gu8_TCPDirTransfMode =0; //开启透传模式
/* code */
sprintf((char*)&Sendbuf[0],"%s\r\n","AT");
gu16_SendLen = strlen(Sendbuf);
(*status) = M_AT_TESTING;
break;
// case 2:
// /* code */
// sprintf((char*)&Sendbuf[0],"%s\r\n","ATI");
// break;
case M_SIM_CHECK_START://查询SIM卡
/* code */
gu8_TCPDirTransfMode =0; //开启透传模式
sprintf((char*)&Sendbuf[0],"%s\r\n","AT+CPIN?");
gu16_SendLen = strlen(Sendbuf);
(*status) = M_SIM_CHECKING;
break;
case M_CSQ_CHECK_START://查询信号,31最大,小于10证明信号超级不好
/* code */
gu8_TCPDirTransfMode =0; //开启透传模式
sprintf((char*)&Sendbuf[0],"%s\r\n","AT+CSQ");
gu16_SendLen = strlen(Sendbuf)+2;
(*status) = M_CSQ_CHECKING;
break;
case M_CGREG_CHECK_START://查询PS注册情况,注册则返回1,证明获取IP,可以进行网络使用啦
/* code */
sprintf((char*)&Sendbuf[0],"%s\r\n","AT+CGREG?");
gu16_SendLen = strlen(Sendbuf);
(*status) = M_CGREG_CHECKING;
break;
case M_CGATT_CHECK_START://附着网络是否成功
/* code */
sprintf((char*)&Sendbuf[0],"%s\r\n","AT+CGATT?");
gu16_SendLen = strlen(Sendbuf);
(*status) = M_CGATT_CHECKING;
break;
case M_QIACT1_SET_START:// 激活QIACT PDP场景
/* code */
sprintf((char*)&Sendbuf[0],"%s\r\n",EC20_CONTEXT_PRFL);
gu16_SendLen = strlen(Sendbuf);
(*status) = M_QIACT1_SETTING;
break;
case M_QUERY_QIACT_START:// 查询场景状态
/* code */
sprintf((char*)&Sendbuf[0],"%s\r\n",EC20_CONTEXT_INFO);
gu16_SendLen = strlen(Sendbuf);
(*status) = M_QUERY_QIACT_ING;
break;
case M_FTP_CFG_CONTID_START : // FTP 上下文设置 FTP CONTEX ID SET
/* code */
APP_EC20Link_Init();
sprintf((char*)&Sendbuf[0],EC20_FTP_CONTEXTID,st_EC20LinkVar.u8_FtpContextID);
gu16_SendLen = strlen(Sendbuf);
(*status) = M_FTP_CFG_CONTID_ING;
break;
case M_FTP_CFG_ACC_START : // ACCOUNT 设置 FTP ACCOUNT SET
/* code */
sprintf((char*)&Sendbuf[0],EC20_FTP_ACCOUNT,
&st_EC20LinkVar.s_FtpUserName[0],
&st_EC20LinkVar.s_FtpUserPassword[0]);
gu16_SendLen = strlen(Sendbuf);
(*status) = M_FTP_CFG_ACC_ING;
DEBUG_printf(DEBUG_UART,"CMD M_FTP_CFG_ACC_START\r\n");
DEBUG_printf(DEBUG_UART,"STA M_FTP_CFG_ACC_ING\r\n");
break;
case M_FTP_CFG_FT_START : // filetype 设置 FTP filetype SET
/* code */
sprintf((char*)&Sendbuf[0],EC20_FTP_FILE_TYPE,st_EC20LinkVar.u8_FtpFileType);
gu16_SendLen = strlen(Sendbuf);
(*status) = M_FTP_CFG_FT_ING;
DEBUG_printf(DEBUG_UART,"CMD M_FTP_CFG_FT_START\r\n");
DEBUG_printf(DEBUG_UART,"STA M_FTP_CFG_FT_ING\r\n");
break;
case M_FTP_CFG_TM_START : // transfer mode 上下文设置 FTP transfer mode SET
/* code */
sprintf((char*)&Sendbuf[0],EC20_FTP_TRANS_MODE,st_EC20LinkVar.u8_FtpTransMode);
gu16_SendLen = strlen(Sendbuf);
(*status) = M_FTP_CFG_TM_ING;
DEBUG_printf(DEBUG_UART,"CMD M_FTP_CFG_TM_START\r\n");
DEBUG_printf(DEBUG_UART,"STA M_FTP_CFG_TM_ING\r\n");
break;
case M_FTP_CFG_RSPT_START : // rsptimeout 设置 FTP rsptimeout SET
/* code */
sprintf((char*)&Sendbuf[0],EC20_FTP_RSP_TIMEOUT,st_EC20LinkVar.u8_FtpTimeOut1S);
gu16_SendLen = strlen(Sendbuf);
(*status) = M_FTP_CFG_RSPT_ING;
DEBUG_printf(DEBUG_UART,"CMD M_FTP_CFG_RSPT_START\r\n");
DEBUG_printf(DEBUG_UART,"STA M_FTP_CFG_RSPT_ING\r\n");
break;
case M_FTP_QFTPOPEN_START : // ftp 打开 ftp
/* code */
sprintf((char*)&Sendbuf[0],EC20_FTP_OPEN,&st_EC20LinkVar.s_FtpServerDMN[0],
st_EC20LinkVar.u16_FtpPortNum);
gu16_SendLen = strlen(Sendbuf);
(*status) = M_FTP_QFTPOPEN_ING;
DEBUG_printf(DEBUG_UART,"CMD M_FTP_QFTPOPEN_START\r\n");
DEBUG_printf(DEBUG_UART,"STA M_FTP_QFTPOPEN_ING\r\n");
break;
case M_FTP_QFTPCLOSE_START : // ftp 关闭 ftp close
/* code */
sprintf((char*)&Sendbuf[0],EC20_FTP_CLOSE);
gu16_SendLen = strlen(Sendbuf);
(*status) = M_FTP_QFTPCLOSE_ING;
DEBUG_printf(DEBUG_UART,"CMD M_FTP_QFTPCLOSE_START\r\n");
DEBUG_printf(DEBUG_UART,"STA M_FTP_QFTPCLOSE_ING\r\n");
break;
case M_FTP_QFTPCWD_START : // ftp 配置 FTP(S)服务器当前目录
/* code */
sprintf((char*)&Sendbuf[0],EC20_FTP_CWD_FOLDER,&st_EC20LinkVar.s_FtpFilePath[0]);
gu16_SendLen = strlen(Sendbuf);
(*status) = M_FTP_QFTPCWD_ING;
DEBUG_printf(DEBUG_UART,"CMD M_FTP_QFTPCWD_START\r\n");
DEBUG_printf(DEBUG_UART,"STA M_FTP_QFTPCWD_ING\r\n");
break;
case M_FTP_QFTPSIZE_START : // ftp 获取文件的大小
/* code */
sprintf((char*)&Sendbuf[0],EC20_FTP_QUERY_SIZE,&st_EC20LinkVar.s_FtpFileName[0]);
gu16_SendLen = strlen(Sendbuf);
(*status) = M_FTP_QFTPSIZE_ING;
DEBUG_printf(DEBUG_UART,"CMD M_FTP_QFTPSIZE_START\r\n");
DEBUG_printf(DEBUG_UART,"STA M_FTP_QFTPSIZE_ING\r\n");
break;
case M_FTP_QFTPGET_START : // ftp
/* code */
sprintf((char*)&Sendbuf[0],EC20_FTP_GET_FILE,
&st_EC20LinkVar.s_FtpFileName[0],
EC20_FILE_NEW_NAME);
gu16_SendLen = strlen(Sendbuf);
(*status) = M_FTP_QFTPGET_ING;
DEBUG_printf(DEBUG_UART,"CMD M_FTP_QFTPGET_START\r\n");
DEBUG_printf(DEBUG_UART,"STA M_FTP_QFTPGET_ING\r\n");
break;
case M_FTP_QFDELUFSALL_START : // ftp
/* code */
sprintf((char*)&Sendbuf[0],EC20_FILE_QFDELUFSALL);
gu16_SendLen = strlen(Sendbuf);
(*status) = M_FTP_QFDELUFSALL_ING;
DEBUG_printf(DEBUG_UART,"CMD M_FTP_QFDELUFSALL_START\r\n");
DEBUG_printf(DEBUG_UART,"STA M_FTP_QFDELUFSALL_ING\r\n");
break;
case M_FTP_QFOPEN_START : // ftp
/* code */
st_EC20LinkVar.p_FileName = EC20_FILE_NEW_NAME;
sprintf((char*)&Sendbuf[0],EC20_FILE_OPEN,st_EC20LinkVar.p_FileName);
gu16_SendLen = strlen(Sendbuf);
(*status) = M_FTP_QFOPEN_ING;
DEBUG_printf(DEBUG_UART,"CMD M_FTP_QFOPEN_START\r\n");
DEBUG_printf(DEBUG_UART,"STA M_FTP_QFOPEN_ING\r\n");
break;
case M_FTP_QFCLOSE_START : // ftp
/* code */
sprintf((char*)&Sendbuf[0],EC20_FILE_CLOSE,st_EC20LinkVar.u16_FileHandle);
gu16_SendLen = strlen(Sendbuf);
(*status) = M_FTP_QFCLOSE_ING;
DEBUG_printf(DEBUG_UART,"CMD M_FTP_QFCLOSE_START\r\n");
DEBUG_printf(DEBUG_UART,"STA M_FTP_QFCLOSE_ING\r\n");
break;
case M_FTP_QFSEEK_START : // ftp
/* code */
uint32_t lu32_BSP_ERR = 0;
BSP_FLASH_Erase(0,&lu32_BSP_ERR);
st_EC20LinkVar.u32_FilePosition = 0;
sprintf((char*)&Sendbuf[0],EC20_FILE_SEEK,
st_EC20LinkVar.u16_FileHandle,
st_EC20LinkVar.u32_FilePosition);
gu16_SendLen = strlen(Sendbuf);
(*status) = M_FTP_QFSEEK_ING;
DEBUG_printf(DEBUG_UART,"CMD M_FTP_QFSEEK_START\r\n");
DEBUG_printf(DEBUG_UART,"STA M_FTP_QFSEEK_ING\r\n");
break;
case M_FTP_QFREAD_START : // ftp
/* code */
sprintf((char*)&Sendbuf[0],EC20_FILE_READ,
st_EC20LinkVar.u16_FileHandle,
EC20_FILE_EXCHANGE_SIZE);
gu16_SendLen = strlen(Sendbuf);
(*status) = M_FTP_QFREAD_ING;
DEBUG_printf(DEBUG_UART,"CMD M_FTP_QFREAD_START\r\n");
DEBUG_printf(DEBUG_UART,"STA M_FTP_QFREAD_ING\r\n");
break;
// case M_QIOPEN_START:// OPEN EC200 TCP SOKCET 打开EC200 SOCKET
// /* code */
// gu8_TCPDirTransfMode = M_EC20_AT; // 进入AT模式
// sprintf((char*)&Sendbuf[0],"%s\r\n",EC20_SOCKET_OPEN_TEST);
// gu16_SendLen = strlen(Sendbuf);
// (*status) = M_QIOPEN_ING;
// break;
// case M_TCP_LOGIN_START:// LOGING
// /* code */
// gu8_TCPDirTransfMode = M_EC20_TT ; //开启透传模式
// memset(&gs_TCPRecvLocalInfo,0,sizeof(gs_TCPRecvLocalInfo));
// l_err = F_TCP_LoginDataPack();
// if(SUCCESS == l_err)
// {
// gu16_SendLen = gs_TCP_DataPack.u32Length;
// memcpy(&Sendbuf,&gu8A_TCPToalDataBag,gu16_SendLen);
// (*status) = M_TCP_LOGIN_ING;
// }
// break;
// case M_TCP_DATAUP_START:// TCP 数据上报开始
// /* code */
// // sprintf((char*)&Sendbuf[0],"%s\r\n",EC20_SOCKET_OPEN);
// // gu16_SendLen = strlen(Sendbuf);
// // (*status) = M_QIOPEN_ING;
// memset(&gs_TCPRecvLocalInfo,0,sizeof(gs_TCPRecvLocalInfo));
// l_err = F_TCP_DataUpDataPack();
// if(SUCCESS == l_err)
// {
// gu16_SendLen = gs_TCP_DataPack.u32Length;
// memcpy(&Sendbuf,&gu8A_TCPToalDataBag,gu16_SendLen);
// (*status) = M_TCP_DATAUP_ING;
// }
// break;
// case M_QICLOSE_START:// OPEN EC200 TCP SOKCET 打开EC200 SOCKET
// /* code */
// sprintf((char*)&Sendbuf[0],"%s\r\n",EC20_SOCKET_CLOSE);
// gu16_SendLen = strlen(Sendbuf);
// (*status) = M_QICLOSE_ING;
// break;
// case M_QMTCFG_SET_START://设置数据格式
// /* code */
// sprintf((char*)&Sendbuf[0],"%s\r\n","AT+QMTCFG=\"recv/mode\",0,0,1");
// gu16_SendLen = strlen(Sendbuf);
// (*status) = M_QMTCFG_SETTING;
// break;
// case M_QMTOPEN_OPEN_START://打开工业物联网云端口
// /* code */
// sprintf((char*)&Sendbuf[0],"%s\r\n","AT+QMTOPEN=0,\"www.sukon-cloud.com\",9006");
// gu16_SendLen = strlen(Sendbuf);
// (*status) = M_QMTOPEN_OPENING;
// break;
// case M_QMTCONN_CONN_START://这步执行成功后,设备应该在线了。
// /* code */
// sprintf((char*)&Sendbuf[0],"%s\r\n","AT+QMTCONN=0,\"SMETTest\",\"SMETTest\",\"123456\"");
// gu16_SendLen = strlen(Sendbuf);
// (*status) = M_QMTCONN_CONNING;
// break;
// case M_QMTPUBEX_PUB_START://发送数据命令
// /* code */
// memset(&Sendbuf,0,sizeof(Sendbuf));
// F_DataPacking_SUNKUN_1(Sendbuf,sizeof(Sendbuf));
// gu16_SendLen = strlen(Sendbuf);
// memset(&Sendbuf,0,sizeof(Sendbuf));
// sprintf((char*)&Sendbuf[0],"%s,%d\r\n","AT+QMTPUBEX=0,0,0,0,\"sys/device/SMETTest/variant_data\"",gu16_SendLen);
// gu16_SendLen = strlen(Sendbuf);
// MX_FEED_IWDG();
// HAL_UART_Transmit(&huart4, (uint8_t *)&Sendbuf,gu16_SendLen, 0xffff);//huart1需要根据你的配置修改
// MX_FEED_IWDG();
// MX_FEED_IWDG();
// HAL_Delay(800);
// memset(&Sendbuf,0,sizeof(Sendbuf));
// F_DataPacking_SUNKUN_1(Sendbuf,sizeof(Sendbuf));
// gu16_SendLen = strlen(Sendbuf);
// //sprintf(Sendbuf,SUNKON_PAYLOAD,gf_testUAV,gf_testUBV,gf_testUCV,gf_testIAA,gf_testIBA,gf_testICA,gf_testPAW,gf_testPBW,gf_testPCW,gf_testPTW);
// //sprintf((char*)&Sendbuf[0],"%s\r\n","{\"type\":\"variant_data\",\"version\":\"1.0\",\"time\":1638766638000,\"params\":{\"UAV\":220.5}}");
// HAL_UART_Transmit(&huart4, (uint8_t *)&Sendbuf,gu16_SendLen, 0xffff);//huart1需要根据你的配置修改
// (*status) = M_QMTPUBEX_PUBING;
// return 1;
// break;
// case M_QMTDISC_0_START://清除链接
// /* code */
// memset(&Sendbuf,0,sizeof(Sendbuf));
// sprintf((char*)&Sendbuf[0],"%s\r\n"," AT+QMTDISC=0");
// gu16_SendLen = strlen(Sendbuf);
// (*status) = M_QMTDISC_0_ING;
// break;
default:
//return ERROR;
goto JUMP_STA_ING_HANDLE;
break;
}
(*cmd) = (*status);
HAL_UART_Transmit(&huart1, (uint8_t *)&Sendbuf,gu16_SendLen, 0xffff);//huart1需要根据你的配置修改
HAL_UART_Transmit(&UART_4G, (uint8_t *)&Sendbuf,gu16_SendLen, 0xffff);//hUART_4G需要根据你的配置修改
// memset(&g_SysBaseTime,0,sizeof(g_SysBaseTime));
// Sys_BaseTimeInit();
g32_LastSec = Sys_GetSec();
//ING STATUS
JUMP_STA_ING_HANDLE:
switch ( lu32_status )
{
case M_EC20_HARD_RESET_ING:
g32_NowSec = Sys_GetSec();
g32_DiffSec = g32_NowSec - g32_LastSec;
pch = strstr(m_u8_EC20RecvBuff, "RDY");
if (pch != NULL)
{
// (*status) += 1;
(*status) = M_EC20_HARD_RESET_INIT_WAIT;
(*cmd) = M_EC20_HARD_RESET_INIT_WAIT;
g32_LastSec = Sys_GetSec();
}
else if( g32_DiffSec > 10)
{
// (*status) += 2;
(*status) = M_EC20_HARD_RESET_ERR;
}
break;
case M_EC20_HARD_RESET_INIT_WAIT:
//重启后的初始化等待步骤
g32_NowSec = Sys_GetSec();
g32_DiffSec = g32_NowSec - g32_LastSec;
if(g32_DiffSec > M_EC20_RESET_INIT_WAIT_S)
{
(*cmd) = M_SIM_CHECK_START;
}
break;
// g32_NowSec = Sys_GetSec();
// g32_DiffSec = g32_NowSec - g32_LastSec;
// pch = strstr(ArryBuf, str_OK);
// if (pch != NULL)
// {
// (*status) += 1;
// }
// else if( g32_DiffSec > 6)
// {
// (*status) += 2;
// }
case M_AT_TESTING:
pch = strstr(m_u8_EC20RecvBuff, str_OK);
if (pch != NULL)
{
(*status) += 1;
}
else if( g_SysBaseTime.f2s == 1)
{
(*status) += 2;
}
break;
case M_SIM_CHECKING:
pch = strstr(m_u8_EC20RecvBuff, str_OK);
if (pch != NULL)
{
(*status) += 1;
}
else if( g_SysBaseTime.f2s == 1)
{
//(*status) += 2;
(*status) = M_SIM_CHECK_ERR;
}
break;
case M_CSQ_CHECKING:
{
pch = strstr(m_u8_EC20RecvBuff, str_OK);
if (pch != NULL)
{
(*status) += 1;
}
else if( g_SysBaseTime.f2s == 1)
{
(*status) += 2;
}
break;
}
case M_CGATT_CHECKING:
{
pch = strstr(m_u8_EC20RecvBuff, str_OK);
if (pch != NULL)
{
(*status) += 1;
}
else if( g_SysBaseTime.f2s == 1)
{
(*status) += 2;
}
break;
}
case M_QIACT1_SETTING:
pch = strstr(m_u8_EC20RecvBuff, EC20_CONTEXT_PRFL_ANS);
if (pch != NULL)
{
(*status) += 1;
}
else if( g_SysBaseTime.f2s == 1)
{
(*status) += 2;
}
break;
case M_QUERY_QIACT_ING:
g32_NowSec = Sys_GetSec();
g32_DiffSec = g32_NowSec - g32_LastSec;
pch = strstr(m_u8_EC20RecvBuff, EC20_CONTEXT_INFO_ANS);
if (pch != NULL)
{
(*status) += 1;
}
// else if( g_SysBaseTime.f2s == 1)
// {
// (*status) += 2;
// }
else if( g32_DiffSec > 8)
{
(*status) += 2; //M_QIOPEN_ERR
}
break;
case M_FTP_CFG_CONTID_ING:
g32_NowSec = Sys_GetSec();
g32_DiffSec = g32_NowSec - g32_LastSec;
pch = strstr(m_u8_EC20RecvBuff, EC20_FTP_OK);
if (pch != NULL)
{
(*status) = M_FTP_CFG_CONTID_OK;
DEBUG_printf(DEBUG_UART,"FTP context id set ok\r\n");
}
// else if( g_SysBaseTime.f2s == 1)
// {
// (*status) += 2;
// }
else if( g32_DiffSec > 8)
{
(*status) = M_FTP_CFG_CONTID_ERR; //M_QIOPEN_ERR
DEBUG_printf(DEBUG_UART,"FTP context id set timeout\r\n");
}
break;
case M_FTP_CFG_ACC_ING:
g32_NowSec = Sys_GetSec();
g32_DiffSec = g32_NowSec - g32_LastSec;
pch = strstr(m_u8_EC20RecvBuff, EC20_FTP_OK);
if (pch != NULL)
{
(*status) = M_FTP_CFG_ACC_OK;
DEBUG_printf(DEBUG_UART,"FTP ACC set ok\r\n");
}
// else if( g_SysBaseTime.f2s == 1)
// {
// (*status) += 2;
// }
else if( g32_DiffSec > 8)
{
(*status) = M_FTP_CFG_ACC_ERR; //M_QIOPEN_ERR
DEBUG_printf(DEBUG_UART,"FTP ACC set timeout\r\n");
}
break;
case M_FTP_CFG_FT_ING:
g32_NowSec = Sys_GetSec();
g32_DiffSec = g32_NowSec - g32_LastSec;
pch = strstr(m_u8_EC20RecvBuff, EC20_FTP_OK);
if (pch != NULL)
{
(*status) = M_FTP_CFG_FT_OK;
DEBUG_printf(DEBUG_UART,"FTP file type set ok\r\n");
}
// else if( g_SysBaseTime.f2s == 1)
// {
// (*status) += 2;
// }
else if( g32_DiffSec > 8)
{
(*status) = M_FTP_CFG_FT_ERR; //M_QIOPEN_ERR
DEBUG_printf(DEBUG_UART,"FTP file type set timeout\r\n");
}
break;
case M_FTP_CFG_TM_ING:
g32_NowSec = Sys_GetSec();
g32_DiffSec = g32_NowSec - g32_LastSec;
pch = strstr(m_u8_EC20RecvBuff, EC20_FTP_OK);
if (pch != NULL)
{
(*status) = M_FTP_CFG_TM_OK;
DEBUG_printf(DEBUG_UART,"FTP transfer mode set ok\r\n");
}
// else if( g_SysBaseTime.f2s == 1)
// {
// (*status) += 2;
// }
else if( g32_DiffSec > 8)
{
(*status) = M_FTP_CFG_TM_ERR; //
DEBUG_printf(DEBUG_UART,"FTP transfer mode set timeout\r\n");
}
break;
case M_FTP_CFG_RSPT_ING:
g32_NowSec = Sys_GetSec();
g32_DiffSec = g32_NowSec - g32_LastSec;
pch = strstr(m_u8_EC20RecvBuff, EC20_FTP_OK);
if (pch != NULL)
{
(*status) = M_FTP_CFG_RSPT_OK;
DEBUG_printf(DEBUG_UART,"FTP RSPT set ok\r\n");
}
// else if( g_SysBaseTime.f2s == 1)
// {
// (*status) += 2;
// }
else if( g32_DiffSec > 8)
{
(*status) = M_FTP_CFG_RSPT_ERR; //
DEBUG_printf(DEBUG_UART,"FTP RSPT set timeout\r\n");
}
break;
case M_FTP_QFTPOPEN_ING:
g32_NowSec = Sys_GetSec();
g32_DiffSec = g32_NowSec - g32_LastSec;
// pch = strstr(m_u8_EC20RecvBuff, EC20_FTP_OPEN_ANS);
// if (pch != NULL)
// {
// (*status) = M_FTP_QFTPOPEN_OK;
// }
if(TRUE == st_EC20RecvCmd)
{
st_EC20RecvCmd = FALSE;
retStr = strstr((char*)&m_u8_EC20RecvBuff[0],EC20_FTP_OPEN_ANS);
retStr1 = strstr((char*)&m_u8_EC20RecvBuff[0],EC20_FTP_ERR);
if(NULL != retStr)
{
retStrHead = retStr + sizeof(EC20_FTP_OPEN_ANS) - 1;
retStrTail = strstr(retStrHead,"\r\n");
tempLenth = retStrTail - retStrHead;
tempLenth = MIN(tempLenth,sizeof(st_EC20LinkVar.s_FtpLoginInfo));
memcpy(&st_EC20LinkVar.s_FtpLoginInfo[0],retStrHead,tempLenth);
retStr1 = strstr(retStrHead,",");
st_EC20LinkVar.u16_FtpErrCode = atoi((char*)&st_EC20LinkVar.s_FtpLoginInfo[0]);
st_EC20LinkVar.u16_FtpProErrCode = atoi(retStr1 + 1);
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPOPEN_ING s_FtpLoginInfo %s\r\n",st_EC20LinkVar.s_FtpLoginInfo);
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPOPEN_ING u16_FtpErrCode %d\r\n",st_EC20LinkVar.u16_FtpErrCode);
if(0 == st_EC20LinkVar.u16_FtpErrCode)
{
//ret = PROC_JUMP_EXIT;
(*status) = M_FTP_QFTPOPEN_OK;
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPOPEN_OK \r\n");
}
else
{
(*status) = M_FTP_QFTPOPEN_ERR;
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPOPEN_ERR u16_FtpErrCode %d\r\n",st_EC20LinkVar.u16_FtpErrCode);
}
}
else if(NULL != retStr1)
{
retStrHead = retStr1 + sizeof(EC20_FTP_ERR) - 1;
retStrTail = strstr(retStrHead,"\r\n");
tempLenth = retStrTail - retStrHead;
tempLenth = MIN(tempLenth,sizeof(st_EC20LinkVar.s_FtpLoginInfo));
memcpy(&st_EC20LinkVar.s_FtpLoginInfo[0],retStrHead,tempLenth);
st_EC20LinkVar.u16_FtpErrCode = atoi((char*)&st_EC20LinkVar.s_FtpLoginInfo[0]);
st_EC20LinkVar.u16_FtpProErrCode = 0;
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPOPEN_ING s_FtpLoginInfo %s\r\n",st_EC20LinkVar.s_FtpLoginInfo);
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPOPEN_ING u16_FtpErrCode %d\r\n",st_EC20LinkVar.u16_FtpErrCode);
if(0 == st_EC20LinkVar.u16_FtpErrCode)
{
//ret = PROC_JUMP_EXIT;
(*status) = M_FTP_QFTPOPEN_OK;
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPOPEN_OK \r\n");
}
else
{
(*status) = M_FTP_QFTPOPEN_ERR;
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPOPEN_ING u16_FtpErrCode %d\r\n",st_EC20LinkVar.u16_FtpErrCode);
}
}
else
{
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPOPEN_ING unknow\r\n");
}
}
else if ( g32_DiffSec > 8)
{
(*status) = M_FTP_QFTPOPEN_ERR; //
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPOPEN_ERR timeout \r\n");
}
break;
case M_FTP_QFDELUFSALL_ING:
g32_NowSec = Sys_GetSec();
g32_DiffSec = g32_NowSec - g32_LastSec;
pch = strstr(m_u8_EC20RecvBuff, EC20_FTP_OK);
if (pch != NULL)
{
(*status) = M_FTP_QFDELUFSALL_OK;
DEBUG_printf(DEBUG_UART,"EC20 M_FTP_QFDELUFSALL_OK ok\r\n");
}
else if( g32_DiffSec > 8)
{
(*status) = M_FTP_QFDELUFSALL_ERR; //
DEBUG_printf(DEBUG_UART,"EC20 M_FTP_QFDELUFSALL_ERR timeout\r\n");
}
break;
case M_FTP_QFTPCLOSE_ING:
g32_NowSec = Sys_GetSec();
g32_DiffSec = g32_NowSec - g32_LastSec;
if(TRUE == st_EC20RecvCmd)
{
st_EC20RecvCmd = FALSE;
retStr = strstr((char*)&m_u8_EC20RecvBuff[0],EC20_FTP_CLOSE_ANS);
retStr1 = strstr((char*)&m_u8_EC20RecvBuff[0],EC20_FTP_ERR);
if(NULL != retStr)
{
retStrHead = retStr + sizeof(EC20_FTP_CLOSE_ANS) - 1;
retStrTail = strstr(retStrHead,"\r\n");
tempLenth = retStrTail - retStrHead;
tempLenth = MIN(tempLenth,sizeof(st_EC20LinkVar.s_FtpLogoffInfo));
memcpy(&st_EC20LinkVar.s_FtpLogoffInfo[0],retStrHead,tempLenth);
retStr1 = strstr(retStrHead,",");
st_EC20LinkVar.u16_FtpErrCode = atoi((char*)&st_EC20LinkVar.s_FtpLogoffInfo[0]);
st_EC20LinkVar.u16_FtpProErrCode = atoi(retStr1 + 1);
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPCLOSE_ING s_FtpLogoffInfo %s\r\n",st_EC20LinkVar.s_FtpLogoffInfo);
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPCLOSE_ING u16_FtpErrCode %d\r\n",st_EC20LinkVar.u16_FtpErrCode);
//ret = PROC_JUMP_NEXT;
(*status) = M_FTP_QFTPCLOSE_OK;
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPCLOSE_OK\r\n");
}
else if(NULL != retStr1)
{
retStrHead = retStr1 + sizeof(EC20_FTP_ERR) - 1;
retStrTail = strstr(retStrHead,"\r\n");
tempLenth = retStrTail - retStrHead;
tempLenth = MIN(tempLenth,sizeof(st_EC20LinkVar.s_FtpLogoffInfo));
memcpy(&st_EC20LinkVar.s_FtpLogoffInfo[0],retStrHead,tempLenth);
st_EC20LinkVar.u16_FtpErrCode = atoi((char*)&st_EC20LinkVar.s_FtpLogoffInfo[0]);
st_EC20LinkVar.u16_FtpProErrCode = 0;
//ret = PROC_JUMP_NEXT;
(*status) = M_FTP_QFTPCLOSE_ERR;
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPCLOSE_ING s_FtpLogoffInfo %s\r\n",st_EC20LinkVar.s_FtpLogoffInfo);
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPCLOSE_ING u16_FtpErrCode %d\r\n",st_EC20LinkVar.u16_FtpErrCode);
}
else
{
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPCLOSE_ING unknow\r\n");
}
}
else if ( g32_DiffSec > 8)
{
(*status) = M_FTP_QFTPCLOSE_ERR; //
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPCLOSE_ING timeout \r\n");
}
break;
case M_FTP_QFTPCWD_ING:
g32_NowSec = Sys_GetSec();
g32_DiffSec = g32_NowSec - g32_LastSec;
if(TRUE == st_EC20RecvCmd)
{
st_EC20RecvCmd = FALSE;
retStr = strstr((char*)&m_u8_EC20RecvBuff[0],EC20_FTP_CWD_FOLDER_ANS);
retStr1 = strstr((char*)&m_u8_EC20RecvBuff[0],EC20_FTP_ERR);
if(NULL != retStr)
{
retStrHead = retStr + sizeof(EC20_FTP_CWD_FOLDER_ANS) - 1;
retStrTail = strstr(retStrHead,"\r\n");
tempLenth = retStrTail - retStrHead;
tempLenth = MIN(tempLenth,sizeof(st_EC20LinkVar.s_FtpFolderInfo));
memcpy(&st_EC20LinkVar.s_FtpFolderInfo[0],retStrHead,tempLenth);
retStr1 = strstr(retStrHead,",");
st_EC20LinkVar.u16_FtpErrCode = atoi((char*)&st_EC20LinkVar.s_FtpFolderInfo[0]);
st_EC20LinkVar.u16_FtpProErrCode = atoi(retStr1 + 1);
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPCWD_ING s_FtpFolderInfo %s\r\n",st_EC20LinkVar.s_FtpFolderInfo);
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPCWD_ING u16_FtpErrCode %d\r\n",st_EC20LinkVar.u16_FtpErrCode);
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPCWD_ING u16_FtpProErrCode %d\r\n",st_EC20LinkVar.u16_FtpProErrCode);
if(0 == st_EC20LinkVar.u16_FtpErrCode)
{
//ret = PROC_JUMP_EXIT;
(*status) = M_FTP_QFTPCWD_OK; //
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPCWD_OK\r\n");
}
else
{
(*status) = M_FTP_QFTPCWD_ERR; //
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPCWD_ERR u16_FtpErrCode %d \r\n",st_EC20LinkVar.u16_FtpErrCode);
}
}
else if(NULL != retStr1)
{
retStrHead = retStr1 + sizeof(EC20_FTP_ERR) - 1;
retStrTail = strstr(retStrHead,"\r\n");
tempLenth = retStrTail - retStrHead;
tempLenth = MIN(tempLenth,sizeof(st_EC20LinkVar.s_FtpFolderInfo));
memcpy(&st_EC20LinkVar.s_FtpFolderInfo[0],retStrHead,tempLenth);
st_EC20LinkVar.u16_FtpErrCode = atoi((char*)&st_EC20LinkVar.s_FtpFolderInfo[0]);
st_EC20LinkVar.u16_FtpProErrCode = 0;
if(0 == st_EC20LinkVar.u16_FtpErrCode)
{
//ret = PROC_JUMP_EXIT;
(*status) = M_FTP_QFTPCWD_ERR; //
}
(*status) = M_FTP_QFTPCWD_ERR; //
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPCWD_ERR u16_FtpErrCode %s %d \r\n",EC20_FTP_ERR,st_EC20LinkVar.u16_FtpErrCode);
}
}
else if( g32_DiffSec > 8)
{
(*status) = M_FTP_QFTPCWD_ERR; //
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPCWD_ING timeout \r\n");
}
break;
case M_FTP_QFTPSIZE_ING:
g32_NowSec = Sys_GetSec();
g32_DiffSec = g32_NowSec - g32_LastSec;
if(TRUE == st_EC20RecvCmd)
{
st_EC20RecvCmd = FALSE;
retStr = strstr((char*)&m_u8_EC20RecvBuff[0],EC20_FTP_QUERY_SIZE_ANS);
retStr1 = strstr((char*)&m_u8_EC20RecvBuff[0],EC20_FTP_ERR);
if(NULL != retStr)
{
retStrHead = retStr + sizeof(EC20_FTP_QUERY_SIZE_ANS) - 1;
retStrTail = strstr(retStrHead,"\r\n");
tempLenth = retStrTail - retStrHead;
tempLenth = MIN(tempLenth,sizeof(st_EC20LinkVar.s_FtpFileInfo));
memcpy(&st_EC20LinkVar.s_FtpFileInfo[0],retStrHead,tempLenth);
retStr1 = strstr(retStrHead,",");
st_EC20LinkVar.u16_FtpErrCode = atoi((char*)&st_EC20LinkVar.s_FtpFileInfo[0]);
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPSIZE_ING s_FtpFileInfo %s\r\n",st_EC20LinkVar.s_FtpFileInfo);
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPSIZE_ING u16_FtpErrCode %d\r\n",st_EC20LinkVar.u16_FtpErrCode);
if(0 == st_EC20LinkVar.u16_FtpErrCode)
{
st_EC20LinkVar.u32_FtpFileOriginalSize = atoi(retStr1 + 1);
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPSIZE_OK u32_FtpFileOriginalSize %d\r\n",st_EC20LinkVar.u32_FtpFileOriginalSize);
//ret = PROC_JUMP_EXIT;
(*status) = M_FTP_QFTPSIZE_OK;
}
else
{
(*status) = M_FTP_QFTPSIZE_ERR;
st_EC20LinkVar.u16_FtpProErrCode = atoi(retStr1 + 1);
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPSIZE_ERR u16_FtpProErrCode %d\r\n",st_EC20LinkVar.u16_FtpProErrCode);
}
}
else if(NULL != retStr1)
{
retStrHead = retStr1 + sizeof(EC20_FTP_ERR) - 1;
retStrTail = strstr(retStrHead,"\r\n");
tempLenth = retStrTail - retStrHead;
tempLenth = MIN(tempLenth,sizeof(st_EC20LinkVar.s_FtpFileInfo));
memcpy(&st_EC20LinkVar.s_FtpFileInfo[0],retStrHead,tempLenth);
st_EC20LinkVar.u16_FtpErrCode = atoi((char*)&st_EC20LinkVar.s_FtpFileInfo[0]);
st_EC20LinkVar.u16_FtpProErrCode = 0;
if(0 == st_EC20LinkVar.u16_FtpErrCode)
{
//ret = PROC_JUMP_EXIT;
(*status) = M_FTP_QFTPSIZE_ERR;
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPSIZE_ERR u16_FtpErrCode CME %d \r\n",st_EC20LinkVar.u16_FtpErrCode);
}
else
{
(*status) = M_FTP_QFTPSIZE_ERR;
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPSIZE_ERR u16_FtpErrCode CME %d \r\n",st_EC20LinkVar.u16_FtpErrCode);
}
}
else
{
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPSIZE_ING unkonw\r\n");
}
}
else if( g32_DiffSec > 8)
{
(*status) = M_FTP_QFTPSIZE_ERR; //
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPSIZE_ERR timeout \r\n");
}
break;
case M_FTP_QFTPGET_ING:
g32_NowSec = Sys_GetSec();
g32_DiffSec = g32_NowSec - g32_LastSec;
if(TRUE == st_EC20RecvCmd)
{
st_EC20RecvCmd = FALSE;
retStr = strstr((char*)&m_u8_EC20RecvBuff[0],EC20_FTP_GET_FILE_ANS);
retStr1 = strstr((char*)&m_u8_EC20RecvBuff[0],EC20_FTP_ERR);
if(NULL != retStr)
{
retStrHead = retStr + sizeof(EC20_FTP_GET_FILE_ANS) - 1;
retStrTail = strstr(retStrHead,"\r\n");
tempLenth = retStrTail - retStrHead;
tempLenth = MIN(tempLenth,sizeof(st_EC20LinkVar.s_FtpDataInfo));
memcpy(&st_EC20LinkVar.s_FtpDataInfo[0],retStrHead,tempLenth);
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPGET_ING s_FtpDataInfo %s \r\n",st_EC20LinkVar.s_FtpDataInfo[0]);
retStr1 = strstr(retStrHead,",");
st_EC20LinkVar.u16_FtpErrCode = atoi((char*)&st_EC20LinkVar.s_FtpDataInfo[0]);
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPGET_ING u16_FtpErrCode %d \r\n",st_EC20LinkVar.u16_FtpErrCode);
if(0 == st_EC20LinkVar.u16_FtpErrCode)
{
st_EC20LinkVar.u32_FtpFileDownloadSize = atoi(retStr1 + 1);
//ret = PROC_JUMP_EXIT;
(*status) = M_FTP_QFTPGET_OK;
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPGET_OK u32_FtpFileDownloadSize %d \r\n",st_EC20LinkVar.u32_FtpFileDownloadSize);
}
else if(613 == st_EC20LinkVar.u16_FtpErrCode)
{
(*status) = M_FTP_QFTPGET_ERR;
st_EC20LinkVar.u16_FtpProErrCode = atoi(retStr1 + 1);
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPGET_ERR u16_FtpProErrCode %d \r\n",st_EC20LinkVar.u16_FtpProErrCode);
}
else
{
}
} //END if(NULL != retStr)
else if(NULL != retStr1)
{
retStrHead = retStr1 + sizeof(EC20_FTP_ERR) - 1;
retStrTail = strstr(retStrHead,"\r\n");
tempLenth = retStrTail - retStrHead;
tempLenth = MIN(tempLenth,sizeof(st_EC20LinkVar.s_FtpDataInfo));
memcpy(&st_EC20LinkVar.s_FtpDataInfo[0],retStrHead,tempLenth);
st_EC20LinkVar.u16_FtpErrCode = atoi((char*)&st_EC20LinkVar.s_FtpDataInfo[0]);
st_EC20LinkVar.u16_FtpProErrCode = 0;
if(0 == st_EC20LinkVar.u16_FtpErrCode)
{
//ret = PROC_JUMP_EXIT;
(*status) = M_FTP_QFTPGET_ERR;
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPGET_OK u16_FtpErrCode CME %d \r\n",st_EC20LinkVar.u16_FtpErrCode);
}
else
{
(*status) = M_FTP_QFTPGET_ERR;
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPGET_ERR u16_FtpErrCode CME %d \r\n",st_EC20LinkVar.u16_FtpErrCode);
}
} //END else if(NULL != retStr1)
else
{
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPGET_ING unkonw\r\n");
}
} // END if(TRUE == st_EC20RecvCmd)
else if( g32_DiffSec > 16)
{
(*status) = M_FTP_QFTPGET_ERR; //
DEBUG_printf(DEBUG_UART,"M_FTP_QFTPGET_ERR timeout \r\n");
}
case M_FTP_QFOPEN_ING:
g32_NowSec = Sys_GetSec();
g32_DiffSec = g32_NowSec - g32_LastSec;
if(TRUE == st_EC20RecvCmd)
{
st_EC20RecvCmd = FALSE;
retFunc = Alg_EC20Link_ParseInfo(EC20_FILE_OPEN_ANS,
&st_EC20LinkVar.s_FileOpenInfo[0],
sizeof(st_EC20LinkVar.s_FileOpenInfo));
if(SUCC == retFunc)
{
st_EC20LinkVar.u16_FileHandle = atoi((char*)&st_EC20LinkVar.s_FileOpenInfo[0]);
DEBUG_printf(DEBUG_UART,"M_FTP_QFOPEN_OK u16_FileHandle =%d\r\n",st_EC20LinkVar.u16_FileHandle);
(*status) = M_FTP_QFOPEN_OK; //
// ret = PROC_JUMP_EXIT;
}
retFunc = Alg_EC20Link_ParseInfo(EC20_FILE_ERR,
&st_EC20LinkVar.s_FileOpenInfo[0],
sizeof(st_EC20LinkVar.s_FileOpenInfo));
if(SUCC == retFunc)
{
st_EC20LinkVar.u16_FileErrCode = atoi((char*)&st_EC20LinkVar.s_FileOpenInfo[0]);
if(426 == st_EC20LinkVar.u16_FileErrCode) //426 = 文件已经打开 file is already open
{
// ret = PROC_JUMP_EXIT;
DEBUG_printf(DEBUG_UART,"M_FTP_QFOPEN_OK file is already open\r\n");
(*status) = M_FTP_QFOPEN_OK; //
}
else
{
DEBUG_printf(DEBUG_UART,"M_FTP_QFOPEN_ERR u16_FileErrCode = %d\r\n",st_EC20LinkVar.u16_FileErrCode);
(*status) = M_FTP_QFOPEN_ERR; //
}
}
}
else if( g32_DiffSec > 8)
{
(*status) = M_FTP_QFOPEN_ERR; //
DEBUG_printf(DEBUG_UART,"M_FTP_QFOPEN_ING timeout \r\n");
}
break;
case M_FTP_QFCLOSE_ING:
g32_NowSec = Sys_GetSec();
g32_DiffSec = g32_NowSec - g32_LastSec;
if(TRUE == st_EC20RecvCmd)
{
st_EC20RecvCmd = FALSE;
retFunc = Alg_EC20Link_ParseInfo(EC20_FILE_OK,
&st_EC20LinkVar.s_FileCloseInfo[0],
sizeof(st_EC20LinkVar.s_FileCloseInfo));
if(SUCC == retFunc)
{
// ret = PROC_JUMP_EXIT;
(*status) = M_FTP_QFCLOSE_OK; //
}
retFunc = Alg_EC20Link_ParseInfo(EC20_FILE_ERR,
&st_EC20LinkVar.s_FileCloseInfo[0],
sizeof(st_EC20LinkVar.s_FileCloseInfo));
if(SUCC == retFunc)
{
st_EC20LinkVar.u16_FileErrCode = atoi((char*)&st_EC20LinkVar.s_FileCloseInfo[0]);
// ret = PROC_JUMP_EXIT;
(*status) = M_FTP_QFCLOSE_ERR; //
DEBUG_printf(DEBUG_UART,"M_FTP_QFCLOSE_ING u16_FileErrCode %d \r\n",st_EC20LinkVar.u16_FileErrCode);
}
}
else if( g32_DiffSec > 8)
{
(*status) = M_FTP_QFCLOSE_ERR; //
DEBUG_printf(DEBUG_UART,"M_FTP_QFCLOSE_ERR timeout \r\n");
}
break;
case M_FTP_QFSEEK_ING:
g32_NowSec = Sys_GetSec();
g32_DiffSec = g32_NowSec - g32_LastSec;
if(TRUE == st_EC20RecvCmd)
{
st_EC20RecvCmd = FALSE;
retFunc = Alg_EC20Link_ParseInfo(EC20_FILE_OK,
&st_EC20LinkVar.s_FileCloseInfo[0],
sizeof(st_EC20LinkVar.s_FileCloseInfo));
if(SUCC == retFunc)
{
(*status) = M_FTP_QFSEEK_OK; //
DEBUG_printf(DEBUG_UART,"M_FTP_QFSEEK_OK \r\n");
// ret = PROC_JUMP_EXIT;
}
retFunc = Alg_EC20Link_ParseInfo(EC20_FILE_ERR,
&st_EC20LinkVar.s_FileCloseInfo[0],
sizeof(st_EC20LinkVar.s_FileCloseInfo));
if(SUCC == retFunc)
{
st_EC20LinkVar.u16_FileErrCode = atoi((char*)&st_EC20LinkVar.s_FileCloseInfo[0]);
(*status) = M_FTP_QFSEEK_ERR; //
DEBUG_printf(DEBUG_UART,"M_FTP_QFSEEK_ERR \r\n");
}
}
else if( g32_DiffSec > 8)
{
(*status) = M_FTP_QFSEEK_ERR; //
DEBUG_printf(DEBUG_UART,"M_FTP_QFSEEK_ERR timeout \r\n");
}
break;
case M_FTP_QFREAD_ING:
g32_NowSec = Sys_GetSec();
g32_DiffSec = g32_NowSec - g32_LastSec;
if(TRUE == st_EC20RecvCmd)
{
st_EC20RecvCmd = FALSE;
if(0 == s_u16_recvFirstFlag)
{
retFunc = Alg_EC20Link_ParseInfo(EC20_FILE_RW_ANS,
&st_EC20LinkVar.s_FileReadInfo[0],
sizeof(st_EC20LinkVar.s_FileReadInfo));
if(NULL == retFunc)
{
m_u8_EC20RecvLenth = 0;
DEBUG_printf(DEBUG_UART,"M_FTP_QFREAD_ING retFunc = NULL \r\n");
}
else if(SUCC == retFunc)
{
st_EC20LinkVar.u16_FileTransLen = atoi((char*)&st_EC20LinkVar.s_FileReadInfo[0]);
retHeader = (char*)&m_u8_EC20RecvBuff[0];
retStr = strstr((char*)&m_u8_EC20RecvBuff[0],EC20_FILE_RW_ANS);//GET
retStr = strstr(retStr,"\r\n");
retTail = retStr + strlen("\r\n");
u32FileLenth = retTail - retHeader;
m_u8_EC20RecvLenth -= u32FileLenth;
s_u16_recvFirstFlag = 1;
DEBUG_printf(DEBUG_UART,"M_FTP_QFREAD_ING st_EC20LinkVar.u16_FileTransLen %d\r\n",st_EC20LinkVar.u16_FileTransLen);
DEBUG_printf(DEBUG_UART,"M_FTP_QFREAD_ING u32FileLenth %d\r\n",u32FileLenth);
DEBUG_printf(DEBUG_UART,"M_FTP_QFREAD_ING m_u8_EC20RecvLenth %d\r\n",m_u8_EC20RecvLenth);
}
}
if(m_u8_EC20RecvLenth >= (st_EC20LinkVar.u16_FileTransLen + 6 - s_u32_Revclenth))
{
s_u32_PutBufferlenth = st_EC20LinkVar.u16_FileTransLen - s_u32_Revclenth;
}
else
{
s_u32_PutBufferlenth = m_u8_EC20RecvLenth;
}
memcpy(&m_u8_FileRecvBuffer[s_u32_Revclenth],&m_u8_EC20RecvBuff[u32FileLenth],s_u32_PutBufferlenth);
s_u32_Revclenth += s_u32_PutBufferlenth;
DEBUG_printf(DEBUG_UART,"M_FTP_QFREAD_ING s_u32_PutBufferlenth %d\r\n",s_u32_PutBufferlenth);
DEBUG_printf(DEBUG_UART,"M_FTP_QFREAD_ING s_u32_Revclenth %d\r\n",s_u32_Revclenth);
if(s_u32_Revclenth == st_EC20LinkVar.u16_FileTransLen)
{
retHeader = (char*)&m_u8_EC20RecvBuff[u32FileLenth] + s_u32_PutBufferlenth;
retStr = strstr(retHeader,"\r\nOK\r\n");
if(NULL != retStr)
{
DEBUG_printf(DEBUG_UART,"BSP_FLASH_Write st_EC20LinkVar.u32_FilePosition %d\r\n",st_EC20LinkVar.u32_FilePosition);
if(BSP_OK == EE_Write_CHECK((st_EC20LinkVar.u32_FilePosition + EE_OTAFileAddr),
(uint16_t*)m_u8_FileRecvBuffer,
(st_EC20LinkVar.u16_FileTransLen )));
{
DEBUG_printf(DEBUG_UART,"EE_Write_CHECK over %d\r\n",st_EC20LinkVar.u16_FileTransLen);
s_u16_recvFirstFlag = 0;
s_u32_Revclenth = 0;
s_u32_PutBufferlenth= 0;
memset(&m_u8_FileRecvBuffer[0],0,EC20_RECV_BUFF_SIZE);
//ret = PROC_JUMP_NEXT;
(*status) = M_FTP_QFREAD_ING1;
(*cmd) = M_FTP_QFREAD_ING1;
}
// if(BSP_OK == BSP_FLASH_Write((st_EC20LinkVar.u32_FilePosition + APP_ADDR),
// (uint16_t*)m_u8_FileRecvBuffer,
// (st_EC20LinkVar.u16_FileTransLen >> 1) + (st_EC20LinkVar.u16_FileTransLen % 2)));
// {
// DEBUG_printf(DEBUG_UART,"BSP_FLASH_Write over %d\r\n",st_EC20LinkVar.u16_FileTransLen);
// s_u16_recvFirstFlag = 0;
// s_u32_Revclenth = 0;
// s_u32_PutBufferlenth= 0;
// memset(&m_u8_FileRecvBuffer[0],0,EC20_RECV_BUFF_SIZE);
// //ret = PROC_JUMP_NEXT;
// (*status) = M_FTP_QFREAD_ING1;
// (*cmd) = M_FTP_QFREAD_ING1;
// }
}
}
retFunc = Alg_EC20Link_ParseInfo(EC20_FILE_ERR,
&st_EC20LinkVar.s_FileReadInfo[0],
sizeof(st_EC20LinkVar.s_FileReadInfo));
if(SUCC == retFunc)
{
st_EC20LinkVar.u16_FileErrCode = atoi((char*)&st_EC20LinkVar.s_FileReadInfo[0]);
s_u16_recvFirstFlag = 0;
s_u32_Revclenth = 0;
s_u32_PutBufferlenth = 0;
memset(&m_u8_FileRecvBuffer[0],0,EC20_RECV_BUFF_SIZE);
}
} //END if(TRUE == st_EC20RecvCmd)
else if( g32_DiffSec > 13)
{
(*status) = M_FTP_QFSEEK_ERR; //
DEBUG_printf(DEBUG_UART,"M_FTP_QFREAD_ING timeout \r\n");
}
break;
case M_FTP_QFREAD_ING1:
st_EC20LinkVar.u32_FilePosition += st_EC20LinkVar.u16_FileTransLen;
st_EC20LinkVar.u32_FileSaveSize += st_EC20LinkVar.u16_FileTransLen;
if(st_EC20LinkVar.u32_FtpFileDownloadSize <= st_EC20LinkVar.u32_FileSaveSize)
{
//ret = PROC_JUMP_EXIT;
DEBUG_printf(DEBUG_UART,"PROC_JUMP_EXIT \r\n");
DEBUG_printf(DEBUG_UART,"u32_FtpFileDownloadSize %d u32_FileSaveSize %d\r\n",
st_EC20LinkVar.u32_FtpFileDownloadSize,st_EC20LinkVar.u32_FileSaveSize);
(*status) = M_FTP_QFREAD_OK;
(*cmd) = M_FTP_QFREAD_OK;
}
else
{
// tempProcParm.Flag = PROC_FLAG_BUSY0;
(*status) = M_FTP_QFREAD_START;
(*cmd) = M_FTP_QFREAD_START;
DEBUG_printf(DEBUG_UART,"u32_FtpFileDownloadSize %d u32_FileSaveSize %d\r\n",
st_EC20LinkVar.u32_FtpFileDownloadSize,st_EC20LinkVar.u32_FileSaveSize);
}
break;
//static ValueState st_EC20RecvCmd;
// case M_QIOPEN_ING:
// g32_NowSec = Sys_GetSec();
// g32_DiffSec = g32_NowSec - g32_LastSec;
// pch = strstr(m_u8_EC20RecvBuff, EC20_SOCKET_OPEN_ANS);
// if (pch != NULL)
// {
// (*status) += 1; //M_QIOPEN_OK
// }
// else if( g32_DiffSec > 30)
// {
// (*status) += 2; //M_QIOPEN_ERR
// }
// pch = strstr(m_u8_EC20RecvBuff, EC20_SOCKET_OPEN_ANS_ERR);
// if (pch != NULL)
// {
// (*status) += 2; //M_QIOPEN_ERR
// }
// break;
// g32_NowSec = Sys_GetSec();
// g32_DiffSec = g32_NowSec - g32_LastSec;
// pch = strstr(ArryBuf, "RDY");
// if (pch != NULL)
// {
// (*status) += 1;
// }
// else if( g32_DiffSec > 6)
// {
// (*status) += 2;
// }
// break;
// case M_QICLOSE_ING:
// pch = strstr(m_u8_EC20RecvBuff, EC20_SOCKET_CLOSE_ANS);
// if (pch != NULL)
// {
// (*status) += 1;
// }
// else if( g_SysBaseTime.f2s == 1)
// {
// (*status) += 2;
// }
// break;
// case M_TCP_LOGIN_ING:
// if(M_TCP_COMM_PKTYPE_LOGIN_ACK == gs_TCPRecvLocalInfo.u32PK_Type)
// {
// (*status) = M_TCP_LOGIN_OK;
// }
// else if( g_SysBaseTime.f6s == 1)
// {
// //(*status) += 2;
// (*status) = M_TCP_LOGIN_ERR;
// }
// memset(&gs_TCPRecvLocalInfo,0,sizeof(gs_TCPRecvLocalInfo));
// // if (pch != NULL)
// // {
// // (*status) += 1;
// // }
// // else if( g_SysBaseTime.f2s == 1)
// // {
// // (*status) += 2;
// // }
// break;
// case M_TCP_DATAUP_ING:
// // pch = strstr(ArryBuf, EC20_SOCKET_CLOSE_ANS);
// // if (pch != NULL)
// // {
// // (*status) += 1;
// // }
// // else if( g_SysBaseTime.f2s == 1)
// // {
// // (*status) += 2;
// // }
// if(M_TCP_COMM_PKTYPE_DATAUP_ACK == gs_TCPRecvLocalInfo.u32PK_Type)
// {
// (*status) = M_TCP_DATAUP_OK;
// }
// else if( g_SysBaseTime.f6s == 1)
// {
// //(*status) += 2;
// (*status) = M_TCP_DATAUP_ERR;
// }
// memset(&gs_TCPRecvLocalInfo,0,sizeof(gs_TCPRecvLocalInfo));
// //临时调试:
// // (*status) = M_TCP_CIRCY_SEND_WAIT;
// // (*cmd) = M_TCP_CIRCY_SEND_WAIT;
// break;
// case M_QMTCFG_SETTING:
// pch = strstr(m_u8_EC20RecvBuff, str_OK);
// if (pch != NULL)
// {
// (*status) += 1;
// }
// else if( g_SysBaseTime.f2s == 1)
// {
// (*status) += 2;
// }
// break;
// case M_QMTOPEN_OPENING:
// g32_NowSec = Sys_GetSec();
// g32_DiffSec = g32_NowSec - g32_LastSec;
// pch = strstr(m_u8_EC20RecvBuff, str_OK);
// if (pch != NULL)
// {
// (*status) += 1;
// }
// else if( g32_DiffSec > 6)
// {
// (*status) += 2;
// }
// break;
// case M_QMTCONN_CONNING:
// pch = strstr(m_u8_EC20RecvBuff, str_OK);
// if (pch != NULL)
// {
// (*status) += 1;
// }
// else if( g_SysBaseTime.f2s == 1)
// {
// (*status) += 2;
// }
// break;
// case M_QMTPUBEX_PUBING:
// pch = strstr(m_u8_EC20RecvBuff, str_OK);
// if(pch != NULL)
// {
// (*status) += 1;
// }
// else if( g_SysBaseTime.f2s == 1)
// {
// (*status) += 2;
// }
// break;
// case M_QMTDISC_0_ING:
// pch = strstr(m_u8_EC20RecvBuff, str_OK);
// if (pch != NULL)
// {
// (*status) += 1;
// }
// else if( g_SysBaseTime.f2s == 1)
// {
// (*status) += 2;
// }
// break;
default:
lu32_status = (uint32_t)(*status);
//DEBUG_printf(0,"EC200N status = %u NO CHANGE \r\n",lu32_status);
goto JUMP_CMD_RES_HANDEL;
break;
}
lu32_status = (uint32_t)(*status);
if(gLastSTA != lu32_status)
{
DEBUG_printf(DEBUG_UART,"EC200N status = %u \r\n",lu32_status);
}
gLastSTA = lu32_status;
JUMP_CMD_RES_HANDEL:
lu32_status = (uint32_t)(*status);
switch ( lu32_status )
{
case M_EC20_HARD_RESET_OK:
HAL_Delay(1000);
MX_FEED_IWDG();
HAL_Delay(1000);
MX_FEED_IWDG();
HAL_Delay(1000);
MX_FEED_IWDG();
(*cmd) = M_SIM_CHECK_START;
break;
case M_EC20_HARD_RESET_ERR:
(*cmd) = M_EC20_HARD_RESET_START;
break;
case M_AT_TEST_OK:
(*cmd) = M_SIM_CHECK_START;
break;
case M_SIM_CHECK_OK:
(*cmd) = M_CSQ_CHECK_START;
break;
case M_SIM_CHECK_ERR:
(*cmd) = M_EC20_HARD_RESET_START;
break;
case M_CSQ_CHECK_OK:
(*cmd) = M_CGATT_CHECK_START;
break;
case M_CGATT_CHECK_OK:
if(0)
{
(*cmd) = M_QMTCFG_SET_START;
}
else //如果是TCP模式的话,
{
(*cmd) = M_QIACT1_SET_START;
}
break;
case M_CGATT_CHECK_ERR:
(*cmd) = M_SIM_CHECK_START;
break;
case M_QIACT1_SET_OK:
if(0)
{
(*cmd) = M_QMTCFG_SET_START;
}
else //如果是TCP模式的话,
{
(*cmd) = M_QUERY_QIACT_START;
}
break;
case M_QIACT1_SET_ERR:
//如果设置不成功,直接查询 PDP场景
(*cmd) = M_QUERY_QIACT_START;
break;
case M_QUERY_QIACT_OK:
(*cmd) = M_FTP_CFG_CONTID_START;
break;
case M_QUERY_QIACT_ERR:
(*cmd) = M_EC20_HARD_RESET_START;
break;
// case M_QIOPEN_OK:
// (*cmd) = M_TCP_LOGIN_START;
// break;
// case M_QIOPEN_ERR:
// (*cmd) = M_SIM_CHECK_START;
// break;
// case M_TCP_LOGIN_OK:
// gu16_LoginRetryCnt = 0;
// (*cmd) = M_TCP_DATAUP_START;
// break;
// case M_TCP_LOGIN_ERR:
// if(gu8_debug)
// {
// //临时修改 如果登录不成功 直接继续 DATAUP
// (*cmd) = M_TCP_DATAUP_START;
// (*status) = M_TCP_DATAUP_START;
// }
// else
// {
// gu16_LoginRetryCnt++;
// (*cmd) = M_TCP_LOGIN_START;
// (*status) = M_TCP_LOGIN_START;
// if(gu16_LoginRetryCnt > 3 )
// {
// (*cmd) = M_EC20_HARD_RESET_START;
// }
// }
// break;
// case M_TCP_DATAUP_OK:
// gu16_DataUpRetryCnt = 0;
// (*cmd) = M_TCP_CIRCY_SEND_WAIT;
// (*status) = M_TCP_CIRCY_SEND_WAIT;
// g32_LastSec = Sys_GetSec();
// break;
// case M_TCP_DATAUP_ERR:
// if(gu8_debug)
// {
// //临时修改 如果登录不成功 直接继续 DATAUP
// (*cmd) = M_TCP_DATAUP_START;
// }
// else
// {
// (*cmd) = M_TCP_DATAUP_START;
// (*status) = M_TCP_DATAUP_START;
// if(gu16_DataUpRetryCnt > 3 )
// {
// (*cmd) = M_EC20_HARD_RESET_START;
// }
// }
// break;
// case M_TCP_CIRCY_SEND_WAIT:
// //当前是循环发送模式
// g32_NowSec = Sys_GetSec();
// g32_DiffSec = g32_NowSec - g32_LastSec;
// if(g32_DiffSec > M_TCP_DATAUP_INTER_S)
// {
// (*cmd) = M_TCP_DATAUP_START;
// }
// break;
// case M_QMTCFG_SET_OK:
// (*cmd) = M_QMTOPEN_OPEN_START;
// break;
// case M_QMTCFG_SET_ERR:
// (*cmd) = M_QMTDISC_0_START;
// break;
// case M_QMTOPEN_OPEN_OK:
// (*cmd) = M_QMTCONN_CONN_START;
// break;
// case M_QMTOPEN_OPEN_ERR:
// (*cmd) = M_QMTDISC_0_START;
// break;
// case M_QMTCONN_CONN_OK:
// (*cmd) = M_QMTPUBEX_PUB_START;
// break;
// case M_QMTCONN_CONN_ERR:
// (*cmd) = M_QMTDISC_0_START;
// break;
// case M_QMTDISC_0_OK:
// (*cmd) = M_QMTOPEN_OPEN_START;
// break;
// case M_QMTDISC_0_ERR:
// (*cmd) = M_QMTOPEN_OPEN_START;
// break;
// //新修改的
// case M_QMTPUBEX_PUB_ERR:
// (*cmd) = M_QMTOPEN_OPEN_START;
// break;
// case M_QMTPUBEX_PUB_OK:
// //当前是循环发送模式
// (*cmd) = M_CIRCY_SEND_WAIT;
// (*status) = M_CIRCY_SEND_WAIT;
// g32_LastSec = Sys_GetSec();
// break;
// case M_CIRCY_SEND_WAIT:
// //当前是循环发送模式
// g32_NowSec = Sys_GetSec();
// g32_DiffSec = g32_NowSec - g32_LastSec;
// if(g32_DiffSec > 0)
// {
// (*cmd) = M_QMTPUBEX_PUB_START;
// }
// break;
/*FTP*/
case M_FTP_CFG_CONTID_OK:
(*cmd) = M_FTP_CFG_ACC_START;
break;
case M_FTP_CFG_CONTID_ERR:
(*cmd) = M_FTP_CFG_CONTID_START;
break;
case M_FTP_CFG_ACC_OK:
(*cmd) = M_FTP_CFG_FT_START;
break;
case M_FTP_CFG_ACC_ERR:
(*cmd) = M_FTP_CFG_CONTID_START;
break;
case M_FTP_CFG_FT_OK:
(*cmd) = M_FTP_CFG_TM_START;
break;
case M_FTP_CFG_FT_ERR:
(*cmd) = M_FTP_CFG_CONTID_START;
break;
case M_FTP_CFG_TM_OK:
(*cmd) = M_FTP_CFG_RSPT_START;
break;
case M_FTP_CFG_TM_ERR:
(*cmd) = M_FTP_CFG_CONTID_START;
break;
case M_FTP_CFG_RSPT_OK:
(*cmd) = M_FTP_QFTPOPEN_START;
break;
case M_FTP_CFG_RSPT_ERR:
(*cmd) = M_FTP_CFG_CONTID_START;
break;
case M_FTP_QFTPOPEN_OK:
(*cmd) = M_FTP_QFTPCWD_START;
break;
case M_FTP_QFTPOPEN_ERR:
(*cmd) = M_FTP_QFTPCLOSE_START;
break;
case M_FTP_QFTPCLOSE_OK:
(*cmd) = M_FTP_CFG_CONTID_START;
break;
case M_FTP_QFTPCLOSE_ERR:
(*cmd) = M_EC20_HARD_RESET_START;
break;
case M_FTP_QFTPCWD_OK:
(*cmd) = M_FTP_QFTPSIZE_START;
break;
case M_FTP_QFTPCWD_ERR:
(*cmd) = M_FTP_QFTPCLOSE_START;
break;
case M_FTP_QFTPSIZE_OK:
(*cmd) = M_FTP_QFTPGET_START;
break;
case M_FTP_QFTPSIZE_ERR:
(*cmd) = M_FTP_QFTPCLOSE_START;
break;
case M_FTP_QFTPGET_OK:
(*cmd) = M_FTP_QFOPEN_START;
break;
case M_FTP_QFTPGET_ERR:
if( 613 == st_EC20LinkVar.u16_FtpErrCode ) //文件错误
{
gSavedLastCMD = M_FTP_QFTPGET_ERR;
gSavedLastSTA = M_FTP_QFTPGET_ERR;
(*cmd) = M_FTP_QFDELUFSALL_START; //删除4G模块内部的UFS系统内的所有文件
}
else
{
(*cmd) = M_FTP_QFTPCLOSE_START;
}
break;
case M_FTP_QFDELUFSALL_OK:
if( M_FTP_QFTPGET_ERR == gSavedLastSTA )
{
(*cmd) = M_FTP_QFTPGET_START;
}
else
{
(*cmd) = M_FTP_QFTPCLOSE_START;
}
break;
case M_FTP_QFDELUFSALL_ERR:
(*cmd) = M_FTP_QFCLOSE_START;
break;
case M_FTP_QFOPEN_OK:
(*cmd) = M_FTP_QFSEEK_START;
break;
case M_FTP_QFOPEN_ERR:
(*cmd) = M_FTP_QFTPCLOSE_START;
break;
case M_FTP_QFCLOSE_OK:
(*cmd) = M_FTP_CFG_CONTID_START;
break;
case M_FTP_QFCLOSE_ERR:
(*cmd) = M_EC20_HARD_RESET_START;
break;
case M_FTP_QFSEEK_OK:
(*cmd) = M_FTP_QFREAD_START;
break;
case M_FTP_QFSEEK_ERR:
(*cmd) = M_FTP_QFTPCLOSE_START;
break;
case M_FTP_QFREAD_OK:
(*cmd) = M_FTP_QFREAD_OK;
gs_DecCmd.SysCmd = M_OTA_JUMP;
uint32_t lu32_filelen = st_EC20LinkVar.u32_FtpFileDownloadSize;
char str_md5[80];
DEBUG_printf(DEBUG_UART,"MD5 cal start lu32_filelen= %d \r\n",lu32_filelen);
//get_flash_md5("C",lu32_filelen,&str_md5[0]);
get_EEPROM_md5("C",lu32_filelen,&str_md5[0]);
DEBUG_printf(DEBUG_UART,"MD5 = %s\r\n",str_md5);
break;
case M_FTP_QFREAD_ERR:
(*cmd) = M_FTP_QFSEEK_START;
break;
default:
lu32_cmd = (uint32_t)(*cmd);
//DEBUG_printf(DEBUG_UART,"EC200N CMD = %u UNHANDLE\r\n",lu32_cmd);
//DEBUG_printf(0,"EC200N cmd = %u NO CHANGE \r\n",lu32_cmd);
//SEGGER_RTT_printf(0,"RTT cmd = %u NO CHANGE \r\n",lu32_cmd);
return ERROR;
break;
}
lu32_cmd = (uint32_t)(*cmd);
if( lu32_cmd!= gLastCMD)
{
DEBUG_printf(DEBUG_UART,"EC200N cmd = %u \r\n",lu32_cmd);
}
gLastCMD = lu32_cmd;
}
// typedef enum
// {
// M_T_4G_IDLE = 0x0000,
// M_T_SETOTA, //1
// M_T_LOGINACK,//2
// M_T_DATAUPACK//2
// } enum_TEST_4G;
// uint16_t F_TEST_TCP_COMM(enum_TEST_4G *cmd)
// {
// uint32_t lu32_cmd = 0;
// ErrorStatus l_err = SUCCESS;
// lu32_cmd = (*cmd);
// switch (lu32_cmd)
// {
// case M_T_4G_IDLE:
// /* code */
// break;
// case M_T_SETOTA: //1
// /* code */
// l_err = F_TCP_SETOTAPack();
// if(SUCCESS == l_err)
// {
// gu16_SendLen = gs_TCP_DataPack.u32Length;
// memcpy(&Sendbuf,&gu8A_TCPToalDataBag,gu16_SendLen);
// HAL_UART_Transmit(&huart1, (uint8_t *)&Sendbuf,gu16_SendLen, 0xffff);
// (*cmd) = M_T_4G_IDLE;
// }
// break;
// case M_T_LOGINACK: //3
// /* code */
// l_err = F_TCP_LoginAckPack();
// if(SUCCESS == l_err)
// {
// gu16_SendLen = gs_TCP_DataPack.u32Length;
// memcpy(&Sendbuf,&gu8A_TCPToalDataBag,gu16_SendLen);
// HAL_UART_Transmit(&huart1, (uint8_t *)&Sendbuf,gu16_SendLen, 0xffff);
// (*cmd) = M_T_4G_IDLE;
// }
// break;
// case M_T_DATAUPACK:
// /* code */
// break;
// default:
// break;
// }
// }
/******************************************************************************
* Name : Alg_EC20Link_ParseInfo
* brief : None.
* param : None.
* retval : BSP status
*******************************************************************************/
FuncState Alg_EC20Link_ParseInfo(char* pChar,char* pDstStr,uint16_t dstLenth)
{
char *pTempStr;
char *pTempStrHead;
char *pTempStrTail;
uint16_t tempLenth;
FuncState ret = FAIL;
// pTempStr = strstr((char*)&m_u8_EC20RecvBuff[0],pChar);
pTempStr = strstr((char*)&m_u8_EC20RecvBuff[0],pChar);
if(NULL != pTempStr)
{
pTempStrHead = pTempStr + strlen(pChar);
pTempStrTail = strstr(pTempStrHead,"\r\n");
if(pTempStrTail < pTempStrHead)
{
pTempStrHead = pTempStr;
}
tempLenth = pTempStrTail - pTempStrHead;
tempLenth = MIN(tempLenth,dstLenth);
memset(pDstStr,0x00,dstLenth);
memcpy(pDstStr,pTempStrHead,tempLenth);
ret = SUCC;
}
return ret;
}
void APP_EC20Link_Init(void)
{
uint16_t i;
char *retStr = NULL;
char *retStr1 = NULL;
char *retStrHead = NULL;
char *retStrTail = NULL;
uint16_t tempLenth;
// for(i = 0;i < EC20LINK_FUNC_OBJS_LENTH;i++)
// {
// memset(&st_ProcParm[i],0,sizeof(_ProcParmType_Def));
// }
// m_u16_TimeSliceIndex = 0;
// st_TimeSliceState = FALSE;
// st_EC20SendCmd = FALSE;
st_EC20RecvCmd = FALSE;
st_EC20RestCmd = FALSE;
st_EC20DownloadCmd = FALSE;
// st_EC20BurnCmd = FALSE;
//memset(&m_u8_EC20SendBuff[0],0,EC20_SEND_BUFF_SIZE);
memset(&m_u8_EC20RecvBuff[0],0,EC20_RECV_BUFF_SIZE);
//m_u8_EC20SendLenth = 0;
m_u8_EC20RecvLenth = 0;
//memset(&st_PrcoStateAll,0,sizeof(_ProcStateAllType_Def));
//m_u32_SignalQLTYCnt = 0;
memset(&st_EC20LinkVar,0,sizeof(_ProcVariableAllType_Def));
// for(i = 0;i < EC20LINK_FUNC_OBJS_LENTH;i++)
// {
// if(PROC_CLASS_REST == EC20LinkFuncObjs[i].ProcClass)
// {
// st_ProcParm[i].Ctl = PROC_CTL_ENBL;
// break;
// }
// }
st_EC20LinkVar.u16_FtpPortNum = 21;
st_EC20LinkVar.u8_FtpContextID = 1;
st_EC20LinkVar.u8_FtpFileType = 0;
st_EC20LinkVar.u8_FtpTransMode = 1;
st_EC20LinkVar.u8_FtpTimeOut1S = 90;
//GPIO_SetBits(GPIOE, GPIO_Pin_12);
// if(gs_TCPRecInfoOTA.u16_FLG == )
// gs_TCPRecInfoOTA.
// retStr = strstr((char*)&m_u8_EC20RecvBuff[0],M_OTA_IPAITE);
// retStrHead = retStr + sizeof(EC20_FTP_CWD_FOLDER_ANS) - 1;
// retStrTail = strstr(retStrHead,"\r\n");
// tempLenth = retStrTail - retStrHead;
// tempLenth = MIN(tempLenth,sizeof(st_EC20LinkVar.s_FtpFolderInfo));
// retStr = strstr((char*)&gs_TCPRecInfoOTA.ucA_OTA_URL[0],M_OTA_IPAITE);
// if(NULL != retStr)
// {
// retStrHead = retStr + sizeof(M_OTA_IPAITE);
// retStrTail = strstr(retStrHead,"\\");
// tempLenth = retStrTail - retStrHead;
// tempLenth = MIN(tempLenth,sizeof(st_EC20LinkVar.s_FtpServerDMN));
// memcpy(&st_EC20LinkVar.s_FtpServerDMN[0],retStrHead,tempLenth);
// }
memcpy(&st_EC20LinkVar.s_FtpFilePath[0],&stBoot2.FilePath[0],STRING_FILE_PATH_LEN);
memcpy(&st_EC20LinkVar.s_FtpServerDMN[0],&stBoot2.ServerDMN[0],STRING_SERVER_DMN_LEN);
memcpy(&st_EC20LinkVar.s_FtpFileName[0],&stBoot2.FileName[0],STRING_FILE_NAME_LEN);
memcpy(&st_EC20LinkVar.s_FtpUserName[0],&stBoot2.UserName[0],STRING_USER_NAME_LEN);
memcpy(&st_EC20LinkVar.s_FtpUserPassword[0],&stBoot2.PassWord[0],STRING_PASSWORD_LEN);
DEBUG_printf(DEBUG_UART,"BOOT st_EC20LinkVar s_FtpFilePath %s\r\n",st_EC20LinkVar.s_FtpFilePath);
DEBUG_printf(DEBUG_UART,"BOOT st_EC20LinkVar s_FtpServerDMN %s\r\n",st_EC20LinkVar.s_FtpServerDMN);
DEBUG_printf(DEBUG_UART,"BOOT st_EC20LinkVar s_FtpFileName %s\r\n",st_EC20LinkVar.s_FtpFileName);
DEBUG_printf(DEBUG_UART,"BOOT st_EC20LinkVar s_FtpUserName %s\r\n",st_EC20LinkVar.s_FtpUserName);
DEBUG_printf(DEBUG_UART,"BOOT st_EC20LinkVar s_FtpUserPassword %s\r\n",st_EC20LinkVar.s_FtpUserPassword);
// strcpy(&st_EC20LinkVar.s_FtpUserName[0], "cartech");
// strcpy(&st_EC20LinkVar.s_FtpUserPassword[0],"n13CF16thA");
// strcpy(&st_EC20LinkVar.s_FtpServerDMN[0], "39.98.76.17");
// strcpy(&st_EC20LinkVar.s_FtpFilePath[0], "/test");
// strcpy(&st_EC20LinkVar.s_FtpFileName[0], "SMP0100A00PRO.bin");
}
// {
// "type":"variant_data",
// "version":"1.0",
// "time":1638766638000,
// "params":
// {
// "UAV":0.1,
// "UBV":0.1,
// "UCV":0.1,
// "IAA":0.1,
// "IBA":0.1,
// "ICA":0.1,
// "PAW":0.0,
// "PBW":0.0,
// "PCW":10178313.0,
// "PTW":10178313.0
// }
// }
程序跳转前一定要关闭中断,不然会出一些让你摸不到头脑的问题。
?