Skip to content

Commit 25d1e2c

Browse files
author
Antti Kauppila
committed
LoRa: LoRaMac need removed from LoRaMacCommand class
- LoRaMacCommand does not have any external dependencies anymore - Also LoRaMacMlme is not using LoRaMacCommand anymore
1 parent 79bd263 commit 25d1e2c

File tree

5 files changed

+70
-36
lines changed

5 files changed

+70
-36
lines changed

features/lorawan/lorastack/mac/LoRaMac.cpp

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ using namespace events;
7878

7979

8080
LoRaMac::LoRaMac(LoRaWANTimeHandler &lora_time)
81-
: mac_commands(*this), _lora_time(lora_time)
81+
: mac_commands(), _lora_time(lora_time)
8282
{
8383
lora_phy = NULL;
8484
//radio_events_t RadioEvents;
@@ -621,21 +621,27 @@ void LoRaMac::on_radio_rx_done(uint8_t *payload, uint16_t size, int16_t rssi,
621621
}
622622

623623
// Decode frame payload MAC commands
624-
if (mac_commands.process_mac_commands(_params.payload, 0, frame_len, snr,
625-
mlme.get_confirmation(),
626-
_params.sys_params, *lora_phy) != LORAWAN_STATUS_OK) {
624+
if (LORAWAN_STATUS_OK != mac_commands.process_mac_commands(
625+
_params.payload, 0, frame_len, snr,
626+
mlme.get_confirmation(), _params.sys_params, *lora_phy)) {
627627
mcps.get_indication().status = LORAMAC_EVENT_INFO_STATUS_ERROR;
628+
} else if (mac_commands.has_sticky_mac_cmd()) {
629+
set_mlme_schedule_ul_indication();
630+
mac_commands.clear_sticky_mac_cmd();
628631
}
629632
} else {
630633
skip_indication = true;
631634
}
632635
} else {
633636
if (fctrl.bits.fopts_len > 0) {
634637
// Decode Options field MAC commands. Omit the fPort.
635-
if (mac_commands.process_mac_commands(payload, 8, app_payload_start_index - 1, snr,
636-
mlme.get_confirmation(),
637-
_params.sys_params, *lora_phy ) != LORAWAN_STATUS_OK) {
638+
if (LORAWAN_STATUS_OK != mac_commands.process_mac_commands(
639+
payload, 8, app_payload_start_index - 1, snr,
640+
mlme.get_confirmation(), _params.sys_params, *lora_phy )) {
638641
mcps.get_indication().status = LORAMAC_EVENT_INFO_STATUS_ERROR;
642+
} else if (mac_commands.has_sticky_mac_cmd()) {
643+
set_mlme_schedule_ul_indication();
644+
mac_commands.clear_sticky_mac_cmd();
639645
}
640646
}
641647

@@ -658,10 +664,14 @@ void LoRaMac::on_radio_rx_done(uint8_t *payload, uint16_t size, int16_t rssi,
658664
} else {
659665
if (fctrl.bits.fopts_len > 0) {
660666
// Decode Options field MAC commands
661-
if (mac_commands.process_mac_commands(payload, 8, app_payload_start_index, snr,
662-
mlme.get_confirmation(),
663-
_params.sys_params, *lora_phy) != LORAWAN_STATUS_OK) {
667+
if (LORAWAN_STATUS_OK != mac_commands.process_mac_commands(
668+
payload, 8, app_payload_start_index, snr,
669+
mlme.get_confirmation(),
670+
_params.sys_params, *lora_phy)) {
664671
mcps.get_indication().status = LORAMAC_EVENT_INFO_STATUS_ERROR;
672+
} else if (mac_commands.has_sticky_mac_cmd()) {
673+
set_mlme_schedule_ul_indication();
674+
mac_commands.clear_sticky_mac_cmd();
665675
}
666676
}
667677
}
@@ -1657,7 +1667,7 @@ lorawan_status_t LoRaMac::initialize(loramac_primitives_t *primitives,
16571667
lora_phy = phy;
16581668

16591669
// Activate MLME subsystem
1660-
mlme.activate_mlme_subsystem(this, lora_phy, &mac_commands);
1670+
mlme.activate_mlme_subsystem(this, lora_phy);
16611671

16621672
// Activate MCPS subsystem
16631673
mcps.activate_mcps_subsystem(this, lora_phy);
@@ -1961,7 +1971,11 @@ lorawan_status_t LoRaMac::multicast_channel_unlink(
19611971

19621972
lorawan_status_t LoRaMac::mlme_request( loramac_mlme_req_t *mlmeRequest )
19631973
{
1964-
return mlme.set_request(mlmeRequest, &_params);
1974+
lorawan_status_t status = mlme.set_request(mlmeRequest, &_params);
1975+
if (MLME_LINK_CHECK == mlmeRequest->type) {
1976+
status = mac_commands.add_mac_command(MOTE_MAC_LINK_CHECK_REQ, 0, 0);
1977+
}
1978+
return status;
19651979
}
19661980

19671981
lorawan_status_t LoRaMac::mcps_request( loramac_mcps_req_t *mcpsRequest )

features/lorawan/lorastack/mac/LoRaMacCommand.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ SPDX-License-Identifier: BSD-3-Clause
3939
static const uint8_t max_eirp_table[] = { 8, 10, 12, 13, 14, 16, 18, 20, 21, 24, 26, 27, 29, 30, 33, 36 };
4040

4141

42-
LoRaMacCommand::LoRaMacCommand(LoRaMac& lora_mac)
43-
: _lora_mac(lora_mac)
42+
LoRaMacCommand::LoRaMacCommand()
4443
{
4544
mac_cmd_in_next_tx = false;
45+
sticky_mac_cmd = false;
4646
mac_cmd_buf_idx = 0;
4747
mac_cmd_buf_idx_to_repeat = 0;
4848

@@ -91,7 +91,8 @@ lorawan_status_t LoRaMacCommand::add_mac_command(uint8_t cmd, uint8_t p1,
9191
// Status: Datarate ACK, Channel ACK
9292
mac_cmd_buffer[mac_cmd_buf_idx++] = p1;
9393
// This is a sticky MAC command answer. Setup indication
94-
_lora_mac.set_mlme_schedule_ul_indication();
94+
// _lora_mac.set_mlme_schedule_ul_indication();
95+
sticky_mac_cmd = true;
9596
status = LORAWAN_STATUS_OK;
9697
}
9798
break;
@@ -118,7 +119,8 @@ lorawan_status_t LoRaMacCommand::add_mac_command(uint8_t cmd, uint8_t p1,
118119
mac_cmd_buffer[mac_cmd_buf_idx++] = cmd;
119120
// No payload for this answer
120121
// This is a sticky MAC command answer. Setup indication
121-
_lora_mac.set_mlme_schedule_ul_indication();
122+
// _lora_mac.set_mlme_schedule_ul_indication();
123+
sticky_mac_cmd = true;
122124
status = LORAWAN_STATUS_OK;
123125
}
124126
break;
@@ -135,7 +137,8 @@ lorawan_status_t LoRaMacCommand::add_mac_command(uint8_t cmd, uint8_t p1,
135137
// Status: Uplink frequency exists, Channel frequency OK
136138
mac_cmd_buffer[mac_cmd_buf_idx++] = p1;
137139
// This is a sticky MAC command answer. Setup indication
138-
_lora_mac.set_mlme_schedule_ul_indication();
140+
// _lora_mac.set_mlme_schedule_ul_indication();
141+
sticky_mac_cmd = true;
139142
status = LORAWAN_STATUS_OK;
140143
}
141144
break;
@@ -216,7 +219,6 @@ void LoRaMacCommand::clear_repeat_buffer()
216219

217220
void LoRaMacCommand::copy_repeat_commands_to_buffer()
218221
{
219-
// Copy the MAC commands which must be re-send into the MAC command buffer
220222
memcpy(&mac_cmd_buffer[mac_cmd_buf_idx], mac_cmd_buffer_to_repeat, mac_cmd_buf_idx_to_repeat);
221223
mac_cmd_buf_idx += mac_cmd_buf_idx_to_repeat;
222224
}
@@ -236,10 +238,18 @@ bool LoRaMacCommand::is_mac_command_in_next_tx() const
236238
return mac_cmd_in_next_tx;
237239
}
238240

239-
lorawan_status_t LoRaMacCommand::process_mac_commands(uint8_t *payload,
240-
uint8_t mac_index,
241-
uint8_t commands_size,
242-
uint8_t snr,
241+
void LoRaMacCommand::clear_sticky_mac_cmd()
242+
{
243+
sticky_mac_cmd = false;
244+
}
245+
246+
bool LoRaMacCommand::has_sticky_mac_cmd() const
247+
{
248+
return sticky_mac_cmd;
249+
}
250+
251+
lorawan_status_t LoRaMacCommand::process_mac_commands(uint8_t *payload, uint8_t mac_index,
252+
uint8_t commands_size, uint8_t snr,
243253
loramac_mlme_confirm_t& mlme_conf,
244254
lora_mac_system_params_t &mac_sys_params,
245255
LoRaPHY &lora_phy)
@@ -416,8 +426,8 @@ lorawan_status_t LoRaMacCommand::process_mac_commands(uint8_t *payload,
416426

417427
bool LoRaMacCommand::is_sticky_mac_command_pending()
418428
{
429+
//DEAD CODE: mac_cmd_buf_idx_to_repeat is never set
419430
if (mac_cmd_buf_idx_to_repeat > 0) {
420-
// Sticky MAC commands pending
421431
return true;
422432
}
423433
return false;

features/lorawan/lorastack/mac/LoRaMacCommand.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class LoRaMac;
5454
class LoRaMacCommand {
5555

5656
public:
57-
LoRaMacCommand(LoRaMac &lora_mac);
57+
LoRaMacCommand();
5858
~LoRaMacCommand();
5959

6060
/**
@@ -129,6 +129,18 @@ class LoRaMacCommand {
129129
*/
130130
bool is_mac_command_in_next_tx() const;
131131

132+
/**
133+
* @brief Clear sticky MAC commands.
134+
*/
135+
void clear_sticky_mac_cmd();
136+
137+
/**
138+
* @brief Check if MAC command buffer contains sticky commands
139+
*
140+
* @return status True: buffer has sticky MAC commands in it, false: no sticky commands in buffer]
141+
*/
142+
bool has_sticky_mac_cmd() const;
143+
132144
/**
133145
* @brief Decodes MAC commands in the fOpts field and in the payload
134146
*
@@ -148,13 +160,16 @@ class LoRaMacCommand {
148160
bool is_sticky_mac_command_pending();
149161

150162
private:
151-
LoRaMac& _lora_mac;
152-
153163
/**
154164
* Indicates if the MAC layer wants to send MAC commands
155165
*/
156166
bool mac_cmd_in_next_tx;
157167

168+
/**
169+
* Indicates if there are any pending sticky MAC commands
170+
*/
171+
bool sticky_mac_cmd;
172+
158173
/**
159174
* Contains the current Mac command buffer index in 'mac_cmd_buffer'
160175
*/

features/lorawan/lorastack/mac/LoRaMacMlme.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,24 @@ SPDX-License-Identifier: BSD-3-Clause
2727
#include "lorastack/mac/LoRaMacMlme.h"
2828

2929
LoRaMacMlme::LoRaMacMlme()
30-
: _lora_mac(NULL), _lora_phy(NULL), _mac_cmd(NULL)
30+
: _lora_mac(NULL), _lora_phy(NULL)
3131
{
3232
}
3333

3434
LoRaMacMlme::~LoRaMacMlme()
3535
{
3636
}
3737

38-
void LoRaMacMlme::activate_mlme_subsystem(LoRaMac *mac, LoRaPHY *phy,
39-
LoRaMacCommand *cmd)
38+
void LoRaMacMlme::activate_mlme_subsystem(LoRaMac *mac, LoRaPHY *phy)
4039
{
4140
_lora_mac = mac;
4241
_lora_phy = phy;
43-
_mac_cmd = cmd;
4442
}
4543

4644
lorawan_status_t LoRaMacMlme::set_request(loramac_mlme_req_t *request,
4745
loramac_protocol_params *params)
4846
{
49-
if (request && params && _lora_mac && _lora_phy && _mac_cmd) {
47+
if (request && params && _lora_mac && _lora_phy) {
5048

5149
lorawan_status_t status = LORAWAN_STATUS_SERVICE_UNKNOWN;
5250
loramac_mhdr_t machdr;
@@ -118,7 +116,7 @@ lorawan_status_t LoRaMacMlme::set_request(loramac_mlme_req_t *request,
118116
// LoRaMac will send this command piggy-backed
119117
confirmation.req_type = request->type;
120118

121-
status = _mac_cmd->add_mac_command(MOTE_MAC_LINK_CHECK_REQ, 0, 0);
119+
status = LORAWAN_STATUS_OK;
122120
break;
123121
}
124122
case MLME_TXCW: {

features/lorawan/lorastack/mac/LoRaMacMlme.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ SPDX-License-Identifier: BSD-3-Clause
2828

2929
#include "lorawan/system/lorawan_data_structures.h"
3030
#include "lorastack/phy/LoRaPHY.h"
31-
#include "lorastack/mac/LoRaMacCommand.h"
3231

3332
// forward declaration
3433
class LoRaMac;
@@ -56,9 +55,8 @@ class LoRaMacMlme {
5655
*
5756
* @param mac pointer to MAC layer
5857
* @param phy pointer to PHY layer
59-
* @param cmd pointer to MAC commands
6058
*/
61-
void activate_mlme_subsystem(LoRaMac *mac, LoRaPHY *phy, LoRaMacCommand *cmd);
59+
void activate_mlme_subsystem(LoRaMac *mac, LoRaPHY *phy);
6260

6361
/** Sets up an MLME Request
6462
*
@@ -99,7 +97,6 @@ class LoRaMacMlme {
9997
*/
10098
LoRaMac *_lora_mac;
10199
LoRaPHY *_lora_phy;
102-
LoRaMacCommand *_mac_cmd;
103100

104101
/**
105102
* Structure to hold MLME indication data.

0 commit comments

Comments
 (0)