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.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
LoRaWANInterface.cpp
00001 /** 00002 * @file 00003 * 00004 * @brief A LoRaWAN network interface 00005 * 00006 * Copyright (c) 2017, Arm Limited and affiliates. 00007 * SPDX-License-Identifier: Apache-2.0 00008 * 00009 * Licensed under the Apache License, Version 2.0 (the "License"); 00010 * you may not use this file except in compliance with the License. 00011 * You may obtain a copy of the License at 00012 * 00013 * http://www.apache.org/licenses/LICENSE-2.0 00014 * 00015 * Unless required by applicable law or agreed to in writing, software 00016 * distributed under the License is distributed on an "AS IS" BASIS, 00017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00018 * See the License for the specific language governing permissions and 00019 * limitations under the License. 00020 */ 00021 00022 #include "LoRaWANInterface.h" 00023 #include "lorastack/phy/loraphy_target.h" 00024 #include "mbed-trace/mbed_trace.h" 00025 #define TRACE_GROUP "LSTK" 00026 00027 using namespace mbed; 00028 using namespace events; 00029 00030 LoRaWANInterface::LoRaWANInterface(LoRaRadio &radio) 00031 : _default_phy(NULL) 00032 { 00033 _default_phy = new LoRaPHY_region; 00034 MBED_ASSERT(_default_phy); 00035 _lw_stack.bind_phy_and_radio_driver(radio, *_default_phy); 00036 } 00037 00038 LoRaWANInterface::LoRaWANInterface(LoRaRadio &radio, LoRaPHY &phy) 00039 : _default_phy(NULL) 00040 { 00041 _lw_stack.bind_phy_and_radio_driver(radio, phy); 00042 } 00043 00044 LoRaWANInterface::~LoRaWANInterface() 00045 { 00046 delete _default_phy; 00047 _default_phy = NULL; 00048 } 00049 00050 lorawan_status_t LoRaWANInterface::initialize(EventQueue *queue) 00051 { 00052 Lock lock(*this); 00053 return _lw_stack.initialize_mac_layer(queue); 00054 } 00055 00056 lorawan_status_t LoRaWANInterface::connect() 00057 { 00058 Lock lock(*this); 00059 return _lw_stack.connect(); 00060 } 00061 00062 lorawan_status_t LoRaWANInterface::connect(const lorawan_connect_t &connect) 00063 { 00064 Lock lock(*this); 00065 return _lw_stack.connect(connect); 00066 } 00067 00068 lorawan_status_t LoRaWANInterface::disconnect() 00069 { 00070 Lock lock(*this); 00071 return _lw_stack.shutdown(); 00072 } 00073 00074 lorawan_status_t LoRaWANInterface::add_link_check_request() 00075 { 00076 Lock lock(*this); 00077 return _lw_stack.set_link_check_request(); 00078 } 00079 00080 void LoRaWANInterface::remove_link_check_request() 00081 { 00082 Lock lock(*this); 00083 _lw_stack.remove_link_check_request(); 00084 } 00085 00086 lorawan_status_t LoRaWANInterface::set_datarate(uint8_t data_rate) 00087 { 00088 Lock lock(*this); 00089 return _lw_stack.set_channel_data_rate(data_rate); 00090 } 00091 00092 lorawan_status_t LoRaWANInterface::set_confirmed_msg_retries(uint8_t count) 00093 { 00094 Lock lock(*this); 00095 return _lw_stack.set_confirmed_msg_retry(count); 00096 } 00097 00098 lorawan_status_t LoRaWANInterface::enable_adaptive_datarate() 00099 { 00100 Lock lock(*this); 00101 return _lw_stack.enable_adaptive_datarate(true); 00102 } 00103 00104 lorawan_status_t LoRaWANInterface::disable_adaptive_datarate() 00105 { 00106 Lock lock(*this); 00107 return _lw_stack.enable_adaptive_datarate(false); 00108 } 00109 00110 lorawan_status_t LoRaWANInterface::set_channel_plan(const lorawan_channelplan_t &channel_plan) 00111 { 00112 Lock lock(*this); 00113 return _lw_stack.add_channels(channel_plan); 00114 } 00115 00116 lorawan_status_t LoRaWANInterface::get_channel_plan(lorawan_channelplan_t &channel_plan) 00117 { 00118 Lock lock(*this); 00119 return _lw_stack.get_enabled_channels(channel_plan); 00120 } 00121 00122 lorawan_status_t LoRaWANInterface::remove_channel(uint8_t id) 00123 { 00124 Lock lock(*this); 00125 return _lw_stack.remove_a_channel(id); 00126 } 00127 00128 lorawan_status_t LoRaWANInterface::remove_channel_plan() 00129 { 00130 Lock lock(*this); 00131 return _lw_stack.drop_channel_list(); 00132 } 00133 00134 int16_t LoRaWANInterface::send(uint8_t port, const uint8_t *data, uint16_t length, int flags) 00135 { 00136 Lock lock(*this); 00137 return _lw_stack.handle_tx(port, data, length, flags); 00138 } 00139 00140 lorawan_status_t LoRaWANInterface::cancel_sending(void) 00141 { 00142 Lock lock(*this); 00143 return _lw_stack.stop_sending(); 00144 } 00145 00146 lorawan_status_t LoRaWANInterface::get_tx_metadata(lorawan_tx_metadata &metadata) 00147 { 00148 Lock lock(*this); 00149 return _lw_stack.acquire_tx_metadata(metadata); 00150 } 00151 00152 lorawan_status_t LoRaWANInterface::get_rx_metadata(lorawan_rx_metadata &metadata) 00153 { 00154 Lock lock(*this); 00155 return _lw_stack.acquire_rx_metadata(metadata); 00156 } 00157 00158 lorawan_status_t LoRaWANInterface::get_backoff_metadata(int &backoff) 00159 { 00160 Lock lock(*this); 00161 return _lw_stack.acquire_backoff_metadata(backoff); 00162 } 00163 00164 int16_t LoRaWANInterface::receive(uint8_t port, uint8_t *data, uint16_t length, int flags) 00165 { 00166 Lock lock(*this); 00167 return _lw_stack.handle_rx(data, length, port, flags, true); 00168 } 00169 00170 int16_t LoRaWANInterface::receive(uint8_t *data, uint16_t length, uint8_t &port, int &flags) 00171 { 00172 Lock lock(*this); 00173 return _lw_stack.handle_rx(data, length, port, flags, false); 00174 } 00175 00176 lorawan_status_t LoRaWANInterface::add_app_callbacks(lorawan_app_callbacks_t *callbacks) 00177 { 00178 Lock lock(*this); 00179 return _lw_stack.set_lora_callbacks(callbacks); 00180 } 00181 00182 lorawan_status_t LoRaWANInterface::set_device_class(const device_class_t device_class) 00183 { 00184 Lock lock(*this); 00185 return _lw_stack.set_device_class(device_class); 00186 }
Generated on Tue Jul 12 2022 13:54:27 by
