Echo example of class C devices receiving downlink and sending as next uplink

Dependencies:   libmDot-mbed5 ISL29011

Files at this revision

API Documentation at this revision

Comitter:
jreiss
Date:
Thu Mar 07 14:12:55 2019 +0000
Parent:
35:470b2b934241
Commit message:
Add ack received with two uplinks sent after join

Changed in this revision

examples/src/class_c_example_copy.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 470b2b934241 -r 18e6b0e367b6 examples/src/class_c_example_copy.cpp
--- a/examples/src/class_c_example_copy.cpp	Tue Mar 05 13:34:21 2019 +0000
+++ b/examples/src/class_c_example_copy.cpp	Thu Mar 07 14:12:55 2019 +0000
@@ -22,14 +22,14 @@
 // * either the network name and passphrase can be used or //
 //     the network ID (8 bytes) and KEY (16 bytes)         //
 /////////////////////////////////////////////////////////////
-static std::string network_name = "iotlab01";
-static std::string network_passphrase = "11223344";
-//static uint8_t network_id[] = { 0x6C, 0x4E, 0xEF, 0x66, 0xF4, 0x79, 0x86, 0xA6 };
-//static uint8_t network_key[] = { 0x1F, 0x33, 0xA1, 0x70, 0xA5, 0xF1, 0xFD, 0xA0, 0xAB, 0x69, 0x7A, 0xAE, 0x2B, 0x95, 0x91, 0x6B };
+//static std::string network_name = "iotlab01";
+//static std::string network_passphrase = "11223344";
+static uint8_t network_id[] = { 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11 };
+static uint8_t network_key[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88 };
 static uint8_t frequency_sub_band = 4;
 static lora::NetworkType network_type = lora::PUBLIC_LORAWAN;
 static uint8_t join_delay = 6;
-static uint8_t ack = 0;
+static uint8_t ack = 1;
 static bool adr = true;
 
 mDot* dot = NULL;
@@ -221,8 +221,8 @@
     // only one method or the other should be used!
     // network ID = crc64(network name)
     // network KEY = cmac(network passphrase)
-    update_ota_config_name_phrase(network_name, network_passphrase, frequency_sub_band, network_type, ack);
-    //update_ota_config_id_key(network_id, network_key, frequency_sub_band, network_type, ack);
+    // update_ota_config_name_phrase(network_name, network_passphrase, frequency_sub_band, network_type, ack);
+    update_ota_config_id_key(network_id, network_key, frequency_sub_band, network_type, ack);
 
     // configure the Dot for class C operation
     // the Dot must also be configured on the gateway for class C
@@ -252,32 +252,42 @@
         std::string tx_str;
  //       uint8_t recv_from_uart;
         
-        std::vector<uint8_t> tx_data;
-        if (!dot->getNetworkJoinStatus()) {
-            join_network();
-        }
-        
-        send_string("start!",dot);
-        send_string(tx_str.c_str(),dot);
-        
+    std::vector<uint8_t> tx_data;
+   
+    int count = 0;
+    
     while (true) {
 
         // join network if not joined
         if (!dot->getNetworkJoinStatus()) {
             join_network();
-            send_string("start!",dot);
-            send_string(tx_str.c_str(),dot);
-        }
-
+            while (dot->getIsTransmitting()) ;
+            
+            dot->setAck(1);
+            
+            events.AckReceived = false;
+            
+            while (!events.AckReceived) {
+                send_string("start!",dot);
+            }
+            
+            events.AckReceived = false;
+            
+            while (!events.AckReceived) {        
+                send_string(tx_str.c_str(),dot);
+            }
+            
+            dot->setAck(0);
+        }       
         
-        
-        if (!Last_RX.empty()) {
-
+        if (!Last_RX.empty()) { // || count++ > 100) {
+            count = 0;
+            
             tx_str=Last_RX;
             Last_RX.clear();
       
             pc.printf("%s",tx_str.c_str());
-            send_string(tx_str.c_str(),dot);
+                send_string(tx_str.c_str(),dot);
             } 
             
             osDelay(100);