/* */ #include #include //for isdigit() #include //for malloc() #include #include #include #define KEY_BS 8 #define KEY_ESC 27 #define RS232putch ToCom2 #define RS232getch ReadCom2 #define Is232 IsCom2 #define RS232putstr ToCom2Str #define Install232 InstallCom2 #define Restore232 RestoreCom2 #define INTERVAL 500 /*the time (between the same key clicked continusly) to determine user want a differeent key input or not*/ /* The less this value is, the faster the user should key in the same key to show different key-value*/ int type1(char *); int upload(char *); int init_user(int DeBug); int show232setting(); int paratableinit(); int setfilename(char name_[]); int run(char name_[],char argu_[]); int setargu(char argu_[]); int download(char name_[]);//auto download int keypad(); unsigned long calday(unsigned int *dd,int *hh,int *mm,int *ss); int store(char data[],char);//store data to DRAM, the address is space[],fixed length int toFLASH(int LengthToBeSaved,char End); #define MAXMODULE 8 char far * initlog(int *N);//return start address of log file int getmaxlog(); int searchlogmodule(); //define globe variables unsigned char **address; char far * creatfile();//return start address of file void closefile(char filename[],unsigned long size);//write file information in file header unsigned long far * timetick=(unsigned long far *)0x0040006CL; unsigned long starttick; unsigned long TIMEd; //assign as a globe variable is for simply use unsigned long K;//free space in FLASH char far * p_Start;//datalog file start address in FLASH, use for FlashWrite() int QUIT=0; char *space; //this space may be very very large, careful usage is needed. void menu(); int data(); int X87017(); int main() { int quit=0; int i; space=(char *)malloc(2560); if(space==NULL) { LCDPrintf("\n\rNot enough memory"); Print("\n\rNot enough memory"); goto ENDX; } if(initLCD()>0) Print("\nLCD wrong"); else { clrLCD(); LCDPrintf("\n\r\n\r ICPDAS"); } strset(space,0); for(i=0;i<2560;i++) space[i]=0; p_Start=initlog(&i); if(p_Start==(char far *)0xf0000000) { Print("file open error"); LCDPrintf("file open error"); return 1; } menu(); Install232(9600L,8,0); while(!quit) { if(Kbhit()) { int key=Getch(); switch(key) { case KEY_F2: X87017();menu();break;//set file name for auto download case '#' : //quit 7188xlite case '=' : LCDPrintf("\n\rquit");quit=1;break; case KEY_F4:quit=1;break; }//switch }//kbhit }//while loop ENDX: closeLCD(); Restore232(); free(space); return 0; } void menu() { clrLCD(); LCDPrintf("press F2 to log 87017 channel 0 value.."); } int init_user(int DeBug) { InstallCom2(9600L,8,0);//COM2 return 0; } //The unit of FLASH write is 256 bytes. //each data is 80 bytes //When number of data stored in DRAM execeed 32, we write them to FLASH(10 blocks=2560bytes) #define CCfield 80 int X87017() { int i; char temp[80]; char ww1[10]; char ww[10]; int state7000; char response7k[58];//>+XX.XXX(max 7*8+1=57) another 1 for end:0 unsigned int day; int quit; QUIT=0; temp[0]=0; while(!QUIT) { if(Kbhit()) { int key=Getch(); if(key==KEY_ESC) { store("END",1); QUIT=1; return 1; } } if((*timetick-TIMEd)>3000) { TIMEd=*timetick; strncpy(ww1,address[i]+1,2); // "!AAmodulename" two bytes for address AA sprintf(ww,"#01S1C0",ww1); SendCmdTo7000(2, "#01S1C0", 0); // send command to device via com2 485 port state7000=ReceiveResponseFrom7000(2,response7k,500,0); // receive RS232 device response from com1 232 port if(state7000==0) { strset(temp,32); strncpy(temp,response7k,strlen(response7k)); temp[strlen(response7k)+3]=0; LCDPrintf("\n\rValue:%s",temp); Print("\n\rValue:%s",temp); store(temp,0);//store to flash//fixed length }//ifstate }//iftimed }//while return 0; } //save temparary data to FLASH //save char space[] to FLASH int toFLASH(int Length,char End) { static unsigned int i=0;//Number of "package" which has been stored unsigned long add=(unsigned long)p_Start;//XXXXYYYY add=(add&0x0ffff)+((add>>16)<<4);//XYYYY unsigned int f_seg; unsigned int f_offset; int j; f_offset=(unsigned int)(add&0x0f); f_seg=(unsigned int)(add>>4); for(j=0;j=x)) //quit STOP save into FLASH { Print("\n\rclosefile"); closefile("data.log",(unsigned long)i*2560);//write file information in file header return 1; } else return 0; } //User want to log data from 7000 module. Now, initialize char far * initlog(int *N) { //N:number of module char far * p_start; //find space in FLASH K=getmaxlog();//return the free Kbytes K=(K<=5)?K:5; *N=1; //creat a new file in FLASH to store data:max 63K p_start=creatfile(); return p_start;//return start address of log file in FLASH } //fixed length storage //here we demo the structure of datalog rather than data structure impliment //CCfield is the number that the program will store this number of characters to DRAM //in general this number is 80 int store(char data[],char END)//store data to DRAM, the address is space[],fixed length { int i; int k; static int used=0; i=strlen(data); i=(i=2560)//if full of "space", then "toFLASH" { Print("ee"); QUIT=toFLASH(2560,1);//save one time for this demo program used=0; strnset(space,0,2560); return 0; } for(k=0;ksize; } } size=1+size/1000; fid=FlashReadId(); if((fid>>8)==0xB0)//256k size=-(size+64-256); else if((fid>>8)==0xA4) //512K size=-(size+64-512); return size;//in kb } //erase FLASH and get the file start address only char far * creatfile() { int fileno=GetFileNo();//get the total number of files stored in the FLASH static FILE_DATA far *fdata; fdata=GetFileInfoByNo(fileno-1);//to the last file unsigned long addr=(unsigned long)fdata->addr;//conver address pointer to calculateable unsigned long unsigned long high=addr>>16;//won't change address value unsigned long low= addr&0x0ffff; unsigned long newfileheaderat=(high<<4)+low+fdata->size;//calculate out the new file header address //prepare header information unsigned int seg=newfileheaderat>>4; unsigned int offset=newfileheaderat&0x0f;//mrak at 2001.7.12 //creat 64K anyway, if error than stop int res=FlashErase((seg&0xf000)+0x1000); if(res) return ((char far*)0xf0000000); // addr=newfileheaderat+(unsigned long)32; addr=( (unsigned long)(seg+2 )<<16)+(unsigned long)(offset);//mark at 2001.7.12 return ((char far *)addr);//return file data start address } void closefile(char filename[],unsigned long Xsize)//write file information in file header { unsigned long size=Xsize; int fileno=GetFileNo();//get the total number of files stored in the FLASH static FILE_DATA far *fdata; fdata=GetFileInfoByNo(fileno-1);//to the last file unsigned long addr=(unsigned long)fdata->addr;//conver address pointer to calculateable unsigned long unsigned long high=addr>>16;//won't change address value unsigned long low= addr&0x0ffff; unsigned long newfileheaderat=(high<<4)+low+fdata->size;//calculate out the new file header address // prepare header information unsigned int seg=newfileheaderat>>4; unsigned int offset=newfileheaderat&0x0f; FlashWrite(seg,offset+0,0x88);//write mark FlashWrite(seg,offset+1,0x71);//write mark int ik=0; while((filename[ik]!=0)&&(ik<12)) { FlashWrite(seg,offset+2+ik,filename[ik]);//write filename ik++; } while(ik<12) { FlashWrite(seg,offset+2+ik,0);//write filename insert 00 ik++; } FlashWrite(seg,offset+14,1);//write year FlashWrite(seg,offset+15,1);//write month FlashWrite(seg,offset+16,1);//write day FlashWrite(seg,offset+17,1);//write hour FlashWrite(seg,offset+18,1);//write minute FlashWrite(seg,offset+19,1);//write sec unsigned char *temp=(unsigned char *)&size; FlashWrite(seg,offset+20,temp[0]);//write size FlashWrite(seg,offset+21,temp[1]);//write size FlashWrite(seg,offset+22,temp[2]);//write size FlashWrite(seg,offset+23,temp[3]);//write size //write start address: little endium // FlashWrite(seg,offset+24,offset&0x0ff);//write offset FlashWrite(seg,offset+25,offset/256);//write offset //seg+2:offset->32 bytes long file header FlashWrite(seg,offset+26,(seg+2)&0x0ff);//write segment FlashWrite(seg,offset+27,(seg+2)/256);//write segment } int type1(char *taco) { unsigned long i; char name[13]; int fileno=GetFileNo();//get the total number of files stored in the FLASH for(int j=fileno-1;j>=0;j--) { GetFileName(j,name); if(!strncmp(name,taco,12))break; } static FILE_DATA far *fdata; fdata=GetFileInfoByNo(j);//to the last file unsigned long st; char far* JJ; if(!fdata) { Print("\n\rNo this file"); } else { st=(unsigned long)fdata->size;//conver address pointer to calculateable unsigned long JJ=fdata->addr; int k=0; for(i=0;i1760) { k=0; Print("\n\r..Press any key to continue"); int key=Getch(); if(key==27) goto END2; } } END2: Print("\n\rShow \"%s\" information",name); Print("\n\r%2d)%-12s ",j,taco); Print("%02d/%02d/%02d ",fdata->month,fdata->day,fdata->year+1980); Print("%02d:%02d:%02d",fdata->hour,fdata->minute,fdata->sec); st=fdata->size; Print("%7lu[%05lX]",fdata->size,fdata->size);//fail Print("%Fp-%Fp",fdata->addr,fdata->addr+st); ////// } return 0; } int upload(char *taco) { unsigned long i; int key; char name[13]; char buf[257];//0~255 for data, 256 for \0 static FILE_DATA far *fdata; unsigned char far* JJ; unsigned long st; int k=0; int e=0; int start=1; //find the newest file named as *taco int fileno=GetFileNo();//get the total number of files stored in the FLASH for(int j=fileno-1;j>=0;j--) { GetFileName(j,name); if(!strncmp(name,taco,12))break; } fdata=GetFileInfoByNo(j);//to the last file if(!fdata) { Print("\n\rNo this file"); goto END2; } st=(unsigned long)fdata->size;//conver address pointer to calculateable unsigned long JJ=(unsigned char far *)fdata->addr; i=0; Print("\n\rPress any key to upload"); Getch(); InstallCom1(115200L,8,0); while(i=st) { buf[k]=']'; buf[k+1]=0; ToCom1Str(buf); goto END3; } } buf[k]=0; k=0; ToCom1Str(buf); }//if start }//while END3: RestoreCom1(); LCDPrintf("\n\rLog has been finished"); LCDPrintf("\n\rPress any key to end this program"); Getch(); Print("\n\ri=%lu",i-1); Print("\n\rk=%d",k); Print("\n\re=%d",e); Print("\n\rEnd3"); return 0; END2: return 1; }