/* (1)This is a demo program which demonstrates how you can use the GPS/GSM function and for 7188XA. (2)It also demonstrates how to use 7-segments LED as a simple HMI tool. (3)Connect the DB-9 connector of GPS receiver to COM1 of 7188XA. Connect the DB-9 connector of GSM module to COM3 of 7188XA. Compiler file: demo.c 7188XA.lib GPS.lib GSM.lib 2002/02/06 written by Tony */ #include #include #include #include"..\lib\7188xa.h" #include"..\lib\GPS.h" #include"..\lib\GSM.h" /***********The following are Functions for HMI****************/ void Shownull(void) { LedOff(); Disable5DigitLed(); } void ShowUTC_h(int hour) { LedOn(); Show5DigitLedWithDot(1,1); Show5DigitLed(2,16); Show5DigitLed(3,16); Show5DigitLed(4,hour/10); Show5DigitLedWithDot(5,hour%10); Enable5DigitLed(); } void ShowUTC_ms(int min,int sec) { LedOn(); Show5DigitLed(1,16); Show5DigitLed(2,min/10); Show5DigitLedWithDot(3,min%10); Show5DigitLed(4,sec/10); Show5DigitLed(5,sec%10); Enable5DigitLed(); } void ShowNS(int NS) { LedOn(); Show5DigitLedWithDot(1,2); Show5DigitLed(2,16); Show5DigitLed(3,16); Show5DigitLed(4,NS/10); Show5DigitLed(5,NS%10); Enable5DigitLed(); } void ShowLat(int degree, int minute) { LedOn(); Show5DigitLed(1,16); Show5DigitLed(2,degree/10); Show5DigitLedWithDot(3,degree%10); Show5DigitLed(4,minute/10); Show5DigitLed(5,minute%10); Enable5DigitLed(); } void ShowEW(int EW) { LedOn(); Show5DigitLedWithDot(1,3); Show5DigitLed(2,16); Show5DigitLed(3,16); Show5DigitLed(4,EW/10); Show5DigitLed(5,EW%10); Enable5DigitLed(); } void ShowLon(int degree, int minute) { LedOn(); Show5DigitLed(1,degree/100); Show5DigitLed(2,(degree%100)/10); Show5DigitLedWithDot(3,degree%10); Show5DigitLed(4,minute/10); Show5DigitLed(5,minute%10); Enable5DigitLed(); } void ShowQua(int Quality) { LedOn(); Show5DigitLedWithDot(1,4); Show5DigitLed(2,16); Show5DigitLed(3,16); Show5DigitLed(4,16); Show5DigitLed(5,Quality); Enable5DigitLed(); } void ShowNOS(int NOS) { LedOn(); Show5DigitLedWithDot(1,5); Show5DigitLed(2,16); Show5DigitLed(3,16); Show5DigitLed(4,16); Show5DigitLed(5,NOS); Enable5DigitLed(); } /*********************the above are Functions for HMI*****************/ void main(void) { char gpgga[512]; char UTC[12],Lat[15],NS[2],Lon[15],EW[2],GPSqua[2],NOS[3]; char ha[3],ma[3],sa[3],drgee1[3],min1[3],drgee2[4],min2[3]; int h,m,s,d1,m1,ns,d2,m2,ew,qua,nos; int i,j,decflag=0,q; STOPWATCH cdt1,cdt2,cdt3; int type; int ver; type=Is7188xa(); /*detect the current operation system*/ if(type){ ver=GetLibVersion(); Print("Hello 7188XA! (Flash memory is %d K)\n\r",type); Print("Library version is %d.%02d",ver>>8,ver&0xff); } else{ Print("Hello PC!, this program is not run under 7188XA."); return; } InstallCom1(4800,8,0,1); InstallCom3(9600,8,0); h=m=s=d1=m1=ns=d2=m2=ew=qua=nos=0; T_StopWatchStart(&cdt1); T_StopWatchStart(&cdt2); T_StopWatchStart(&cdt3); for(;;) { if(Kbhit()){ /*Press 'q' or 'Q' to end program*/ q=Getch(); if(q=='q' || q=='Q'){ Enable5DigitLed(); DelayMs(500); RestoreCom1(); RestoreCom3(); return; } } if(T_StopWatchGetTime(&cdt1)>=1000){ /*Get the NMEA message and handle these string pre second.*/ Get_NMEA(1,"$GPGGA",gpgga); Get_Field(1,gpgga,UTC); Get_Field(2,gpgga,Lat); Get_Field(3,gpgga,NS); Get_Field(4,gpgga,Lon); Get_Field(5,gpgga,EW); Get_Field(6,gpgga,GPSqua); Get_Field(7,gpgga,NOS); for(j=0;j<2;j++){ ha[j]=UTC[j]; ma[j]=UTC[j+2]; sa[j]=UTC[j+4]; } ha[2]=ma[2]=sa[2]=0; h=(atoi(ha))+8;m=atoi(ma);s=atoi(sa); if(h>=24) h=h-24; SetTime(h,m,s); for(j=0;j<2;j++){ drgee1[j]=Lat[j]; min1[j]=Lat[j+2]; } drgee1[3]=min1[3]=0; d1=atoi(drgee1);m1=atoi(min1); if(NS[0]=='N') ns=30; else ns=31; for(j=0;j<5;j++){ if(j<3) drgee2[j]=Lon[j]; else min2[j-3]=Lon[j]; } drgee2[4]=min2[2]=0; d2=atoi(drgee2);m2=atoi(min2); if(EW[0]=='E') ew=50; else ew=51; qua=atoi(GPSqua); nos=atoi(NOS); T_StopWatchStart(&cdt1); } if(T_StopWatchGetTime(&cdt2)>=800){ /*Show the whole NMEA message via HMI display per 0.8 second(if the number of satellite in use are more than 3)*/ if(nos>=3){ if(decflag>15) decflag=0; switch (decflag){ case 0: ShowUTC_h(h); break; case 2: ShowUTC_ms(m,s); break; case 4: ShowNS(ns); break; case 6: ShowLat(d1,m1); break; case 8: ShowEW(ew); break; case 10: ShowLon(d2,m2); break; case 12: ShowQua(qua); break; case 14: ShowNOS(nos); break; default: Shownull(); break; } decflag++; T_StopWatchStart(&cdt2); } else{ /*Only show the UTC via HMI display per 0.8 second(if the number of satellite in use are less than 3)*/ if(decflag>3) decflag=0; switch (decflag){ case 0: ShowUTC_h(h); break; case 2: ShowUTC_ms(m,s); break; default: Shownull(); break; } decflag++; T_StopWatchStart(&cdt2); } } if(T_StopWatchGetTime(&cdt3)>=3600000L){ /*Transmit the NMEA message to remote host via GSM module. per an hour.*/ SMS(3,"0939220164",gpgga); T_StopWatchStart(&cdt3); } } }