From d42f0a1900ee4df12d24f044f5265c926a5d34d3 Mon Sep 17 00:00:00 2001 From: PaulZC Date: Mon, 27 Dec 2021 12:51:25 +0000 Subject: [PATCH 01/11] Add support for socket Direct Link mode --- keywords.txt | 5 + library.properties | 2 +- ...parkFun_u-blox_SARA-R5_Arduino_Library.cpp | 101 ++++++++++++++++++ src/SparkFun_u-blox_SARA-R5_Arduino_Library.h | 12 ++- 4 files changed, 117 insertions(+), 3 deletions(-) diff --git a/keywords.txt b/keywords.txt index ef87c40..208f7f4 100644 --- a/keywords.txt +++ b/keywords.txt @@ -105,6 +105,11 @@ socketWriteUDP KEYWORD2 socketRead KEYWORD2 socketReadUDP KEYWORD2 socketListen KEYWORD2 +socketDirectLinkMode KEYWORD2 +socketDirectLinkTimeTrigger KEYWORD2 +socketDirectLinkDataLengthTrigger KEYWORD2 +socketDirectLinkCharacterTrigger KEYWORD2 +socketDirectLinkCongestionTimer KEYWORD2 socketGetLastError KEYWORD2 lastRemoteIP KEYWORD2 ping KEYWORD2 diff --git a/library.properties b/library.properties index 1c15352..41bbd7d 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SparkFun u-blox SARA-R5 Arduino Library -version=1.0.1 +version=1.0.2 author=SparkFun Electronics maintainer=SparkFun Electronics sentence=Library for the u-blox SARA-R5 LTE-M / NB-IoT modules with secure cloud diff --git a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp index 1cd973a..13d8c3d 100644 --- a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp +++ b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp @@ -2290,6 +2290,107 @@ SARA_R5_error_t SARA_R5::socketListen(int socket, unsigned int port) return err; } +SARA_R5_error_t SARA_R5::socketDirectLinkMode(int socket) +{ + SARA_R5_error_t err; + char *command; + + command = sara_r5_calloc_char(strlen(SARA_R5_SOCKET_DIRECT_LINK) + 8); + if (command == NULL) + return SARA_R5_ERROR_OUT_OF_MEMORY; + sprintf(command, "%s=%d", SARA_R5_SOCKET_DIRECT_LINK, socket); + + err = sendCommandWithResponse(command, SARA_R5_RESPONSE_CONNECT, NULL, + SARA_R5_STANDARD_RESPONSE_TIMEOUT); + + free(command); + return err; +} + +SARA_R5_error_t SARA_R5::socketDirectLinkTimeTrigger(int socket, int timerTrigger) +{ + // valid range is 0 (trigger disabled), 100-120000 + if (!((timerTrigger == 0) || ((timerTrigger >= 100) && (timerTrigger <= 120000)))) + return SARA_R5_ERROR_ERROR; + + SARA_R5_error_t err; + char *command; + + command = sara_r5_calloc_char(strlen(SARA_R5_UD_CONFIGURATION) + 16); + if (command == NULL) + return SARA_R5_ERROR_OUT_OF_MEMORY; + sprintf(command, "%s=5,%d,%d", SARA_R5_UD_CONFIGURATION, socket, timerTrigger); + + err = sendCommandWithResponse(command, SARA_R5_RESPONSE_OK, NULL, + SARA_R5_STANDARD_RESPONSE_TIMEOUT); + + free(command); + return err; +} + +SARA_R5_error_t SARA_R5::socketDirectLinkDataLengthTrigger(int socket, int dataLengthTrigger) +{ + // valid range is 0, 3-1472 for UDP + if (!((dataLengthTrigger == 0) || ((dataLengthTrigger >= 3) && (dataLengthTrigger <= 1472)))) + return SARA_R5_ERROR_ERROR; + + SARA_R5_error_t err; + char *command; + + command = sara_r5_calloc_char(strlen(SARA_R5_UD_CONFIGURATION) + 16); + if (command == NULL) + return SARA_R5_ERROR_OUT_OF_MEMORY; + sprintf(command, "%s=6,%d,%d", SARA_R5_UD_CONFIGURATION, socket, dataLengthTrigger); + + err = sendCommandWithResponse(command, SARA_R5_RESPONSE_OK, NULL, + SARA_R5_STANDARD_RESPONSE_TIMEOUT); + + free(command); + return err; +} + +SARA_R5_error_t SARA_R5::socketDirectLinkCharacterTrigger(int socket, int characterTrigger) +{ + // The allowed range is -1, 0-255, the factory-programmed value is -1; -1 means trigger disabled. + if (!((characterTrigger >= -1) && (characterTrigger <= 255))) + return SARA_R5_ERROR_ERROR; + + SARA_R5_error_t err; + char *command; + + command = sara_r5_calloc_char(strlen(SARA_R5_UD_CONFIGURATION) + 16); + if (command == NULL) + return SARA_R5_ERROR_OUT_OF_MEMORY; + sprintf(command, "%s=7,%d,%d", SARA_R5_UD_CONFIGURATION, socket, characterTrigger); + + err = sendCommandWithResponse(command, SARA_R5_RESPONSE_OK, NULL, + SARA_R5_STANDARD_RESPONSE_TIMEOUT); + + free(command); + return err; +} + +SARA_R5_error_t SARA_R5::socketDirectLinkCongestionTimer(int socket, int congestionTimer) +{ + // valid range is 0, 1000-72000 + if (!((congestionTimer == 0) || ((congestionTimer >= 1000) && (congestionTimer <= 72000)))) + return SARA_R5_ERROR_ERROR; + + SARA_R5_error_t err; + char *command; + + command = sara_r5_calloc_char(strlen(SARA_R5_UD_CONFIGURATION) + 16); + if (command == NULL) + return SARA_R5_ERROR_OUT_OF_MEMORY; + sprintf(command, "%s=8,%d,%d", SARA_R5_UD_CONFIGURATION, socket, congestionTimer); + + err = sendCommandWithResponse(command, SARA_R5_RESPONSE_OK, NULL, + SARA_R5_STANDARD_RESPONSE_TIMEOUT); + + free(command); + return err; +} + //Issues command to get last socket error, then prints to serial. Also updates rx/backlog buffers. int SARA_R5::socketGetLastError() { diff --git a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h index 9176cb6..05d1073 100644 --- a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h +++ b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h @@ -118,6 +118,8 @@ const char SARA_R5_READ_SOCKET[] = "+USORD"; // Read from a socket const char SARA_R5_READ_UDP_SOCKET[] = "+USORF"; // Read UDP data from a socket const char SARA_R5_LISTEN_SOCKET[] = "+USOLI"; // Listen for connection on socket const char SARA_R5_GET_ERROR[] = "+USOER"; // Get last socket error. +const char SARA_R5_SOCKET_DIRECT_LINK[] = "+USODL"; // Set socket in Direct Link mode +const char SARA_R5_UD_CONFIGURATION[] = "+UDCONF"; // User Datagram Configuration // ### Ping const char SARA_R5_PING_COMMAND[] = "+UPING"; // Ping // ### HTTP @@ -139,6 +141,7 @@ const char SARA_R5_FILE_SYSTEM_READ_FILE[] = "+URDFILE"; // Read a file // ### Response const char SARA_R5_RESPONSE_OK[] = "OK\r\n"; const char SARA_R5_RESPONSE_ERROR[] = "ERROR\r\n"; +const char SARA_R5_RESPONSE_CONNECT[] = "CONNECT\r\n"; // CTRL+Z and ESC ASCII codes for SMS message sends const char ASCII_CTRL_Z = 0x1A; @@ -208,7 +211,7 @@ typedef enum SARA_R5_ERROR_UNEXPECTED_RESPONSE, // 4 SARA_R5_ERROR_NO_RESPONSE, // 5 SARA_R5_ERROR_DEREGISTERED, // 6 - SARA_R5_ERROR_ERROR // 7 + SARA_R5_ERROR_ERROR // 7 } SARA_R5_error_t; #define SARA_R5_SUCCESS SARA_R5_ERROR_SUCCESS @@ -597,10 +600,15 @@ class SARA_R5 : public Print SARA_R5_error_t socketWrite(int socket, const char *str); SARA_R5_error_t socketWrite(int socket, String str); SARA_R5_error_t socketWriteUDP(int socket, const char *address, int port, const char *str, int len = -1); - SARA_R5_error_t socketWriteUDP(int socket, String address, int port, String str, int len = -1); + SARA_R5_error_t socketWriteUDP(int socket, String address, int port, String str, int len = -1); SARA_R5_error_t socketRead(int socket, int length, char *readDest); SARA_R5_error_t socketReadUDP(int socket, int length, char *readDest); SARA_R5_error_t socketListen(int socket, unsigned int port); + SARA_R5_error_t socketDirectLinkMode(int socket); + SARA_R5_error_t socketDirectLinkTimeTrigger(int socket, int timerTrigger); + SARA_R5_error_t socketDirectLinkDataLengthTrigger(int socket, int dataLengthTrigger); + SARA_R5_error_t socketDirectLinkCharacterTrigger(int socket, int characterTrigger); + SARA_R5_error_t socketDirectLinkCongestionTimer(int socket, int congestionTimer); int socketGetLastError(); IPAddress lastRemoteIP(void); From 01a03b21566c5bd03a43b162af9d473c3076434b Mon Sep 17 00:00:00 2001 From: PaulZC Date: Tue, 28 Dec 2021 09:23:19 +0000 Subject: [PATCH 02/11] Correct compiler warnings --- ...parkFun_u-blox_SARA-R5_Arduino_Library.cpp | 129 +++++++++++------- src/SparkFun_u-blox_SARA-R5_Arduino_Library.h | 8 +- 2 files changed, 81 insertions(+), 56 deletions(-) diff --git a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp index 13d8c3d..cfdfb69 100644 --- a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp +++ b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp @@ -158,7 +158,7 @@ boolean SARA_R5::processReadEvent(char* event) unsigned int port, listenPort; IPAddress remoteIP, localIP; int ret = sscanf(event, - "+UUSOLI: %d,\"%d.%d.%d.%d\",%u,%d,\"%d.%d.%d.%d\",%u", + "+UUSOLI: %d,\"%hhu.%hhu.%hhu.%hhu\",%u,%d,\"%hhu.%hhu.%hhu.%hhu\",%u", &socket, &remoteIP[0], &remoteIP[1], &remoteIP[2], &remoteIP[3], &port, &listenSocket, @@ -222,7 +222,7 @@ boolean SARA_R5::poll(void) IPAddress remoteIP, localIP; if (sscanf(saraRXBuffer, - "+UUSOLI: %d,\"%d.%d.%d.%d\",%u,%d,\"%d.%d.%d.%d\",%u", + "+UUSOLI: %d,\"%hhu.%hhu.%hhu.%hhu\",%u,%d,\"%hhu.%hhu.%hhu.%hhu\",%u", &socket, &remoteIP[0], &remoteIP[1], &remoteIP[2], &remoteIP[3], &port, &listenSocket, @@ -265,7 +265,7 @@ boolean SARA_R5::poll(void) // Found a Location string! // This assumes the ULOC response type is "1". TO DO: check that is true... scanNum = sscanf(saraRXBuffer, - "+UULOC: %hhu/%hhu/%u,%hhu:%hhu:%hhu.%u,%u.%[^,],%u.%[^,],%u,%lu,%u,%u,*%s", + "+UULOC: %hhu/%hhu/%u,%hhu:%hhu:%hhu.%u,%u.%[^,],%u.%[^,],%u,%lu,%u,%u,%*s", &clck.date.day, &clck.date.month, &clck.date.year, &clck.time.hour, &clck.time.minute, &clck.time.second, &clck.time.ms, &latH, latL, &lonH, lonL, &altU, &uncertainty, @@ -296,7 +296,7 @@ boolean SARA_R5::poll(void) if (strstr(saraRXBuffer, "+UUSIMSTAT")) { - scanNum = sscanf(saraRXBuffer, "+UUSIMSTAT:%d", &state); + scanNum = sscanf(saraRXBuffer, "+UUSIMSTAT:%hhu", (uint8_t*)&state); if (scanNum < 1) return false; // Break out if we didn't find enough @@ -310,12 +310,12 @@ boolean SARA_R5::poll(void) } { int result; - IPAddress remoteIP = (0,0,0,0); + IPAddress remoteIP = {0,0,0,0}; int scanNum; if (strstr(saraRXBuffer, "+UUPSDA")) { - scanNum = sscanf(saraRXBuffer, "+UUPSDA: %d,\"%d.%d.%d.%d\"", + scanNum = sscanf(saraRXBuffer, "+UUPSDA: %d,\"%hhu.%hhu.%hhu.%hhu\"", &result, &remoteIP[0], &remoteIP[1], &remoteIP[2], &remoteIP[3]); if (scanNum < 1) return false; // Break out if we didn't find enough @@ -333,7 +333,7 @@ boolean SARA_R5::poll(void) int p_size = 0; int ttl = 0; String remote_host = ""; - IPAddress remoteIP = (0,0,0,0); + IPAddress remoteIP = {0,0,0,0}; long rtt = 0; int scanNum; char *searchPtr = saraRXBuffer; @@ -365,7 +365,7 @@ boolean SARA_R5::poll(void) if (*searchPtr == '\0') return false; // Break out if we didn't find enough - scanNum = sscanf(searchPtr, "\",\"%d.%d.%d.%d\",%d,%d", + scanNum = sscanf(searchPtr, "\",\"%hhu.%hhu.%hhu.%hhu\",%d,%ld", &remoteIP[0], &remoteIP[1], &remoteIP[2], &remoteIP[3], &ttl, &rtt); if (scanNum < 6) @@ -484,6 +484,9 @@ size_t SARA_R5::write(const char *str) size_t SARA_R5::write(const char *buffer, size_t size) { + //size is unused at the moment but could be used if this function is ever updated to use write instead of print. + size_t ignoreMe = size; ignoreMe -= 0; // Avoid the pesky compiler warning. + if (_hardSerial != NULL) { return _hardSerial->print(buffer); @@ -500,7 +503,6 @@ size_t SARA_R5::write(const char *buffer, size_t size) SARA_R5_error_t SARA_R5::at(void) { SARA_R5_error_t err; - char *command; err = sendCommandWithResponse(NULL, SARA_R5_RESPONSE_OK, NULL, SARA_R5_STANDARD_RESPONSE_TIMEOUT); @@ -804,8 +806,6 @@ SARA_R5_error_t SARA_R5::clock(uint8_t *y, uint8_t *mo, uint8_t *d, SARA_R5_error_t err; char *command; char *response; - char *clockBegin; - char *clockEnd; int iy, imo, id, ih, imin, is, itz; @@ -851,7 +851,7 @@ SARA_R5_error_t SARA_R5::setUtimeMode(SARA_R5_utime_mode_t mode, SARA_R5_utime_s SARA_R5_error_t err; char *command; - command = sara_r5_calloc_char(strlen(SARA_R5_GNSS_REQUEST_TIME) + 5); + command = sara_r5_calloc_char(strlen(SARA_R5_GNSS_REQUEST_TIME) + 16); if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; if (mode == SARA_R5_UTIME_MODE_STOP) // stop UTIME does not require a sensor @@ -892,7 +892,7 @@ SARA_R5_error_t SARA_R5::getUtimeMode(SARA_R5_utime_mode_t *mode, SARA_R5_utime_ // Response format: \r\n+UTIME: [,]\r\n\r\nOK\r\n if (err == SARA_R5_ERROR_SUCCESS) { - int scanned = sscanf(response, "\r\n+UTIME: %d,%d\r\n", &m, &s); + int scanned = sscanf(response, "\r\n+UTIME: %hhu,%hhu\r\n", (uint8_t*)&m, (uint8_t*)&s); if (scanned == 2) { *mode = m; @@ -916,7 +916,7 @@ SARA_R5_error_t SARA_R5::setUtimeIndication(SARA_R5_utime_urc_configuration_t co SARA_R5_error_t err; char *command; - command = sara_r5_calloc_char(strlen(SARA_R5_GNSS_TIME_INDICATION) + 3); + command = sara_r5_calloc_char(strlen(SARA_R5_GNSS_TIME_INDICATION) + 16); if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; sprintf(command, "%s=%d", SARA_R5_GNSS_TIME_INDICATION, config); @@ -953,7 +953,7 @@ SARA_R5_error_t SARA_R5::getUtimeIndication(SARA_R5_utime_urc_configuration_t *c // Response format: \r\n+UTIMEIND: \r\n\r\nOK\r\n if (err == SARA_R5_ERROR_SUCCESS) { - int scanned = sscanf(response, "\r\n+UTIMEIND: %d\r\n", &c); + int scanned = sscanf(response, "\r\n+UTIMEIND: %hhu\r\n", (uint8_t*)&c); if (scanned == 1) { *config = c; @@ -974,7 +974,11 @@ SARA_R5_error_t SARA_R5::setUtimeConfiguration(int32_t offsetNanoseconds, int32_ command = sara_r5_calloc_char(strlen(SARA_R5_GNSS_TIME_CONFIGURATION) + 48); if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; +#ifdef ARDUINO_ARCH_ESP32 // ESP32 based boards sprintf(command, "%s=%d,%d", SARA_R5_GNSS_TIME_CONFIGURATION, offsetNanoseconds, offsetSeconds); +#else + sprintf(command, "%s=%ld,%ld", SARA_R5_GNSS_TIME_CONFIGURATION, offsetNanoseconds, offsetSeconds); +#endif err = sendCommandWithResponse(command, SARA_R5_RESPONSE_OK, NULL, SARA_R5_STANDARD_RESPONSE_TIMEOUT); @@ -1009,7 +1013,11 @@ SARA_R5_error_t SARA_R5::getUtimeConfiguration(int32_t *offsetNanoseconds, int32 // Response format: \r\n+UTIMECFG: ,\r\n\r\nOK\r\n if (err == SARA_R5_ERROR_SUCCESS) { +#ifdef ARDUINO_ARCH_ESP32 // ESP32 based boards int scanned = sscanf(response, "\r\n+UTIMECFG: %d,%d\r\n", &ons, &os); +#else + int scanned = sscanf(response, "\r\n+UTIMECFG: %ld,%ld\r\n", &ons, &os); +#endif if (scanned == 2) { *offsetNanoseconds = ons; @@ -1226,7 +1234,7 @@ SARA_R5_error_t SARA_R5::getAPN(int cid, String *apn, IPAddress *ip) char *command; char *response; int ipOctets[4]; - int rcid; + int rcid = -1; if (cid > SARA_R5_NUM_PDP_CONTEXT_IDENTIFIERS) return SARA_R5_ERROR_ERROR; @@ -1306,7 +1314,7 @@ SARA_R5_error_t SARA_R5::getAPN(int cid, String *apn, IPAddress *ip) else // We don't have a match so let's clear the APN and IP address { *apn = ""; - *ip = (0,0,0,0); + *ip = {0,0,0,0}; } } if ((rcid == cid) || (searchPtr == NULL) || (*searchPtr == '\0')) // Stop searching @@ -1460,7 +1468,6 @@ uint8_t SARA_R5::getOperators(struct operator_stats *opRet, int maxOps) char *opBegin; char *opEnd; int op = 0; - int sscanRead = 0; int stat; char longOp[26]; char shortOp[11]; @@ -1642,7 +1649,6 @@ SARA_R5_error_t SARA_R5::sendSMS(String number, String message) char *command; char *messageCStr; char *numberCStr; - int messageIndex; SARA_R5_error_t err; numberCStr = sara_r5_calloc_char(number.length() + 2); @@ -1882,7 +1888,7 @@ SARA_R5_error_t SARA_R5::setFlowControl(SARA_R5_flow_control_t value) SARA_R5_error_t err; char *command; - command = sara_r5_calloc_char(strlen(SARA_R5_FLOW_CONTROL) + 3); + command = sara_r5_calloc_char(strlen(SARA_R5_FLOW_CONTROL) + 16); if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; sprintf(command, "%s%d", SARA_R5_FLOW_CONTROL, value); @@ -1903,7 +1909,7 @@ SARA_R5_error_t SARA_R5::setGpioMode(SARA_R5_gpio_t gpio, // Example command: AT+UGPIOC=16,2 // Example command: AT+UGPIOC=23,0,1 - command = sara_r5_calloc_char(strlen(SARA_R5_COMMAND_GPIO) + 10); + command = sara_r5_calloc_char(strlen(SARA_R5_COMMAND_GPIO) + 16); if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; if (mode == GPIO_OUTPUT) @@ -2024,7 +2030,7 @@ int SARA_R5::socketOpen(SARA_R5_socket_protocol_t protocol, unsigned int localPo return sockId; } -SARA_R5_error_t SARA_R5::socketClose(int socket, int timeout) +SARA_R5_error_t SARA_R5::socketClose(int socket, unsigned long timeout) { SARA_R5_error_t err; char *command; @@ -2080,7 +2086,7 @@ SARA_R5_error_t SARA_R5::socketWrite(int socket, const char *str) SARA_R5_error_t err; unsigned long writeDelay; - command = sara_r5_calloc_char(strlen(SARA_R5_WRITE_SOCKET) + 8); + command = sara_r5_calloc_char(strlen(SARA_R5_WRITE_SOCKET) + 16); if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; response = sara_r5_calloc_char(128); @@ -2097,7 +2103,8 @@ SARA_R5_error_t SARA_R5::socketWrite(int socket, const char *str) if (err == SARA_R5_ERROR_SUCCESS) { writeDelay = millis(); - while (millis() - writeDelay < 50); //uBlox specification says to wait 50ms after receiving "@" to write data. + while (millis() < (writeDelay + 50)) + ; //uBlox specification says to wait 50ms after receiving "@" to write data. hwPrint(str); err = waitForResponse(SARA_R5_RESPONSE_OK, SARA_R5_RESPONSE_ERROR, SARA_R5_SOCKET_WRITE_TIMEOUT); @@ -2107,10 +2114,10 @@ SARA_R5_error_t SARA_R5::socketWrite(int socket, const char *str) if (_printDebug == true) { _debugPort->print("WriteCmd Err Response: "); - _debugPort->print(err); - _debugPort->print(" => {"); - _debugPort->print(response); - _debugPort->println("}"); + _debugPort->print(err); + _debugPort->print(" => {"); + _debugPort->print(response); + _debugPort->println("}"); } } @@ -2206,7 +2213,7 @@ SARA_R5_error_t SARA_R5::socketRead(int socket, int length, char *readDest) return SARA_R5_ERROR_UNEXPECTED_RESPONSE; } - while ((readIndex < length) && (readIndex < strlen(strBegin))) + while ((readIndex < length) && (readIndex < (int)strlen(strBegin))) { readDest[readIndex] = strBegin[1 + readIndex]; readIndex += 1; @@ -2260,7 +2267,7 @@ SARA_R5_error_t SARA_R5::socketReadUDP(int socket, int length, char *readDest) return SARA_R5_ERROR_UNEXPECTED_RESPONSE; } - while ((readIndex < length) && (readIndex < strlen(strBegin))) + while ((readIndex < length) && (readIndex < (int)strlen(strBegin))) { readDest[readIndex] = strBegin[1 + readIndex]; readIndex += 1; @@ -2307,7 +2314,7 @@ SARA_R5_error_t SARA_R5::socketDirectLinkMode(int socket) return err; } -SARA_R5_error_t SARA_R5::socketDirectLinkTimeTrigger(int socket, int timerTrigger) +SARA_R5_error_t SARA_R5::socketDirectLinkTimeTrigger(int socket, unsigned long timerTrigger) { // valid range is 0 (trigger disabled), 100-120000 if (!((timerTrigger == 0) || ((timerTrigger >= 100) && (timerTrigger <= 120000)))) @@ -2319,7 +2326,7 @@ SARA_R5_error_t SARA_R5::socketDirectLinkTimeTrigger(int socket, int timerTrigge command = sara_r5_calloc_char(strlen(SARA_R5_UD_CONFIGURATION) + 16); if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; - sprintf(command, "%s=5,%d,%d", SARA_R5_UD_CONFIGURATION, socket, timerTrigger); + sprintf(command, "%s=5,%d,%ld", SARA_R5_UD_CONFIGURATION, socket, timerTrigger); err = sendCommandWithResponse(command, SARA_R5_RESPONSE_OK, NULL, SARA_R5_STANDARD_RESPONSE_TIMEOUT); @@ -2370,7 +2377,7 @@ SARA_R5_error_t SARA_R5::socketDirectLinkCharacterTrigger(int socket, int charac return err; } -SARA_R5_error_t SARA_R5::socketDirectLinkCongestionTimer(int socket, int congestionTimer) +SARA_R5_error_t SARA_R5::socketDirectLinkCongestionTimer(int socket, unsigned long congestionTimer) { // valid range is 0, 1000-72000 if (!((congestionTimer == 0) || ((congestionTimer >= 1000) && (congestionTimer <= 72000)))) @@ -2382,7 +2389,7 @@ SARA_R5_error_t SARA_R5::socketDirectLinkCongestionTimer(int socket, int congest command = sara_r5_calloc_char(strlen(SARA_R5_UD_CONFIGURATION) + 16); if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; - sprintf(command, "%s=8,%d,%d", SARA_R5_UD_CONFIGURATION, socket, congestionTimer); + sprintf(command, "%s=8,%d,%ld", SARA_R5_UD_CONFIGURATION, socket, congestionTimer); err = sendCommandWithResponse(command, SARA_R5_RESPONSE_OK, NULL, SARA_R5_STANDARD_RESPONSE_TIMEOUT); @@ -2439,7 +2446,7 @@ SARA_R5_error_t SARA_R5::resetHTTPprofile(int profile) if (profile >= SARA_R5_NUM_HTTP_PROFILES) return SARA_R5_ERROR_ERROR; - command = sara_r5_calloc_char(strlen(SARA_R5_HTTP_PROFILE) + 3); + command = sara_r5_calloc_char(strlen(SARA_R5_HTTP_PROFILE) + 16); if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; sprintf(command, "%s=%d", SARA_R5_HTTP_PROFILE, profile); @@ -2459,7 +2466,7 @@ SARA_R5_error_t SARA_R5::setHTTPserverIPaddress(int profile, IPAddress address) if (profile >= SARA_R5_NUM_HTTP_PROFILES) return SARA_R5_ERROR_ERROR; - command = sara_r5_calloc_char(strlen(SARA_R5_HTTP_PROFILE) + 32); + command = sara_r5_calloc_char(strlen(SARA_R5_HTTP_PROFILE) + 64); if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; sprintf(command, "%s=%d,%d,\"%d.%d.%d.%d\"", SARA_R5_HTTP_PROFILE, profile, SARA_R5_HTTP_OP_CODE_SERVER_IP, @@ -2543,7 +2550,7 @@ SARA_R5_error_t SARA_R5::setHTTPauthentication(int profile, boolean authenticate if (profile >= SARA_R5_NUM_HTTP_PROFILES) return SARA_R5_ERROR_ERROR; - command = sara_r5_calloc_char(strlen(SARA_R5_HTTP_PROFILE) + 12); + command = sara_r5_calloc_char(strlen(SARA_R5_HTTP_PROFILE) + 32); if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; sprintf(command, "%s=%d,%d,%d", SARA_R5_HTTP_PROFILE, profile, SARA_R5_HTTP_OP_CODE_AUTHENTICATION, @@ -2564,7 +2571,7 @@ SARA_R5_error_t SARA_R5::setHTTPserverPort(int profile, int port) if (profile >= SARA_R5_NUM_HTTP_PROFILES) return SARA_R5_ERROR_ERROR; - command = sara_r5_calloc_char(strlen(SARA_R5_HTTP_PROFILE) + 12); + command = sara_r5_calloc_char(strlen(SARA_R5_HTTP_PROFILE) + 32); if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; sprintf(command, "%s=%d,%d,%d", SARA_R5_HTTP_PROFILE, profile, SARA_R5_HTTP_OP_CODE_SERVER_PORT, @@ -2585,7 +2592,7 @@ SARA_R5_error_t SARA_R5::setHTTPsecure(int profile, boolean secure) if (profile >= SARA_R5_NUM_HTTP_PROFILES) return SARA_R5_ERROR_ERROR; - command = sara_r5_calloc_char(strlen(SARA_R5_HTTP_PROFILE) + 12); + command = sara_r5_calloc_char(strlen(SARA_R5_HTTP_PROFILE) + 32); if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; sprintf(command, "%s=%d,%d,%d", SARA_R5_HTTP_PROFILE, profile, SARA_R5_HTTP_OP_CODE_SECURE, @@ -2608,7 +2615,7 @@ SARA_R5_error_t SARA_R5::ping(String remote_host, int retry, int p_size, remote_host.length()); if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; - sprintf(command, "%s=\"%s\",%d,%d,%d,%d", SARA_R5_PING_COMMAND, + sprintf(command, "%s=\"%s\",%d,%d,%ld,%d", SARA_R5_PING_COMMAND, remote_host.c_str(), retry, p_size, timeout, ttl); err = sendCommandWithResponse(command, SARA_R5_RESPONSE_OK, NULL, @@ -2757,7 +2764,7 @@ SARA_R5_error_t SARA_R5::setPDPconfiguration(int profile, SARA_R5_pdp_configurat if (profile >= SARA_R5_NUM_PSD_PROFILES) return SARA_R5_ERROR_ERROR; - command = sara_r5_calloc_char(strlen(SARA_R5_MESSAGE_PDP_CONFIG) + 24); + command = sara_r5_calloc_char(strlen(SARA_R5_MESSAGE_PDP_CONFIG) + 64); if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; sprintf(command, "%s=%d,%d,\"%d.%d.%d.%d\"", SARA_R5_MESSAGE_PDP_CONFIG, profile, parameter, @@ -2778,7 +2785,7 @@ SARA_R5_error_t SARA_R5::performPDPaction(int profile, SARA_R5_pdp_actions_t act if (profile >= SARA_R5_NUM_PSD_PROFILES) return SARA_R5_ERROR_ERROR; - command = sara_r5_calloc_char(strlen(SARA_R5_MESSAGE_PDP_ACTION) + 12); + command = sara_r5_calloc_char(strlen(SARA_R5_MESSAGE_PDP_ACTION) + 32); if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; sprintf(command, "%s=%d,%d", SARA_R5_MESSAGE_PDP_ACTION, profile, action); @@ -2798,7 +2805,7 @@ SARA_R5_error_t SARA_R5::activatePDPcontext(boolean status, int cid) if (cid >= SARA_R5_NUM_PDP_CONTEXT_IDENTIFIERS) return SARA_R5_ERROR_ERROR; - command = sara_r5_calloc_char(strlen(SARA_R5_MESSAGE_PDP_CONTEXT_ACTIVATE) + 12); + command = sara_r5_calloc_char(strlen(SARA_R5_MESSAGE_PDP_CONTEXT_ACTIVATE) + 32); if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; if (cid == -1) @@ -2868,7 +2875,7 @@ SARA_R5_error_t SARA_R5::gpsPower(boolean enable, gnss_system_t gnss_sys, gnss_a } // GPS power management - command = sara_r5_calloc_char(strlen(SARA_R5_GNSS_POWER) + 10); // gnss_sys could be up to three digits + command = sara_r5_calloc_char(strlen(SARA_R5_GNSS_POWER) + 32); // gnss_sys could be up to three digits if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; if (enable) @@ -2888,6 +2895,9 @@ SARA_R5_error_t SARA_R5::gpsPower(boolean enable, gnss_system_t gnss_sys, gnss_a SARA_R5_error_t SARA_R5::gpsEnableClock(boolean enable) { + //enable is unused at the moment but could be used if this function is ever implemented. + boolean ignoreMe = enable; ignoreMe |= false; // Avoid the pesky compiler warning. + // AT+UGZDA=<0,1> SARA_R5_error_t err = SARA_R5_ERROR_SUCCESS; return err; @@ -2902,6 +2912,9 @@ SARA_R5_error_t SARA_R5::gpsGetClock(struct ClockData *clock) SARA_R5_error_t SARA_R5::gpsEnableFix(boolean enable) { + //enable is unused at the moment but could be used if this function is ever implemented. + boolean ignoreMe = enable; ignoreMe |= false; // Avoid the pesky compiler warning. + // AT+UGGGA=<0,1> SARA_R5_error_t err = SARA_R5_ERROR_SUCCESS; return err; @@ -2916,6 +2929,9 @@ SARA_R5_error_t SARA_R5::gpsGetFix(struct PositionData *pos) SARA_R5_error_t SARA_R5::gpsEnablePos(boolean enable) { + //enable is unused at the moment but could be used if this function is ever implemented. + boolean ignoreMe = enable; ignoreMe |= false; // Avoid the pesky compiler warning. + // AT+UGGLL=<0,1> SARA_R5_error_t err = SARA_R5_ERROR_SUCCESS; return err; @@ -2930,6 +2946,9 @@ SARA_R5_error_t SARA_R5::gpsGetPos(struct PositionData *pos) SARA_R5_error_t SARA_R5::gpsEnableSat(boolean enable) { + //enable is unused at the moment but could be used if this function is ever implemented. + boolean ignoreMe = enable; ignoreMe |= false; // Avoid the pesky compiler warning. + // AT+UGGSV=<0,1> SARA_R5_error_t err = SARA_R5_ERROR_SUCCESS; return err; @@ -3012,6 +3031,9 @@ SARA_R5_error_t SARA_R5::gpsGetRmc(struct PositionData *pos, struct SpeedData *s SARA_R5_error_t SARA_R5::gpsEnableSpeed(boolean enable) { + //enable is unused at the moment but could be used if this function is ever implemented. + boolean ignoreMe = enable; ignoreMe |= false; // Avoid the pesky compiler warning. + // AT+UGVTG=<0,1> SARA_R5_error_t err = SARA_R5_ERROR_SUCCESS; return err; @@ -3045,8 +3067,13 @@ SARA_R5_error_t SARA_R5::gpsRequest(unsigned int timeout, uint32_t accuracy, command = sara_r5_calloc_char(strlen(SARA_R5_GNSS_REQUEST_LOCATION) + 24); if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; +#ifdef ARDUINO_ARCH_ESP32 // ESP32 based boards sprintf(command, "%s=2,3,%d,%d,%d", SARA_R5_GNSS_REQUEST_LOCATION, detailed ? 1 : 0, timeout, accuracy); +#else + sprintf(command, "%s=2,3,%d,%d,%ld", SARA_R5_GNSS_REQUEST_LOCATION, + detailed ? 1 : 0, timeout, accuracy); +#endif err = sendCommandWithResponse(command, SARA_R5_RESPONSE_OK, NULL, SARA_R5_10_SEC_TIMEOUT); @@ -3232,7 +3259,7 @@ SARA_R5_error_t SARA_R5::functionality(SARA_R5_functionality_t function) SARA_R5_error_t err; char *command; - command = sara_r5_calloc_char(strlen(SARA_R5_COMMAND_FUNC) + 4); + command = sara_r5_calloc_char(strlen(SARA_R5_COMMAND_FUNC) + 16); if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; sprintf(command, "%s=%d", SARA_R5_COMMAND_FUNC, function); @@ -3297,7 +3324,7 @@ SARA_R5_error_t SARA_R5::getMNOprofile(mobile_network_operator_t *mno) return err; } - int ret = sscanf(response, "\r\n+UMNOPROF: %d,%d,%d,%d", &o, &d, &r, &u); + int ret = sscanf(response, "\r\n+UMNOPROF: %hhd,%hhd,%d,%d", (int8_t*)&o, (int8_t*)&d, &r, &u); if (ret >= 1) { if (_printDebug == true) @@ -3335,7 +3362,7 @@ SARA_R5_error_t SARA_R5::waitForResponse(const char *expectedResponse, const cha if (_printDebug == true) _debugPort->print((String)c); if (c == expectedResponse[responseIndex]) { - if (++responseIndex == strlen(expectedResponse)) + if (++responseIndex == (int)strlen(expectedResponse)) { found = true; } @@ -3346,7 +3373,7 @@ SARA_R5_error_t SARA_R5::waitForResponse(const char *expectedResponse, const cha } if (c == expectedError[errorIndex]) { - if (++errorIndex == strlen(expectedError)) + if (++errorIndex == (int)strlen(expectedError)) { found = true; } @@ -3406,7 +3433,7 @@ SARA_R5_error_t SARA_R5::sendCommandWithResponse( charsRead++; if (c == expectedResponse[index]) { - if (++index == strlen(expectedResponse)) + if (++index == (int)strlen(expectedResponse)) { found = true; } @@ -3547,7 +3574,6 @@ SARA_R5_error_t SARA_R5::parseSocketListenIndication(IPAddress localIP, IPAddres SARA_R5_error_t SARA_R5::parseSocketCloseIndication(String *closeIndication) { - SARA_R5_error_t err; int search; int socket; @@ -3654,7 +3680,7 @@ int SARA_R5::readAvailable(char *inString) char SARA_R5::readChar(void) { - char ret; + char ret = 0; if (_hardSerial != NULL) { @@ -3760,7 +3786,6 @@ char *SARA_R5::sara_r5_calloc_char(size_t num) void SARA_R5::pruneBacklog() { char* event; - int pruneLen = 0; char pruneBuffer[RXBuffSize]; memset(pruneBuffer, 0, RXBuffSize); diff --git a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h index 05d1073..3e7739f 100644 --- a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h +++ b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h @@ -446,7 +446,7 @@ class SARA_R5 : public Print // Loop polling and polling setup boolean bufferedPoll(void); - boolean processReadEvent(char* event); + boolean processReadEvent(char* event); boolean poll(void); void setSocketReadCallback(void (*socketReadCallback)(int, String)); void setSocketCloseCallback(void (*socketCloseCallback)(int)); @@ -595,7 +595,7 @@ class SARA_R5 : public Print // IP Transport Layer int socketOpen(SARA_R5_socket_protocol_t protocol, unsigned int localPort = 0); - SARA_R5_error_t socketClose(int socket, int timeout = SARA_R5_2_MIN_TIMEOUT); + SARA_R5_error_t socketClose(int socket, unsigned long timeout = SARA_R5_2_MIN_TIMEOUT); SARA_R5_error_t socketConnect(int socket, const char *address, unsigned int port); SARA_R5_error_t socketWrite(int socket, const char *str); SARA_R5_error_t socketWrite(int socket, String str); @@ -605,10 +605,10 @@ class SARA_R5 : public Print SARA_R5_error_t socketReadUDP(int socket, int length, char *readDest); SARA_R5_error_t socketListen(int socket, unsigned int port); SARA_R5_error_t socketDirectLinkMode(int socket); - SARA_R5_error_t socketDirectLinkTimeTrigger(int socket, int timerTrigger); + SARA_R5_error_t socketDirectLinkTimeTrigger(int socket, unsigned long timerTrigger); SARA_R5_error_t socketDirectLinkDataLengthTrigger(int socket, int dataLengthTrigger); SARA_R5_error_t socketDirectLinkCharacterTrigger(int socket, int characterTrigger); - SARA_R5_error_t socketDirectLinkCongestionTimer(int socket, int congestionTimer); + SARA_R5_error_t socketDirectLinkCongestionTimer(int socket, unsigned long congestionTimer); int socketGetLastError(); IPAddress lastRemoteIP(void); From 8408f4370f3070d80282873f193512369f9170e7 Mon Sep 17 00:00:00 2001 From: PaulZC Date: Tue, 28 Dec 2021 09:45:28 +0000 Subject: [PATCH 03/11] Replace boolean with bool --- keywords.txt | 2 +- ...parkFun_u-blox_SARA-R5_Arduino_Library.cpp | 76 +++++++++---------- src/SparkFun_u-blox_SARA-R5_Arduino_Library.h | 58 +++++++------- 3 files changed, 68 insertions(+), 68 deletions(-) diff --git a/keywords.txt b/keywords.txt index 208f7f4..174e570 100644 --- a/keywords.txt +++ b/keywords.txt @@ -127,7 +127,7 @@ sendHTTPPOSTdata KEYWORD2 setPDPconfiguration KEYWORD2 performPDPaction KEYWORD2 activatePDPcontext KEYWORD2 -boolean isGPSon KEYWORD2 +isGPSon KEYWORD2 gpsPower KEYWORD2 gpsEnableClock KEYWORD2 gpsGetClock KEYWORD2 diff --git a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp index cfdfb69..4b431ab 100644 --- a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp +++ b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp @@ -42,7 +42,7 @@ SARA_R5::SARA_R5(int powerPin, int resetPin, uint8_t maxInitDepth) } #ifdef SARA_R5_SOFTWARE_SERIAL_ENABLED -boolean SARA_R5::begin(SoftwareSerial &softSerial, unsigned long baud) +bool SARA_R5::begin(SoftwareSerial &softSerial, unsigned long baud) { SARA_R5_error_t err; @@ -57,7 +57,7 @@ boolean SARA_R5::begin(SoftwareSerial &softSerial, unsigned long baud) } #endif -boolean SARA_R5::begin(HardwareSerial &hardSerial, unsigned long baud) +bool SARA_R5::begin(HardwareSerial &hardSerial, unsigned long baud) { SARA_R5_error_t err; @@ -79,7 +79,7 @@ void SARA_R5::enableDebugging(Stream &debugPort) _printDebug = true; } -boolean SARA_R5::bufferedPoll(void) +bool SARA_R5::bufferedPoll(void) { int avail = 0; char c = 0; @@ -131,7 +131,7 @@ boolean SARA_R5::bufferedPoll(void) return handled; } -boolean SARA_R5::processReadEvent(char* event) +bool SARA_R5::processReadEvent(char* event) { { int socket, length; @@ -190,7 +190,7 @@ boolean SARA_R5::processReadEvent(char* event) return false; } -boolean SARA_R5::poll(void) +bool SARA_R5::poll(void) { int avail = 0; char c = 0; @@ -510,7 +510,7 @@ SARA_R5_error_t SARA_R5::at(void) return err; } -SARA_R5_error_t SARA_R5::enableEcho(boolean enable) +SARA_R5_error_t SARA_R5::enableEcho(bool enable) { SARA_R5_error_t err; char *command; @@ -1031,7 +1031,7 @@ SARA_R5_error_t SARA_R5::getUtimeConfiguration(int32_t *offsetNanoseconds, int32 return err; } -SARA_R5_error_t SARA_R5::autoTimeZone(boolean enable) +SARA_R5_error_t SARA_R5::autoTimeZone(bool enable) { SARA_R5_error_t err; char *command; @@ -1122,7 +1122,7 @@ SARA_R5_registration_status_t SARA_R5::registration(void) return (SARA_R5_registration_status_t)status; } -boolean SARA_R5::setNetworkProfile(mobile_network_operator_t mno, boolean autoReset, boolean urcNotification) +bool SARA_R5::setNetworkProfile(mobile_network_operator_t mno, bool autoReset, bool urcNotification) { mobile_network_operator_t currentMno; @@ -1262,7 +1262,7 @@ SARA_R5_error_t SARA_R5::getAPN(int cid, String *apn, IPAddress *ip) char *searchPtr = response; - boolean keepGoing = true; + bool keepGoing = true; while (keepGoing == true) { int apnLen = 0; @@ -2542,7 +2542,7 @@ SARA_R5_error_t SARA_R5::setHTTPpassword(int profile, String password) return err; } -SARA_R5_error_t SARA_R5::setHTTPauthentication(int profile, boolean authenticate) +SARA_R5_error_t SARA_R5::setHTTPauthentication(int profile, bool authenticate) { SARA_R5_error_t err; char *command; @@ -2584,7 +2584,7 @@ SARA_R5_error_t SARA_R5::setHTTPserverPort(int profile, int port) return err; } -SARA_R5_error_t SARA_R5::setHTTPsecure(int profile, boolean secure) +SARA_R5_error_t SARA_R5::setHTTPsecure(int profile, bool secure) { SARA_R5_error_t err; char *command; @@ -2797,7 +2797,7 @@ SARA_R5_error_t SARA_R5::performPDPaction(int profile, SARA_R5_pdp_actions_t act return err; } -SARA_R5_error_t SARA_R5::activatePDPcontext(boolean status, int cid) +SARA_R5_error_t SARA_R5::activatePDPcontext(bool status, int cid) { SARA_R5_error_t err; char *command; @@ -2820,12 +2820,12 @@ SARA_R5_error_t SARA_R5::activatePDPcontext(boolean status, int cid) return err; } -boolean SARA_R5::isGPSon(void) +bool SARA_R5::isGPSon(void) { SARA_R5_error_t err; char *command; char *response; - boolean on = false; + bool on = false; command = sara_r5_calloc_char(strlen(SARA_R5_GNSS_POWER) + 2); if (command == NULL) @@ -2861,11 +2861,11 @@ boolean SARA_R5::isGPSon(void) return on; } -SARA_R5_error_t SARA_R5::gpsPower(boolean enable, gnss_system_t gnss_sys, gnss_aiding_mode_t gnss_aiding) +SARA_R5_error_t SARA_R5::gpsPower(bool enable, gnss_system_t gnss_sys, gnss_aiding_mode_t gnss_aiding) { SARA_R5_error_t err; char *command; - boolean gpsState; + bool gpsState; // Don't turn GPS on/off if it's already on/off gpsState = isGPSon(); @@ -2893,10 +2893,10 @@ SARA_R5_error_t SARA_R5::gpsPower(boolean enable, gnss_system_t gnss_sys, gnss_a return err; } -SARA_R5_error_t SARA_R5::gpsEnableClock(boolean enable) +SARA_R5_error_t SARA_R5::gpsEnableClock(bool enable) { //enable is unused at the moment but could be used if this function is ever implemented. - boolean ignoreMe = enable; ignoreMe |= false; // Avoid the pesky compiler warning. + bool ignoreMe = enable; ignoreMe |= false; // Avoid the pesky compiler warning. // AT+UGZDA=<0,1> SARA_R5_error_t err = SARA_R5_ERROR_SUCCESS; @@ -2910,10 +2910,10 @@ SARA_R5_error_t SARA_R5::gpsGetClock(struct ClockData *clock) return err; } -SARA_R5_error_t SARA_R5::gpsEnableFix(boolean enable) +SARA_R5_error_t SARA_R5::gpsEnableFix(bool enable) { //enable is unused at the moment but could be used if this function is ever implemented. - boolean ignoreMe = enable; ignoreMe |= false; // Avoid the pesky compiler warning. + bool ignoreMe = enable; ignoreMe |= false; // Avoid the pesky compiler warning. // AT+UGGGA=<0,1> SARA_R5_error_t err = SARA_R5_ERROR_SUCCESS; @@ -2927,10 +2927,10 @@ SARA_R5_error_t SARA_R5::gpsGetFix(struct PositionData *pos) return err; } -SARA_R5_error_t SARA_R5::gpsEnablePos(boolean enable) +SARA_R5_error_t SARA_R5::gpsEnablePos(bool enable) { //enable is unused at the moment but could be used if this function is ever implemented. - boolean ignoreMe = enable; ignoreMe |= false; // Avoid the pesky compiler warning. + bool ignoreMe = enable; ignoreMe |= false; // Avoid the pesky compiler warning. // AT+UGGLL=<0,1> SARA_R5_error_t err = SARA_R5_ERROR_SUCCESS; @@ -2944,10 +2944,10 @@ SARA_R5_error_t SARA_R5::gpsGetPos(struct PositionData *pos) return err; } -SARA_R5_error_t SARA_R5::gpsEnableSat(boolean enable) +SARA_R5_error_t SARA_R5::gpsEnableSat(bool enable) { //enable is unused at the moment but could be used if this function is ever implemented. - boolean ignoreMe = enable; ignoreMe |= false; // Avoid the pesky compiler warning. + bool ignoreMe = enable; ignoreMe |= false; // Avoid the pesky compiler warning. // AT+UGGSV=<0,1> SARA_R5_error_t err = SARA_R5_ERROR_SUCCESS; @@ -2961,7 +2961,7 @@ SARA_R5_error_t SARA_R5::gpsGetSat(uint8_t *sats) return err; } -SARA_R5_error_t SARA_R5::gpsEnableRmc(boolean enable) +SARA_R5_error_t SARA_R5::gpsEnableRmc(bool enable) { // AT+UGRMC=<0,1> SARA_R5_error_t err; @@ -2990,7 +2990,7 @@ SARA_R5_error_t SARA_R5::gpsEnableRmc(boolean enable) } SARA_R5_error_t SARA_R5::gpsGetRmc(struct PositionData *pos, struct SpeedData *spd, - struct ClockData *clk, boolean *valid) + struct ClockData *clk, bool *valid) { SARA_R5_error_t err; char *command; @@ -3029,10 +3029,10 @@ SARA_R5_error_t SARA_R5::gpsGetRmc(struct PositionData *pos, struct SpeedData *s return err; } -SARA_R5_error_t SARA_R5::gpsEnableSpeed(boolean enable) +SARA_R5_error_t SARA_R5::gpsEnableSpeed(bool enable) { //enable is unused at the moment but could be used if this function is ever implemented. - boolean ignoreMe = enable; ignoreMe |= false; // Avoid the pesky compiler warning. + bool ignoreMe = enable; ignoreMe |= false; // Avoid the pesky compiler warning. // AT+UGVTG=<0,1> SARA_R5_error_t err = SARA_R5_ERROR_SUCCESS; @@ -3047,7 +3047,7 @@ SARA_R5_error_t SARA_R5::gpsGetSpeed(struct SpeedData *speed) } SARA_R5_error_t SARA_R5::gpsRequest(unsigned int timeout, uint32_t accuracy, - boolean detailed) + bool detailed) { // AT+ULOC=2,,,, SARA_R5_error_t err; @@ -3121,7 +3121,7 @@ SARA_R5_error_t SARA_R5::getFileContents(String filename, String *contents) return SARA_R5_ERROR_UNEXPECTED_RESPONSE; } - boolean keepGoing = true; + bool keepGoing = true; int bytesRead = 0; if (_printDebug == true) _debugPort->print(F("getFileContents: file contents are \"")); @@ -3218,7 +3218,7 @@ SARA_R5_error_t SARA_R5::init(unsigned long baud, return SARA_R5_ERROR_SUCCESS; } -void SARA_R5::invertPowerPin(boolean invert) +void SARA_R5::invertPowerPin(bool invert) { _invertPowerPin = invert; } @@ -3272,7 +3272,7 @@ SARA_R5_error_t SARA_R5::functionality(SARA_R5_functionality_t function) return err; } -SARA_R5_error_t SARA_R5::setMNOprofile(mobile_network_operator_t mno, boolean autoReset, boolean urcNotification) +SARA_R5_error_t SARA_R5::setMNOprofile(mobile_network_operator_t mno, bool autoReset, bool urcNotification) { SARA_R5_error_t err; char *command; @@ -3348,7 +3348,7 @@ SARA_R5_error_t SARA_R5::getMNOprofile(mobile_network_operator_t *mno) SARA_R5_error_t SARA_R5::waitForResponse(const char *expectedResponse, const char *expectedError, uint16_t timeout) { unsigned long timeIn; - boolean found = false; + bool found = false; int responseIndex = 0, errorIndex = 0; int backlogIndex = strlen(saraResponseBacklog); @@ -3407,9 +3407,9 @@ SARA_R5_error_t SARA_R5::waitForResponse(const char *expectedResponse, const cha SARA_R5_error_t SARA_R5::sendCommandWithResponse( const char *command, const char *expectedResponse, char *responseDest, - unsigned long commandTimeout, boolean at) + unsigned long commandTimeout, bool at) { - boolean found = false; + bool found = false; int index = 0; int destIndex = 0; unsigned int charsRead = 0; @@ -3466,12 +3466,12 @@ SARA_R5_error_t SARA_R5::sendCommandWithResponse( // Send a custom command with an expected (potentially partial) response, store entire response SARA_R5_error_t SARA_R5::sendCustomCommandWithResponse(const char *command, const char *expectedResponse, - char *responseDest, unsigned long commandTimeout, boolean at) + char *responseDest, unsigned long commandTimeout, bool at) { return sendCommandWithResponse(command, expectedResponse, responseDest, commandTimeout, at); } -int SARA_R5::sendCommand(const char *command, boolean at) +int SARA_R5::sendCommand(const char *command, bool at) { int backlogIndex = strlen(saraResponseBacklog); @@ -3837,7 +3837,7 @@ char *SARA_R5::readDataUntil(char *destination, unsigned int destSize, return strEnd; } -boolean SARA_R5::parseGPRMCString(char *rmcString, PositionData *pos, +bool SARA_R5::parseGPRMCString(char *rmcString, PositionData *pos, ClockData *clk, SpeedData *spd) { char *ptr, *search; diff --git a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h index 3e7739f..03175b3 100644 --- a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h +++ b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h @@ -432,9 +432,9 @@ class SARA_R5 : public Print // Begin -- initialize BT module and ensure it's connected #ifdef SARA_R5_SOFTWARE_SERIAL_ENABLED - boolean begin(SoftwareSerial &softSerial, unsigned long baud = 9600); + bool begin(SoftwareSerial &softSerial, unsigned long baud = 9600); #endif - boolean begin(HardwareSerial &hardSerial, unsigned long baud = 9600); + bool begin(HardwareSerial &hardSerial, unsigned long baud = 9600); // Debug prints void enableDebugging(Stream &debugPort = Serial); //Turn on debug printing. If user doesn't specify then Serial will be used. @@ -442,12 +442,12 @@ class SARA_R5 : public Print // Invert the polarity of the power pin - if required // Normally the SARA's power pin is pulled low and released to toggle the power // But the Asset Tracker needs this to be pulled high and released instead - void invertPowerPin(boolean invert = false); + void invertPowerPin(bool invert = false); // Loop polling and polling setup - boolean bufferedPoll(void); - boolean processReadEvent(char* event); - boolean poll(void); + bool bufferedPoll(void); + bool processReadEvent(char* event); + bool poll(void); void setSocketReadCallback(void (*socketReadCallback)(int, String)); void setSocketCloseCallback(void (*socketCloseCallback)(int)); void setGpsReadCallback(void (*gpsRequestCallback)(ClockData time, @@ -464,7 +464,7 @@ class SARA_R5 : public Print // General AT Commands SARA_R5_error_t at(void); - SARA_R5_error_t enableEcho(boolean enable = true); + SARA_R5_error_t enableEcho(bool enable = true); String getManufacturerID(void); String getModelID(void); String getFirmwareVersion(void); @@ -481,7 +481,7 @@ class SARA_R5 : public Print // TODO: Return a clock struct SARA_R5_error_t clock(uint8_t *y, uint8_t *mo, uint8_t *d, uint8_t *h, uint8_t *min, uint8_t *s, uint8_t *tz); - SARA_R5_error_t autoTimeZone(boolean enable); + SARA_R5_error_t autoTimeZone(bool enable); SARA_R5_error_t setUtimeMode(SARA_R5_utime_mode_t mode = SARA_R5_UTIME_MODE_PPS, SARA_R5_utime_sensor_t sensor = SARA_R5_UTIME_SENSOR_GNSS_LTE); SARA_R5_error_t getUtimeMode(SARA_R5_utime_mode_t *mode, SARA_R5_utime_sensor_t *sensor); SARA_R5_error_t setUtimeIndication(SARA_R5_utime_urc_configuration_t config = SARA_R5_UTIME_URC_CONFIGURATION_ENABLED); @@ -492,7 +492,7 @@ class SARA_R5 : public Print // Network service AT commands int8_t rssi(void); SARA_R5_registration_status_t registration(void); - boolean setNetworkProfile(mobile_network_operator_t mno, boolean autoReset = false, boolean urcNotification = false); + bool setNetworkProfile(mobile_network_operator_t mno, bool autoReset = false, bool urcNotification = false); mobile_network_operator_t getNetworkProfile(void); typedef enum { @@ -621,9 +621,9 @@ class SARA_R5 : public Print SARA_R5_error_t setHTTPserverName(int profile, String server); // Default: empty string SARA_R5_error_t setHTTPusername(int profile, String username); // Default: empty string SARA_R5_error_t setHTTPpassword(int profile, String password); // Default: empty string - SARA_R5_error_t setHTTPauthentication(int profile, boolean authenticate); // Default: no authentication + SARA_R5_error_t setHTTPauthentication(int profile, bool authenticate); // Default: no authentication SARA_R5_error_t setHTTPserverPort(int profile, int port); // Default: 80 - SARA_R5_error_t setHTTPsecure(int profile, boolean secure); // Default: disabled (HTTP on port 80). Set to true for HTTPS on port 443 + SARA_R5_error_t setHTTPsecure(int profile, bool secure); // Default: disabled (HTTP on port 80). Set to true for HTTPS on port 443 // TO DO: Add custom request headers SARA_R5_error_t getHTTPprotocolError(int profile, int *error_class, int *error_code); // Read the most recent HTTP protocol error for this profile SARA_R5_error_t sendHTTPGET(int profile, String path, String responseFilename); @@ -635,7 +635,7 @@ class SARA_R5 : public Print SARA_R5_error_t setPDPconfiguration(int profile, SARA_R5_pdp_configuration_parameter_t parameter, String value); // Set parameters in the chosen PSD profile SARA_R5_error_t setPDPconfiguration(int profile, SARA_R5_pdp_configuration_parameter_t parameter, IPAddress value); // Set parameters in the chosen PSD profile SARA_R5_error_t performPDPaction(int profile, SARA_R5_pdp_actions_t action); // Performs the requested action for the specified PSD profile. - SARA_R5_error_t activatePDPcontext(boolean status, int cid = -1); // Activates or deactivates the specified PDP context. Default to all (cid = -1) + SARA_R5_error_t activatePDPcontext(bool status, int cid = -1); // Activates or deactivates the specified PDP context. Default to all (cid = -1) // GPS typedef enum @@ -656,27 +656,27 @@ class SARA_R5 : public Print GNSS_AIDING_MODE_ASSISTNOW_ONLINE = 4, GNSS_AIDING_MODE_ASSISTNOW_AUTONOMOUS = 8 } gnss_aiding_mode_t; - boolean isGPSon(void); - SARA_R5_error_t gpsPower(boolean enable = true, + bool isGPSon(void); + SARA_R5_error_t gpsPower(bool enable = true, gnss_system_t gnss_sys = GNSS_SYSTEM_GPS, gnss_aiding_mode_t gnss_aiding = GNSS_AIDING_MODE_AUTOMATIC); - SARA_R5_error_t gpsEnableClock(boolean enable = true); + SARA_R5_error_t gpsEnableClock(bool enable = true); SARA_R5_error_t gpsGetClock(struct ClockData *clock); - SARA_R5_error_t gpsEnableFix(boolean enable = true); + SARA_R5_error_t gpsEnableFix(bool enable = true); SARA_R5_error_t gpsGetFix(float *lat, float *lon, unsigned int *alt, uint8_t *quality, uint8_t *sat); SARA_R5_error_t gpsGetFix(struct PositionData *pos); - SARA_R5_error_t gpsEnablePos(boolean enable = true); + SARA_R5_error_t gpsEnablePos(bool enable = true); SARA_R5_error_t gpsGetPos(struct PositionData *pos); - SARA_R5_error_t gpsEnableSat(boolean enable = true); + SARA_R5_error_t gpsEnableSat(bool enable = true); SARA_R5_error_t gpsGetSat(uint8_t *sats); - SARA_R5_error_t gpsEnableRmc(boolean enable = true); + SARA_R5_error_t gpsEnableRmc(bool enable = true); SARA_R5_error_t gpsGetRmc(struct PositionData *pos, struct SpeedData *speed, - struct ClockData *clk, boolean *valid); - SARA_R5_error_t gpsEnableSpeed(boolean enable = true); + struct ClockData *clk, bool *valid); + SARA_R5_error_t gpsEnableSpeed(bool enable = true); SARA_R5_error_t gpsGetSpeed(struct SpeedData *speed); - SARA_R5_error_t gpsRequest(unsigned int timeout, uint32_t accuracy, boolean detailed = true); + SARA_R5_error_t gpsRequest(unsigned int timeout, uint32_t accuracy, bool detailed = true); // File system SARA_R5_error_t getFileContents(String filename, String *contents); @@ -686,7 +686,7 @@ class SARA_R5 : public Print // Send a custom command with an expected (potentially partial) response, store entire response SARA_R5_error_t sendCustomCommandWithResponse(const char *command, const char *expectedResponse, - char *responseDest, unsigned long commandTimeout = SARA_R5_STANDARD_RESPONSE_TIMEOUT, boolean at = true); + char *responseDest, unsigned long commandTimeout = SARA_R5_STANDARD_RESPONSE_TIMEOUT, bool at = true); private: HardwareSerial *_hardSerial; @@ -695,11 +695,11 @@ class SARA_R5 : public Print #endif Stream *_debugPort; //The stream to send debug messages to if enabled. Usually Serial. - boolean _printDebug = false; //Flag to print debugging variables + bool _printDebug = false; //Flag to print debugging variables int _powerPin; int _resetPin; - boolean _invertPowerPin = false; + bool _invertPowerPin = false; unsigned long _baud; IPAddress _lastRemoteIP; @@ -728,7 +728,7 @@ class SARA_R5 : public Print void hwReset(void); - SARA_R5_error_t setMNOprofile(mobile_network_operator_t mno, boolean autoReset = false, boolean urcNotification = false); + SARA_R5_error_t setMNOprofile(mobile_network_operator_t mno, bool autoReset = false, bool urcNotification = false); SARA_R5_error_t getMNOprofile(mobile_network_operator_t *mno); // Wait for an expected response (don't send a command) @@ -736,10 +736,10 @@ class SARA_R5 : public Print // Send command with an expected (potentially partial) response, store entire response SARA_R5_error_t sendCommandWithResponse(const char *command, const char *expectedResponse, - char *responseDest, unsigned long commandTimeout, boolean at = true); + char *responseDest, unsigned long commandTimeout, bool at = true); // Send a command -- prepend AT if at is true - int sendCommand(const char *command, boolean at); + int sendCommand(const char *command, bool at); SARA_R5_error_t parseSocketReadIndication(int socket, int length); SARA_R5_error_t parseSocketReadIndicationUDP(int socket, int length); @@ -765,7 +765,7 @@ class SARA_R5 : public Print // GPS Helper functions char *readDataUntil(char *destination, unsigned int destSize, char *source, char delimiter); - boolean parseGPRMCString(char *rmcString, PositionData *pos, ClockData *clk, SpeedData *spd); + bool parseGPRMCString(char *rmcString, PositionData *pos, ClockData *clk, SpeedData *spd); }; From 47b867a991375b42cc2279a4c2691e1f4002eb32 Mon Sep 17 00:00:00 2001 From: PaulZC Date: Tue, 28 Dec 2021 09:46:39 +0000 Subject: [PATCH 04/11] Comment the non-implemented GPS functions --- keywords.txt | 20 +++++++------- ...parkFun_u-blox_SARA-R5_Arduino_Library.cpp | 19 +++----------- src/SparkFun_u-blox_SARA-R5_Arduino_Library.h | 26 +++++++++---------- 3 files changed, 26 insertions(+), 39 deletions(-) diff --git a/keywords.txt b/keywords.txt index 174e570..15ba344 100644 --- a/keywords.txt +++ b/keywords.txt @@ -129,18 +129,18 @@ performPDPaction KEYWORD2 activatePDPcontext KEYWORD2 isGPSon KEYWORD2 gpsPower KEYWORD2 -gpsEnableClock KEYWORD2 -gpsGetClock KEYWORD2 -gpsEnableFix KEYWORD2 -gpsGetFix KEYWORD2 -gpsEnablePos KEYWORD2 -gpsGetPos KEYWORD2 -gpsEnableSat KEYWORD2 -gpsGetSat KEYWORD2 +# gpsEnableClock KEYWORD2 +# gpsGetClock KEYWORD2 +# gpsEnableFix KEYWORD2 +# gpsGetFix KEYWORD2 +# gpsEnablePos KEYWORD2 +# gpsGetPos KEYWORD2 +# gpsEnableSat KEYWORD2 +# gpsGetSat KEYWORD2 gpsEnableRmc KEYWORD2 gpsGetRmc KEYWORD2 -gpsEnableSpeed KEYWORD2 -gpsGetSpeed KEYWORD2 +# gpsEnableSpeed KEYWORD2 +# gpsGetSpeed KEYWORD2 gpsRequest KEYWORD2 getFileContents KEYWORD2 functionality KEYWORD2 diff --git a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp index 4b431ab..9286dcf 100644 --- a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp +++ b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp @@ -2893,11 +2893,9 @@ SARA_R5_error_t SARA_R5::gpsPower(bool enable, gnss_system_t gnss_sys, gnss_aidi return err; } +/* SARA_R5_error_t SARA_R5::gpsEnableClock(bool enable) { - //enable is unused at the moment but could be used if this function is ever implemented. - bool ignoreMe = enable; ignoreMe |= false; // Avoid the pesky compiler warning. - // AT+UGZDA=<0,1> SARA_R5_error_t err = SARA_R5_ERROR_SUCCESS; return err; @@ -2912,9 +2910,6 @@ SARA_R5_error_t SARA_R5::gpsGetClock(struct ClockData *clock) SARA_R5_error_t SARA_R5::gpsEnableFix(bool enable) { - //enable is unused at the moment but could be used if this function is ever implemented. - bool ignoreMe = enable; ignoreMe |= false; // Avoid the pesky compiler warning. - // AT+UGGGA=<0,1> SARA_R5_error_t err = SARA_R5_ERROR_SUCCESS; return err; @@ -2929,9 +2924,6 @@ SARA_R5_error_t SARA_R5::gpsGetFix(struct PositionData *pos) SARA_R5_error_t SARA_R5::gpsEnablePos(bool enable) { - //enable is unused at the moment but could be used if this function is ever implemented. - bool ignoreMe = enable; ignoreMe |= false; // Avoid the pesky compiler warning. - // AT+UGGLL=<0,1> SARA_R5_error_t err = SARA_R5_ERROR_SUCCESS; return err; @@ -2946,9 +2938,6 @@ SARA_R5_error_t SARA_R5::gpsGetPos(struct PositionData *pos) SARA_R5_error_t SARA_R5::gpsEnableSat(bool enable) { - //enable is unused at the moment but could be used if this function is ever implemented. - bool ignoreMe = enable; ignoreMe |= false; // Avoid the pesky compiler warning. - // AT+UGGSV=<0,1> SARA_R5_error_t err = SARA_R5_ERROR_SUCCESS; return err; @@ -2960,6 +2949,7 @@ SARA_R5_error_t SARA_R5::gpsGetSat(uint8_t *sats) SARA_R5_error_t err = SARA_R5_ERROR_SUCCESS; return err; } +*/ SARA_R5_error_t SARA_R5::gpsEnableRmc(bool enable) { @@ -3029,11 +3019,9 @@ SARA_R5_error_t SARA_R5::gpsGetRmc(struct PositionData *pos, struct SpeedData *s return err; } +/* SARA_R5_error_t SARA_R5::gpsEnableSpeed(bool enable) { - //enable is unused at the moment but could be used if this function is ever implemented. - bool ignoreMe = enable; ignoreMe |= false; // Avoid the pesky compiler warning. - // AT+UGVTG=<0,1> SARA_R5_error_t err = SARA_R5_ERROR_SUCCESS; return err; @@ -3045,6 +3033,7 @@ SARA_R5_error_t SARA_R5::gpsGetSpeed(struct SpeedData *speed) SARA_R5_error_t err = SARA_R5_ERROR_SUCCESS; return err; } +*/ SARA_R5_error_t SARA_R5::gpsRequest(unsigned int timeout, uint32_t accuracy, bool detailed) diff --git a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h index 03175b3..dbb547a 100644 --- a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h +++ b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h @@ -660,21 +660,19 @@ class SARA_R5 : public Print SARA_R5_error_t gpsPower(bool enable = true, gnss_system_t gnss_sys = GNSS_SYSTEM_GPS, gnss_aiding_mode_t gnss_aiding = GNSS_AIDING_MODE_AUTOMATIC); - SARA_R5_error_t gpsEnableClock(bool enable = true); - SARA_R5_error_t gpsGetClock(struct ClockData *clock); - SARA_R5_error_t gpsEnableFix(bool enable = true); - SARA_R5_error_t gpsGetFix(float *lat, float *lon, - unsigned int *alt, uint8_t *quality, uint8_t *sat); - SARA_R5_error_t gpsGetFix(struct PositionData *pos); - SARA_R5_error_t gpsEnablePos(bool enable = true); - SARA_R5_error_t gpsGetPos(struct PositionData *pos); - SARA_R5_error_t gpsEnableSat(bool enable = true); - SARA_R5_error_t gpsGetSat(uint8_t *sats); + //SARA_R5_error_t gpsEnableClock(bool enable = true); + //SARA_R5_error_t gpsGetClock(struct ClockData *clock); + //SARA_R5_error_t gpsEnableFix(bool enable = true); + //SARA_R5_error_t gpsGetFix(float *lat, float *lon, unsigned int *alt, uint8_t *quality, uint8_t *sat); + //SARA_R5_error_t gpsGetFix(struct PositionData *pos); + //SARA_R5_error_t gpsEnablePos(bool enable = true); + //SARA_R5_error_t gpsGetPos(struct PositionData *pos); + //SARA_R5_error_t gpsEnableSat(bool enable = true); + //SARA_R5_error_t gpsGetSat(uint8_t *sats); SARA_R5_error_t gpsEnableRmc(bool enable = true); - SARA_R5_error_t gpsGetRmc(struct PositionData *pos, struct SpeedData *speed, - struct ClockData *clk, bool *valid); - SARA_R5_error_t gpsEnableSpeed(bool enable = true); - SARA_R5_error_t gpsGetSpeed(struct SpeedData *speed); + SARA_R5_error_t gpsGetRmc(struct PositionData *pos, struct SpeedData *speed, struct ClockData *clk, bool *valid); + //SARA_R5_error_t gpsEnableSpeed(bool enable = true); + //SARA_R5_error_t gpsGetSpeed(struct SpeedData *speed); SARA_R5_error_t gpsRequest(unsigned int timeout, uint32_t accuracy, bool detailed = true); From 1ba7e4e9a6c06de4bf80c2c089647d34c97d32d0 Mon Sep 17 00:00:00 2001 From: PaulZC Date: Tue, 28 Dec 2021 10:30:19 +0000 Subject: [PATCH 05/11] Disable software serial on Apollo3 (not supported with v2 of the core) --- src/SparkFun_u-blox_SARA-R5_Arduino_Library.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h index dbb547a..eea7a59 100644 --- a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h +++ b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h @@ -32,7 +32,10 @@ #endif #ifdef ARDUINO_ARCH_APOLLO3 // Arduino Apollo boards (Artemis module, RedBoard Artemis, etc) -#define SARA_R5_SOFTWARE_SERIAL_ENABLED // Enable software serial +#define SARA_R5_SOFTWARE_SERIAL_ENABLEDx // Disable software serial (no longer supported with v2 of Apollo3) +// Note: paulvha has provided software serial support for v2 of the Apollo3 / Artemis core. +// Further details are available at: +// https://github.com/paulvha/apollo3/tree/master/SoftwareSerial #endif #ifdef ARDUINO_ARCH_STM32 // STM32 based boards (Disco, Nucleo, etc) From 987999ed27dc93ab59936f749932ad4f41903834 Mon Sep 17 00:00:00 2001 From: PaulZC Date: Tue, 28 Dec 2021 14:34:06 +0000 Subject: [PATCH 06/11] Correct sscanf to int for all platforms. Correct poll +UULOC --- ...parkFun_u-blox_SARA-R5_Arduino_Library.cpp | 144 +++++++++++++----- 1 file changed, 105 insertions(+), 39 deletions(-) diff --git a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp index 9286dcf..d00a05c 100644 --- a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp +++ b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp @@ -157,13 +157,19 @@ bool SARA_R5::processReadEvent(char* event) int socket, listenSocket; unsigned int port, listenPort; IPAddress remoteIP, localIP; + int remoteIPstore[4], localIPstore[4]; int ret = sscanf(event, - "+UUSOLI: %d,\"%hhu.%hhu.%hhu.%hhu\",%u,%d,\"%hhu.%hhu.%hhu.%hhu\",%u", + "+UUSOLI: %d,\"%d.%d.%d.%d\",%u,%d,\"%d.%d.%d.%d\",%u", &socket, - &remoteIP[0], &remoteIP[1], &remoteIP[2], &remoteIP[3], + &remoteIPstore[0], &remoteIPstore[1], &remoteIPstore[2], &remoteIPstore[3], &port, &listenSocket, - &localIP[0], &localIP[1], &localIP[2], &localIP[3], + &localIPstore[0], &localIPstore[1], &localIPstore[2], &localIPstore[3], &listenPort); + for (int i = 0; i <= 3; i++) + { + remoteIP[i] = (uint8_t)remoteIPstore[i]; + localIP[i] = (uint8_t)localIPstore[i]; + } if (ret > 4) { if (_printDebug == true) _debugPort->println("PARSED SOCKET LISTEN"); @@ -221,13 +227,20 @@ bool SARA_R5::poll(void) unsigned int port, listenPort; IPAddress remoteIP, localIP; - if (sscanf(saraRXBuffer, - "+UUSOLI: %d,\"%hhu.%hhu.%hhu.%hhu\",%u,%d,\"%hhu.%hhu.%hhu.%hhu\",%u", - &socket, - &remoteIP[0], &remoteIP[1], &remoteIP[2], &remoteIP[3], - &port, &listenSocket, - &localIP[0], &localIP[1], &localIP[2], &localIP[3], - &listenPort) > 4) + int remoteIPstore[4], localIPstore[4]; + int ret = sscanf(saraRXBuffer, + "+UUSOLI: %d,\"%d.%d.%d.%d\",%u,%d,\"%d.%d.%d.%d\",%u", + &socket, + &remoteIPstore[0], &remoteIPstore[1], &remoteIPstore[2], &remoteIPstore[3], + &port, &listenSocket, + &localIPstore[0], &localIPstore[1], &localIPstore[2], &localIPstore[3], + &listenPort); + for (int i = 0; i <= 3; i++) + { + remoteIP[i] = (uint8_t)remoteIPstore[i]; + localIP[i] = (uint8_t)localIPstore[i]; + } + if (ret > 4) { parseSocketListenIndication(localIP, remoteIP); handled = true; @@ -255,7 +268,8 @@ bool SARA_R5::poll(void) SpeedData spd; unsigned long uncertainty; int scanNum; - unsigned int latH, lonH, altU, speedU, cogU; + int latH, lonH, alt; + unsigned int speedU, cogU; char latL[10], lonL[10]; // Maybe we should also scan for +UUGIND and extract the activated gnss system? @@ -263,25 +277,57 @@ bool SARA_R5::poll(void) if (strstr(saraRXBuffer, "+UULOC")) { // Found a Location string! + if (_printDebug == true) + { + _debugPort->print("poll +UULOC: saraRXBuffer: "); + _debugPort->println(saraRXBuffer); + } + // This assumes the ULOC response type is "1". TO DO: check that is true... + int dateStore[5]; scanNum = sscanf(saraRXBuffer, - "+UULOC: %hhu/%hhu/%u,%hhu:%hhu:%hhu.%u,%u.%[^,],%u.%[^,],%u,%lu,%u,%u,%*s", - &clck.date.day, &clck.date.month, &clck.date.year, - &clck.time.hour, &clck.time.minute, &clck.time.second, &clck.time.ms, - &latH, latL, &lonH, lonL, &altU, &uncertainty, + "+UULOC: %d/%d/%d,%d:%d:%d.%d,%d.%[^,],%d.%[^,],%d,%lu,%u,%u,%*s", + &dateStore[0], &dateStore[1], &clck.date.year, + &dateStore[2], &dateStore[3], &dateStore[4], &clck.time.ms, + &latH, latL, &lonH, lonL, &alt, &uncertainty, &speedU, &cogU); + clck.date.day = dateStore[0]; + clck.date.month = dateStore[1]; + clck.time.hour = dateStore[2]; + clck.time.minute = dateStore[3]; + clck.time.second = dateStore[4]; if (scanNum < 13) return false; // Break out if we didn't find enough - gps.lat = (float)latH + ((float)atol(latL) / pow(10, strlen(latL))); - gps.lon = (float)lonH + ((float)atol(lonL) / pow(10, strlen(lonL))); - gps.alt = (float)altU; + if (latH >= 0) + gps.lat = (float)latH + ((float)atol(latL) / pow(10, strlen(latL))); + else + gps.lat = (float)latH - ((float)atol(latL) / pow(10, strlen(latL))); + if (lonH >= 0) + gps.lon = (float)lonH + ((float)atol(lonL) / pow(10, strlen(lonL))); + else + gps.lon = (float)lonH - ((float)atol(lonL) / pow(10, strlen(lonL))); + gps.alt = (float)alt; if (scanNum >= 15) // If detailed response, get speed data { spd.speed = (float)speedU; spd.cog = (float)cogU; } + if (_printDebug == true) + { + _debugPort->print("poll +UULOC: lat: "); + _debugPort->print(gps.lat, 6); + _debugPort->print(" lon: "); + _debugPort->print(gps.lon, 6); + _debugPort->print(" alt: "); + _debugPort->print(gps.alt, 2); + _debugPort->print(" speed: "); + _debugPort->print(spd.speed, 2); + _debugPort->print(" cog: "); + _debugPort->println(spd.cog, 2); + } + if (_gpsRequestCallback != NULL) { _gpsRequestCallback(clck, gps, spd, uncertainty); @@ -296,7 +342,9 @@ bool SARA_R5::poll(void) if (strstr(saraRXBuffer, "+UUSIMSTAT")) { - scanNum = sscanf(saraRXBuffer, "+UUSIMSTAT:%hhu", (uint8_t*)&state); + int stateStore; + scanNum = sscanf(saraRXBuffer, "+UUSIMSTAT:%d", &stateStore); + state = (SARA_R5_sim_states_t)stateStore; if (scanNum < 1) return false; // Break out if we didn't find enough @@ -315,8 +363,13 @@ bool SARA_R5::poll(void) if (strstr(saraRXBuffer, "+UUPSDA")) { - scanNum = sscanf(saraRXBuffer, "+UUPSDA: %d,\"%hhu.%hhu.%hhu.%hhu\"", - &result, &remoteIP[0], &remoteIP[1], &remoteIP[2], &remoteIP[3]); + int remoteIPstore[4]; + scanNum = sscanf(saraRXBuffer, "+UUPSDA: %d,\"%d.%d.%d.%d\"", + &result, &remoteIPstore[0], &remoteIPstore[1], &remoteIPstore[2], &remoteIPstore[3]); + for (int i = 0; i <= 3; i++) + { + remoteIP[i] = (uint8_t)remoteIPstore[i]; + } if (scanNum < 1) return false; // Break out if we didn't find enough @@ -342,11 +395,11 @@ bool SARA_R5::poll(void) searchPtr = strstr(searchPtr, "+UUPING: "); if (searchPtr != NULL) { - // if (_printDebug == true) - // { - // _debugPort->print("poll +UUPING: saraRXBuffer: "); - // _debugPort->println(saraRXBuffer); - // } + //if (_printDebug == true) + //{ + // _debugPort->print("poll +UUPING: saraRXBuffer: "); + // _debugPort->println(saraRXBuffer); + //} // Extract the retries and payload size scanNum = sscanf(searchPtr, "+UUPING: %d,%d,", &retry, &p_size); @@ -365,8 +418,13 @@ bool SARA_R5::poll(void) if (*searchPtr == '\0') return false; // Break out if we didn't find enough - scanNum = sscanf(searchPtr, "\",\"%hhu.%hhu.%hhu.%hhu\",%d,%ld", - &remoteIP[0], &remoteIP[1], &remoteIP[2], &remoteIP[3], &ttl, &rtt); + int remoteIPstore[4]; + scanNum = sscanf(searchPtr, "\",\"%d.%d.%d.%d\",%d,%ld", + &remoteIPstore[0], &remoteIPstore[1], &remoteIPstore[2], &remoteIPstore[3], &ttl, &rtt); + for (int i = 0; i <= 3; i++) + { + remoteIP[i] = (uint8_t)remoteIPstore[i]; + } if (scanNum < 6) return false; // Break out if we didn't find enough @@ -892,7 +950,10 @@ SARA_R5_error_t SARA_R5::getUtimeMode(SARA_R5_utime_mode_t *mode, SARA_R5_utime_ // Response format: \r\n+UTIME: [,]\r\n\r\nOK\r\n if (err == SARA_R5_ERROR_SUCCESS) { - int scanned = sscanf(response, "\r\n+UTIME: %hhu,%hhu\r\n", (uint8_t*)&m, (uint8_t*)&s); + int mStore, sStore; + int scanned = sscanf(response, "\r\n+UTIME: %d,%d\r\n", &mStore, &sStore); + m = (SARA_R5_utime_mode_t)mStore; + s = (SARA_R5_utime_sensor_t)sStore; if (scanned == 2) { *mode = m; @@ -953,7 +1014,9 @@ SARA_R5_error_t SARA_R5::getUtimeIndication(SARA_R5_utime_urc_configuration_t *c // Response format: \r\n+UTIMEIND: \r\n\r\nOK\r\n if (err == SARA_R5_ERROR_SUCCESS) { - int scanned = sscanf(response, "\r\n+UTIMEIND: %hhu\r\n", (uint8_t*)&c); + int cStore; + int scanned = sscanf(response, "\r\n+UTIMEIND: %d\r\n", &cStore); + c = (SARA_R5_utime_urc_configuration_t)cStore; if (scanned == 1) { *config = c; @@ -974,7 +1037,7 @@ SARA_R5_error_t SARA_R5::setUtimeConfiguration(int32_t offsetNanoseconds, int32_ command = sara_r5_calloc_char(strlen(SARA_R5_GNSS_TIME_CONFIGURATION) + 48); if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; -#ifdef ARDUINO_ARCH_ESP32 // ESP32 based boards +#ifdef ARDUINO_ARCH_ESP32 sprintf(command, "%s=%d,%d", SARA_R5_GNSS_TIME_CONFIGURATION, offsetNanoseconds, offsetSeconds); #else sprintf(command, "%s=%ld,%ld", SARA_R5_GNSS_TIME_CONFIGURATION, offsetNanoseconds, offsetSeconds); @@ -1013,7 +1076,7 @@ SARA_R5_error_t SARA_R5::getUtimeConfiguration(int32_t *offsetNanoseconds, int32 // Response format: \r\n+UTIMECFG: ,\r\n\r\nOK\r\n if (err == SARA_R5_ERROR_SUCCESS) { -#ifdef ARDUINO_ARCH_ESP32 // ESP32 based boards +#ifdef ARDUINO_ARCH_ESP32 int scanned = sscanf(response, "\r\n+UTIMECFG: %d,%d\r\n", &ons, &os); #else int scanned = sscanf(response, "\r\n+UTIMECFG: %ld,%ld\r\n", &ons, &os); @@ -3056,7 +3119,7 @@ SARA_R5_error_t SARA_R5::gpsRequest(unsigned int timeout, uint32_t accuracy, command = sara_r5_calloc_char(strlen(SARA_R5_GNSS_REQUEST_LOCATION) + 24); if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; -#ifdef ARDUINO_ARCH_ESP32 // ESP32 based boards +#ifdef ARDUINO_ARCH_ESP32 sprintf(command, "%s=2,3,%d,%d,%d", SARA_R5_GNSS_REQUEST_LOCATION, detailed ? 1 : 0, timeout, accuracy); #else @@ -3288,9 +3351,10 @@ SARA_R5_error_t SARA_R5::getMNOprofile(mobile_network_operator_t *mno) char *command; char *response; mobile_network_operator_t o; - mobile_network_operator_t d; + int d; int r; int u; + int oStore; command = sara_r5_calloc_char(strlen(SARA_R5_COMMAND_MNO) + 2); if (command == NULL) @@ -3313,16 +3377,18 @@ SARA_R5_error_t SARA_R5::getMNOprofile(mobile_network_operator_t *mno) return err; } - int ret = sscanf(response, "\r\n+UMNOPROF: %hhd,%hhd,%d,%d", (int8_t*)&o, (int8_t*)&d, &r, &u); - if (ret >= 1) - { - if (_printDebug == true) + int ret = sscanf(response, "\r\n+UMNOPROF: %d,%d,%d,%d", &oStore, &d, &r, &u); + o = (mobile_network_operator_t)oStore; + + if (ret >= 1) + { + if (_printDebug == true) { _debugPort->print("getMNOprofile: MNO is: "); _debugPort->println(o); } *mno = o; - } + } else { err = SARA_R5_ERROR_INVALID; From 38336e57fefef0fd230a776f8cc63944a723de9c Mon Sep 17 00:00:00 2001 From: PaulZC Date: Tue, 28 Dec 2021 20:12:35 +0000 Subject: [PATCH 07/11] Add gpsAidingServerConf --- keywords.txt | 1 + ...parkFun_u-blox_SARA-R5_Arduino_Library.cpp | 48 ++++++++++++++----- src/SparkFun_u-blox_SARA-R5_Arduino_Library.h | 8 +++- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/keywords.txt b/keywords.txt index 15ba344..b462036 100644 --- a/keywords.txt +++ b/keywords.txt @@ -142,6 +142,7 @@ gpsGetRmc KEYWORD2 # gpsEnableSpeed KEYWORD2 # gpsGetSpeed KEYWORD2 gpsRequest KEYWORD2 +gpsAidingServerConf KEYWORD2 getFileContents KEYWORD2 functionality KEYWORD2 sendCustomCommandWithResponse KEYWORD2 diff --git a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp index d00a05c..e80ad69 100644 --- a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp +++ b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp @@ -283,7 +283,7 @@ bool SARA_R5::poll(void) _debugPort->println(saraRXBuffer); } - // This assumes the ULOC response type is "1". TO DO: check that is true... + // This assumes the ULOC response type is "0" or "1" - as selected by gpsRequest detailed int dateStore[5]; scanNum = sscanf(saraRXBuffer, "+UULOC: %d/%d/%d,%d:%d:%d.%d,%d.%[^,],%d.%[^,],%d,%lu,%u,%u,%*s", @@ -317,9 +317,9 @@ bool SARA_R5::poll(void) if (_printDebug == true) { _debugPort->print("poll +UULOC: lat: "); - _debugPort->print(gps.lat, 6); + _debugPort->print(gps.lat, 7); _debugPort->print(" lon: "); - _debugPort->print(gps.lon, 6); + _debugPort->print(gps.lon, 7); _debugPort->print(" alt: "); _debugPort->print(gps.alt, 2); _debugPort->print(" speed: "); @@ -1476,16 +1476,16 @@ SARA_R5_error_t SARA_R5::enterPPP(uint8_t cid, char dialing_type_char, return SARA_R5_ERROR_OUT_OF_MEMORY; if (dialing_type_char != 0) { - sprintf(command, "%s%c*%lu**%s*%hhu#", SARA_R5_MESSAGE_ENTER_PPP, dialing_type_char, - dialNumber, PPP_L2P[l2p], cid); + sprintf(command, "%s%c*%lu**%s*%u#", SARA_R5_MESSAGE_ENTER_PPP, dialing_type_char, + dialNumber, PPP_L2P[l2p], (unsigned int)cid); } else { - sprintf(command, "%s*%lu**%s*%hhu#", SARA_R5_MESSAGE_ENTER_PPP, - dialNumber, PPP_L2P[l2p], cid); + sprintf(command, "%s*%lu**%s*%u#", SARA_R5_MESSAGE_ENTER_PPP, + dialNumber, PPP_L2P[l2p], (unsigned int)cid); } - err = sendCommandWithResponse(command, SARA_R5_RESPONSE_OK, NULL, + err = sendCommandWithResponse(command, SARA_R5_RESPONSE_CONNECT, NULL, SARA_R5_STANDARD_RESPONSE_TIMEOUT); free(command); @@ -3099,7 +3099,7 @@ SARA_R5_error_t SARA_R5::gpsGetSpeed(struct SpeedData *speed) */ SARA_R5_error_t SARA_R5::gpsRequest(unsigned int timeout, uint32_t accuracy, - bool detailed) + bool detailed, unsigned int sensor) { // AT+ULOC=2,,,, SARA_R5_error_t err; @@ -3120,11 +3120,11 @@ SARA_R5_error_t SARA_R5::gpsRequest(unsigned int timeout, uint32_t accuracy, if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; #ifdef ARDUINO_ARCH_ESP32 - sprintf(command, "%s=2,3,%d,%d,%d", SARA_R5_GNSS_REQUEST_LOCATION, - detailed ? 1 : 0, timeout, accuracy); + sprintf(command, "%s=2,%d,%d,%d,%d", SARA_R5_GNSS_REQUEST_LOCATION, + sensor, detailed ? 1 : 0, timeout, accuracy); #else - sprintf(command, "%s=2,3,%d,%d,%ld", SARA_R5_GNSS_REQUEST_LOCATION, - detailed ? 1 : 0, timeout, accuracy); + sprintf(command, "%s=2,%d,%d,%d,%ld", SARA_R5_GNSS_REQUEST_LOCATION, + sensor, detailed ? 1 : 0, timeout, accuracy); #endif err = sendCommandWithResponse(command, SARA_R5_RESPONSE_OK, NULL, SARA_R5_10_SEC_TIMEOUT); @@ -3133,6 +3133,28 @@ SARA_R5_error_t SARA_R5::gpsRequest(unsigned int timeout, uint32_t accuracy, return err; } +SARA_R5_error_t SARA_R5::gpsAidingServerConf(const char *primaryServer, const char *secondaryServer, const char *authToken, + unsigned int days, unsigned int period, unsigned int resolution, + unsigned int gnssTypes, unsigned int mode, unsigned int dataType) +{ + SARA_R5_error_t err; + char *command; + + command = sara_r5_calloc_char(strlen(SARA_R5_AIDING_SERVER_CONFIGURATION) + 256); + if (command == NULL) + return SARA_R5_ERROR_OUT_OF_MEMORY; + + sprintf(command, "%s=\"%s\",\"%s\",\"%s\",%d,%d,%d,%d,%d,%d", SARA_R5_AIDING_SERVER_CONFIGURATION, + primaryServer, secondaryServer, authToken, + days, period, resolution, gnssTypes, mode, dataType); + + err = sendCommandWithResponse(command, SARA_R5_RESPONSE_OK, NULL, + SARA_R5_STANDARD_RESPONSE_TIMEOUT); + + free(command); + return err; +} + SARA_R5_error_t SARA_R5::getFileContents(String filename, String *contents) { SARA_R5_error_t err; diff --git a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h index eea7a59..8ffe3e2 100644 --- a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h +++ b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h @@ -139,6 +139,7 @@ const char SARA_R5_GNSS_TIME_INDICATION[] = "+UTIMEIND"; // Time information req const char SARA_R5_GNSS_TIME_CONFIGURATION[] = "+UTIMECFG"; // Sets time configuration const char SARA_R5_GNSS_CONFIGURE_SENSOR[] = "+ULOCGNSS"; // Configure GNSS sensor const char SARA_R5_GNSS_CONFIGURE_LOCATION[] = "+ULOCCELL"; // Configure cellular location sensor (CellLocate®) +const char SARA_R5_AIDING_SERVER_CONFIGURATION[] = "+UGSRV"; // Configure aiding server (CellLocate®) // ### File System const char SARA_R5_FILE_SYSTEM_READ_FILE[] = "+URDFILE"; // Read a file // ### Response @@ -677,7 +678,12 @@ class SARA_R5 : public Print //SARA_R5_error_t gpsEnableSpeed(bool enable = true); //SARA_R5_error_t gpsGetSpeed(struct SpeedData *speed); - SARA_R5_error_t gpsRequest(unsigned int timeout, uint32_t accuracy, bool detailed = true); + SARA_R5_error_t gpsRequest(unsigned int timeout, uint32_t accuracy, bool detailed = true, unsigned int sensor = 3); + + //CellLocate + SARA_R5_error_t gpsAidingServerConf(const char *primaryServer, const char *secondaryServer, const char *authToken, + unsigned int days = 14, unsigned int period = 4, unsigned int resolution = 1, + unsigned int gnssTypes = 65, unsigned int mode = 0, unsigned int dataType = 15); // File system SARA_R5_error_t getFileContents(String filename, String *contents); From 3be8766408575adf5fb3177771cb43c097007c37 Mon Sep 17 00:00:00 2001 From: Nathan Seidle Date: Tue, 28 Dec 2021 14:49:23 -0700 Subject: [PATCH 08/11] Do not rebegin serial port if user assigned it before lib begin. Add end() to beginSerial to allow ESP32 software serial. --- src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp index 1cd973a..7bc3c06 100644 --- a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp +++ b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp @@ -3044,7 +3044,8 @@ SARA_R5_error_t SARA_R5::init(unsigned long baud, if (_printDebug == true) _debugPort->println(F("Begin module init.")); - beginSerial(baud); // Begin serial + if(hwAvailable() == -1) + beginSerial(baud); // If port is null, begin serial if (initType == SARA_R5_INIT_AUTOBAUD) { @@ -3594,6 +3595,7 @@ void SARA_R5::beginSerial(unsigned long baud) #ifdef SARA_R5_SOFTWARE_SERIAL_ENABLED else if (_softSerial != NULL) { + _softSerial->end(); _softSerial->begin(baud); } #endif From 8fe9b215118c30865672e383af4d7af8a6dbe3f1 Mon Sep 17 00:00:00 2001 From: PaulZC Date: Wed, 29 Dec 2021 13:23:42 +0000 Subject: [PATCH 09/11] Add support for ESPSoftwareSerial --- ...parkFun_u-blox_SARA-R5_Arduino_Library.cpp | 8 +++++-- src/SparkFun_u-blox_SARA-R5_Arduino_Library.h | 22 ++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp index fff8883..2293791 100644 --- a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp +++ b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp @@ -3246,8 +3246,12 @@ SARA_R5_error_t SARA_R5::init(unsigned long baud, if (_printDebug == true) _debugPort->println(F("Begin module init.")); - if(hwAvailable() == -1) - beginSerial(baud); // If port is null, begin serial + // There's no 'easy' way to tell if the serial port has already been begun for us. + // We have to assume it has not been begun and so do it here. + // For special cases like Software Serial on ESP32, we need to begin _and_ end the port externally + // _before_ calling the SARA_R5 .begin. + // See SARA-R5_Example2_Identification_ESPSoftwareSerial for more details. + beginSerial(baud); if (initType == SARA_R5_INIT_AUTOBAUD) { diff --git a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h index 8ffe3e2..1605547 100644 --- a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h +++ b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.h @@ -43,11 +43,31 @@ #endif #ifdef ARDUINO_ARCH_ESP32 // ESP32 based boards +// Check to see if ESP Software Serial has been included +// Note: you need to #include at the very start of your script, +// _before_ the #include , for this to work. +// See SARA-R5_Example2_Identification_ESPSoftwareSerial for more details. +#if __has_include( ) +#define SARA_R5_SOFTWARE_SERIAL_ENABLED // Enable software serial +#else #define SARA_R5_SOFTWARE_SERIAL_ENABLEDx // Disable software serial #endif +#endif + +#ifdef ARDUINO_ARCH_ESP8266 // ESP8266 based boards +// Check to see if ESP Software Serial has been included +// Note: you need to #include at the very start of your script, +// _before_ the #include , for this to work. +// See SARA-R5_Example2_Identification_ESPSoftwareSerial for more details. +#if __has_include( ) +#define SARA_R5_SOFTWARE_SERIAL_ENABLED // Enable software serial +#else +#define SARA_R5_SOFTWARE_SERIAL_ENABLEDx // Disable software serial +#endif +#endif #ifdef SARA_R5_SOFTWARE_SERIAL_ENABLED -#include +#include // SoftwareSerial.h is guarded. It is OK to include it twice. #endif #include From fed67d67deb0198e5d73d58150c3fb38d3560ddc Mon Sep 17 00:00:00 2001 From: PaulZC Date: Wed, 29 Dec 2021 13:25:02 +0000 Subject: [PATCH 10/11] Add an example for ESPSoftwareSerial on the ESP32 --- ...mple2_Identification_ESPSoftwareSerial.ino | 139 ++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 examples/SARA-R5_Example2_Identification_ESPSoftwareSerial/SARA-R5_Example2_Identification_ESPSoftwareSerial.ino diff --git a/examples/SARA-R5_Example2_Identification_ESPSoftwareSerial/SARA-R5_Example2_Identification_ESPSoftwareSerial.ino b/examples/SARA-R5_Example2_Identification_ESPSoftwareSerial/SARA-R5_Example2_Identification_ESPSoftwareSerial.ino new file mode 100644 index 0000000..0a6de25 --- /dev/null +++ b/examples/SARA-R5_Example2_Identification_ESPSoftwareSerial/SARA-R5_Example2_Identification_ESPSoftwareSerial.ino @@ -0,0 +1,139 @@ +/* + + SARA-R5 Example + =============== + + Identification - using ESPSoftwareSerial + + Written by: Paul Clark + Date: December 29th 2021 + + This example demonstrates how to read the SARA's: + Manufacturer identification + Model identification + Firmware version identification + Product Serial No. + IMEI identification + IMSI identification + SIM CCID + Subscriber number + Capabilities + SIM state + + The ESP32 core doesn't include SoftwareSerial. Instead we use the library by Peter Lerup and Dirk O. Kaar: + https://github.com/plerup/espsoftwareserial + + Feel like supporting open source hardware? + Buy a board from SparkFun! + + Licence: MIT + Please see LICENSE.md for full details + +*/ + +// Include SoftwareSerial.h _before_ including SparkFun_u-blox_SARA-R5_Arduino_Library.h +// to allow the SARA-R5 library to detect SoftwareSerial.h using an #if __has_include +#include //Click here to get the library: http://librarymanager/All#ESPSoftwareSerial_ESP8266/ESP32 + +#include //Click here to get the library: http://librarymanager/All#SparkFun_u-blox_SARA-R5_Arduino_Library + +// Create a SoftwareSerial object to pass to the SARA-R5 library +// Note: we need to call saraSerial.begin and saraSerial.end in setup() - see below for details +SoftwareSerial saraSerial; + +// Create a SARA_R5 object to use throughout the sketch +// Usually we would tell the library which GPIO pin to use to control the SARA power (see below), +// but we can start the SARA without a power pin. It just means we need to manually +// turn the power on if required! ;-D +SARA_R5 mySARA; + +// Create a SARA_R5 object to use throughout the sketch +// We need to tell the library what GPIO pin is connected to the SARA power pin. +// If you're using the MicroMod Asset Tracker and the MicroMod Artemis Processor Board, +// the pin name is G2 which is connected to pin AD34. +// Change the pin number if required. +//SARA_R5 mySARA(34); + +// Map SIM states to more readable strings +String simStateString[] = +{ + "Not present", // 0 + "PIN needed", // 1 + "PIN blocked", // 2 + "PUK blocked", // 3 + "Not operational", // 4 + "Restricted", // 5 + "Operational" // 6 +}; + +// processSIMstate is provided to the SARA-R5 library via a +// callback setter -- setSIMstateReadCallback. (See setup()) +void processSIMstate(SARA_R5_sim_states_t state) +{ + Serial.println(); + Serial.print(F("SIM state: ")); + Serial.print(String(state)); + Serial.println(); +} + +void setup() +{ + Serial.begin(115200); // Start the serial console + + // Wait for user to press key to begin + Serial.println(F("SARA-R5 Example")); + Serial.println(F("Press any key to begin")); + + while (!Serial.available()) // Wait for the user to press a key (send any serial character) + ; + while (Serial.available()) // Empty the serial RX buffer + Serial.read(); + + //mySARA.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial + + // For the MicroMod Asset Tracker, we need to invert the power pin so it pulls high instead of low + // Comment the next line if required + mySARA.invertPowerPin(true); + + // ESPSoftwareSerial does not like repeated .begin's without a .end in between. + // We need to .begin and .end the saraSerial port here, before the mySARA.begin, to set up the pin numbers etc. + // E.g. to use: 57600 baud; 8 databits, no parity, 1 stop bit; RXD on pin 33; TXD on pin 32; no inversion. + Serial.println(F("Configuring SoftwareSerial saraSerial")); + saraSerial.begin(57600, SWSERIAL_8N1, 33, 32, false); + saraSerial.end(); + + // Initialize the SARA + if (mySARA.begin(saraSerial, 57600) ) + { + Serial.println(F("SARA-R5 connected!")); + } + else + { + Serial.println(F("Unable to communicate with the SARA.")); + Serial.println(F("Manually power-on (hold the SARA On button for 3 seconds) on and try again.")); + while (1) ; // Loop forever on fail + } + Serial.println(); + + Serial.println("Manufacturer ID: " + String(mySARA.getManufacturerID())); + Serial.println("Model ID: " + String(mySARA.getModelID())); + Serial.println("Firmware Version: " + String(mySARA.getFirmwareVersion())); + Serial.println("Product Serial No.: " + String(mySARA.getSerialNo())); + Serial.println("IMEI: " + String(mySARA.getIMEI())); + Serial.println("IMSI: " + String(mySARA.getIMSI())); + Serial.println("SIM CCID: " + String(mySARA.getCCID())); + Serial.println("Subscriber No.: " + String(mySARA.getSubscriberNo())); + Serial.println("Capabilities: " + String(mySARA.getCapabilities())); + + // Set a callback to return the SIM state once requested + mySARA.setSIMstateReportCallback(&processSIMstate); + // Now enable SIM state reporting for states 0 to 6 (by setting the reporting mode LSb) + if (mySARA.setSIMstateReportingMode(1) == SARA_R5_SUCCESS) + Serial.println("SIM state reports requested..."); + // You can disable the SIM staus reports again by calling assetTracker.setSIMstateReportingMode(0) +} + +void loop() +{ + mySARA.poll(); // Keep processing data from the SARA so we can extract the SIM status +} From a43adb7cb73cb9ba6ade94f2e355d3160a25ccd0 Mon Sep 17 00:00:00 2001 From: PaulZC Date: Wed, 29 Dec 2021 13:31:19 +0000 Subject: [PATCH 11/11] Correct compiler warnings on the ESP8266 --- src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp index 2293791..f76ac2c 100644 --- a/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp +++ b/src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp @@ -1037,7 +1037,7 @@ SARA_R5_error_t SARA_R5::setUtimeConfiguration(int32_t offsetNanoseconds, int32_ command = sara_r5_calloc_char(strlen(SARA_R5_GNSS_TIME_CONFIGURATION) + 48); if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; -#ifdef ARDUINO_ARCH_ESP32 +#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) sprintf(command, "%s=%d,%d", SARA_R5_GNSS_TIME_CONFIGURATION, offsetNanoseconds, offsetSeconds); #else sprintf(command, "%s=%ld,%ld", SARA_R5_GNSS_TIME_CONFIGURATION, offsetNanoseconds, offsetSeconds); @@ -1076,7 +1076,7 @@ SARA_R5_error_t SARA_R5::getUtimeConfiguration(int32_t *offsetNanoseconds, int32 // Response format: \r\n+UTIMECFG: ,\r\n\r\nOK\r\n if (err == SARA_R5_ERROR_SUCCESS) { -#ifdef ARDUINO_ARCH_ESP32 +#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) int scanned = sscanf(response, "\r\n+UTIMECFG: %d,%d\r\n", &ons, &os); #else int scanned = sscanf(response, "\r\n+UTIMECFG: %ld,%ld\r\n", &ons, &os); @@ -1762,7 +1762,7 @@ SARA_R5_error_t SARA_R5::getPreferredMessageStorage(int *used, int *total, Strin int u; int t; - command = sara_r5_calloc_char(strlen(SARA_R5_PREF_MESSAGE_STORE) + 6); + command = sara_r5_calloc_char(strlen(SARA_R5_PREF_MESSAGE_STORE) + 32); if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; sprintf(command, "%s=\"%s\"", SARA_R5_PREF_MESSAGE_STORE, memory.c_str()); @@ -2806,7 +2806,7 @@ SARA_R5_error_t SARA_R5::setPDPconfiguration(int profile, SARA_R5_pdp_configurat if (profile >= SARA_R5_NUM_PSD_PROFILES) return SARA_R5_ERROR_ERROR; - command = sara_r5_calloc_char(strlen(SARA_R5_MESSAGE_PDP_CONFIG) + 24); + command = sara_r5_calloc_char(strlen(SARA_R5_MESSAGE_PDP_CONFIG) + 64); if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; sprintf(command, "%s=%d,%d,\"%s\"", SARA_R5_MESSAGE_PDP_CONFIG, profile, parameter, @@ -3119,7 +3119,7 @@ SARA_R5_error_t SARA_R5::gpsRequest(unsigned int timeout, uint32_t accuracy, command = sara_r5_calloc_char(strlen(SARA_R5_GNSS_REQUEST_LOCATION) + 24); if (command == NULL) return SARA_R5_ERROR_OUT_OF_MEMORY; -#ifdef ARDUINO_ARCH_ESP32 +#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) sprintf(command, "%s=2,%d,%d,%d,%d", SARA_R5_GNSS_REQUEST_LOCATION, sensor, detailed ? 1 : 0, timeout, accuracy); #else