2017-11-27 13:34:56 +00:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
*
|
|
|
|
* @brief Implementation of LoRaWANBase
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2018-04-10 11:04:18 +00:00
|
|
|
#include "LoRaWANInterface.h"
|
2017-11-27 13:34:56 +00:00
|
|
|
|
2017-12-11 10:20:11 +00:00
|
|
|
using namespace events;
|
|
|
|
|
2018-03-12 11:30:00 +00:00
|
|
|
LoRaWANInterface::LoRaWANInterface(LoRaRadio& radio)
|
2017-11-27 13:34:56 +00:00
|
|
|
{
|
2018-04-20 07:03:18 +00:00
|
|
|
_lw_stack.bind_radio_driver(radio);
|
2017-11-27 13:34:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LoRaWANInterface::~LoRaWANInterface()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-01-12 14:39:31 +00:00
|
|
|
lorawan_status_t LoRaWANInterface::initialize(EventQueue *queue)
|
2017-11-27 13:34:56 +00:00
|
|
|
{
|
2018-05-03 15:40:50 +00:00
|
|
|
Lock lock(*this);
|
2018-04-20 07:03:18 +00:00
|
|
|
return _lw_stack.initialize_mac_layer(queue);
|
2017-11-27 13:34:56 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 14:39:31 +00:00
|
|
|
lorawan_status_t LoRaWANInterface::connect()
|
2017-11-27 13:34:56 +00:00
|
|
|
{
|
2018-05-03 15:40:50 +00:00
|
|
|
Lock lock(*this);
|
2018-04-20 07:03:18 +00:00
|
|
|
return _lw_stack.connect();
|
2017-11-27 13:34:56 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 14:39:31 +00:00
|
|
|
lorawan_status_t LoRaWANInterface::connect(const lorawan_connect_t &connect)
|
2017-11-27 13:34:56 +00:00
|
|
|
{
|
2018-05-03 15:40:50 +00:00
|
|
|
Lock lock(*this);
|
2018-04-20 07:03:18 +00:00
|
|
|
return _lw_stack.connect(connect);
|
2017-11-27 13:34:56 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 14:39:31 +00:00
|
|
|
lorawan_status_t LoRaWANInterface::disconnect()
|
2017-11-27 13:34:56 +00:00
|
|
|
{
|
2018-05-03 15:40:50 +00:00
|
|
|
Lock lock(*this);
|
2018-04-20 07:03:18 +00:00
|
|
|
return _lw_stack.shutdown();
|
2017-11-27 13:34:56 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 14:39:31 +00:00
|
|
|
lorawan_status_t LoRaWANInterface::add_link_check_request()
|
2017-12-15 10:30:40 +00:00
|
|
|
{
|
2018-05-03 15:40:50 +00:00
|
|
|
Lock lock(*this);
|
2018-04-20 07:03:18 +00:00
|
|
|
return _lw_stack.set_link_check_request();
|
2017-12-15 10:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LoRaWANInterface::remove_link_check_request()
|
|
|
|
{
|
2018-05-03 15:40:50 +00:00
|
|
|
Lock lock(*this);
|
2018-04-20 07:03:18 +00:00
|
|
|
_lw_stack.remove_link_check_request();
|
2017-12-15 10:30:40 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 14:39:31 +00:00
|
|
|
lorawan_status_t LoRaWANInterface::set_datarate(uint8_t data_rate)
|
2017-11-27 13:34:56 +00:00
|
|
|
{
|
2018-05-03 15:40:50 +00:00
|
|
|
Lock lock(*this);
|
2018-04-20 07:03:18 +00:00
|
|
|
return _lw_stack.set_channel_data_rate(data_rate);
|
2017-11-27 13:34:56 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 14:39:31 +00:00
|
|
|
lorawan_status_t LoRaWANInterface::set_confirmed_msg_retries(uint8_t count)
|
2017-11-27 13:34:56 +00:00
|
|
|
{
|
2018-05-03 15:40:50 +00:00
|
|
|
Lock lock(*this);
|
2018-04-20 07:03:18 +00:00
|
|
|
return _lw_stack.set_confirmed_msg_retry(count);
|
2017-11-27 13:34:56 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 14:39:31 +00:00
|
|
|
lorawan_status_t LoRaWANInterface::enable_adaptive_datarate()
|
2017-11-27 13:34:56 +00:00
|
|
|
{
|
2018-05-03 15:40:50 +00:00
|
|
|
Lock lock(*this);
|
2018-04-20 07:03:18 +00:00
|
|
|
return _lw_stack.enable_adaptive_datarate(true);
|
2017-11-27 13:34:56 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 14:39:31 +00:00
|
|
|
lorawan_status_t LoRaWANInterface::disable_adaptive_datarate()
|
2017-11-27 13:34:56 +00:00
|
|
|
{
|
2018-05-03 15:40:50 +00:00
|
|
|
Lock lock(*this);
|
2018-04-20 07:03:18 +00:00
|
|
|
return _lw_stack.enable_adaptive_datarate(false);
|
2017-11-27 13:34:56 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 14:39:31 +00:00
|
|
|
lorawan_status_t LoRaWANInterface::set_channel_plan(const lorawan_channelplan_t &channel_plan)
|
2017-11-27 13:34:56 +00:00
|
|
|
{
|
2018-05-03 15:40:50 +00:00
|
|
|
Lock lock(*this);
|
2018-04-20 07:03:18 +00:00
|
|
|
return _lw_stack.add_channels(channel_plan);
|
2017-11-27 13:34:56 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 14:39:31 +00:00
|
|
|
lorawan_status_t LoRaWANInterface::get_channel_plan(lorawan_channelplan_t &channel_plan)
|
2017-11-27 13:34:56 +00:00
|
|
|
{
|
2018-05-03 15:40:50 +00:00
|
|
|
Lock lock(*this);
|
2018-04-20 07:03:18 +00:00
|
|
|
return _lw_stack.get_enabled_channels(channel_plan);
|
2017-11-27 13:34:56 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 14:39:31 +00:00
|
|
|
lorawan_status_t LoRaWANInterface::remove_channel(uint8_t id)
|
2017-11-27 13:34:56 +00:00
|
|
|
{
|
2018-05-03 15:40:50 +00:00
|
|
|
Lock lock(*this);
|
2018-04-20 07:03:18 +00:00
|
|
|
return _lw_stack.remove_a_channel(id);
|
2017-11-27 13:34:56 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 14:39:31 +00:00
|
|
|
lorawan_status_t LoRaWANInterface::remove_channel_plan()
|
2017-11-27 13:34:56 +00:00
|
|
|
{
|
2018-05-03 15:40:50 +00:00
|
|
|
Lock lock(*this);
|
2018-04-20 07:03:18 +00:00
|
|
|
return _lw_stack.drop_channel_list();
|
2017-11-27 13:34:56 +00:00
|
|
|
}
|
|
|
|
|
2018-04-10 10:04:23 +00:00
|
|
|
int16_t LoRaWANInterface::send(uint8_t port, const uint8_t* data, uint16_t length, int flags)
|
2017-11-27 13:34:56 +00:00
|
|
|
{
|
2018-05-03 15:40:50 +00:00
|
|
|
Lock lock(*this);
|
2018-04-20 07:03:18 +00:00
|
|
|
return _lw_stack.handle_tx(port, data, length, flags);
|
2018-04-10 10:04:23 +00:00
|
|
|
}
|
2017-12-15 10:30:40 +00:00
|
|
|
|
2018-05-15 11:59:55 +00:00
|
|
|
lorawan_status_t LoRaWANInterface::get_tx_metadata(lorawan_tx_metadata& metadata)
|
|
|
|
{
|
|
|
|
Lock lock(*this);
|
|
|
|
return _lw_stack.acquire_tx_metadata(metadata);
|
|
|
|
}
|
|
|
|
|
2018-04-10 10:04:23 +00:00
|
|
|
int16_t LoRaWANInterface::receive(uint8_t port, uint8_t* data, uint16_t length, int flags)
|
|
|
|
{
|
2018-05-03 15:40:50 +00:00
|
|
|
Lock lock(*this);
|
2018-04-20 07:03:18 +00:00
|
|
|
return _lw_stack.handle_rx(data, length, port, flags, true);
|
2017-11-27 13:34:56 +00:00
|
|
|
}
|
|
|
|
|
2018-04-10 10:04:23 +00:00
|
|
|
int16_t LoRaWANInterface::receive(uint8_t* data, uint16_t length, uint8_t& port, int& flags)
|
2017-11-27 13:34:56 +00:00
|
|
|
{
|
2018-05-03 15:40:50 +00:00
|
|
|
Lock lock(*this);
|
2018-04-20 07:03:18 +00:00
|
|
|
return _lw_stack.handle_rx(data, length, port, flags, false);
|
2017-11-27 13:34:56 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 14:39:31 +00:00
|
|
|
lorawan_status_t LoRaWANInterface::add_app_callbacks(lorawan_app_callbacks_t *callbacks)
|
2018-02-20 13:48:08 +00:00
|
|
|
{
|
2018-05-03 15:40:50 +00:00
|
|
|
Lock lock(*this);
|
2018-04-20 07:03:18 +00:00
|
|
|
return _lw_stack.set_lora_callbacks(callbacks);
|
2018-02-20 13:48:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lorawan_status_t LoRaWANInterface::set_device_class(const device_class_t device_class)
|
|
|
|
{
|
2018-05-03 15:40:50 +00:00
|
|
|
Lock lock(*this);
|
2018-04-20 07:03:18 +00:00
|
|
|
return _lw_stack.set_device_class(device_class);
|
2018-02-20 13:48:08 +00:00
|
|
|
}
|