mirror of https://github.com/ARMmbed/mbed-os.git
Lora: Remove singleton construction of LoRaWANStack
After changing LoRaMacCrypto as C++ class, we no longer have static variables in LoRa implementation. Therefore singleton pattern can be removed.pull/6692/head
parent
b933cc6aeb
commit
2b2ce300ea
|
@ -23,14 +23,9 @@
|
|||
|
||||
using namespace events;
|
||||
|
||||
inline LoRaWANStack& stk_obj()
|
||||
{
|
||||
return LoRaWANStack::get_lorawan_stack();
|
||||
}
|
||||
|
||||
LoRaWANInterface::LoRaWANInterface(LoRaRadio& radio)
|
||||
{
|
||||
stk_obj().bind_radio_driver(radio);
|
||||
_lw_stack.bind_radio_driver(radio);
|
||||
}
|
||||
|
||||
LoRaWANInterface::~LoRaWANInterface()
|
||||
|
@ -39,95 +34,95 @@ LoRaWANInterface::~LoRaWANInterface()
|
|||
|
||||
lorawan_status_t LoRaWANInterface::initialize(EventQueue *queue)
|
||||
{
|
||||
return stk_obj().initialize_mac_layer(queue);
|
||||
return _lw_stack.initialize_mac_layer(queue);
|
||||
}
|
||||
|
||||
lorawan_status_t LoRaWANInterface::connect()
|
||||
{
|
||||
return stk_obj().connect();
|
||||
return _lw_stack.connect();
|
||||
}
|
||||
|
||||
lorawan_status_t LoRaWANInterface::connect(const lorawan_connect_t &connect)
|
||||
{
|
||||
return stk_obj().connect(connect);
|
||||
return _lw_stack.connect(connect);
|
||||
}
|
||||
|
||||
lorawan_status_t LoRaWANInterface::disconnect()
|
||||
{
|
||||
return stk_obj().shutdown();
|
||||
return _lw_stack.shutdown();
|
||||
}
|
||||
|
||||
lorawan_status_t LoRaWANInterface::add_link_check_request()
|
||||
{
|
||||
return stk_obj().set_link_check_request();
|
||||
return _lw_stack.set_link_check_request();
|
||||
}
|
||||
|
||||
void LoRaWANInterface::remove_link_check_request()
|
||||
{
|
||||
stk_obj().remove_link_check_request();
|
||||
_lw_stack.remove_link_check_request();
|
||||
}
|
||||
|
||||
lorawan_status_t LoRaWANInterface::set_datarate(uint8_t data_rate)
|
||||
{
|
||||
return stk_obj().set_channel_data_rate(data_rate);
|
||||
return _lw_stack.set_channel_data_rate(data_rate);
|
||||
}
|
||||
|
||||
lorawan_status_t LoRaWANInterface::set_confirmed_msg_retries(uint8_t count)
|
||||
{
|
||||
return stk_obj().set_confirmed_msg_retry(count);
|
||||
return _lw_stack.set_confirmed_msg_retry(count);
|
||||
}
|
||||
|
||||
lorawan_status_t LoRaWANInterface::enable_adaptive_datarate()
|
||||
{
|
||||
return stk_obj().enable_adaptive_datarate(true);
|
||||
return _lw_stack.enable_adaptive_datarate(true);
|
||||
}
|
||||
|
||||
lorawan_status_t LoRaWANInterface::disable_adaptive_datarate()
|
||||
{
|
||||
return stk_obj().enable_adaptive_datarate(false);
|
||||
return _lw_stack.enable_adaptive_datarate(false);
|
||||
}
|
||||
|
||||
lorawan_status_t LoRaWANInterface::set_channel_plan(const lorawan_channelplan_t &channel_plan)
|
||||
{
|
||||
return stk_obj().add_channels(channel_plan);
|
||||
return _lw_stack.add_channels(channel_plan);
|
||||
}
|
||||
|
||||
lorawan_status_t LoRaWANInterface::get_channel_plan(lorawan_channelplan_t &channel_plan)
|
||||
{
|
||||
return stk_obj().get_enabled_channels(channel_plan);
|
||||
return _lw_stack.get_enabled_channels(channel_plan);
|
||||
}
|
||||
|
||||
lorawan_status_t LoRaWANInterface::remove_channel(uint8_t id)
|
||||
{
|
||||
return stk_obj().remove_a_channel(id);
|
||||
return _lw_stack.remove_a_channel(id);
|
||||
}
|
||||
|
||||
lorawan_status_t LoRaWANInterface::remove_channel_plan()
|
||||
{
|
||||
return stk_obj().drop_channel_list();
|
||||
return _lw_stack.drop_channel_list();
|
||||
}
|
||||
|
||||
int16_t LoRaWANInterface::send(uint8_t port, const uint8_t* data, uint16_t length, int flags)
|
||||
{
|
||||
return stk_obj().handle_tx(port, data, length, flags);
|
||||
return _lw_stack.handle_tx(port, data, length, flags);
|
||||
}
|
||||
|
||||
int16_t LoRaWANInterface::receive(uint8_t port, uint8_t* data, uint16_t length, int flags)
|
||||
{
|
||||
return stk_obj().handle_rx(data, length, port, flags, true);
|
||||
return _lw_stack.handle_rx(data, length, port, flags, true);
|
||||
}
|
||||
|
||||
int16_t LoRaWANInterface::receive(uint8_t* data, uint16_t length, uint8_t& port, int& flags)
|
||||
{
|
||||
return stk_obj().handle_rx(data, length, port, flags, false);
|
||||
return _lw_stack.handle_rx(data, length, port, flags, false);
|
||||
}
|
||||
|
||||
lorawan_status_t LoRaWANInterface::add_app_callbacks(lorawan_app_callbacks_t *callbacks)
|
||||
{
|
||||
return stk_obj().set_lora_callbacks(callbacks);
|
||||
return _lw_stack.set_lora_callbacks(callbacks);
|
||||
}
|
||||
|
||||
lorawan_status_t LoRaWANInterface::set_device_class(const device_class_t device_class)
|
||||
{
|
||||
return stk_obj().set_device_class(device_class);
|
||||
return _lw_stack.set_device_class(device_class);
|
||||
}
|
||||
|
|
|
@ -434,6 +434,9 @@ public:
|
|||
* or other negative error code if request failed.
|
||||
*/
|
||||
virtual lorawan_status_t set_device_class(const device_class_t device_class);
|
||||
|
||||
private:
|
||||
LoRaWANStack _lw_stack;
|
||||
};
|
||||
|
||||
#endif /* LORAWANINTERFACE_H_ */
|
||||
|
|
|
@ -103,19 +103,9 @@ LoRaWANStack::LoRaWANStack()
|
|||
LoRaMacPrimitives.mlme_indication = callback(this, &LoRaWANStack::mlme_indication_handler);
|
||||
}
|
||||
|
||||
LoRaWANStack::~LoRaWANStack()
|
||||
{
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* Public member functions *
|
||||
****************************************************************************/
|
||||
LoRaWANStack& LoRaWANStack::get_lorawan_stack()
|
||||
{
|
||||
static LoRaWANStack _lw_stack;
|
||||
return _lw_stack;
|
||||
}
|
||||
|
||||
void LoRaWANStack::bind_radio_driver(LoRaRadio& radio)
|
||||
{
|
||||
_loramac.bind_radio_driver(radio);
|
||||
|
|
|
@ -70,7 +70,7 @@ private:
|
|||
} device_states_t;
|
||||
|
||||
public:
|
||||
static LoRaWANStack& get_lorawan_stack();
|
||||
LoRaWANStack();
|
||||
|
||||
/** Binds radio driver to PHY layer.
|
||||
*
|
||||
|
@ -396,9 +396,6 @@ public:
|
|||
lorawan_status_t set_device_class(const device_class_t& device_class);
|
||||
|
||||
private:
|
||||
LoRaWANStack();
|
||||
~LoRaWANStack();
|
||||
|
||||
/**
|
||||
* Checks if the user provided port is valid or not
|
||||
*/
|
||||
|
@ -465,7 +462,6 @@ private:
|
|||
void send_automatic_uplink_message(const uint8_t port);
|
||||
|
||||
private:
|
||||
|
||||
LoRaMac _loramac;
|
||||
loramac_primitives_t LoRaMacPrimitives;
|
||||
|
||||
|
|
Loading…
Reference in New Issue