basic loraWAN sending, some settings done-- no keys or any of that though

Files at this revision

API Documentation at this revision

Comitter:
mbed_official
Date:
Fri Mar 09 13:15:17 2018 +0000
Parent:
1:c7fae321242f
Child:
3:8c7198d1a2a1
Commit message:
Refactor construction of LoRaWANInterface object

This is refactoring of commit 59b4e195c39 to get rid of unnecessary pointer assignment.

.
Commit copied from https://github.com/ARMmbed/mbed-os-example-lorawan

Changed in this revision

README.md Show annotated file Show diff for this revision Revisions of this file
lora_radio_helper.cpp Show diff for this revision Revisions of this file
lora_radio_helper.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
--- a/README.md	Fri Mar 09 13:00:20 2018 +0000
+++ b/README.md	Fri Mar 09 13:15:17 2018 +0000
@@ -36,7 +36,7 @@
 
 ### Add network credentials
 
-Open the file `mbed_app.json` in the root directory of your application. This file contains all the user specific configurations your application and the Mbed OS LoRaWAN stack need. 
+Open the file `mbed_app.json` in the root directory of your application. This file contains all the user specific configurations your application and the Mbed OS LoRaWAN stack need. Network credentials are typically provided by LoRa network provider.
 
 #### For OTAA
 
--- a/lora_radio_helper.cpp	Fri Mar 09 13:00:20 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,76 +0,0 @@
-/**
- * Copyright (c) 2017, Arm Limited and affiliates.
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "SX1272_LoRaRadio.h"
-#include "SX1276_LoRaRadio.h"
-
-#define SX1272   0xFF
-#define SX1276   0xEE
-
-#if (MBED_CONF_APP_LORA_RADIO == SX1272)
-
-    static SX1272_LoRaRadio radio(MBED_CONF_APP_LORA_SPI_MOSI,
-                                  MBED_CONF_APP_LORA_SPI_MISO,
-                                  MBED_CONF_APP_LORA_SPI_SCLK,
-                                  MBED_CONF_APP_LORA_CS,
-                                  MBED_CONF_APP_LORA_RESET,
-                                  MBED_CONF_APP_LORA_DIO0,
-                                  MBED_CONF_APP_LORA_DIO1,
-                                  MBED_CONF_APP_LORA_DIO2,
-                                  MBED_CONF_APP_LORA_DIO3,
-                                  MBED_CONF_APP_LORA_DIO4,
-                                  MBED_CONF_APP_LORA_DIO5,
-                                  MBED_CONF_APP_LORA_RF_SWITCH_CTL1,
-                                  MBED_CONF_APP_LORA_RF_SWITCH_CTL2,
-                                  MBED_CONF_APP_LORA_TXCTL,
-                                  MBED_CONF_APP_LORA_RXCTL,
-                                  MBED_CONF_APP_LORA_ANT_SWITCH,
-                                  MBED_CONF_APP_LORA_PWR_AMP_CTL,
-                                  MBED_CONF_APP_LORA_TCXO);
-
-#elif (MBED_CONF_APP_LORA_RADIO == SX1276)
-
-    static SX1276_LoRaRadio radio(MBED_CONF_APP_LORA_SPI_MOSI,
-                                  MBED_CONF_APP_LORA_SPI_MISO,
-                                  MBED_CONF_APP_LORA_SPI_SCLK,
-                                  MBED_CONF_APP_LORA_CS,
-                                  MBED_CONF_APP_LORA_RESET,
-                                  MBED_CONF_APP_LORA_DIO0,
-                                  MBED_CONF_APP_LORA_DIO1,
-                                  MBED_CONF_APP_LORA_DIO2,
-                                  MBED_CONF_APP_LORA_DIO3,
-                                  MBED_CONF_APP_LORA_DIO4,
-                                  MBED_CONF_APP_LORA_DIO5,
-                                  MBED_CONF_APP_LORA_RF_SWITCH_CTL1,
-                                  MBED_CONF_APP_LORA_RF_SWITCH_CTL2,
-                                  MBED_CONF_APP_LORA_TXCTL,
-                                  MBED_CONF_APP_LORA_RXCTL,
-                                  MBED_CONF_APP_LORA_ANT_SWITCH,
-                                  MBED_CONF_APP_LORA_PWR_AMP_CTL,
-                                  MBED_CONF_APP_LORA_TCXO);
-
-#else
-    #error "Unknown LoRa radio specified (SX1272,SX1276 are valid)"
-#endif
-
-/**
- * Returns a reference the LoRaRadio object
- */
-LoRaRadio& get_lora_radio()
-{
-    return radio;
-}
--- a/lora_radio_helper.h	Fri Mar 09 13:00:20 2018 +0000
+++ b/lora_radio_helper.h	Fri Mar 09 13:15:17 2018 +0000
@@ -20,12 +20,56 @@
 #ifndef APP_LORA_RADIO_HELPER_H_
 #define APP_LORA_RADIO_HELPER_H_
 
