📄 mstate.c.bak
字号:
break;
}
case FUNC_TEST_LCD:
{
LCD_test();
LCD_clear_screen();
LCD_locate(2,4); LCD_write_string("LCD 测试完成!",0);
LCD_locate(8,2); LCD_write_string("【清除】退出",0);
break;
}
case FUNC_TEST_PRINT:
{
LCD_clear_screen();
LCD_locate(0,6); LCD_write_string("收 据",0);
LCD_locate(2,0); LCD_write_string("报装号: 123456",0);
LCD_locate(4,0); LCD_write_string("用户名: 李沧海",0);
LCD_locate(6,0); LCD_write_string("上月读数:12791",0);
LCD_locate(8,0); LCD_write_string("本月读数:13035",0);
LCD_locate(10,0); LCD_write_string("性质:商业 电价:0.65",0);
LCD_locate(12,0); LCD_write_string("电量:244 缴费:158.6",0);
LCD_locate(15,0); LCD_write_string("[F1]走纸 [F2]退纸",0);
LCD_locate(18,0); LCD_write_string("确认/打印 清除/退出",0);
break;
}
case FUNC_TEST_FILE:
{
LCD_clear_screen();
LCD_locate(0,6); LCD_write_string("文件测试",0);
LCD_locate(2,0); LCD_write_string("文件名称:",0);
LCD_locate(4,0); LCD_write_string("文件大小:",0);
LCD_locate(6,0); LCD_write_string("建立文件:",0);
LCD_locate(8,0); LCD_write_string("打开文件:",0);
LCD_locate(10,0); LCD_write_string("读 文 件:",0);
LCD_locate(12,0); LCD_write_string("写 文 件:",0);
LCD_locate(14,0); LCD_write_string("数据校验:",0);
LCD_locate(16,0); LCD_write_string("测试结果:",0);
LCD_locate(2,10); LCD_write_string("test.bin",0);
LCD_locate(4,10); LCD_write_string("4096 Bytes",0);
LCD_locate(6,10); LCD_write_string("OK",0);
LCD_locate(8,10); LCD_write_string("OK",0);
LCD_locate(10,10); LCD_write_string("OK",0);
Delay_ms(255);
LCD_locate(12,10); LCD_write_string("OK",0);
Delay_ms(255);
LCD_locate(14,10); LCD_write_string("OK",0);
LCD_locate(16,10); LCD_write_string("测试成功",0);
LCD_locate(18,8); LCD_write_string("【清除】退出",0);
break;
}
default:
break;
}
}
//-----------------------
void MState_display_run()
{
unsigned char result = 0;
LCD_clear_screen();
if( MState_inf.Step == STEP_RUN_GETFILE ) {
//result = load_file();
result = 1;
LCD_clear_screen();
if( result == 1 ){
LCD_locate(2,3);
LCD_write_string("执行文件错误!",0);
LCD_locate(8,2); LCD_write_string("【任意键】退出",0);
}else if( result == 2 ){
LCD_locate(2,3);
LCD_write_string("数据库文件错误!",0);
LCD_locate(8,2); LCD_write_string("【任意键】退出",0);
}
}
}
void MState_display(void)
{
if( MState_inf.Fresh == FRESH_ON )
{
switch( MState_inf.State )
{
case MACHINE_STATE_FACE:
{
MState_display_face();
break;
}
case MACHINE_STATE_MAIN:
{
MState_display_main();
break;
}
case MACHINE_STATE_SYSINF:
{
MState_display_sysinf();
break;
}
case MACHINE_STATE_CONFIG:
{
MState_display_config();
break;
}
case MACHINE_STATE_COM:
{
MState_display_com();
break;
}
case MACHINE_STATE_TEST:
{
MState_display_test();
break;
}
case MACHINE_STATE_RUN:
{
MState_display_run();
break;
}
default:
break;
}
MState_inf.Fresh = FRESH_OFF;
}
}
//==============================
extern unsigned char COM_FrameBuf[];
extern unsigned char COM_TransBuf[];
unsigned char FileDir_1[32]= { 0x50,0x44,0x41,0x4f,0x55,0x20,0x20,0x20,\
0x44,0x42,0x46,0x00,0x00,0x00,0x00,0x00,\
0x00,0x00,0x00,0x00,0x00,0x00,0x29,0x11,\
0x07,0x00,0x07,0x00,0x3b,0xff,0x04,0x00};
unsigned char FileDir_2[32]= { 0x54,0x31,0x20,0x20,0x20,0x20,0x20,0x20,\
0x42,0x49,0x4e,0x00,0x00,0x00,0x00,0x00,\
0x00,0x00,0x00,0x00,0x00,0x00,0x29,0x11,\
0x07,0x00,0xaa,0x00,0xec,0xbf,0x00,0x00};
#define RUN_ADDRESS 0x02000000
void Com_download_file(int Len,unsigned char *file)
{
int fd,num,RcvCount;
void (* func)(void);
char *pDest = (char*)RUN_ADDRESS;
RcvCount = 0;
while( RcvCount < Len )
{
num = COM_frame_get();
if(num>0)
{
if( file[0] ){
fd = File_open( file );
if(fd<0) return;
File_write(fd,COM_FrameBuf,num);
//File_close(fd);
}else{
Mem_Cpy( (pDest+RcvCount),COM_FrameBuf,num );
}
COM_TransBuf[3] = 0x47;
COM_TransBuf[4] = 0x01;
COM_frame_send(2);
RcvCount += num;
}
}
if(file[0] == 0)
{
func = (void (*)())(RUN_ADDRESS);
func();
}else{
File_close(fd);
}
}
void Com_upload_file(void)
{
;
}
//------------------------------
void MState_com_work(void)
{
int num,i,j,p;
struct RTC_struct RTC_inf;
struct CONFIG_struct Config_inf;
struct FILE_struct tmd_inf;
unsigned char FName[11];
unsigned char Msg;
unsigned char *pTmp;
num = COM_frame_get();
if(num>0)
{
switch( COM_FrameBuf[0] )
{
case 0x45: //--->> PC link
{
COM_TransBuf[3] = 0x47;
COM_TransBuf[4] = 0x01;
COM_frame_send(2);
break;
}
case 0x48: //--->> RTC fresh
{
RTC_inf.Year = COM_FrameBuf[1];
RTC_inf.Mon = COM_FrameBuf[2];
RTC_inf.Day = COM_FrameBuf[3];
RTC_inf.Hour = COM_FrameBuf[4];
RTC_inf.Min = COM_FrameBuf[5];
RTC_inf.Sec = COM_FrameBuf[6];
RTC_inf.Week = COM_FrameBuf[7];
RTC_set( &RTC_inf );
COM_TransBuf[3] = 0x48;
COM_TransBuf[4] = 0x01;
COM_frame_send(2);
break;
}
case 0x49: //--->> COM quit
{
MState_inf.State = MACHINE_STATE_MAIN;
MState_inf.Func = FUNC_MAIN;
MState_inf.Fresh = FRESH_ON;
break;
}
case 0x4A: //--->> creat file
{
//--->> get file name
for(i=0;i<11;i++) FName[i] = 0x20;
for(i=0;i<8;i++) {
Msg = COM_FrameBuf[i+6];
if( Msg == 0x2E ) { break;}
FName[i] = Msg;
}
FName[8] = COM_FrameBuf[i+7];
FName[9] = COM_FrameBuf[i+8];
FName[10] = COM_FrameBuf[i+9];
i = File_create(FName);
//i = 1;
if(i>=0){
COM_TransBuf[3] = 0x4A;
COM_TransBuf[4] = 0x01;
COM_frame_send(2);
i = 0;
i += ((unsigned int)COM_FrameBuf[1]);
i += ((unsigned int)COM_FrameBuf[2])<<8;
i += ((unsigned int)COM_FrameBuf[3])<<16;
Com_download_file(i,FName);
}else{
COM_TransBuf[3] = 0x4A;
COM_TransBuf[4] = 0xEF;
COM_frame_send(2);
}
break;
}
case 0x4B: //--->> Hand shake
{
RS232_send_char(0x02);
break;
}
case 0x4C: //--->> delete file
{
//--->> get file name
for(i=0;i<11;i++) FName[i] = 0x20;
for(i=0;i<8;i++) {
Msg = COM_FrameBuf[i+1];
if( Msg == 0x2E ) { break;}
FName[i] = Msg;
}
for(i=1;i<30;i++) {
if( COM_FrameBuf[i] != 0x2E ){ continue; }
break;
}
FName[8] = COM_FrameBuf[i+1];
FName[9] = COM_FrameBuf[i+2];
FName[10] = COM_FrameBuf[i+3];
i = File_delete(FName);
//i = 1;
if(i>=0){
COM_TransBuf[3] = 0x4C;
COM_TransBuf[4] = 0x01;
}else{
COM_TransBuf[3] = 0x47;
COM_TransBuf[4] = 0x02;
}
COM_frame_send(2);
break;
}
case 0x4E: //--->> download and run
{
COM_TransBuf[3] = 0x4E;
COM_TransBuf[4] = 0x01;
COM_frame_send(2);
for(i=0;i<11;i++) FName[i] = 0x00;
i = 0;
i += ((unsigned int)COM_FrameBuf[1]);
i += ((unsigned int)COM_FrameBuf[2])<<8;
i += ((unsigned int)COM_FrameBuf[3])<<16;
i += ((unsigned int)COM_FrameBuf[4])<<24;
Com_download_file(i,FName);
break;
}
case 0x50: //--->> set user_inf
{
//Config_inf_read( &Config_inf );
for(i=0;i<10;i++)
{ Config_inf.User_name[i] = COM_FrameBuf[i+1]; }
for(i=0;i<6;i++)
{ Config_inf.User_numb[i] = COM_FrameBuf[i+11]; }
//Config_inf_write( &Config_inf );
COM_TransBuf[3] = 0x50;
COM_TransBuf[4] = 0x01;
COM_frame_send(2);
break;
}
case 0x51: //--->> upload user_inf
{
//Config_inf_read( &Config_inf );
for(i=0;i<10;i++)
//{ COM_TransBuf[i+5] = Config_inf.User_name[i]; }
{ COM_TransBuf[i+5] = 'A'+i; }
for(i=0;i<6;i++)
//{ COM_TransBuf[i+13] = Config_inf.User_numb[i]; }
{ COM_TransBuf[i+15] = '1'+i; }
COM_TransBuf[3] = 0x51;
COM_TransBuf[4] = 0x01;
COM_frame_send(0x12);
break;
}
case 0x52: //--->> upload file_inf
{
//for(i=0;i<256;i++) COM_TransBuf[i] = 0;
num = 6;
for(i=0;i<6;i++)
{
p = File_inf_get(i,&tmd_inf);
if( p >= 0 )
{
pTmp = (unsigned char *)(&tmd_inf);
for(j=0;j<32;j++){
//COM_TransBuf[ ((num<<5)+6) ] = pTmp[j];
COM_TransBuf[ num++ ] = pTmp[j];
}
//num++;
}
}
num = (num-6)/32;
COM_TransBuf[3] = 0x52;
COM_TransBuf[4] = 0x01;
COM_TransBuf[5] = num; //--->> file num
//--->>if no file, this is 0x00,len is 3
//for(i=0;i<32;i++) COM_TransBuf[i+6] = FileDir_1[i];
//for(i=0;i<32;i++) COM_TransBuf[i+38] = FileDir_2[i];
//COM_TransBuf[5] = 2;
COM_frame_send( num*32+3 );
break;
}
}
}
}
void MState_Sysinf_work(void)
{
struct RTC_struct RTC_inf;
switch( MState_inf.Func )
{
case FUNC_SYSINF_TIME_INF:
{
RTC_get( &RTC_inf );
if( (RTC_inf.Sec) != MState_again[0] ){
MState_again[0] = RTC_inf.Sec;
Bcd_to_Ascii(RTC_inf.Year, MState_msg);
LCD_locate(4,2); LCD_write_string("20",0);
LCD_locate(4,4); LCD_write_ASCII(MState_msg[0],0);
LCD_locate(4,5); LCD_write_ASCII(MState_msg[1],0);
LCD_locate(4,6); LCD_write_string("年",0);
Bcd_to_Ascii(RTC_inf.Mon, MState_msg);
LCD_locate(4,8); LCD_write_ASCII(MState_msg[0],0);
LCD_locate(4,9); LCD_write_ASCII(MState_msg[1],0);
LCD_locate(4,10); LCD_write_string("月",0);
Bcd_to_Ascii(RTC_inf.Day, MState_msg);
LCD_locate(4,12); LCD_write_ASCII(MState_msg[0],0);
LCD_locate(4,13); LCD_write_ASCII(MState_msg[1],0);
LCD_locate(4,14); LCD_write_string("日",0);
LCD_locate(8,6); LCD_write_string("星期:",0);
LCD_locate(8,12);
switch(RTC_inf.Week)
{
case 1: LCD_write_string("一",0);break;
case 2: LCD_write_string("二",0);break;
case 3: LCD_write_string("三",0);break;
case 4: LCD_write_string("四",0);break;
case 5: LCD_write_string("五",0);break;
case 6: LCD_write_string("六",0);break;
case 7: LCD_write_string("日",0);break;
default: break;
}
Bcd_to_Ascii(RTC_inf.Hour, MState_msg);
LCD_locate(12,4); LCD_write_ASCII(MState_msg[0],0);
LCD_locate(12,5); LCD_write_ASCII(MState_msg[1],0);
LCD_locate(12,6); LCD_write_string(":",0);
Bcd_to_Ascii(RTC_inf.Min, MState_msg);
LCD_locate(12,8); LCD_write_ASCII(MState_msg[0],0);
LCD_locate(12,9); LCD_write_ASCII(MState_msg[1],0);
LCD_locate(12,10); LCD_write_string(":",0);
Bcd_to_Ascii(RTC_inf.Sec, MState_msg);
LCD_locate(12,12); LCD_write_ASCII(MState_msg[0],0);
LCD_locate(12,13); LCD_write_ASCII(MState_msg[1],0);
}
break;
}
}
}
//------------------------------
void MState_work(void)
{
switch( MState_inf.State )
{
case MACHINE_STATE_FACE:
{
break;
}
case MACHINE_STATE_MAIN:
{
break;
}
case MACHINE_STATE_SYSINF:
{
MState_Sysinf_work();
break;
}
case MACHINE_STATE_CONFIG:
{
break;
}
case MACHINE_STATE_COM:
{
MState_com_work();
break;
}
case MACHINE_STATE_TEST:
{
break;
}
case MACHINE_STATE_RUN:
{
break;
}
default:
break;
}
}
//==============================
//------------------------------
void MState_PM(void)
{
}
//==============================
//------------------------------
void MState_open(void)
{
MState_inf.State = 0;
MState_inf.Func = 0;
MState_inf.Step = 0;
MState_inf.Fresh = 1;
}
void MState_handle(void)
{
// unsigned char key;
while(1)
{
MState_key();
MState_display();
MState_work();
MState_PM();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -