Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MPU6050 Grove_temperature
Diff: communication/LoRaWanComm.cpp
- Revision:
- 10:d2ce206bd94e
- Parent:
- 8:e00fa6ea253c
- Child:
- 11:14864dee8646
--- a/communication/LoRaWanComm.cpp Sat Jun 29 02:14:30 2019 +0000 +++ b/communication/LoRaWanComm.cpp Sun Jul 07 12:30:40 2019 -0300 @@ -5,23 +5,47 @@ #include "LoRAWanComm.h" -LoRAWanComm::LoRAWanComm(const char* parameters): ev_queue() { } +LoRAWanComm::LoRAWanComm(const char* parameters) { } LoRAWanComm::~LoRAWanComm() { } int LoRAWanComm::initialize(LoraData* data) { D_LOG("INITIALIZE %s! \r\n", this->getName() ); + // INICIANDO O LORAWAN !! + this->data = data; + if(data->getCallBack() == NULL) { + D_LOG("Yoou must pass a call bak method to LoraData before of initialization process! \r\n"); + return FALSE; + } - // INICIANDO O LORAWAN !! lorawan = new LoRaWANInterface(*data->radio); // 1 - Initialize LoRaWAN stack - if (lorawan->initialize(&ev_queue) != LORAWAN_STATUS_OK) { - printf("LoRa initialization failed! \r\n"); - return -1; + if (lorawan->initialize(data->ev_queue) != LORAWAN_STATUS_OK) { + D_LOG("LoRa initialization failed! \r\n"); + return FALSE; } - return 1; + D_LOG("Mbed LoRaWANStack initialized \r\n"); + + // prepare application callbacks + lorawan->add_app_callbacks( data->getCallBack() ); + + // confirmed messages !! + if(data->confirmed_msg_retries > 0) + lorawan->set_confirmed_msg_retries(data->confirmed_msg_retries); + + // Enable adaptive data rate + if(data->enable_adaptive_datarate) { + if (lorawan->enable_adaptive_datarate() != LORAWAN_STATUS_OK) { + D_LOG("enable_adaptive_datarate failed! \r\n"); + return FALSE; + } + + D_LOG("Adaptive data rate (ADR) - Enabled \r\n"); + } + + return TRUE; } int LoRAWanComm::finalize() { @@ -36,23 +60,17 @@ return "LoRAWAN"; } -int LoRAWanComm::connect() { - return -1; +int LoRAWanComm::connect() { + if(data->connect_params == NULL) { + D_LOG("Please, initialize the 'connect_params' in the LoraData instance before the connection process. \r\n"); + return FALSE; + } + + return lorawan->connect(*data->connect_params); } int LoRAWanComm::disconnect() { - return -1; -} - -//////////////////////////////////////////////////////////////////////////////////// - -void LoRAWanComm::prepareCallBack( lorawan_app_callbacks_t &callbacks ) { - // prepare application callbacks - lorawan->add_app_callbacks(&callbacks); -} - -void LoRAWanComm::lora_event_handler(lorawan_event_t event) { - + return -1; // lorawan->dis } ////////////////////////////////////////////////////////////////////////////////////