Skip to content

Commit 2b2ce30

Browse files
author
Kimmo Vaisanen
committed
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.
1 parent b933cc6 commit 2b2ce30

File tree

4 files changed

+24
-40
lines changed

4 files changed

+24
-40
lines changed

features/lorawan/LoRaWANInterface.cpp

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,9 @@
2323

2424
using namespace events;
2525

26-
inline LoRaWANStack& stk_obj()
27-
{
28-
return LoRaWANStack::get_lorawan_stack();
29-
}
30-
3126
LoRaWANInterface::LoRaWANInterface(LoRaRadio& radio)
3227
{
33-
stk_obj().bind_radio_driver(radio);
28+
_lw_stack.bind_radio_driver(radio);
3429
}
3530

3631
LoRaWANInterface::~LoRaWANInterface()
@@ -39,95 +34,95 @@ LoRaWANInterface::~LoRaWANInterface()
3934

4035
lorawan_status_t LoRaWANInterface::initialize(EventQueue *queue)
4136
{
42-
return stk_obj().initialize_mac_layer(queue);
37+
return _lw_stack.initialize_mac_layer(queue);
4338
}
4439

4540
lorawan_status_t LoRaWANInterface::connect()
4641
{
47-
return stk_obj().connect();
42+
return _lw_stack.connect();
4843
}
4944

5045
lorawan_status_t LoRaWANInterface::connect(const lorawan_connect_t &connect)
5146
{
52-
return stk_obj().connect(connect);
47+
return _lw_stack.connect(connect);
5348
}
5449

5550
lorawan_status_t LoRaWANInterface::disconnect()
5651
{
57-
return stk_obj().shutdown();
52+
return _lw_stack.shutdown();
5853
}
5954

6055
lorawan_status_t LoRaWANInterface::add_link_check_request()
6156
{
62-
return stk_obj().set_link_check_request();
57+
return _lw_stack.set_link_check_request();
6358
}
6459

6560
void LoRaWANInterface::remove_link_check_request()
6661
{
67-
stk_obj().remove_link_check_request();
62+
_lw_stack.remove_link_check_request();
6863
}
6964

7065
lorawan_status_t LoRaWANInterface::set_datarate(uint8_t data_rate)
7166
{
72-
return stk_obj().set_channel_data_rate(data_rate);
67+
return _lw_stack.set_channel_data_rate(data_rate);
7368
}
7469

7570
lorawan_status_t LoRaWANInterface::set_confirmed_msg_retries(uint8_t count)
7671
{
77-
return stk_obj().set_confirmed_msg_retry(count);
72+
return _lw_stack.set_confirmed_msg_retry(count);
7873
}
7974

8075
lorawan_status_t LoRaWANInterface::enable_adaptive_datarate()
8176
{
82-
return stk_obj().enable_adaptive_datarate(true);
77+
return _lw_stack.enable_adaptive_datarate(true);
8378
}
8479

8580
lorawan_status_t LoRaWANInterface::disable_adaptive_datarate()
8681
{
87-
return stk_obj().enable_adaptive_datarate(false);
82+
return _lw_stack.enable_adaptive_datarate(false);
8883
}
8984

9085
lorawan_status_t LoRaWANInterface::set_channel_plan(const lorawan_channelplan_t &channel_plan)
9186
{
92-
return stk_obj().add_channels(channel_plan);
87+
return _lw_stack.add_channels(channel_plan);
9388
}
9489

9590
lorawan_status_t LoRaWANInterface::get_channel_plan(lorawan_channelplan_t &channel_plan)
9691
{
97-
return stk_obj().get_enabled_channels(channel_plan);
92+
return _lw_stack.get_enabled_channels(channel_plan);
9893
}
9994

10095
lorawan_status_t LoRaWANInterface::remove_channel(uint8_t id)
10196
{
102-
return stk_obj().remove_a_channel(id);
97+
return _lw_stack.remove_a_channel(id);
10398
}
10499

