Skip to content

Commit 2f9d637

Browse files
committed
Update examples 12 and 14 to use the updated getFileContents
1 parent 9d69e1e commit 2f9d637

File tree

4 files changed

+154
-24
lines changed

4 files changed

+154
-24
lines changed

examples/SARA-R5_Example12_AssistNowOnline/SARA-R5_AssistNow_Online.ino

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,62 @@ void prettyPrintString(String theString) // Pretty-print a String in HEX and ASC
186186

187187
Serial.println();
188188
}
189+
190+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
191+
192+
void prettyPrintChars(char *theData, int theLength) // Pretty-print char data in HEX and ASCII format
193+
{
194+
Serial.println();
195+
Serial.print(F("String length is "));
196+
Serial.print(theLength);
197+
Serial.print(F(" (0x"));
198+
Serial.print(theLength, HEX);
199+
Serial.println(F(")"));
200+
Serial.println();
201+
202+
for (int i = 0; i < theLength; i += 16)
203+
{
204+
if (i < 10000) Serial.print(F("0"));
205+
if (i < 1000) Serial.print(F("0"));
206+
if (i < 100) Serial.print(F("0"));
207+
if (i < 10) Serial.print(F("0"));
208+
Serial.print(i);
209+
210+
Serial.print(F(" 0x"));
211+
212+
if (i < 0x1000) Serial.print(F("0"));
213+
if (i < 0x100) Serial.print(F("0"));
214+
if (i < 0x10) Serial.print(F("0"));
215+
Serial.print(i, HEX);
216+
217+
Serial.print(F(" "));
218+
219+
int j;
220+
for (j = 0; ((i + j) < theLength) && (j < 16); j++)
221+
{
222+
if (theData[i + j] < 0x10) Serial.print(F("0"));
223+
Serial.print(theData[i + j], HEX);
224+
Serial.print(F(" "));
225+
}
226+
227+
if (((i + j) == theLength) && (j < 16))
228+
{
229+
for (int k = 0; k < (16 - (theLength % 16)); k++)
230+
{
231+
Serial.print(F(" "));
232+
}
233+
}
234+
235+
for (j = 0; ((i + j) < theLength) && (j < 16); j++)
236+
{
237+
if ((theData[i + j] >= 0x20) && (theData[i + j] <= 0x7E))
238+
Serial.write(theData[i + j]);
239+
else
240+
Serial.print(F("."));
241+
}
242+
243+
Serial.println();
244+
}
245+
246+
Serial.println();
247+
}

examples/SARA-R5_Example12_AssistNowOnline/SARA-R5_Example12_AssistNowOnline.ino

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,27 @@ void setup()
173173

174174
// Read the AssistNow data from file and push it to the module
175175

176+
int fileSize;
177+
if (mySARA.getFileSize(theFilename, &fileSize) != SARA_R5_SUCCESS)
178+
{
179+
Serial.print(F("getFileSize failed! Freezing..."));
180+
while (1)
181+
; // Do nothing more
182+
}
183+
184+
Serial.print(F("AssistNow file size is: "));
185+
Serial.println(fileSize);
186+
176187
// Read the data from file
177-
String theAssistData = "";
178-
if (mySARA.getFileContents(theFilename, &theAssistData) != SARA_R5_SUCCESS)
188+
char theAssistData[fileSize];
189+
if (mySARA.getFileContents(theFilename, (char *)theAssistData) != SARA_R5_SUCCESS)
179190
{
180191
Serial.println(F("getFileContents failed! Freezing..."));
181192
while (1)
182193
; // Do nothing more
183194
}
184195

185-
//prettyPrintString(theAssistData); // Uncomment this line to see the whole file contents (including the HTTP header)
196+
//prettyPrintChars(theAssistData, fileSize); // Uncomment this line to see the whole file contents (including the HTTP header)
186197

187198
// Tell the module to return UBX_MGA_ACK_DATA0 messages when we push the AssistNow data
188199
myGNSS.setAckAiding(1);
@@ -198,7 +209,7 @@ void setup()
198209
// We have called setAckAiding(1) to instruct the module to return MGA-ACK messages.
199210
// So, set the pushAssistNowData mgaAck parameter to SFE_UBLOX_MGA_ASSIST_ACK_YES.
200211
// Wait for up to 100ms for each ACK to arrive! 100ms is a bit excessive... 7ms is nearer the mark.
201-
myGNSS.pushAssistNowData(theAssistData, theAssistData.length(), SFE_UBLOX_MGA_ASSIST_ACK_YES, 100);
212+
myGNSS.pushAssistNowData((const uint8_t *)theAssistData, fileSize, SFE_UBLOX_MGA_ASSIST_ACK_YES, 100);
202213

203214
// Set setI2CpollingWait to 125ms to avoid pounding the I2C bus
204215
myGNSS.setI2CpollingWait(125);

examples/SARA-R5_Example14_AssistNowOffline/SARA-R5_AssistNow_Online.ino renamed to examples/SARA-R5_Example14_AssistNowOffline/SARA-R5_AssistNow_Offline.ino

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,6 @@ bool getAssistNowOfflineData(String theFilename)
120120
return false;
121121
}
122122

123-
int fileSize;
124-
if (mySARA.getFileSize(theFilename, &fileSize) != SARA_R5_SUCCESS)
125-
{
126-
Serial.print(F("getAssistNowOfflineData: No file written?!"));
127-
return false;
128-
}
129-
130-
Serial.print(F("File size is: "));
131-
Serial.println(fileSize);
132-
133123
return true;
134124
}
135125

@@ -193,3 +183,62 @@ void prettyPrintString(String theString) // Pretty-print a String in HEX and ASC
193183

