stm32_ota/USER/USERCMD/usercmd.c

128 lines
5.6 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "usercmd.h"
#include "flash.h"
#include "usart.h"
#include "sysport.h"
#include "user_tcp.h"
#include "userapp.h"
#include "osPort.h"
#include "logflash.h"
#include "key.h"
#include "user_ftp.h"
#include "user_tcp.h"
/******************************************************************************
*供外部使用的常变量定义
*******************************************************************************/
/*用来保存FLASH内的配置信息*/
IAPFlash_u uIapFlash ; //定义IAPFlash_u共用体变量
/*********************************************************************************************************************
* 名 称void InitIapFlashConfig( IAPFlash_u *config )
* 功 能先从FLASH读出IAPFlash信息然后对IAPFlash_u类型的全局变量初始化最终再写入FLASH中
* 说 明读取RunAppNum更新FLASH中的RunAppNum标志位
*********************************************************************************************************************/
void InitIapFlashConfig( IAPFlash_u *config )
{
Get_uIapFlash(config) ; //从FLASH中读取IAP信息到共用体变量uIapFlash中
config->sIapFlash.Head = '[' ; //帧头初始化
if((uint8_t)config->sIapFlash.IapFlag == 0xff ) /*未配置过IapFlag*/
{
config->sIapFlash.IapFlag = 0x31 ; //升级标志位初始化
}
if((uint8_t)config->sIapFlash.RunAppNum == 0xff ) /*未配置过RunAppNum*/
{
config->sIapFlash.RunAppNum = 0x31 ; //RunAppNum初始化
}
if((uint8_t)config->sIapFlash.JumpResult == 0xff ) /*未配置过JumpResult*/
{
config->sIapFlash.JumpResult = 0x31 ; //JumpResult初始化系统从boot跳转到APP成功将JumpResult位设置为true并写入FLASH。//如果BOOT启动判断该为为false则判定APP有问题直接运行应急程序APP1
}
if((uint8_t)config->sIapFlash.FtpFolder[0] == 0xff ) /*未配置过FtpFolder*/
{
memset( config->sIapFlash.FtpFolder, 0, FOLDER_MAXLEN) ;
strcpy( config->sIapFlash.FtpFolder, "/firmware") ; //如果未配置FtpFolder则将默认路径设置为/ABM
}
else
{
SetAppFtpDir(&sFtpBoot, config->sIapFlash.FtpFolder) ;
}
if( (uint8_t)config->sIapFlash.FtpUsername[0] == 0xff ) /*FLASH中存储ftp用户名的字段有效*/
{
memset( config->sIapFlash.FtpUsername, 0, USERNAME_MAXLEN) ;
strcpy( config->sIapFlash.FtpUsername, "caiyu") ; //如果未配置FtpUsername则将FTP默认用户名设置为ABM
}
else
{
SetAppFtpUsername(&sFtpBoot, config->sIapFlash.FtpUsername) ;
}
if((uint8_t)config->sIapFlash.FtpPassword[0] == 0xff) /*FLASH中存储ftp用户名密码的字段无效*/
{
memset( config->sIapFlash.FtpPassword, 0, PASSWORD_MAXLEN) ;
strcpy( config->sIapFlash.FtpPassword, "aa") ; //如果未配置FtpUsername则将FTP默认用户名密码设置为Shop344794749
}
else
{
SetAppFtpPassword(&sFtpBoot, config->sIapFlash.FtpPassword) ;
}
if( (uint8_t)config->sIapFlash.FtpIP[0] == 0xff ) /*FLASH中存储FtpIP字段无效*/
{
memset( config->sIapFlash.FtpIP, 0, MAX_IP_LEN) ;
strcpy( config->sIapFlash.FtpIP, "58.23.31.118") ; //如果未配置FtpIP则将FTP服务器IP设置为"121.5.217.252"
}
else
{
SetAppFtpIP(&sFtpBoot, config->sIapFlash.FtpIP) ;
}
if( ((uint8_t)config->sIapFlash.TcpIP[0] == 0xFF) ||
((uint8_t)config->sIapFlash.TcpIP[0] == 0x00)) /*FLASH中存储FtpIP字段无效*/
{
memset( config->sIapFlash.TcpIP, 0, MAX_IP_LEN) ;
strcpy( config->sIapFlash.TcpIP, TCP_CONNECTID0_SERVERIP0) ;//如果未配置FtpIP则将FTP服务器IP设置为TCP_CONNECTID0_SERVERIP0
}
else /*FLASH中存储FtpIP字段有效将s_Channal0缺省IP修改为配置IP*/
{
SetAppTcpIP(&sChannal0, uIapFlash.sIapFlash.TcpIP ) ; //更新TCP服务器的IP
}
if( ((uint8_t)config->sIapFlash.TcpPort[0] == 0xFF) ||
((uint8_t)config->sIapFlash.TcpPort[0] == 0x00) ) /*FLASH中存储FtpIP字段无效*/
{
memset( config->sIapFlash.TcpPort, 0, PORT_MAXLEN) ;
char port[PORT_MAXLEN] = {0} ;
itoa(TCP_CONNECTID0_SERVERPORT0, port, 10);
strcpy( config->sIapFlash.TcpPort, port) ; //如果未配置TcpPort则将FTP服务器IP设置为TCP_CONNECTID0_SERVERPORT0
}
else
{
SetAppTcpPort(&sChannal0, uIapFlash.sIapFlash.TcpPort ) ; //更新TCP服务器的port
}
config->sIapFlash.Tail = ']' ; //帧尾初始化
Set_uIapFlash(config) ; //将初始化信息重新写入FLASH中
}
/**************************************************************************************************
* 名 称: void Get_uIapFlash(IAPFlash_u *config)
* 功能说明: 从内部flash中IAPCONFIG_AREA_ADDR地址读取一页获取FLASH中的IAP信息
* 入口参数:
* @param1 *uIapInfo IAPFlash_u共用体变量指针
**************************************************************************************************/
void Get_uIapFlash(IAPFlash_u *config)
{
memset( config->iapFlashBuffer , 0, IAPFLASHCONFIGLEN) ;
Read_Flash_Byte(IAPCONFIG_AREA_ADDR, uIapFlash.iapFlashBuffer, IAPFLASHCONFIGLEN) ;
}
/**************************************************************************************************
* 名 称: void Set_uIapFlash(IAPFlash_u *config)
* 功能说明: 将新的IAP信息写入FLASH
* 入口参数:
* @param1 *uIapInfo IAPFlash_u共用体变量指针
**************************************************************************************************/
void Set_uIapFlash(IAPFlash_u *config)
{
Write_Flash_OnePage(IAPCONFIG_AREA_ADDR, config->iapFlashBuffer, IAPFLASHCONFIGLEN) ;
}