Skip to content

Commit 138bb85

Browse files
committed
Allocate memory for the AssistNow data
1 parent a2134bc commit 138bb85

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

examples/SARA-R5_Example12_AssistNowOnline/SARA-R5_Example12_AssistNowOnline.ino

+6-3
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,12 @@ void setup()
185185
Serial.println(fileSize);
186186

187187
// Read the data from file
188-
char theAssistData[fileSize];
189-
if (mySARA.getFileContents(theFilename, (char *)theAssistData) != SARA_R5_SUCCESS)
188+
char *theAssistData = new char[fileSize];
189+
if (mySARA.getFileContents(theFilename, theAssistData) != SARA_R5_SUCCESS)
190190
{
191191
Serial.println(F("getFileContents failed! Freezing..."));
192192
while (1)
193-
; // Do nothing more
193+
; // Do nothing more
194194
}
195195

196196
//prettyPrintChars(theAssistData, fileSize); // Uncomment this line to see the whole file contents (including the HTTP header)
@@ -211,6 +211,9 @@ void setup()
211211
// Wait for up to 100ms for each ACK to arrive! 100ms is a bit excessive... 7ms is nearer the mark.
212212
myGNSS.pushAssistNowData((const uint8_t *)theAssistData, fileSize, SFE_UBLOX_MGA_ASSIST_ACK_YES, 100);
213213

214+
// Delete the memory allocated to store the AssistNow data
215+
delete[] theAssistData;
216+
214217
// Set setI2CpollingWait to 125ms to avoid pounding the I2C bus
215218
myGNSS.setI2CpollingWait(125);
216219

examples/SARA-R5_Example14_AssistNowOffline/SARA-R5_Example14_AssistNowOffline.ino

+6-3
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ void setup()
222222
Serial.println(fileSize);
223223

224224
// Read the data from file
225-
char theAssistData[fileSize];
226-
if (mySARA.getFileContents(theFilename, (char *)theAssistData) != SARA_R5_SUCCESS)
225+
char *theAssistData = new char[fileSize];
226+
if (mySARA.getFileContents(theFilename, theAssistData) != SARA_R5_SUCCESS)
227227
{
228228
Serial.println(F("getFileContents failed! Freezing..."));
229229
while (1)
@@ -322,7 +322,10 @@ void setup()
322322
// It will ignore the HTTP header at the start of the AssistNow file.
323323
myGNSS.pushAssistNowData(todayStart, true, (const uint8_t *)theAssistData, tomorrowStart - todayStart, SFE_UBLOX_MGA_ASSIST_ACK_YES, 100);
324324

325-
// Set setI2CpollingWait to 125ms to avoid pounding the I2C bus
325+
// Delete the memory allocated to store the AssistNow data
326+
delete[] theAssistData;
327+
328+
// Set setI2CpollingWait to 125ms to avoid pounding the I2C bus
326329
myGNSS.setI2CpollingWait(125);
327330
}
328331

0 commit comments

Comments
 (0)