lora

Revision:
2:dc95ac6d6d4e
Parent:
0:7037ed05f54f
Child:
3:8c7198d1a2a1
--- a/main.cpp	Fri Mar 09 13:00:20 2018 +0000
+++ b/main.cpp	Fri Mar 09 13:15:17 2018 +0000
@@ -74,9 +74,9 @@
 static void lora_event_handler(lorawan_event_t event);
 
 /**
- * Pointer to LoRaWAN interface
+ * Constructing Mbed LoRaWANInterface and passing it down the radio object.
  */
-static LoRaWANInterface* lorawan = NULL;
+static LoRaWANInterface lorawan(radio);
 
 /**
  * Application specific callbacks
@@ -88,10 +88,6 @@
  */
 int main (void)
 {
-    // Constructing Mbed LoRaWANInterface and passing it down the radio object.
-    LoRaWANInterface lora(get_lora_radio());
-    lorawan = &lora;
-
     // setup tracing
     setup_trace();
 
@@ -99,7 +95,7 @@
     lorawan_status_t retcode;
 
     // Initialize LoRaWAN stack
-    if (lorawan->initialize(&ev_queue) != LORAWAN_STATUS_OK) {
+    if (lorawan.initialize(&ev_queue) != LORAWAN_STATUS_OK) {
         printf("\r\n LoRa initialization failed! \r\n");
         return -1;
     }
@@ -108,10 +104,10 @@
 
     // prepare application callbacks
     callbacks.events = mbed::callback(lora_event_handler);
-    lorawan->add_app_callbacks(&callbacks);
+    lorawan.add_app_callbacks(&callbacks);
 
     // Set number of retries in case of CONFIRMED messages
-    if (lorawan->set_confirmed_msg_retries(CONFIRMED_MSG_RETRY_COUNTER)
+    if (lorawan.set_confirmed_msg_retries(CONFIRMED_MSG_RETRY_COUNTER)
                                           != LORAWAN_STATUS_OK) {
         printf("\r\n set_confirmed_msg_retries failed! \r\n\r\n");
         return -1;
@@ -121,14 +117,14 @@
            CONFIRMED_MSG_RETRY_COUNTER);
 
     // Enable adaptive data rate
-    if (lorawan->enable_adaptive_datarate() != LORAWAN_STATUS_OK) {
+    if (lorawan.enable_adaptive_datarate() != LORAWAN_STATUS_OK) {
         printf("\r\n enable_adaptive_datarate failed! \r\n");
         return -1;
     }
 
     printf("\r\n Adaptive data  rate (ADR) - Enabled \r\n");
 
-    retcode = lorawan->connect();
+    retcode = lorawan.connect();
 
     if (retcode == LORAWAN_STATUS_OK ||
         retcode == LORAWAN_STATUS_CONNECT_IN_PROGRESS) {
@@ -165,7 +161,7 @@
     packet_len = sprintf((char*) tx_buffer, "Dummy Sensor Value is %3.1f",
                     sensor_value);
 
-    retcode = lorawan->send(MBED_CONF_LORA_APP_PORT, tx_buffer, packet_len,
+    retcode = lorawan.send(MBED_CONF_LORA_APP_PORT, tx_buffer, packet_len,
                            MSG_CONFIRMED_FLAG);
 
     if (retcode < 0) {
@@ -184,7 +180,7 @@
 static void receive_message()
 {
     int16_t retcode;
-    retcode = lorawan->receive(MBED_CONF_LORA_APP_PORT, rx_buffer,
+    retcode = lorawan.receive(MBED_CONF_LORA_APP_PORT, rx_buffer,
                               LORAMAC_PHY_MAXPAYLOAD,
                               MSG_CONFIRMED_FLAG|MSG_UNCONFIRMED_FLAG);