Listing 1

Rabbit C Program


1 // GPS logger - © Copyright Vision Software 2000
2 //******************************************************
3 #define BINBUFSIZE 255 // serial buffer size must be a power of 2 - 1
4 #define BOUTBUFSIZE 255 // output buffer
5 #define CINBUFSIZE 255 // serial buffer size must be a power of 2 - 1
6 #define COUTBUFSIZE 255 // output buffer
7 #define maxs 254
8 #define timeout 3000UL // will time out 3000 milliseconds after receiving
9 // a character unless cof_serBread completes
10
11 main()
12 {
13 int getOk, done;
14 int vswitch1,vswitch2,vswitch3,reci,outcount,wrapcount;
15 char s[maxs + 1]; // plus 1 for null terminator
16 char recs[300][70];
17 wrapcount=299; // maximum number of records
18 done = 0;
19 vswitch1=0; // initialize virtual switch as off
20 vswitch2=0;
21 vswitch3=0;
22 reci=0; // recorded lines counter
23 outcount=0; // output lines counter
24
25 WrPortI(SPCR, &SPCRShadow, 0x84); // setup parallel port A as output
26 WrPortI(PADR, &PADRShadow, 0xff); // turn off all LED's
27
28 serBopen(4800);
29 serCopen(4800);
30 while (!done) {
31 if( (PADRShadow & 1) == vswitch1)
32 BitWrPortI(PADR, &PADRShadow, !vswitch1, 0); // light the LED depending on the switch
33 if( ((PADRShadow & 2) >> 1) == vswitch2)
34 BitWrPortI(PADR, &PADRShadow, !vswitch2 , 1); // light the LED depending on the switch
35 if( ((PADRShadow & 4) >> 2) == vswitch3)
36 BitWrPortI(PADR, &PADRShadow, !vswitch3 , 2); // light the LED depending on the switch
37 loophead();
38 costate { // read a line of the GPS data
39 wfd getOk = cof_serBgets(s, maxs, timeout); // yields until return or null terminated string
40 if (getOk) {
41 vswitch2 = !vswitch2;
42 if ( (s[3]=='G') && (s[4]=='G') && (s[5]=='A') ) { //only $GPGGA lines
43 if ( ((s[11]=='0') && (s[12]=='0')) ||
44 ((s[11]=='1') && (s[12]=='5')) ||
45 ((s[11]=='3') && (s[12]=='0')) ||
46 ((s[11]=='4') && (s[12]=='5'))
47 ){ //00, 15, 30, or 45 seconds only
48 strcpy(recs[reci],s);
49 reci++;
50 if (reci>wrapcount) //wrap the index at the end of the array
51 reci=0;
52 vswitch1 = !vswitch1;
53 s[3]=0; //prevent a false repeat
54 }
55 }
56 }
57 }
58
59 // print the saved lines
60 costate {
61 if ((PADRShadow & 4) == 4){
62 serCputs("GPS Logger v1.0\n\r");
63 while(reci!=0) {
64 // printf("%s\n",recs[outcount]); // output to stdio debugger window
65 wfd cof_serCputs(recs[outcount]); // then yields until the string is written
66 wfd cof_serCputs(" \n\r");
67 yield;
68 outcount++;
69 if (outcount>=reci){ //end
70 reci=0;
71 outcount=0;
72 }
73 }
74 vswitch3 = !vswitch3; // reset the LED
75 }
76 } // end of costate
77
78 // also check button 1 and toggle vswitch on or off
79 costate {
80 if (BitRdPortI(PBDR, 2))
81 abort; // if button not down skip out of costatement
82
83 waitfor(DelayMs(50)); // wait 50 ms
84
85 if(BitRdPortI(PBDR,2))
86 abort; // if button not still down skip out
87
88 vswitch3 = !vswitch3; // toggle virtual switch since button was down 50 ms
89

GPS C program file