#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) ; }