A mbed library for the RN2483. Heavily based on the Sodaq_RN2483 library for Arduino (https://github.com/SodaqMoja/Sodaq_RN2483). This is currently under-going initial testing, but seems to work! Tested on a NRF51 and FRDM K64F.

Dependents:   rn2483-TestProgram

Revision:
4:0c066401ae12
Parent:
3:ee222a99783c
Child:
5:eb983e9336a7
--- a/RN2483.cpp	Mon Nov 21 16:36:54 2016 +0000
+++ b/RN2483.cpp	Mon Nov 21 20:21:43 2016 +0000
@@ -212,14 +212,28 @@
 * @brief Informs the RN2483 to do an ADC conversion on the VDD.
 * @return Returns mV as a decimal from 0 to 3600. -1 on error.
 */
-long RN2483::getVDD()
+bool RN2483::getVDD(long *vdd)
 {
     _RN2483.printf(STR_CMD_GET_VDD);
     _RN2483.printf(CRLF);
-    char buffer[10];
-    if(readBytesUntil('\n', buffer, 10)) {
-        return strtol(buffer,NULL ,10);
+    Timer t;
+    t.start();
+    int timeout = t.read_ms() + RECEIVE_TIMEOUT; // hard timeouts
+    while (t.read_ms() < timeout) {
+        if (readLn() > 0) {
+            char *temp;
+            bool rc = true;
+            errno = 0;
+            *vdd = strtol(this->inputBuffer, &temp, 10);
+            if (temp == this->inputBuffer || *temp != '\0' || ((*vdd == LONG_MIN || 
+            *vdd == LONG_MAX) && errno == ERANGE)){
+                rc = false;
+            }
+            t.stop();
+            return rc;
+        }
     }
+    t.stop();
     return false;
 }
 
@@ -803,14 +817,15 @@
 * if the terminator character has been detected
 * @param The terminator character to look for
 * @param The buffer to read into.
-* @param The size of the buffer.
+* @param The number of bytes to read.
 * @return The number of bytes read. 0 means no valid data found.
 */
-size_t RN2483::readBytesUntil(char terminator, char *buffer, size_t length)
+size_t RN2483::readBytesUntil(char terminator, char *buffer, size_t bytesToRead)
 {
-    if (length < 1) return 0;
+    if (bytesToRead < 1) return 0;
+    //memset(buffer, '\0', ((sizeof buffer) / (sizeof *buffer)));
     size_t index = 0;
-    while (index < length) {
+    while (index < (bytesToRead - 1 )) {
         int c = timedRead(1000);
         if (c < 0 || c == terminator) break;
         *buffer++ = (char)c;