arm studio build

Dependencies:   libxDot-mbed5

Revision:
0:a91cd1b08360
Child:
1:0d25d9ddbe9f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/wbit_util.cpp	Mon Jun 18 17:31:35 2018 +0000
@@ -0,0 +1,41 @@
+#include "wbit_util.h"
+#include "dot_util.h"
+#include "mbed.h"
+#include "mDot.h"
+
+uint8_t j_attempts = 0;
+//return number of attempts it took to join the network
+uint8_t join_network_attempts_wbit() {
+    return j_attempts;
+}    
+
+bool join_network_wbit(uint8_t nmbAttempts) {
+    //int32_t j_attempts = 0;
+    j_attempts = 0;
+    int32_t ret = mDot::MDOT_ERROR;
+    
+// attempt to join the network
+    while (ret != mDot::MDOT_OK) {
+        j_attempts++;
+        logInfo("attempt %d to join network",j_attempts);
+        ret = dot->joinNetwork();
+        if (ret == mDot::MDOT_OK) return true;
+        
+        logError("failed to join network %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
+        if (j_attempts >= nmbAttempts)
+        {
+            logInfo("attempts %d to join network exceeds specified attempts $d ",j_attempts,nmbAttempts);   
+            return false;
+        }               
+        // in some frequency bands we need to wait until another channel is available before transmitting again
+        uint32_t delay_s = (dot->getNextTxMs() / 1000) + 1;
+        if (delay_s < 2) {
+            logInfo("waiting %lu s until next free channel", delay_s);
+            wait(delay_s);
+        } else {
+            logInfo("sleeping %lu s until next free channel", delay_s);
+            dot->sleep(delay_s, mDot::RTC_ALARM, false);
+        }        
+    }//while
+    return false;
+}
\ No newline at end of file