Skip to content

Commit 50004ca

Browse files
author
Kimmo Vaisanen
committed
Lora: Add initialize() method to set LoRaWANTimeHandler class for phy
Instead of giving LoRaWANTimeHandler object as parameter for constructor, object is now given via own initialize() method. This change is needed for future refactoring where application can give own PHY object for LoRa stack.
1 parent 93233c4 commit 50004ca

23 files changed

+55
-52
lines changed

features/lorawan/lorastack/mac/LoRaMac.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ using namespace mbed;
7373

7474
LoRaMac::LoRaMac()
7575
: _lora_time(),
76-
_lora_phy(_lora_time),
76+
_lora_phy(),
7777
_mac_commands(),
7878
_channel_plan(),
7979
_lora_crypto(),
@@ -1687,6 +1687,7 @@ void LoRaMac::set_tx_continuous_wave(uint8_t channel, int8_t datarate, int8_t tx
16871687
lorawan_status_t LoRaMac::initialize(EventQueue *queue)
16881688
{
16891689
_lora_time.activate_timer_subsystem(queue);
1690+
_lora_phy.initialize(&_lora_time);
16901691

16911692
_ev_queue = queue;
16921693

features/lorawan/lorastack/phy/LoRaPHY.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ SPDX-License-Identifier: BSD-3-Clause
3535

3636
#define CHANNELS_IN_MASK 16
3737

38-
LoRaPHY::LoRaPHY(LoRaWANTimeHandler &lora_time)
39-
: _radio(NULL),
40-
_lora_time(lora_time)
38+
LoRaPHY::LoRaPHY()
39+
: _radio(NULL)
4140
{
4241
memset(&phy_params, 0, sizeof(phy_params));
4342
}
@@ -47,6 +46,11 @@ LoRaPHY::~LoRaPHY()
4746
_radio = NULL;
4847
}
4948

49+
void LoRaPHY::initialize(LoRaWANTimeHandler *lora_time)
50+
{
51+
_lora_time = lora_time;
52+
}
53+
5054
bool LoRaPHY::mask_bit_test(const uint16_t *mask, unsigned bit)
5155
{
5256
return mask[bit / 16] & (1U << (bit % 16));
@@ -268,9 +272,9 @@ lorawan_time_t LoRaPHY::update_band_timeoff(bool joined, bool duty_cycle,
268272
for (uint8_t i = 0; i < nb_bands; i++) {
269273

270274
if (joined == false) {
271-
uint32_t txDoneTime = MAX(_lora_time.get_elapsed_time(bands[i].last_join_tx_time),
275+
uint32_t txDoneTime = MAX(_lora_time->get_elapsed_time(bands[i].last_join_tx_time),
272276
(duty_cycle == true) ?
273-
_lora_time.get_elapsed_time(bands[i].last_tx_time) : 0);
277+
_lora_time->get_elapsed_time(bands[i].last_tx_time) : 0);
274278

275279
if (bands[i].off_time <= txDoneTime) {
276280
bands[i].off_time = 0;
@@ -284,12 +288,12 @@ lorawan_time_t LoRaPHY::update_band_timeoff(bool joined, bool duty_cycle,
284288
// if network has been joined
285289
if (duty_cycle == true) {
286290

287-
if (bands[i].off_time <= _lora_time.get_elapsed_time(bands[i].last_tx_time)) {
291+
if (bands[i].off_time <= _lora_time->get_elapsed_time(bands[i].last_tx_time)) {
288292
bands[i].off_time = 0;
289293
}
290294

291295
if (bands[i].off_time != 0) {
292-
next_tx_delay = MIN(bands[i].off_time - _lora_time.get_elapsed_time(bands[i].last_tx_time),
296+
next_tx_delay = MIN(bands[i].off_time - _lora_time->get_elapsed_time(bands[i].last_tx_time),
293297
next_tx_delay);
294298
}
295299
} else {
@@ -1222,7 +1226,7 @@ lorawan_status_t LoRaPHY::set_next_channel(channel_selection_params_t *params,
12221226
}
12231227

12241228
if (params->aggregate_timeoff
1225-
<= _lora_time.get_elapsed_time(params->last_aggregate_tx_time)) {
1229+
<= _lora_time->get_elapsed_time(params->last_aggregate_tx_time)) {
12261230
// Reset Aggregated time off
12271231
*aggregate_timeoff = 0;
12281232

@@ -1238,7 +1242,7 @@ lorawan_status_t LoRaPHY::set_next_channel(channel_selection_params_t *params,
12381242
} else {
12391243
delay_tx++;
12401244
next_tx_delay = params->aggregate_timeoff -
1241-
_lora_time.get_elapsed_time(params->last_aggregate_tx_time);
1245+
_lora_time->get_elapsed_time(params->last_aggregate_tx_time);
12421246
}
12431247

12441248
if (channel_count > 0) {

features/lorawan/lorastack/phy/LoRaPHY.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ class LoRaPHY : private mbed::NonCopyable<LoRaPHY> {
4545
public:
4646
virtual ~LoRaPHY();
4747

48+
/** Initialize LoRaPHY
49+
*
50+
* LoRaMac calls this to initialize LoRaPHY.
51+
*
52+
* @param lora_time a pointer to LoRaWANTimeHandler object
53+
*/
54+
void initialize(LoRaWANTimeHandler *lora_time);
55+
4856
/** Stores a reference to Radio object.
4957
*
5058
* Application is responsible for constructing a 'LoRaRadio' object
@@ -517,7 +525,7 @@ class LoRaPHY : private mbed::NonCopyable<LoRaPHY> {
517525
bool verify_nb_join_trials(uint8_t nb_join_trials);
518526

519527
protected:
520-
LoRaPHY(LoRaWANTimeHandler &lora_time);
528+
LoRaPHY();
521529

522530
/**
523531
* Looks up corresponding band for a frequency. Returns -1 if not in any band.
@@ -624,7 +632,7 @@ class LoRaPHY : private mbed::NonCopyable<LoRaPHY> {
624632

625633
protected:
626634
LoRaRadio *_radio;
627-
LoRaWANTimeHandler &_lora_time;
635+
LoRaWANTimeHandler *_lora_time;
628636
loraphy_params_t phy_params;
629637
};
630638

features/lorawan/lorastack/phy/LoRaPHYAS923.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,7 @@ static const uint32_t bandwidths_AS923[] = {125000, 125000, 125000, 125000, 1250
241241
*/
242242
static const int8_t rx1_dr_offset_AS923[] = {0, 1, 2, 3, 4, 5, -1, -2};
243243

244-
LoRaPHYAS923::LoRaPHYAS923(LoRaWANTimeHandler &lora_time)
245-
: LoRaPHY(lora_time)
244+
LoRaPHYAS923::LoRaPHYAS923()
246245
{
247246
bands[0] = AS923_BAND0;
248247

@@ -352,7 +351,7 @@ lorawan_status_t LoRaPHYAS923::set_next_channel(channel_selection_params_t* next
352351
channel_mask[0] |= LC(1) + LC(2);
353352
}
354353

355-
if (next_channel_prams->aggregate_timeoff <= _lora_time.get_elapsed_time(next_channel_prams->last_aggregate_tx_time)) {
354+
if (next_channel_prams->aggregate_timeoff <= _lora_time->get_elapsed_time(next_channel_prams->last_aggregate_tx_time)) {
356355
// Reset Aggregated time off
357356
*aggregate_timeoff = 0;
358357

@@ -368,7 +367,7 @@ lorawan_status_t LoRaPHYAS923::set_next_channel(channel_selection_params_t* next
368367
enabled_channels, &delay_tx);
369368
} else {
370369
delay_tx++;
371-
next_tx_delay = next_channel_prams->aggregate_timeoff - _lora_time.get_elapsed_time(next_channel_prams->last_aggregate_tx_time);
370+
next_tx_delay = next_channel_prams->aggregate_timeoff - _lora_time->get_elapsed_time(next_channel_prams->last_aggregate_tx_time);
372371
}
373372

374373
if (nb_enabled_channels > 0) {

features/lorawan/lorastack/phy/LoRaPHYAS923.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
class LoRaPHYAS923 : public LoRaPHY {
5151

5252
public:
53-
LoRaPHYAS923(LoRaWANTimeHandler &lora_time);
53+
LoRaPHYAS923();
5454
virtual ~LoRaPHYAS923();
5555

5656
virtual int8_t get_alternate_DR(uint8_t nb_trials);

features/lorawan/lorastack/phy/LoRaPHYAU915.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ static const uint8_t max_payload_with_repeater_AU915[] = { 51, 51, 51, 115,
221221
222, 222, 222, 0, 33, 109, 222, 222, 222, 222, 0, 0 };
222222

223223

224-
LoRaPHYAU915::LoRaPHYAU915(LoRaWANTimeHandler &lora_time)
225-
: LoRaPHY(lora_time)
224+
LoRaPHYAU915::LoRaPHYAU915()
226225
{
227226
bands[0] = AU915_BAND0;
228227

@@ -584,7 +583,7 @@ lorawan_status_t LoRaPHYAU915::set_next_channel(channel_selection_params_t* next
584583
}
585584
}
586585

587-
if (next_chan_params->aggregate_timeoff <= _lora_time.get_elapsed_time(next_chan_params->last_aggregate_tx_time)) {
586+
if (next_chan_params->aggregate_timeoff <= _lora_time->get_elapsed_time(next_chan_params->last_aggregate_tx_time)) {
588587
// Reset Aggregated time off
589588
*aggregated_timeOff = 0;
590589

@@ -600,7 +599,7 @@ lorawan_status_t LoRaPHYAU915::set_next_channel(channel_selection_params_t* next
600599
enabled_channels, &delay_tx);
601600
} else {
602601
delay_tx++;
603-
next_tx_delay = next_chan_params->aggregate_timeoff - _lora_time.get_elapsed_time(next_chan_params->last_aggregate_tx_time);
602+
next_tx_delay = next_chan_params->aggregate_timeoff - _lora_time->get_elapsed_time(next_chan_params->last_aggregate_tx_time);
604603
}
605604

606605
if (nb_enabled_channels > 0) {

features/lorawan/lorastack/phy/LoRaPHYAU915.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class LoRaPHYAU915 : public LoRaPHY{
5353

5454
public:
5555

56-
LoRaPHYAU915(LoRaWANTimeHandler &lora_time);
56+
LoRaPHYAU915();
5757
virtual ~LoRaPHYAU915();
5858

5959
virtual bool rx_config(rx_config_params_t* config);

features/lorawan/lorastack/phy/LoRaPHYCN470.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ static const uint8_t max_payloads_CN470[] = {51, 51, 51, 115, 222, 222};
204204
static const uint8_t max_payloads_with_repeater_CN470[] = {51, 51, 51, 115, 222, 222};
205205

206206

207-
LoRaPHYCN470::LoRaPHYCN470(LoRaWANTimeHandler &lora_time)
208-
: LoRaPHY(lora_time)
207+
LoRaPHYCN470::LoRaPHYCN470()
209208
{
210209
bands[0] = CN470_BAND0;
211210

features/lorawan/lorastack/phy/LoRaPHYCN470.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class LoRaPHYCN470 : public LoRaPHY {
5353

5454
public:
5555

56-
LoRaPHYCN470(LoRaWANTimeHandler &lora_time);
56+
LoRaPHYCN470();
5757
virtual ~LoRaPHYCN470();
5858

5959
virtual bool rx_config(rx_config_params_t* config);

features/lorawan/lorastack/phy/LoRaPHYCN779.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ static const uint8_t max_payloads_CN779[] = {51, 51, 51, 115, 242, 242, 242, 242
230230
static const uint8_t max_payloads_with_repeater_CN779[] = {51, 51, 51, 115, 222, 222, 222, 222};
231231

232232

233-
LoRaPHYCN779::LoRaPHYCN779(LoRaWANTimeHandler &lora_time)
234-
: LoRaPHY(lora_time)
233+
LoRaPHYCN779::LoRaPHYCN779()
235234
{
236235
bands[0] = CN779_BAND0;
237236

features/lorawan/lorastack/phy/LoRaPHYCN779.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class LoRaPHYCN779 : public LoRaPHY {
4545

4646
public:
4747

48-
LoRaPHYCN779(LoRaWANTimeHandler &lora_time);
48+
LoRaPHYCN779();
4949
virtual ~LoRaPHYCN779();
5050

5151
private:

features/lorawan/lorastack/phy/LoRaPHYEU433.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,7 @@ static const uint8_t max_payloads_EU433[] = {51, 51, 51, 115, 242, 242, 242, 242
231231
static const uint8_t max_payloads_with_repeater_EU433[] = {51, 51, 51, 115, 222, 222, 222, 222};
232232

233233

234-
LoRaPHYEU433::LoRaPHYEU433(LoRaWANTimeHandler &lora_time)
235-
: LoRaPHY(lora_time)
234+
LoRaPHYEU433::LoRaPHYEU433()
236235
{
237236
bands[0] = EU433_BAND0;
238237

features/lorawan/lorastack/phy/LoRaPHYEU433.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class LoRaPHYEU433 : public LoRaPHY {
5151

5252
public:
5353

54-
LoRaPHYEU433(LoRaWANTimeHandler &lora_time);
54+
LoRaPHYEU433();
5555
virtual ~LoRaPHYEU433();
5656

5757
private:

features/lorawan/lorastack/phy/LoRaPHYEU868.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,7 @@ static const uint8_t max_payloads_EU868[] = {51, 51, 51, 115, 242, 242, 242, 242
256256
*/
257257
static const uint8_t max_payloads_repeater_EU868[] = {51, 51, 51, 115, 222, 222, 222, 222};
258258

259-
LoRaPHYEU868::LoRaPHYEU868(LoRaWANTimeHandler &lora_time)
260-
: LoRaPHY(lora_time)
259+
LoRaPHYEU868::LoRaPHYEU868()
261260
{
262261
bands[0] = EU868_BAND0;
263262
bands[1] = EU868_BAND1;

features/lorawan/lorastack/phy/LoRaPHYEU868.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
class LoRaPHYEU868 : public LoRaPHY {
5555

5656
public:
57-
LoRaPHYEU868(LoRaWANTimeHandler &lora_time);
57+
LoRaPHYEU868();
5858
virtual ~LoRaPHYEU868();
5959

6060
private:

features/lorawan/lorastack/phy/LoRaPHYIN865.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ static const uint8_t max_payloads_with_repeater[] = { 51, 51, 51, 115, 222, 222,
232232
*/
233233
static const int8_t rx1_dr_offset_IN865[] = { 0, 1, 2, 3, 4, 5, -1, -2 };
234234

235-
LoRaPHYIN865::LoRaPHYIN865(LoRaWANTimeHandler &lora_time)
236-
: LoRaPHY(lora_time)
235+
LoRaPHYIN865::LoRaPHYIN865()
237236
{
238237
bands[0] = IN865_BAND0;
239238

features/lorawan/lorastack/phy/LoRaPHYIN865.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class LoRaPHYIN865 : public LoRaPHY {
5252

5353
public:
5454

55-
LoRaPHYIN865(LoRaWANTimeHandler &lora_time);
55+
LoRaPHYIN865();
5656
virtual ~LoRaPHYIN865();
5757

5858
virtual uint8_t apply_DR_offset(int8_t dr, int8_t dr_offset );

features/lorawan/lorastack/phy/LoRaPHYKR920.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,7 @@ static const uint8_t max_payloads_KR920[] = { 51, 51, 51, 115, 242, 242 };
241241
*/
242242
static const uint8_t max_payloads_with_repeater_KR920[] = { 51, 51, 51, 115, 222, 222 };
243243

244-
LoRaPHYKR920::LoRaPHYKR920(LoRaWANTimeHandler &lora_time)
245-
: LoRaPHY(lora_time)
244+
LoRaPHYKR920::LoRaPHYKR920()
246245
{
247246
bands[0] = KR920_BAND0;
248247

@@ -422,7 +421,7 @@ lorawan_status_t LoRaPHYKR920::set_next_channel(channel_selection_params_t* para
422421
channel_mask[0] |= LC(1) + LC(2) + LC(3);
423422
}
424423

425-
if (params->aggregate_timeoff <= _lora_time.get_elapsed_time(params->last_aggregate_tx_time)) {
424+
if (params->aggregate_timeoff <= _lora_time->get_elapsed_time(params->last_aggregate_tx_time)) {
426425
// Reset Aggregated time off
427426
*aggregate_timeoff = 0;
428427

@@ -436,7 +435,7 @@ lorawan_status_t LoRaPHYKR920::set_next_channel(channel_selection_params_t* para
436435
enabled_channels, &delay_tx);
437436
} else {
438437
delay_tx++;
439-
nextTxDelay = params->aggregate_timeoff - _lora_time.get_elapsed_time(params->last_aggregate_tx_time);
438+
nextTxDelay = params->aggregate_timeoff - _lora_time->get_elapsed_time(params->last_aggregate_tx_time);
440439
}
441440

442441
if (nb_enabled_channels > 0) {

features/lorawan/lorastack/phy/LoRaPHYKR920.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class LoRaPHYKR920 : public LoRaPHY {
5151

5252
public:
5353

54-
LoRaPHYKR920(LoRaWANTimeHandler &lora_time);
54+
LoRaPHYKR920();
5555
virtual ~LoRaPHYKR920();
5656

5757
virtual bool verify_frequency_for_band(uint32_t freq, uint8_t band) const;

features/lorawan/lorastack/phy/LoRaPHYUS915.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,7 @@ static const uint8_t max_payloads_US915[] = { 11, 53, 125, 242, 242, 0, 0, 0, 53
211211
*/
212212
static const uint8_t max_payloads_with_repeater_US915[] = {11, 53, 125, 242, 242, 0, 0, 0, 33, 109, 222, 222, 222, 222, 0, 0};
213213

214-
LoRaPHYUS915::LoRaPHYUS915(LoRaWANTimeHandler &lora_time)
215-
: LoRaPHY(lora_time)
214+
LoRaPHYUS915::LoRaPHYUS915()
216215
{
217216
bands[0] = US915_BAND0;
218217

@@ -624,7 +623,7 @@ lorawan_status_t LoRaPHYUS915::set_next_channel(channel_selection_params_t* para
624623
}
625624
}
626625

627-
if (params->aggregate_timeoff <= _lora_time.get_elapsed_time(params->last_aggregate_tx_time)) {
626+
if (params->aggregate_timeoff <= _lora_time->get_elapsed_time(params->last_aggregate_tx_time)) {
628627
// Reset Aggregated time off
629628
*aggregate_timeOff = 0;
630629

@@ -638,7 +637,7 @@ lorawan_status_t LoRaPHYUS915::set_next_channel(channel_selection_params_t* para
638637
enabled_channels, &delay_tx);
639638
} else {
640639
delay_tx++;
641-
next_tx_delay = params->aggregate_timeoff - _lora_time.get_elapsed_time(params->last_aggregate_tx_time);
640+
next_tx_delay = params->aggregate_timeoff - _lora_time->get_elapsed_time(params->last_aggregate_tx_time);
642641
}
643642

644643
if (nb_enabled_channels > 0) {

features/lorawan/lorastack/phy/LoRaPHYUS915.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class LoRaPHYUS915 : public LoRaPHY {
5151

5252
public:
5353

54-
LoRaPHYUS915(LoRaWANTimeHandler &lora_time);
54+
LoRaPHYUS915();
5555
virtual ~LoRaPHYUS915();
5656

5757
virtual void restore_default_channels();

features/lorawan/lorastack/phy/LoRaPHYUS915Hybrid.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,7 @@ static const uint8_t max_payloads_US915_HYBRID[] = { 11, 53, 125, 242, 242, 0, 0
210210
*/
211211
static const uint8_t max_payloads_with_repeater_US915_HYBRID[] = { 11, 53, 125, 242, 242, 0, 0, 0, 33, 109, 222, 222, 222, 222, 0, 0 };
212212

213-
LoRaPHYUS915Hybrid::LoRaPHYUS915Hybrid(LoRaWANTimeHandler &lora_time)
214-
: LoRaPHY(lora_time)
213+
LoRaPHYUS915Hybrid::LoRaPHYUS915Hybrid()
215214
{
216215
bands[0] = US915_HYBRID_BAND0;
217216

@@ -622,7 +621,7 @@ lorawan_status_t LoRaPHYUS915Hybrid::set_next_channel(channel_selection_params_t
622621
}
623622
}
624623

625-
if (params->aggregate_timeoff <= _lora_time.get_elapsed_time( params->last_aggregate_tx_time)) {
624+
if (params->aggregate_timeoff <= _lora_time->get_elapsed_time( params->last_aggregate_tx_time)) {
626625
// Reset Aggregated time off
627626
*aggregate_timeOff = 0;
628627

@@ -638,7 +637,7 @@ lorawan_status_t LoRaPHYUS915Hybrid::set_next_channel(channel_selection_params_t
638637
enabled_channels, &delay_tx);
639638
} else {
640639
delay_tx++;
641-
next_tx_delay = params->aggregate_timeoff - _lora_time.get_elapsed_time(params->last_aggregate_tx_time);
640+
next_tx_delay = params->aggregate_timeoff - _lora_time->get_elapsed_time(params->last_aggregate_tx_time);
642641
}
643642

644643
if (nb_enabled_channels > 0) {

features/lorawan/lorastack/phy/LoRaPHYUS915Hybrid.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class LoRaPHYUS915Hybrid : public LoRaPHY {
5151

5252
public:
5353

54-
LoRaPHYUS915Hybrid(LoRaWANTimeHandler &lora_time);
54+
LoRaPHYUS915Hybrid();
5555
virtual ~LoRaPHYUS915Hybrid();
5656

5757
virtual void restore_default_channels();

0 commit comments

Comments
 (0)