Skip to content

Commit e18d76a

Browse files
Kimmo VaisanenHasnain Virk
authored andcommitted
Change LoRaWANTimer to a C++ class
LoRaWANTimer is now called as LoRaWANTimeHandler class as this class handles both current time and timer functionalities. Some refactoring on how LoRa objects are created was needed: - LoRaWANTimeHandler object is created by LoRaWANStack and shares with LoRaMac and PHY. - LoRaPHY object is now member of LoRaWANStack class instead of static variable in source file.
1 parent b634ca4 commit e18d76a

28 files changed

+246
-217
lines changed

features/lorawan/LoRaWANStack.cpp

Lines changed: 17 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -41,42 +41,6 @@ SPDX-License-Identifier: BSD-3-Clause
4141
#define INVALID_PORT 0xFF
4242
#define MAX_CONFIRMED_MSG_RETRIES 255
4343

44-
#ifdef MBED_CONF_LORA_PHY
45-
#if MBED_CONF_LORA_PHY == 0
46-
#include "lorawan/lorastack/phy/LoRaPHYEU868.h"
47-
static SingletonPtr<LoRaPHYEU868> lora_phy;
48-
#elif MBED_CONF_LORA_PHY == 1
49-
#include "lorawan/lorastack/phy/LoRaPHYAS923.h"
50-
static SingletonPtr<LoRaPHYAS923> lora_phy;
51-
#elif MBED_CONF_LORA_PHY == 2
52-
#include "lorawan/lorastack/phy/LoRaPHYAU915.h"
53-
static SingletonPtr<LoRaPHYAU915> lora_phy;
54-
#elif MBED_CONF_LORA_PHY == 3
55-
#include "lorawan/lorastack/phy/LoRaPHYCN470.h"
56-
static SingletonPtr<LoRaPHYCN470> lora_phy;
57-
#elif MBED_CONF_LORA_PHY == 4
58-
#include "lorawan/lorastack/phy/LoRaPHYCN779.h"
59-
static SingletonPtr<LoRaPHYCN779> lora_phy;
60-
#elif MBED_CONF_LORA_PHY == 5
61-
#include "lorawan/lorastack/phy/LoRaPHYEU433.h"
62-
static SingletonPtr<LoRaPHYEU433> lora_phy;
63-
#elif MBED_CONF_LORA_PHY == 6
64-
#include "lorawan/lorastack/phy/LoRaPHYIN865.h"
65-
static SingletonPtr<LoRaPHYIN865> lora_phy;
66-
#elif MBED_CONF_LORA_PHY == 7
67-
#include "lorawan/lorastack/phy/LoRaPHYKR920.h"
68-
static SingletonPtr<LoRaPHYKR920> lora_phy;
69-
#elif MBED_CONF_LORA_PHY == 8
70-
#include "lorawan/lorastack/phy/LoRaPHYUS915.h"
71-
static SingletonPtr<LoRaPHYUS915> lora_phy;
72-
#elif MBED_CONF_LORA_PHY == 9
73-
#include "lorawan/lorastack/phy/LoRaPHYUS915Hybrid.h"
74-
static SingletonPtr<LoRaPHYUS915Hybrid> lora_phy;
75-
#endif //MBED_CONF_LORA_PHY == VALUE
76-
#else
77-
#error "Must set LoRa PHY layer parameters."
78-
#endif //MBED_CONF_LORA_PHY
79-
8044
using namespace mbed;
8145
using namespace events;
8246

@@ -128,8 +92,9 @@ lora_mac_status_t LoRaWANStack::set_application_port(uint8_t port)
12892
* Constructor and destructor *
12993
****************************************************************************/
13094
LoRaWANStack::LoRaWANStack()
131-
: _device_current_state(DEVICE_STATE_NOT_INITIALIZED), _mac_handlers(NULL),
132-
_num_retry(1), _queue(NULL), _duty_cycle_on(LORAWAN_DUTYCYCLE_ON)
95+
: _loramac(_lora_time), _lora_phy(_lora_time),
96+
_device_current_state(DEVICE_STATE_NOT_INITIALIZED), _mac_handlers(NULL),
97+
_num_retry(1), _queue(NULL), _duty_cycle_on(LORAWAN_DUTYCYCLE_ON)
13398
{
13499
#ifdef MBED_CONF_LORA_APP_PORT
135100
// is_port_valid() is not virtual, so we can call it in constructor
@@ -170,7 +135,7 @@ radio_events_t *LoRaWANStack::bind_radio_driver(LoRaRadio& radio)
170135
// Store pointer to callback routines inside MAC layer (non-IRQ safe)
171136
_mac_handlers = _loramac.GetPhyEventHandlers();
172137
// passes the reference to radio driver down to PHY layer
173-
lora_phy.get()->set_radio_instance(radio);
138+
_lora_phy.set_radio_instance(radio);
174139
return _mac_handlers;
175140
}
176141