-/**
- * Helper function for the application to
- * get access to a LoRaRadio object. Based upon the target platform,
- * a certain radio driver is selected, constructed and returned to the
- * application.
- */
-LoRaRadio& get_lora_radio();
+#include "SX1272_LoRaRadio.h"
+#include "SX1276_LoRaRadio.h"
+
+#define SX1272   0xFF
+#define SX1276   0xEE
+
+#if (MBED_CONF_APP_LORA_RADIO == SX1272)
+
+    SX1272_LoRaRadio radio(MBED_CONF_APP_LORA_SPI_MOSI,
+                           MBED_CONF_APP_LORA_SPI_MISO,
+                           MBED_CONF_APP_LORA_SPI_SCLK,
+                           MBED_CONF_APP_LORA_CS,
+                           MBED_CONF_APP_LORA_RESET,
+                           MBED_CONF_APP_LORA_DIO0,
+                           MBED_CONF_APP_LORA_DIO1,
+                           MBED_CONF_APP_LORA_DIO2,
+                           MBED_CONF_APP_LORA_DIO3,
+                           MBED_CONF_APP_LORA_DIO4,
+                           MBED_CONF_APP_LORA_DIO5,
+                           MBED_CONF_APP_LORA_RF_SWITCH_CTL1,
+                           MBED_CONF_APP_LORA_RF_SWITCH_CTL2,
+                           MBED_CONF_APP_LORA_TXCTL,
+                           MBED_CONF_APP_LORA_RXCTL,
+                           MBED_CONF_APP_LORA_ANT_SWITCH,
+                           MBED_CONF_APP_LORA_PWR_AMP_CTL,
+                           MBED_CONF_APP_LORA_TCXO);
+
+#elif (MBED_CONF_APP_LORA_RADIO == SX1276)
+
+    SX1276_LoRaRadio radio(MBED_CONF_APP_LORA_SPI_MOSI,
+                           MBED_CONF_APP_LORA_SPI_MISO,
+                           MBED_CONF_APP_LORA_SPI_SCLK,
+                           MBED_CONF_APP_LORA_CS,
+                           MBED_CONF_APP_LORA_RESET,
+                           MBED_CONF_APP_LORA_DIO0,
+                           MBED_CONF_APP_LORA_DIO1,
+                           MBED_CONF_APP_LORA_DIO2,
+                           MBED_CONF_APP_LORA_DIO3,
+                           MBED_CONF_APP_LORA_DIO4,
+                           MBED_CONF_APP_LORA_DIO5,
+                           MBED_CONF_APP_LORA_RF_SWITCH_CTL1,
+                           MBED_CONF_APP_LORA_RF_SWITCH_CTL2,
+                           MBED_CONF_APP_LORA_TXCTL,
+                           MBED_CONF_APP_LORA_RXCTL,
+                           MBED_CONF_APP_LORA_ANT_SWITCH,
+                           MBED_CONF_APP_LORA_PWR_AMP_CTL,
+                           MBED_CONF_APP_LORA_TCXO);
+
+#else
+    #error "Unknown LoRa radio specified (SX1272,SX1276 are valid)"
+#endif
 
 #endif /* APP_LORA_RADIO_HELPER_H_ */
--- 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);
 
--- a/mbed_app.json	Fri Mar 09 13:00:20 2018 +0000
+++ b/mbed_app.json	Fri Mar 09 13:15:17 2018 +0000
@@ -209,6 +209,28 @@
             "lora-ant-switch":      "ANT_SWITCH",
             "lora-pwr-amp-ctl":     "NC",
             "lora-tcxo":            "NC"
+        },
+
+        "MTB_RAK811": {
+            "lora-radio":          "SX1276",
+            "lora-spi-mosi":       "SPI_RF_MOSI",
+            "lora-spi-miso":       "SPI_RF_MISO",
+            "lora-spi-sclk":       "SPI_RF_SCK",
+            "lora-cs":             "SPI_RF_CS",
+            "lora-reset":          "SPI_RF_RESET",
+            "lora-dio0":           "DIO0",
+            "lora-dio1":           "DIO1",
+            "lora-dio2":           "DIO2",
+            "lora-dio3":           "DIO3",
+            "lora-dio4":           "DIO4",
+            "lora-dio5":           "NC",
+            "lora-rf-switch-ctl1": "NC",
+            "lora-rf-switch-ctl2": "NC",
+            "lora-txctl":          "ANT_CTX_PA",
+            "lora-rxctl":          "ANT_CRX_RX",
+            "lora-ant-switch":     "NC",
+            "lora-pwr-amp-ctl":    "NC",
+            "lora-tcxo":           "RF_TCXO_EN"
         }
     },
     "macros": ["MBEDTLS_USER_CONFIG_FILE=\"mbedtls_lora_config.h\""]