1 | /******************************************************************************/
|
2 | extern void MsgHandler(unsigned char newchar)
|
3 | /*******************************************************************************
|
4 | * ABSTRACT: Processes the characters coming in from USART. In this case,
|
5 | * this is the port connected to the gps receiver.
|
6 | *
|
7 | * INPUT: newchar Next character from the serial port.
|
8 | * OUTPUT: None
|
9 | * RETURN: None
|
10 | */
|
11 | {
|
12 | static unsigned char commas; // Number of commas for far in sentence
|
13 | static unsigned char index; // Individual array index
|
14 |
|
15 | if (newchar == 0) // A NULL character resets GPS decoding
|
16 | {
|
17 | commas = 25; // Set to an outrageous value
|
18 | sentence_type = FALSE; // Clear local parse variable
|
19 | return;
|
20 | }
|
21 |
|
22 | if (newchar == '$') // Start of Sentence character, reset
|
23 | {
|
24 | commas = 0; // No commas detected in sentence for far
|
25 | sentence_type = FALSE; // Clear local parse variable
|
26 | return;
|
27 | }
|
28 |
|
29 | if (newchar == ',') // If there is a comma
|
30 | {
|
31 | commas += 1; // Increment the comma count
|
32 | index = 0; // And reset the field index
|
33 | return;
|
34 | }
|
35 |
|
36 | if (commas == 0)
|
37 | {
|
38 | switch(newchar)
|
39 | {
|
40 | case ('C'): // Only the GPRMC sentence contains a "C"
|
41 | sentence_type = GPRMC; // Set local parse variable
|
42 | break;
|
43 | case ('S'): // Take note if sentence contains an "S"
|
44 | sentence_type = 'S'; // ...because we don't want to parse it
|
45 | break;
|
46 | case ('A'): // The GPGGA sentence ID contains "A"
|
47 | if (sentence_type != 'S') // As does GPGSA, which we will ignore
|
48 | sentence_type = GPGGA; // Set local parse variable
|
49 | break;
|
50 | }
|
51 |
|
52 | return;
|
53 | }
|
54 |
|
55 | if (sentence_type == GPGGA) // GPGGA sentence decode initiated
|
56 | {
|
57 | switch (commas)
|
58 | {
|
59 | case (1): // Time field, grab characters
|
60 | Time_Temp[index++] = newchar;
|
61 | return;
|
62 | case (2): // Latitude field, grab chars
|
63 | Latitude_Temp[index++] = newchar;
|
64 | return;
|
65 | case (3):
|
66 | Northsouth_Temp = newchar;
|
67 | return;
|
68 | case (4): // Longitude field, grab chars
|
69 | Longitude_Temp[index++] = newchar;
|
70 | return;
|
71 | case (5):
|
72 | Eastwest_Temp = newchar;
|
73 | return;
|
74 | case (7): // Satellite field, grab chars
|
75 | Satellites_Temp[index++] = newchar;
|
76 | return;
|
77 | case (9): // Altitude field, grab chars
|
78 | Altitude_Temp[index++] = newchar;
|
79 | return;
|
80 | }
|
81 |
|
82 | return;
|
83 | } // end if (sentence_type == GPGGA)
|
84 |
|
85 | if (sentence_type == GPRMC) // GPGGA sentence decode initiated
|
86 | {
|
87 | switch (commas)
|
88 | {
|
89 | case (7): // Speed field, grab characters
|
90 | Speed_Temp[index++] = newchar;
|
91 | return;
|
92 | case (8): // Course field, grab characters
|
93 | Course_Temp[index++] = newchar;
|
94 | return;
|
95 | }
|
96 |
|
97 | return;
|
98 | } // end if (sentence_type == GPRMC)
|
99 |
|
100 | return;
|
101 |
|
102 | } // End MsgHandler(unsigned char newchar)
|