📄 main.cpp
字号:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "FlashBSP.h"
static int BurnUpdate(char* pFileName);
static int BurnBootloader();
static int BurnProgramm(char* pFileName);
static int BurnConfiguration(CONFIGURATION *pCfg);
static int EraseProgramm();
static int EraseBootloader();
static int EraseUpdate();
static int EraseConfiguration();
static int ReadEthInfo(NET_PARAM *eth_info);
static char CheckSum(char* pData, int nLen);
static CONFIGURATION configuration = {
{0xffff, 0, 0}, //CFG_AREA_HEADER cfgAreaHeader
BAUD9600, //sp232_info
BAUD9600, //sp485_info
{ //NET_PARAM eth_info
"192.168.10.235",
"255.0.0.0",
"192.168.10.1",
"demo.net",
"Phocus1820",
{0x00,0x50,0xc2,0x5b,0xb0,0x4e},
0,
0
},
{0, 0} //MODE_INFO mode_info
};
int main()
{
char text[100] = {0};
char updatedir[100] = {0};
char programdir[100] = {0};
int IsContinue = 0;
volatile int i;
NET_PARAM eth_info_temp;
int selection = 0; //0 - bootloader
//1 - update
//2 - program
//3 - configuration
//4 - bootloader+update+program+configuration
//5 - bootloader+update+program+configuration with default settings
//6 - bootloader+update+program
Phocus1820_init();
do
{
memset(text, 0, 100);
//strcpy(updatedir, "../../PhocusUpdate/Release/PhocusUpdate.bin");
strcpy(updatedir, "../../PhocusUpdate/Release/PhocusUpdate.bin");
strcpy(programdir, "../../Phocus1821/Firmware/Release/OCRProject.bin");
ReadEthInfo(ð_info_temp);
//选择烧写内容
do
{
printf("\n");
printf("*************************************************\n");
printf("*Select which to burn: *\n");
printf("*\tB-Burn bootloader automatically *\n");
printf("*\tu-Burn update *\n");
printf("*\tU-Burn update automatically *\n");
printf("*\tp-Burn program *\n");
printf("*\tP-Burn program automatically *\n");
printf("*\tc-Burn configuration *\n");
printf("*\tC-Burn configuration automatically *\n");
printf("*\ta-Burn all *\n");
printf("*\tA-Burn all automatically *\n");
printf("*\te-Burn all except configuration *\n");
printf("*\tE-Burn all except configuration *\n");
printf("*\t automatically *\n");
printf("*\tn-Burn none *\n");
printf("*************************************************\n");
printf("\n");
printf("-------------------------------------------------\n");
printf("|Current IP address is %s", eth_info_temp.strLocalIPAddr);
for(int i = 31 - sizeof(eth_info_temp.strLocalIPAddr); i > 0; i --)
{
printf(" ");
}
printf("|\n");
printf("|Current Mac is %02x-%02x-%02x-%02x-%02x-%02x |\n", eth_info_temp.bMacAddr[0], eth_info_temp.bMacAddr[1], eth_info_temp.bMacAddr[2], eth_info_temp.bMacAddr[3], eth_info_temp.bMacAddr[4], eth_info_temp.bMacAddr[5]);
printf("-------------------------------------------------\n");
printf("\n");
gets(text);
switch(text[0])
{
case 'B':
printf("Your selection is \"Burn bootloader automatically\".\n");
selection = 1;
break;
case 'u':
printf("Your selection is \"Burn update\".\n");
selection = 2;
break;
case 'U':
printf("Your selection is \"Burn update automatically\".\n");
selection = 3;
break;
case 'p':
printf("Your selection is \"Burn program\".\n");
selection = 4;
break;
case 'P':
printf("Your selection is \"Burn program automatically\".\n");
selection = 5;
break;
case 'c':
printf("Your selection is \"Burn configuration\".\n");
selection = 6;
break;
case 'C':
printf("Your selection is \"Burn configuration automatically\".\n");
selection = 7;
break;
case 'a':
printf("Your selection is \"Burn all\".\n");
selection = 8;
break;
case 'A':
printf("Your selection is \"Burn all automatically\".\n");
selection = 9;
break;
case 'e':
printf("Your selection is \"Burn all except configuration\".\n");
selection = 10;
break;
case 'E':
printf("Your selection is \"Burn all except configuration automatically\".\n");
selection = 11;
break;
case 'n':
printf("Your selection is \"Burn none\".\n");
selection = -1;
break;
default:
printf("No such selection. Please input a valid character.\n");
break;
}
}while (
text[0] != 'B' &&
text[0] != 'u' &&
text[0] != 'U' &&
text[0] != 'p' &&
text[0] != 'P' &&
text[0] != 'c' &&
text[0] != 'C' &&
text[0] != 'a' &&
text[0] != 'A' &&
text[0] != 'e' &&
text[0] != 'E' &&
text[0] != 'n'
);
//自定义IP和Mac
if(selection == 6 || selection == 8 || selection == 10)
{
do
{
int m;
int n;
char *p = text + 2;
text[1] = 0;
//输入IP地址
printf("\n");
printf("*************************************************\n");
printf("*Input the IP address like: 192.168.10.168 *\n");
printf("*************************************************\n");
printf("\n");
printf("Current IP address is %s .\n", eth_info_temp.strLocalIPAddr);
gets(p);
//检验IP地址是否正确
m = 0;
n= 0;
while(*p != '\0')
{
if(p > text + 18 || m > 3 || n > 3)
{
text[1] = 'e';
break;
}
else
{
if(*p < '0' || *p > '9')
{
if(n > 0 && *p == '.')
{
m ++;
n = 0;
p ++;
}
else
{
text[1] = 'e';
break;
}
}
else
{
n ++;
p ++;
}
}
}
if(m != 3 || n > 3 || n == 0)
{
text[1] = 'e';
}
if(text[1] == 'e')
{
printf("Invalid IP address. Please input a valid IP.\n");
}
else
{
strcpy(configuration.eth_info.strLocalIPAddr, text + 2);
}
}while(text[1] == 'e');
do
{
int m;
int n;
char *p = text + 50;
text[1] = 0;
//输入Mac
printf("\n");
printf("***********************************************\n");
printf("*Input the Mac like: 00-50-c2-5b-b0-44 *\n");
printf("***********************************************\n");
printf("\n");
printf("Current Mac is %02x-%02x-%02x-%02x-%02x-%02x\n", eth_info_temp.bMacAddr[0], eth_info_temp.bMacAddr[1], eth_info_temp.bMacAddr[2], eth_info_temp.bMacAddr[3], eth_info_temp.bMacAddr[4], eth_info_temp.bMacAddr[5]);
gets(p);
for(m = 0; m < 6;m ++)
{
for(n = 0; n < 2; n ++) //字段前两个字符
{
if(*p >= '0' && *p <= '9') //字符为数字
{
*p -= '0';
}
else if(*p >= 'a' && *p <= 'f') //字符为a-f的字母
{
*p -= ('a' - (char)10);
}
else //不是有效字符,错误
{
text[1] = 'e';
break;
}
p ++;
}
if(text[1] == 'e') //检查每个字段最后一个字符
{
break;
}
else if(*p == '-' && m < 5) //前四个字段以'-'结束
{
p ++;
}
else if(*p == '\0' && m == 5) //最后一个字段以'\0'结束
{
p ++;
}
else //最后一个字符无效,错误
{
text[1] = 'e';
break;
}
}
if(text[1] == 'e')
{
printf("Invalid Mac. Please input a valid Mac.\n");
}
else
{
configuration.eth_info.bMacAddr[0] = *(text + 50) * 16 + *(text +51);
configuration.eth_info.bMacAddr[1] = *(text + 53) * 16 + *(text +54);
configuration.eth_info.bMacAddr[2] = *(text + 56) * 16 + *(text +57);
configuration.eth_info.bMacAddr[3] = *(text + 59) * 16 + *(text +60);
configuration.eth_info.bMacAddr[4] = *(text + 62) * 16 + *(text +63);
configuration.eth_info.bMacAddr[5] = *(text + 65) * 16 + *(text +66);
}
}while(text[1] == 'e');
}
//指定升级程序路径
if(selection == 2 || selection == 8 || selection == 10)
{
memset(updatedir, 0, 100);
printf("\n");
printf("*************************************************\n");
printf("*Input the update's location like: *\n");
printf("*\tC:/dsp/update.bin *\n");
printf("*************************************************\n");
gets(updatedir);
printf("The update's location is\n");
printf("\t\"%s\".\n", updatedir);
}
//指定应用程序路径
if(selection == 4 || selection == 8 || selection == 10)
{
memset(programdir, 0, 100);
//输入升级程序所在路径
printf("\n");
printf("*************************************************\n");
printf("*Input the program's location like: *\n");
printf("*\tC:/dsp/program.bin *\n");
printf("*************************************************\n");
gets(programdir);
printf("The program's location is\n");
printf("\t\"%s\".\n", programdir);
}
if(selection == 1 || selection == 8 || selection == 9 || selection == 10 || selection == 11)
{
//烧写Bootloader
EraseBootloader();
i = 0;
while(i < 500000)
{
i ++;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -