@@ -9,15 +9,16 @@ SARA_R5::SARA_R5()
9
9
UBX_CELL_error_t SARA_R5::setUtimeMode (UBX_CELL_utime_mode_t mode, UBX_CELL_utime_sensor_t sensor)
10
10
{
11
11
UBX_CELL_error_t err;
12
+ size_t cmdLen = strlen (UBX_CELL_GNSS_REQUEST_TIME) + 16 ;
12
13
char *command;
13
14
14
- command = ubx_cell_calloc_char (strlen (UBX_CELL_GNSS_REQUEST_TIME) + 16 );
15
+ command = ubx_cell_calloc_char (cmdLen );
15
16
if (command == nullptr )
16
17
return UBX_CELL_ERROR_OUT_OF_MEMORY;
17
18
if (mode == UBX_CELL_UTIME_MODE_STOP) // stop UTIME does not require a sensor
18
- sprintf (command, " %s=%d" , UBX_CELL_GNSS_REQUEST_TIME, mode);
19
+ snprintf (command, cmdLen , " %s=%d" , UBX_CELL_GNSS_REQUEST_TIME, mode);
19
20
else
20
- sprintf (command, " %s=%d,%d" , UBX_CELL_GNSS_REQUEST_TIME, mode, sensor);
21
+ snprintf (command, cmdLen , " %s=%d,%d" , UBX_CELL_GNSS_REQUEST_TIME, mode, sensor);
21
22
22
23
err = sendCommandWithResponse (command, UBX_CELL_RESPONSE_OK_OR_ERROR, nullptr , UBX_CELL_10_SEC_TIMEOUT);
23
24
free (command);
@@ -27,16 +28,17 @@ UBX_CELL_error_t SARA_R5::setUtimeMode(UBX_CELL_utime_mode_t mode, UBX_CELL_utim
27
28
UBX_CELL_error_t SARA_R5::getUtimeMode (UBX_CELL_utime_mode_t *mode, UBX_CELL_utime_sensor_t *sensor)
28
29
{
29
30
UBX_CELL_error_t err;
31
+ size_t cmdLen = strlen (UBX_CELL_GNSS_REQUEST_TIME) + 2 ;
30
32
char *command;
31
33
char *response;
32
34
33
35
UBX_CELL_utime_mode_t m;
34
36
UBX_CELL_utime_sensor_t s;
35
37
36
- command = ubx_cell_calloc_char (strlen (UBX_CELL_GNSS_REQUEST_TIME) + 2 );
38
+ command = ubx_cell_calloc_char (cmdLen );
37
39
if (command == nullptr )
38
40
return UBX_CELL_ERROR_OUT_OF_MEMORY;
39
- sprintf (command, " %s?" , UBX_CELL_GNSS_REQUEST_TIME);
41
+ snprintf (command, cmdLen , " %s?" , UBX_CELL_GNSS_REQUEST_TIME);
40
42
41
43
response = ubx_cell_calloc_char (minimumResponseAllocation);
42
44
if (response == nullptr )
@@ -83,12 +85,13 @@ UBX_CELL_error_t SARA_R5::getUtimeMode(UBX_CELL_utime_mode_t *mode, UBX_CELL_uti
83
85
UBX_CELL_error_t SARA_R5::setUtimeIndication (UBX_CELL_utime_urc_configuration_t config)
84
86
{
85
87
UBX_CELL_error_t err;
88
+ size_t cmdLen = strlen (UBX_CELL_GNSS_TIME_INDICATION) + 16 ;
86
89
char *command;
87
90
88
- command = ubx_cell_calloc_char (strlen (UBX_CELL_GNSS_TIME_INDICATION) + 16 );
91
+ command = ubx_cell_calloc_char (cmdLen );
89
92
if (command == nullptr )
90
93
return UBX_CELL_ERROR_OUT_OF_MEMORY;
91
- sprintf (command, " %s=%d" , UBX_CELL_GNSS_TIME_INDICATION, config);
94
+ snprintf (command, cmdLen , " %s=%d" , UBX_CELL_GNSS_TIME_INDICATION, config);
92
95
93
96
err = sendCommandWithResponse (command, UBX_CELL_RESPONSE_OK_OR_ERROR, nullptr , UBX_CELL_STANDARD_RESPONSE_TIMEOUT);
94
97
free (command);
@@ -98,15 +101,16 @@ UBX_CELL_error_t SARA_R5::setUtimeIndication(UBX_CELL_utime_urc_configuration_t
98
101
UBX_CELL_error_t SARA_R5::getUtimeIndication (UBX_CELL_utime_urc_configuration_t *config)
99
102
{
100
103
UBX_CELL_error_t err;
104
+ size_t cmdLen = strlen (UBX_CELL_GNSS_TIME_INDICATION) + 2 ;
101
105
char *command;
102
106
char *response;
103
107
104
108
UBX_CELL_utime_urc_configuration_t c;
105
109
106
- command = ubx_cell_calloc_char (strlen (UBX_CELL_GNSS_TIME_INDICATION) + 2 );
110
+ command = ubx_cell_calloc_char (cmdLen );
107
111
if (command == nullptr )
108
112
return UBX_CELL_ERROR_OUT_OF_MEMORY;
109
- sprintf (command, " %s?" , UBX_CELL_GNSS_TIME_INDICATION);
113
+ snprintf (command, cmdLen , " %s?" , UBX_CELL_GNSS_TIME_INDICATION);
110
114
111
115
response = ubx_cell_calloc_char (minimumResponseAllocation);
112
116
if (response == nullptr )
@@ -146,15 +150,16 @@ UBX_CELL_error_t SARA_R5::getUtimeIndication(UBX_CELL_utime_urc_configuration_t
146
150
UBX_CELL_error_t SARA_R5::setUtimeConfiguration (int32_t offsetNanoseconds, int32_t offsetSeconds)
147
151
{
148
152
UBX_CELL_error_t err;
153
+ size_t cmdLen = strlen (UBX_CELL_GNSS_TIME_CONFIGURATION) + 48 ;
149
154
char *command;
150
155
151
- command = ubx_cell_calloc_char (strlen (UBX_CELL_GNSS_TIME_CONFIGURATION) + 48 );
156
+ command = ubx_cell_calloc_char (cmdLen );
152
157
if (command == nullptr )
153
158
return UBX_CELL_ERROR_OUT_OF_MEMORY;
154
159
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
155
- sprintf (command, " %s=%d,%d" , UBX_CELL_GNSS_TIME_CONFIGURATION, offsetNanoseconds, offsetSeconds);
160
+ snprintf (command, cmdLen , " %s=%d,%d" , UBX_CELL_GNSS_TIME_CONFIGURATION, offsetNanoseconds, offsetSeconds);
156
161
#else
157
- sprintf (command, " %s=%ld,%ld" , UBX_CELL_GNSS_TIME_CONFIGURATION, offsetNanoseconds, offsetSeconds);
162
+ snprintf (command, cmdLen , " %s=%ld,%ld" , UBX_CELL_GNSS_TIME_CONFIGURATION, offsetNanoseconds, offsetSeconds);
158
163
#endif
159
164
160
165
err = sendCommandWithResponse (command, UBX_CELL_RESPONSE_OK_OR_ERROR, nullptr , UBX_CELL_STANDARD_RESPONSE_TIMEOUT);
@@ -165,16 +170,17 @@ UBX_CELL_error_t SARA_R5::setUtimeConfiguration(int32_t offsetNanoseconds, int32
165
170
UBX_CELL_error_t SARA_R5::getUtimeConfiguration (int32_t *offsetNanoseconds, int32_t *offsetSeconds)
166
171
{
167
172
UBX_CELL_error_t err;
173
+ size_t cmdLen = strlen (UBX_CELL_GNSS_TIME_CONFIGURATION) + 2 ;
168
174
char *command;
169
175
char *response;
170
176
171
177
int32_t ons;
172
178
int32_t os;
173
179
174
- command = ubx_cell_calloc_char (strlen (UBX_CELL_GNSS_TIME_CONFIGURATION) + 2 );
180
+ command = ubx_cell_calloc_char (cmdLen );
175
181
if (command == nullptr )
176
182
return UBX_CELL_ERROR_OUT_OF_MEMORY;
177
- sprintf (command, " %s?" , UBX_CELL_GNSS_TIME_CONFIGURATION);
183
+ snprintf (command, cmdLen , " %s?" , UBX_CELL_GNSS_TIME_CONFIGURATION);
178
184
179
185
response = ubx_cell_calloc_char (minimumResponseAllocation);
180
186
if (response == nullptr )
@@ -218,15 +224,16 @@ UBX_CELL_error_t SARA_R5::getUtimeConfiguration(int32_t *offsetNanoseconds, int3
218
224
UBX_CELL_error_t SARA_R5::setPDPconfiguration (int profile, UBX_CELL_pdp_configuration_parameter_t parameter, int value)
219
225
{
220
226
UBX_CELL_error_t err;
227
+ size_t cmdLen = strlen (UBX_CELL_MESSAGE_PDP_CONFIG) + 24 ;
221
228
char *command;
222
229
223
230
if (profile >= UBX_CELL_NUM_PSD_PROFILES)
224
231
return UBX_CELL_ERROR_ERROR;
225
232
226
- command = ubx_cell_calloc_char (strlen (UBX_CELL_MESSAGE_PDP_CONFIG) + 24 );
233
+ command = ubx_cell_calloc_char (cmdLen );
227
234
if (command == nullptr )
228
235
return UBX_CELL_ERROR_OUT_OF_MEMORY;
229
- sprintf (command, " %s=%d,%d,%d" , UBX_CELL_MESSAGE_PDP_CONFIG, profile, parameter, value);
236
+ snprintf (command, cmdLen , " %s=%d,%d,%d" , UBX_CELL_MESSAGE_PDP_CONFIG, profile, parameter, value);
230
237
231
238
err = sendCommandWithResponse (command, UBX_CELL_RESPONSE_OK_OR_ERROR, nullptr , UBX_CELL_STANDARD_RESPONSE_TIMEOUT);
232
239
@@ -244,15 +251,16 @@ UBX_CELL_error_t SARA_R5::setPDPconfiguration(int profile, UBX_CELL_pdp_configur
244
251
String value)
245
252
{
246
253
UBX_CELL_error_t err;
254
+ size_t cmdLen = strlen (UBX_CELL_MESSAGE_PDP_CONFIG) + 64 ;
247
255
char *command;
248
256
249
257
if (profile >= UBX_CELL_NUM_PSD_PROFILES)
250
258
return UBX_CELL_ERROR_ERROR;
251
259
252
- command = ubx_cell_calloc_char (strlen (UBX_CELL_MESSAGE_PDP_CONFIG) + 64 );
260
+ command = ubx_cell_calloc_char (cmdLen );
253
261
if (command == nullptr )
254
262
return UBX_CELL_ERROR_OUT_OF_MEMORY;
255
- sprintf (command, " %s=%d,%d,\" %s\" " , UBX_CELL_MESSAGE_PDP_CONFIG, profile, parameter, value.c_str ());
263
+ snprintf (command, cmdLen , " %s=%d,%d,\" %s\" " , UBX_CELL_MESSAGE_PDP_CONFIG, profile, parameter, value.c_str ());
256
264
257
265
err = sendCommandWithResponse (command, UBX_CELL_RESPONSE_OK_OR_ERROR, nullptr , UBX_CELL_STANDARD_RESPONSE_TIMEOUT);
258
266
@@ -264,15 +272,16 @@ UBX_CELL_error_t SARA_R5::setPDPconfiguration(int profile, UBX_CELL_pdp_configur
264
272
IPAddress value)
265
273
{
266
274
UBX_CELL_error_t err;
275
+ size_t cmdLen = strlen (UBX_CELL_MESSAGE_PDP_CONFIG) + 64 ;
267
276
char *command;
268
277
269
278
if (profile >= UBX_CELL_NUM_PSD_PROFILES)
270
279
return UBX_CELL_ERROR_ERROR;
271
280
272
- command = ubx_cell_calloc_char (strlen (UBX_CELL_MESSAGE_PDP_CONFIG) + 64 );
281
+ command = ubx_cell_calloc_char (cmdLen );
273
282
if (command == nullptr )
274
283
return UBX_CELL_ERROR_OUT_OF_MEMORY;
275
- sprintf (command, " %s=%d,%d,\" %d.%d.%d.%d\" " , UBX_CELL_MESSAGE_PDP_CONFIG, profile, parameter, value[0 ], value[1 ],
284
+ snprintf (command, cmdLen , " %s=%d,%d,\" %d.%d.%d.%d\" " , UBX_CELL_MESSAGE_PDP_CONFIG, profile, parameter, value[0 ], value[1 ],
276
285
value[2 ], value[3 ]);
277
286
278
287
err = sendCommandWithResponse (command, UBX_CELL_RESPONSE_OK_OR_ERROR, nullptr , UBX_CELL_STANDARD_RESPONSE_TIMEOUT);
@@ -284,15 +293,16 @@ UBX_CELL_error_t SARA_R5::setPDPconfiguration(int profile, UBX_CELL_pdp_configur
284
293
UBX_CELL_error_t SARA_R5::performPDPaction (int profile, UBX_CELL_pdp_actions_t action)
285
294
{
286
295
UBX_CELL_error_t err;
296
+ size_t cmdLen = strlen (UBX_CELL_MESSAGE_PDP_ACTION) + 32 ;
287
297
char *command;
288
298
289
299
if (profile >= UBX_CELL_NUM_PSD_PROFILES)
290
300
return UBX_CELL_ERROR_ERROR;
291
301
292
- command = ubx_cell_calloc_char (strlen (UBX_CELL_MESSAGE_PDP_ACTION) + 32 );
302
+ command = ubx_cell_calloc_char (cmdLen );
293
303
if (command == nullptr )
294
304
return UBX_CELL_ERROR_OUT_OF_MEMORY;
295
- sprintf (command, " %s=%d,%d" , UBX_CELL_MESSAGE_PDP_ACTION, profile, action);
305
+ snprintf (command, cmdLen , " %s=%d,%d" , UBX_CELL_MESSAGE_PDP_ACTION, profile, action);
296
306
297
307
err = sendCommandWithResponse (command, UBX_CELL_RESPONSE_OK_OR_ERROR, nullptr , UBX_CELL_STANDARD_RESPONSE_TIMEOUT);
298
308
@@ -302,6 +312,7 @@ UBX_CELL_error_t SARA_R5::performPDPaction(int profile, UBX_CELL_pdp_actions_t a
302
312
303
313
UBX_CELL_error_t SARA_R5::getNetworkAssignedIPAddress (int profile, IPAddress *address)
304
314
{
315
+ size_t cmdLen = strlen (UBX_CELL_NETWORK_ASSIGNED_DATA) + 16 ;
305
316
char *command;
306
317
char *response;
307
318
UBX_CELL_error_t err;
@@ -310,10 +321,10 @@ UBX_CELL_error_t SARA_R5::getNetworkAssignedIPAddress(int profile, IPAddress *ad
310
321
int paramTag = 0 ; // 0: IP address: dynamic IP address assigned during PDP context activation
311
322
int paramVals[4 ];
312
323
313
- command = ubx_cell_calloc_char (strlen (UBX_CELL_NETWORK_ASSIGNED_DATA) + 16 );
324
+ command = ubx_cell_calloc_char (cmdLen );
314
325
if (command == nullptr )
315
326
return UBX_CELL_ERROR_OUT_OF_MEMORY;
316
- sprintf (command, " %s=%d,%d" , UBX_CELL_NETWORK_ASSIGNED_DATA, profile, paramTag);
327
+ snprintf (command, cmdLen , " %s=%d,%d" , UBX_CELL_NETWORK_ASSIGNED_DATA, profile, paramTag);
317
328
318
329
response = ubx_cell_calloc_char (minimumResponseAllocation);
319
330
if (response == nullptr )
0 commit comments