@@ -200,12 +165,13 @@ lora_mac_status_t LoRaWANStack::initialize_mac_layer(EventQueue *queue)
200165
_compliance_test.app_data_buffer = compliance_test_buffer;
201166
#endif
202167

203-
TimerTimeCounterInit(queue);
168+
_lora_time.TimerTimeCounterInit(queue);
169+
204170
LoRaMacPrimitives.MacMcpsConfirm = callback(this, &LoRaWANStack::mcps_confirm);
205171
LoRaMacPrimitives.MacMcpsIndication = callback(this, &LoRaWANStack::mcps_indication);
206172
LoRaMacPrimitives.MacMlmeConfirm = callback(this, &LoRaWANStack::mlme_confirm);
207173
LoRaMacPrimitives.MacMlmeIndication = callback(this, &LoRaWANStack::mlme_indication);
208-
_loramac.LoRaMacInitialization(&LoRaMacPrimitives, &LoRaMacCallbacks, lora_phy.get(), queue);
174+
_loramac.LoRaMacInitialization(&LoRaMacPrimitives, &LoRaMacCallbacks, &_lora_phy, queue);
209175

210176
mib_req.type = LORA_MIB_ADR;
211177
mib_req.param.adr_enable = LORAWAN_ADR_ON;
@@ -276,7 +242,7 @@ lora_mac_status_t LoRaWANStack::send_compliance_test_frame_to_mac()
276242
GetPhyParams_t phy_params;
277243
PhyParam_t default_datarate;
278244
phy_params.Attribute = PHY_DEF_TX_DR;
279-
default_datarate = lora_phy.get_phy_params(&phy_params);
245+
default_datarate = _lora_phy.get_phy_params(&phy_params);
280246

281247
prepare_special_tx_frame(_compliance_test.app_port);
282248

@@ -338,7 +304,7 @@ lora_mac_status_t LoRaWANStack::send_frame_to_mac()
338304
GetPhyParams_t phy_params;
339305
PhyParam_t default_datarate;
340306
phy_params.Attribute = PHY_DEF_TX_DR;
341-
default_datarate = lora_phy.get()->get_phy_params(&phy_params);
307+
default_datarate = _lora_phy.get_phy_params(&phy_params);
342308

343309
mcps_req.type = _tx_msg.type;
344310

