@@ -26,6 +26,27 @@ int pin_UART1_TX = 4;
26
26
int pin_UART1_RX = 13 ;
27
27
28
28
#include < SparkFun_Unicore_GNSS_Arduino_Library.h> // http://librarymanager/All#SparkFun_Unicore_GNSS
29
+ #include < SparkFun_Extensible_Message_Parser.h> // http://librarymanager/All#SparkFun_Extensible_Message_Parser
30
+
31
+ #define NMEA_PARSER_INDEX 0
32
+ #define RTCM_PARSER_INDEX 1
33
+
34
+ // Build the table listing all of the parsers
35
+ SEMP_PARSE_ROUTINE const parserTable[] =
36
+ {
37
+ sempNmeaPreamble,
38
+ sempRtcmPreamble,
39
+ };
40
+ const int parserCount = sizeof (parserTable) / sizeof (parserTable[0 ]);
41
+
42
+ const char * const parserNames[] =
43
+ {
44
+ " NMEA Parser" ,
45
+ " RTCM Parser" ,
46
+ };
47
+ const int parserNameCount = sizeof (parserNames) / sizeof (parserNames[0 ]);
48
+
49
+ SEMP_PARSE_STATE *parse; // State of the parsers
29
50
30
51
UM980 myGNSS;
31
52
@@ -84,13 +105,94 @@ void setup()
84
105
85
106
myGNSS.saveConfiguration (); // Save the current configuration into non-volatile memory (NVM)
86
107
87
- Serial.println (" Output will be a mix of NMEA and binary RTCM non-visible characters" );
108
+ // Initialize the parser
109
+ parse = sempBeginParser (parserTable, parserCount,
110
+ parserNames, parserNameCount,
111
+ 0 , 3000 , processMessage, " Example 17 Parser" );
112
+ if (!parse)
113
+ while (1 )
114
+ {
115
+ Serial.println (" HALTED: Failed to initialize the parser!" );
116
+ sleep (15 );
117
+ }
118
+
119
+ Serial.println (" Output will be a mix of NMEA and binary RTCM" );
88
120
}
89
121
90
122
void loop ()
91
123
{
92
- // Read in NMEA from the UM980
93
- // RTCM is binary and will appear as random characters.
124
+ // Read the raw data one byte at a time and update the parser state
125
+ // based on the incoming byte
94
126
while (SerialGNSS.available ())
95
- Serial.write (SerialGNSS.read ());
127
+ {
128
+ // Read the byte from the UM980
129
+ uint8_t incoming = SerialGNSS.read ();
130
+
131
+ // Parse this byte
132
+ sempParseNextByte (parse, incoming);
133
+ }
134
+ }
135
+
136
+ // Call back from within parser, for end of message
137
+ // Process a complete message incoming from parser
138
+ void processMessage (SEMP_PARSE_STATE *parse, uint16_t type)
139
+ {
140
+ SEMP_SCRATCH_PAD *scratchPad = (SEMP_SCRATCH_PAD *)parse->scratchPad ;
141
+ char *typeName;
142
+
143
+ // Display the raw message
144
+ // The type value is the index into the raw data array
145
+ Serial.println ();
146
+ Serial.printf (" Valid %s message: 0x%04x (%d) bytes\r\n " ,
147
+ parserNames[type], parse->length , parse->length );
148
+ dumpBuffer (parse->buffer , parse->length );
149
+ }
150
+
151
+ // Display the contents of a buffer
152
+ void dumpBuffer (const uint8_t *buffer, uint16_t length)
153
+ {
154
+ int bytes;
155
+ const uint8_t *end;
156
+ int index ;
157
+ char line[128 ];
158
+ uint16_t offset;
159
+
160
+ end = &buffer[length];
161
+ offset = 0 ;
162
+ while (buffer < end)
163
+ {
164
+ // Determine the number of bytes to display on the line
165
+ bytes = end - buffer;
166
+ if (bytes > (16 - (offset & 0xf )))
167
+ bytes = 16 - (offset & 0xf );
168
+
169
+ // Display the offset
170
+ sprintf (line, " 0x%08lx: " , offset);
171
+
172
+ // Skip leading bytes
173
+ for (index = 0 ; index < (offset & 0xf ); index ++)
174
+ sprintf (&line[strlen (line)], " " );
175
+
176
+ // Display the data bytes
177
+ for (index = 0 ; index < bytes; index ++)
178
+ sprintf (&line[strlen (line)], " %02x " , buffer[index ]);
179
+
180
+ // Separate the data bytes from the ASCII
181
+ for (; index < (16 - (offset & 0xf )); index ++)
182
+ sprintf (&line[strlen (line)], " " );
183
+ sprintf (&line[strlen (line)], " " );
184
+
185
+ // Skip leading bytes
186
+ for (index = 0 ; index < (offset & 0xf ); index ++)
187
+ sprintf (&line[strlen (line)], " " );
188
+
189
+ // Display the ASCII values
190
+ for (index = 0 ; index < bytes; index ++)
191
+ sprintf (&line[strlen (line)], " %c" , ((buffer[index ] < ' ' ) || (buffer[index ] >= 0x7f )) ? ' .' : buffer[index ]);
192
+ Serial.println (line);
193
+
194
+ // Set the next line of data
195
+ buffer += bytes;
196
+ offset += bytes;
197
+ }
96
198
}
0 commit comments