Skip to content

Commit f18e6db

Browse files
committed
Addressed comments from pull request review.
Removed F macro from Serial.printf calls.
1 parent 42d3d78 commit f18e6db

File tree

2 files changed

+51
-58
lines changed

2 files changed

+51
-58
lines changed

src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp

+46-53
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,6 @@ bool SARA_R5::bufferedPoll(void)
308308
}
309309
}
310310

311-
// This is a bug. event could be nullptr, and even if it is not it is pointing into
312-
// _saraRXBuffer meaning it is calling free on a random pointer whose memory
313-
// may be referenced later.
314-
//free(event);
315311
_bufferedPollReentrant = false;
316312

317313
return handled;
@@ -858,12 +854,12 @@ void SARA_R5::setHTTPCommandCallback(void (*httpCommandRequestCallback)(int prof
858854
_httpCommandRequestCallback = httpCommandRequestCallback;
859855
}
860856

861-
void SARA_R5::setMQTTCommandCallback(void (*mqttCommandRequestCallback)(SARA_R5_mqtt_command_opcode_t command, int result))
857+
void SARA_R5::setMQTTCommandCallback(void (*mqttCommandRequestCallback)(int command, int result))
862858
{
863859
_mqttCommandRequestCallback = mqttCommandRequestCallback;
864860
}
865861

866-
void SARA_R5::setFTPCommandCallback(void (*ftpCommandRequestCallback)(SARA_R5_ftp_command_opcode_t command, int result))
862+
void SARA_R5::setFTPCommandCallback(void (*ftpCommandRequestCallback)(int command, int result))
867863
{
868864
_ftpCommandRequestCallback = ftpCommandRequestCallback;
869865
}
@@ -1618,51 +1614,53 @@ int8_t SARA_R5::rssi(void)
16181614

16191615
SARA_R5_error_t SARA_R5::getExtSignalQuality(signal_quality& signal_quality)
16201616
{
1621-
char *command;
1622-
char *response;
1623-
SARA_R5_error_t err;
1617+
char *command;
1618+
char *response;
1619+
SARA_R5_error_t err;
16241620

1625-
command = sara_r5_calloc_char(strlen(SARA_R5_EXT_SIGNAL_QUALITY) + 1);
1626-
if (command == nullptr)
1627-
{
1628-
return SARA_R5_ERROR_OUT_OF_MEMORY;
1629-
}
1621+
command = sara_r5_calloc_char(strlen(SARA_R5_EXT_SIGNAL_QUALITY) + 1);
1622+
if (command == nullptr)
1623+
{
1624+
return SARA_R5_ERROR_OUT_OF_MEMORY;
1625+
}
16301626

1631-
sprintf(command, "%s", SARA_R5_EXT_SIGNAL_QUALITY);
1627+
sprintf(command, "%s", SARA_R5_EXT_SIGNAL_QUALITY);
16321628

1633-
response = sara_r5_calloc_char(minimumResponseAllocation);
1634-
if (response == nullptr)
1635-
{
1636-
free(command);
1637-
return SARA_R5_ERROR_OUT_OF_MEMORY;
1638-
}
1629+
response = sara_r5_calloc_char(minimumResponseAllocation);
1630+
if (response == nullptr)
1631+
{
1632+
free(command);
1633+
return SARA_R5_ERROR_OUT_OF_MEMORY;
1634+
}
16391635

1640-
err = sendCommandWithResponse(command,
1641-
SARA_R5_RESPONSE_OK_OR_ERROR, response, 10000,
1642-
minimumResponseAllocation, AT_COMMAND);
1643-
if (err != SARA_R5_ERROR_SUCCESS)
1644-
{
1645-
free(command);
1646-
free(response);
1647-
return SARA_R5_ERROR_ERROR;
1648-
}
1636+
err = sendCommandWithResponse(command,
1637+
SARA_R5_RESPONSE_OK_OR_ERROR, response, 10000,
1638+
minimumResponseAllocation, AT_COMMAND);
1639+
if (err != SARA_R5_ERROR_SUCCESS)
1640+
{
1641+
free(command);
1642+
free(response);
1643+
return SARA_R5_ERROR_ERROR;
1644+
}
16491645

1650-
int scanned = 0;
1651-
char *searchPtr = strstr(response, "+CESQ: ");
1652-
if (searchPtr != nullptr) {
1653-
scanned = sscanf(searchPtr, "+CESQ: %u,%u,%u,%u,%u,%u", &signal_quality.rxlev, &signal_quality.ber,
1654-
&signal_quality.rscp, &signal_quality.enc0, &signal_quality.rsrq, &signal_quality.rsrp);
1655-
}
1646+
int scanned = 0;
1647+
char *searchPtr = strstr(response, "+CESQ: ");
1648+
if (searchPtr != nullptr)
1649+
{
1650+
while (*searchPtr == ' ') searchPtr++; // skip spaces
1651+
scanned = sscanf(searchPtr, "%u,%u,%u,%u,%u,%u", &signal_quality.rxlev, &signal_quality.ber,
1652+
&signal_quality.rscp, &signal_quality.enc0, &signal_quality.rsrq, &signal_quality.rsrp);
1653+
}
16561654

1657-
err = SARA_R5_ERROR_UNEXPECTED_RESPONSE;
1658-
if (scanned == 6)
1659-
{
1660-
err = SARA_R5_ERROR_SUCCESS;
1661-
}
1655+
err = SARA_R5_ERROR_UNEXPECTED_RESPONSE;
1656+
if (scanned == 6)
1657+
{
1658+
err = SARA_R5_ERROR_SUCCESS;
1659+
}
16621660

1663-
free(command);
1664-
free(response);
1665-
return err;
1661+
free(command);
1662+
free(response);
1663+
return err;
16661664
}
16671665

16681666
SARA_R5_registration_status_t SARA_R5::registration(bool eps)
@@ -5587,7 +5585,7 @@ SARA_R5_error_t SARA_R5::getFileBlock(const String& filename, char* buffer, size
55875585
sprintf(cmd, "at+urdblock=\"%s\",%zu,%zu\r\n", filename.c_str(), offset, requested_length);
55885586
if (_printDebug == true)
55895587
{
5590-
_debugPort->printf(F("getFileBlock: sending command: %s\r\n"), cmd);
5588+
_debugPort->printf("getFileBlock: sending command: %s\r\n", cmd);
55915589
}
55925590
sendCommand(cmd, false);
55935591

@@ -5618,7 +5616,7 @@ SARA_R5_error_t SARA_R5::getFileBlock(const String& filename, char* buffer, size
56185616
cmd[bytes_read] = 0;
56195617
if (_printDebug == true)
56205618
{
5621-
_debugPort->printf(F("getFileBlock: header: [%s]\r\n"), cmd);
5619+
_debugPort->printf("getFileBlock: header: [%s]\r\n", cmd);
56225620
}
56235621
cmd[bytes_read - 2] = 0;
56245622

@@ -5628,7 +5626,7 @@ SARA_R5_error_t SARA_R5::getFileBlock(const String& filename, char* buffer, size
56285626
free(cmd);
56295627
if (_printDebug == true)
56305628
{
5631-
_debugPort->printf(F("getFileBlock: reading %zu bytes\r\n"), data_length);
5629+
_debugPort->printf("getFileBlock: reading %zu bytes\r\n", data_length);
56325630
}
56335631

56345632
bytes_read = 0;
@@ -5643,7 +5641,7 @@ SARA_R5_error_t SARA_R5::getFileBlock(const String& filename, char* buffer, size
56435641

56445642
if (_printDebug == true)
56455643
{
5646-
_debugPort->printf(F("getFileBlock: read %zu bytes\r\n"), bytes_read);
5644+
_debugPort->printf("getFileBlock: read %zu bytes\r\n", bytes_read);
56475645
}
56485646

56495647
return SARA_R5_ERROR_SUCCESS;
@@ -6717,11 +6715,6 @@ void SARA_R5::pruneBacklog()
67176715
// _debugPort->println(F("pruneBacklog: backlog is now empty"));
67186716
// }
67196717
// }
6720-
6721-
// This is a bug. event could be nullptr, and even if it is not it is pointing into
6722-
// _saraResponseBacklog meaning it is calling free on a random pointer whose memory
6723-
// may be referenced later.
6724-
//free(event);
67256718
}
67266719

67276720
// GPS Helper Functions:

src/SparkFun_u-blox_SARA-R5_Arduino_Library.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ typedef enum
535535
SARA_R5_FTP_COMMAND_RMDIR,
536536
SARA_R5_FTP_COMMAND_DIR_INFO = 13,
537537
SARA_R5_FTP_COMMAND_LS,
538-
SARA_R5_FTP_COMMAND_GET_FOTA_FILE
538+
SARA_R5_FTP_COMMAND_GET_FOTA_FILE = 100
539539
} SARA_R5_ftp_command_opcode_t;
540540

541541
typedef enum
@@ -691,8 +691,8 @@ class SARA_R5 : public Print
691691
void setPSDActionCallback(void (*psdActionRequestCallback)(int result, IPAddress ip));
692692
void setPingCallback(void (*pingRequestCallback)(int retry, int p_size, String remote_hostname, IPAddress ip, int ttl, long rtt));
693693
void setHTTPCommandCallback(void (*httpCommandRequestCallback)(int profile, int command, int result));
694-
void setMQTTCommandCallback(void (*mqttCommandRequestCallback)(SARA_R5_mqtt_command_opcode_t command, int result));
695-
void setFTPCommandCallback(void (*ftpCommandRequestCallback)(SARA_R5_ftp_command_opcode_t command, int result));
694+
void setMQTTCommandCallback(void (*mqttCommandRequestCallback)(int command, int result));
695+
void setFTPCommandCallback(void (*ftpCommandRequestCallback)(int command, int result));
696696

697697
SARA_R5_error_t setRegistrationCallback(void (*registrationCallback)(SARA_R5_registration_status_t status,
698698
unsigned int lac, unsigned int ci, int Act));
@@ -1063,8 +1063,8 @@ class SARA_R5 : public Print
10631063
void (*_psdActionRequestCallback)(int, IPAddress);
10641064
void (*_pingRequestCallback)(int, int, String, IPAddress, int, long);
10651065
void (*_httpCommandRequestCallback)(int, int, int);
1066-
void (*_mqttCommandRequestCallback)(SARA_R5_mqtt_command_opcode_t, int);
1067-
void (*_ftpCommandRequestCallback)(SARA_R5_ftp_command_opcode_t, int);
1066+
void (*_mqttCommandRequestCallback)(int, int);
1067+
void (*_ftpCommandRequestCallback)(int, int);
10681068
void (*_registrationCallback)(SARA_R5_registration_status_t status, unsigned int lac, unsigned int ci, int Act);
10691069
void (*_epsRegistrationCallback)(SARA_R5_registration_status_t status, unsigned int tac, unsigned int ci, int Act);
10701070

0 commit comments

Comments
 (0)