194184
Serial.println();
195185
}
186+
187+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
188+
189+
void prettyPrintChars(char *theData, int theLength) // Pretty-print char data in HEX and ASCII format
190+
{
191+
Serial.println();
192+
Serial.print(F("String length is "));
193+
Serial.print(theLength);
194+
Serial.print(F(" (0x"));
195+
Serial.print(theLength, HEX);
196+
Serial.println(F(")"));
197+
Serial.println();
198+
199+
for (int i = 0; i < theLength; i += 16)
200+
{
201+
if (i < 10000) Serial.print(F("0"));
202+
if (i < 1000) Serial.print(F("0"));
203+
if (i < 100) Serial.print(F("0"));
204+
if (i < 10) Serial.print(F("0"));
205+
Serial.print(i);
206+
207+
Serial.print(F(" 0x"));
208+
209+
if (i < 0x1000) Serial.print(F("0"));
210+
if (i < 0x100) Serial.print(F("0"));
211+
if (i < 0x10) Serial.print(F("0"));
212+
Serial.print(i, HEX);
213+
214+
Serial.print(F(" "));
215+
216+
int j;
217+
for (j = 0; ((i + j) < theLength) && (j < 16); j++)
218+
{
219+
if (theData[i + j] < 0x10) Serial.print(F("0"));
220+
Serial.print(theData[i + j], HEX);
221+
Serial.print(F(" "));
222+
}
223+
224+
if (((i + j) == theLength) && (j < 16))
225+
{
226+
for (int k = 0; k < (16 - (theLength % 16)); k++)
227+
{
228+
Serial.print(F(" "));
229+
}
230+
}
231+
232+
for (j = 0; ((i + j) < theLength) && (j < 16); j++)
233+
{
234+
if ((theData[i + j] >= 0x20) && (theData[i + j] <= 0x7E))
235+
Serial.write(theData[i + j]);
236+
else
237+
Serial.print(F("."));
238+
}
239+
240+
Serial.println();
241+
}
242+
243+
Serial.println();
244+
}

examples/SARA-R5_Example14_AssistNowOffline/SARA-R5_Example14_AssistNowOffline.ino

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,27 @@ void setup()
210210

211211
// Read the AssistNow data from file
212212

213+
int fileSize;
214+
if (mySARA.getFileSize(theFilename, &fileSize) != SARA_R5_SUCCESS)
215+
{
216+
Serial.print(F("getFileSize failed! Freezing..."));
217+
while (1)
218+
; // Do nothing more
219+
}
220+
221+
Serial.print(F("File size is: "));
222+
Serial.println(fileSize);
223+
213224
// Read the data from file
214-
String theAssistData = "";
215-
if (mySARA.getFileContents(theFilename, &theAssistData) != SARA_R5_SUCCESS)
225+
char theAssistData[fileSize];
226+
if (mySARA.getFileContents(theFilename, (char *)theAssistData) != SARA_R5_SUCCESS)
216227
{
217228
Serial.println(F("getFileContents failed! Freezing..."));
218229
while (1)
219230
; // Do nothing more
220231
}
221232

222-
//prettyPrintString(theAssistData); // Uncomment this line to see the whole file contents (including the HTTP header)
233+
//prettyPrintChars(theAssistData, fileSize); // Uncomment this line to see the whole file contents (including the HTTP header)
223234

224235
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
225236

@@ -254,13 +265,13 @@ void setup()
254265
// Find where the AssistNow data for today starts and ends
255266

256267
size_t todayStart = 0; // Default to sending all the data
257-
size_t tomorrowStart = (size_t)theAssistData.length();
268+
size_t tomorrowStart = (size_t)fileSize;
258269

259-
if (theAssistData.length() > 0)
270+
if (fileSize > 0)
260271
{
261272
// Find the start of today's data
262-
todayStart = myGNSS.findMGAANOForDate(theAssistData, (size_t)theAssistData.length(), year + 2000, month, day);
263-
if (todayStart < (size_t)theAssistData.length())
273+
todayStart = myGNSS.findMGAANOForDate((const uint8_t *)theAssistData, (size_t)fileSize, year + 2000, month, day);
274+
if (todayStart < (size_t)fileSize)
264275
{
265276
Serial.print(F("Found the data for today starting at location "));
266277
Serial.println(todayStart);
@@ -271,8 +282,8 @@ void setup()
271282
}
272283

273284
// Find the start of tomorrow's data
274-
tomorrowStart = myGNSS.findMGAANOForDate(theAssistData, (size_t)theAssistData.length(), year + 2000, month, day, 1);
275-
if (tomorrowStart < (size_t)theAssistData.length())
285+
tomorrowStart = myGNSS.findMGAANOForDate((const uint8_t *)theAssistData, (size_t)fileSize, year + 2000, month, day, 1);
286+
if (tomorrowStart < (size_t)fileSize)
276287
{
277288
Serial.print(F("Found the data for tomorrow starting at location "));
278289
Serial.println(tomorrowStart);
@@ -309,7 +320,7 @@ void setup()
309320
//
310321
// pushAssistNowData is clever and will only push valid UBX-format data.
311322
// It will ignore the HTTP header at the start of the AssistNow file.
312-
myGNSS.pushAssistNowData(todayStart, true, theAssistData, tomorrowStart - todayStart, SFE_UBLOX_MGA_ASSIST_ACK_YES, 100);
323+
myGNSS.pushAssistNowData(todayStart, true, (const uint8_t *)theAssistData, tomorrowStart - todayStart, SFE_UBLOX_MGA_ASSIST_ACK_YES, 100);
313324

314325
// Set setI2CpollingWait to 125ms to avoid pounding the I2C bus
315326
myGNSS.setI2CpollingWait(125);

0 commit comments

Comments
 (0)