stm32_ota/USER/USERAPP/userapp.c

383 lines
16 KiB
C
Raw Normal View History

2023-12-15 06:28:06 +00:00
#include "userapp.h"
#include <string.h>
#include <stdlib.h>
/********************************************************************************
* @file userapp.c
* @author <EFBFBD>̳ϿƼ<EFBFBD> Mr.Wang
* @version V1.0.0
* @date 11-Dec-2018
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>SmartGateӦ<EFBFBD>ó<EFBFBD><EFBFBD>򣬶<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD>װ
******************************************************************************
* @attention
* <EFBFBD><EFBFBD><EFBFBD>жԳ<EFBFBD>USER<EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD>װ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>gateapp<EFBFBD><EFBFBD>
*******************************************************************************/
/*********Ӧ<>ò<EFBFBD><C3B2>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>*******************************************************/
#include "usart.h" //printf
#include "watchdog.h"
#include "ec20module.h"
#include "ec20net.h"
#include "ec20tcp.h"
#include "ec20http.h" //RunResult Send_Post( POSTP_s *psHttpP, char* postBody )
#include "user_key.h"
#include "sysport.h"
#include "malloc.h"
#include "cjson.h"
#include "rtc.h"
#include "beep.h"
#include "led.h"
#include "logflash.h"
#include "syslib.h"
#include "user_oled.h"
#include "user_ftp.h"
#include "user_tcp.h"
#include "user_http.h"
#include "gate_timer.h"
#include "usercmd.h"
#include "logflash.h"
#include "io.h"
#include "pvd.h"
#include "oled.h"
#include "stm32Temp.h"
#include "iap.h"
/**********************************************************************************/
/**********************************************************************************
*<EFBFBD>ڲ<EFBFBD>ʹ<EFBFBD>õij<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
**********************************************************************************/
/**********************************************************************************
*<EFBFBD><EFBFBD><EFBFBD>ⲿʹ<EFBFBD>õij<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***********************************************************************************/
Application gateApp ; //gateApp<70><70><EFBFBD><EFBFBD>Ӧ<EFBFBD>ò<EFBFBD><C3B2><EFBFBD>
DownFileP_s sDownApp ; //sDownApp<70><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><D8B2><EFBFBD><EFBFBD>Ľṹ<C4BD><E1B9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
NETSTATUS_s sNetStatus ; //NETSTATUS_s<5F><EFBFBD><E1B9B9><EFBFBD><EFBFBD><EFBFBD>ͱ<EFBFBD><CDB1><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD>״̬
/**************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> void Board_Init(void)
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܿ<EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
**************************************************************************************************/
void Board_Init(void)
{
SysTick_Init() ; //ϵͳ<CFB5>δ<EFBFBD><CEB4><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC> 1ms<6D>ж<EFBFBD>һ<EFBFBD><D2BB> <20>ж<EFBFBD><D0B6>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ι<EFBFBD><CEB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
MyMenInit(SRAMIN) ; //<2F><>̬<EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
// Watchdog_Init() ; //<2F><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD>ɿ<EFBFBD><C9BF><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD>Ź<EFBFBD>
// RTC_Init(INT_RANK_15) ; //ʵʱʱ<CAB1>ӳ<EFBFBD>ʼ<EFBFBD><CABC>
// PrintfDeviceInfo() ; //UART_DEBUG<55><47><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD>Ϣ
// Watchdog_Feed() ; //<2F><><EFBFBD>Ź<EFBFBD>ι<EFBFBD><CEB9>
Gpio_Init(PC, PIN8, GPIO_Mode_Out_PP) ;
GPIO_WriteBit(GPIOC,PIN8,Bit_SET);
//KeyInit() ; //<2F><>ʼ<EFBFBD><CABC>KEY<45><59><EFBFBD><EFBFBD>
// Led_Init() ; //<2F><>ʼ<EFBFBD><CABC>LED
//Beep_Init() ; //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// OLED_Init() ; //OLED<45><44>ʼ<EFBFBD><CABC>
// RS232Init(115200) ; //RS232<33><32>ʼ<EFBFBD><CABC>
// RS485Init(115200) ; //RS485<38><35>ʼ<EFBFBD><CABC>
// Pvd_Init( EXTI_Trigger_Rising_Falling, INT_RANK_14) ;
// PWR_PVD_Init() ;
}
/**************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> RunResult FindAppFile(DownFileP_s *psFileParm)
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>sFtpBoot.ftpDirectoryĿ¼<EFBFBD>в<EFBFBD><EFBFBD>ң<EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>Ϊ24λMAC<EFBFBD><EFBFBD>ַ+.bin<EFBFBD><EFBFBD>/("CommonApp.bin")<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸Ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>fileName<EFBFBD><EFBFBD>eAppType
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param1 *psFileParm DownFileP_s<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param1 RUNOK <EFBFBD><EFBFBD>Ŀ¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>µĹ̼<EFBFBD>
* ˵ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> ec20AtBuf[EC20_ATBUF_LEN] 320<EFBFBD>ֽڣ<EFBFBD> <EFBFBD><EFBFBD><EFBFBD>Ե<EFBFBD>dir<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(EC20_ATBUF_LEN-50)ʱҲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֲ<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܡ<EFBFBD>
**************************************************************************************************/
RunResult NetDisconnetc(void)
{
RunResult result = RUNOK ;
if( TCPBIT_2 == true )
{
AppLogPrintf("BOOT<EFBFBD>Ͽ<EFBFBD>TCP<EFBFBD><EFBFBD><EFBFBD><EFBFBD>") ;
TcpDisconnetc() ; //<2F>Ͽ<EFBFBD>Socket ȥ<><C8A5><EFBFBD><EFBFBD>TCP<43><50>·<EFBFBD><C2B7>PDP
}
if( FTPBIT_4 == true )
{
AppLogPrintf("BOOTע<EFBFBD><EFBFBD>FTP<EFBFBD><EFBFBD>½!") ;
result = AppFtpClose() ; //FTPע<50><D7A2>
}
return result ;
}
/**************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> RunResult FindAppFile(DownFileP_s *psFileParm)
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>sFtpBoot.ftpDirectoryĿ¼<EFBFBD>в<EFBFBD><EFBFBD>ң<EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>Ϊ24λMAC<EFBFBD><EFBFBD>ַ+.bin<EFBFBD><EFBFBD>/("CommonApp.bin")<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸Ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>fileName<EFBFBD><EFBFBD>eAppType
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param1 *psFileParm DownFileP_s<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param1 RUNOK <EFBFBD><EFBFBD>Ŀ¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>µĹ̼<EFBFBD>
* ˵ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> ec20AtBuf[EC20_ATBUF_LEN] 320<EFBFBD>ֽڣ<EFBFBD> <EFBFBD><EFBFBD><EFBFBD>Ե<EFBFBD>dir<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(EC20_ATBUF_LEN-50)ʱҲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֲ<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܡ<EFBFBD>
**************************************************************************************************/
RunResult FindAppFile(DownFileP_s *psFileParm)
{
RunResult result = RUNERR ;
GetDeviceMacAddress(psFileParm->fileName, STRMACID) ;
strcat((char*)psFileParm->fileName, ".bin") ; //<2F><>Ҫ<EFBFBD><D2AA>ȡ<EFBFBD>¹̼<C2B9><CCBC>ļ<EFBFBD><C4BC><EFBFBD> <20><><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>Ϊ24λMAC<41><43>ַ+.bin<69><6E>
if(RUNOK == Ftp_Find_File( sFtpBoot.ftpDirectory, psFileParm->fileName ) ) //<2F><>FTP<54><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD><D0B2><EFBFBD>Ψһ<CEA8>¹̼<C2B9><CCBC><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>Ϊ24λMAC<41><43>ַ+.bin<69><6E>
{
psFileParm->eAppType = SelfApp ;
result = RUNOK ;
}
else //<2F><>FTP<54><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD><D0B2><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD>¹̼<C2B9><CCBC><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>CommonApp.bin<69><6E>
{
memset(psFileParm->fileName, 0, MAC_BYTES_LEN+4+1) ; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
strcat((char*)psFileParm->fileName, "App.bin") ; //<2F><><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
//result= Ftp_Find_File( sFtpBoot.ftpDirectory, psFileParm->fileName ) ; //<2F><>FTP<54><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD><D0B2><EFBFBD>ͨ<EFBFBD>ù̼<C3B9><CCBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>CommonApp.bin<69><6E>
if( kmp(ec20AtBuf, (char*)psFileParm->fileName) >= 0 )
{
psFileParm->eAppType = CommonApp ;
result = RUNOK ;
}
}
return (result) ;
}
/**************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> RunResult DownSubpackVerify(DownFileP_s *psFileParm, int *pHeadPos)
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>Ӱ<EFBFBD>Ȼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>й̼<EFBFBD><EFBFBD>Ϸ<EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸Ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>appFlashAddr(У<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>BIN<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>ǰ4<EFBFBD><EFBFBD><EFBFBD>ֽڴ<EFBFBD><EFBFBD>š<EFBFBD>ջ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>__initial_sp <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ľ<EFBFBD><EFBFBD>Ƕ<EFBFBD>ջ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>ַ <EFBFBD><EFBFBD><EFBFBD>DZ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ġ<EFBFBD>ջ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>)
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param1 *psFileParm DownFileP_s<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param1 RUNOK <EFBFBD>̼<EFBFBD>ջ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַУ<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
* @param2 RUNERR <EFBFBD>̼<EFBFBD>ջ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַУ<EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
* @param3 TIMEOUT <EFBFBD>̼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
* @param4 *pHeadPos <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ec20FtpBuf<EFBFBD>е<EFBFBD>ƫ<EFBFBD>Ƶ<EFBFBD>ַ
**************************************************************************************************/
RunResult DownSubpackVerify(DownFileP_s *psFileParm, int *pHeadPos)
{
RunResult result = RUNERR ;
*pHeadPos = Ftp_Down_File(psFileParm->fileName, 0, ONCE_DOWN_LEN) ; //<2F><><EFBFBD>ص<EFBFBD>һ<EFBFBD><D2BB><EFBFBD>Ӱ<EFBFBD>
if( *pHeadPos >= 0 ) /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳɹ<DDB3>*/
2023-12-20 10:22:52 +00:00
{
psFileParm->appFlashAddr = Check_AppNum(*(vu32*)((u32)&ec20FtpBuf[*pHeadPos+4])) ; //<2F><><EFBFBD><EFBFBD>APP<50>е<EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD>ַ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>APP2\APP3
if( psFileParm->appFlashAddr != 0) // <20>̼<EFBFBD>У<EFBFBD><D0A3><EFBFBD>Ϸ<EFBFBD>
{
result = RUNOK ;
}
else //<2F>̼<EFBFBD>У<EFBFBD><D0A3>ʧ<EFBFBD><CAA7>
{
result = RUNERR ;
2023-12-15 06:28:06 +00:00
}
2023-12-20 10:22:52 +00:00
}
2023-12-15 06:28:06 +00:00
else
2023-12-20 10:22:52 +00:00
{
result = TIMEOUT ;
}
2023-12-15 06:28:06 +00:00
return (result) ;
}
/**************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> RunResult DownOtherSubpack(DownFileP_s *psFileParm)
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¹̼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>subpack<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>sbupack<EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>FLASH<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param1 *psFileParm DownFileP_s<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param1 RUNOK <EFBFBD>̼<EFBFBD><EFBFBD><EFBFBD><EFBFBD>سɹ<EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>FLASH<EFBFBD>ɹ<EFBFBD>
* @param2 RUNERR <EFBFBD>̼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
* @param3 TIMEOUT <EFBFBD>̼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӱ<EFBFBD>д<EFBFBD><EFBFBD>FLASHʧ<EFBFBD><EFBFBD>
**************************************************************************************************/
RunResult DownOtherSubpack(DownFileP_s *psFileParm)
{
int headPos ;
for( psFileParm->subPackNum = 2; psFileParm->subPackNum <= psFileParm->subPackSum; psFileParm->subPackNum++ ) //<2F>ӵ<EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
2023-12-20 10:22:52 +00:00
Wait_For_Nms(50) ;
2023-12-15 06:28:06 +00:00
uint16_t downLen = ONCE_DOWN_LEN ; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵij<DDB5><C4B3><EFBFBD>
if( psFileParm->subPackNum == psFileParm->subPackSum ) /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>*/
{
downLen = psFileParm->fileSize%ONCE_DOWN_LEN ; //<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
}
headPos = Ftp_Down_File(psFileParm->fileName, (psFileParm->subPackNum-1)*ONCE_DOWN_LEN, downLen) ; //<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
if( headPos >= 0 ) //<2F>Ӱ<EFBFBD><D3B0><EFBFBD><EFBFBD>سɹ<D8B3>
{
TcpUpdata( BOOTTOTCPFRAME, "<EFBFBD>Ӱ<EFBFBD><EFBFBD><EFBFBD>%d <20><><EFBFBD><EFBFBD><EFBFBD>سɹ<D8B3><C9B9><EFBFBD>", psFileParm->subPackNum) ;
if( RUNOK == Write_Flash(psFileParm->appFlashAddr+(psFileParm->subPackNum-1)*ONCE_DOWN_LEN, (uint8_t*)(ec20FtpBuf+headPos), downLen))
{
TcpUpdata( BOOTTOTCPFRAME, "<EFBFBD>Ӱ<EFBFBD><EFBFBD><EFBFBD>%d <20><>д<EFBFBD><D0B4>FLASH<53>ɹ<EFBFBD><C9B9><EFBFBD>", psFileParm->subPackNum) ;
}
else //<2F>Ӱ<EFBFBD>дFLASHʧ<48><CAA7>
{
TcpUpdata( BOOTTOTCPFRAME, "<EFBFBD>Ӱ<EFBFBD><EFBFBD><EFBFBD>%d <20><>д<EFBFBD><D0B4>FLASHʧ<48>ܣ<EFBFBD><DCA3><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", psFileParm->subPackNum) ;
return TIMEOUT ;
}
}
else //<2F>Ӱ<EFBFBD><D3B0><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
{
TcpUpdata( BOOTTOTCPFRAME, "<EFBFBD>Ӱ<EFBFBD><EFBFBD><EFBFBD>%d <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", psFileParm->subPackNum) ;
return RUNERR ;
}
}
return (RUNOK) ;
}
/**************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> uint32_t Check_AppNum( u32 appNumFlagWord )
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>صĹ̼<EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>Ϸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҽ<EFBFBD>¼appNum
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param1 appNum appNum<EFBFBD>Ż<EFBFBD><EFBFBD><EFBFBD>APP<EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD>FLASH<EFBFBD>׵<EFBFBD>ַ
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param1 flagWord <EFBFBD><EFBFBD><EFBFBD>ع̼<EFBFBD>Ӧ<EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>FLASH<EFBFBD>Ŀ<EFBFBD>ʼ<EFBFBD><EFBFBD>ַ
* @arg APP2_AREA_ADDR: <EFBFBD><EFBFBD><EFBFBD>صĹ̼<EFBFBD>ΪAPP2<EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>FLASH<EFBFBD>ڵ<EFBFBD>APP2_AREA_ADDRλ<EFBFBD><EFBFBD>
* @arg APP3_AREA_ADDR: <EFBFBD><EFBFBD><EFBFBD>صĹ̼<EFBFBD>ΪAPP3<EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>FLASH<EFBFBD>ڵ<EFBFBD>APP3_AREA_ADDRλ<EFBFBD><EFBFBD>
* @arg 0: <EFBFBD>̼<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD>
**************************************************************************************************/
uint32_t Check_AppNum( u32 appNumFlagWord )
{
uint32_t flagWord = appNumFlagWord & 0xFFFF0000 ;
if(flagWord >= APP3_AREA_ADDR){
return APP3_AREA_ADDR ;
}
if(flagWord >= APP2_AREA_ADDR){
return APP2_AREA_ADDR ;
}
return 0;
/*
switch(flagWord)
{
case(APP2_AREA_ADDR & 0xFFFF0000):
return APP2_AREA_ADDR ;
case(APP3_AREA_ADDR & 0xFFFF0000):
return APP3_AREA_ADDR ;
default:
return 0 ;
}*/
}
/**************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> void Erase_App_Area(uint32_t appNum)
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>APP1\APP2\APP3<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>FLASH<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param1 appNum appNum<EFBFBD>Ż<EFBFBD><EFBFBD><EFBFBD>APP<EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD>FLASH<EFBFBD>׵<EFBFBD>ַ
**************************************************************************************************/
void Erase_App_Area(uint32_t appNum)
{
FLASH_Status eraseResult ;
uint8_t pageSum = 0, pageNum = 0 ;
FLASH_Unlock(); //Flash<73><68><EFBFBD><EFBFBD>
switch(appNum)
{
case 0x00000031: case APP1_AREA_ADDR:
{
// pageSum = APP1_AREA_SIZE/FLASH_PAGE_SIZE ; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>APP1_AREA_SIZE<5A><45><EFBFBD><EFBFBD>ռ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD>ҳ
// while(pageSum--)
// {
// eraseResult = FLASH_ErasePage(APP1_AREA_ADDR+pageNum*FLASH_PAGE_SIZE) ;
// pageNum++ ;
// }
break ;
}
case 0x00000032: case APP2_AREA_ADDR:
{
pageSum = APP2_AREA_SIZE/FLASH_PAGE_SIZE ; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>APP1_AREA_SIZE<5A><45><EFBFBD><EFBFBD>ռ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD>ҳ
while(pageSum--)
{
eraseResult = FLASH_ErasePage(APP2_AREA_ADDR+pageNum*FLASH_PAGE_SIZE) ;
pageNum++ ;
}
break ;
}
case 0x00000033: case APP3_AREA_ADDR:
{
pageSum = APP3_AREA_SIZE/FLASH_PAGE_SIZE ; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>APP1_AREA_SIZE<5A><45><EFBFBD><EFBFBD>ռ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD>ҳ
while(pageSum--)
{
eraseResult = FLASH_ErasePage(APP3_AREA_ADDR+pageNum*FLASH_PAGE_SIZE) ;
pageNum++ ;
}
break ;
}
default:
{
break ;
}
}
FLASH_Lock(); //Flash<73><68><EFBFBD><EFBFBD>
}
/**************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> void PrintfDeviceInfo(void)
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> DEBUG<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
**************************************************************************************************/
void PrintfDeviceInfo(void)
{
printf("\r\n**************************************************************" ) ;
printf("\r\n<EFBFBD><EFBFBD>Ȩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> : <20>̳ϿƼ<CFBF> 2017/8-2027/8 .\
\r\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD> : Mr. Wang 13635513618 .") ;
Query_AppVersion((char*)gateApp.bootVers) ;
//SetAppVersion(&gateApp, (char*)gateApp.bootVers) ;
printf("\r\nBoot<EFBFBD>汾 : %.*s",VERSION_LEN, gateApp.bootVers) ;
memset(uIapFlash.sIapFlash.BootVers, 0, VERSION_LEN+1) ;
strncpy((char*)uIapFlash.sIapFlash.BootVers, (const char*)gateApp.bootVers, VERSION_LEN ) ; //<2F><><EFBFBD><EFBFBD>Boot<6F><EFBFBD><E6B1BE><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD>µ<EFBFBD>boot<6F><EFBFBD><E6B1BE>
Set_uIapFlash(&uIapFlash) ; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD>FLASH<53><48>
GetDeviceMacAddress((uint8_t*)gateApp.macId, STRMACID) ;
printf("\r\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> : %.*s", MAC_BYTES_LEN, gateApp.macId) ;
DeviceRstReason((uint8_t*)gateApp.rstReason, VERSION_LEN) ;
printf("\r\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><EFBFBD> : %.*s", VERSION_LEN, gateApp.rstReason) ;
printf("\r\n**************************************************************" ) ;
}
/**************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> void DeviceRstReason(uint8_t *reason, uint8_t maxLen)
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD>ж<EFBFBD>Ӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><EFBFBD>
**************************************************************************************************/
void DeviceRstReason(uint8_t *reason, uint8_t maxLen)
{
if( SET == RCC_GetFlagStatus( RCC_FLAG_PORRST) )
{
strncpy((char*)reason, "<EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", maxLen) ;
}
if( SET == RCC_GetFlagStatus(RCC_FLAG_SFTRST) )
{
strncpy((char*)reason, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", maxLen) ;
}
if( SET == RCC_GetFlagStatus(RCC_FLAG_IWDGRST) )
{
strncpy((char*)reason, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ź<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", maxLen) ;
}
if( SET == RCC_GetFlagStatus(RCC_FLAG_WWDGRST) )
{
strncpy((char*)reason, "<EFBFBD><EFBFBD><EFBFBD>ڿ<EFBFBD><EFBFBD>Ź<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", maxLen) ;
}
if( (RESET == RCC_GetFlagStatus(RCC_FLAG_SFTRST)) &&
(RESET == RCC_GetFlagStatus(RCC_FLAG_IWDGRST)) &&
(RESET == RCC_GetFlagStatus(RCC_FLAG_WWDGRST)) &&
(SET == RCC_GetFlagStatus(RCC_FLAG_PINRST))
)
{
strncpy((char*)reason, "Ӳ<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", maxLen) ;
}
RCC_ClearFlag() ;
}
/**************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> void InitApplictationState(Application *appPointer)
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>Application<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><EFBFBD>г<EFBFBD>ʼ<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> @param *appPointer Application<EFBFBD>ָ<EFBFBD><EFBFBD>
*************************************************************************************************/
void InitApplictationState(Application *appPointer)
{
memset(appPointer->appVers, 0, VERSION_LEN+1) ;
memset(appPointer->bootVers, 0, VERSION_LEN+1) ;
memset(appPointer->macId, 0, MAC_BYTES_LEN+1) ;
}
void SetAppVersion(Application *appPointer, char *version)
{
strncpy((char*)appPointer->appVers, version, VERSION_LEN) ;
*(appPointer->appVers+VERSION_LEN+1) = 0 ;
}
void SetBootVersion(Application *appPointer, char *version)
{
strncpy((char*)appPointer->bootVers, version, VERSION_LEN) ;
*(appPointer->bootVers+VERSION_LEN+1) = 0 ;
}