1
1
/*
2
- SparkFun SBF in SPARTN test example sketch
2
+ SparkFun SBF-in- SPARTN test example sketch
3
3
4
4
The mosaic-X5 can output raw L-Band (LBandBeam1) data, interspersed with SBF messages
5
5
6
- This example demonstrates how to use two parsers to extract the SBF from the L-Band stream
6
+ This example demonstrates how to use two parsers to separate the SBF from the L-Band stream
7
+ and extract SPARTN from the remaining raw L-Band
7
8
8
9
License: MIT. Please see LICENSE.md for more details
9
10
*/
@@ -109,7 +110,6 @@ const uint8_t rawDataStream[] =
109
110
110
111
uint32_t dataOffset1;
111
112
SEMP_PARSE_STATE *parse1;
112
- uint32_t dataOffset2;
113
113
SEMP_PARSE_STATE *parse2;
114
114
115
115
// ----------------------------------------
@@ -133,36 +133,30 @@ void setup()
133
133
if (!parse1)
134
134
reportFatalError (" Failed to initialize parser 1" );
135
135
136
+ sempEnableDebugOutput (parse1); // Debug - comment if desired
137
+
138
+ // Add the callback for invalid SBF data,
139
+ // to allow it to be passed to the SPARTN parser
140
+ sempSbfSetInvalidDataCallback (parse1, invalidSbfData);
141
+
136
142
parse2 = sempBeginParser (parserTable2, parserCount2,
137
143
parser2Names, parser2NameCount,
138
144
0 , BUFFER_LENGTH, processSpartnMessage, " SPARTN_Test" );
139
145
if (!parse2)
140
146
reportFatalError (" Failed to initialize parser 2" );
141
147
148
+ sempEnableDebugOutput (parse2); // Debug - comment if desired
149
+
142
150
// Obtain a raw data stream from somewhere
143
151
Serial.printf (" Raw data stream: %d bytes\r\n " , RAW_DATA_BYTES);
144
152
145
153
// The raw data stream is passed to the SBF parser one byte at a time
146
- sempEnableDebugOutput (parse1);
147
-
148
- // Any data which is not SBF is passed to the SPARTN parser
149
- sempEnableDebugOutput (parse2);
150
-
154
+ // Any data which is not SBF is passed to the SPARTN parser via the callback
151
155
for (dataOffset1 = 0 ; dataOffset1 < RAW_DATA_BYTES; dataOffset1++)
152
156
{
153
157
// Update the SBF parser state based on the incoming byte
158
+ // Non-SBF data is parsed automatically by invalidSbfData
154
159
sempParseNextByte (parse1, rawDataStream[dataOffset1]);
155
-
156
- // If the data is not SBF, the state will return to sempFirstByte
157
- if (parse1->state == sempFirstByte)
158
- {
159
- // Data is not SBF, so pass it to the SPARTN parser
160
- for (dataOffset2 = 0 ; dataOffset2 < parse1->length ; dataOffset2++)
161
- {
162
- // Update the SPARTN parser state based on the non-SBF byte
163
- sempParseNextByte (parse2, parse1->buffer [dataOffset2]);
164
- }
165
- }
166
160
}
167
161
168
162
// Done parsing the data
@@ -176,6 +170,18 @@ void loop()
176
170
// Nothing to do here...
177
171
}
178
172
173
+ // Callback from within the SBF parser when invalid data is identified
174
+ // The data is passed on to the SPARTN parser
175
+ void invalidSbfData (SEMP_PARSE_STATE *parse)
176
+ {
177
+ // Data is not SBF, so pass it to the SPARTN parser
178
+ for (uint32_t dataOffset = 0 ; dataOffset < parse->length ; dataOffset++)
179
+ {
180
+ // Update the SPARTN parser state based on the non-SBF byte
181
+ sempParseNextByte (parse2, parse->buffer [dataOffset]);
182
+ }
183
+ }
184
+
179
185
// Call back from within parser, for end of message
180
186
// Process a complete message incoming from parser
181
187
void processSbfMessage (SEMP_PARSE_STATE *parse, uint16_t type)
@@ -213,15 +219,13 @@ void processSpartnMessage(SEMP_PARSE_STATE *parse, uint16_t type)
213
219
SEMP_SCRATCH_PAD *scratchPad = (SEMP_SCRATCH_PAD *)parse->scratchPad ;
214
220
215
221
static bool displayOnce = true ;
216
- uint32_t offset;
217
222
218
223
// Display the raw message
219
224
Serial.println ();
220
- offset = dataOffset2 + 1 - parse->length ;
221
- Serial.printf (" Valid SPARTN message, type %d, subtype %d : %d bytes at 0x%08lx (%ld)\r\n " ,
225
+ Serial.printf (" Valid SPARTN message, type %d, subtype %d : %d bytes\r\n " ,
222
226
scratchPad->spartn .messageType ,
223
227
scratchPad->spartn .messageSubtype ,
224
- parse->length , offset, offset );
228
+ parse->length );
225
229
dumpBuffer (parse->buffer , parse->length );
226
230
227
231
// Display the parser state
0 commit comments