@@ -514,7 +480,7 @@ lora_mac_status_t LoRaWANStack::add_channels(const lora_channelplan_t &channel_p
514480

515481
// Check first how many channels the selected PHY layer supports
516482
get_phy.Attribute = PHY_MAX_NB_CHANNELS;
517-
phy_param = lora_phy.get()->get_phy_params(&get_phy);
483+
phy_param = _lora_phy.get_phy_params(&get_phy);
518484
max_num_channels = (uint8_t) phy_param.Value;
519485

520486
// check if user is setting more channels than supported
@@ -558,17 +524,17 @@ lora_mac_status_t LoRaWANStack::drop_channel_list()
558524

559525
// Check first how many channels the selected PHY layer supports
560526
get_phy.Attribute = PHY_MAX_NB_CHANNELS;
561-
phy_param = lora_phy.get()->get_phy_params(&get_phy);
527+
phy_param = _lora_phy.get_phy_params(&get_phy);
562528
max_num_channels = (uint8_t) phy_param.Value;
563529

564530
// Now check the channel mask for enabled channels
565531
get_phy.Attribute = PHY_CHANNELS_MASK;
566-
phy_param = lora_phy.get()->get_phy_params(&get_phy);
532+
phy_param = _lora_phy.get_phy_params(&get_phy);
567533
channel_masks = phy_param.ChannelsMask;
568534

569535
// Now check the channel mask for default channels
570536
get_phy.Attribute = PHY_CHANNELS_DEFAULT_MASK;
571-
phy_param = lora_phy.get()->get_phy_params(&get_phy);
537+
phy_param = _lora_phy.get_phy_params(&get_phy);
572538
default_channel_masks = phy_param.ChannelsMask;
573539

574540
for (uint8_t i = 0; i < max_num_channels; i++) {
@@ -607,7 +573,7 @@ lora_mac_status_t LoRaWANStack::remove_a_channel(uint8_t channel_id)
607573

608574
// Check first how many channels the selected PHY layer supports
609575
get_phy.Attribute = PHY_MAX_NB_CHANNELS;
610-
phy_param = lora_phy.get()->get_phy_params(&get_phy);
576+
phy_param = _lora_phy.get_phy_params(&get_phy);
611577
max_num_channels = (uint8_t) phy_param.Value;
612578

613579
// According to specification channel IDs start from 0 and last valid
@@ -619,7 +585,7 @@ lora_mac_status_t LoRaWANStack::remove_a_channel(uint8_t channel_id)
619585

620586
// Now check the Default channel mask
621587
get_phy.Attribute = PHY_CHANNELS_DEFAULT_MASK;
622-
phy_param = lora_phy.get()->get_phy_params(&get_phy);
588+
phy_param = _lora_phy.get_phy_params(&get_phy);
623589
channel_masks = phy_param.ChannelsMask;
624590

625591
// check if the channel ID give belongs to a default channel
@@ -654,12 +620,12 @@ lora_mac_status_t LoRaWANStack::get_enabled_channels(lora_channelplan_t& channel
654620

655621
// Check first how many channels the selected PHY layer supports
656622
get_phy.Attribute = PHY_MAX_NB_CHANNELS;
657-
phy_param = lora_phy.get()->get_phy_params(&get_phy);
623+
phy_param = _lora_phy.get_phy_params(&get_phy);
658624
max_num_channels = (uint8_t) phy_param.Value;
659625

660626
// Now check the Default channel mask
661627
get_phy.Attribute = PHY_CHANNELS_MASK;
662-
phy_param = lora_phy.get()->get_phy_params(&get_phy);
628+
phy_param = _lora_phy.get_phy_params(&get_phy);
663629
channel_masks = phy_param.ChannelsMask;
664630

665631
// Request Mib to get channels

features/lorawan/LoRaWANStack.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,42 @@ SPDX-License-Identifier: BSD-3-Clause
3535
#include "lorawan/system/lorawan_data_structures.h"
3636
#include "LoRaRadio.h"
3737

38+
#ifdef MBED_CONF_LORA_PHY
39+
#if MBED_CONF_LORA_PHY == 0
40+
#include "lorawan/lorastack/phy/LoRaPHYEU868.h"
41+
#define LoRaPHY_region LoRaPHYEU868
42+
#elif MBED_CONF_LORA_PHY == 1
43+
#include "lorawan/lorastack/phy/LoRaPHYAS923.h"
44+
#define LoRaPHY_region LoRaPHYAS923
45+
#elif MBED_CONF_LORA_PHY == 2
46+
#include "lorawan/lorastack/phy/LoRaPHYAU915.h"
47+
#define LoRaPHY_region LoRaPHYAU915;
48+
#elif MBED_CONF_LORA_PHY == 3
49+
#include "lorawan/lorastack/phy/LoRaPHYCN470.h"
50+
#define LoRaPHY_region LoRaPHYCN470
51+
#elif MBED_CONF_LORA_PHY == 4
52+
#include "lorawan/lorastack/phy/LoRaPHYCN779.h"
53+
#define LoRaPHY_region LoRaPHYCN779
54+
#elif MBED_CONF_LORA_PHY == 5
55+
#include "lorawan/lorastack/phy/LoRaPHYEU433.h"
56+
#define LoRaPHY_region LoRaPHYEU433
57+
#elif MBED_CONF_LORA_PHY == 6
58+
#include "lorawan/lorastack/phy/LoRaPHYIN865.h"
59+
#define LoRaPHY_region LoRaPHYIN865
60+
#elif MBED_CONF_LORA_PHY == 7
61+
#include "lorawan/lorastack/phy/LoRaPHYKR920.h"
62+
#define LoRaPHY_region LoRaPHYKR920
63+
#elif MBED_CONF_LORA_PHY == 8
64+
#include "lorawan/lorastack/phy/LoRaPHYUS915.h"
65+
#define LoRaPHY_region LoRaPHYUS915
66+
#elif MBED_CONF_LORA_PHY == 9
67+
#include "lorawan/lorastack/phy/LoRaPHYUS915Hybrid.h"
68+
#define LoRaPHY_region LoRaPHYUS915Hybrid
69+
#endif //MBED_CONF_LORA_PHY == VALUE
70+
#else
71+
#error "Must set LoRa PHY layer parameters."
72+
#endif //MBED_CONF_LORA_PHY
73+
3874
/**
3975
* A mask for the network ID.
4076
*/
@@ -429,7 +465,9 @@ class LoRaWANStack: private mbed::NonCopyable<LoRaWANStack> {
429465
*/
430466
lora_mac_status_t error_type_converter(LoRaMacStatus_t type);
431467

468+
LoRaWANTimeHandler _lora_time;
432469
LoRaMac _loramac;
470+
LoRaPHY_region _lora_phy;
433471

434472
#if defined(LORAWAN_COMPLIANCE_TEST)
435473
compliance_test_t _compliance_test;

0 commit comments

Comments
 (0)