Rev 3 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3 | Rev 4 | ||
---|---|---|---|
Line 31... | Line 31... | ||
31 | decodePacket(char *linebuff, int linePos, Location *loc); |
31 | decodePacket(char *linebuff, int linePos, Location *loc); |
32 | 32 | ||
33 | bool updateLocation(Location *loc, usart_ctl *uc) |
33 | bool updateLocation(Location *loc, usart_ctl *uc) |
34 | { |
34 | { |
35 | unsigned chars = SerialCharsReceived(uc); |
35 | unsigned chars = SerialCharsReceived(uc); |
36 | if (!chars) |
36 | if (!chars) |
37 | return false; // nothing to read, return immediately |
37 | return false; // nothing to read, return immediately |
38 | 38 | ||
39 | for (int i = 0; i < chars; i++) |
39 | for (int i = 0; i < chars; i++) |
- | 40 | { |
|
- | 41 | char c = GetCharSerial(uc); |
|
- | 42 | switch (lineState) |
|
40 | { |
43 | { |
- | 44 | case SEARCH: |
|
- | 45 | if (c != '$') |
|
- | 46 | break; |
|
41 | char c = GetCharSerial(uc); |
47 | lineState = READING; |
- | 48 | linePos = 0; |
|
- | 49 | case READING: |
|
42 | switch (lineState) |
50 | if (c == '\r') |
43 | { |
51 | { |
44 | case SEARCH: |
52 | // log the actual time of reading |
- | 53 | ||
45 | if (c != '$') |
54 | // handle the packet |
46 | break; |
55 | bool success = decodePacket(linebuff, linePos, loc); |
- | 56 | ||
47 | lineState = READING; |
57 | lineState = SEARCH; |
- | 58 | ||
48 | linePos = 0; |
59 | linePos = 0; |
- | 60 | return success; |
|
- | 61 | } |
|
- | 62 | // if the line buffer is not full, place character in buffer |
|
- | 63 | if (linePos < sizeof(linebuff)) |
|
- | 64 | linebuff[linePos++] = c; |
|
- | 65 | else |
|
- | 66 | { |
|
49 | case READING: |
67 | lineState = SEARCH; |
- | 68 | // search for the $ in any unread string |
|
- | 69 | for (int i = 1; i < linePos; i++) |
|
50 | if (c == '\r') |
70 | if (linebuff[i] == '$') |
51 | { |
71 | { |
- | 72 | memcpy(linebuff, linebuff + i, linePos - i); |
|
52 | // handle the read code |
73 | linePos = 1; |
53 | bool success = decodePacket(linebuff, linePos, loc); |
74 | linebuff[linePos++] = c; |
54 | lineState = SEARCH; |
75 | lineState = READING; |
- | 76 | } |
|
55 | 77 | ||
- | 78 | if (lineState == SEARCH) |
|
56 | linePos = 0; |
79 | linePos = 0; |
57 | return success; |
- | |
58 | } |
- | |
59 | if (linePos < sizeof(linebuff)) |
- | |
60 | linebuff[linePos++] = c; |
- | |
61 | else |
- | |
62 | { |
- | |
63 | lineState = SEARCH; |
- | |
64 | // search for the $ in any unread string |
- | |
65 | int i; |
- | |
66 | - | ||
67 | for (i = 0; i < linePos; i++) |
- | |
68 | if (linebuff[i] == '$') |
- | |
69 | { |
- | |
70 | memcpy(linebuff, linebuff + i, linePos - i); |
- | |
71 | linePos = 1; |
- | |
72 | linebuff[linePos++] = c; |
- | |
73 | lineState = READING; |
- | |
74 | } |
- | |
75 | - | ||
76 | if (lineState == SEARCH) |
- | |
77 | linePos = 0; |
- | |
78 | } |
- | |
79 | break; |
- | |
80 | } |
80 | } |
- | 81 | break; |
|
- | 82 | } |
|
81 | } |
83 | } |
82 | return false; |
84 | return false; |
83 | } |
85 | } |
84 | 86 | ||
85 | static int8_t |
87 | static int8_t |
Line 209... | Line 211... | ||
209 | if (rmcCallback) |
211 | if (rmcCallback) |
210 | { |
212 | { |
211 | linebuff[linePos++] = '\r'; |
213 | linebuff[linePos++] = '\r'; |
212 | linebuff[linePos++] = '\n'; |
214 | linebuff[linePos++] = '\n'; |
213 | linebuff[linePos++] = 0; |
215 | linebuff[linePos++] = 0; |
- | 216 | ||
214 | rmcCallback((uint8_t *)linebuff, linePos); |
217 | rmcCallback((uint8_t *)linebuff, linePos); |
215 | } |
218 | } |
216 | } |
219 | } |
217 | 220 | ||
218 | return true; |
221 | return true; |