105100
lorawan_status_t LoRaWANInterface::remove_channel_plan()
106101
{
107-
return stk_obj().drop_channel_list();
102+
return _lw_stack.drop_channel_list();
108103
}
109104

110105
int16_t LoRaWANInterface::send(uint8_t port, const uint8_t* data, uint16_t length, int flags)
111106
{
112-
return stk_obj().handle_tx(port, data, length, flags);
107+
return _lw_stack.handle_tx(port, data, length, flags);
113108
}
114109

115110
int16_t LoRaWANInterface::receive(uint8_t port, uint8_t* data, uint16_t length, int flags)
116111
{
117-
return stk_obj().handle_rx(data, length, port, flags, true);
112+
return _lw_stack.handle_rx(data, length, port, flags, true);
118113
}
119114

120115
int16_t LoRaWANInterface::receive(uint8_t* data, uint16_t length, uint8_t& port, int& flags)
121116
{
122-
return stk_obj().handle_rx(data, length, port, flags, false);
117+
return _lw_stack.handle_rx(data, length, port, flags, false);
123118
}
124119

125120
lorawan_status_t LoRaWANInterface::add_app_callbacks(lorawan_app_callbacks_t *callbacks)
126121
{
127-
return stk_obj().set_lora_callbacks(callbacks);
122+
return _lw_stack.set_lora_callbacks(callbacks);
128123
}
129124

130125
lorawan_status_t LoRaWANInterface::set_device_class(const device_class_t device_class)
131126
{
132-
return stk_obj().set_device_class(device_class);
127+
return _lw_stack.set_device_class(device_class);
133128
}

features/lorawan/LoRaWANInterface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,9 @@ class LoRaWANInterface: public LoRaWANBase {
434434
* or other negative error code if request failed.
435435
*/
436436
virtual lorawan_status_t set_device_class(const device_class_t device_class);
437+
438+
private:
439+
LoRaWANStack _lw_stack;
437440
};
438441

439442
#endif /* LORAWANINTERFACE_H_ */

features/lorawan/LoRaWANStack.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,9 @@ LoRaWANStack::LoRaWANStack()
103103
LoRaMacPrimitives.mlme_indication = callback(this, &LoRaWANStack::mlme_indication_handler);
104104
}
105105

106-
LoRaWANStack::~LoRaWANStack()
107-
{
108-
}
109-
110106
/*****************************************************************************
111107
* Public member functions *
112108
****************************************************************************/
113-
LoRaWANStack& LoRaWANStack::get_lorawan_stack()
114-
{
115-
static LoRaWANStack _lw_stack;
116-
return _lw_stack;
117-
}
118-
119109
void LoRaWANStack::bind_radio_driver(LoRaRadio& radio)
120110
{
121111
_loramac.bind_radio_driver(radio);

features/lorawan/LoRaWANStack.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class LoRaWANStack: private mbed::NonCopyable<LoRaWANStack> {
7070
} device_states_t;
7171

7272
public:
73-
static LoRaWANStack& get_lorawan_stack();
73+
LoRaWANStack();
7474

7575
/** Binds radio driver to PHY layer.
7676
*
@@ -396,9 +396,6 @@ class LoRaWANStack: private mbed::NonCopyable<LoRaWANStack> {
396396
lorawan_status_t set_device_class(const device_class_t& device_class);
397397

398398
private:
399-
LoRaWANStack();
400-
~LoRaWANStack();
401-
402399
/**
403400
* Checks if the user provided port is valid or not
404401
*/
@@ -465,7 +462,6 @@ class LoRaWANStack: private mbed::NonCopyable<LoRaWANStack> {
465462
void send_automatic_uplink_message(const uint8_t port);
466463

467464
private:
468-
469465
LoRaMac _loramac;
470466
loramac_primitives_t LoRaMacPrimitives;
471467

0 commit comments

Comments
 (0)