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
LoRaWanComm.cpp
00001 #include "sgam_mdw.h" 00002 #include "mbed.h" 00003 #include "mbed_events.h" 00004 #include "LoRaWANInterface.h" 00005 00006 #include "LoRaWanComm.h" 00007 00008 LoRaWanComm::LoRaWanComm(const char* parameters) { } 00009 LoRaWanComm::~LoRaWanComm() { } 00010 00011 int LoRaWanComm::initialize(LoraData* data) { 00012 D_LOG("INITIALIZE %s! \r\n", this->getName() ); 00013 00014 // INICIANDO O LORAWAN !! 00015 this->data = data; 00016 if(data->getCallBack() == NULL) { 00017 D_LOG("You must pass a call bak method to LoraData before the initialization process! \r\n"); 00018 return FALSE; 00019 } 00020 00021 lorawan = new LoRaWANInterface(*data->radio); 00022 00023 // 1 - Initialize LoRaWAN stack 00024 if (lorawan->initialize(data->ev_queue) != LORAWAN_STATUS_OK) { 00025 D_LOG("LoRa initialization failed! \r\n"); 00026 return FALSE; 00027 } 00028 00029 D_LOG("Mbed LoRaWANStack initialized \r\n"); 00030 00031 // prepare application callbacks 00032 lorawan->add_app_callbacks( data->getCallBack() ); 00033 00034 // confirmed messages !! 00035 if(data->confirmed_msg_retries > 0) 00036 lorawan->set_confirmed_msg_retries(data->confirmed_msg_retries); 00037 00038 // Enable adaptive data rate 00039 if(data->enable_adaptive_datarate) { 00040 if (lorawan->enable_adaptive_datarate() != LORAWAN_STATUS_OK) { 00041 D_LOG("enable_adaptive_datarate failed! \r\n"); 00042 return FALSE; 00043 } 00044 00045 D_LOG("Adaptive data rate (ADR) - Enabled \r\n"); 00046 } 00047 00048 return TRUE; 00049 } 00050 00051 int LoRaWanComm::finalize() { 00052 D_LOG("FINALIZE %s! \r\n", this->getName() ); 00053 00054 if(lorawan != NULL) delete lorawan; 00055 00056 return 1; 00057 } 00058 00059 const char* LoRaWanComm::getName() { 00060 return "LoRAWAN"; 00061 } 00062 00063 LoraData* LoRaWanComm::getData() { 00064 return data; 00065 } 00066 00067 int LoRaWanComm::connect() { 00068 if(data->connect_params == NULL) { 00069 D_LOG("Please, initialize the 'connect_params' in the LoraData instance before the connection process. \r\n"); 00070 return FALSE; 00071 } 00072 00073 return lorawan->connect(*data->connect_params); 00074 } 00075 00076 int LoRaWanComm::disconnect() { 00077 return -1; // lorawan->dis 00078 } 00079 00080 //////////////////////////////////////////////////////////////////////////////////// 00081 int LoRaWanComm::write(const unsigned char* buffer, int offset) { 00082 return lorawan->send(data->lora_port, buffer, offset, data->read_write_flags); 00083 } 00084 00085 int LoRaWanComm::read(unsigned char* buffer, int offset) { 00086 return lorawan->receive(data->lora_port, buffer, offset, data->read_write_flags); 00087 }
Generated on Fri Jul 15 2022 01:20:42 by
1.7.2