// GPS logger - Copyright Vision Software 2000 //************************************************************** // The input and output buffers sizes are defined here. If these // are not define to be a (2^n)-1, where n = 1...15, or they are // not define at all, they will be defaulted to 31 and a compiler // warning will be displayed. //************************************************************** #define BINBUFSIZE 255 // serial buffer size must be a power of 2 - 1 #define BOUTBUFSIZE 255 // output buffer #define CINBUFSIZE 255 // serial buffer size must be a power of 2 - 1 #define COUTBUFSIZE 255 // output buffer #define maxs 254 #define timeout 3000UL // will time out 3000 milliseconds after receiving // a character unless cof_serBread completes main() { int getOk, done; int vswitch1,vswitch2,vswitch3,reci,outcount,wrapcount; char s[maxs + 1]; // plus 1 for null terminator char recs[300][70]; wrapcount=299; // maximum number of records done = 0; vswitch1=0; // initialize virtual switch as off vswitch2=0; vswitch3=0; reci=0; // recorded lines counter outcount=0; // output lines counter WrPortI(SPCR, &SPCRShadow, 0x84); // setup parallel port A as output WrPortI(PADR, &PADRShadow, 0xff); // turn off all LED's serBopen(4800); serCopen(4800); while (!done) { if( (PADRShadow & 1) == vswitch1) BitWrPortI(PADR, &PADRShadow, !vswitch1, 0); // light the LED depending on the switch if( ((PADRShadow & 2) >> 1) == vswitch2) BitWrPortI(PADR, &PADRShadow, !vswitch2 , 1); // light the LED depending on the switch if( ((PADRShadow & 4) >> 2) == vswitch3) BitWrPortI(PADR, &PADRShadow, !vswitch3 , 2); // light the LED depending on the switch loophead(); costate { // read a line of the GPS data wfd getOk = cof_serBgets(s, maxs, timeout); // yields until return or null terminated string if (getOk) { vswitch2 = !vswitch2; if ( (s[3]=='G') && (s[4]=='G') && (s[5]=='A') ) { //only $GPGGA lines if ( ((s[11]=='0') && (s[12]=='0')) || //only at 30 second intervals ((s[11]=='1') && (s[12]=='5')) || ((s[11]=='3') && (s[12]=='0')) || ((s[11]=='4') && (s[12]=='5')) ){ //00, 15, 30, or 45 seconds only strcpy(recs[reci],s); reci++; if (reci>wrapcount) //wrap the index reci=0; vswitch1 = !vswitch1; s[3]=0; //prevent a false repeat } } } } // print the saved lines costate { if ((PADRShadow & 4) == 4){ serCputs("GPS Logger v1.0\n\r"); while(reci!=0) { // printf("%s\n",recs[outcount]); wfd cof_serCputs(recs[outcount]); // then yields until the string is written wfd cof_serCputs(" \n\r"); yield; outcount++; if (outcount>=reci){ //end reci=0; outcount=0; } } vswitch3 = !vswitch3; // reset the LED } } // end of costate // also check button 1 and toggle vswitch on or off costate { if (BitRdPortI(PBDR, 2)) abort; // if button not down skip out of costatement waitfor(DelayMs(50)); // wait 50 ms if(BitRdPortI(PBDR,2)) abort; // if button not still down skip out vswitch3 = !vswitch3; // toggle virtual switch since button was down 50 ms // now wait for the button to be up for at least 200 ms before considering another toggle while (1) { waitfor(BitRdPortI(PBDR, 2)); // wait for button to go up waitfor(DelayMs(200)); // wait additional 200 milliseconds if (BitRdPortI(PBDR,2)) break; // if button still up break out of while loop } } // end of costate } while (serBwrFree() != BOUTBUFSIZE) ; // allow transmission to complete before closing serBclose(); }