From 5cb9368ea430837ff7ae321263874ff3d848b41c Mon Sep 17 00:00:00 2001 From: siddacious Date: Wed, 25 Mar 2020 14:21:46 -0700 Subject: [PATCH 01/14] actionified, formatted and doxy'd --- .github/workflows/githubci.yml | 32 + .travis.yml | 10 - Adafruit_FONA.cpp | 1134 ++++++++++++++++-------------- Adafruit_FONA.h | 137 ++-- README.md | 2 +- includes/FONAConfig.h | 1 - includes/FONAExtIncludes.h | 4 - includes/platform/FONAPlatStd.h | 40 +- includes/platform/FONAPlatform.h | 17 +- library.properties | 2 +- 10 files changed, 751 insertions(+), 628 deletions(-) create mode 100644 .github/workflows/githubci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/githubci.yml b/.github/workflows/githubci.yml new file mode 100644 index 0000000..028b973 --- /dev/null +++ b/.github/workflows/githubci.yml @@ -0,0 +1,32 @@ +name: Arduino Library CI + +on: [pull_request, push, repository_dispatch] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/setup-python@v1 + with: + python-version: '3.x' + - uses: actions/checkout@v2 + - uses: actions/checkout@v2 + with: + repository: adafruit/ci-arduino + path: ci + + - name: pre-install + run: bash ci/actions_install.sh + + - name: test platforms + run: python3 ci/build_platform.py main_platforms + + - name: clang + run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r . + + - name: doxygen + env: + GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }} + PRETTYNAME : "Adafruit FONA Arduino Library" + run: bash ci/doxy_gen_and_deploy.sh diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6b62611..0000000 --- a/.travis.yml +++ /dev/null @@ -1,10 +0,0 @@ -language: c -sudo: false -before_install: - - source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/install.sh) -script: - - build_main_platforms -notifications: - email: - on_success: change - on_failure: change diff --git a/Adafruit_FONA.cpp b/Adafruit_FONA.cpp index 9a78181..247e8d0 100644 --- a/Adafruit_FONA.cpp +++ b/Adafruit_FONA.cpp @@ -14,23 +14,22 @@ Written by Limor Fried/Ladyada for Adafruit Industries. BSD license, all text above must be included in any redistribution ****************************************************/ - // next line per http://postwarrior.com/arduino-ethershield-error-prog_char-does-not-name-a-type/ +// next line per +// http://postwarrior.com/arduino-ethershield-error-prog_char-does-not-name-a-type/ #include "Adafruit_FONA.h" #if defined(ESP8266) - // ESP8266 doesn't have the min and max functions natively available like - // AVR libc seems to provide. Include the STL algorithm library to get these. - // Unfortunately algorithm isn't available in AVR libc so this is ESP8266 - // specific (and likely needed for ARM or other platforms, but they lack - // software serial and are currently incompatible with the FONA library). - #include - using namespace std; +// ESP8266 doesn't have the min and max functions natively available like +// AVR libc seems to provide. Include the STL algorithm library to get these. +// Unfortunately algorithm isn't available in AVR libc so this is ESP8266 +// specific (and likely needed for ARM or other platforms, but they lack +// software serial and are currently incompatible with the FONA library). +#include +using namespace std; #endif - -Adafruit_FONA::Adafruit_FONA(int8_t rst) -{ +Adafruit_FONA::Adafruit_FONA(int8_t rst) { _rstpin = rst; apn = F("FONAnet"); @@ -42,9 +41,7 @@ Adafruit_FONA::Adafruit_FONA(int8_t rst) ok_reply = F("OK"); } -uint8_t Adafruit_FONA::type(void) { - return _type; -} +uint8_t Adafruit_FONA::type(void) { return _type; } boolean Adafruit_FONA::begin(Stream &port) { mySerial = &port; @@ -61,14 +58,16 @@ boolean Adafruit_FONA::begin(Stream &port) { int16_t timeout = 7000; while (timeout > 0) { - while (mySerial->available()) mySerial->read(); + while (mySerial->available()) + mySerial->read(); if (sendCheckReply(F("AT"), ok_reply)) break; - while (mySerial->available()) mySerial->read(); + while (mySerial->available()) + mySerial->read(); if (sendCheckReply(F("AT"), F("AT"))) break; delay(500); - timeout-=500; + timeout -= 500; } if (timeout <= 0) { @@ -87,7 +86,7 @@ boolean Adafruit_FONA::begin(Stream &port) { sendCheckReply(F("ATE0"), ok_reply); delay(100); - if (! sendCheckReply(F("ATE0"), ok_reply)) { + if (!sendCheckReply(F("ATE0"), ok_reply)) { return false; } @@ -97,15 +96,14 @@ boolean Adafruit_FONA::begin(Stream &port) { delay(100); flushInput(); - - DEBUG_PRINT(F("\t---> ")); DEBUG_PRINTLN("ATI"); + DEBUG_PRINT(F("\t---> ")); + DEBUG_PRINTLN("ATI"); mySerial->println("ATI"); readline(500, true); - DEBUG_PRINT (F("\t<--- ")); DEBUG_PRINTLN(replybuffer); - - + DEBUG_PRINT(F("\t<--- ")); + DEBUG_PRINTLN(replybuffer); if (prog_char_strstr(replybuffer, (prog_char *)F("SIM808 R14")) != 0) { _type = FONA808_V2; @@ -113,22 +111,25 @@ boolean Adafruit_FONA::begin(Stream &port) { _type = FONA808_V1; } else if (prog_char_strstr(replybuffer, (prog_char *)F("SIM800 R13")) != 0) { _type = FONA800L; - } else if (prog_char_strstr(replybuffer, (prog_char *)F("SIMCOM_SIM5320A")) != 0) { + } else if (prog_char_strstr(replybuffer, (prog_char *)F("SIMCOM_SIM5320A")) != + 0) { _type = FONA3G_A; - } else if (prog_char_strstr(replybuffer, (prog_char *)F("SIMCOM_SIM5320E")) != 0) { + } else if (prog_char_strstr(replybuffer, (prog_char *)F("SIMCOM_SIM5320E")) != + 0) { _type = FONA3G_E; } if (_type == FONA800L) { // determine if L or H - DEBUG_PRINT(F("\t---> ")); DEBUG_PRINTLN("AT+GMM"); + DEBUG_PRINT(F("\t---> ")); + DEBUG_PRINTLN("AT+GMM"); mySerial->println("AT+GMM"); readline(500, true); - DEBUG_PRINT (F("\t<--- ")); DEBUG_PRINTLN(replybuffer); - + DEBUG_PRINT(F("\t<--- ")); + DEBUG_PRINTLN(replybuffer); if (prog_char_strstr(replybuffer, (prog_char *)F("SIM800H")) != 0) { _type = FONA800H; @@ -136,13 +137,14 @@ boolean Adafruit_FONA::begin(Stream &port) { } #if defined(FONA_PREF_SMS_STORAGE) - sendCheckReply(F("AT+CPMS=" FONA_PREF_SMS_STORAGE "," FONA_PREF_SMS_STORAGE "," FONA_PREF_SMS_STORAGE), ok_reply); + sendCheckReply(F("AT+CPMS=" FONA_PREF_SMS_STORAGE "," FONA_PREF_SMS_STORAGE + "," FONA_PREF_SMS_STORAGE), + ok_reply); #endif return true; } - /********* Serial port ********************************************/ boolean Adafruit_FONA::setBaudrate(uint16_t baud) { return sendCheckReply(F("AT+IPREX="), baud, ok_reply); @@ -150,7 +152,8 @@ boolean Adafruit_FONA::setBaudrate(uint16_t baud) { /********* Real Time Clock ********************************************/ -boolean Adafruit_FONA::readRTC(uint8_t *year, uint8_t *month, uint8_t *date, uint8_t *hr, uint8_t *min, uint8_t *sec) { +boolean Adafruit_FONA::readRTC(uint8_t *year, uint8_t *month, uint8_t *date, + uint8_t *hr, uint8_t *min, uint8_t *sec) { uint16_t v; sendParseReply(F("AT+CCLK?"), F("+CCLK: "), &v, '/', 0); *year = v; @@ -159,12 +162,11 @@ boolean Adafruit_FONA::readRTC(uint8_t *year, uint8_t *month, uint8_t *date, uin } boolean Adafruit_FONA::enableRTC(uint8_t i) { - if (! sendCheckReply(F("AT+CLTS="), i, ok_reply)) + if (!sendCheckReply(F("AT+CLTS="), i, ok_reply)) return false; return sendCheckReply(F("AT&W"), ok_reply); } - /********* BATTERY & ADC ********************************************/ /* returns value in mV (uint16_t) */ @@ -176,11 +178,10 @@ boolean Adafruit_FONA::getBattVoltage(uint16_t *v) { boolean Adafruit_FONA_3G::getBattVoltage(uint16_t *v) { float f; boolean b = sendParseReply(F("AT+CBC"), F("+CBC: "), &f, ',', 2); - *v = f*1000; + *v = f * 1000; return b; } - /* returns the percentage charge of battery as reported by sim800 */ boolean Adafruit_FONA::getBattPercent(uint16_t *p) { return sendParseReply(F("AT+CBC"), F("+CBC: "), p, ',', 1); @@ -192,8 +193,7 @@ boolean Adafruit_FONA::getADCVoltage(uint16_t *v) { /********* SIM ***********************************************************/ -uint8_t Adafruit_FONA::unlockSIM(char *pin) -{ +uint8_t Adafruit_FONA::unlockSIM(char *pin) { char sendbuff[14] = "AT+CPIN="; sendbuff[8] = pin[0]; sendbuff[9] = pin[1]; @@ -209,7 +209,7 @@ uint8_t Adafruit_FONA::getSIMCCID(char *ccid) { // up to 28 chars for reply, 20 char total ccid if (replybuffer[0] == '+') { // fona 3g? - strncpy(ccid, replybuffer+8, 20); + strncpy(ccid, replybuffer + 8, 20); } else { // fona 800 or 800 strncpy(ccid, replybuffer, 20); @@ -240,16 +240,17 @@ uint8_t Adafruit_FONA::getIMEI(char *imei) { uint8_t Adafruit_FONA::getNetworkStatus(void) { uint16_t status; - if (! sendParseReply(F("AT+CREG?"), F("+CREG: "), &status, ',', 1)) return 0; + if (!sendParseReply(F("AT+CREG?"), F("+CREG: "), &status, ',', 1)) + return 0; return status; } - uint8_t Adafruit_FONA::getRSSI(void) { uint16_t reply; - if (! sendParseReply(F("AT+CSQ"), F("+CSQ: "), &reply) ) return 0; + if (!sendParseReply(F("AT+CSQ"), F("+CSQ: "), &reply)) + return 0; return reply; } @@ -258,7 +259,8 @@ uint8_t Adafruit_FONA::getRSSI(void) { boolean Adafruit_FONA::setAudio(uint8_t a) { // 0 is headset, 1 is external audio - if (a > 1) return false; + if (a > 1) + return false; return sendCheckReply(F("AT+CHFA="), a, ok_reply); } @@ -266,7 +268,8 @@ boolean Adafruit_FONA::setAudio(uint8_t a) { uint8_t Adafruit_FONA::getVolume(void) { uint16_t reply; - if (! sendParseReply(F("AT+CLVL?"), F("+CLVL: "), &reply) ) return 0; + if (!sendParseReply(F("AT+CLVL?"), F("+CLVL: "), &reply)) + return 0; return reply; } @@ -275,7 +278,6 @@ boolean Adafruit_FONA::setVolume(uint8_t i) { return sendCheckReply(F("AT+CLVL="), i, ok_reply); } - boolean Adafruit_FONA::playDTMF(char dtmf) { char str[4]; str[0] = '\"'; @@ -290,7 +292,7 @@ boolean Adafruit_FONA::playToolkitTone(uint8_t t, uint16_t len) { } boolean Adafruit_FONA_3G::playToolkitTone(uint8_t t, uint16_t len) { - if (! sendCheckReply(F("AT+CPTONE="), t, ok_reply)) + if (!sendCheckReply(F("AT+CPTONE="), t, ok_reply)) return false; delay(len); return sendCheckReply(F("AT+CPTONE=0"), ok_reply); @@ -298,21 +300,22 @@ boolean Adafruit_FONA_3G::playToolkitTone(uint8_t t, uint16_t len) { boolean Adafruit_FONA::setMicVolume(uint8_t a, uint8_t level) { // 0 is headset, 1 is external audio - if (a > 1) return false; + if (a > 1) + return false; return sendCheckReply(F("AT+CMIC="), a, level, ok_reply); } /********* FM RADIO *******************************************************/ - boolean Adafruit_FONA::FMradio(boolean onoff, uint8_t a) { - if (! onoff) { + if (!onoff) { return sendCheckReply(F("AT+FMCLOSE"), ok_reply); } // 0 is headset, 1 is external audio - if (a > 1) return false; + if (a > 1) + return false; return sendCheckReply(F("AT+FMOPEN="), a, ok_reply); } @@ -337,7 +340,8 @@ boolean Adafruit_FONA::setFMVolume(uint8_t i) { int8_t Adafruit_FONA::getFMVolume() { uint16_t level; - if (! sendParseReply(F("AT+FMVOLUME?"), F("+FMVOLUME: "), &level) ) return 0; + if (!sendParseReply(F("AT+FMVOLUME?"), F("+FMVOLUME: "), &level)) + return 0; return level; } @@ -353,23 +357,27 @@ int8_t Adafruit_FONA::getFMSignalLevel(uint16_t station) { getReply(F("AT+FMSIGNAL="), station, FONA_DEFAULT_TIMEOUT_MS); // Check response starts with expected value. char *p = prog_char_strstr(replybuffer, PSTR("+FMSIGNAL: ")); - if (p == 0) return -1; - p+=11; + if (p == 0) + return -1; + p += 11; // Find second colon to get start of signal quality. p = strchr(p, ':'); - if (p == 0) return -1; - p+=1; + if (p == 0) + return -1; + p += 1; // Parse signal quality. int8_t level = atoi(p); - readline(); // eat the "OK" + readline(); // eat the "OK" return level; } /********* PWM/BUZZER **************************************************/ boolean Adafruit_FONA::setPWM(uint16_t period, uint8_t duty) { - if (period > 2000) return false; - if (duty > 100) return false; + if (period > 2000) + return false; + if (duty > 100) + return false; return sendCheckReply(F("AT+SPWM=0,"), period, duty, ok_reply); } @@ -377,23 +385,22 @@ boolean Adafruit_FONA::setPWM(uint16_t period, uint8_t duty) { /********* CALL PHONES **************************************************/ boolean Adafruit_FONA::callPhone(char *number) { char sendbuff[35] = "ATD"; - strncpy(sendbuff+3, number, min(30, (int)strlen(number))); + strncpy(sendbuff + 3, number, min(30, (int)strlen(number))); uint8_t x = strlen(sendbuff); sendbuff[x] = ';'; - sendbuff[x+1] = 0; - //DEBUG_PRINTLN(sendbuff); + sendbuff[x + 1] = 0; + // DEBUG_PRINTLN(sendbuff); return sendCheckReply(sendbuff, ok_reply); } - uint8_t Adafruit_FONA::getCallStatus(void) { uint16_t phoneStatus; - if (! sendParseReply(F("AT+CPAS"), F("+CPAS: "), &phoneStatus)) + if (!sendParseReply(F("AT+CPAS"), F("+CPAS: "), &phoneStatus)) return FONA_CALL_FAILED; // 1, since 0 is actually a known, good reply - return phoneStatus; // 0 ready, 2 unkown, 3 ringing, 4 call in progress + return phoneStatus; // 0 ready, 2 unkown, 3 ringing, 4 call in progress } boolean Adafruit_FONA::hangUp(void) { @@ -403,7 +410,8 @@ boolean Adafruit_FONA::hangUp(void) { boolean Adafruit_FONA_3G::hangUp(void) { getReply(F("ATH")); - return (prog_char_strstr(replybuffer, (prog_char *)F("VOICE CALL: END")) != 0); + return (prog_char_strstr(replybuffer, (prog_char *)F("VOICE CALL: END")) != + 0); } boolean Adafruit_FONA::pickUp(void) { @@ -414,10 +422,10 @@ boolean Adafruit_FONA_3G::pickUp(void) { return sendCheckReply(F("ATA"), F("VOICE CALL: BEGIN")); } - void Adafruit_FONA::onIncomingCall() { - DEBUG_PRINT(F("> ")); DEBUG_PRINTLN(F("Incoming call...")); + DEBUG_PRINT(F("> ")); + DEBUG_PRINTLN(F("Incoming call...")); Adafruit_FONA::_incomingCall = true; } @@ -425,7 +433,7 @@ void Adafruit_FONA::onIncomingCall() { boolean Adafruit_FONA::_incomingCall = false; boolean Adafruit_FONA::callerIdNotification(boolean enable, uint8_t interrupt) { - if(enable){ + if (enable) { attachInterrupt(interrupt, onIncomingCall, FALLING); return sendCheckReply(F("AT+CLIP=1"), ok_reply); } @@ -434,26 +442,24 @@ boolean Adafruit_FONA::callerIdNotification(boolean enable, uint8_t interrupt) { return sendCheckReply(F("AT+CLIP=0"), ok_reply); } -boolean Adafruit_FONA::incomingCallNumber(char* phonenum) { +boolean Adafruit_FONA::incomingCallNumber(char *phonenum) { //+CLIP: "",145,"",0,"",0 - if(!Adafruit_FONA::_incomingCall) + if (!Adafruit_FONA::_incomingCall) return false; readline(); - while(!prog_char_strcmp(replybuffer, (prog_char*)F("RING")) == 0) { + while (!prog_char_strcmp(replybuffer, (prog_char *)F("RING")) == 0) { flushInput(); readline(); } - readline(); //reads incoming phone number line + readline(); // reads incoming phone number line parseReply(F("+CLIP: \""), phonenum, '"'); - DEBUG_PRINT(F("Phone Number: ")); DEBUG_PRINTLN(replybuffer); - Adafruit_FONA::_incomingCall = false; return true; } @@ -463,7 +469,8 @@ boolean Adafruit_FONA::incomingCallNumber(char* phonenum) { uint8_t Adafruit_FONA::getSMSInterrupt(void) { uint16_t reply; - if (! sendParseReply(F("AT+CFGRI?"), F("+CFGRI: "), &reply) ) return 0; + if (!sendParseReply(F("AT+CFGRI?"), F("+CFGRI: "), &reply)) + return 0; return reply; } @@ -476,7 +483,8 @@ int8_t Adafruit_FONA::getNumSMS(void) { uint16_t numsms; // get into text mode - if (! sendCheckReply(F("AT+CMGF=1"), ok_reply)) return -1; + if (!sendCheckReply(F("AT+CMGF=1"), ok_reply)) + return -1; // ask how many sms are stored if (sendParseReply(F("AT+CPMS?"), F(FONA_PREF_SMS_STORAGE ","), &numsms)) @@ -488,37 +496,35 @@ int8_t Adafruit_FONA::getNumSMS(void) { return -1; } -// Reading SMS's is a bit involved so we don't use helpers that may cause delays or debug -// printouts! -boolean Adafruit_FONA::readSMS(uint8_t i, char *smsbuff, - uint16_t maxlen, uint16_t *readlen) { +// Reading SMS's is a bit involved so we don't use helpers that may cause delays +// or debug printouts! +boolean Adafruit_FONA::readSMS(uint8_t i, char *smsbuff, uint16_t maxlen, + uint16_t *readlen) { // text mode - if (! sendCheckReply(F("AT+CMGF=1"), ok_reply)) return false; + if (!sendCheckReply(F("AT+CMGF=1"), ok_reply)) + return false; // show all text mode parameters - if (! sendCheckReply(F("AT+CSDH=1"), ok_reply)) return false; + if (!sendCheckReply(F("AT+CSDH=1"), ok_reply)) + return false; // parse out the SMS len uint16_t thesmslen = 0; - DEBUG_PRINT(F("AT+CMGR=")); DEBUG_PRINTLN(i); - - //getReply(F("AT+CMGR="), i, 1000); // do not print debug! + // getReply(F("AT+CMGR="), i, 1000); // do not print debug! mySerial->print(F("AT+CMGR=")); mySerial->println(i); readline(1000); // timeout - //DEBUG_PRINT(F("Reply: ")); DEBUG_PRINTLN(replybuffer); + // DEBUG_PRINT(F("Reply: ")); DEBUG_PRINTLN(replybuffer); // parse it out... - DEBUG_PRINTLN(replybuffer); - - if (! parseReply(F("+CMGR:"), &thesmslen, ',', 11)) { + if (!parseReply(F("+CMGR:"), &thesmslen, ',', 11)) { *readlen = 0; return false; } @@ -531,7 +537,6 @@ boolean Adafruit_FONA::readSMS(uint8_t i, char *smsbuff, strncpy(smsbuff, replybuffer, thelen); smsbuff[thelen] = 0; // end the string - DEBUG_PRINTLN(replybuffer); *readlen = thelen; @@ -545,23 +550,21 @@ boolean Adafruit_FONA::readSMS(uint8_t i, char *smsbuff, // otherwise false. boolean Adafruit_FONA::getSMSSender(uint8_t i, char *sender, int senderlen) { // Ensure text mode and all text mode parameters are sent. - if (! sendCheckReply(F("AT+CMGF=1"), ok_reply)) return false; - if (! sendCheckReply(F("AT+CSDH=1"), ok_reply)) return false; - + if (!sendCheckReply(F("AT+CMGF=1"), ok_reply)) + return false; + if (!sendCheckReply(F("AT+CSDH=1"), ok_reply)) + return false; DEBUG_PRINT(F("AT+CMGR=")); DEBUG_PRINTLN(i); - // Send command to retrieve SMS message and parse a line of response. mySerial->print(F("AT+CMGR=")); mySerial->println(i); readline(1000); - DEBUG_PRINTLN(replybuffer); - // Parse the second field in the response. boolean result = parseReplyQuoted(F("+CMGR:"), sender, senderlen, ',', 1); // Drop any remaining data from the response. @@ -570,15 +573,19 @@ boolean Adafruit_FONA::getSMSSender(uint8_t i, char *sender, int senderlen) { } boolean Adafruit_FONA::sendSMS(char *smsaddr, char *smsmsg) { - if (! sendCheckReply(F("AT+CMGF=1"), ok_reply)) return false; + if (!sendCheckReply(F("AT+CMGF=1"), ok_reply)) + return false; char sendcmd[30] = "AT+CMGS=\""; - strncpy(sendcmd+9, smsaddr, 30-9-2); // 9 bytes beginning, 2 bytes for close quote + null + strncpy(sendcmd + 9, smsaddr, + 30 - 9 - 2); // 9 bytes beginning, 2 bytes for close quote + null sendcmd[strlen(sendcmd)] = '\"'; - if (! sendCheckReply(sendcmd, F("> "))) return false; + if (!sendCheckReply(sendcmd, F("> "))) + return false; - DEBUG_PRINT(F("> ")); DEBUG_PRINTLN(smsmsg); + DEBUG_PRINT(F("> ")); + DEBUG_PRINTLN(smsmsg); mySerial->println(smsmsg); mySerial->println(); @@ -586,20 +593,20 @@ boolean Adafruit_FONA::sendSMS(char *smsaddr, char *smsmsg) { DEBUG_PRINTLN("^Z"); - if ( (_type == FONA3G_A) || (_type == FONA3G_E) ) { + if ((_type == FONA3G_A) || (_type == FONA3G_E)) { // Eat two sets of CRLF readline(200); - //DEBUG_PRINT("Line 1: "); DEBUG_PRINTLN(strlen(replybuffer)); + // DEBUG_PRINT("Line 1: "); DEBUG_PRINTLN(strlen(replybuffer)); readline(200); - //DEBUG_PRINT("Line 2: "); DEBUG_PRINTLN(strlen(replybuffer)); + // DEBUG_PRINT("Line 2: "); DEBUG_PRINTLN(strlen(replybuffer)); } readline(10000); // read the +CMGS reply, wait up to 10 seconds!!! - //DEBUG_PRINT("Line 3: "); DEBUG_PRINTLN(strlen(replybuffer)); + // DEBUG_PRINT("Line 3: "); DEBUG_PRINTLN(strlen(replybuffer)); if (strstr(replybuffer, "+CMGS") == 0) { return false; } readline(1000); // read OK - //DEBUG_PRINT("* "); DEBUG_PRINTLN(replybuffer); + // DEBUG_PRINT("* "); DEBUG_PRINTLN(replybuffer); if (strcmp(replybuffer, "OK") != 0) { return false; @@ -608,9 +615,9 @@ boolean Adafruit_FONA::sendSMS(char *smsaddr, char *smsmsg) { return true; } - boolean Adafruit_FONA::deleteSMS(uint8_t i) { - if (! sendCheckReply(F("AT+CMGF=1"), ok_reply)) return false; + if (!sendCheckReply(F("AT+CMGF=1"), ok_reply)) + return false; // read an sms char sendbuff[12] = "AT+CMGD=000"; sendbuff[8] = (i / 100) + '0'; @@ -624,52 +631,54 @@ boolean Adafruit_FONA::deleteSMS(uint8_t i) { /********* USSD *********************************************************/ -boolean Adafruit_FONA::sendUSSD(char *ussdmsg, char *ussdbuff, uint16_t maxlen, uint16_t *readlen) { - if (! sendCheckReply(F("AT+CUSD=1"), ok_reply)) return false; +boolean Adafruit_FONA::sendUSSD(char *ussdmsg, char *ussdbuff, uint16_t maxlen, + uint16_t *readlen) { + if (!sendCheckReply(F("AT+CUSD=1"), ok_reply)) + return false; char sendcmd[30] = "AT+CUSD=1,\""; - strncpy(sendcmd+11, ussdmsg, 30-11-2); // 11 bytes beginning, 2 bytes for close quote + null + strncpy(sendcmd + 11, ussdmsg, + 30 - 11 - 2); // 11 bytes beginning, 2 bytes for close quote + null sendcmd[strlen(sendcmd)] = '\"'; - if (! sendCheckReply(sendcmd, ok_reply)) { + if (!sendCheckReply(sendcmd, ok_reply)) { *readlen = 0; return false; } else { - readline(10000); // read the +CUSD reply, wait up to 10 seconds!!! - //DEBUG_PRINT("* "); DEBUG_PRINTLN(replybuffer); - char *p = prog_char_strstr(replybuffer, PSTR("+CUSD: ")); - if (p == 0) { - *readlen = 0; - return false; - } - p+=7; //+CUSD - // Find " to get start of ussd message. - p = strchr(p, '\"'); - if (p == 0) { - *readlen = 0; - return false; - } - p+=1; //" - // Find " to get end of ussd message. - char *strend = strchr(p, '\"'); - - uint16_t lentocopy = min(maxlen-1, strend - p); - strncpy(ussdbuff, p, lentocopy+1); - ussdbuff[lentocopy] = 0; - *readlen = lentocopy; + readline(10000); // read the +CUSD reply, wait up to 10 seconds!!! + // DEBUG_PRINT("* "); DEBUG_PRINTLN(replybuffer); + char *p = prog_char_strstr(replybuffer, PSTR("+CUSD: ")); + if (p == 0) { + *readlen = 0; + return false; + } + p += 7; //+CUSD + // Find " to get start of ussd message. + p = strchr(p, '\"'); + if (p == 0) { + *readlen = 0; + return false; + } + p += 1; //" + // Find " to get end of ussd message. + char *strend = strchr(p, '\"'); + + uint16_t lentocopy = min(maxlen - 1, strend - p); + strncpy(ussdbuff, p, lentocopy + 1); + ussdbuff[lentocopy] = 0; + *readlen = lentocopy; } return true; } - /********* TIME **********************************************************/ boolean Adafruit_FONA::enableNetworkTimeSync(boolean onoff) { if (onoff) { - if (! sendCheckReply(F("AT+CLTS=1"), ok_reply)) + if (!sendCheckReply(F("AT+CLTS=1"), ok_reply)) return false; } else { - if (! sendCheckReply(F("AT+CLTS=0"), ok_reply)) + if (!sendCheckReply(F("AT+CLTS=0"), ok_reply)) return false; } @@ -678,9 +687,10 @@ boolean Adafruit_FONA::enableNetworkTimeSync(boolean onoff) { return true; } -boolean Adafruit_FONA::enableNTPTimeSync(boolean onoff, FONAFlashStringPtr ntpserver) { +boolean Adafruit_FONA::enableNTPTimeSync(boolean onoff, + FONAFlashStringPtr ntpserver) { if (onoff) { - if (! sendCheckReply(F("AT+CNTPCID=1"), ok_reply)) + if (!sendCheckReply(F("AT+CNTPCID=1"), ok_reply)) return false; mySerial->print(F("AT+CNTP=\"")); @@ -694,15 +704,15 @@ boolean Adafruit_FONA::enableNTPTimeSync(boolean onoff, FONAFlashStringPtr ntpse if (strcmp(replybuffer, "OK") != 0) return false; - if (! sendCheckReply(F("AT+CNTP"), ok_reply, 10000)) + if (!sendCheckReply(F("AT+CNTP"), ok_reply, 10000)) return false; uint16_t status; readline(10000); - if (! parseReply(F("+CNTP:"), &status)) + if (!parseReply(F("+CNTP:"), &status)) return false; } else { - if (! sendCheckReply(F("AT+CNTPCID=0"), ok_reply)) + if (!sendCheckReply(F("AT+CNTPCID=0"), ok_reply)) return false; } @@ -710,13 +720,13 @@ boolean Adafruit_FONA::enableNTPTimeSync(boolean onoff, FONAFlashStringPtr ntpse } boolean Adafruit_FONA::getTime(char *buff, uint16_t maxlen) { - getReply(F("AT+CCLK?"), (uint16_t) 10000); + getReply(F("AT+CCLK?"), (uint16_t)10000); if (strncmp(replybuffer, "+CCLK: ", 7) != 0) return false; - char *p = replybuffer+7; - uint16_t lentocopy = min(maxlen-1, (int)strlen(p)); - strncpy(buff, p, lentocopy+1); + char *p = replybuffer + 7; + uint16_t lentocopy = min(maxlen - 1, (int)strlen(p)); + strncpy(buff, p, lentocopy + 1); buff[lentocopy] = 0; readline(); // eat OK @@ -726,54 +736,51 @@ boolean Adafruit_FONA::getTime(char *buff, uint16_t maxlen) { /********* GPS **********************************************************/ - boolean Adafruit_FONA::enableGPS(boolean onoff) { uint16_t state; // first check if its already on or off if (_type == FONA808_V2) { - if (! sendParseReply(F("AT+CGNSPWR?"), F("+CGNSPWR: "), &state) ) + if (!sendParseReply(F("AT+CGNSPWR?"), F("+CGNSPWR: "), &state)) return false; } else { - if (! sendParseReply(F("AT+CGPSPWR?"), F("+CGPSPWR: "), &state)) + if (!sendParseReply(F("AT+CGPSPWR?"), F("+CGPSPWR: "), &state)) return false; } if (onoff && !state) { if (_type == FONA808_V2) { - if (! sendCheckReply(F("AT+CGNSPWR=1"), ok_reply)) // try GNS command - return false; + if (!sendCheckReply(F("AT+CGNSPWR=1"), ok_reply)) // try GNS command + return false; } else { - if (! sendCheckReply(F("AT+CGPSPWR=1"), ok_reply)) - return false; + if (!sendCheckReply(F("AT+CGPSPWR=1"), ok_reply)) + return false; } } else if (!onoff && state) { if (_type == FONA808_V2) { - if (! sendCheckReply(F("AT+CGNSPWR=0"), ok_reply)) // try GNS command - return false; + if (!sendCheckReply(F("AT+CGNSPWR=0"), ok_reply)) // try GNS command + return false; } else { - if (! sendCheckReply(F("AT+CGPSPWR=0"), ok_reply)) - return false; + if (!sendCheckReply(F("AT+CGPSPWR=0"), ok_reply)) + return false; } } return true; } - - boolean Adafruit_FONA_3G::enableGPS(boolean onoff) { uint16_t state; // first check if its already on or off - if (! Adafruit_FONA::sendParseReply(F("AT+CGPS?"), F("+CGPS: "), &state) ) + if (!Adafruit_FONA::sendParseReply(F("AT+CGPS?"), F("+CGPS: "), &state)) return false; if (onoff && !state) { - if (! sendCheckReply(F("AT+CGPS=1"), ok_reply)) + if (!sendCheckReply(F("AT+CGPS=1"), ok_reply)) return false; } else if (!onoff && state) { - if (! sendCheckReply(F("AT+CGPS=0"), ok_reply)) + if (!sendCheckReply(F("AT+CGPS=0"), ok_reply)) return false; // this takes a little time readline(2000); // eat '+CGPS: 0' @@ -786,39 +793,50 @@ int8_t Adafruit_FONA::GPSstatus(void) { // 808 V2 uses GNS commands and doesn't have an explicit 2D/3D fix status. // Instead just look for a fix and if found assume it's a 3D fix. getReply(F("AT+CGNSINF")); - char *p = prog_char_strstr(replybuffer, (prog_char*)F("+CGNSINF: ")); - if (p == 0) return -1; - p+=10; + char *p = prog_char_strstr(replybuffer, (prog_char *)F("+CGNSINF: ")); + if (p == 0) + return -1; + p += 10; readline(); // eat 'OK' - if (p[0] == '0') return 0; // GPS is not even on! + if (p[0] == '0') + return 0; // GPS is not even on! - p+=2; // Skip to second value, fix status. - //DEBUG_PRINTLN(p); + p += 2; // Skip to second value, fix status. + // DEBUG_PRINTLN(p); // Assume if the fix status is '1' then we have a 3D fix, otherwise no fix. - if (p[0] == '1') return 3; - else return 1; + if (p[0] == '1') + return 3; + else + return 1; } if (_type == FONA3G_A || _type == FONA3G_E) { // FONA 3G doesn't have an explicit 2D/3D fix status. // Instead just look for a fix and if found assume it's a 3D fix. getReply(F("AT+CGPSINFO")); - char *p = prog_char_strstr(replybuffer, (prog_char*)F("+CGPSINFO:")); - if (p == 0) return -1; - if (p[10] != ',') return 3; // if you get anything, its 3D fix + char *p = prog_char_strstr(replybuffer, (prog_char *)F("+CGPSINFO:")); + if (p == 0) + return -1; + if (p[10] != ',') + return 3; // if you get anything, its 3D fix return 0; - } - else { + } else { // 808 V1 looks for specific 2D or 3D fix state. getReply(F("AT+CGPSSTATUS?")); - char *p = prog_char_strstr(replybuffer, (prog_char*)F("SSTATUS: Location ")); - if (p == 0) return -1; - p+=18; + char *p = + prog_char_strstr(replybuffer, (prog_char *)F("SSTATUS: Location ")); + if (p == 0) + return -1; + p += 18; readline(); // eat 'OK' - //DEBUG_PRINTLN(p); - if (p[0] == 'U') return 0; - if (p[0] == 'N') return 1; - if (p[0] == '2') return 2; - if (p[0] == '3') return 3; + // DEBUG_PRINTLN(p); + if (p[0] == 'U') + return 0; + if (p[0] == 'N') + return 1; + if (p[0] == '2') + return 2; + if (p[0] == '3') + return 3; } // else return 0; @@ -827,7 +845,7 @@ int8_t Adafruit_FONA::GPSstatus(void) { uint8_t Adafruit_FONA::getGPS(uint8_t arg, char *buffer, uint8_t maxbuff) { int32_t x = arg; - if ( (_type == FONA3G_A) || (_type == FONA3G_E) ) { + if ((_type == FONA3G_A) || (_type == FONA3G_E)) { getReply(F("AT+CGPSINFO")); } else if (_type == FONA808_V1) { getReply(F("AT+CGPSINF="), x); @@ -835,15 +853,15 @@ uint8_t Adafruit_FONA::getGPS(uint8_t arg, char *buffer, uint8_t maxbuff) { getReply(F("AT+CGNSINF")); } - char *p = prog_char_strstr(replybuffer, (prog_char*)F("SINF")); + char *p = prog_char_strstr(replybuffer, (prog_char *)F("SINF")); if (p == 0) { buffer[0] = 0; return 0; } - p+=6; + p += 6; - uint8_t len = max(maxbuff-1, (int)strlen(p)); + uint8_t len = max(maxbuff - 1, (int)strlen(p)); strncpy(buffer, p, len); buffer[len] = 0; @@ -851,7 +869,8 @@ uint8_t Adafruit_FONA::getGPS(uint8_t arg, char *buffer, uint8_t maxbuff) { return len; } -boolean Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, float *heading, float *altitude) { +boolean Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, + float *heading, float *altitude) { char gpsbuffer[120]; @@ -872,31 +891,36 @@ boolean Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, float *h // skip beginning char *tok; - // grab the latitude + // grab the latitude char *latp = strtok(gpsbuffer, ","); - if (! latp) return false; + if (!latp) + return false; // grab latitude direction char *latdir = strtok(NULL, ","); - if (! latdir) return false; + if (!latdir) + return false; // grab longitude char *longp = strtok(NULL, ","); - if (! longp) return false; + if (!longp) + return false; // grab longitude direction char *longdir = strtok(NULL, ","); - if (! longdir) return false; + if (!longdir) + return false; // skip date & time tok = strtok(NULL, ","); tok = strtok(NULL, ","); - // only grab altitude if needed + // only grab altitude if needed if (altitude != NULL) { // grab altitude char *altp = strtok(NULL, ","); - if (! altp) return false; + if (!altp) + return false; *altitude = atof(altp); } @@ -904,7 +928,8 @@ boolean Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, float *h if (speed_kph != NULL) { // grab the speed in km/h char *speedp = strtok(NULL, ","); - if (! speedp) return false; + if (!speedp) + return false; *speed_kph = atof(speedp); } @@ -914,7 +939,8 @@ boolean Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, float *h // grab the speed in knots char *coursep = strtok(NULL, ","); - if (! coursep) return false; + if (!coursep) + return false; *heading = atof(coursep); } @@ -929,7 +955,8 @@ boolean Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, float *h degrees += minutes; // turn direction into + or - - if (latdir[0] == 'S') degrees *= -1; + if (latdir[0] == 'S') + degrees *= -1; *lat = degrees; @@ -940,7 +967,8 @@ boolean Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, float *h degrees += minutes; // turn direction into + or - - if (longdir[0] == 'W') degrees *= -1; + if (longdir[0] == 'W') + degrees *= -1; *lon = degrees; @@ -950,23 +978,28 @@ boolean Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, float *h // skip GPS run status char *tok = strtok(gpsbuffer, ","); - if (! tok) return false; + if (!tok) + return false; // skip fix status tok = strtok(NULL, ","); - if (! tok) return false; + if (!tok) + return false; // skip date tok = strtok(NULL, ","); - if (! tok) return false; + if (!tok) + return false; // grab the latitude char *latp = strtok(NULL, ","); - if (! latp) return false; + if (!latp) + return false; // grab longitude char *longp = strtok(NULL, ","); - if (! longp) return false; + if (!longp) + return false; *lat = atof(latp); *lon = atof(longp); @@ -975,7 +1008,8 @@ boolean Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, float *h if (altitude != NULL) { // grab altitude char *altp = strtok(NULL, ","); - if (! altp) return false; + if (!altp) + return false; *altitude = atof(altp); } @@ -984,7 +1018,8 @@ boolean Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, float *h if (speed_kph != NULL) { // grab the speed in km/h char *speedp = strtok(NULL, ","); - if (! speedp) return false; + if (!speedp) + return false; *speed_kph = atof(speedp); } @@ -994,41 +1029,48 @@ boolean Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, float *h // grab the speed in knots char *coursep = strtok(NULL, ","); - if (! coursep) return false; + if (!coursep) + return false; *heading = atof(coursep); } - } - else { + } else { // Parse 808 V1 response. // skip mode char *tok = strtok(gpsbuffer, ","); - if (! tok) return false; + if (!tok) + return false; // skip date tok = strtok(NULL, ","); - if (! tok) return false; + if (!tok) + return false; // skip fix tok = strtok(NULL, ","); - if (! tok) return false; + if (!tok) + return false; // grab the latitude char *latp = strtok(NULL, ","); - if (! latp) return false; + if (!latp) + return false; // grab latitude direction char *latdir = strtok(NULL, ","); - if (! latdir) return false; + if (!latdir) + return false; // grab longitude char *longp = strtok(NULL, ","); - if (! longp) return false; + if (!longp) + return false; // grab longitude direction char *longdir = strtok(NULL, ","); - if (! longdir) return false; + if (!longdir) + return false; double latitude = atof(latp); double longitude = atof(longp); @@ -1040,7 +1082,8 @@ boolean Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, float *h degrees += minutes; // turn direction into + or - - if (latdir[0] == 'S') degrees *= -1; + if (latdir[0] == 'S') + degrees *= -1; *lat = degrees; @@ -1051,7 +1094,8 @@ boolean Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, float *h degrees += minutes; // turn direction into + or - - if (longdir[0] == 'W') degrees *= -1; + if (longdir[0] == 'W') + degrees *= -1; *lon = degrees; @@ -1060,11 +1104,11 @@ boolean Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, float *h // grab the speed in knots char *speedp = strtok(NULL, ","); - if (! speedp) return false; + if (!speedp) + return false; // convert to kph *speed_kph = atof(speedp) * 1.852; - } // only grab heading if needed @@ -1072,10 +1116,10 @@ boolean Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, float *h // grab the speed in knots char *coursep = strtok(NULL, ","); - if (! coursep) return false; + if (!coursep) + return false; *heading = atof(coursep); - } // no need to continue @@ -1095,25 +1139,28 @@ boolean Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, float *h // skip mode tok = strtok(gpsbuffer, ","); - if (! tok) return false; + if (!tok) + return false; // skip lat tok = strtok(NULL, ","); - if (! tok) return false; + if (!tok) + return false; // skip long tok = strtok(NULL, ","); - if (! tok) return false; + if (!tok) + return false; // grab altitude char *altp = strtok(NULL, ","); - if (! altp) return false; + if (!altp) + return false; *altitude = atof(altp); } return true; - } boolean Adafruit_FONA::enableGPSNMEA(uint8_t i) { @@ -1135,28 +1182,28 @@ boolean Adafruit_FONA::enableGPSNMEA(uint8_t i) { } } - /********* GPRS **********************************************************/ - boolean Adafruit_FONA::enableGPRS(boolean onoff) { if (onoff) { // disconnect all sockets sendCheckReply(F("AT+CIPSHUT"), F("SHUT OK"), 20000); - if (! sendCheckReply(F("AT+CGATT=1"), ok_reply, 10000)) + if (!sendCheckReply(F("AT+CGATT=1"), ok_reply, 10000)) return false; // set bearer profile! connection type GPRS - if (! sendCheckReply(F("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\""), - ok_reply, 10000)) + if (!sendCheckReply(F("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\""), ok_reply, + 10000)) return false; // set bearer profile access point name if (apn) { - // Send command AT+SAPBR=3,1,"APN","" where is the configured APN value. - if (! sendCheckReplyQuoted(F("AT+SAPBR=3,1,\"APN\","), apn, ok_reply, 10000)) + // Send command AT+SAPBR=3,1,"APN","" where is the + // configured APN value. + if (!sendCheckReplyQuoted(F("AT+SAPBR=3,1,\"APN\","), apn, ok_reply, + 10000)) return false; // send AT+CSTT,"apn","user","pass" @@ -1165,63 +1212,68 @@ boolean Adafruit_FONA::enableGPRS(boolean onoff) { mySerial->print(F("AT+CSTT=\"")); mySerial->print(apn); if (apnusername) { - mySerial->print("\",\""); - mySerial->print(apnusername); + mySerial->print("\",\""); + mySerial->print(apnusername); } if (apnpassword) { - mySerial->print("\",\""); - mySerial->print(apnpassword); + mySerial->print("\",\""); + mySerial->print(apnpassword); } mySerial->println("\""); - DEBUG_PRINT(F("\t---> ")); DEBUG_PRINT(F("AT+CSTT=\"")); + DEBUG_PRINT(F("\t---> ")); + DEBUG_PRINT(F("AT+CSTT=\"")); DEBUG_PRINT(apn); if (apnusername) { - DEBUG_PRINT("\",\""); - DEBUG_PRINT(apnusername); + DEBUG_PRINT("\",\""); + DEBUG_PRINT(apnusername); } if (apnpassword) { - DEBUG_PRINT("\",\""); - DEBUG_PRINT(apnpassword); + DEBUG_PRINT("\",\""); + DEBUG_PRINT(apnpassword); } DEBUG_PRINTLN("\""); - if (! expectReply(ok_reply)) return false; + if (!expectReply(ok_reply)) + return false; // set username/password if (apnusername) { - // Send command AT+SAPBR=3,1,"USER","" where is the configured APN username. - if (! sendCheckReplyQuoted(F("AT+SAPBR=3,1,\"USER\","), apnusername, ok_reply, 10000)) + // Send command AT+SAPBR=3,1,"USER","" where is the + // configured APN username. + if (!sendCheckReplyQuoted(F("AT+SAPBR=3,1,\"USER\","), apnusername, + ok_reply, 10000)) return false; } if (apnpassword) { - // Send command AT+SAPBR=3,1,"PWD","" where is the configured APN password. - if (! sendCheckReplyQuoted(F("AT+SAPBR=3,1,\"PWD\","), apnpassword, ok_reply, 10000)) + // Send command AT+SAPBR=3,1,"PWD","" where is the + // configured APN password. + if (!sendCheckReplyQuoted(F("AT+SAPBR=3,1,\"PWD\","), apnpassword, + ok_reply, 10000)) return false; } } // open GPRS context - if (! sendCheckReply(F("AT+SAPBR=1,1"), ok_reply, 30000)) + if (!sendCheckReply(F("AT+SAPBR=1,1"), ok_reply, 30000)) return false; // bring up wireless connection - if (! sendCheckReply(F("AT+CIICR"), ok_reply, 10000)) + if (!sendCheckReply(F("AT+CIICR"), ok_reply, 10000)) return false; } else { // disconnect all sockets - if (! sendCheckReply(F("AT+CIPSHUT"), F("SHUT OK"), 20000)) + if (!sendCheckReply(F("AT+CIPSHUT"), F("SHUT OK"), 20000)) return false; // close GPRS context - if (! sendCheckReply(F("AT+SAPBR=0,1"), ok_reply, 10000)) + if (!sendCheckReply(F("AT+SAPBR=0,1"), ok_reply, 10000)) return false; - if (! sendCheckReply(F("AT+CGATT=0"), ok_reply, 10000)) + if (!sendCheckReply(F("AT+CGATT=0"), ok_reply, 10000)) return false; - } return true; } @@ -1230,54 +1282,57 @@ boolean Adafruit_FONA_3G::enableGPRS(boolean onoff) { if (onoff) { // disconnect all sockets - //sendCheckReply(F("AT+CIPSHUT"), F("SHUT OK"), 5000); + // sendCheckReply(F("AT+CIPSHUT"), F("SHUT OK"), 5000); - if (! sendCheckReply(F("AT+CGATT=1"), ok_reply, 10000)) + if (!sendCheckReply(F("AT+CGATT=1"), ok_reply, 10000)) return false; - // set bearer profile access point name if (apn) { - // Send command AT+CGSOCKCONT=1,"IP","" where is the configured APN name. - if (! sendCheckReplyQuoted(F("AT+CGSOCKCONT=1,\"IP\","), apn, ok_reply, 10000)) + // Send command AT+CGSOCKCONT=1,"IP","" where is + // the configured APN name. + if (!sendCheckReplyQuoted(F("AT+CGSOCKCONT=1,\"IP\","), apn, ok_reply, + 10000)) return false; // set username/password if (apnusername) { - char authstring[100] = "AT+CGAUTH=1,1,\""; - char *strp = authstring + strlen(authstring); - prog_char_strcpy(strp, (prog_char *)apnusername); - strp+=prog_char_strlen((prog_char *)apnusername); - strp[0] = '\"'; - strp++; - strp[0] = 0; - - if (apnpassword) { - strp[0] = ','; strp++; - strp[0] = '\"'; strp++; - prog_char_strcpy(strp, (prog_char *)apnpassword); - strp+=prog_char_strlen((prog_char *)apnpassword); - strp[0] = '\"'; - strp++; - strp[0] = 0; - } - - if (! sendCheckReply(authstring, ok_reply, 10000)) - return false; + char authstring[100] = "AT+CGAUTH=1,1,\""; + char *strp = authstring + strlen(authstring); + prog_char_strcpy(strp, (prog_char *)apnusername); + strp += prog_char_strlen((prog_char *)apnusername); + strp[0] = '\"'; + strp++; + strp[0] = 0; + + if (apnpassword) { + strp[0] = ','; + strp++; + strp[0] = '\"'; + strp++; + prog_char_strcpy(strp, (prog_char *)apnpassword); + strp += prog_char_strlen((prog_char *)apnpassword); + strp[0] = '\"'; + strp++; + strp[0] = 0; + } + + if (!sendCheckReply(authstring, ok_reply, 10000)) + return false; } } // connect in transparent - if (! sendCheckReply(F("AT+CIPMODE=1"), ok_reply, 10000)) + if (!sendCheckReply(F("AT+CIPMODE=1"), ok_reply, 10000)) return false; // open network (?) - if (! sendCheckReply(F("AT+NETOPEN=,,1"), F("Network opened"), 10000)) + if (!sendCheckReply(F("AT+NETOPEN=,,1"), F("Network opened"), 10000)) return false; readline(); // eat 'OK' } else { // close GPRS context - if (! sendCheckReply(F("AT+NETCLOSE"), F("Network closed"), 10000)) + if (!sendCheckReply(F("AT+NETCLOSE"), F("Network closed"), 10000)) return false; readline(); // eat 'OK' @@ -1289,29 +1344,31 @@ boolean Adafruit_FONA_3G::enableGPRS(boolean onoff) { uint8_t Adafruit_FONA::GPRSstate(void) { uint16_t state; - if (! sendParseReply(F("AT+CGATT?"), F("+CGATT: "), &state) ) + if (!sendParseReply(F("AT+CGATT?"), F("+CGATT: "), &state)) return -1; return state; } void Adafruit_FONA::setGPRSNetworkSettings(FONAFlashStringPtr apn, - FONAFlashStringPtr username, FONAFlashStringPtr password) { + FONAFlashStringPtr username, + FONAFlashStringPtr password) { this->apn = apn; this->apnusername = username; this->apnpassword = password; } -boolean Adafruit_FONA::getGSMLoc(uint16_t *errorcode, char *buff, uint16_t maxlen) { +boolean Adafruit_FONA::getGSMLoc(uint16_t *errorcode, char *buff, + uint16_t maxlen) { getReply(F("AT+CIPGSMLOC=1,1"), (uint16_t)10000); - if (! parseReply(F("+CIPGSMLOC: "), errorcode)) + if (!parseReply(F("+CIPGSMLOC: "), errorcode)) return false; - char *p = replybuffer+14; - uint16_t lentocopy = min(maxlen-1, (int)strlen(p)); - strncpy(buff, p, lentocopy+1); + char *p = replybuffer + 14; + uint16_t lentocopy = min(maxlen - 1, (int)strlen(p)); + strncpy(buff, p, lentocopy + 1); readline(); // eat OK @@ -1324,7 +1381,7 @@ boolean Adafruit_FONA::getGSMLoc(float *lat, float *lon) { char gpsbuffer[120]; // make sure we could get a response - if (! getGSMLoc(&returncode, gpsbuffer, 120)) + if (!getGSMLoc(&returncode, gpsbuffer, 120)) return false; // make sure we have a valid return code @@ -1334,32 +1391,34 @@ boolean Adafruit_FONA::getGSMLoc(float *lat, float *lon) { // +CIPGSMLOC: 0,-74.007729,40.730160,2015/10/15,19:24:55 // tokenize the gps buffer to locate the lat & long char *longp = strtok(gpsbuffer, ","); - if (! longp) return false; + if (!longp) + return false; char *latp = strtok(NULL, ","); - if (! latp) return false; + if (!latp) + return false; *lat = atof(latp); *lon = atof(longp); return true; - } /********* TCP FUNCTIONS ************************************/ - boolean Adafruit_FONA::TCPconnect(char *server, uint16_t port) { flushInput(); // close all old connections - if (! sendCheckReply(F("AT+CIPSHUT"), F("SHUT OK"), 20000) ) return false; + if (!sendCheckReply(F("AT+CIPSHUT"), F("SHUT OK"), 20000)) + return false; // single connection at a time - if (! sendCheckReply(F("AT+CIPMUX=0"), ok_reply) ) return false; + if (!sendCheckReply(F("AT+CIPMUX=0"), ok_reply)) + return false; // manually read data - if (! sendCheckReply(F("AT+CIPRXGET=1"), ok_reply) ) return false; - + if (!sendCheckReply(F("AT+CIPRXGET=1"), ok_reply)) + return false; DEBUG_PRINT(F("AT+CIPSTART=\"TCP\",\"")); DEBUG_PRINT(server); @@ -1367,15 +1426,16 @@ boolean Adafruit_FONA::TCPconnect(char *server, uint16_t port) { DEBUG_PRINT(port); DEBUG_PRINTLN(F("\"")); - mySerial->print(F("AT+CIPSTART=\"TCP\",\"")); mySerial->print(server); mySerial->print(F("\",\"")); mySerial->print(port); mySerial->println(F("\"")); - if (! expectReply(ok_reply)) return false; - if (! expectReply(F("CONNECT OK"))) return false; + if (!expectReply(ok_reply)) + return false; + if (!expectReply(F("CONNECT OK"))) + return false; // looks like it was a success (?) return true; @@ -1386,10 +1446,12 @@ boolean Adafruit_FONA::TCPclose(void) { } boolean Adafruit_FONA::TCPconnected(void) { - if (! sendCheckReply(F("AT+CIPSTATUS"), ok_reply, 100) ) return false; + if (!sendCheckReply(F("AT+CIPSTATUS"), ok_reply, 100)) + return false; readline(100); - DEBUG_PRINT (F("\t<--- ")); DEBUG_PRINTLN(replybuffer); + DEBUG_PRINT(F("\t<--- ")); + DEBUG_PRINTLN(replybuffer); return (strcmp(replybuffer, "STATE: CONNECT OK") == 0); } @@ -1399,27 +1461,28 @@ boolean Adafruit_FONA::TCPsend(char *packet, uint8_t len) { DEBUG_PRINT(F("AT+CIPSEND=")); DEBUG_PRINTLN(len); #ifdef ADAFRUIT_FONA_DEBUG - for (uint16_t i=0; iprint(F("AT+CIPSEND=")); mySerial->println(len); readline(); - DEBUG_PRINT (F("\t<--- ")); DEBUG_PRINTLN(replybuffer); + DEBUG_PRINT(F("\t<--- ")); + DEBUG_PRINTLN(replybuffer); - if (replybuffer[0] != '>') return false; + if (replybuffer[0] != '>') + return false; mySerial->write(packet, len); readline(3000); // wait up to 3 seconds to send the data - DEBUG_PRINT (F("\t<--- ")); DEBUG_PRINTLN(replybuffer); - + DEBUG_PRINT(F("\t<--- ")); + DEBUG_PRINTLN(replybuffer); return (strcmp(replybuffer, "SEND OK") == 0); } @@ -1427,30 +1490,32 @@ boolean Adafruit_FONA::TCPsend(char *packet, uint8_t len) { uint16_t Adafruit_FONA::TCPavailable(void) { uint16_t avail; - if (! sendParseReply(F("AT+CIPRXGET=4"), F("+CIPRXGET: 4,"), &avail, ',', 0) ) return false; - - - DEBUG_PRINT (avail); DEBUG_PRINTLN(F(" bytes available")); + if (!sendParseReply(F("AT+CIPRXGET=4"), F("+CIPRXGET: 4,"), &avail, ',', 0)) + return false; + DEBUG_PRINT(avail); + DEBUG_PRINTLN(F(" bytes available")); return avail; } - uint16_t Adafruit_FONA::TCPread(uint8_t *buff, uint8_t len) { uint16_t avail; mySerial->print(F("AT+CIPRXGET=2,")); mySerial->println(len); readline(); - if (! parseReply(F("+CIPRXGET: 2,"), &avail, ',', 0)) return false; + if (!parseReply(F("+CIPRXGET: 2,"), &avail, ',', 0)) + return false; readRaw(avail); #ifdef ADAFRUIT_FONA_DEBUG - DEBUG_PRINT (avail); DEBUG_PRINTLN(F(" bytes read")); - for (uint8_t i=0;i ")); DEBUG_PRINT(F("AT+HTTPPARA=\"")); DEBUG_PRINT(parameter); DEBUG_PRINTLN('"'); - mySerial->print(F("AT+HTTPPARA=\"")); mySerial->print(parameter); if (quoted) @@ -1514,8 +1575,7 @@ boolean Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, return HTTP_para_end(true); } -boolean Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, - int32_t value) { +boolean Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, int32_t value) { HTTP_para_start(parameter, false); mySerial->print(value); return HTTP_para_end(false); @@ -1524,14 +1584,12 @@ boolean Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, boolean Adafruit_FONA::HTTP_data(uint32_t size, uint32_t maxTime) { flushInput(); - DEBUG_PRINT(F("\t---> ")); DEBUG_PRINT(F("AT+HTTPDATA=")); DEBUG_PRINT(size); DEBUG_PRINT(','); DEBUG_PRINTLN(maxTime); - mySerial->print(F("AT+HTTPDATA=")); mySerial->print(size); mySerial->print(","); @@ -1543,14 +1601,14 @@ boolean Adafruit_FONA::HTTP_data(uint32_t size, uint32_t maxTime) { boolean Adafruit_FONA::HTTP_action(uint8_t method, uint16_t *status, uint16_t *datalen, int32_t timeout) { // Send request. - if (! sendCheckReply(F("AT+HTTPACTION="), method, ok_reply)) + if (!sendCheckReply(F("AT+HTTPACTION="), method, ok_reply)) return false; // Parse response status and size. readline(timeout); - if (! parseReply(F("+HTTPACTION:"), status, ',', 1)) + if (!parseReply(F("+HTTPACTION:"), status, ',', 1)) return false; - if (! parseReply(F("+HTTPACTION:"), datalen, ',', 2)) + if (!parseReply(F("+HTTPACTION:"), datalen, ',', 2)) return false; return true; @@ -1558,7 +1616,7 @@ boolean Adafruit_FONA::HTTP_action(uint8_t method, uint16_t *status, boolean Adafruit_FONA::HTTP_readall(uint16_t *datalen) { getReply(F("AT+HTTPREAD")); - if (! parseReply(F("+HTTPREAD:"), datalen, ',', 0)) + if (!parseReply(F("+HTTPREAD:"), datalen, ',', 0)) return false; return true; @@ -1570,20 +1628,22 @@ boolean Adafruit_FONA::HTTP_ssl(boolean onoff) { /********* HTTP HIGH LEVEL FUNCTIONS ***************************/ -boolean Adafruit_FONA::HTTP_GET_start(char *url, - uint16_t *status, uint16_t *datalen){ - if (! HTTP_setup(url)) +boolean Adafruit_FONA::HTTP_GET_start(char *url, uint16_t *status, + uint16_t *datalen) { + if (!HTTP_setup(url)) return false; // HTTP GET - if (! HTTP_action(FONA_HTTP_GET, status, datalen, 30000)) + if (!HTTP_action(FONA_HTTP_GET, status, datalen, 30000)) return false; - DEBUG_PRINT(F("Status: ")); DEBUG_PRINTLN(*status); - DEBUG_PRINT(F("Len: ")); DEBUG_PRINTLN(*datalen); + DEBUG_PRINT(F("Status: ")); + DEBUG_PRINTLN(*status); + DEBUG_PRINT(F("Len: ")); + DEBUG_PRINTLN(*datalen); // HTTP response data - if (! HTTP_readall(datalen)) + if (!HTTP_readall(datalen)) return false; return true; @@ -1591,7 +1651,7 @@ boolean Adafruit_FONA::HTTP_GET_start(char *url, /* boolean Adafruit_FONA_3G::HTTP_GET_start(char *ipaddr, char *path, uint16_t port - uint16_t *status, uint16_t *datalen){ + uint16_t *status, uint16_t *datalen){ char send[100] = "AT+CHTTPACT=\""; char *sendp = send + strlen(send); memset(sendp, 0, 100 - strlen(send)); @@ -1625,53 +1685,50 @@ boolean Adafruit_FONA_3G::HTTP_GET_start(char *ipaddr, char *path, uint16_t port } */ -void Adafruit_FONA::HTTP_GET_end(void) { - HTTP_term(); -} +void Adafruit_FONA::HTTP_GET_end(void) { HTTP_term(); } boolean Adafruit_FONA::HTTP_POST_start(char *url, - FONAFlashStringPtr contenttype, - const uint8_t *postdata, uint16_t postdatalen, - uint16_t *status, uint16_t *datalen){ - if (! HTTP_setup(url)) + FONAFlashStringPtr contenttype, + const uint8_t *postdata, + uint16_t postdatalen, uint16_t *status, + uint16_t *datalen) { + if (!HTTP_setup(url)) return false; - if (! HTTP_para(F("CONTENT"), contenttype)) { + if (!HTTP_para(F("CONTENT"), contenttype)) { return false; } // HTTP POST data - if (! HTTP_data(postdatalen, 10000)) + if (!HTTP_data(postdatalen, 10000)) return false; mySerial->write(postdata, postdatalen); - if (! expectReply(ok_reply)) + if (!expectReply(ok_reply)) return false; // HTTP POST - if (! HTTP_action(FONA_HTTP_POST, status, datalen)) + if (!HTTP_action(FONA_HTTP_POST, status, datalen)) return false; - DEBUG_PRINT(F("Status: ")); DEBUG_PRINTLN(*status); - DEBUG_PRINT(F("Len: ")); DEBUG_PRINTLN(*datalen); + DEBUG_PRINT(F("Status: ")); + DEBUG_PRINTLN(*status); + DEBUG_PRINT(F("Len: ")); + DEBUG_PRINTLN(*datalen); // HTTP response data - if (! HTTP_readall(datalen)) + if (!HTTP_readall(datalen)) return false; return true; } -void Adafruit_FONA::HTTP_POST_end(void) { - HTTP_term(); -} +void Adafruit_FONA::HTTP_POST_end(void) { HTTP_term(); } void Adafruit_FONA::setUserAgent(FONAFlashStringPtr useragent) { this->useragent = useragent; } -void Adafruit_FONA::setHTTPSRedirect(boolean onoff) { - httpsredirect = onoff; -} +void Adafruit_FONA::setHTTPSRedirect(boolean onoff) { httpsredirect = onoff; } /********* HTTP HELPERS ****************************************/ @@ -1680,21 +1737,21 @@ boolean Adafruit_FONA::HTTP_setup(char *url) { HTTP_term(); // Initialize and set parameters - if (! HTTP_init()) + if (!HTTP_init()) return false; - if (! HTTP_para(F("CID"), 1)) + if (!HTTP_para(F("CID"), 1)) return false; - if (! HTTP_para(F("UA"), useragent)) + if (!HTTP_para(F("UA"), useragent)) return false; - if (! HTTP_para(F("URL"), url)) + if (!HTTP_para(F("URL"), url)) return false; // HTTPS redirect if (httpsredirect) { - if (! HTTP_para(F("REDIR"),1)) + if (!HTTP_para(F("REDIR"), 1)) return false; - if (! HTTP_ssl(true)) + if (!HTTP_ssl(true)) return false; } @@ -1703,53 +1760,43 @@ boolean Adafruit_FONA::HTTP_setup(char *url) { /********* HELPERS *********************************************/ -boolean Adafruit_FONA::expectReply(FONAFlashStringPtr reply, - uint16_t timeout) { +boolean Adafruit_FONA::expectReply(FONAFlashStringPtr reply, uint16_t timeout) { readline(timeout); - DEBUG_PRINT(F("\t<--- ")); DEBUG_PRINTLN(replybuffer); + DEBUG_PRINT(F("\t<--- ")); + DEBUG_PRINTLN(replybuffer); - return (prog_char_strcmp(replybuffer, (prog_char*)reply) == 0); + return (prog_char_strcmp(replybuffer, (prog_char *)reply) == 0); } /********* LOW LEVEL *******************************************/ -inline int Adafruit_FONA::available(void) { - return mySerial->available(); -} +inline int Adafruit_FONA::available(void) { return mySerial->available(); } -inline size_t Adafruit_FONA::write(uint8_t x) { - return mySerial->write(x); -} +inline size_t Adafruit_FONA::write(uint8_t x) { return mySerial->write(x); } -inline int Adafruit_FONA::read(void) { - return mySerial->read(); -} +inline int Adafruit_FONA::read(void) { return mySerial->read(); } -inline int Adafruit_FONA::peek(void) { - return mySerial->peek(); -} +inline int Adafruit_FONA::peek(void) { return mySerial->peek(); } -inline void Adafruit_FONA::flush() { - mySerial->flush(); -} +inline void Adafruit_FONA::flush() { mySerial->flush(); } void Adafruit_FONA::flushInput() { - // Read all available serial input to flush pending data. - uint16_t timeoutloop = 0; - while (timeoutloop++ < 40) { - while(available()) { - read(); - timeoutloop = 0; // If char was received reset the timer - } - delay(1); + // Read all available serial input to flush pending data. + uint16_t timeoutloop = 0; + while (timeoutloop++ < 40) { + while (available()) { + read(); + timeoutloop = 0; // If char was received reset the timer } + delay(1); + } } uint16_t Adafruit_FONA::readRaw(uint16_t b) { uint16_t idx = 0; - while (b && (idx < sizeof(replybuffer)-1)) { + while (b && (idx < sizeof(replybuffer) - 1)) { if (mySerial->available()) { replybuffer[idx] = mySerial->read(); idx++; @@ -1766,49 +1813,50 @@ uint8_t Adafruit_FONA::readline(uint16_t timeout, boolean multiline) { while (timeout--) { if (replyidx >= 254) { - //DEBUG_PRINTLN(F("SPACE")); + // DEBUG_PRINTLN(F("SPACE")); break; } - while(mySerial->available()) { - char c = mySerial->read(); - if (c == '\r') continue; + while (mySerial->available()) { + char c = mySerial->read(); + if (c == '\r') + continue; if (c == 0xA) { - if (replyidx == 0) // the first 0x0A is ignored + if (replyidx == 0) // the first 0x0A is ignored continue; if (!multiline) { - timeout = 0; // the second 0x0A is the end of the line + timeout = 0; // the second 0x0A is the end of the line break; } } replybuffer[replyidx] = c; - //DEBUG_PRINT(c, HEX); DEBUG_PRINT("#"); DEBUG_PRINTLN(c); + // DEBUG_PRINT(c, HEX); DEBUG_PRINT("#"); DEBUG_PRINTLN(c); replyidx++; } if (timeout == 0) { - //DEBUG_PRINTLN(F("TIMEOUT")); + // DEBUG_PRINTLN(F("TIMEOUT")); break; } delay(1); } - replybuffer[replyidx] = 0; // null term + replybuffer[replyidx] = 0; // null term return replyidx; } uint8_t Adafruit_FONA::getReply(char *send, uint16_t timeout) { flushInput(); - - DEBUG_PRINT(F("\t---> ")); DEBUG_PRINTLN(send); - + DEBUG_PRINT(F("\t---> ")); + DEBUG_PRINTLN(send); mySerial->println(send); uint8_t l = readline(timeout); - DEBUG_PRINT (F("\t<--- ")); DEBUG_PRINTLN(replybuffer); + DEBUG_PRINT(F("\t<--- ")); + DEBUG_PRINTLN(replybuffer); return l; } @@ -1816,63 +1864,72 @@ uint8_t Adafruit_FONA::getReply(char *send, uint16_t timeout) { uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr send, uint16_t timeout) { flushInput(); - - DEBUG_PRINT(F("\t---> ")); DEBUG_PRINTLN(send); - + DEBUG_PRINT(F("\t---> ")); + DEBUG_PRINTLN(send); mySerial->println(send); uint8_t l = readline(timeout); - DEBUG_PRINT (F("\t<--- ")); DEBUG_PRINTLN(replybuffer); + DEBUG_PRINT(F("\t<--- ")); + DEBUG_PRINTLN(replybuffer); return l; } -// Send prefix, suffix, and newline. Return response (and also set replybuffer with response). -uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr prefix, char *suffix, uint16_t timeout) { +// Send prefix, suffix, and newline. Return response (and also set replybuffer +// with response). +uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr prefix, char *suffix, + uint16_t timeout) { flushInput(); - - DEBUG_PRINT(F("\t---> ")); DEBUG_PRINT(prefix); DEBUG_PRINTLN(suffix); - + DEBUG_PRINT(F("\t---> ")); + DEBUG_PRINT(prefix); + DEBUG_PRINTLN(suffix); mySerial->print(prefix); mySerial->println(suffix); uint8_t l = readline(timeout); - DEBUG_PRINT (F("\t<--- ")); DEBUG_PRINTLN(replybuffer); + DEBUG_PRINT(F("\t<--- ")); + DEBUG_PRINTLN(replybuffer); return l; } -// Send prefix, suffix, and newline. Return response (and also set replybuffer with response). -uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr prefix, int32_t suffix, uint16_t timeout) { +// Send prefix, suffix, and newline. Return response (and also set replybuffer +// with response). +uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr prefix, int32_t suffix, + uint16_t timeout) { flushInput(); - - DEBUG_PRINT(F("\t---> ")); DEBUG_PRINT(prefix); DEBUG_PRINTLN(suffix, DEC); - + DEBUG_PRINT(F("\t---> ")); + DEBUG_PRINT(prefix); + DEBUG_PRINTLN(suffix, DEC); mySerial->print(prefix); mySerial->println(suffix, DEC); uint8_t l = readline(timeout); - DEBUG_PRINT (F("\t<--- ")); DEBUG_PRINTLN(replybuffer); + DEBUG_PRINT(F("\t<--- ")); + DEBUG_PRINTLN(replybuffer); return l; } -// Send prefix, suffix, suffix2, and newline. Return response (and also set replybuffer with response). -uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr prefix, int32_t suffix1, int32_t suffix2, uint16_t timeout) { +// Send prefix, suffix, suffix2, and newline. Return response (and also set +// replybuffer with response). +uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr prefix, int32_t suffix1, + int32_t suffix2, uint16_t timeout) { flushInput(); - - DEBUG_PRINT(F("\t---> ")); DEBUG_PRINT(prefix); - DEBUG_PRINT(suffix1, DEC); DEBUG_PRINT(','); DEBUG_PRINTLN(suffix2, DEC); - + DEBUG_PRINT(F("\t---> ")); + DEBUG_PRINT(prefix); + DEBUG_PRINT(suffix1, DEC); + DEBUG_PRINT(','); + DEBUG_PRINTLN(suffix2, DEC); mySerial->print(prefix); mySerial->print(suffix1); @@ -1881,19 +1938,24 @@ uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr prefix, int32_t suffix1, int3 uint8_t l = readline(timeout); - DEBUG_PRINT (F("\t<--- ")); DEBUG_PRINTLN(replybuffer); + DEBUG_PRINT(F("\t<--- ")); + DEBUG_PRINTLN(replybuffer); return l; } -// Send prefix, ", suffix, ", and newline. Return response (and also set replybuffer with response). -uint8_t Adafruit_FONA::getReplyQuoted(FONAFlashStringPtr prefix, FONAFlashStringPtr suffix, uint16_t timeout) { +// Send prefix, ", suffix, ", and newline. Return response (and also set +// replybuffer with response). +uint8_t Adafruit_FONA::getReplyQuoted(FONAFlashStringPtr prefix, + FONAFlashStringPtr suffix, + uint16_t timeout) { flushInput(); - - DEBUG_PRINT(F("\t---> ")); DEBUG_PRINT(prefix); - DEBUG_PRINT('"'); DEBUG_PRINT(suffix); DEBUG_PRINTLN('"'); - + DEBUG_PRINT(F("\t---> ")); + DEBUG_PRINT(prefix); + DEBUG_PRINT('"'); + DEBUG_PRINT(suffix); + DEBUG_PRINTLN('"'); mySerial->print(prefix); mySerial->print('"'); @@ -1902,101 +1964,122 @@ uint8_t Adafruit_FONA::getReplyQuoted(FONAFlashStringPtr prefix, FONAFlashString uint8_t l = readline(timeout); - DEBUG_PRINT (F("\t<--- ")); DEBUG_PRINTLN(replybuffer); + DEBUG_PRINT(F("\t<--- ")); + DEBUG_PRINTLN(replybuffer); return l; } -boolean Adafruit_FONA::sendCheckReply(char *send, char *reply, uint16_t timeout) { - if (! getReply(send, timeout) ) - return false; -/* - for (uint8_t i=0; i= 100) - #include "Arduino.h" - #if !defined(__SAM3X8E__) && !defined(ARDUINO_ARCH_SAMD) // Arduino Due doesn't support #include - #endif +#include "Arduino.h" +#if !defined(__SAM3X8E__) && \ + !defined(ARDUINO_ARCH_SAMD) // Arduino Due doesn't support #include + // +#endif #else - #include "WProgram.h" - #include +#include "WProgram.h" +#include #endif #if (defined(__AVR__)) @@ -46,25 +46,27 @@ // DebugStream sets the Stream output to use // for debug (only applies when ADAFRUIT_FONA_DEBUG // is defined in config) -#define DebugStream Serial +#define DebugStream Serial #ifdef ADAFRUIT_FONA_DEBUG // need to do some debugging... -#define DEBUG_PRINT(...) DebugStream.print(__VA_ARGS__) -#define DEBUG_PRINTLN(...) DebugStream.println(__VA_ARGS__) +#define DEBUG_PRINT(...) DebugStream.print(__VA_ARGS__) +#define DEBUG_PRINTLN(...) DebugStream.println(__VA_ARGS__) #endif // a few typedefs to keep things portable -typedef Stream FONAStreamType; -typedef const __FlashStringHelper * FONAFlashStringPtr; +typedef Stream FONAStreamType; +typedef const __FlashStringHelper *FONAFlashStringPtr; -#define prog_char char PROGMEM +#define prog_char char PROGMEM -#define prog_char_strcmp(a, b) strcmp_P((a), (b)) -// define prog_char_strncmp(a, b, c) strncmp_P((a), (b), (c)) -#define prog_char_strstr(a, b) strstr_P((a), (b)) -#define prog_char_strlen(a) strlen_P((a)) -#define prog_char_strcpy(to, fromprogmem) strcpy_P((to), (fromprogmem)) -//define prog_char_strncpy(to, from, len) strncpy_P((to), (fromprogmem), (len)) +#define prog_char_strcmp(a, b) strcmp_P((a), (b)) +// define prog_char_strncmp(a, b, c) strncmp_P((a), (b), +// (c)) +#define prog_char_strstr(a, b) strstr_P((a), (b)) +#define prog_char_strlen(a) strlen_P((a)) +#define prog_char_strcpy(to, fromprogmem) strcpy_P((to), (fromprogmem)) +// define prog_char_strncpy(to, from, len) strncpy_P((to), +// (fromprogmem), (len)) #endif /* ADAFRUIT_FONA_LIBRARY_SRC_INCLUDES_PLATFORM_FONAPLATSTD_H_ */ diff --git a/includes/platform/FONAPlatform.h b/includes/platform/FONAPlatform.h index 0bf98d0..deb5204 100644 --- a/includes/platform/FONAPlatform.h +++ b/includes/platform/FONAPlatform.h @@ -21,17 +21,15 @@ * Author: Pat Deegan */ - #ifndef ADAFRUIT_FONA_LIBRARY_SRC_INCLUDES_PLATFORM_FONAPLATFORM_H_ #define ADAFRUIT_FONA_LIBRARY_SRC_INCLUDES_PLATFORM_FONAPLATFORM_H_ #include "../FONAConfig.h" -// only "standard" config supported in this release -- namely AVR-based arduino type affairs +// only "standard" config supported in this release -- namely AVR-based arduino +// type affairs #include "FONAPlatStd.h" - - #ifndef DEBUG_PRINT // debug is disabled @@ -40,23 +38,20 @@ #endif - #ifndef prog_char_strcmp -#define prog_char_strcmp(a, b) strcmp((a), (b)) +#define prog_char_strcmp(a, b) strcmp((a), (b)) #endif #ifndef prog_char_strstr -#define prog_char_strstr(a, b) strstr((a), (b)) +#define prog_char_strstr(a, b) strstr((a), (b)) #endif #ifndef prog_char_strlen -#define prog_char_strlen(a) strlen((a)) +#define prog_char_strlen(a) strlen((a)) #endif - #ifndef prog_char_strcpy -#define prog_char_strcpy(to, fromprogmem) strcpy((to), (fromprogmem)) +#define prog_char_strcpy(to, fromprogmem) strcpy((to), (fromprogmem)) #endif - #endif /* ADAFRUIT_FONA_LIBRARY_SRC_INCLUDES_PLATFORM_FONAPLATFORM_H_ */ diff --git a/library.properties b/library.properties index fc20e2b..d42e7e6 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Adafruit FONA Library -version=1.3.5 +version=1.3.6 author=Adafruit maintainer=Adafruit sentence=Arduino library for the Adafruit FONA From dc8ef626d7872498257631c47a5087ba81935af0 Mon Sep 17 00:00:00 2001 From: siddacious Date: Wed, 25 Mar 2020 17:03:04 -0700 Subject: [PATCH 02/14] more formatting --- includes/platform/FONAPlatStd.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/platform/FONAPlatStd.h b/includes/platform/FONAPlatStd.h index f5f8247..058958c 100644 --- a/includes/platform/FONAPlatStd.h +++ b/includes/platform/FONAPlatStd.h @@ -61,8 +61,8 @@ typedef const __FlashStringHelper *FONAFlashStringPtr; #define prog_char char PROGMEM #define prog_char_strcmp(a, b) strcmp_P((a), (b)) -// define prog_char_strncmp(a, b, c) strncmp_P((a), (b), -// (c)) +// define prog_char_strncmp(a, b, c) strncmp_P((a), +// (b), (c)) #define prog_char_strstr(a, b) strstr_P((a), (b)) #define prog_char_strlen(a) strlen_P((a)) #define prog_char_strcpy(to, fromprogmem) strcpy_P((to), (fromprogmem)) From 3da1d866f3447d255a5e50a6bb21c110b8a881e1 Mon Sep 17 00:00:00 2001 From: siddacious Date: Thu, 26 Mar 2020 14:27:28 -0700 Subject: [PATCH 03/14] adding .skips --- examples/FONA3G_setbaud/.esp32.test.skip | 0 examples/FONA3G_setbaud/.metro_m4.test.skip | 0 examples/FONA3G_setbaud/.zero.test.skip | 0 examples/FONA_SMS_Response/.esp32.test.skip | 0 examples/FONA_SMS_Response/.esp8266.test.skip | 0 examples/FONA_SMS_Response/.metro_m4.test.skip | 0 examples/FONA_SMS_Response/.zero.test.skip | 0 examples/FONAtest/.esp32.test.skip | 0 examples/FONAtest/.metro_m4.test.skip | 0 examples/FONAtest/.zero.test.skip | 0 examples/FONAtest_KEY_mod/.esp32.test.skip | 0 examples/FONAtest_KEY_mod/.esp8266.test.skip | 0 examples/FONAtest_KEY_mod/.metro_m4.test.skip | 0 examples/FONAtest_KEY_mod/.zero.test.skip | 0 examples/GPS/.esp32.test.skip | 0 examples/GPS/.metro_m4.test.skip | 0 examples/GPS/.zero.test.skip | 0 examples/IncomingCall/.esp32.test.skip | 0 examples/IncomingCall/.metro_m4.test.skip | 0 examples/IncomingCall/.zero.test.skip | 0 20 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 examples/FONA3G_setbaud/.esp32.test.skip create mode 100644 examples/FONA3G_setbaud/.metro_m4.test.skip create mode 100644 examples/FONA3G_setbaud/.zero.test.skip create mode 100644 examples/FONA_SMS_Response/.esp32.test.skip create mode 100644 examples/FONA_SMS_Response/.esp8266.test.skip create mode 100644 examples/FONA_SMS_Response/.metro_m4.test.skip create mode 100644 examples/FONA_SMS_Response/.zero.test.skip create mode 100644 examples/FONAtest/.esp32.test.skip create mode 100644 examples/FONAtest/.metro_m4.test.skip create mode 100644 examples/FONAtest/.zero.test.skip create mode 100644 examples/FONAtest_KEY_mod/.esp32.test.skip create mode 100644 examples/FONAtest_KEY_mod/.esp8266.test.skip create mode 100644 examples/FONAtest_KEY_mod/.metro_m4.test.skip create mode 100644 examples/FONAtest_KEY_mod/.zero.test.skip create mode 100644 examples/GPS/.esp32.test.skip create mode 100644 examples/GPS/.metro_m4.test.skip create mode 100644 examples/GPS/.zero.test.skip create mode 100644 examples/IncomingCall/.esp32.test.skip create mode 100644 examples/IncomingCall/.metro_m4.test.skip create mode 100644 examples/IncomingCall/.zero.test.skip diff --git a/examples/FONA3G_setbaud/.esp32.test.skip b/examples/FONA3G_setbaud/.esp32.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/FONA3G_setbaud/.metro_m4.test.skip b/examples/FONA3G_setbaud/.metro_m4.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/FONA3G_setbaud/.zero.test.skip b/examples/FONA3G_setbaud/.zero.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/FONA_SMS_Response/.esp32.test.skip b/examples/FONA_SMS_Response/.esp32.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/FONA_SMS_Response/.esp8266.test.skip b/examples/FONA_SMS_Response/.esp8266.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/FONA_SMS_Response/.metro_m4.test.skip b/examples/FONA_SMS_Response/.metro_m4.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/FONA_SMS_Response/.zero.test.skip b/examples/FONA_SMS_Response/.zero.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/FONAtest/.esp32.test.skip b/examples/FONAtest/.esp32.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/FONAtest/.metro_m4.test.skip b/examples/FONAtest/.metro_m4.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/FONAtest/.zero.test.skip b/examples/FONAtest/.zero.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/FONAtest_KEY_mod/.esp32.test.skip b/examples/FONAtest_KEY_mod/.esp32.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/FONAtest_KEY_mod/.esp8266.test.skip b/examples/FONAtest_KEY_mod/.esp8266.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/FONAtest_KEY_mod/.metro_m4.test.skip b/examples/FONAtest_KEY_mod/.metro_m4.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/FONAtest_KEY_mod/.zero.test.skip b/examples/FONAtest_KEY_mod/.zero.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/GPS/.esp32.test.skip b/examples/GPS/.esp32.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/GPS/.metro_m4.test.skip b/examples/GPS/.metro_m4.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/GPS/.zero.test.skip b/examples/GPS/.zero.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/IncomingCall/.esp32.test.skip b/examples/IncomingCall/.esp32.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/IncomingCall/.metro_m4.test.skip b/examples/IncomingCall/.metro_m4.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/examples/IncomingCall/.zero.test.skip b/examples/IncomingCall/.zero.test.skip new file mode 100644 index 0000000..e69de29 From c16bf58f6101c4f9b79f40d6b49c7c7f7ea31e05 Mon Sep 17 00:00:00 2001 From: siddacious Date: Thu, 26 Mar 2020 16:29:56 -0700 Subject: [PATCH 04/14] saving progress :| --- Adafruit_FONA.cpp | 708 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 622 insertions(+), 86 deletions(-) diff --git a/Adafruit_FONA.cpp b/Adafruit_FONA.cpp index 247e8d0..e808a10 100644 --- a/Adafruit_FONA.cpp +++ b/Adafruit_FONA.cpp @@ -42,8 +42,13 @@ Adafruit_FONA::Adafruit_FONA(int8_t rst) { } uint8_t Adafruit_FONA::type(void) { return _type; } - -boolean Adafruit_FONA::begin(Stream &port) { +/** + * @brief Connect to the cell module + * + * @param port the serial connection to uset o connect + * @return bool true on success, false if a connection cannot be made + */ +bool Adafruit_FONA::begin(Stream &port) { mySerial = &port; pinMode(_rstpin, OUTPUT); @@ -146,13 +151,38 @@ boolean Adafruit_FONA::begin(Stream &port) { } /********* Serial port ********************************************/ -boolean Adafruit_FONA::setBaudrate(uint16_t baud) { +/** + * @brief + * + * @param baud + * @return bool true on suc + */ +/** + * @brief Set the baud rate that the module will use + * + * @param baud The new baud rate to set + * @return true success + * @return false failure + */ +bool Adafruit_FONA::setBaudrate(uint16_t baud) { return sendCheckReply(F("AT+IPREX="), baud, ok_reply); } /********* Real Time Clock ********************************************/ -boolean Adafruit_FONA::readRTC(uint8_t *year, uint8_t *month, uint8_t *date, +/** + * @brief Read the Real Time Clock + * + * @param year + * @param month + * @param date + * @param hr + * @param min + * @param sec + * @return true success + * @return false failure + */ +bool Adafruit_FONA::readRTC(uint8_t *year, uint8_t *month, uint8_t *date, uint8_t *hr, uint8_t *min, uint8_t *sec) { uint16_t v; sendParseReply(F("AT+CCLK?"), F("+CCLK: "), &v, '/', 0); @@ -160,8 +190,14 @@ boolean Adafruit_FONA::readRTC(uint8_t *year, uint8_t *month, uint8_t *date, DEBUG_PRINTLN(*year); } - -boolean Adafruit_FONA::enableRTC(uint8_t i) { +/** + * @brief + * + * @param i + * @return true + * @return false + */ +bool Adafruit_FONA::enableRTC(uint8_t i) { if (!sendCheckReply(F("AT+CLTS="), i, ok_reply)) return false; return sendCheckReply(F("AT&W"), ok_reply); @@ -170,29 +206,62 @@ boolean Adafruit_FONA::enableRTC(uint8_t i) { /********* BATTERY & ADC ********************************************/ /* returns value in mV (uint16_t) */ -boolean Adafruit_FONA::getBattVoltage(uint16_t *v) { +/** + * @brief + * + * @param v + * @return true + * @return false + */ +bool Adafruit_FONA::getBattVoltage(uint16_t *v) { return sendParseReply(F("AT+CBC"), F("+CBC: "), v, ',', 2); } /* returns value in mV (uint16_t) */ -boolean Adafruit_FONA_3G::getBattVoltage(uint16_t *v) { +/** + * @brief + * + * @param v + * @return true + * @return false + */ +bool Adafruit_FONA_3G::getBattVoltage(uint16_t *v) { float f; - boolean b = sendParseReply(F("AT+CBC"), F("+CBC: "), &f, ',', 2); + bool b = sendParseReply(F("AT+CBC"), F("+CBC: "), &f, ',', 2); *v = f * 1000; return b; } /* returns the percentage charge of battery as reported by sim800 */ -boolean Adafruit_FONA::getBattPercent(uint16_t *p) { +/** + * @brief + * + * @param p + * @return true + * @return false + */ +bool Adafruit_FONA::getBattPercent(uint16_t *p) { return sendParseReply(F("AT+CBC"), F("+CBC: "), p, ',', 1); } - -boolean Adafruit_FONA::getADCVoltage(uint16_t *v) { +/** + * @brief + * + * @param v + * @return true + * @return false + */ +bool Adafruit_FONA::getADCVoltage(uint16_t *v) { return sendParseReply(F("AT+CADC?"), F("+CADC: 1,"), v); } /********* SIM ***********************************************************/ +/** + * @brief Unlock the sim with a provided PIN + * + * @param pin The pin to use to unlock the SIM + * @return uint8_t + */ uint8_t Adafruit_FONA::unlockSIM(char *pin) { char sendbuff[14] = "AT+CPIN="; sendbuff[8] = pin[0]; @@ -204,6 +273,12 @@ uint8_t Adafruit_FONA::unlockSIM(char *pin) { return sendCheckReply(sendbuff, ok_reply); } +/** + * @brief + * + * @param ccid + * @return uint8_t + */ uint8_t Adafruit_FONA::getSIMCCID(char *ccid) { getReply(F("AT+CCID")); // up to 28 chars for reply, 20 char total ccid @@ -223,6 +298,12 @@ uint8_t Adafruit_FONA::getSIMCCID(char *ccid) { /********* IMEI **********************************************************/ +/** + * @brief + * + * @param imei + * @return uint8_t + */ uint8_t Adafruit_FONA::getIMEI(char *imei) { getReply(F("AT+GSN")); @@ -237,6 +318,11 @@ uint8_t Adafruit_FONA::getIMEI(char *imei) { /********* NETWORK *******************************************************/ +/** + * @brief + * + * @return uint8_t + */ uint8_t Adafruit_FONA::getNetworkStatus(void) { uint16_t status; @@ -257,7 +343,14 @@ uint8_t Adafruit_FONA::getRSSI(void) { /********* AUDIO *******************************************************/ -boolean Adafruit_FONA::setAudio(uint8_t a) { +/** + * @brief + * + * @param a + * @return true success + * @return false failure + */ +bool Adafruit_FONA::setAudio(uint8_t a) { // 0 is headset, 1 is external audio if (a > 1) return false; @@ -274,11 +367,25 @@ uint8_t Adafruit_FONA::getVolume(void) { return reply; } -boolean Adafruit_FONA::setVolume(uint8_t i) { +/** + * @brief + * + * @param i + * @return true success + * @return false failure + */ +bool Adafruit_FONA::setVolume(uint8_t i) { return sendCheckReply(F("AT+CLVL="), i, ok_reply); } -boolean Adafruit_FONA::playDTMF(char dtmf) { +/** + * @brief + * + * @param dtmf + * @return true success + * @return false failure + */ +bool Adafruit_FONA::playDTMF(char dtmf) { char str[4]; str[0] = '\"'; str[1] = dtmf; @@ -287,18 +394,41 @@ boolean Adafruit_FONA::playDTMF(char dtmf) { return sendCheckReply(F("AT+CLDTMF=3,"), str, ok_reply); } -boolean Adafruit_FONA::playToolkitTone(uint8_t t, uint16_t len) { +/** + * @brief + * + * @param t + * @param len + * @return true success + * @return false failure + */ +bool Adafruit_FONA::playToolkitTone(uint8_t t, uint16_t len) { return sendCheckReply(F("AT+STTONE=1,"), t, len, ok_reply); } - -boolean Adafruit_FONA_3G::playToolkitTone(uint8_t t, uint16_t len) { +/** + * @brief + * + * @param t + * @param len + * @return true success + * @return false failure + */ +bool Adafruit_FONA_3G::playToolkitTone(uint8_t t, uint16_t len) { if (!sendCheckReply(F("AT+CPTONE="), t, ok_reply)) return false; delay(len); return sendCheckReply(F("AT+CPTONE=0"), ok_reply); } -boolean Adafruit_FONA::setMicVolume(uint8_t a, uint8_t level) { +/** + * @brief + * + * @param a + * @param level + * @return true success + * @return false failure + */ +bool Adafruit_FONA::setMicVolume(uint8_t a, uint8_t level) { // 0 is headset, 1 is external audio if (a > 1) return false; @@ -308,7 +438,15 @@ boolean Adafruit_FONA::setMicVolume(uint8_t a, uint8_t level) { /********* FM RADIO *******************************************************/ -boolean Adafruit_FONA::FMradio(boolean onoff, uint8_t a) { +/** + * @brief + * + * @param onoff + * @param a + * @return true success + * @return false failure + */ +bool Adafruit_FONA::FMradio(bool onoff, uint8_t a) { if (!onoff) { return sendCheckReply(F("AT+FMCLOSE"), ok_reply); } @@ -320,7 +458,14 @@ boolean Adafruit_FONA::FMradio(boolean onoff, uint8_t a) { return sendCheckReply(F("AT+FMOPEN="), a, ok_reply); } -boolean Adafruit_FONA::tuneFMradio(uint16_t station) { +/** + * @brief + * + * @param station + * @return true success + * @return false failure + */ +bool Adafruit_FONA::tuneFMradio(uint16_t station) { // Fail if FM station is outside allowed range. if ((station < 870) || (station > 1090)) return false; @@ -328,7 +473,14 @@ boolean Adafruit_FONA::tuneFMradio(uint16_t station) { return sendCheckReply(F("AT+FMFREQ="), station, ok_reply); } -boolean Adafruit_FONA::setFMVolume(uint8_t i) { +/** + * @brief + * + * @param i + * @return true success + * @return false failure + */ +bool Adafruit_FONA::setFMVolume(uint8_t i) { // Fail if volume is outside allowed range (0-6). if (i > 6) { return false; @@ -373,7 +525,15 @@ int8_t Adafruit_FONA::getFMSignalLevel(uint16_t station) { /********* PWM/BUZZER **************************************************/ -boolean Adafruit_FONA::setPWM(uint16_t period, uint8_t duty) { +/** + * @brief + * + * @param period + * @param duty + * @return true success + * @return false failure + */ +bool Adafruit_FONA::setPWM(uint16_t period, uint8_t duty) { if (period > 2000) return false; if (duty > 100) @@ -383,7 +543,15 @@ boolean Adafruit_FONA::setPWM(uint16_t period, uint8_t duty) { } /********* CALL PHONES **************************************************/ -boolean Adafruit_FONA::callPhone(char *number) { + +/** + * @brief + * + * @param number + * @return true success + * @return false failure + */ +bool Adafruit_FONA::callPhone(char *number) { char sendbuff[35] = "ATD"; strncpy(sendbuff + 3, number, min(30, (int)strlen(number))); uint8_t x = strlen(sendbuff); @@ -402,23 +570,47 @@ uint8_t Adafruit_FONA::getCallStatus(void) { return phoneStatus; // 0 ready, 2 unkown, 3 ringing, 4 call in progress } - -boolean Adafruit_FONA::hangUp(void) { +/** + * @brief + * + * @return true + * @return false + */ +bool Adafruit_FONA::hangUp(void) { return sendCheckReply(F("ATH0"), ok_reply); } - -boolean Adafruit_FONA_3G::hangUp(void) { +/** + * @brief + * + * @return true + * @return false + */ +bool Adafruit_FONA_3G::hangUp(void) { getReply(F("ATH")); return (prog_char_strstr(replybuffer, (prog_char *)F("VOICE CALL: END")) != 0); } -boolean Adafruit_FONA::pickUp(void) { + +/** + * @brief + * + * @return true + * @return false + */ +bool Adafruit_FONA::pickUp(void) { return sendCheckReply(F("ATA"), ok_reply); } -boolean Adafruit_FONA_3G::pickUp(void) { + +/** + * @brief + * + * @return true + * @return false + */ +bool Adafruit_FONA_3G::pickUp(void) { return sendCheckReply(F("ATA"), F("VOICE CALL: BEGIN")); } @@ -430,9 +622,18 @@ void Adafruit_FONA::onIncomingCall() { Adafruit_FONA::_incomingCall = true; } -boolean Adafruit_FONA::_incomingCall = false; +bool Adafruit_FONA::_incomingCall = false; -boolean Adafruit_FONA::callerIdNotification(boolean enable, uint8_t interrupt) { + +/** + * @brief + * + * @param enable + * @param interrupt + * @return true + * @return false + */ +bool Adafruit_FONA::callerIdNotification(bool enable, uint8_t interrupt) { if (enable) { attachInterrupt(interrupt, onIncomingCall, FALLING); return sendCheckReply(F("AT+CLIP=1"), ok_reply); @@ -442,7 +643,14 @@ boolean Adafruit_FONA::callerIdNotification(boolean enable, uint8_t interrupt) { return sendCheckReply(F("AT+CLIP=0"), ok_reply); } -boolean Adafruit_FONA::incomingCallNumber(char *phonenum) { +/** + * @brief + * + * @param phonenum + * @return true + * @return false + */ +bool Adafruit_FONA::incomingCallNumber(char *phonenum) { //+CLIP: "",145,"",0,"",0 if (!Adafruit_FONA::_incomingCall) return false; @@ -475,7 +683,14 @@ uint8_t Adafruit_FONA::getSMSInterrupt(void) { return reply; } -boolean Adafruit_FONA::setSMSInterrupt(uint8_t i) { +/** + * @brief + * + * @param i + * @return true + * @return false + */ +bool Adafruit_FONA::setSMSInterrupt(uint8_t i) { return sendCheckReply(F("AT+CFGRI="), i, ok_reply); } @@ -498,7 +713,18 @@ int8_t Adafruit_FONA::getNumSMS(void) { // Reading SMS's is a bit involved so we don't use helpers that may cause delays // or debug printouts! -boolean Adafruit_FONA::readSMS(uint8_t i, char *smsbuff, uint16_t maxlen, + +/** + * @brief + * + * @param i + * @param smsbuff + * @param maxlen + * @param readlen + * @return true + * @return false + */ +bool Adafruit_FONA::readSMS(uint8_t i, char *smsbuff, uint16_t maxlen, uint16_t *readlen) { // text mode if (!sendCheckReply(F("AT+CMGF=1"), ok_reply)) @@ -548,7 +774,17 @@ boolean Adafruit_FONA::readSMS(uint8_t i, char *smsbuff, uint16_t maxlen, // and a null terminator will be added if less than senderlen charactesr are // copied to the result. Returns true if a result was successfully retrieved, // otherwise false. -boolean Adafruit_FONA::getSMSSender(uint8_t i, char *sender, int senderlen) { + +/** + * @brief + * + * @param i + * @param sender + * @param senderlen + * @return true + * @return false + */ +bool Adafruit_FONA::getSMSSender(uint8_t i, char *sender, int senderlen) { // Ensure text mode and all text mode parameters are sent. if (!sendCheckReply(F("AT+CMGF=1"), ok_reply)) return false; @@ -566,13 +802,21 @@ boolean Adafruit_FONA::getSMSSender(uint8_t i, char *sender, int senderlen) { DEBUG_PRINTLN(replybuffer); // Parse the second field in the response. - boolean result = parseReplyQuoted(F("+CMGR:"), sender, senderlen, ',', 1); + bool result = parseReplyQuoted(F("+CMGR:"), sender, senderlen, ',', 1); // Drop any remaining data from the response. flushInput(); return result; } -boolean Adafruit_FONA::sendSMS(char *smsaddr, char *smsmsg) { +/** + * @brief + * + * @param smsaddr + * @param smsmsg + * @return true + * @return false + */ +bool Adafruit_FONA::sendSMS(char *smsaddr, char *smsmsg) { if (!sendCheckReply(F("AT+CMGF=1"), ok_reply)) return false; @@ -615,7 +859,14 @@ boolean Adafruit_FONA::sendSMS(char *smsaddr, char *smsmsg) { return true; } -boolean Adafruit_FONA::deleteSMS(uint8_t i) { +/** + * @brief + * + * @param i + * @return true + * @return false + */ +bool Adafruit_FONA::deleteSMS(uint8_t i) { if (!sendCheckReply(F("AT+CMGF=1"), ok_reply)) return false; // read an sms @@ -631,7 +882,17 @@ boolean Adafruit_FONA::deleteSMS(uint8_t i) { /********* USSD *********************************************************/ -boolean Adafruit_FONA::sendUSSD(char *ussdmsg, char *ussdbuff, uint16_t maxlen, +/** + * @brief + * + * @param ussdmsg + * @param ussdbuff + * @param maxlen + * @param readlen + * @return true + * @return false + */ +bool Adafruit_FONA::sendUSSD(char *ussdmsg, char *ussdbuff, uint16_t maxlen, uint16_t *readlen) { if (!sendCheckReply(F("AT+CUSD=1"), ok_reply)) return false; @@ -673,7 +934,14 @@ boolean Adafruit_FONA::sendUSSD(char *ussdmsg, char *ussdbuff, uint16_t maxlen, /********* TIME **********************************************************/ -boolean Adafruit_FONA::enableNetworkTimeSync(boolean onoff) { +/** + * @brief + * + * @param onoff + * @return true + * @return false + */ +bool Adafruit_FONA::enableNetworkTimeSync(bool onoff) { if (onoff) { if (!sendCheckReply(F("AT+CLTS=1"), ok_reply)) return false; @@ -687,7 +955,15 @@ boolean Adafruit_FONA::enableNetworkTimeSync(boolean onoff) { return true; } -boolean Adafruit_FONA::enableNTPTimeSync(boolean onoff, +/** + * @brief + * + * @param onoff + * @param ntpserver + * @return true + * @return false + */ +bool Adafruit_FONA::enableNTPTimeSync(bool onoff, FONAFlashStringPtr ntpserver) { if (onoff) { if (!sendCheckReply(F("AT+CNTPCID=1"), ok_reply)) @@ -719,7 +995,15 @@ boolean Adafruit_FONA::enableNTPTimeSync(boolean onoff, return true; } -boolean Adafruit_FONA::getTime(char *buff, uint16_t maxlen) { +/** + * @brief + * + * @param buff + * @param maxlen + * @return true + * @return false + */ +bool Adafruit_FONA::getTime(char *buff, uint16_t maxlen) { getReply(F("AT+CCLK?"), (uint16_t)10000); if (strncmp(replybuffer, "+CCLK: ", 7) != 0) return false; @@ -736,7 +1020,14 @@ boolean Adafruit_FONA::getTime(char *buff, uint16_t maxlen) { /********* GPS **********************************************************/ -boolean Adafruit_FONA::enableGPS(boolean onoff) { +/** + * @brief + * + * @param onoff + * @return true + * @return false + */ +bool Adafruit_FONA::enableGPS(bool onoff) { uint16_t state; // first check if its already on or off @@ -769,7 +1060,14 @@ boolean Adafruit_FONA::enableGPS(boolean onoff) { return true; } -boolean Adafruit_FONA_3G::enableGPS(boolean onoff) { +/** + * @brief + * + * @param onoff + * @return true + * @return false + */ +bool Adafruit_FONA_3G::enableGPS(bool onoff) { uint16_t state; // first check if its already on or off @@ -869,7 +1167,18 @@ uint8_t Adafruit_FONA::getGPS(uint8_t arg, char *buffer, uint8_t maxbuff) { return len; } -boolean Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, +/** + * @brief + * + * @param lat + * @param lon + * @param speed_kph + * @param heading + * @param altitude + * @return true + * @return false + */ +bool Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, float *heading, float *altitude) { char gpsbuffer[120]; @@ -1163,7 +1472,14 @@ boolean Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, return true; } -boolean Adafruit_FONA::enableGPSNMEA(uint8_t i) { +/** + * @brief + * + * @param i + * @return true + * @return false + */ +bool Adafruit_FONA::enableGPSNMEA(uint8_t i) { char sendbuff[15] = "AT+CGPSOUT=000"; sendbuff[11] = (i / 100) + '0'; @@ -1184,7 +1500,14 @@ boolean Adafruit_FONA::enableGPSNMEA(uint8_t i) { /********* GPRS **********************************************************/ -boolean Adafruit_FONA::enableGPRS(boolean onoff) { +/** + * @brief + * + * @param onoff + * @return true + * @return false + */ +bool Adafruit_FONA::enableGPRS(bool onoff) { if (onoff) { // disconnect all sockets @@ -1278,7 +1601,14 @@ boolean Adafruit_FONA::enableGPRS(boolean onoff) { return true; } -boolean Adafruit_FONA_3G::enableGPRS(boolean onoff) { +/** + * @brief + * + * @param onoff + * @return true + * @return false + */ +bool Adafruit_FONA_3G::enableGPRS(bool onoff) { if (onoff) { // disconnect all sockets @@ -1358,7 +1688,16 @@ void Adafruit_FONA::setGPRSNetworkSettings(FONAFlashStringPtr apn, this->apnpassword = password; } -boolean Adafruit_FONA::getGSMLoc(uint16_t *errorcode, char *buff, +/** + * @brief + * + * @param errorcode + * @param buff + * @param maxlen + * @return true + * @return false + */ +bool Adafruit_FONA::getGSMLoc(uint16_t *errorcode, char *buff, uint16_t maxlen) { getReply(F("AT+CIPGSMLOC=1,1"), (uint16_t)10000); @@ -1375,7 +1714,15 @@ boolean Adafruit_FONA::getGSMLoc(uint16_t *errorcode, char *buff, return true; } -boolean Adafruit_FONA::getGSMLoc(float *lat, float *lon) { +/** + * @brief + * + * @param lat + * @param lon + * @return true + * @return false + */ +bool Adafruit_FONA::getGSMLoc(float *lat, float *lon) { uint16_t returncode; char gpsbuffer[120]; @@ -1405,7 +1752,16 @@ boolean Adafruit_FONA::getGSMLoc(float *lat, float *lon) { } /********* TCP FUNCTIONS ************************************/ -boolean Adafruit_FONA::TCPconnect(char *server, uint16_t port) { +/** + * @brief + * + * @param server + * @param port + * @return true + * @return false + */ + +bool Adafruit_FONA::TCPconnect(char *server, uint16_t port) { flushInput(); // close all old connections @@ -1441,11 +1797,23 @@ boolean Adafruit_FONA::TCPconnect(char *server, uint16_t port) { return true; } -boolean Adafruit_FONA::TCPclose(void) { +/** + * @brief + * + * @return true + * @return false + */ +bool Adafruit_FONA::TCPclose(void) { return sendCheckReply(F("AT+CIPCLOSE"), ok_reply); } -boolean Adafruit_FONA::TCPconnected(void) { +/** + * @brief + * + * @return true + * @return false + */ +bool Adafruit_FONA::TCPconnected(void) { if (!sendCheckReply(F("AT+CIPSTATUS"), ok_reply, 100)) return false; readline(100); @@ -1456,7 +1824,15 @@ boolean Adafruit_FONA::TCPconnected(void) { return (strcmp(replybuffer, "STATE: CONNECT OK") == 0); } -boolean Adafruit_FONA::TCPsend(char *packet, uint8_t len) { +/** + * @brief + * + * @param packet + * @param len + * @return true + * @return false + */ +bool Adafruit_FONA::TCPsend(char *packet, uint8_t len) { DEBUG_PRINT(F("AT+CIPSEND=")); DEBUG_PRINTLN(len); @@ -1527,16 +1903,28 @@ uint16_t Adafruit_FONA::TCPread(uint8_t *buff, uint8_t len) { /********* HTTP LOW LEVEL FUNCTIONS ************************************/ -boolean Adafruit_FONA::HTTP_init() { +/** + * @brief + * + * @return true + * @return false + */ +bool Adafruit_FONA::HTTP_init() { return sendCheckReply(F("AT+HTTPINIT"), ok_reply); } -boolean Adafruit_FONA::HTTP_term() { +/** + * @brief + * + * @return true + * @return false + */ +bool Adafruit_FONA::HTTP_term() { return sendCheckReply(F("AT+HTTPTERM"), ok_reply); } void Adafruit_FONA::HTTP_para_start(FONAFlashStringPtr parameter, - boolean quoted) { + bool quoted) { flushInput(); DEBUG_PRINT(F("\t---> ")); @@ -1552,7 +1940,14 @@ void Adafruit_FONA::HTTP_para_start(FONAFlashStringPtr parameter, mySerial->print(F("\",")); } -boolean Adafruit_FONA::HTTP_para_end(boolean quoted) { +/** + * @brief + * + * @param quoted + * @return true + * @return false + */ +bool Adafruit_FONA::HTTP_para_end(bool quoted) { if (quoted) mySerial->println('"'); else @@ -1561,27 +1956,59 @@ boolean Adafruit_FONA::HTTP_para_end(boolean quoted) { return expectReply(ok_reply); } -boolean Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, +/** + * @brief + * + * @param parameter + * @param value + * @return true + * @return false + */ +bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, const char *value) { HTTP_para_start(parameter, true); mySerial->print(value); return HTTP_para_end(true); } -boolean Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, +/** + * @brief + * + * @param parameter + * @param value + * @return true + * @return false + */ +bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, FONAFlashStringPtr value) { HTTP_para_start(parameter, true); mySerial->print(value); return HTTP_para_end(true); } -boolean Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, int32_t value) { +/** + * @brief + * + * @param parameter + * @param value + * @return true + * @return false + */ +bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, int32_t value) { HTTP_para_start(parameter, false); mySerial->print(value); return HTTP_para_end(false); } -boolean Adafruit_FONA::HTTP_data(uint32_t size, uint32_t maxTime) { +/** + * @brief + * + * @param size + * @param maxTime + * @return true + * @return false + */ +bool Adafruit_FONA::HTTP_data(uint32_t size, uint32_t maxTime) { flushInput(); DEBUG_PRINT(F("\t---> ")); @@ -1598,7 +2025,17 @@ boolean Adafruit_FONA::HTTP_data(uint32_t size, uint32_t maxTime) { return expectReply(F("DOWNLOAD")); } -boolean Adafruit_FONA::HTTP_action(uint8_t method, uint16_t *status, +/** + * @brief + * + * @param method + * @param status + * @param datalen + * @param timeout + * @return true + * @return false + */ +bool Adafruit_FONA::HTTP_action(uint8_t method, uint16_t *status, uint16_t *datalen, int32_t timeout) { // Send request. if (!sendCheckReply(F("AT+HTTPACTION="), method, ok_reply)) @@ -1614,7 +2051,14 @@ boolean Adafruit_FONA::HTTP_action(uint8_t method, uint16_t *status, return true; } -boolean Adafruit_FONA::HTTP_readall(uint16_t *datalen) { +/** + * @brief + * + * @param datalen + * @return true + * @return false + */ +bool Adafruit_FONA::HTTP_readall(uint16_t *datalen) { getReply(F("AT+HTTPREAD")); if (!parseReply(F("+HTTPREAD:"), datalen, ',', 0)) return false; @@ -1622,13 +2066,29 @@ boolean Adafruit_FONA::HTTP_readall(uint16_t *datalen) { return true; } -boolean Adafruit_FONA::HTTP_ssl(boolean onoff) { +/** + * @brief + * + * @param onoff + * @return true + * @return false + */ +bool Adafruit_FONA::HTTP_ssl(bool onoff) { return sendCheckReply(F("AT+HTTPSSL="), onoff ? 1 : 0, ok_reply); } /********* HTTP HIGH LEVEL FUNCTIONS ***************************/ -boolean Adafruit_FONA::HTTP_GET_start(char *url, uint16_t *status, +/** + * @brief + * + * @param url + * @param status + * @param datalen + * @return true + * @return false + */ +bool Adafruit_FONA::HTTP_GET_start(char *url, uint16_t *status, uint16_t *datalen) { if (!HTTP_setup(url)) return false; @@ -1650,7 +2110,7 @@ boolean Adafruit_FONA::HTTP_GET_start(char *url, uint16_t *status, } /* -boolean Adafruit_FONA_3G::HTTP_GET_start(char *ipaddr, char *path, uint16_t port +bool Adafruit_FONA_3G::HTTP_GET_start(char *ipaddr, char *path, uint16_t port uint16_t *status, uint16_t *datalen){ char send[100] = "AT+CHTTPACT=\""; char *sendp = send + strlen(send); @@ -1687,7 +2147,19 @@ boolean Adafruit_FONA_3G::HTTP_GET_start(char *ipaddr, char *path, uint16_t port void Adafruit_FONA::HTTP_GET_end(void) { HTTP_term(); } -boolean Adafruit_FONA::HTTP_POST_start(char *url, +/** + * @brief + * + * @param url + * @param contenttype + * @param postdata + * @param postdatalen + * @param status + * @param datalen + * @return true + * @return false + */ +bool Adafruit_FONA::HTTP_POST_start(char *url, FONAFlashStringPtr contenttype, const uint8_t *postdata, uint16_t postdatalen, uint16_t *status, @@ -1728,11 +2200,18 @@ void Adafruit_FONA::setUserAgent(FONAFlashStringPtr useragent) { this->useragent = useragent; } -void Adafruit_FONA::setHTTPSRedirect(boolean onoff) { httpsredirect = onoff; } +void Adafruit_FONA::setHTTPSRedirect(bool onoff) { httpsredirect = onoff; } /********* HTTP HELPERS ****************************************/ -boolean Adafruit_FONA::HTTP_setup(char *url) { +/** + * @brief + * + * @param url + * @return true + * @return false + */ +bool Adafruit_FONA::HTTP_setup(char *url) { // Handle any pending HTTP_term(); @@ -1760,7 +2239,15 @@ boolean Adafruit_FONA::HTTP_setup(char *url) { /********* HELPERS *********************************************/ -boolean Adafruit_FONA::expectReply(FONAFlashStringPtr reply, uint16_t timeout) { +/** + * @brief + * + * @param reply + * @param timeout + * @return true + * @return false + */ +bool Adafruit_FONA::expectReply(FONAFlashStringPtr reply, uint16_t timeout) { readline(timeout); DEBUG_PRINT(F("\t<--- ")); @@ -1808,7 +2295,7 @@ uint16_t Adafruit_FONA::readRaw(uint16_t b) { return idx; } -uint8_t Adafruit_FONA::readline(uint16_t timeout, boolean multiline) { +uint8_t Adafruit_FONA::readline(uint16_t timeout, bool multiline) { uint16_t replyidx = 0; while (timeout--) { @@ -1970,7 +2457,16 @@ uint8_t Adafruit_FONA::getReplyQuoted(FONAFlashStringPtr prefix, return l; } -boolean Adafruit_FONA::sendCheckReply(char *send, char *reply, +/** + * @brief + * + * @param send + * @param reply + * @param timeout + * @return true + * @return false + */ +bool Adafruit_FONA::sendCheckReply(char *send, char *reply, uint16_t timeout) { if (!getReply(send, timeout)) return false; @@ -1987,7 +2483,16 @@ boolean Adafruit_FONA::sendCheckReply(char *send, char *reply, return (strcmp(replybuffer, reply) == 0); } -boolean Adafruit_FONA::sendCheckReply(FONAFlashStringPtr send, +/** + * @brief + * + * @param send + * @param reply + * @param timeout + * @return true + * @return false + */ +bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr send, FONAFlashStringPtr reply, uint16_t timeout) { if (!getReply(send, timeout)) @@ -1996,7 +2501,16 @@ boolean Adafruit_FONA::sendCheckReply(FONAFlashStringPtr send, return (prog_char_strcmp(replybuffer, (prog_char *)reply) == 0); } -boolean Adafruit_FONA::sendCheckReply(char *send, FONAFlashStringPtr reply, +/** + * @brief + * + * @param send + * @param reply + * @param timeout + * @return true + * @return false + */ +bool Adafruit_FONA::sendCheckReply(char *send, FONAFlashStringPtr reply, uint16_t timeout) { if (!getReply(send, timeout)) return false; @@ -2005,7 +2519,18 @@ boolean Adafruit_FONA::sendCheckReply(char *send, FONAFlashStringPtr reply, // Send prefix, suffix, and newline. Verify FONA response matches reply // parameter. -boolean Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, char *suffix, + +/** + * @brief + * + * @param prefix + * @param suffix + * @param reply + * @param timeout + * @return true + * @return false + */ +bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, char *suffix, FONAFlashStringPtr reply, uint16_t timeout) { getReply(prefix, suffix, timeout); @@ -2014,7 +2539,18 @@ boolean Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, char *suffix, // Send prefix, suffix, and newline. Verify FONA response matches reply // parameter. -boolean Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix, + +/** + * @brief + * + * @param prefix + * @param suffix + * @param reply + * @param timeout + * @return true + * @return false + */ +bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix, FONAFlashStringPtr reply, uint16_t timeout) { getReply(prefix, suffix, timeout); @@ -2023,7 +2559,7 @@ boolean Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix, // Send prefix, suffix, suffix2, and newline. Verify FONA response matches // reply parameter. -boolean Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, +bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix1, int32_t suffix2, FONAFlashStringPtr reply, uint16_t timeout) { @@ -2033,7 +2569,7 @@ boolean Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, // Send prefix, ", suffix, ", and newline. Verify FONA response matches reply // parameter. -boolean Adafruit_FONA::sendCheckReplyQuoted(FONAFlashStringPtr prefix, +bool Adafruit_FONA::sendCheckReplyQuoted(FONAFlashStringPtr prefix, FONAFlashStringPtr suffix, FONAFlashStringPtr reply, uint16_t timeout) { @@ -2041,7 +2577,7 @@ boolean Adafruit_FONA::sendCheckReplyQuoted(FONAFlashStringPtr prefix, return (prog_char_strcmp(replybuffer, (prog_char *)reply) == 0); } -boolean Adafruit_FONA::parseReply(FONAFlashStringPtr toreply, uint16_t *v, +bool Adafruit_FONA::parseReply(FONAFlashStringPtr toreply, uint16_t *v, char divider, uint8_t index) { char *p = prog_char_strstr( replybuffer, (prog_char *)toreply); // get the pointer to the voltage @@ -2062,7 +2598,7 @@ boolean Adafruit_FONA::parseReply(FONAFlashStringPtr toreply, uint16_t *v, return true; } -boolean Adafruit_FONA::parseReply(FONAFlashStringPtr toreply, char *v, +bool Adafruit_FONA::parseReply(FONAFlashStringPtr toreply, char *v, char divider, uint8_t index) { uint8_t i = 0; char *p = prog_char_strstr(replybuffer, (prog_char *)toreply); @@ -2093,7 +2629,7 @@ boolean Adafruit_FONA::parseReply(FONAFlashStringPtr toreply, char *v, // quotes) to the specified character array (v). Only up to maxlen characters // are copied into the result buffer, so make sure to pass a large enough buffer // to handle the response. -boolean Adafruit_FONA::parseReplyQuoted(FONAFlashStringPtr toreply, char *v, +bool Adafruit_FONA::parseReplyQuoted(FONAFlashStringPtr toreply, char *v, int maxlen, char divider, uint8_t index) { uint8_t i = 0, j; @@ -2130,7 +2666,7 @@ boolean Adafruit_FONA::parseReplyQuoted(FONAFlashStringPtr toreply, char *v, return true; } -boolean Adafruit_FONA::sendParseReply(FONAFlashStringPtr tosend, +bool Adafruit_FONA::sendParseReply(FONAFlashStringPtr tosend, FONAFlashStringPtr toreply, uint16_t *v, char divider, uint8_t index) { getReply(tosend); @@ -2145,7 +2681,7 @@ boolean Adafruit_FONA::sendParseReply(FONAFlashStringPtr tosend, // needed for CBC and others -boolean Adafruit_FONA_3G::sendParseReply(FONAFlashStringPtr tosend, +bool Adafruit_FONA_3G::sendParseReply(FONAFlashStringPtr tosend, FONAFlashStringPtr toreply, float *f, char divider, uint8_t index) { getReply(tosend); @@ -2158,7 +2694,7 @@ boolean Adafruit_FONA_3G::sendParseReply(FONAFlashStringPtr tosend, return true; } -boolean Adafruit_FONA_3G::parseReply(FONAFlashStringPtr toreply, float *f, +bool Adafruit_FONA_3G::parseReply(FONAFlashStringPtr toreply, float *f, char divider, uint8_t index) { char *p = prog_char_strstr( replybuffer, (prog_char *)toreply); // get the pointer to the voltage From 1451f631194365e35cb70dfd2385165a8b4d33c4 Mon Sep 17 00:00:00 2001 From: siddacious Date: Thu, 26 Mar 2020 16:38:14 -0700 Subject: [PATCH 05/14] more progress --- Adafruit_FONA.cpp | 804 +++++++++++++++++++++++++--------------------- 1 file changed, 445 insertions(+), 359 deletions(-) diff --git a/Adafruit_FONA.cpp b/Adafruit_FONA.cpp index e808a10..fe74c32 100644 --- a/Adafruit_FONA.cpp +++ b/Adafruit_FONA.cpp @@ -44,7 +44,7 @@ Adafruit_FONA::Adafruit_FONA(int8_t rst) { uint8_t Adafruit_FONA::type(void) { return _type; } /** * @brief Connect to the cell module - * + * * @param port the serial connection to uset o connect * @return bool true on success, false if a connection cannot be made */ @@ -153,13 +153,13 @@ bool Adafruit_FONA::begin(Stream &port) { /********* Serial port ********************************************/ /** * @brief - * - * @param baud + * + * @param baud * @return bool true on suc */ /** * @brief Set the baud rate that the module will use - * + * * @param baud The new baud rate to set * @return true success * @return false failure @@ -172,13 +172,13 @@ bool Adafruit_FONA::setBaudrate(uint16_t baud) { /** * @brief Read the Real Time Clock - * - * @param year - * @param month - * @param date - * @param hr - * @param min - * @param sec + * + * @param year + * @param month + * @param date + * @param hr + * @param min + * @param sec * @return true success * @return false failure */ @@ -191,11 +191,11 @@ bool Adafruit_FONA::readRTC(uint8_t *year, uint8_t *month, uint8_t *date, DEBUG_PRINTLN(*year); } /** - * @brief - * - * @param i - * @return true - * @return false + * @brief + * + * @param i + * @return true success + * @return false failure */ bool Adafruit_FONA::enableRTC(uint8_t i) { if (!sendCheckReply(F("AT+CLTS="), i, ok_reply)) @@ -207,11 +207,11 @@ bool Adafruit_FONA::enableRTC(uint8_t i) { /* returns value in mV (uint16_t) */ /** - * @brief - * - * @param v - * @return true - * @return false + * @brief + * + * @param v + * @return true success + * @return false failure */ bool Adafruit_FONA::getBattVoltage(uint16_t *v) { return sendParseReply(F("AT+CBC"), F("+CBC: "), v, ',', 2); @@ -219,11 +219,11 @@ bool Adafruit_FONA::getBattVoltage(uint16_t *v) { /* returns value in mV (uint16_t) */ /** - * @brief - * - * @param v - * @return true - * @return false + * @brief + * + * @param v + * @return true success + * @return false failure */ bool Adafruit_FONA_3G::getBattVoltage(uint16_t *v) { float f; @@ -234,21 +234,21 @@ bool Adafruit_FONA_3G::getBattVoltage(uint16_t *v) { /* returns the percentage charge of battery as reported by sim800 */ /** - * @brief - * - * @param p - * @return true - * @return false + * @brief + * + * @param p + * @return true success + * @return false failure */ bool Adafruit_FONA::getBattPercent(uint16_t *p) { return sendParseReply(F("AT+CBC"), F("+CBC: "), p, ',', 1); } /** - * @brief - * - * @param v - * @return true - * @return false + * @brief + * + * @param v + * @return true success + * @return false failure */ bool Adafruit_FONA::getADCVoltage(uint16_t *v) { return sendParseReply(F("AT+CADC?"), F("+CADC: 1,"), v); @@ -258,9 +258,9 @@ bool Adafruit_FONA::getADCVoltage(uint16_t *v) { /** * @brief Unlock the sim with a provided PIN - * + * * @param pin The pin to use to unlock the SIM - * @return uint8_t + * @return uint8_t */ uint8_t Adafruit_FONA::unlockSIM(char *pin) { char sendbuff[14] = "AT+CPIN="; @@ -274,10 +274,10 @@ uint8_t Adafruit_FONA::unlockSIM(char *pin) { } /** - * @brief - * - * @param ccid - * @return uint8_t + * @brief + * + * @param ccid + * @return uint8_t */ uint8_t Adafruit_FONA::getSIMCCID(char *ccid) { getReply(F("AT+CCID")); @@ -299,10 +299,10 @@ uint8_t Adafruit_FONA::getSIMCCID(char *ccid) { /********* IMEI **********************************************************/ /** - * @brief - * - * @param imei - * @return uint8_t + * @brief + * + * @param imei + * @return uint8_t */ uint8_t Adafruit_FONA::getIMEI(char *imei) { getReply(F("AT+GSN")); @@ -319,9 +319,9 @@ uint8_t Adafruit_FONA::getIMEI(char *imei) { /********* NETWORK *******************************************************/ /** - * @brief - * - * @return uint8_t + * @brief + * + * @return uint8_t */ uint8_t Adafruit_FONA::getNetworkStatus(void) { uint16_t status; @@ -344,9 +344,9 @@ uint8_t Adafruit_FONA::getRSSI(void) { /********* AUDIO *******************************************************/ /** - * @brief - * - * @param a + * @brief + * + * @param a * @return true success * @return false failure */ @@ -368,9 +368,9 @@ uint8_t Adafruit_FONA::getVolume(void) { } /** - * @brief - * - * @param i + * @brief + * + * @param i * @return true success * @return false failure */ @@ -379,9 +379,9 @@ bool Adafruit_FONA::setVolume(uint8_t i) { } /** - * @brief - * - * @param dtmf + * @brief + * + * @param dtmf * @return true success * @return false failure */ @@ -395,10 +395,10 @@ bool Adafruit_FONA::playDTMF(char dtmf) { } /** - * @brief - * - * @param t - * @param len + * @brief + * + * @param t + * @param len * @return true success * @return false failure */ @@ -406,10 +406,10 @@ bool Adafruit_FONA::playToolkitTone(uint8_t t, uint16_t len) { return sendCheckReply(F("AT+STTONE=1,"), t, len, ok_reply); } /** - * @brief - * - * @param t - * @param len + * @brief + * + * @param t + * @param len * @return true success * @return false failure */ @@ -421,10 +421,10 @@ bool Adafruit_FONA_3G::playToolkitTone(uint8_t t, uint16_t len) { } /** - * @brief - * - * @param a - * @param level + * @brief + * + * @param a + * @param level * @return true success * @return false failure */ @@ -439,10 +439,10 @@ bool Adafruit_FONA::setMicVolume(uint8_t a, uint8_t level) { /********* FM RADIO *******************************************************/ /** - * @brief - * - * @param onoff - * @param a + * @brief + * + * @param onoff + * @param a * @return true success * @return false failure */ @@ -459,9 +459,9 @@ bool Adafruit_FONA::FMradio(bool onoff, uint8_t a) { } /** - * @brief - * - * @param station + * @brief + * + * @param station * @return true success * @return false failure */ @@ -474,9 +474,9 @@ bool Adafruit_FONA::tuneFMradio(uint16_t station) { } /** - * @brief - * - * @param i + * @brief + * + * @param i * @return true success * @return false failure */ @@ -526,12 +526,12 @@ int8_t Adafruit_FONA::getFMSignalLevel(uint16_t station) { /********* PWM/BUZZER **************************************************/ /** - * @brief - * - * @param period - * @param duty + * @brief + * + * @param period + * @param duty * @return true success - * @return false failure + * @return false failure */ bool Adafruit_FONA::setPWM(uint16_t period, uint8_t duty) { if (period > 2000) @@ -545,9 +545,9 @@ bool Adafruit_FONA::setPWM(uint16_t period, uint8_t duty) { /********* CALL PHONES **************************************************/ /** - * @brief - * - * @param number + * @brief + * + * @param number * @return true success * @return false failure */ @@ -571,19 +571,19 @@ uint8_t Adafruit_FONA::getCallStatus(void) { return phoneStatus; // 0 ready, 2 unkown, 3 ringing, 4 call in progress } /** - * @brief - * - * @return true - * @return false + * @brief + * + * @return true success + * @return false failure */ bool Adafruit_FONA::hangUp(void) { return sendCheckReply(F("ATH0"), ok_reply); } /** - * @brief - * - * @return true - * @return false + * @brief + * + * @return true success + * @return false failure */ bool Adafruit_FONA_3G::hangUp(void) { getReply(F("ATH")); @@ -594,10 +594,10 @@ bool Adafruit_FONA_3G::hangUp(void) { /** - * @brief - * - * @return true - * @return false + * @brief + * + * @return true success + * @return false failure */ bool Adafruit_FONA::pickUp(void) { return sendCheckReply(F("ATA"), ok_reply); @@ -605,10 +605,10 @@ bool Adafruit_FONA::pickUp(void) { /** - * @brief - * - * @return true - * @return false + * @brief + * + * @return true success + * @return false failure */ bool Adafruit_FONA_3G::pickUp(void) { return sendCheckReply(F("ATA"), F("VOICE CALL: BEGIN")); @@ -626,12 +626,12 @@ bool Adafruit_FONA::_incomingCall = false; /** - * @brief - * - * @param enable - * @param interrupt - * @return true - * @return false + * @brief + * + * @param enable + * @param interrupt + * @return true success + * @return false failure */ bool Adafruit_FONA::callerIdNotification(bool enable, uint8_t interrupt) { if (enable) { @@ -644,11 +644,11 @@ bool Adafruit_FONA::callerIdNotification(bool enable, uint8_t interrupt) { } /** - * @brief - * - * @param phonenum - * @return true - * @return false + * @brief + * + * @param phonenum + * @return true success + * @return false failure */ bool Adafruit_FONA::incomingCallNumber(char *phonenum) { //+CLIP: "",145,"",0,"",0 @@ -684,11 +684,11 @@ uint8_t Adafruit_FONA::getSMSInterrupt(void) { } /** - * @brief - * - * @param i - * @return true - * @return false + * @brief + * + * @param i + * @return true success + * @return false failure */ bool Adafruit_FONA::setSMSInterrupt(uint8_t i) { return sendCheckReply(F("AT+CFGRI="), i, ok_reply); @@ -715,14 +715,14 @@ int8_t Adafruit_FONA::getNumSMS(void) { // or debug printouts! /** - * @brief - * - * @param i - * @param smsbuff - * @param maxlen - * @param readlen - * @return true - * @return false + * @brief + * + * @param i + * @param smsbuff + * @param maxlen + * @param readlen + * @return true success + * @return false failure */ bool Adafruit_FONA::readSMS(uint8_t i, char *smsbuff, uint16_t maxlen, uint16_t *readlen) { @@ -776,13 +776,13 @@ bool Adafruit_FONA::readSMS(uint8_t i, char *smsbuff, uint16_t maxlen, // otherwise false. /** - * @brief - * - * @param i - * @param sender - * @param senderlen - * @return true - * @return false + * @brief + * + * @param i + * @param sender + * @param senderlen + * @return true success + * @return false failure */ bool Adafruit_FONA::getSMSSender(uint8_t i, char *sender, int senderlen) { // Ensure text mode and all text mode parameters are sent. @@ -809,12 +809,12 @@ bool Adafruit_FONA::getSMSSender(uint8_t i, char *sender, int senderlen) { } /** - * @brief - * - * @param smsaddr - * @param smsmsg - * @return true - * @return false + * @brief + * + * @param smsaddr + * @param smsmsg + * @return true success + * @return false failure */ bool Adafruit_FONA::sendSMS(char *smsaddr, char *smsmsg) { if (!sendCheckReply(F("AT+CMGF=1"), ok_reply)) @@ -860,11 +860,11 @@ bool Adafruit_FONA::sendSMS(char *smsaddr, char *smsmsg) { } /** - * @brief - * - * @param i - * @return true - * @return false + * @brief + * + * @param i + * @return true success + * @return false failure */ bool Adafruit_FONA::deleteSMS(uint8_t i) { if (!sendCheckReply(F("AT+CMGF=1"), ok_reply)) @@ -883,14 +883,14 @@ bool Adafruit_FONA::deleteSMS(uint8_t i) { /********* USSD *********************************************************/ /** - * @brief - * - * @param ussdmsg - * @param ussdbuff - * @param maxlen - * @param readlen - * @return true - * @return false + * @brief + * + * @param ussdmsg + * @param ussdbuff + * @param maxlen + * @param readlen + * @return true success + * @return false failure */ bool Adafruit_FONA::sendUSSD(char *ussdmsg, char *ussdbuff, uint16_t maxlen, uint16_t *readlen) { @@ -935,11 +935,11 @@ bool Adafruit_FONA::sendUSSD(char *ussdmsg, char *ussdbuff, uint16_t maxlen, /********* TIME **********************************************************/ /** - * @brief - * - * @param onoff - * @return true - * @return false + * @brief + * + * @param onoff + * @return true success + * @return false failure */ bool Adafruit_FONA::enableNetworkTimeSync(bool onoff) { if (onoff) { @@ -956,12 +956,12 @@ bool Adafruit_FONA::enableNetworkTimeSync(bool onoff) { } /** - * @brief - * - * @param onoff - * @param ntpserver - * @return true - * @return false + * @brief + * + * @param onoff + * @param ntpserver + * @return true success + * @return false failure */ bool Adafruit_FONA::enableNTPTimeSync(bool onoff, FONAFlashStringPtr ntpserver) { @@ -996,12 +996,12 @@ bool Adafruit_FONA::enableNTPTimeSync(bool onoff, } /** - * @brief - * - * @param buff - * @param maxlen - * @return true - * @return false + * @brief + * + * @param buff + * @param maxlen + * @return true success + * @return false failure */ bool Adafruit_FONA::getTime(char *buff, uint16_t maxlen) { getReply(F("AT+CCLK?"), (uint16_t)10000); @@ -1021,11 +1021,11 @@ bool Adafruit_FONA::getTime(char *buff, uint16_t maxlen) { /********* GPS **********************************************************/ /** - * @brief - * - * @param onoff - * @return true - * @return false + * @brief + * + * @param onoff + * @return true success + * @return false failure */ bool Adafruit_FONA::enableGPS(bool onoff) { uint16_t state; @@ -1061,11 +1061,11 @@ bool Adafruit_FONA::enableGPS(bool onoff) { } /** - * @brief - * - * @param onoff - * @return true - * @return false + * @brief + * + * @param onoff + * @return true success + * @return false failure */ bool Adafruit_FONA_3G::enableGPS(bool onoff) { uint16_t state; @@ -1168,15 +1168,15 @@ uint8_t Adafruit_FONA::getGPS(uint8_t arg, char *buffer, uint8_t maxbuff) { } /** - * @brief - * - * @param lat - * @param lon - * @param speed_kph - * @param heading - * @param altitude - * @return true - * @return false + * @brief + * + * @param lat + * @param lon + * @param speed_kph + * @param heading + * @param altitude + * @return true success + * @return false failure */ bool Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, float *heading, float *altitude) { @@ -1473,11 +1473,11 @@ bool Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, } /** - * @brief - * - * @param i - * @return true - * @return false + * @brief + * + * @param i + * @return true success + * @return false failure */ bool Adafruit_FONA::enableGPSNMEA(uint8_t i) { @@ -1501,11 +1501,11 @@ bool Adafruit_FONA::enableGPSNMEA(uint8_t i) { /********* GPRS **********************************************************/ /** - * @brief - * - * @param onoff - * @return true - * @return false + * @brief + * + * @param onoff + * @return true success + * @return false failure */ bool Adafruit_FONA::enableGPRS(bool onoff) { @@ -1602,11 +1602,11 @@ bool Adafruit_FONA::enableGPRS(bool onoff) { } /** - * @brief - * - * @param onoff - * @return true - * @return false + * @brief + * + * @param onoff + * @return true success + * @return false failure */ bool Adafruit_FONA_3G::enableGPRS(bool onoff) { @@ -1689,13 +1689,13 @@ void Adafruit_FONA::setGPRSNetworkSettings(FONAFlashStringPtr apn, } /** - * @brief - * - * @param errorcode - * @param buff - * @param maxlen - * @return true - * @return false + * @brief + * + * @param errorcode + * @param buff + * @param maxlen + * @return true success + * @return false failure */ bool Adafruit_FONA::getGSMLoc(uint16_t *errorcode, char *buff, uint16_t maxlen) { @@ -1715,12 +1715,12 @@ bool Adafruit_FONA::getGSMLoc(uint16_t *errorcode, char *buff, } /** - * @brief - * - * @param lat - * @param lon - * @return true - * @return false + * @brief + * + * @param lat + * @param lon + * @return true success + * @return false failure */ bool Adafruit_FONA::getGSMLoc(float *lat, float *lon) { @@ -1753,14 +1753,14 @@ bool Adafruit_FONA::getGSMLoc(float *lat, float *lon) { /********* TCP FUNCTIONS ************************************/ /** - * @brief - * - * @param server - * @param port - * @return true - * @return false + * @brief + * + * @param server + * @param port + * @return true success + * @return false failure */ - + bool Adafruit_FONA::TCPconnect(char *server, uint16_t port) { flushInput(); @@ -1798,20 +1798,20 @@ bool Adafruit_FONA::TCPconnect(char *server, uint16_t port) { } /** - * @brief - * - * @return true - * @return false + * @brief + * + * @return true success + * @return false failure */ bool Adafruit_FONA::TCPclose(void) { return sendCheckReply(F("AT+CIPCLOSE"), ok_reply); } /** - * @brief - * - * @return true - * @return false + * @brief + * + * @return true success + * @return false failure */ bool Adafruit_FONA::TCPconnected(void) { if (!sendCheckReply(F("AT+CIPSTATUS"), ok_reply, 100)) @@ -1825,12 +1825,12 @@ bool Adafruit_FONA::TCPconnected(void) { } /** - * @brief - * - * @param packet - * @param len - * @return true - * @return false + * @brief + * + * @param packet + * @param len + * @return true success + * @return false failure */ bool Adafruit_FONA::TCPsend(char *packet, uint8_t len) { @@ -1904,20 +1904,20 @@ uint16_t Adafruit_FONA::TCPread(uint8_t *buff, uint8_t len) { /********* HTTP LOW LEVEL FUNCTIONS ************************************/ /** - * @brief - * - * @return true - * @return false + * @brief + * + * @return true success + * @return false failure */ bool Adafruit_FONA::HTTP_init() { return sendCheckReply(F("AT+HTTPINIT"), ok_reply); } /** - * @brief - * - * @return true - * @return false + * @brief + * + * @return true success + * @return false failure */ bool Adafruit_FONA::HTTP_term() { return sendCheckReply(F("AT+HTTPTERM"), ok_reply); @@ -1941,11 +1941,11 @@ void Adafruit_FONA::HTTP_para_start(FONAFlashStringPtr parameter, } /** - * @brief - * - * @param quoted - * @return true - * @return false + * @brief + * + * @param quoted + * @return true success + * @return false failure */ bool Adafruit_FONA::HTTP_para_end(bool quoted) { if (quoted) @@ -1957,12 +1957,12 @@ bool Adafruit_FONA::HTTP_para_end(bool quoted) { } /** - * @brief - * - * @param parameter - * @param value - * @return true - * @return false + * @brief + * + * @param parameter + * @param value + * @return true success + * @return false failure */ bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, const char *value) { @@ -1972,12 +1972,12 @@ bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, } /** - * @brief - * - * @param parameter - * @param value - * @return true - * @return false + * @brief + * + * @param parameter + * @param value + * @return true success + * @return false failure */ bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, FONAFlashStringPtr value) { @@ -1987,12 +1987,12 @@ bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, } /** - * @brief - * - * @param parameter - * @param value - * @return true - * @return false + * @brief + * + * @param parameter + * @param value + * @return true success + * @return false failure */ bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, int32_t value) { HTTP_para_start(parameter, false); @@ -2001,12 +2001,12 @@ bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, int32_t value) { } /** - * @brief - * - * @param size - * @param maxTime - * @return true - * @return false + * @brief + * + * @param size + * @param maxTime + * @return true success + * @return false failure */ bool Adafruit_FONA::HTTP_data(uint32_t size, uint32_t maxTime) { flushInput(); @@ -2026,14 +2026,14 @@ bool Adafruit_FONA::HTTP_data(uint32_t size, uint32_t maxTime) { } /** - * @brief - * - * @param method - * @param status - * @param datalen - * @param timeout - * @return true - * @return false + * @brief + * + * @param method + * @param status + * @param datalen + * @param timeout + * @return true success + * @return false failure */ bool Adafruit_FONA::HTTP_action(uint8_t method, uint16_t *status, uint16_t *datalen, int32_t timeout) { @@ -2052,11 +2052,11 @@ bool Adafruit_FONA::HTTP_action(uint8_t method, uint16_t *status, } /** - * @brief - * - * @param datalen - * @return true - * @return false + * @brief + * + * @param datalen + * @return true success + * @return false failure */ bool Adafruit_FONA::HTTP_readall(uint16_t *datalen) { getReply(F("AT+HTTPREAD")); @@ -2067,11 +2067,11 @@ bool Adafruit_FONA::HTTP_readall(uint16_t *datalen) { } /** - * @brief - * - * @param onoff - * @return true - * @return false + * @brief + * + * @param onoff + * @return true success + * @return false failure */ bool Adafruit_FONA::HTTP_ssl(bool onoff) { return sendCheckReply(F("AT+HTTPSSL="), onoff ? 1 : 0, ok_reply); @@ -2080,13 +2080,13 @@ bool Adafruit_FONA::HTTP_ssl(bool onoff) { /********* HTTP HIGH LEVEL FUNCTIONS ***************************/ /** - * @brief - * - * @param url - * @param status - * @param datalen - * @return true - * @return false + * @brief + * + * @param url + * @param status + * @param datalen + * @return true success + * @return false failure */ bool Adafruit_FONA::HTTP_GET_start(char *url, uint16_t *status, uint16_t *datalen) { @@ -2148,16 +2148,16 @@ bool Adafruit_FONA_3G::HTTP_GET_start(char *ipaddr, char *path, uint16_t port void Adafruit_FONA::HTTP_GET_end(void) { HTTP_term(); } /** - * @brief - * - * @param url - * @param contenttype - * @param postdata - * @param postdatalen - * @param status - * @param datalen - * @return true - * @return false + * @brief + * + * @param url + * @param contenttype + * @param postdata + * @param postdatalen + * @param status + * @param datalen + * @return true success + * @return false failure */ bool Adafruit_FONA::HTTP_POST_start(char *url, FONAFlashStringPtr contenttype, @@ -2205,11 +2205,11 @@ void Adafruit_FONA::setHTTPSRedirect(bool onoff) { httpsredirect = onoff; } /********* HTTP HELPERS ****************************************/ /** - * @brief - * - * @param url - * @return true - * @return false + * @brief + * + * @param url + * @return true success + * @return false failure */ bool Adafruit_FONA::HTTP_setup(char *url) { // Handle any pending @@ -2240,12 +2240,12 @@ bool Adafruit_FONA::HTTP_setup(char *url) { /********* HELPERS *********************************************/ /** - * @brief - * - * @param reply - * @param timeout - * @return true - * @return false + * @brief + * + * @param reply + * @param timeout + * @return true success + * @return false failure */ bool Adafruit_FONA::expectReply(FONAFlashStringPtr reply, uint16_t timeout) { readline(timeout); @@ -2458,13 +2458,13 @@ uint8_t Adafruit_FONA::getReplyQuoted(FONAFlashStringPtr prefix, } /** - * @brief - * - * @param send - * @param reply - * @param timeout - * @return true - * @return false + * @brief + * + * @param send + * @param reply + * @param timeout + * @return true success + * @return false failure */ bool Adafruit_FONA::sendCheckReply(char *send, char *reply, uint16_t timeout) { @@ -2484,13 +2484,13 @@ bool Adafruit_FONA::sendCheckReply(char *send, char *reply, } /** - * @brief - * - * @param send - * @param reply - * @param timeout - * @return true - * @return false + * @brief + * + * @param send + * @param reply + * @param timeout + * @return true success + * @return false failure */ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr send, FONAFlashStringPtr reply, @@ -2502,13 +2502,13 @@ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr send, } /** - * @brief - * - * @param send - * @param reply - * @param timeout - * @return true - * @return false + * @brief + * + * @param send + * @param reply + * @param timeout + * @return true success + * @return false failure */ bool Adafruit_FONA::sendCheckReply(char *send, FONAFlashStringPtr reply, uint16_t timeout) { @@ -2521,14 +2521,14 @@ bool Adafruit_FONA::sendCheckReply(char *send, FONAFlashStringPtr reply, // parameter. /** - * @brief - * - * @param prefix - * @param suffix - * @param reply - * @param timeout - * @return true - * @return false + * @brief + * + * @param prefix + * @param suffix + * @param reply + * @param timeout + * @return true success + * @return false failure */ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, char *suffix, FONAFlashStringPtr reply, @@ -2541,14 +2541,14 @@ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, char *suffix, // parameter. /** - * @brief - * - * @param prefix - * @param suffix - * @param reply - * @param timeout - * @return true - * @return false + * @brief + * + * @param prefix + * @param suffix + * @param reply + * @param timeout + * @return true success + * @return false failure */ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix, FONAFlashStringPtr reply, @@ -2559,6 +2559,18 @@ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix, // Send prefix, suffix, suffix2, and newline. Verify FONA response matches // reply parameter. + +/** + * @brief + * + * @param prefix + * @param suffix1 + * @param suffix2 + * @param reply + * @param timeout + * @return true success + * @return false failure + */ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix1, int32_t suffix2, FONAFlashStringPtr reply, @@ -2569,6 +2581,17 @@ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, // Send prefix, ", suffix, ", and newline. Verify FONA response matches reply // parameter. + +/** + * @brief + * + * @param prefix + * @param suffix + * @param reply + * @param timeout + * @return true success + * @return false failure + */ bool Adafruit_FONA::sendCheckReplyQuoted(FONAFlashStringPtr prefix, FONAFlashStringPtr suffix, FONAFlashStringPtr reply, @@ -2577,6 +2600,16 @@ bool Adafruit_FONA::sendCheckReplyQuoted(FONAFlashStringPtr prefix, return (prog_char_strcmp(replybuffer, (prog_char *)reply) == 0); } +/** + * @brief + * + * @param toreply + * @param v + * @param divider + * @param index + * @return true success + * @return false failure + */ bool Adafruit_FONA::parseReply(FONAFlashStringPtr toreply, uint16_t *v, char divider, uint8_t index) { char *p = prog_char_strstr( @@ -2598,6 +2631,16 @@ bool Adafruit_FONA::parseReply(FONAFlashStringPtr toreply, uint16_t *v, return true; } +/** + * @brief + * + * @param toreply + * @param v + * @param divider + * @param index + * @return true success + * @return false failure + */ bool Adafruit_FONA::parseReply(FONAFlashStringPtr toreply, char *v, char divider, uint8_t index) { uint8_t i = 0; @@ -2629,6 +2672,17 @@ bool Adafruit_FONA::parseReply(FONAFlashStringPtr toreply, char *v, // quotes) to the specified character array (v). Only up to maxlen characters // are copied into the result buffer, so make sure to pass a large enough buffer // to handle the response. +/** + * @brief + * + * @param toreply + * @param v + * @param maxlen + * @param divider + * @param index + * @return true success + * @return false failure + */ bool Adafruit_FONA::parseReplyQuoted(FONAFlashStringPtr toreply, char *v, int maxlen, char divider, uint8_t index) { @@ -2666,6 +2720,17 @@ bool Adafruit_FONA::parseReplyQuoted(FONAFlashStringPtr toreply, char *v, return true; } +/** + * @brief + * + * @param tosend + * @param toreply + * @param v + * @param divider + * @param index + * @return true success + * @return false failure + */ bool Adafruit_FONA::sendParseReply(FONAFlashStringPtr tosend, FONAFlashStringPtr toreply, uint16_t *v, char divider, uint8_t index) { @@ -2681,6 +2746,17 @@ bool Adafruit_FONA::sendParseReply(FONAFlashStringPtr tosend, // needed for CBC and others +/** + * @brief + * + * @param tosend + * @param toreply + * @param f + * @param divider + * @param index + * @return true success + * @return false failure + */ bool Adafruit_FONA_3G::sendParseReply(FONAFlashStringPtr tosend, FONAFlashStringPtr toreply, float *f, char divider, uint8_t index) { @@ -2694,6 +2770,16 @@ bool Adafruit_FONA_3G::sendParseReply(FONAFlashStringPtr tosend, return true; } +/** + * @brief + * + * @param toreply + * @param f + * @param divider + * @param index + * @return true success + * @return false failure + */ bool Adafruit_FONA_3G::parseReply(FONAFlashStringPtr toreply, float *f, char divider, uint8_t index) { char *p = prog_char_strstr( From 6f7deec805810de80a036ab2d185d5759a05a4fe Mon Sep 17 00:00:00 2001 From: siddacious Date: Thu, 26 Mar 2020 17:17:55 -0700 Subject: [PATCH 06/14] formatiing and more progress --- Adafruit_FONA.cpp | 88 ++++++++---------- Adafruit_FONA.h | 227 +++++++++++++++++++++++----------------------- 2 files changed, 149 insertions(+), 166 deletions(-) diff --git a/Adafruit_FONA.cpp b/Adafruit_FONA.cpp index fe74c32..3fc1eab 100644 --- a/Adafruit_FONA.cpp +++ b/Adafruit_FONA.cpp @@ -183,7 +183,7 @@ bool Adafruit_FONA::setBaudrate(uint16_t baud) { * @return false failure */ bool Adafruit_FONA::readRTC(uint8_t *year, uint8_t *month, uint8_t *date, - uint8_t *hr, uint8_t *min, uint8_t *sec) { + uint8_t *hr, uint8_t *min, uint8_t *sec) { uint16_t v; sendParseReply(F("AT+CCLK?"), F("+CCLK: "), &v, '/', 0); *year = v; @@ -576,9 +576,7 @@ uint8_t Adafruit_FONA::getCallStatus(void) { * @return true success * @return false failure */ -bool Adafruit_FONA::hangUp(void) { - return sendCheckReply(F("ATH0"), ok_reply); -} +bool Adafruit_FONA::hangUp(void) { return sendCheckReply(F("ATH0"), ok_reply); } /** * @brief * @@ -592,17 +590,13 @@ bool Adafruit_FONA_3G::hangUp(void) { 0); } - /** * @brief * * @return true success * @return false failure */ -bool Adafruit_FONA::pickUp(void) { - return sendCheckReply(F("ATA"), ok_reply); -} - +bool Adafruit_FONA::pickUp(void) { return sendCheckReply(F("ATA"), ok_reply); } /** * @brief @@ -624,7 +618,6 @@ void Adafruit_FONA::onIncomingCall() { bool Adafruit_FONA::_incomingCall = false; - /** * @brief * @@ -725,7 +718,7 @@ int8_t Adafruit_FONA::getNumSMS(void) { * @return false failure */ bool Adafruit_FONA::readSMS(uint8_t i, char *smsbuff, uint16_t maxlen, - uint16_t *readlen) { + uint16_t *readlen) { // text mode if (!sendCheckReply(F("AT+CMGF=1"), ok_reply)) return false; @@ -893,7 +886,7 @@ bool Adafruit_FONA::deleteSMS(uint8_t i) { * @return false failure */ bool Adafruit_FONA::sendUSSD(char *ussdmsg, char *ussdbuff, uint16_t maxlen, - uint16_t *readlen) { + uint16_t *readlen) { if (!sendCheckReply(F("AT+CUSD=1"), ok_reply)) return false; @@ -964,7 +957,7 @@ bool Adafruit_FONA::enableNetworkTimeSync(bool onoff) { * @return false failure */ bool Adafruit_FONA::enableNTPTimeSync(bool onoff, - FONAFlashStringPtr ntpserver) { + FONAFlashStringPtr ntpserver) { if (onoff) { if (!sendCheckReply(F("AT+CNTPCID=1"), ok_reply)) return false; @@ -1179,7 +1172,7 @@ uint8_t Adafruit_FONA::getGPS(uint8_t arg, char *buffer, uint8_t maxbuff) { * @return false failure */ bool Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, - float *heading, float *altitude) { + float *heading, float *altitude) { char gpsbuffer[120]; @@ -1698,7 +1691,7 @@ void Adafruit_FONA::setGPRSNetworkSettings(FONAFlashStringPtr apn, * @return false failure */ bool Adafruit_FONA::getGSMLoc(uint16_t *errorcode, char *buff, - uint16_t maxlen) { + uint16_t maxlen) { getReply(F("AT+CIPGSMLOC=1,1"), (uint16_t)10000); @@ -1923,8 +1916,7 @@ bool Adafruit_FONA::HTTP_term() { return sendCheckReply(F("AT+HTTPTERM"), ok_reply); } -void Adafruit_FONA::HTTP_para_start(FONAFlashStringPtr parameter, - bool quoted) { +void Adafruit_FONA::HTTP_para_start(FONAFlashStringPtr parameter, bool quoted) { flushInput(); DEBUG_PRINT(F("\t---> ")); @@ -1964,8 +1956,7 @@ bool Adafruit_FONA::HTTP_para_end(bool quoted) { * @return true success * @return false failure */ -bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, - const char *value) { +bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, const char *value) { HTTP_para_start(parameter, true); mySerial->print(value); return HTTP_para_end(true); @@ -1980,7 +1971,7 @@ bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, * @return false failure */ bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, - FONAFlashStringPtr value) { + FONAFlashStringPtr value) { HTTP_para_start(parameter, true); mySerial->print(value); return HTTP_para_end(true); @@ -2036,7 +2027,7 @@ bool Adafruit_FONA::HTTP_data(uint32_t size, uint32_t maxTime) { * @return false failure */ bool Adafruit_FONA::HTTP_action(uint8_t method, uint16_t *status, - uint16_t *datalen, int32_t timeout) { + uint16_t *datalen, int32_t timeout) { // Send request. if (!sendCheckReply(F("AT+HTTPACTION="), method, ok_reply)) return false; @@ -2089,7 +2080,7 @@ bool Adafruit_FONA::HTTP_ssl(bool onoff) { * @return false failure */ bool Adafruit_FONA::HTTP_GET_start(char *url, uint16_t *status, - uint16_t *datalen) { + uint16_t *datalen) { if (!HTTP_setup(url)) return false; @@ -2159,11 +2150,10 @@ void Adafruit_FONA::HTTP_GET_end(void) { HTTP_term(); } * @return true success * @return false failure */ -bool Adafruit_FONA::HTTP_POST_start(char *url, - FONAFlashStringPtr contenttype, - const uint8_t *postdata, - uint16_t postdatalen, uint16_t *status, - uint16_t *datalen) { +bool Adafruit_FONA::HTTP_POST_start(char *url, FONAFlashStringPtr contenttype, + const uint8_t *postdata, + uint16_t postdatalen, uint16_t *status, + uint16_t *datalen) { if (!HTTP_setup(url)) return false; @@ -2466,8 +2456,7 @@ uint8_t Adafruit_FONA::getReplyQuoted(FONAFlashStringPtr prefix, * @return true success * @return false failure */ -bool Adafruit_FONA::sendCheckReply(char *send, char *reply, - uint16_t timeout) { +bool Adafruit_FONA::sendCheckReply(char *send, char *reply, uint16_t timeout) { if (!getReply(send, timeout)) return false; /* @@ -2493,8 +2482,7 @@ bool Adafruit_FONA::sendCheckReply(char *send, char *reply, * @return false failure */ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr send, - FONAFlashStringPtr reply, - uint16_t timeout) { + FONAFlashStringPtr reply, uint16_t timeout) { if (!getReply(send, timeout)) return false; @@ -2511,7 +2499,7 @@ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr send, * @return false failure */ bool Adafruit_FONA::sendCheckReply(char *send, FONAFlashStringPtr reply, - uint16_t timeout) { + uint16_t timeout) { if (!getReply(send, timeout)) return false; return (prog_char_strcmp(replybuffer, (prog_char *)reply) == 0); @@ -2531,8 +2519,7 @@ bool Adafruit_FONA::sendCheckReply(char *send, FONAFlashStringPtr reply, * @return false failure */ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, char *suffix, - FONAFlashStringPtr reply, - uint16_t timeout) { + FONAFlashStringPtr reply, uint16_t timeout) { getReply(prefix, suffix, timeout); return (prog_char_strcmp(replybuffer, (prog_char *)reply) == 0); } @@ -2551,8 +2538,7 @@ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, char *suffix, * @return false failure */ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix, - FONAFlashStringPtr reply, - uint16_t timeout) { + FONAFlashStringPtr reply, uint16_t timeout) { getReply(prefix, suffix, timeout); return (prog_char_strcmp(replybuffer, (prog_char *)reply) == 0); } @@ -2571,10 +2557,9 @@ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix, * @return true success * @return false failure */ -bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, - int32_t suffix1, int32_t suffix2, - FONAFlashStringPtr reply, - uint16_t timeout) { +bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix1, + int32_t suffix2, FONAFlashStringPtr reply, + uint16_t timeout) { getReply(prefix, suffix1, suffix2, timeout); return (prog_char_strcmp(replybuffer, (prog_char *)reply) == 0); } @@ -2593,9 +2578,9 @@ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, * @return false failure */ bool Adafruit_FONA::sendCheckReplyQuoted(FONAFlashStringPtr prefix, - FONAFlashStringPtr suffix, - FONAFlashStringPtr reply, - uint16_t timeout) { + FONAFlashStringPtr suffix, + FONAFlashStringPtr reply, + uint16_t timeout) { getReplyQuoted(prefix, suffix, timeout); return (prog_char_strcmp(replybuffer, (prog_char *)reply) == 0); } @@ -2611,7 +2596,7 @@ bool Adafruit_FONA::sendCheckReplyQuoted(FONAFlashStringPtr prefix, * @return false failure */ bool Adafruit_FONA::parseReply(FONAFlashStringPtr toreply, uint16_t *v, - char divider, uint8_t index) { + char divider, uint8_t index) { char *p = prog_char_strstr( replybuffer, (prog_char *)toreply); // get the pointer to the voltage if (p == 0) @@ -2642,7 +2627,7 @@ bool Adafruit_FONA::parseReply(FONAFlashStringPtr toreply, uint16_t *v, * @return false failure */ bool Adafruit_FONA::parseReply(FONAFlashStringPtr toreply, char *v, - char divider, uint8_t index) { + char divider, uint8_t index) { uint8_t i = 0; char *p = prog_char_strstr(replybuffer, (prog_char *)toreply); if (p == 0) @@ -2684,8 +2669,7 @@ bool Adafruit_FONA::parseReply(FONAFlashStringPtr toreply, char *v, * @return false failure */ bool Adafruit_FONA::parseReplyQuoted(FONAFlashStringPtr toreply, char *v, - int maxlen, char divider, - uint8_t index) { + int maxlen, char divider, uint8_t index) { uint8_t i = 0, j; // Verify response starts with toreply. char *p = prog_char_strstr(replybuffer, (prog_char *)toreply); @@ -2732,8 +2716,8 @@ bool Adafruit_FONA::parseReplyQuoted(FONAFlashStringPtr toreply, char *v, * @return false failure */ bool Adafruit_FONA::sendParseReply(FONAFlashStringPtr tosend, - FONAFlashStringPtr toreply, uint16_t *v, - char divider, uint8_t index) { + FONAFlashStringPtr toreply, uint16_t *v, + char divider, uint8_t index) { getReply(tosend); if (!parseReply(toreply, v, divider, index)) @@ -2758,8 +2742,8 @@ bool Adafruit_FONA::sendParseReply(FONAFlashStringPtr tosend, * @return false failure */ bool Adafruit_FONA_3G::sendParseReply(FONAFlashStringPtr tosend, - FONAFlashStringPtr toreply, float *f, - char divider, uint8_t index) { + FONAFlashStringPtr toreply, float *f, + char divider, uint8_t index) { getReply(tosend); if (!parseReply(toreply, f, divider, index)) @@ -2781,7 +2765,7 @@ bool Adafruit_FONA_3G::sendParseReply(FONAFlashStringPtr tosend, * @return false failure */ bool Adafruit_FONA_3G::parseReply(FONAFlashStringPtr toreply, float *f, - char divider, uint8_t index) { + char divider, uint8_t index) { char *p = prog_char_strstr( replybuffer, (prog_char *)toreply); // get the pointer to the voltage if (p == 0) diff --git a/Adafruit_FONA.h b/Adafruit_FONA.h index fef84ff..b6b914a 100644 --- a/Adafruit_FONA.h +++ b/Adafruit_FONA.h @@ -68,7 +68,7 @@ class Adafruit_FONA : public FONAStreamType { public: Adafruit_FONA(int8_t r); - boolean begin(FONAStreamType &port); + bool begin(FONAStreamType &port); uint8_t type(); // Stream @@ -79,17 +79,17 @@ class Adafruit_FONA : public FONAStreamType { void flush(); // FONA 3G requirements - boolean setBaudrate(uint16_t baud); + bool setBaudrate(uint16_t baud); // RTC - boolean enableRTC(uint8_t i); - boolean readRTC(uint8_t *year, uint8_t *month, uint8_t *date, uint8_t *hr, - uint8_t *min, uint8_t *sec); + bool enableRTC(uint8_t i); + bool readRTC(uint8_t *year, uint8_t *month, uint8_t *date, uint8_t *hr, + uint8_t *min, uint8_t *sec); // Battery and ADC - boolean getADCVoltage(uint16_t *v); - boolean getBattPercent(uint16_t *p); - boolean getBattVoltage(uint16_t *v); + bool getADCVoltage(uint16_t *v); + bool getBattPercent(uint16_t *p); + bool getBattVoltage(uint16_t *v); // SIM query uint8_t unlockSIM(char *pin); @@ -101,126 +101,126 @@ class Adafruit_FONA : public FONAStreamType { uint8_t getIMEI(char *imei); // set Audio output - boolean setAudio(uint8_t a); - boolean setVolume(uint8_t i); + bool setAudio(uint8_t a); + bool setVolume(uint8_t i); uint8_t getVolume(void); - boolean playToolkitTone(uint8_t t, uint16_t len); - boolean setMicVolume(uint8_t a, uint8_t level); - boolean playDTMF(char tone); + bool playToolkitTone(uint8_t t, uint16_t len); + bool setMicVolume(uint8_t a, uint8_t level); + bool playDTMF(char tone); // FM radio functions. - boolean tuneFMradio(uint16_t station); - boolean FMradio(boolean onoff, uint8_t a = FONA_HEADSETAUDIO); - boolean setFMVolume(uint8_t i); + bool tuneFMradio(uint16_t station); + bool FMradio(bool onoff, uint8_t a = FONA_HEADSETAUDIO); + bool setFMVolume(uint8_t i); int8_t getFMVolume(); int8_t getFMSignalLevel(uint16_t station); // SMS handling - boolean setSMSInterrupt(uint8_t i); + bool setSMSInterrupt(uint8_t i); uint8_t getSMSInterrupt(void); int8_t getNumSMS(void); - boolean readSMS(uint8_t i, char *smsbuff, uint16_t max, uint16_t *readsize); - boolean sendSMS(char *smsaddr, char *smsmsg); - boolean deleteSMS(uint8_t i); - boolean getSMSSender(uint8_t i, char *sender, int senderlen); - boolean sendUSSD(char *ussdmsg, char *ussdbuff, uint16_t maxlen, - uint16_t *readlen); + bool readSMS(uint8_t i, char *smsbuff, uint16_t max, uint16_t *readsize); + bool sendSMS(char *smsaddr, char *smsmsg); + bool deleteSMS(uint8_t i); + bool getSMSSender(uint8_t i, char *sender, int senderlen); + bool sendUSSD(char *ussdmsg, char *ussdbuff, uint16_t maxlen, + uint16_t *readlen); // Time - boolean enableNetworkTimeSync(boolean onoff); - boolean enableNTPTimeSync(boolean onoff, FONAFlashStringPtr ntpserver = 0); - boolean getTime(char *buff, uint16_t maxlen); + bool enableNetworkTimeSync(bool onoff); + bool enableNTPTimeSync(bool onoff, FONAFlashStringPtr ntpserver = 0); + bool getTime(char *buff, uint16_t maxlen); // GPRS handling - boolean enableGPRS(boolean onoff); + bool enableGPRS(bool onoff); uint8_t GPRSstate(void); - boolean getGSMLoc(uint16_t *replycode, char *buff, uint16_t maxlen); - boolean getGSMLoc(float *lat, float *lon); + bool getGSMLoc(uint16_t *replycode, char *buff, uint16_t maxlen); + bool getGSMLoc(float *lat, float *lon); void setGPRSNetworkSettings(FONAFlashStringPtr apn, FONAFlashStringPtr username = 0, FONAFlashStringPtr password = 0); // GPS handling - boolean enableGPS(boolean onoff); + bool enableGPS(bool onoff); int8_t GPSstatus(void); uint8_t getGPS(uint8_t arg, char *buffer, uint8_t maxbuff); - boolean getGPS(float *lat, float *lon, float *speed_kph = 0, - float *heading = 0, float *altitude = 0); - boolean enableGPSNMEA(uint8_t nmea); + bool getGPS(float *lat, float *lon, float *speed_kph = 0, float *heading = 0, + float *altitude = 0); + bool enableGPSNMEA(uint8_t nmea); // TCP raw connections - boolean TCPconnect(char *server, uint16_t port); - boolean TCPclose(void); - boolean TCPconnected(void); - boolean TCPsend(char *packet, uint8_t len); + bool TCPconnect(char *server, uint16_t port); + bool TCPclose(void); + bool TCPconnected(void); + bool TCPsend(char *packet, uint8_t len); uint16_t TCPavailable(void); uint16_t TCPread(uint8_t *buff, uint8_t len); // HTTP low level interface (maps directly to SIM800 commands). - boolean HTTP_init(); - boolean HTTP_term(); - void HTTP_para_start(FONAFlashStringPtr parameter, boolean quoted = true); - boolean HTTP_para_end(boolean quoted = true); - boolean HTTP_para(FONAFlashStringPtr parameter, const char *value); - boolean HTTP_para(FONAFlashStringPtr parameter, FONAFlashStringPtr value); - boolean HTTP_para(FONAFlashStringPtr parameter, int32_t value); - boolean HTTP_data(uint32_t size, uint32_t maxTime = 10000); - boolean HTTP_action(uint8_t method, uint16_t *status, uint16_t *datalen, - int32_t timeout = 10000); - boolean HTTP_readall(uint16_t *datalen); - boolean HTTP_ssl(boolean onoff); + bool HTTP_init(); + bool HTTP_term(); + void HTTP_para_start(FONAFlashStringPtr parameter, bool quoted = true); + bool HTTP_para_end(bool quoted = true); + bool HTTP_para(FONAFlashStringPtr parameter, const char *value); + bool HTTP_para(FONAFlashStringPtr parameter, FONAFlashStringPtr value); + bool HTTP_para(FONAFlashStringPtr parameter, int32_t value); + bool HTTP_data(uint32_t size, uint32_t maxTime = 10000); + bool HTTP_action(uint8_t method, uint16_t *status, uint16_t *datalen, + int32_t timeout = 10000); + bool HTTP_readall(uint16_t *datalen); + bool HTTP_ssl(bool onoff); // HTTP high level interface (easier to use, less flexible). - boolean HTTP_GET_start(char *url, uint16_t *status, uint16_t *datalen); + bool HTTP_GET_start(char *url, uint16_t *status, uint16_t *datalen); void HTTP_GET_end(void); - boolean HTTP_POST_start(char *url, FONAFlashStringPtr contenttype, - const uint8_t *postdata, uint16_t postdatalen, - uint16_t *status, uint16_t *datalen); + bool HTTP_POST_start(char *url, FONAFlashStringPtr contenttype, + const uint8_t *postdata, uint16_t postdatalen, + uint16_t *status, uint16_t *datalen); void HTTP_POST_end(void); void setUserAgent(FONAFlashStringPtr useragent); // HTTPS - void setHTTPSRedirect(boolean onoff); + void setHTTPSRedirect(bool onoff); // PWM (buzzer) - boolean setPWM(uint16_t period, uint8_t duty = 50); + bool setPWM(uint16_t period, uint8_t duty = 50); // Phone calls - boolean callPhone(char *phonenum); + bool callPhone(char *phonenum); uint8_t getCallStatus(void); - boolean hangUp(void); - boolean pickUp(void); - boolean callerIdNotification(boolean enable, uint8_t interrupt = 0); - boolean incomingCallNumber(char *phonenum); + bool hangUp(void); + bool pickUp(void); + bool callerIdNotification(bool enable, uint8_t interrupt = 0); + bool incomingCallNumber(char *phonenum); // Helper functions to verify responses. - boolean expectReply(FONAFlashStringPtr reply, uint16_t timeout = 10000); - boolean sendCheckReply(char *send, char *reply, - uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); - boolean sendCheckReply(FONAFlashStringPtr send, FONAFlashStringPtr reply, - uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); - boolean sendCheckReply(char *send, FONAFlashStringPtr reply, - uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); + bool expectReply(FONAFlashStringPtr reply, uint16_t timeout = 10000); + bool sendCheckReply(char *send, char *reply, + uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); + bool sendCheckReply(FONAFlashStringPtr send, FONAFlashStringPtr reply, + uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); + bool sendCheckReply(char *send, FONAFlashStringPtr reply, + uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); protected: - int8_t _rstpin; - uint8_t _type; + int8_t _rstpin; ///< Reset pin + uint8_t _type; ///< Module type - char replybuffer[255]; - FONAFlashStringPtr apn; - FONAFlashStringPtr apnusername; - FONAFlashStringPtr apnpassword; - boolean httpsredirect; - FONAFlashStringPtr useragent; - FONAFlashStringPtr ok_reply; + char replybuffer[255]; ///< buffer for holding replies from the module + FONAFlashStringPtr apn; ///< Access point name + FONAFlashStringPtr apnusername; ///< Access point username + FONAFlashStringPtr apnpassword; ///< Access point password + bool httpsredirect; ///< HTTPS redirect state + FONAFlashStringPtr useragent; ///< User agent used when making requests + FONAFlashStringPtr ok_reply; ///< OK reply for successful requests // HTTP helpers - boolean HTTP_setup(char *url); + bool HTTP_setup(char *url); void flushInput(); uint16_t readRaw(uint16_t b); uint8_t readline(uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS, - boolean multiline = false); + bool multiline = false); uint8_t getReply(char *send, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); uint8_t getReply(FONAFlashStringPtr send, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); @@ -234,34 +234,33 @@ class Adafruit_FONA : public FONAStreamType { uint8_t getReplyQuoted(FONAFlashStringPtr prefix, FONAFlashStringPtr suffix, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); - boolean sendCheckReply(FONAFlashStringPtr prefix, char *suffix, - FONAFlashStringPtr reply, - uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); - boolean sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix, - FONAFlashStringPtr reply, - uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); - boolean sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix, - int32_t suffix2, FONAFlashStringPtr reply, - uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); - boolean sendCheckReplyQuoted(FONAFlashStringPtr prefix, - FONAFlashStringPtr suffix, - FONAFlashStringPtr reply, - uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); - - boolean parseReply(FONAFlashStringPtr toreply, uint16_t *v, - char divider = ',', uint8_t index = 0); - boolean parseReply(FONAFlashStringPtr toreply, char *v, char divider = ',', - uint8_t index = 0); - boolean parseReplyQuoted(FONAFlashStringPtr toreply, char *v, int maxlen, - char divider, uint8_t index); - - boolean sendParseReply(FONAFlashStringPtr tosend, FONAFlashStringPtr toreply, - uint16_t *v, char divider = ',', uint8_t index = 0); - - static boolean _incomingCall; + bool sendCheckReply(FONAFlashStringPtr prefix, char *suffix, + FONAFlashStringPtr reply, + uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); + bool sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix, + FONAFlashStringPtr reply, + uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); + bool sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix, + int32_t suffix2, FONAFlashStringPtr reply, + uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); + bool sendCheckReplyQuoted(FONAFlashStringPtr prefix, + FONAFlashStringPtr suffix, FONAFlashStringPtr reply, + uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); + + bool parseReply(FONAFlashStringPtr toreply, uint16_t *v, char divider = ',', + uint8_t index = 0); + bool parseReply(FONAFlashStringPtr toreply, char *v, char divider = ',', + uint8_t index = 0); + bool parseReplyQuoted(FONAFlashStringPtr toreply, char *v, int maxlen, + char divider, uint8_t index); + + bool sendParseReply(FONAFlashStringPtr tosend, FONAFlashStringPtr toreply, + uint16_t *v, char divider = ',', uint8_t index = 0); + + static bool _incomingCall; ///< Incoming call state var static void onIncomingCall(); - FONAStreamType *mySerial; + FONAStreamType *mySerial; ///< Serial connection }; class Adafruit_FONA_3G : public Adafruit_FONA { @@ -269,19 +268,19 @@ class Adafruit_FONA_3G : public Adafruit_FONA { public: Adafruit_FONA_3G(int8_t r) : Adafruit_FONA(r) { _type = FONA3G_A; } - boolean getBattVoltage(uint16_t *v); - boolean playToolkitTone(uint8_t t, uint16_t len); - boolean hangUp(void); - boolean pickUp(void); - boolean enableGPRS(boolean onoff); - boolean enableGPS(boolean onoff); + bool getBattVoltage(uint16_t *v); + bool playToolkitTone(uint8_t t, uint16_t len); + bool hangUp(void); + bool pickUp(void); + bool enableGPRS(bool onoff); + bool enableGPS(bool onoff); protected: - boolean parseReply(FONAFlashStringPtr toreply, float *f, char divider, - uint8_t index); + bool parseReply(FONAFlashStringPtr toreply, float *f, char divider, + uint8_t index); - boolean sendParseReply(FONAFlashStringPtr tosend, FONAFlashStringPtr toreply, - float *f, char divider = ',', uint8_t index = 0); + bool sendParseReply(FONAFlashStringPtr tosend, FONAFlashStringPtr toreply, + float *f, char divider = ',', uint8_t index = 0); }; #endif From 48e5c3c48f993d454ce74f5ab16b22fd280b05af Mon Sep 17 00:00:00 2001 From: siddacious Date: Thu, 26 Mar 2020 17:21:42 -0700 Subject: [PATCH 07/14] more progress --- Adafruit_FONA.cpp | 7 +------ Adafruit_FONA.h | 4 +++- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Adafruit_FONA.cpp b/Adafruit_FONA.cpp index 3fc1eab..86c6aac 100644 --- a/Adafruit_FONA.cpp +++ b/Adafruit_FONA.cpp @@ -151,12 +151,7 @@ bool Adafruit_FONA::begin(Stream &port) { } /********* Serial port ********************************************/ -/** - * @brief - * - * @param baud - * @return bool true on suc - */ + /** * @brief Set the baud rate that the module will use * diff --git a/Adafruit_FONA.h b/Adafruit_FONA.h index b6b914a..c1251f7 100644 --- a/Adafruit_FONA.h +++ b/Adafruit_FONA.h @@ -65,6 +65,8 @@ #define FONA_CALL_RINGING 3 #define FONA_CALL_INPROGRESS 4 + +/** Object that controls and keeps state for the FONA module. */ class Adafruit_FONA : public FONAStreamType { public: Adafruit_FONA(int8_t r); @@ -262,7 +264,7 @@ class Adafruit_FONA : public FONAStreamType { FONAStreamType *mySerial; ///< Serial connection }; - +/** Object that controls and keeps state for a 3G FONA module. */ class Adafruit_FONA_3G : public Adafruit_FONA { public: From de66c3849fb1ade3b99cbd25d235bddaf7f35a57 Mon Sep 17 00:00:00 2001 From: siddacious Date: Thu, 26 Mar 2020 19:13:25 -0700 Subject: [PATCH 08/14] saving progress --- Adafruit_FONA.cpp | 504 +++++++++++++++++++++++++++++++--------------- Adafruit_FONA.h | 13 +- 2 files changed, 351 insertions(+), 166 deletions(-) diff --git a/Adafruit_FONA.cpp b/Adafruit_FONA.cpp index 86c6aac..04ccb0c 100644 --- a/Adafruit_FONA.cpp +++ b/Adafruit_FONA.cpp @@ -28,7 +28,11 @@ #include using namespace std; #endif - +/** + * @brief Construct a new Adafruit_FONA::Adafruit_FONA object + * + * @param rst The reset pin + */ Adafruit_FONA::Adafruit_FONA(int8_t rst) { _rstpin = rst; @@ -41,6 +45,11 @@ Adafruit_FONA::Adafruit_FONA(int8_t rst) { ok_reply = F("OK"); } +/** + * @brief Get the module type + * + * @return uint8_t The module type + */ uint8_t Adafruit_FONA::type(void) { return _type; } /** * @brief Connect to the cell module @@ -186,7 +195,7 @@ bool Adafruit_FONA::readRTC(uint8_t *year, uint8_t *month, uint8_t *date, DEBUG_PRINTLN(*year); } /** - * @brief + * @brief Enable the Real Time Clock * * @param i * @return true success @@ -200,11 +209,11 @@ bool Adafruit_FONA::enableRTC(uint8_t i) { /********* BATTERY & ADC ********************************************/ -/* returns value in mV (uint16_t) */ +/* returns */ /** - * @brief + * @brief Get the current batery voltage * - * @param v + * @param v battery value pointer to be filled with the current value in mV (uint16_t) * @return true success * @return false failure */ @@ -214,9 +223,9 @@ bool Adafruit_FONA::getBattVoltage(uint16_t *v) { /* returns value in mV (uint16_t) */ /** - * @brief + * @brief Get the current batery voltage * - * @param v + * @param v battery voltage pointer to be filled with the current value in mV (uint16_t) * @return true success * @return false failure */ @@ -227,11 +236,11 @@ bool Adafruit_FONA_3G::getBattVoltage(uint16_t *v) { return b; } -/* returns the percentage charge of battery as reported by sim800 */ +/* */ /** - * @brief + * @brief Get the percentage charge of battery as reported by sim800 * - * @param p + * @param p battery percentage pointer * @return true success * @return false failure */ @@ -239,9 +248,9 @@ bool Adafruit_FONA::getBattPercent(uint16_t *p) { return sendParseReply(F("AT+CBC"), F("+CBC: "), p, ',', 1); } /** - * @brief + * @brief Get the current ADC voltage * - * @param v + * @param v ADC voltage pointer to be filled with the current value in mV (uint16_t) * @return true success * @return false failure */ @@ -254,7 +263,7 @@ bool Adafruit_FONA::getADCVoltage(uint16_t *v) { /** * @brief Unlock the sim with a provided PIN * - * @param pin The pin to use to unlock the SIM + * @param pin pointer to the pin buffer to use to unlock the SIM * @return uint8_t */ uint8_t Adafruit_FONA::unlockSIM(char *pin) { @@ -269,9 +278,9 @@ uint8_t Adafruit_FONA::unlockSIM(char *pin) { } /** - * @brief + * @brief Get the SIM CCID * - * @param ccid + * @param ccid pointer to ccid buffer * @return uint8_t */ uint8_t Adafruit_FONA::getSIMCCID(char *ccid) { @@ -294,9 +303,9 @@ uint8_t Adafruit_FONA::getSIMCCID(char *ccid) { /********* IMEI **********************************************************/ /** - * @brief + * @brief Get the IMEI * - * @param imei + * @param imei buffer * @return uint8_t */ uint8_t Adafruit_FONA::getIMEI(char *imei) { @@ -314,9 +323,9 @@ uint8_t Adafruit_FONA::getIMEI(char *imei) { /********* NETWORK *******************************************************/ /** - * @brief + * @brief Gets the current network status * - * @return uint8_t + * @return uint8_t The nework status */ uint8_t Adafruit_FONA::getNetworkStatus(void) { uint16_t status; @@ -326,7 +335,11 @@ uint8_t Adafruit_FONA::getNetworkStatus(void) { return status; } - +/** + * @brief get the current Received Signal Strength Indication + * + * @return uint8_t The current RSSI + */ uint8_t Adafruit_FONA::getRSSI(void) { uint16_t reply; @@ -339,20 +352,23 @@ uint8_t Adafruit_FONA::getRSSI(void) { /********* AUDIO *******************************************************/ /** - * @brief + * @brief Set the audio ouput * - * @param a + * @param audio_output The output to set. 0 is headset, 1 is external audio * @return true success * @return false failure */ -bool Adafruit_FONA::setAudio(uint8_t a) { - // 0 is headset, 1 is external audio +bool Adafruit_FONA::setAudio(uint8_t audio_output) { if (a > 1) return false; return sendCheckReply(F("AT+CHFA="), a, ok_reply); } - +/** + * @brief Get the current volume level + * + * @return uint8_t The current volume level + */ uint8_t Adafruit_FONA::getVolume(void) { uint16_t reply; @@ -363,9 +379,9 @@ uint8_t Adafruit_FONA::getVolume(void) { } /** - * @brief + * @brief Set the volume * - * @param i + * @param i The new volume to set * @return true success * @return false failure */ @@ -374,9 +390,9 @@ bool Adafruit_FONA::setVolume(uint8_t i) { } /** - * @brief + * @brief Play a DTMF/Key tone * - * @param dtmf + * @param dtmf The tone to play * @return true success * @return false failure */ @@ -390,10 +406,10 @@ bool Adafruit_FONA::playDTMF(char dtmf) { } /** - * @brief + * @brief Play a toolkit tone * - * @param t - * @param len + * @param t The tone to play + * @param len The tone length * @return true success * @return false failure */ @@ -401,10 +417,10 @@ bool Adafruit_FONA::playToolkitTone(uint8_t t, uint16_t len) { return sendCheckReply(F("AT+STTONE=1,"), t, len, ok_reply); } /** - * @brief + * @brief Play a toolkit tone * - * @param t - * @param len + * @param t The tone to play + * @param len The tone length * @return true success * @return false failure */ @@ -416,15 +432,16 @@ bool Adafruit_FONA_3G::playToolkitTone(uint8_t t, uint16_t len) { } /** - * @brief + * @brief Set the microphone gain + * * - * @param a - * @param level + * @param a Which microphone gain to set. 0 is headset, 1 is external audio + * @param level The new gain level * @return true success * @return false failure */ bool Adafruit_FONA::setMicVolume(uint8_t a, uint8_t level) { - // 0 is headset, 1 is external audio + if (a > 1) return false; @@ -434,10 +451,10 @@ bool Adafruit_FONA::setMicVolume(uint8_t a, uint8_t level) { /********* FM RADIO *******************************************************/ /** - * @brief + * @brief Turn the FM Radio on or off * - * @param onoff - * @param a + * @param onoff true; on false: off + * @param a The audio source to use. 0 is headset, 1 is external audio * @return true success * @return false failure */ @@ -446,7 +463,7 @@ bool Adafruit_FONA::FMradio(bool onoff, uint8_t a) { return sendCheckReply(F("AT+FMCLOSE"), ok_reply); } - // 0 is headset, 1 is external audio + if (a > 1) return false; @@ -454,9 +471,9 @@ bool Adafruit_FONA::FMradio(bool onoff, uint8_t a) { } /** - * @brief + * @brief Set the FM Radio station * - * @param station + * @param station The station to set the radio to * @return true success * @return false failure */ @@ -469,9 +486,9 @@ bool Adafruit_FONA::tuneFMradio(uint16_t station) { } /** - * @brief + * @brief Set the FM Radio Volume * - * @param i + * @param i The volume to set * @return true success * @return false failure */ @@ -483,8 +500,12 @@ bool Adafruit_FONA::setFMVolume(uint8_t i) { // Send FM volume command and verify response. return sendCheckReply(F("AT+FMVOLUME="), i, ok_reply); } - -int8_t Adafruit_FONA::getFMVolume() { +/** + * @brief Get the current volume level + * + * @return uint8_t The current volume level + */ +int8_t Adafruit_FONA::getFMVolume(void) { uint16_t level; if (!sendParseReply(F("AT+FMVOLUME?"), F("+FMVOLUME: "), &level)) @@ -492,9 +513,14 @@ int8_t Adafruit_FONA::getFMVolume() { return level; } - +/** + * @brief Gets the current FM signal level + * + * @param station The station to chek the signal level of + * @return int8_t The signal level of the given stations. -1 if FM station is outside allowed range. + */ int8_t Adafruit_FONA::getFMSignalLevel(uint16_t station) { - // Fail if FM station is outside allowed range. + if ((station < 875) || (station > 1080)) { return -1; } @@ -521,7 +547,7 @@ int8_t Adafruit_FONA::getFMSignalLevel(uint16_t station) { /********* PWM/BUZZER **************************************************/ /** - * @brief + * @brief Set the PWM Period and Duty Cycle * * @param period * @param duty @@ -540,9 +566,9 @@ bool Adafruit_FONA::setPWM(uint16_t period, uint8_t duty) { /********* CALL PHONES **************************************************/ /** - * @brief + * @brief Call a phone number * - * @param number + * @param number The phone number to call * @return true success * @return false failure */ @@ -557,23 +583,28 @@ bool Adafruit_FONA::callPhone(char *number) { return sendCheckReply(sendbuff, ok_reply); } +/** + * @brief Get the current call status + * + * @return uint8_t The call status: 0 ready, 1 failure, 2 unkown, 3 ringing, 4 call in progress + */ uint8_t Adafruit_FONA::getCallStatus(void) { uint16_t phoneStatus; if (!sendParseReply(F("AT+CPAS"), F("+CPAS: "), &phoneStatus)) return FONA_CALL_FAILED; // 1, since 0 is actually a known, good reply - return phoneStatus; // 0 ready, 2 unkown, 3 ringing, 4 call in progress + return phoneStatus; } /** - * @brief + * @brief End the current call * * @return true success * @return false failure */ bool Adafruit_FONA::hangUp(void) { return sendCheckReply(F("ATH0"), ok_reply); } /** - * @brief + * @brief End the current call * * @return true success * @return false failure @@ -586,7 +617,7 @@ bool Adafruit_FONA_3G::hangUp(void) { } /** - * @brief + * @brief Answer a call * * @return true success * @return false failure @@ -602,7 +633,10 @@ bool Adafruit_FONA::pickUp(void) { return sendCheckReply(F("ATA"), ok_reply); } bool Adafruit_FONA_3G::pickUp(void) { return sendCheckReply(F("ATA"), F("VOICE CALL: BEGIN")); } - +/** + * @brief On incoming call callback + * + */ void Adafruit_FONA::onIncomingCall() { DEBUG_PRINT(F("> ")); @@ -614,10 +648,10 @@ void Adafruit_FONA::onIncomingCall() { bool Adafruit_FONA::_incomingCall = false; /** - * @brief + * @brief Enable or disable caller ID * - * @param enable - * @param interrupt + * @param enable true to enable, false to disable + * @param interrupt The interrupt to attach * @return true success * @return false failure */ @@ -632,9 +666,9 @@ bool Adafruit_FONA::callerIdNotification(bool enable, uint8_t interrupt) { } /** - * @brief + * @brief Get the number of the incoming call * - * @param phonenum + * @param phonenum The incoming caller's phone number * @return true success * @return false failure */ @@ -662,6 +696,11 @@ bool Adafruit_FONA::incomingCallNumber(char *phonenum) { /********* SMS **********************************************************/ +/** + * @brief Get the current SMS Iterrupt + * + * @return uint8_t The reply + */ uint8_t Adafruit_FONA::getSMSInterrupt(void) { uint16_t reply; @@ -672,16 +711,20 @@ uint8_t Adafruit_FONA::getSMSInterrupt(void) { } /** - * @brief + * @brief Attach an interrupt for SMS notifications * - * @param i + * @param i The interrupt to set * @return true success * @return false failure */ bool Adafruit_FONA::setSMSInterrupt(uint8_t i) { return sendCheckReply(F("AT+CFGRI="), i, ok_reply); } - +/** + * @brief Get the number of SMS + * + * @return int8_t The SMS count. -1 on error + */ int8_t Adafruit_FONA::getNumSMS(void) { uint16_t numsms; @@ -703,12 +746,12 @@ int8_t Adafruit_FONA::getNumSMS(void) { // or debug printouts! /** - * @brief + * @brief Read an SMS message into a provided buffer * - * @param i - * @param smsbuff - * @param maxlen - * @param readlen + * @param i + * @param smsbuff SMS message buffer + * @param maxlen The maximum read length + * @param readlen The length read * @return true success * @return false failure */ @@ -757,18 +800,18 @@ bool Adafruit_FONA::readSMS(uint8_t i, char *smsbuff, uint16_t maxlen, return true; } -// Retrieve the sender of the specified SMS message and copy it as a string to -// the sender buffer. Up to senderlen characters of the sender will be copied -// and a null terminator will be added if less than senderlen charactesr are -// copied to the result. Returns true if a result was successfully retrieved, -// otherwise false. /** - * @brief + * @brief Retrieve the sender of the specified SMS message and copy it as a string to + * the sender buffer. Up to senderlen characters of the sender will be copied + * and a null terminator will be added if less than senderlen charactesr are + * copied to the result. Returns true if a result was successfully retrieved, + * otherwise false. + * * @param i - * @param sender - * @param senderlen + * @param sender The sender buffer + * @param senderlen the length to read * @return true success * @return false failure */ @@ -797,10 +840,10 @@ bool Adafruit_FONA::getSMSSender(uint8_t i, char *sender, int senderlen) { } /** - * @brief + * @brief Send an SMS Message from a buffer provided * - * @param smsaddr - * @param smsmsg + * @param smsaddr The SMS address buffer + * @param smsmsg The SMS message buffer * @return true success * @return false failure */ @@ -848,9 +891,9 @@ bool Adafruit_FONA::sendSMS(char *smsaddr, char *smsmsg) { } /** - * @brief + * @brief Delete an SMS Message * - * @param i + * @param i The message to delete * @return true success * @return false failure */ @@ -871,12 +914,12 @@ bool Adafruit_FONA::deleteSMS(uint8_t i) { /********* USSD *********************************************************/ /** - * @brief + * @brief Send USSD * - * @param ussdmsg - * @param ussdbuff - * @param maxlen - * @param readlen + * @param ussdmsg The USSD message buffer + * @param ussdbuff The USSD bufer + * @param maxlen The maximum read length + * @param readlen The length actually read * @return true success * @return false failure */ @@ -923,9 +966,9 @@ bool Adafruit_FONA::sendUSSD(char *ussdmsg, char *ussdbuff, uint16_t maxlen, /********* TIME **********************************************************/ /** - * @brief + * @brief Enable network time sync * - * @param onoff + * @param onoff true: enable false: disable * @return true success * @return false failure */ @@ -944,10 +987,10 @@ bool Adafruit_FONA::enableNetworkTimeSync(bool onoff) { } /** - * @brief + * @brief Enable NTP time sync * - * @param onoff - * @param ntpserver + * @param onoff true: enable false: disable + * @param ntpserver The NTP server buffer * @return true success * @return false failure */ @@ -984,10 +1027,10 @@ bool Adafruit_FONA::enableNTPTimeSync(bool onoff, } /** - * @brief + * @brief Get the current time * - * @param buff - * @param maxlen + * @param buff Time buffer + * @param maxlen maximum read length * @return true success * @return false failure */ @@ -1009,9 +1052,9 @@ bool Adafruit_FONA::getTime(char *buff, uint16_t maxlen) { /********* GPS **********************************************************/ /** - * @brief + * @brief Enable GPS * - * @param onoff + * @param onoff true: enable false: disable * @return true success * @return false failure */ @@ -1049,9 +1092,9 @@ bool Adafruit_FONA::enableGPS(bool onoff) { } /** - * @brief + * @brief Enable GPS * - * @param onoff + * @param onoff true: enable false: disable * @return true success * @return false failure */ @@ -1073,7 +1116,11 @@ bool Adafruit_FONA_3G::enableGPS(bool onoff) { } return true; } - +/** + * @brief Get teh GPS status + * + * @return int8_t The GPS status + */ int8_t Adafruit_FONA::GPSstatus(void) { if (_type == FONA808_V2) { // 808 V2 uses GNS commands and doesn't have an explicit 2D/3D fix status. @@ -1128,6 +1175,14 @@ int8_t Adafruit_FONA::GPSstatus(void) { return 0; } +/** + * @brief Fill a buffer with the current GPS reading + * + * @param arg The mode to use, where applicable + * @param buffer The buffer to be filled with the reading + * @param maxbuff the maximum amound to write into the buffer + * @return uint8_t The number of bytes read + */ uint8_t Adafruit_FONA::getGPS(uint8_t arg, char *buffer, uint8_t maxbuff) { int32_t x = arg; @@ -1156,13 +1211,13 @@ uint8_t Adafruit_FONA::getGPS(uint8_t arg, char *buffer, uint8_t maxbuff) { } /** - * @brief + * @brief Get a GPS reading * - * @param lat - * @param lon - * @param speed_kph - * @param heading - * @param altitude + * @param lat latitude pointer + * @param lon longitude pointer + * @param speed_kph speed pointer + * @param heading heading pointer + * @param altitude altitude pointer * @return true success * @return false failure */ @@ -1461,9 +1516,9 @@ bool Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, } /** - * @brief + * @brief Enable GPS NMEA * - * @param i + * @param i mode * @return true success * @return false failure */ @@ -1658,7 +1713,11 @@ bool Adafruit_FONA_3G::enableGPRS(bool onoff) { return true; } - +/** + * @brief Get the GPRS state + * + * @return uint8_t The GPRS state + */ uint8_t Adafruit_FONA::GPRSstate(void) { uint16_t state; @@ -1667,7 +1726,13 @@ uint8_t Adafruit_FONA::GPRSstate(void) { return state; } - +/** + * @brief Set the GPRS network settings + * + * @param apn Access point name + * @param username Username + * @param password Password + */ void Adafruit_FONA::setGPRSNetworkSettings(FONAFlashStringPtr apn, FONAFlashStringPtr username, FONAFlashStringPtr password) { @@ -1850,7 +1915,11 @@ bool Adafruit_FONA::TCPsend(char *packet, uint8_t len) { return (strcmp(replybuffer, "SEND OK") == 0); } - +/** + * @brief Check if TCP bytes are available + * + * @return uint16_t The number of available bytes + */ uint16_t Adafruit_FONA::TCPavailable(void) { uint16_t avail; @@ -1862,7 +1931,13 @@ uint16_t Adafruit_FONA::TCPavailable(void) { return avail; } - +/** + * @brief Read from a TCP socket + * + * @param buff The read buffer + * @param len The number of bytes to read + * @return uint16_t The number of bytes read + */ uint16_t Adafruit_FONA::TCPread(uint8_t *buff, uint8_t len) { uint16_t avail; @@ -1892,7 +1967,7 @@ uint16_t Adafruit_FONA::TCPread(uint8_t *buff, uint8_t len) { /********* HTTP LOW LEVEL FUNCTIONS ************************************/ /** - * @brief + * @brief Initialize HTTP * * @return true success * @return false failure @@ -1902,7 +1977,7 @@ bool Adafruit_FONA::HTTP_init() { } /** - * @brief + * @brief Terminate HTTP * * @return true success * @return false failure @@ -1911,6 +1986,12 @@ bool Adafruit_FONA::HTTP_term() { return sendCheckReply(F("AT+HTTPTERM"), ok_reply); } +/** + * @brief Start sending an HTTP parameter + * + * @param parameter The parameter to send + * @param quoted true to quote the parameter + */ void Adafruit_FONA::HTTP_para_start(FONAFlashStringPtr parameter, bool quoted) { flushInput(); @@ -1928,9 +2009,9 @@ void Adafruit_FONA::HTTP_para_start(FONAFlashStringPtr parameter, bool quoted) { } /** - * @brief + * @brief Finish sending an HTTP parameter * - * @param quoted + * @param quoted true if quoted * @return true success * @return false failure */ @@ -1944,10 +2025,10 @@ bool Adafruit_FONA::HTTP_para_end(bool quoted) { } /** - * @brief + * @brief Send HTTP parameter * - * @param parameter - * @param value + * @param parameter The parameter to send + * @param value The parameter value * @return true success * @return false failure */ @@ -1958,10 +2039,10 @@ bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, const char *value) { } /** - * @brief + * @brief Send HTTP parameter * - * @param parameter - * @param value + * @param parameter The parameter to send + * @param value The parameter value * @return true success * @return false failure */ @@ -1973,10 +2054,10 @@ bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, } /** - * @brief + * @brief Send HTTP parameter * - * @param parameter - * @param value + * @param parameter The parameter to send + * @param value The parameter value * @return true success * @return false failure */ @@ -1987,10 +2068,10 @@ bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, int32_t value) { } /** - * @brief + * @brief Get HTTP data * - * @param size - * @param maxTime + * @param size The amount of data to get + * @param maxTime The maximum amount of time * @return true success * @return false failure */ @@ -2012,12 +2093,12 @@ bool Adafruit_FONA::HTTP_data(uint32_t size, uint32_t maxTime) { } /** - * @brief + * @brief Make an HTTP Request * - * @param method - * @param status - * @param datalen - * @param timeout + * @param method The request method + * @param status The request status + * @param datalen The data length + * @param timeout Timeout for waiting for response * @return true success * @return false failure */ @@ -2131,19 +2212,25 @@ bool Adafruit_FONA_3G::HTTP_GET_start(char *ipaddr, char *path, uint16_t port } */ +/** + * @brief End an HTTP GET + * + */ void Adafruit_FONA::HTTP_GET_end(void) { HTTP_term(); } + + /** - * @brief + * @brief Start an HTTP POST request * - * @param url - * @param contenttype - * @param postdata - * @param postdatalen - * @param status + * @param url The URL to POST + * @param contenttype The message content type + * @param postdata The POST data to be sent + * @param postdatalen The length of the POST data + * @param status The request status * @param datalen - * @return true success - * @return false failure + * @return true + * @return false */ bool Adafruit_FONA::HTTP_POST_start(char *url, FONAFlashStringPtr contenttype, const uint8_t *postdata, @@ -2178,21 +2265,33 @@ bool Adafruit_FONA::HTTP_POST_start(char *url, FONAFlashStringPtr contenttype, return true; } - +/** + * @brief End an HTTP POST request + * + */ void Adafruit_FONA::HTTP_POST_end(void) { HTTP_term(); } +/** + * @brief Set the User Agent for HTTP requests + * + * @param useragent The user agent string to use + */ void Adafruit_FONA::setUserAgent(FONAFlashStringPtr useragent) { this->useragent = useragent; } - +/** + * @brief Set the HTTPS redirect flag + * + * @param onoff + */ void Adafruit_FONA::setHTTPSRedirect(bool onoff) { httpsredirect = onoff; } /********* HTTP HELPERS ****************************************/ /** - * @brief + * @brief Configure an HTTP request * - * @param url + * @param url The URL to make the request to * @return true success * @return false failure */ @@ -2243,18 +2342,41 @@ bool Adafruit_FONA::expectReply(FONAFlashStringPtr reply, uint16_t timeout) { /********* LOW LEVEL *******************************************/ -inline int Adafruit_FONA::available(void) { return mySerial->available(); } - -inline size_t Adafruit_FONA::write(uint8_t x) { return mySerial->write(x); } - -inline int Adafruit_FONA::read(void) { return mySerial->read(); } - -inline int Adafruit_FONA::peek(void) { return mySerial->peek(); } - -inline void Adafruit_FONA::flush() { mySerial->flush(); } - +/** + * @brief Serial data available + * + * @return int + */ +inline int Adafruit_FONA::available(void) { return mySerial->available(); } ///< +/** + * @brief Serial write + * + * @param x + * @return size_t + */ +inline size_t Adafruit_FONA::write(uint8_t x) { return mySerial->write(x); } ///< +/** + * @brief Serial read + * + * @return int + */ +inline int Adafruit_FONA::read(void) { return mySerial->read(); } ///< +/** + * @brief Serial peek + * + * @return int + */ +inline int Adafruit_FONA::peek(void) { return mySerial->peek(); } ///< +/** + * @brief Flush the serial data + * + */ +inline void Adafruit_FONA::flush() { mySerial->flush(); } ///< +/** + * @brief Read all available serial input to flush pending data. + * + */ void Adafruit_FONA::flushInput() { - // Read all available serial input to flush pending data. uint16_t timeoutloop = 0; while (timeoutloop++ < 40) { while (available()) { @@ -2264,8 +2386,13 @@ void Adafruit_FONA::flushInput() { delay(1); } } - -uint16_t Adafruit_FONA::readRaw(uint16_t b) { +/** + * @brief Read directly into the reply buffer + * + * @param read_length The number of bytes to return + * @return uint16_t The number of bytes read + */ +uint16_t Adafruit_FONA::readRaw(uint16_t read_length) { uint16_t idx = 0; while (b && (idx < sizeof(replybuffer) - 1)) { @@ -2280,6 +2407,13 @@ uint16_t Adafruit_FONA::readRaw(uint16_t b) { return idx; } +/** + * @brief Read a single line or up to 254 bytes + * + * @param timeout Reply timeout + * @param multiline true: read the maximum amount. false: read up to the second newline + * @return uint8_t the number of bytes read + */ uint8_t Adafruit_FONA::readline(uint16_t timeout, bool multiline) { uint16_t replyidx = 0; @@ -2316,7 +2450,13 @@ uint8_t Adafruit_FONA::readline(uint16_t timeout, bool multiline) { replybuffer[replyidx] = 0; // null term return replyidx; } - +/** + * @brief Send a command and return the reply + * + * @param send The char* command to send + * @param timeout Timeout for reading a response + * @return uint8_t The response length + */ uint8_t Adafruit_FONA::getReply(char *send, uint16_t timeout) { flushInput(); @@ -2333,6 +2473,13 @@ uint8_t Adafruit_FONA::getReply(char *send, uint16_t timeout) { return l; } +/** + * @brief Send a command and return the reply + * + * @param send The FONAFlashStringPtr command to send + * @param timeout Timeout for reading a response + * @return uint8_t The response length + */ uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr send, uint16_t timeout) { flushInput(); @@ -2351,6 +2498,14 @@ uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr send, uint16_t timeout) { // Send prefix, suffix, and newline. Return response (and also set replybuffer // with response). +/** + * @brief Send a command as prefix and suffix + * + * @param prefix The command prefix + * @param suffix The command suffix + * @param timeout Timeout for reading a response + * @return uint8_t The response length + */ uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr prefix, char *suffix, uint16_t timeout) { flushInput(); @@ -2372,6 +2527,14 @@ uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr prefix, char *suffix, // Send prefix, suffix, and newline. Return response (and also set replybuffer // with response). +/** + * @brief Send a command with + * + * @param prefix The command prefix + * @param suffix The command suffix + * @param timeout Timeout for reading a response + * @return uint8_t The response length + */ uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr prefix, int32_t suffix, uint16_t timeout) { flushInput(); @@ -2393,6 +2556,15 @@ uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr prefix, int32_t suffix, // Send prefix, suffix, suffix2, and newline. Return response (and also set // replybuffer with response). +/** + * @brief Send command with prefix and two suffixes + * + * @param prefix The command prefix + * @param suffix1 The comannd first suffix + * @param suffix2 The command second suffix + * @param timeout Timeout for reading a response + * @return uint8_t The response length + */ uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr prefix, int32_t suffix1, int32_t suffix2, uint16_t timeout) { flushInput(); @@ -2418,6 +2590,14 @@ uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr prefix, int32_t suffix1, // Send prefix, ", suffix, ", and newline. Return response (and also set // replybuffer with response). +/** + * @brief Send command prefix and suffix, returning the response length + * + * @param prefix The command prefix + * @param suffix The command suffix + * @param timeout Timeout for reading a response + * @return uint8_t The response length + */ uint8_t Adafruit_FONA::getReplyQuoted(FONAFlashStringPtr prefix, FONAFlashStringPtr suffix, uint16_t timeout) { diff --git a/Adafruit_FONA.h b/Adafruit_FONA.h index c1251f7..78f3533 100644 --- a/Adafruit_FONA.h +++ b/Adafruit_FONA.h @@ -103,7 +103,7 @@ class Adafruit_FONA : public FONAStreamType { uint8_t getIMEI(char *imei); // set Audio output - bool setAudio(uint8_t a); + bool setAudio(uint8_t audio_output); bool setVolume(uint8_t i); uint8_t getVolume(void); bool playToolkitTone(uint8_t t, uint16_t len); @@ -114,7 +114,7 @@ class Adafruit_FONA : public FONAStreamType { bool tuneFMradio(uint16_t station); bool FMradio(bool onoff, uint8_t a = FONA_HEADSETAUDIO); bool setFMVolume(uint8_t i); - int8_t getFMVolume(); + int8_t getFMVolume(void); int8_t getFMSignalLevel(uint16_t station); // SMS handling @@ -220,7 +220,7 @@ class Adafruit_FONA : public FONAStreamType { bool HTTP_setup(char *url); void flushInput(); - uint16_t readRaw(uint16_t b); + uint16_t readRaw(uint16_t read_length); uint8_t readline(uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS, bool multiline = false); uint8_t getReply(char *send, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); @@ -268,7 +268,12 @@ class Adafruit_FONA : public FONAStreamType { class Adafruit_FONA_3G : public Adafruit_FONA { public: - Adafruit_FONA_3G(int8_t r) : Adafruit_FONA(r) { _type = FONA3G_A; } + /** + * @brief Construct a new Adafruit_FONA_3G object + * + * @param reset_pin + */ + Adafruit_FONA_3G(int8_t reset_pin) : Adafruit_FONA(reset_pin) { _type = FONA3G_A; } bool getBattVoltage(uint16_t *v); bool playToolkitTone(uint8_t t, uint16_t len); From 18e7e1b236312b4eed8b29214dfa40641eaab159 Mon Sep 17 00:00:00 2001 From: siddacious Date: Thu, 26 Mar 2020 19:45:26 -0700 Subject: [PATCH 09/14] Done? --- Adafruit_FONA.cpp | 268 +++++++++++++++++++++++----------------------- Adafruit_FONA.h | 15 +-- 2 files changed, 144 insertions(+), 139 deletions(-) diff --git a/Adafruit_FONA.cpp b/Adafruit_FONA.cpp index 04ccb0c..5b053a1 100644 --- a/Adafruit_FONA.cpp +++ b/Adafruit_FONA.cpp @@ -213,7 +213,8 @@ bool Adafruit_FONA::enableRTC(uint8_t i) { /** * @brief Get the current batery voltage * - * @param v battery value pointer to be filled with the current value in mV (uint16_t) + * @param v battery value pointer to be filled with the current value in mV + * (uint16_t) * @return true success * @return false failure */ @@ -225,7 +226,8 @@ bool Adafruit_FONA::getBattVoltage(uint16_t *v) { /** * @brief Get the current batery voltage * - * @param v battery voltage pointer to be filled with the current value in mV (uint16_t) + * @param v battery voltage pointer to be filled with the current value in mV + * (uint16_t) * @return true success * @return false failure */ @@ -250,7 +252,8 @@ bool Adafruit_FONA::getBattPercent(uint16_t *p) { /** * @brief Get the current ADC voltage * - * @param v ADC voltage pointer to be filled with the current value in mV (uint16_t) + * @param v ADC voltage pointer to be filled with the current value in mV + * (uint16_t) * @return true success * @return false failure */ @@ -433,7 +436,7 @@ bool Adafruit_FONA_3G::playToolkitTone(uint8_t t, uint16_t len) { /** * @brief Set the microphone gain - * + * * * @param a Which microphone gain to set. 0 is headset, 1 is external audio * @param level The new gain level @@ -441,7 +444,7 @@ bool Adafruit_FONA_3G::playToolkitTone(uint8_t t, uint16_t len) { * @return false failure */ bool Adafruit_FONA::setMicVolume(uint8_t a, uint8_t level) { - + if (a > 1) return false; @@ -463,7 +466,6 @@ bool Adafruit_FONA::FMradio(bool onoff, uint8_t a) { return sendCheckReply(F("AT+FMCLOSE"), ok_reply); } - if (a > 1) return false; @@ -517,7 +519,8 @@ int8_t Adafruit_FONA::getFMVolume(void) { * @brief Gets the current FM signal level * * @param station The station to chek the signal level of - * @return int8_t The signal level of the given stations. -1 if FM station is outside allowed range. + * @return int8_t The signal level of the given stations. -1 if FM station is + * outside allowed range. */ int8_t Adafruit_FONA::getFMSignalLevel(uint16_t station) { @@ -586,7 +589,8 @@ bool Adafruit_FONA::callPhone(char *number) { /** * @brief Get the current call status * - * @return uint8_t The call status: 0 ready, 1 failure, 2 unkown, 3 ringing, 4 call in progress + * @return uint8_t The call status: 0 ready, 1 failure, 2 unkown, 3 ringing, 4 + * call in progress */ uint8_t Adafruit_FONA::getCallStatus(void) { uint16_t phoneStatus; @@ -625,7 +629,7 @@ bool Adafruit_FONA_3G::hangUp(void) { bool Adafruit_FONA::pickUp(void) { return sendCheckReply(F("ATA"), ok_reply); } /** - * @brief + * @brief Answer an incoming call * * @return true success * @return false failure @@ -635,7 +639,7 @@ bool Adafruit_FONA_3G::pickUp(void) { } /** * @brief On incoming call callback - * + * */ void Adafruit_FONA::onIncomingCall() { @@ -748,7 +752,7 @@ int8_t Adafruit_FONA::getNumSMS(void) { /** * @brief Read an SMS message into a provided buffer * - * @param i + * @param i * @param smsbuff SMS message buffer * @param maxlen The maximum read length * @param readlen The length read @@ -800,9 +804,9 @@ bool Adafruit_FONA::readSMS(uint8_t i, char *smsbuff, uint16_t maxlen, return true; } - /** - * @brief Retrieve the sender of the specified SMS message and copy it as a string to + * @brief Retrieve the sender of the specified SMS message and copy it as a + string to * the sender buffer. Up to senderlen characters of the sender will be copied * and a null terminator will be added if less than senderlen charactesr are * copied to the result. Returns true if a result was successfully retrieved, @@ -1544,9 +1548,9 @@ bool Adafruit_FONA::enableGPSNMEA(uint8_t i) { /********* GPRS **********************************************************/ /** - * @brief + * @brief Enable GPRS * - * @param onoff + * @param onoff true: enable false: disable * @return true success * @return false failure */ @@ -1645,9 +1649,9 @@ bool Adafruit_FONA::enableGPRS(bool onoff) { } /** - * @brief + * @brief Enable GPRS * - * @param onoff + * @param onoff true: enable false; disable * @return true success * @return false failure */ @@ -1742,11 +1746,11 @@ void Adafruit_FONA::setGPRSNetworkSettings(FONAFlashStringPtr apn, } /** - * @brief + * @brief Get GSM location * * @param errorcode - * @param buff - * @param maxlen + * @param buff location buffer + * @param maxlen maximum read length * @return true success * @return false failure */ @@ -1768,10 +1772,10 @@ bool Adafruit_FONA::getGSMLoc(uint16_t *errorcode, char *buff, } /** - * @brief + * @brief Get GSM Location * - * @param lat - * @param lon + * @param lat latitude pointer + * @param lon longitude pointer * @return true success * @return false failure */ @@ -1806,10 +1810,10 @@ bool Adafruit_FONA::getGSMLoc(float *lat, float *lon) { /********* TCP FUNCTIONS ************************************/ /** - * @brief + * @brief Start a TCP connection * - * @param server - * @param port + * @param server The server to connect to + * @param port The port to connect to * @return true success * @return false failure */ @@ -1851,7 +1855,7 @@ bool Adafruit_FONA::TCPconnect(char *server, uint16_t port) { } /** - * @brief + * @brief Close the TCP connection * * @return true success * @return false failure @@ -1861,7 +1865,7 @@ bool Adafruit_FONA::TCPclose(void) { } /** - * @brief + * @brief Check the TCP connection status * * @return true success * @return false failure @@ -1878,10 +1882,10 @@ bool Adafruit_FONA::TCPconnected(void) { } /** - * @brief + * @brief Send TCP Packets * - * @param packet - * @param len + * @param packet Packet buffer + * @param len Length to send * @return true success * @return false failure */ @@ -2119,9 +2123,9 @@ bool Adafruit_FONA::HTTP_action(uint8_t method, uint16_t *status, } /** - * @brief + * @brief Read all available HTTP data * - * @param datalen + * @param datalen The length read * @return true success * @return false failure */ @@ -2134,9 +2138,9 @@ bool Adafruit_FONA::HTTP_readall(uint16_t *datalen) { } /** - * @brief + * @brief Enable or disable SSL * - * @param onoff + * @param onoff true: enable false: disable * @return true success * @return false failure */ @@ -2147,11 +2151,11 @@ bool Adafruit_FONA::HTTP_ssl(bool onoff) { /********* HTTP HIGH LEVEL FUNCTIONS ***************************/ /** - * @brief + * @brief Start a HTTP GET request * - * @param url - * @param status - * @param datalen + * @param url The URL to request + * @param status request status pointer + * @param datalen The data length * @return true success * @return false failure */ @@ -2218,8 +2222,6 @@ bool Adafruit_FONA_3G::HTTP_GET_start(char *ipaddr, char *path, uint16_t port */ void Adafruit_FONA::HTTP_GET_end(void) { HTTP_term(); } - - /** * @brief Start an HTTP POST request * @@ -2324,10 +2326,10 @@ bool Adafruit_FONA::HTTP_setup(char *url) { /********* HELPERS *********************************************/ /** - * @brief + * @brief Check if the received reply matches the expectation * - * @param reply - * @param timeout + * @param reply The expected reply + * @param timeout Read timeout * @return true success * @return false failure */ @@ -2344,37 +2346,39 @@ bool Adafruit_FONA::expectReply(FONAFlashStringPtr reply, uint16_t timeout) { /** * @brief Serial data available - * - * @return int + * + * @return int */ -inline int Adafruit_FONA::available(void) { return mySerial->available(); } ///< +inline int Adafruit_FONA::available(void) { return mySerial->available(); } ///< /** * @brief Serial write - * - * @param x - * @return size_t + * + * @param x + * @return size_t */ -inline size_t Adafruit_FONA::write(uint8_t x) { return mySerial->write(x); } ///< +inline size_t Adafruit_FONA::write(uint8_t x) { + return mySerial->write(x); +} ///< /** * @brief Serial read - * - * @return int + * + * @return int */ -inline int Adafruit_FONA::read(void) { return mySerial->read(); } ///< +inline int Adafruit_FONA::read(void) { return mySerial->read(); } ///< /** * @brief Serial peek - * - * @return int + * + * @return int */ -inline int Adafruit_FONA::peek(void) { return mySerial->peek(); } ///< +inline int Adafruit_FONA::peek(void) { return mySerial->peek(); } ///< /** * @brief Flush the serial data - * + * */ inline void Adafruit_FONA::flush() { mySerial->flush(); } ///< /** * @brief Read all available serial input to flush pending data. - * + * */ void Adafruit_FONA::flushInput() { uint16_t timeoutloop = 0; @@ -2411,7 +2415,8 @@ uint16_t Adafruit_FONA::readRaw(uint16_t read_length) { * @brief Read a single line or up to 254 bytes * * @param timeout Reply timeout - * @param multiline true: read the maximum amount. false: read up to the second newline + * @param multiline true: read the maximum amount. false: read up to the second + * newline * @return uint8_t the number of bytes read */ uint8_t Adafruit_FONA::readline(uint16_t timeout, bool multiline) { @@ -2623,11 +2628,11 @@ uint8_t Adafruit_FONA::getReplyQuoted(FONAFlashStringPtr prefix, } /** - * @brief + * @brief Send data and verify the response matches an expected response * - * @param send - * @param reply - * @param timeout + * @param send The buffer of data to send + * @param reply Buffer with the expected reply + * @param timeout Read timeout * @return true success * @return false failure */ @@ -2648,11 +2653,11 @@ bool Adafruit_FONA::sendCheckReply(char *send, char *reply, uint16_t timeout) { } /** - * @brief + * @brief Send data and verify the response matches an expected response * - * @param send - * @param reply - * @param timeout + * @param send The buffer of data to send + * @param reply Buffer with the expected reply + * @param timeout Read timeout * @return true success * @return false failure */ @@ -2665,11 +2670,11 @@ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr send, } /** - * @brief + * @brief Send data and verify the response matches an expected response * - * @param send - * @param reply - * @param timeout + * @param send The buffer of data to send + * @param reply Buffer with the expected reply + * @param timeout Read timeout * @return true success * @return false failure */ @@ -2684,12 +2689,12 @@ bool Adafruit_FONA::sendCheckReply(char *send, FONAFlashStringPtr reply, // parameter. /** - * @brief + * @brief Send data and verify the response matches an expected response * - * @param prefix - * @param suffix - * @param reply - * @param timeout + * @param prefix The prefix buffer of data to send + * @param suffix The suffix buffer of data to send + * @param reply Buffer with the expected reply + * @param timeout Read timeout * @return true success * @return false failure */ @@ -2703,12 +2708,12 @@ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, char *suffix, // parameter. /** - * @brief + * @brief Send data and verify the response matches an expected response * - * @param prefix - * @param suffix - * @param reply - * @param timeout + * @param prefix The prefix buffer of data to send + * @param suffix The suffix to send + * @param reply Buffer with the expected reply + * @param timeout Read timeout * @return true success * @return false failure */ @@ -2718,17 +2723,14 @@ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix, return (prog_char_strcmp(replybuffer, (prog_char *)reply) == 0); } -// Send prefix, suffix, suffix2, and newline. Verify FONA response matches -// reply parameter. - /** - * @brief + * @brief Send data and verify the response matches an expected response * - * @param prefix - * @param suffix1 - * @param suffix2 - * @param reply - * @param timeout + * @param prefix The prefix buffer of data to send + * @param suffix1 The first suffix to send + * @param suffix2 The second suffix to send + * @param reply Buffer with the expected reply + * @param timeout Read timeout * @return true success * @return false failure */ @@ -2739,16 +2741,13 @@ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix1, return (prog_char_strcmp(replybuffer, (prog_char *)reply) == 0); } -// Send prefix, ", suffix, ", and newline. Verify FONA response matches reply -// parameter. - /** - * @brief + * @brief Send data and verify the response matches an expected response * - * @param prefix - * @param suffix - * @param reply - * @param timeout + * @param prefix The prefix buffer of data to send + * @param suffix The suffix buffer send + * @param reply The expected response + * @param timeout Read timeout * @return true success * @return false failure */ @@ -2761,12 +2760,12 @@ bool Adafruit_FONA::sendCheckReplyQuoted(FONAFlashStringPtr prefix, } /** - * @brief + * @brief Parse a received reply * - * @param toreply - * @param v - * @param divider - * @param index + * @param toreply Reply string + * @param v read buffer + * @param divider The divider character + * @param index The index to read up to * @return true success * @return false failure */ @@ -2792,11 +2791,16 @@ bool Adafruit_FONA::parseReply(FONAFlashStringPtr toreply, uint16_t *v, } /** - * @brief + + + * @brief Parse a string in the response fields and copy its value + * (without quotes) to the specified character array (v). Only up + * to maxlen characters are copied into the result buffer, so make + * sure to pass a large enough buffer to handle the response. * * @param toreply - * @param v - * @param divider + * @param v The response buffer + * @param divider The divider character * @param index * @return true success * @return false failure @@ -2828,17 +2832,17 @@ bool Adafruit_FONA::parseReply(FONAFlashStringPtr toreply, char *v, return true; } -// Parse a quoted string in the response fields and copy its value (without -// quotes) to the specified character array (v). Only up to maxlen characters -// are copied into the result buffer, so make sure to pass a large enough buffer -// to handle the response. +// /** - * @brief + * @brief Parse a quoted string in the response fields and copy its value + * (without quotes) to the specified character array (v). Only up to + * maxlen characters are copied into the result buffer, + * so make sure to pass a large enough buffer to handle the response. * * @param toreply - * @param v - * @param maxlen - * @param divider + * @param v response buffer + * @param maxlen The maximum read length + * @param divider The divider character * @param index * @return true success * @return false failure @@ -2880,13 +2884,13 @@ bool Adafruit_FONA::parseReplyQuoted(FONAFlashStringPtr toreply, char *v, } /** - * @brief + * @brief Send data and parse the reply * - * @param tosend - * @param toreply - * @param v - * @param divider - * @param index + * @param tosend The data buffer to send + * @param toreply The expected reply string + * @param v The data buffer + * @param divider The divider character + * @param index The index to read to * @return true success * @return false failure */ @@ -2906,13 +2910,13 @@ bool Adafruit_FONA::sendParseReply(FONAFlashStringPtr tosend, // needed for CBC and others /** - * @brief + * @brief Send data and parse the reply * - * @param tosend - * @param toreply - * @param f - * @param divider - * @param index + * @param tosend The data buffer to send + * @param toreply The expected reply string + * @param f data buffer (float) + * @param divider The divider character + * @param index The index to read to * @return true success * @return false failure */ @@ -2930,12 +2934,12 @@ bool Adafruit_FONA_3G::sendParseReply(FONAFlashStringPtr tosend, } /** - * @brief + * @brief Parse a reply * - * @param toreply - * @param f - * @param divider - * @param index + * @param toreply The expected reply string + * @param f data buffer (float) + * @param divider The divider character + * @param index The index to read to * @return true success * @return false failure */ diff --git a/Adafruit_FONA.h b/Adafruit_FONA.h index 78f3533..8f0b468 100644 --- a/Adafruit_FONA.h +++ b/Adafruit_FONA.h @@ -65,7 +65,6 @@ #define FONA_CALL_RINGING 3 #define FONA_CALL_INPROGRESS 4 - /** Object that controls and keeps state for the FONA module. */ class Adafruit_FONA : public FONAStreamType { public: @@ -206,15 +205,15 @@ class Adafruit_FONA : public FONAStreamType { protected: int8_t _rstpin; ///< Reset pin - uint8_t _type; ///< Module type + uint8_t _type; ///< Module type - char replybuffer[255]; ///< buffer for holding replies from the module + char replybuffer[255]; ///< buffer for holding replies from the module FONAFlashStringPtr apn; ///< Access point name FONAFlashStringPtr apnusername; ///< Access point username FONAFlashStringPtr apnpassword; ///< Access point password - bool httpsredirect; ///< HTTPS redirect state - FONAFlashStringPtr useragent; ///< User agent used when making requests - FONAFlashStringPtr ok_reply; ///< OK reply for successful requests + bool httpsredirect; ///< HTTPS redirect state + FONAFlashStringPtr useragent; ///< User agent used when making requests + FONAFlashStringPtr ok_reply; ///< OK reply for successful requests // HTTP helpers bool HTTP_setup(char *url); @@ -273,7 +272,9 @@ class Adafruit_FONA_3G : public Adafruit_FONA { * * @param reset_pin */ - Adafruit_FONA_3G(int8_t reset_pin) : Adafruit_FONA(reset_pin) { _type = FONA3G_A; } + Adafruit_FONA_3G(int8_t reset_pin) : Adafruit_FONA(reset_pin) { + _type = FONA3G_A; + } bool getBattVoltage(uint16_t *v); bool playToolkitTone(uint8_t t, uint16_t len); From 834382799a3c0e3c02e5fb94890aed004af5e138 Mon Sep 17 00:00:00 2001 From: siddacious Date: Thu, 26 Mar 2020 19:57:07 -0700 Subject: [PATCH 10/14] fix typo --- Adafruit_FONA.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Adafruit_FONA.cpp b/Adafruit_FONA.cpp index 5b053a1..136fdab 100644 --- a/Adafruit_FONA.cpp +++ b/Adafruit_FONA.cpp @@ -362,10 +362,10 @@ uint8_t Adafruit_FONA::getRSSI(void) { * @return false failure */ bool Adafruit_FONA::setAudio(uint8_t audio_output) { - if (a > 1) + if (audio_output > 1) return false; - return sendCheckReply(F("AT+CHFA="), a, ok_reply); + return sendCheckReply(F("AT+CHFA="), audio_output, ok_reply); } /** * @brief Get the current volume level @@ -2399,11 +2399,11 @@ void Adafruit_FONA::flushInput() { uint16_t Adafruit_FONA::readRaw(uint16_t read_length) { uint16_t idx = 0; - while (b && (idx < sizeof(replybuffer) - 1)) { + while (read_length && (idx < sizeof(replybuffer) - 1)) { if (mySerial->available()) { replybuffer[idx] = mySerial->read(); idx++; - b--; + read_length--; } } replybuffer[idx] = 0; From 972bc1f26b353b093fc182234d4716ed73d64eab Mon Sep 17 00:00:00 2001 From: siddacious Date: Fri, 27 Mar 2020 10:00:42 -0700 Subject: [PATCH 11/14] fixes, formatting change --- Adafruit_FONA.cpp | 243 +++++++++++++++++----------------------------- Adafruit_FONA.h | 4 +- 2 files changed, 89 insertions(+), 158 deletions(-) diff --git a/Adafruit_FONA.cpp b/Adafruit_FONA.cpp index 136fdab..2d55a3d 100644 --- a/Adafruit_FONA.cpp +++ b/Adafruit_FONA.cpp @@ -29,7 +29,7 @@ using namespace std; #endif /** - * @brief Construct a new Adafruit_FONA::Adafruit_FONA object + * @brief Construct a new Adafruit_FONA object * * @param rst The reset pin */ @@ -54,7 +54,7 @@ uint8_t Adafruit_FONA::type(void) { return _type; } /** * @brief Connect to the cell module * - * @param port the serial connection to uset o connect + * @param port the serial connection to use to connect * @return bool true on success, false if a connection cannot be made */ bool Adafruit_FONA::begin(Stream &port) { @@ -165,58 +165,56 @@ bool Adafruit_FONA::begin(Stream &port) { * @brief Set the baud rate that the module will use * * @param baud The new baud rate to set - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::setBaudrate(uint16_t baud) { return sendCheckReply(F("AT+IPREX="), baud, ok_reply); } /********* Real Time Clock ********************************************/ - +// This RTC setup isn't fully operational +// see https://forums.adafruit.com/viewtopic.php?f=19&t=58002&p=294235#p294235 /** * @brief Read the Real Time Clock * - * @param year - * @param month - * @param date - * @param hr - * @param min - * @param sec - * @return true success - * @return false failure + * @param year pointer to a uint8_t to be set with year data + * @param month pointer to a uint8_t to be set with month data + * @param day pointer to a uint8_t to be set with day data + * @param hr pointer to a uint8_t to be set with hour data + * @param min pointer to a uint8_t to be set with minute data + * @param sec pointer to a uint8_t to be set with year data + * @return true: success, false: failure */ -bool Adafruit_FONA::readRTC(uint8_t *year, uint8_t *month, uint8_t *date, +bool Adafruit_FONA::readRTC(uint8_t *year, uint8_t *month, uint8_t *day, uint8_t *hr, uint8_t *min, uint8_t *sec) { uint16_t v; sendParseReply(F("AT+CCLK?"), F("+CCLK: "), &v, '/', 0); + // TODO: https://github.com/adafruit/Adafruit_FONA/issues/111 *year = v; DEBUG_PRINTLN(*year); } + /** * @brief Enable the Real Time Clock * - * @param i - * @return true success - * @return false failure + * @param mode 1: Enable 0: Disable + * @return true: Success , false: failure */ -bool Adafruit_FONA::enableRTC(uint8_t i) { - if (!sendCheckReply(F("AT+CLTS="), i, ok_reply)) +bool Adafruit_FONA::enableRTC(uint8_t mode) { + if (!sendCheckReply(F("AT+CLTS="), mode, ok_reply)) return false; return sendCheckReply(F("AT&W"), ok_reply); } /********* BATTERY & ADC ********************************************/ -/* returns */ /** * @brief Get the current batery voltage * * @param v battery value pointer to be filled with the current value in mV * (uint16_t) - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::getBattVoltage(uint16_t *v) { return sendParseReply(F("AT+CBC"), F("+CBC: "), v, ',', 2); @@ -228,8 +226,7 @@ bool Adafruit_FONA::getBattVoltage(uint16_t *v) { * * @param v battery voltage pointer to be filled with the current value in mV * (uint16_t) - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA_3G::getBattVoltage(uint16_t *v) { float f; @@ -243,8 +240,7 @@ bool Adafruit_FONA_3G::getBattVoltage(uint16_t *v) { * @brief Get the percentage charge of battery as reported by sim800 * * @param p battery percentage pointer - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::getBattPercent(uint16_t *p) { return sendParseReply(F("AT+CBC"), F("+CBC: "), p, ',', 1); @@ -254,8 +250,7 @@ bool Adafruit_FONA::getBattPercent(uint16_t *p) { * * @param v ADC voltage pointer to be filled with the current value in mV * (uint16_t) - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::getADCVoltage(uint16_t *v) { return sendParseReply(F("AT+CADC?"), F("+CADC: 1,"), v); @@ -358,8 +353,7 @@ uint8_t Adafruit_FONA::getRSSI(void) { * @brief Set the audio ouput * * @param audio_output The output to set. 0 is headset, 1 is external audio - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::setAudio(uint8_t audio_output) { if (audio_output > 1) @@ -385,8 +379,7 @@ uint8_t Adafruit_FONA::getVolume(void) { * @brief Set the volume * * @param i The new volume to set - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::setVolume(uint8_t i) { return sendCheckReply(F("AT+CLVL="), i, ok_reply); @@ -396,8 +389,7 @@ bool Adafruit_FONA::setVolume(uint8_t i) { * @brief Play a DTMF/Key tone * * @param dtmf The tone to play - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::playDTMF(char dtmf) { char str[4]; @@ -413,8 +405,7 @@ bool Adafruit_FONA::playDTMF(char dtmf) { * * @param t The tone to play * @param len The tone length - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::playToolkitTone(uint8_t t, uint16_t len) { return sendCheckReply(F("AT+STTONE=1,"), t, len, ok_reply); @@ -424,8 +415,7 @@ bool Adafruit_FONA::playToolkitTone(uint8_t t, uint16_t len) { * * @param t The tone to play * @param len The tone length - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA_3G::playToolkitTone(uint8_t t, uint16_t len) { if (!sendCheckReply(F("AT+CPTONE="), t, ok_reply)) @@ -440,8 +430,7 @@ bool Adafruit_FONA_3G::playToolkitTone(uint8_t t, uint16_t len) { * * @param a Which microphone gain to set. 0 is headset, 1 is external audio * @param level The new gain level - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::setMicVolume(uint8_t a, uint8_t level) { @@ -458,8 +447,7 @@ bool Adafruit_FONA::setMicVolume(uint8_t a, uint8_t level) { * * @param onoff true; on false: off * @param a The audio source to use. 0 is headset, 1 is external audio - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::FMradio(bool onoff, uint8_t a) { if (!onoff) { @@ -476,8 +464,7 @@ bool Adafruit_FONA::FMradio(bool onoff, uint8_t a) { * @brief Set the FM Radio station * * @param station The station to set the radio to - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::tuneFMradio(uint16_t station) { // Fail if FM station is outside allowed range. @@ -491,8 +478,7 @@ bool Adafruit_FONA::tuneFMradio(uint16_t station) { * @brief Set the FM Radio Volume * * @param i The volume to set - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::setFMVolume(uint8_t i) { // Fail if volume is outside allowed range (0-6). @@ -554,8 +540,7 @@ int8_t Adafruit_FONA::getFMSignalLevel(uint16_t station) { * * @param period * @param duty - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::setPWM(uint16_t period, uint8_t duty) { if (period > 2000) @@ -572,8 +557,7 @@ bool Adafruit_FONA::setPWM(uint16_t period, uint8_t duty) { * @brief Call a phone number * * @param number The phone number to call - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::callPhone(char *number) { char sendbuff[35] = "ATD"; @@ -603,15 +587,13 @@ uint8_t Adafruit_FONA::getCallStatus(void) { /** * @brief End the current call * - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::hangUp(void) { return sendCheckReply(F("ATH0"), ok_reply); } /** * @brief End the current call * - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA_3G::hangUp(void) { getReply(F("ATH")); @@ -623,16 +605,14 @@ bool Adafruit_FONA_3G::hangUp(void) { /** * @brief Answer a call * - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::pickUp(void) { return sendCheckReply(F("ATA"), ok_reply); } /** * @brief Answer an incoming call * - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA_3G::pickUp(void) { return sendCheckReply(F("ATA"), F("VOICE CALL: BEGIN")); @@ -656,8 +636,7 @@ bool Adafruit_FONA::_incomingCall = false; * * @param enable true to enable, false to disable * @param interrupt The interrupt to attach - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::callerIdNotification(bool enable, uint8_t interrupt) { if (enable) { @@ -673,8 +652,7 @@ bool Adafruit_FONA::callerIdNotification(bool enable, uint8_t interrupt) { * @brief Get the number of the incoming call * * @param phonenum The incoming caller's phone number - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::incomingCallNumber(char *phonenum) { //+CLIP: "",145,"",0,"",0 @@ -718,8 +696,7 @@ uint8_t Adafruit_FONA::getSMSInterrupt(void) { * @brief Attach an interrupt for SMS notifications * * @param i The interrupt to set - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::setSMSInterrupt(uint8_t i) { return sendCheckReply(F("AT+CFGRI="), i, ok_reply); @@ -756,8 +733,7 @@ int8_t Adafruit_FONA::getNumSMS(void) { * @param smsbuff SMS message buffer * @param maxlen The maximum read length * @param readlen The length read - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::readSMS(uint8_t i, char *smsbuff, uint16_t maxlen, uint16_t *readlen) { @@ -816,8 +792,7 @@ bool Adafruit_FONA::readSMS(uint8_t i, char *smsbuff, uint16_t maxlen, * @param i * @param sender The sender buffer * @param senderlen the length to read - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::getSMSSender(uint8_t i, char *sender, int senderlen) { // Ensure text mode and all text mode parameters are sent. @@ -848,8 +823,7 @@ bool Adafruit_FONA::getSMSSender(uint8_t i, char *sender, int senderlen) { * * @param smsaddr The SMS address buffer * @param smsmsg The SMS message buffer - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::sendSMS(char *smsaddr, char *smsmsg) { if (!sendCheckReply(F("AT+CMGF=1"), ok_reply)) @@ -898,8 +872,7 @@ bool Adafruit_FONA::sendSMS(char *smsaddr, char *smsmsg) { * @brief Delete an SMS Message * * @param i The message to delete - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::deleteSMS(uint8_t i) { if (!sendCheckReply(F("AT+CMGF=1"), ok_reply)) @@ -924,8 +897,7 @@ bool Adafruit_FONA::deleteSMS(uint8_t i) { * @param ussdbuff The USSD bufer * @param maxlen The maximum read length * @param readlen The length actually read - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::sendUSSD(char *ussdmsg, char *ussdbuff, uint16_t maxlen, uint16_t *readlen) { @@ -973,8 +945,7 @@ bool Adafruit_FONA::sendUSSD(char *ussdmsg, char *ussdbuff, uint16_t maxlen, * @brief Enable network time sync * * @param onoff true: enable false: disable - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::enableNetworkTimeSync(bool onoff) { if (onoff) { @@ -995,8 +966,7 @@ bool Adafruit_FONA::enableNetworkTimeSync(bool onoff) { * * @param onoff true: enable false: disable * @param ntpserver The NTP server buffer - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::enableNTPTimeSync(bool onoff, FONAFlashStringPtr ntpserver) { @@ -1035,8 +1005,7 @@ bool Adafruit_FONA::enableNTPTimeSync(bool onoff, * * @param buff Time buffer * @param maxlen maximum read length - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::getTime(char *buff, uint16_t maxlen) { getReply(F("AT+CCLK?"), (uint16_t)10000); @@ -1059,8 +1028,7 @@ bool Adafruit_FONA::getTime(char *buff, uint16_t maxlen) { * @brief Enable GPS * * @param onoff true: enable false: disable - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::enableGPS(bool onoff) { uint16_t state; @@ -1099,8 +1067,7 @@ bool Adafruit_FONA::enableGPS(bool onoff) { * @brief Enable GPS * * @param onoff true: enable false: disable - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA_3G::enableGPS(bool onoff) { uint16_t state; @@ -1222,8 +1189,7 @@ uint8_t Adafruit_FONA::getGPS(uint8_t arg, char *buffer, uint8_t maxbuff) { * @param speed_kph speed pointer * @param heading heading pointer * @param altitude altitude pointer - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, float *heading, float *altitude) { @@ -1523,8 +1489,7 @@ bool Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, * @brief Enable GPS NMEA * * @param i mode - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::enableGPSNMEA(uint8_t i) { @@ -1551,8 +1516,7 @@ bool Adafruit_FONA::enableGPSNMEA(uint8_t i) { * @brief Enable GPRS * * @param onoff true: enable false: disable - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::enableGPRS(bool onoff) { @@ -1652,8 +1616,7 @@ bool Adafruit_FONA::enableGPRS(bool onoff) { * @brief Enable GPRS * * @param onoff true: enable false; disable - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA_3G::enableGPRS(bool onoff) { @@ -1751,8 +1714,7 @@ void Adafruit_FONA::setGPRSNetworkSettings(FONAFlashStringPtr apn, * @param errorcode * @param buff location buffer * @param maxlen maximum read length - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::getGSMLoc(uint16_t *errorcode, char *buff, uint16_t maxlen) { @@ -1776,8 +1738,7 @@ bool Adafruit_FONA::getGSMLoc(uint16_t *errorcode, char *buff, * * @param lat latitude pointer * @param lon longitude pointer - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::getGSMLoc(float *lat, float *lon) { @@ -1814,8 +1775,7 @@ bool Adafruit_FONA::getGSMLoc(float *lat, float *lon) { * * @param server The server to connect to * @param port The port to connect to - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::TCPconnect(char *server, uint16_t port) { @@ -1857,8 +1817,7 @@ bool Adafruit_FONA::TCPconnect(char *server, uint16_t port) { /** * @brief Close the TCP connection * - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::TCPclose(void) { return sendCheckReply(F("AT+CIPCLOSE"), ok_reply); @@ -1867,8 +1826,7 @@ bool Adafruit_FONA::TCPclose(void) { /** * @brief Check the TCP connection status * - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::TCPconnected(void) { if (!sendCheckReply(F("AT+CIPSTATUS"), ok_reply, 100)) @@ -1886,8 +1844,7 @@ bool Adafruit_FONA::TCPconnected(void) { * * @param packet Packet buffer * @param len Length to send - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::TCPsend(char *packet, uint8_t len) { @@ -1973,8 +1930,7 @@ uint16_t Adafruit_FONA::TCPread(uint8_t *buff, uint8_t len) { /** * @brief Initialize HTTP * - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::HTTP_init() { return sendCheckReply(F("AT+HTTPINIT"), ok_reply); @@ -1983,8 +1939,7 @@ bool Adafruit_FONA::HTTP_init() { /** * @brief Terminate HTTP * - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::HTTP_term() { return sendCheckReply(F("AT+HTTPTERM"), ok_reply); @@ -2016,8 +1971,7 @@ void Adafruit_FONA::HTTP_para_start(FONAFlashStringPtr parameter, bool quoted) { * @brief Finish sending an HTTP parameter * * @param quoted true if quoted - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::HTTP_para_end(bool quoted) { if (quoted) @@ -2033,8 +1987,7 @@ bool Adafruit_FONA::HTTP_para_end(bool quoted) { * * @param parameter The parameter to send * @param value The parameter value - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, const char *value) { HTTP_para_start(parameter, true); @@ -2047,8 +2000,7 @@ bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, const char *value) { * * @param parameter The parameter to send * @param value The parameter value - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, FONAFlashStringPtr value) { @@ -2062,8 +2014,7 @@ bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, * * @param parameter The parameter to send * @param value The parameter value - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, int32_t value) { HTTP_para_start(parameter, false); @@ -2076,8 +2027,7 @@ bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, int32_t value) { * * @param size The amount of data to get * @param maxTime The maximum amount of time - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::HTTP_data(uint32_t size, uint32_t maxTime) { flushInput(); @@ -2103,8 +2053,7 @@ bool Adafruit_FONA::HTTP_data(uint32_t size, uint32_t maxTime) { * @param status The request status * @param datalen The data length * @param timeout Timeout for waiting for response - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::HTTP_action(uint8_t method, uint16_t *status, uint16_t *datalen, int32_t timeout) { @@ -2126,8 +2075,7 @@ bool Adafruit_FONA::HTTP_action(uint8_t method, uint16_t *status, * @brief Read all available HTTP data * * @param datalen The length read - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::HTTP_readall(uint16_t *datalen) { getReply(F("AT+HTTPREAD")); @@ -2141,8 +2089,7 @@ bool Adafruit_FONA::HTTP_readall(uint16_t *datalen) { * @brief Enable or disable SSL * * @param onoff true: enable false: disable - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::HTTP_ssl(bool onoff) { return sendCheckReply(F("AT+HTTPSSL="), onoff ? 1 : 0, ok_reply); @@ -2156,8 +2103,7 @@ bool Adafruit_FONA::HTTP_ssl(bool onoff) { * @param url The URL to request * @param status request status pointer * @param datalen The data length - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::HTTP_GET_start(char *url, uint16_t *status, uint16_t *datalen) { @@ -2294,8 +2240,7 @@ void Adafruit_FONA::setHTTPSRedirect(bool onoff) { httpsredirect = onoff; } * @brief Configure an HTTP request * * @param url The URL to make the request to - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::HTTP_setup(char *url) { // Handle any pending @@ -2330,8 +2275,7 @@ bool Adafruit_FONA::HTTP_setup(char *url) { * * @param reply The expected reply * @param timeout Read timeout - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::expectReply(FONAFlashStringPtr reply, uint16_t timeout) { readline(timeout); @@ -2633,8 +2577,7 @@ uint8_t Adafruit_FONA::getReplyQuoted(FONAFlashStringPtr prefix, * @param send The buffer of data to send * @param reply Buffer with the expected reply * @param timeout Read timeout - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::sendCheckReply(char *send, char *reply, uint16_t timeout) { if (!getReply(send, timeout)) @@ -2658,8 +2601,7 @@ bool Adafruit_FONA::sendCheckReply(char *send, char *reply, uint16_t timeout) { * @param send The buffer of data to send * @param reply Buffer with the expected reply * @param timeout Read timeout - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr send, FONAFlashStringPtr reply, uint16_t timeout) { @@ -2675,8 +2617,7 @@ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr send, * @param send The buffer of data to send * @param reply Buffer with the expected reply * @param timeout Read timeout - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::sendCheckReply(char *send, FONAFlashStringPtr reply, uint16_t timeout) { @@ -2695,8 +2636,7 @@ bool Adafruit_FONA::sendCheckReply(char *send, FONAFlashStringPtr reply, * @param suffix The suffix buffer of data to send * @param reply Buffer with the expected reply * @param timeout Read timeout - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, char *suffix, FONAFlashStringPtr reply, uint16_t timeout) { @@ -2714,8 +2654,7 @@ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, char *suffix, * @param suffix The suffix to send * @param reply Buffer with the expected reply * @param timeout Read timeout - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix, FONAFlashStringPtr reply, uint16_t timeout) { @@ -2731,8 +2670,7 @@ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix, * @param suffix2 The second suffix to send * @param reply Buffer with the expected reply * @param timeout Read timeout - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix1, int32_t suffix2, FONAFlashStringPtr reply, @@ -2748,8 +2686,7 @@ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix1, * @param suffix The suffix buffer send * @param reply The expected response * @param timeout Read timeout - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::sendCheckReplyQuoted(FONAFlashStringPtr prefix, FONAFlashStringPtr suffix, @@ -2766,8 +2703,7 @@ bool Adafruit_FONA::sendCheckReplyQuoted(FONAFlashStringPtr prefix, * @param v read buffer * @param divider The divider character * @param index The index to read up to - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::parseReply(FONAFlashStringPtr toreply, uint16_t *v, char divider, uint8_t index) { @@ -2802,8 +2738,7 @@ bool Adafruit_FONA::parseReply(FONAFlashStringPtr toreply, uint16_t *v, * @param v The response buffer * @param divider The divider character * @param index - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::parseReply(FONAFlashStringPtr toreply, char *v, char divider, uint8_t index) { @@ -2844,8 +2779,7 @@ bool Adafruit_FONA::parseReply(FONAFlashStringPtr toreply, char *v, * @param maxlen The maximum read length * @param divider The divider character * @param index - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::parseReplyQuoted(FONAFlashStringPtr toreply, char *v, int maxlen, char divider, uint8_t index) { @@ -2891,8 +2825,7 @@ bool Adafruit_FONA::parseReplyQuoted(FONAFlashStringPtr toreply, char *v, * @param v The data buffer * @param divider The divider character * @param index The index to read to - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA::sendParseReply(FONAFlashStringPtr tosend, FONAFlashStringPtr toreply, uint16_t *v, @@ -2917,8 +2850,7 @@ bool Adafruit_FONA::sendParseReply(FONAFlashStringPtr tosend, * @param f data buffer (float) * @param divider The divider character * @param index The index to read to - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA_3G::sendParseReply(FONAFlashStringPtr tosend, FONAFlashStringPtr toreply, float *f, @@ -2940,8 +2872,7 @@ bool Adafruit_FONA_3G::sendParseReply(FONAFlashStringPtr tosend, * @param f data buffer (float) * @param divider The divider character * @param index The index to read to - * @return true success - * @return false failure + * @return true: success, false: failure */ bool Adafruit_FONA_3G::parseReply(FONAFlashStringPtr toreply, float *f, char divider, uint8_t index) { diff --git a/Adafruit_FONA.h b/Adafruit_FONA.h index 8f0b468..63432fc 100644 --- a/Adafruit_FONA.h +++ b/Adafruit_FONA.h @@ -83,8 +83,8 @@ class Adafruit_FONA : public FONAStreamType { bool setBaudrate(uint16_t baud); // RTC - bool enableRTC(uint8_t i); - bool readRTC(uint8_t *year, uint8_t *month, uint8_t *date, uint8_t *hr, + bool enableRTC(uint8_t mode); + bool readRTC(uint8_t *year, uint8_t *month, uint8_t *day, uint8_t *hr, uint8_t *min, uint8_t *sec); // Battery and ADC From 2fd8cfe1295d24657e15042f2860ab6384b68c98 Mon Sep 17 00:00:00 2001 From: siddacious Date: Fri, 27 Mar 2020 11:04:56 -0700 Subject: [PATCH 12/14] adding docs to mention readRTC behavior --- Adafruit_FONA.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Adafruit_FONA.cpp b/Adafruit_FONA.cpp index 2d55a3d..254f21d 100644 --- a/Adafruit_FONA.cpp +++ b/Adafruit_FONA.cpp @@ -177,12 +177,14 @@ bool Adafruit_FONA::setBaudrate(uint16_t baud) { /** * @brief Read the Real Time Clock * + * **NOTE** Currently this function **will only fill the 'year' variable** + * * @param year pointer to a uint8_t to be set with year data - * @param month pointer to a uint8_t to be set with month data - * @param day pointer to a uint8_t to be set with day data - * @param hr pointer to a uint8_t to be set with hour data - * @param min pointer to a uint8_t to be set with minute data - * @param sec pointer to a uint8_t to be set with year data + * @param month pointer to a uint8_t to be set with month data **NOT WORKING** + * @param day pointer to a uint8_t to be set with day data **NOT WORKING** + * @param hr pointer to a uint8_t to be set with hour data **NOT WORKING** + * @param min pointer to a uint8_t to be set with minute data **NOT WORKING** + * @param sec pointer to a uint8_t to be set with year data **NOT WORKING** * @return true: success, false: failure */ bool Adafruit_FONA::readRTC(uint8_t *year, uint8_t *month, uint8_t *day, From a39a4a1e35fc82129f9ef488bc858a181d599243 Mon Sep 17 00:00:00 2001 From: siddacious Date: Tue, 31 Mar 2020 15:06:10 -0700 Subject: [PATCH 13/14] second pass at filling out the documentation --- Adafruit_FONA.cpp | 375 ++++++++++++++++++++++++++-------------------- Adafruit_FONA.h | 15 +- 2 files changed, 217 insertions(+), 173 deletions(-) diff --git a/Adafruit_FONA.cpp b/Adafruit_FONA.cpp index 254f21d..07f831b 100644 --- a/Adafruit_FONA.cpp +++ b/Adafruit_FONA.cpp @@ -179,12 +179,12 @@ bool Adafruit_FONA::setBaudrate(uint16_t baud) { * * **NOTE** Currently this function **will only fill the 'year' variable** * - * @param year pointer to a uint8_t to be set with year data - * @param month pointer to a uint8_t to be set with month data **NOT WORKING** - * @param day pointer to a uint8_t to be set with day data **NOT WORKING** - * @param hr pointer to a uint8_t to be set with hour data **NOT WORKING** - * @param min pointer to a uint8_t to be set with minute data **NOT WORKING** - * @param sec pointer to a uint8_t to be set with year data **NOT WORKING** + * @param year Pointer to a uint8_t to be set with year data + * @param month Pointer to a uint8_t to be set with month data **NOT WORKING** + * @param day Pointer to a uint8_t to be set with day data **NOT WORKING** + * @param hr Pointer to a uint8_t to be set with hour data **NOT WORKING** + * @param min Pointer to a uint8_t to be set with minute data **NOT WORKING** + * @param sec Pointer to a uint8_t to be set with year data **NOT WORKING** * @return true: success, false: failure */ bool Adafruit_FONA::readRTC(uint8_t *year, uint8_t *month, uint8_t *day, @@ -241,7 +241,7 @@ bool Adafruit_FONA_3G::getBattVoltage(uint16_t *v) { /** * @brief Get the percentage charge of battery as reported by sim800 * - * @param p battery percentage pointer + * @param p Ponter to a uint16_t to set with the battery change as a percentage * @return true: success, false: failure */ bool Adafruit_FONA::getBattPercent(uint16_t *p) { @@ -250,8 +250,8 @@ bool Adafruit_FONA::getBattPercent(uint16_t *p) { /** * @brief Get the current ADC voltage * - * @param v ADC voltage pointer to be filled with the current value in mV - * (uint16_t) + * @param v Ponter to a uint16_t to set with the ADC voltage + * * @return true: success, false: failure */ bool Adafruit_FONA::getADCVoltage(uint16_t *v) { @@ -263,7 +263,7 @@ bool Adafruit_FONA::getADCVoltage(uint16_t *v) { /** * @brief Unlock the sim with a provided PIN * - * @param pin pointer to the pin buffer to use to unlock the SIM + * @param pin Pointer to a buffer with the PIN to use to unlock the SIM * @return uint8_t */ uint8_t Adafruit_FONA::unlockSIM(char *pin) { @@ -280,7 +280,7 @@ uint8_t Adafruit_FONA::unlockSIM(char *pin) { /** * @brief Get the SIM CCID * - * @param ccid pointer to ccid buffer + * @param ccid Pointer to a buffer to be filled with the CCID * @return uint8_t */ uint8_t Adafruit_FONA::getSIMCCID(char *ccid) { @@ -305,7 +305,7 @@ uint8_t Adafruit_FONA::getSIMCCID(char *ccid) { /** * @brief Get the IMEI * - * @param imei buffer + * @param imei Pointer to a buffer to be filled with the IMEI * @return uint8_t */ uint8_t Adafruit_FONA::getIMEI(char *imei) { @@ -325,7 +325,16 @@ uint8_t Adafruit_FONA::getIMEI(char *imei) { /** * @brief Gets the current network status * - * @return uint8_t The nework status + * @return uint8_t The nework status: + * + * * 0: Not registered, MT is not currently searching a new operator to + * register to + * * 1: Registered, home network + * * 2: Not registered, but MT is currently searching a newoperator to register + * to + * * 3: Registration denied + * * 4: Unknown + * * 5: Registered, roaming */ uint8_t Adafruit_FONA::getNetworkStatus(void) { uint16_t status; @@ -354,7 +363,9 @@ uint8_t Adafruit_FONA::getRSSI(void) { /** * @brief Set the audio ouput * - * @param audio_output The output to set. 0 is headset, 1 is external audio + * @param audio_output The output to set. + * * 0: headset + * * 1: external audio * @return true: success, false: failure */ bool Adafruit_FONA::setAudio(uint8_t audio_output) { @@ -380,11 +391,11 @@ uint8_t Adafruit_FONA::getVolume(void) { /** * @brief Set the volume * - * @param i The new volume to set + * @param volume_level The new volume to set * @return true: success, false: failure */ -bool Adafruit_FONA::setVolume(uint8_t i) { - return sendCheckReply(F("AT+CLVL="), i, ok_reply); +bool Adafruit_FONA::setVolume(uint8_t volume_level) { + return sendCheckReply(F("AT+CLVL="), volume_level, ok_reply); } /** @@ -430,7 +441,10 @@ bool Adafruit_FONA_3G::playToolkitTone(uint8_t t, uint16_t len) { * @brief Set the microphone gain * * - * @param a Which microphone gain to set. 0 is headset, 1 is external audio + * @param a Which microphone gain to set. + * * 0: headset + * * 1: external audio + * * @param level The new gain level * @return true: success, false: failure */ @@ -448,7 +462,9 @@ bool Adafruit_FONA::setMicVolume(uint8_t a, uint8_t level) { * @brief Turn the FM Radio on or off * * @param onoff true; on false: off - * @param a The audio source to use. 0 is headset, 1 is external audio + * @param a The audio source to use: + * * 0: headset + * * 1: external audio * @return true: success, false: failure */ bool Adafruit_FONA::FMradio(bool onoff, uint8_t a) { @@ -540,8 +556,8 @@ int8_t Adafruit_FONA::getFMSignalLevel(uint16_t station) { /** * @brief Set the PWM Period and Duty Cycle * - * @param period - * @param duty + * @param period The PWM period + * @param duty The PWM duty cycle * @return true: success, false: failure */ bool Adafruit_FONA::setPWM(uint16_t period, uint8_t duty) { @@ -558,7 +574,7 @@ bool Adafruit_FONA::setPWM(uint16_t period, uint8_t duty) { /** * @brief Call a phone number * - * @param number The phone number to call + * @param number Pointer to a buffer with the phone number to call * @return true: success, false: failure */ bool Adafruit_FONA::callPhone(char *number) { @@ -575,8 +591,12 @@ bool Adafruit_FONA::callPhone(char *number) { /** * @brief Get the current call status * - * @return uint8_t The call status: 0 ready, 1 failure, 2 unkown, 3 ringing, 4 - * call in progress + * @return uint8_t The call status: + * * 0: Ready + * * 1: Failure + * * 2: Unknown + * * 3: Ringing + * * 4: Call in progress */ uint8_t Adafruit_FONA::getCallStatus(void) { uint16_t phoneStatus; @@ -637,7 +657,7 @@ bool Adafruit_FONA::_incomingCall = false; * @brief Enable or disable caller ID * * @param enable true to enable, false to disable - * @param interrupt The interrupt to attach + * @param interrupt An optional interrupt to attach * @return true: success, false: failure */ bool Adafruit_FONA::callerIdNotification(bool enable, uint8_t interrupt) { @@ -653,7 +673,8 @@ bool Adafruit_FONA::callerIdNotification(bool enable, uint8_t interrupt) { /** * @brief Get the number of the incoming call * - * @param phonenum The incoming caller's phone number + * @param phonenum Pointer to a buffer to hold the incoming caller's phone + * number * @return true: success, false: failure */ bool Adafruit_FONA::incomingCallNumber(char *phonenum) { @@ -683,7 +704,7 @@ bool Adafruit_FONA::incomingCallNumber(char *phonenum) { /** * @brief Get the current SMS Iterrupt * - * @return uint8_t The reply + * @return uint8_t The SMS interrupt or 0 on failure */ uint8_t Adafruit_FONA::getSMSInterrupt(void) { uint16_t reply; @@ -731,14 +752,14 @@ int8_t Adafruit_FONA::getNumSMS(void) { /** * @brief Read an SMS message into a provided buffer * - * @param i + * @param message_index The SMS message index to retrieve * @param smsbuff SMS message buffer * @param maxlen The maximum read length * @param readlen The length read * @return true: success, false: failure */ -bool Adafruit_FONA::readSMS(uint8_t i, char *smsbuff, uint16_t maxlen, - uint16_t *readlen) { +bool Adafruit_FONA::readSMS(uint8_t message_index, char *smsbuff, + uint16_t maxlen, uint16_t *readlen) { // text mode if (!sendCheckReply(F("AT+CMGF=1"), ok_reply)) return false; @@ -753,9 +774,9 @@ bool Adafruit_FONA::readSMS(uint8_t i, char *smsbuff, uint16_t maxlen, DEBUG_PRINT(F("AT+CMGR=")); DEBUG_PRINTLN(i); - // getReply(F("AT+CMGR="), i, 1000); // do not print debug! + // getReply(F("AT+CMGR="), message_index, 1000); // do not print debug! mySerial->print(F("AT+CMGR=")); - mySerial->println(i); + mySerial->println(message_index); readline(1000); // timeout // DEBUG_PRINT(F("Reply: ")); DEBUG_PRINTLN(replybuffer); @@ -784,19 +805,17 @@ bool Adafruit_FONA::readSMS(uint8_t i, char *smsbuff, uint16_t maxlen, /** * @brief Retrieve the sender of the specified SMS message and copy it as a - string to - * the sender buffer. Up to senderlen characters of the sender will be copied - * and a null terminator will be added if less than senderlen charactesr are - * copied to the result. Returns true if a result was successfully retrieved, - * otherwise false. - + * string to the sender buffer. Up to senderlen characters of the sender + * will be copied and a null terminator will be added if less than senderlen + * characters are copied to the result. * - * @param i - * @param sender The sender buffer - * @param senderlen the length to read - * @return true: success, false: failure + * @param message_index The SMS message index to retrieve the sender for + * @param sender Pointer to a buffer to fill with the sender + * @param senderlen The maximum length to read + * @return true: a result was successfully retrieved, false: failure */ -bool Adafruit_FONA::getSMSSender(uint8_t i, char *sender, int senderlen) { +bool Adafruit_FONA::getSMSSender(uint8_t message_index, char *sender, + int senderlen) { // Ensure text mode and all text mode parameters are sent. if (!sendCheckReply(F("AT+CMGF=1"), ok_reply)) return false; @@ -804,11 +823,11 @@ bool Adafruit_FONA::getSMSSender(uint8_t i, char *sender, int senderlen) { return false; DEBUG_PRINT(F("AT+CMGR=")); - DEBUG_PRINTLN(i); + DEBUG_PRINTLN(message_index); // Send command to retrieve SMS message and parse a line of response. mySerial->print(F("AT+CMGR=")); - mySerial->println(i); + mySerial->println(message_index); readline(1000); DEBUG_PRINTLN(replybuffer); @@ -873,19 +892,19 @@ bool Adafruit_FONA::sendSMS(char *smsaddr, char *smsmsg) { /** * @brief Delete an SMS Message * - * @param i The message to delete + * @param message_index The message to delete * @return true: success, false: failure */ -bool Adafruit_FONA::deleteSMS(uint8_t i) { +bool Adafruit_FONA::deleteSMS(uint8_t message_index) { if (!sendCheckReply(F("AT+CMGF=1"), ok_reply)) return false; // read an sms char sendbuff[12] = "AT+CMGD=000"; - sendbuff[8] = (i / 100) + '0'; - i %= 100; - sendbuff[9] = (i / 10) + '0'; - i %= 10; - sendbuff[10] = i + '0'; + sendbuff[8] = (message_index / 100) + '0'; + message_index %= 100; + sendbuff[9] = (message_index / 10) + '0'; + message_index %= 10; + sendbuff[10] = message_index + '0'; return sendCheckReply(sendbuff, ok_reply, 2000); } @@ -1005,19 +1024,19 @@ bool Adafruit_FONA::enableNTPTimeSync(bool onoff, /** * @brief Get the current time * - * @param buff Time buffer + * @param time_buffer Pointer to a buffer to hold the time * @param maxlen maximum read length * @return true: success, false: failure */ -bool Adafruit_FONA::getTime(char *buff, uint16_t maxlen) { +bool Adafruit_FONA::getTime(char *time_buffer, uint16_t maxlen) { getReply(F("AT+CCLK?"), (uint16_t)10000); if (strncmp(replybuffer, "+CCLK: ", 7) != 0) return false; char *p = replybuffer + 7; uint16_t lentocopy = min(maxlen - 1, (int)strlen(p)); - strncpy(buff, p, lentocopy + 1); - buff[lentocopy] = 0; + strncpy(time_buffer, p, lentocopy + 1); + time_buffer[lentocopy] = 0; readline(); // eat OK @@ -1092,7 +1111,11 @@ bool Adafruit_FONA_3G::enableGPS(bool onoff) { /** * @brief Get teh GPS status * - * @return int8_t The GPS status + * @return int8_t The GPS status: + * * 0: GPS off + * 1: No fix + * 2: 2D fix + * 3: 3D fix */ int8_t Adafruit_FONA::GPSstatus(void) { if (_type == FONA808_V2) { @@ -1186,11 +1209,12 @@ uint8_t Adafruit_FONA::getGPS(uint8_t arg, char *buffer, uint8_t maxbuff) { /** * @brief Get a GPS reading * - * @param lat latitude pointer - * @param lon longitude pointer - * @param speed_kph speed pointer - * @param heading heading pointer - * @param altitude altitude pointer + * @param lat Pointer to a buffer to be filled with thelatitude + * @param lon Pointer to a buffer to be filled with the longitude + * @param speed_kph Pointer to a buffer to be filled with the speed in + * kilometers per hour + * @param heading Pointer to a buffer to be filled with the heading + * @param altitude Pointer to a buffer to be filled with the altitude * @return true: success, false: failure */ bool Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, @@ -1488,22 +1512,29 @@ bool Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, } /** - * @brief Enable GPS NMEA + * @brief Enable GPS NMEA output + + * @param enable_value + * * FONA 808 v2: + * * 0: Disable + * * 1: Enable + * * For Others see the application note for information on the + * `AT+CGPSOUT=` command: + * * + https://cdn-shop.adafruit.com/datasheets/SIM808_GPS_Application_Note_V1.00.pdf * - * @param i mode * @return true: success, false: failure */ -bool Adafruit_FONA::enableGPSNMEA(uint8_t i) { - +bool Adafruit_FONA::enableGPSNMEA(uint8_t enable_value) { char sendbuff[15] = "AT+CGPSOUT=000"; - sendbuff[11] = (i / 100) + '0'; - i %= 100; - sendbuff[12] = (i / 10) + '0'; - i %= 10; - sendbuff[13] = i + '0'; + sendbuff[11] = (enable_value / 100) + '0'; + enable_value %= 100; + sendbuff[12] = (enable_value / 10) + '0'; + enable_value %= 10; + sendbuff[13] = enable_value + '0'; if (_type == FONA808_V2) { - if (i) + if (enable_value) return sendCheckReply(F("AT+CGNSTST=1"), ok_reply); else return sendCheckReply(F("AT+CGNSTST=0"), ok_reply); @@ -1685,7 +1716,9 @@ bool Adafruit_FONA_3G::enableGPRS(bool onoff) { /** * @brief Get the GPRS state * - * @return uint8_t The GPRS state + * @return uint8_t The GPRS state: + * * 0: Attached + * * 1: Detached */ uint8_t Adafruit_FONA::GPRSstate(void) { uint16_t state; @@ -1698,9 +1731,9 @@ uint8_t Adafruit_FONA::GPRSstate(void) { /** * @brief Set the GPRS network settings * - * @param apn Access point name - * @param username Username - * @param password Password + * @param apn Pointer to the Access point name buffer + * @param username Pointer to the Username buffer + * @param password Pointer to the Password buffer */ void Adafruit_FONA::setGPRSNetworkSettings(FONAFlashStringPtr apn, FONAFlashStringPtr username, @@ -1713,8 +1746,8 @@ void Adafruit_FONA::setGPRSNetworkSettings(FONAFlashStringPtr apn, /** * @brief Get GSM location * - * @param errorcode - * @param buff location buffer + * @param errorcode Pointer to a uint16_t to hold any resulting error code + * @param buff Pointer to a buffer to hold the location * @param maxlen maximum read length * @return true: success, false: failure */ @@ -1738,8 +1771,8 @@ bool Adafruit_FONA::getGSMLoc(uint16_t *errorcode, char *buff, /** * @brief Get GSM Location * - * @param lat latitude pointer - * @param lon longitude pointer + * @param lat Pointer to a buffer to hold the latitude + * @param lon Pointer to a buffer to hold the longitude * @return true: success, false: failure */ bool Adafruit_FONA::getGSMLoc(float *lat, float *lon) { @@ -1775,8 +1808,8 @@ bool Adafruit_FONA::getGSMLoc(float *lat, float *lon) { /** * @brief Start a TCP connection * - * @param server The server to connect to - * @param port The port to connect to + * @param server Pointer to a buffer with the server to connect to + * @param port Pointer to a buffer witht the port to connect to * @return true: success, false: failure */ @@ -1842,20 +1875,20 @@ bool Adafruit_FONA::TCPconnected(void) { } /** - * @brief Send TCP Packets + * @brief Send data via TCP * - * @param packet Packet buffer - * @param len Length to send + * @param data Pointer to a buffer with the data to send + * @param len length of the data to send * @return true: success, false: failure */ -bool Adafruit_FONA::TCPsend(char *packet, uint8_t len) { +bool Adafruit_FONA::TCPsend(char *data, uint8_t len) { DEBUG_PRINT(F("AT+CIPSEND=")); DEBUG_PRINTLN(len); #ifdef ADAFRUIT_FONA_DEBUG for (uint16_t i = 0; i < len; i++) { DEBUG_PRINT(F(" 0x")); - DEBUG_PRINT(packet[i], HEX); + DEBUG_PRINT(data[i], HEX); } #endif DEBUG_PRINTLN(); @@ -1870,7 +1903,7 @@ bool Adafruit_FONA::TCPsend(char *packet, uint8_t len) { if (replybuffer[0] != '>') return false; - mySerial->write(packet, len); + mySerial->write(data, len); readline(3000); // wait up to 3 seconds to send the data DEBUG_PRINT(F("\t<--- ")); @@ -1897,7 +1930,7 @@ uint16_t Adafruit_FONA::TCPavailable(void) { /** * @brief Read from a TCP socket * - * @param buff The read buffer + * @param buff Pointer to a buffer to read into * @param len The number of bytes to read * @return uint16_t The number of bytes read */ @@ -1950,8 +1983,8 @@ bool Adafruit_FONA::HTTP_term() { /** * @brief Start sending an HTTP parameter * - * @param parameter The parameter to send - * @param quoted true to quote the parameter + * @param parameter Pointer to a buffer with the parameter to send + * @param quoted true if the parameter should be quoted */ void Adafruit_FONA::HTTP_para_start(FONAFlashStringPtr parameter, bool quoted) { flushInput(); @@ -1972,7 +2005,7 @@ void Adafruit_FONA::HTTP_para_start(FONAFlashStringPtr parameter, bool quoted) { /** * @brief Finish sending an HTTP parameter * - * @param quoted true if quoted + * @param quoted true if the parameter should be quoted * @return true: success, false: failure */ bool Adafruit_FONA::HTTP_para_end(bool quoted) { @@ -1987,8 +2020,8 @@ bool Adafruit_FONA::HTTP_para_end(bool quoted) { /** * @brief Send HTTP parameter * - * @param parameter The parameter to send - * @param value The parameter value + * @param parameter Pointer to a buffer with the parameter to send + * @param value Pointer to a buffer with the parameter value * @return true: success, false: failure */ bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, const char *value) { @@ -2000,8 +2033,8 @@ bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, const char *value) { /** * @brief Send HTTP parameter * - * @param parameter The parameter to send - * @param value The parameter value + * @param parameter Pointer to a buffer with the parameter to send + * @param value Pointer to a buffer with the parameter value * @return true: success, false: failure */ bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, @@ -2014,7 +2047,7 @@ bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, /** * @brief Send HTTP parameter * - * @param parameter The parameter to send + * @param parameter Pointer to a buffer with the parameter to send * @param value The parameter value * @return true: success, false: failure */ @@ -2025,10 +2058,11 @@ bool Adafruit_FONA::HTTP_para(FONAFlashStringPtr parameter, int32_t value) { } /** - * @brief Get HTTP data + * @brief Begin sending data via HTTP * - * @param size The amount of data to get - * @param maxTime The maximum amount of time + * @param size The amount of data to be sent in bytes + * @param maxTime The maximum amount of time in which to send the data, in + * milliseconds * @return true: success, false: failure */ bool Adafruit_FONA::HTTP_data(uint32_t size, uint32_t maxTime) { @@ -2051,9 +2085,15 @@ bool Adafruit_FONA::HTTP_data(uint32_t size, uint32_t maxTime) { /** * @brief Make an HTTP Request * - * @param method The request method - * @param status The request status - * @param datalen The data length + * @param method The request method: + * * 0: GET + * * 1: POST + * * 2: HEAD + * @param status Pointer to a uint16_t to hold the request status as an RFC2616 + * HTTP response code: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes + * + * @param datalen Pointer to the a `uint16_t` to hold the length of the data + * read * @param timeout Timeout for waiting for response * @return true: success, false: failure */ @@ -2076,7 +2116,8 @@ bool Adafruit_FONA::HTTP_action(uint8_t method, uint16_t *status, /** * @brief Read all available HTTP data * - * @param datalen The length read + * @param datalen Pointer to the a `uint16_t` to hold the length of the data + * read * @return true: success, false: failure */ bool Adafruit_FONA::HTTP_readall(uint16_t *datalen) { @@ -2102,9 +2143,12 @@ bool Adafruit_FONA::HTTP_ssl(bool onoff) { /** * @brief Start a HTTP GET request * - * @param url The URL to request - * @param status request status pointer - * @param datalen The data length + * @param url Pointer to a buffer with the URL to request + * @param status Pointer to a uint16_t to hold the request status as an RFC2616 + * HTTP response code: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes + * + * @param datalen Pointer to the a `uint16_t` to hold the length of the data + * read * @return true: success, false: failure */ bool Adafruit_FONA::HTTP_GET_start(char *url, uint16_t *status, @@ -2173,11 +2217,12 @@ void Adafruit_FONA::HTTP_GET_end(void) { HTTP_term(); } /** * @brief Start an HTTP POST request * - * @param url The URL to POST + * @param url Pointer to a buffer with the URL to POST * @param contenttype The message content type - * @param postdata The POST data to be sent + * @param postdata Pointer to a buffer with the POST data to be sent * @param postdatalen The length of the POST data - * @param status The request status + * @param status Pointer to a uint16_t to hold the request status as an RFC2616 + * HTTP response code: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes * @param datalen * @return true * @return false @@ -2224,7 +2269,7 @@ void Adafruit_FONA::HTTP_POST_end(void) { HTTP_term(); } /** * @brief Set the User Agent for HTTP requests * - * @param useragent The user agent string to use + * @param useragent Pointer to a buffer with the user agent string to set */ void Adafruit_FONA::setUserAgent(FONAFlashStringPtr useragent) { this->useragent = useragent; @@ -2241,7 +2286,7 @@ void Adafruit_FONA::setHTTPSRedirect(bool onoff) { httpsredirect = onoff; } /** * @brief Configure an HTTP request * - * @param url The URL to make the request to + * @param url Pointer to a buffer with the URL to POST * @return true: success, false: failure */ bool Adafruit_FONA::HTTP_setup(char *url) { @@ -2452,8 +2497,8 @@ uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr send, uint16_t timeout) { /** * @brief Send a command as prefix and suffix * - * @param prefix The command prefix - * @param suffix The command suffix + * @param prefix Pointer to a buffer with the command prefix + * @param suffix Pointer to a buffer with the command suffix * @param timeout Timeout for reading a response * @return uint8_t The response length */ @@ -2481,7 +2526,7 @@ uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr prefix, char *suffix, /** * @brief Send a command with * - * @param prefix The command prefix + * @param prefix Pointer to a buffer with the command prefix * @param suffix The command suffix * @param timeout Timeout for reading a response * @return uint8_t The response length @@ -2510,7 +2555,7 @@ uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr prefix, int32_t suffix, /** * @brief Send command with prefix and two suffixes * - * @param prefix The command prefix + * @param prefix Pointer to a buffer with the command prefix * @param suffix1 The comannd first suffix * @param suffix2 The command second suffix * @param timeout Timeout for reading a response @@ -2544,8 +2589,8 @@ uint8_t Adafruit_FONA::getReply(FONAFlashStringPtr prefix, int32_t suffix1, /** * @brief Send command prefix and suffix, returning the response length * - * @param prefix The command prefix - * @param suffix The command suffix + * @param prefix Pointer to a buffer with the command prefix + * @param suffix Pointer to a buffer with the command suffix * @param timeout Timeout for reading a response * @return uint8_t The response length */ @@ -2576,7 +2621,7 @@ uint8_t Adafruit_FONA::getReplyQuoted(FONAFlashStringPtr prefix, /** * @brief Send data and verify the response matches an expected response * - * @param send The buffer of data to send + * @param send Pointer to the buffer of data to send * @param reply Buffer with the expected reply * @param timeout Read timeout * @return true: success, false: failure @@ -2600,8 +2645,8 @@ bool Adafruit_FONA::sendCheckReply(char *send, char *reply, uint16_t timeout) { /** * @brief Send data and verify the response matches an expected response * - * @param send The buffer of data to send - * @param reply Buffer with the expected reply + * @param send Pointer to the buffer of data to send + * @param reply Pointer to a buffer with the expected reply * @param timeout Read timeout * @return true: success, false: failure */ @@ -2616,8 +2661,8 @@ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr send, /** * @brief Send data and verify the response matches an expected response * - * @param send The buffer of data to send - * @param reply Buffer with the expected reply + * @param send Pointer to the buffer of data to send + * @param reply Pointer to a buffer with the expected reply * @param timeout Read timeout * @return true: success, false: failure */ @@ -2634,9 +2679,9 @@ bool Adafruit_FONA::sendCheckReply(char *send, FONAFlashStringPtr reply, /** * @brief Send data and verify the response matches an expected response * - * @param prefix The prefix buffer of data to send - * @param suffix The suffix buffer of data to send - * @param reply Buffer with the expected reply + * @param prefix Pointer to a buffer with the prefix send + * @param suffix Pointer to a buffer with the suffix send + * @param reply Pointer to a buffer with the expected reply * @param timeout Read timeout * @return true: success, false: failure */ @@ -2652,9 +2697,9 @@ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, char *suffix, /** * @brief Send data and verify the response matches an expected response * - * @param prefix The prefix buffer of data to send + * @param prefix Pointer to a buffer with the prefix to send * @param suffix The suffix to send - * @param reply Buffer with the expected reply + * @param reply Pointer to a buffer with the expected reply * @param timeout Read timeout * @return true: success, false: failure */ @@ -2667,10 +2712,10 @@ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix, /** * @brief Send data and verify the response matches an expected response * - * @param prefix The prefix buffer of data to send + * @param prefix Ponter to a buffer with the prefix to send * @param suffix1 The first suffix to send * @param suffix2 The second suffix to send - * @param reply Buffer with the expected reply + * @param reply Pointer to a buffer with the expected reply * @param timeout Read timeout * @return true: success, false: failure */ @@ -2684,9 +2729,9 @@ bool Adafruit_FONA::sendCheckReply(FONAFlashStringPtr prefix, int32_t suffix1, /** * @brief Send data and verify the response matches an expected response * - * @param prefix The prefix buffer of data to send - * @param suffix The suffix buffer send - * @param reply The expected response + * @param prefix Pointer to a buffer with the prefix to send + * @param suffix Pointer to a buffer with the suffix to send + * @param reply Pointer to a buffer with the expected response * @param timeout Read timeout * @return true: success, false: failure */ @@ -2699,18 +2744,18 @@ bool Adafruit_FONA::sendCheckReplyQuoted(FONAFlashStringPtr prefix, } /** - * @brief Parse a received reply + * @brief Parse a string in the response fields using a designated separator + * and copy the value at the specified index in to the supplied buffer. * - * @param toreply Reply string - * @param v read buffer + * @param toreply Pointer to a buffer with reply with the field being parsed + * @param v Pointer to a buffer to fill with the the value from the parsed field * @param divider The divider character - * @param index The index to read up to + * @param index The index of the parsed field to retrieve * @return true: success, false: failure */ bool Adafruit_FONA::parseReply(FONAFlashStringPtr toreply, uint16_t *v, char divider, uint8_t index) { - char *p = prog_char_strstr( - replybuffer, (prog_char *)toreply); // get the pointer to the voltage + char *p = prog_char_strstr(replybuffer, (prog_char *)toreply); if (p == 0) return false; p += prog_char_strlen((prog_char *)toreply); @@ -2730,16 +2775,13 @@ bool Adafruit_FONA::parseReply(FONAFlashStringPtr toreply, uint16_t *v, /** - - * @brief Parse a string in the response fields and copy its value - * (without quotes) to the specified character array (v). Only up - * to maxlen characters are copied into the result buffer, so make - * sure to pass a large enough buffer to handle the response. + * @brief Parse a string in the response fields using a designated separator + * and copy the string at the specified index in to the supplied char buffer. * - * @param toreply - * @param v The response buffer + * @param toreply Pointer to a buffer with reply with the field being parsed + * @param v Pointer to a buffer to fill with the string * @param divider The divider character - * @param index + * @param index The index of the parsed field to retrieve * @return true: success, false: failure */ bool Adafruit_FONA::parseReply(FONAFlashStringPtr toreply, char *v, @@ -2771,16 +2813,17 @@ bool Adafruit_FONA::parseReply(FONAFlashStringPtr toreply, char *v, // /** - * @brief Parse a quoted string in the response fields and copy its value - * (without quotes) to the specified character array (v). Only up to - * maxlen characters are copied into the result buffer, - * so make sure to pass a large enough buffer to handle the response. * - * @param toreply - * @param v response buffer + * @brief Parse a string in the response fields using a designated separator + * and copy the string (without quotes) at the specified index in to the + * supplied char buffer. + * + * @param toreply Pointer to a buffer with reply with the field being parsed + * @param v Pointer to a buffer to fill with the string. Make sure to supply a + * buffer large enough to retrieve the expected value * @param maxlen The maximum read length * @param divider The divider character - * @param index + * @param index The index of the parsed field to retrieve * @return true: success, false: failure */ bool Adafruit_FONA::parseReplyQuoted(FONAFlashStringPtr toreply, char *v, @@ -2822,11 +2865,12 @@ bool Adafruit_FONA::parseReplyQuoted(FONAFlashStringPtr toreply, char *v, /** * @brief Send data and parse the reply * - * @param tosend The data buffer to send - * @param toreply The expected reply string - * @param v The data buffer + * @param tosend Pointer to the data buffer to send + * @param toreply Pointer to a buffer with the expected reply string + * @param v Pointer to a uint16_t buffer to hold the value of the parsed + * response * @param divider The divider character - * @param index The index to read to + * @param index The index of the parsed field to retrieve * @return true: success, false: failure */ bool Adafruit_FONA::sendParseReply(FONAFlashStringPtr tosend, @@ -2847,11 +2891,11 @@ bool Adafruit_FONA::sendParseReply(FONAFlashStringPtr tosend, /** * @brief Send data and parse the reply * - * @param tosend The data buffer to send + * @param tosend Pointer to he data buffer to send * @param toreply The expected reply string - * @param f data buffer (float) + * @param f Pointer to a float buffer to hold value of the parsed field * @param divider The divider character - * @param index The index to read to + * @param index The index of the parsed field to retrieve * @return true: success, false: failure */ bool Adafruit_FONA_3G::sendParseReply(FONAFlashStringPtr tosend, @@ -2870,16 +2914,15 @@ bool Adafruit_FONA_3G::sendParseReply(FONAFlashStringPtr tosend, /** * @brief Parse a reply * - * @param toreply The expected reply string - * @param f data buffer (float) + * @param toreply Pointer to a buffer with the expected reply string + * @param f Pointer to a float buffer to hold the value of the parsed field * @param divider The divider character - * @param index The index to read to + * @param index The index of the parsed field to retrieve * @return true: success, false: failure */ bool Adafruit_FONA_3G::parseReply(FONAFlashStringPtr toreply, float *f, char divider, uint8_t index) { - char *p = prog_char_strstr( - replybuffer, (prog_char *)toreply); // get the pointer to the voltage + char *p = prog_char_strstr(replybuffer, (prog_char *)toreply); if (p == 0) return false; p += prog_char_strlen((prog_char *)toreply); diff --git a/Adafruit_FONA.h b/Adafruit_FONA.h index 63432fc..0f0ad89 100644 --- a/Adafruit_FONA.h +++ b/Adafruit_FONA.h @@ -103,7 +103,7 @@ class Adafruit_FONA : public FONAStreamType { // set Audio output bool setAudio(uint8_t audio_output); - bool setVolume(uint8_t i); + bool setVolume(uint8_t volume_level); uint8_t getVolume(void); bool playToolkitTone(uint8_t t, uint16_t len); bool setMicVolume(uint8_t a, uint8_t level); @@ -120,17 +120,18 @@ class Adafruit_FONA : public FONAStreamType { bool setSMSInterrupt(uint8_t i); uint8_t getSMSInterrupt(void); int8_t getNumSMS(void); - bool readSMS(uint8_t i, char *smsbuff, uint16_t max, uint16_t *readsize); + bool readSMS(uint8_t message_index, char *smsbuff, uint16_t max, + uint16_t *readsize); bool sendSMS(char *smsaddr, char *smsmsg); - bool deleteSMS(uint8_t i); - bool getSMSSender(uint8_t i, char *sender, int senderlen); + bool deleteSMS(uint8_t message_index); + bool getSMSSender(uint8_t message_index, char *sender, int senderlen); bool sendUSSD(char *ussdmsg, char *ussdbuff, uint16_t maxlen, uint16_t *readlen); // Time bool enableNetworkTimeSync(bool onoff); bool enableNTPTimeSync(bool onoff, FONAFlashStringPtr ntpserver = 0); - bool getTime(char *buff, uint16_t maxlen); + bool getTime(char *time_buffer, uint16_t maxlen); // GPRS handling bool enableGPRS(bool onoff); @@ -147,13 +148,13 @@ class Adafruit_FONA : public FONAStreamType { uint8_t getGPS(uint8_t arg, char *buffer, uint8_t maxbuff); bool getGPS(float *lat, float *lon, float *speed_kph = 0, float *heading = 0, float *altitude = 0); - bool enableGPSNMEA(uint8_t nmea); + bool enableGPSNMEA(uint8_t enable_value); // TCP raw connections bool TCPconnect(char *server, uint16_t port); bool TCPclose(void); bool TCPconnected(void); - bool TCPsend(char *packet, uint8_t len); + bool TCPsend(char *data, uint8_t len); uint16_t TCPavailable(void); uint16_t TCPread(uint8_t *buff, uint8_t len); From e7dca5e9aad8c4b411e60cc79636eaf28f4e987c Mon Sep 17 00:00:00 2001 From: siddacious Date: Tue, 31 Mar 2020 15:16:55 -0700 Subject: [PATCH 14/14] fixing typo --- Adafruit_FONA.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_FONA.cpp b/Adafruit_FONA.cpp index 07f831b..174709b 100644 --- a/Adafruit_FONA.cpp +++ b/Adafruit_FONA.cpp @@ -772,7 +772,7 @@ bool Adafruit_FONA::readSMS(uint8_t message_index, char *smsbuff, uint16_t thesmslen = 0; DEBUG_PRINT(F("AT+CMGR=")); - DEBUG_PRINTLN(i); + DEBUG_PRINTLN(message_index); // getReply(F("AT+CMGR="), message_index, 1000); // do not print debug! mySerial->print(F("AT+CMGR="));