mirror of https://github.com/ARMmbed/mbed-os.git
LoRa: LoRaMac need removed from LoRaMacCommand class
- LoRaMacCommand does not have any external dependencies anymore - Also LoRaMacMlme is not using LoRaMacCommand anymorepull/6279/head
parent
0828727643
commit
3c7bd1b794
|
@ -78,7 +78,7 @@ using namespace events;
|
|||
|
||||
|
||||
LoRaMac::LoRaMac(LoRaWANTimeHandler &lora_time)
|
||||
: mac_commands(*this), _lora_time(lora_time)
|
||||
: mac_commands(), _lora_time(lora_time)
|
||||
{
|
||||
lora_phy = NULL;
|
||||
//radio_events_t RadioEvents;
|
||||
|
@ -621,10 +621,13 @@ void LoRaMac::on_radio_rx_done(uint8_t *payload, uint16_t size, int16_t rssi,
|
|||
}
|
||||
|
||||
// Decode frame payload MAC commands
|
||||
if (mac_commands.process_mac_commands(_params.payload, 0, frame_len, snr,
|
||||
mlme.get_confirmation(),
|
||||
_params.sys_params, *lora_phy) != LORAWAN_STATUS_OK) {
|
||||
if (LORAWAN_STATUS_OK != mac_commands.process_mac_commands(
|
||||
_params.payload, 0, frame_len, snr,
|
||||
mlme.get_confirmation(), _params.sys_params, *lora_phy)) {
|
||||
mcps.get_indication().status = LORAMAC_EVENT_INFO_STATUS_ERROR;
|
||||
} else if (mac_commands.has_sticky_mac_cmd()) {
|
||||
set_mlme_schedule_ul_indication();
|
||||
mac_commands.clear_sticky_mac_cmd();
|
||||
}
|
||||
} else {
|
||||
skip_indication = true;
|
||||
|
@ -632,10 +635,13 @@ void LoRaMac::on_radio_rx_done(uint8_t *payload, uint16_t size, int16_t rssi,
|
|||
} else {
|
||||
if (fctrl.bits.fopts_len > 0) {
|
||||
// Decode Options field MAC commands. Omit the fPort.
|
||||
if (mac_commands.process_mac_commands(payload, 8, app_payload_start_index - 1, snr,
|
||||
mlme.get_confirmation(),
|
||||
_params.sys_params, *lora_phy ) != LORAWAN_STATUS_OK) {
|
||||
if (LORAWAN_STATUS_OK != mac_commands.process_mac_commands(
|
||||
payload, 8, app_payload_start_index - 1, snr,
|
||||
mlme.get_confirmation(), _params.sys_params, *lora_phy )) {
|
||||
mcps.get_indication().status = LORAMAC_EVENT_INFO_STATUS_ERROR;
|
||||
} else if (mac_commands.has_sticky_mac_cmd()) {
|
||||
set_mlme_schedule_ul_indication();
|
||||
mac_commands.clear_sticky_mac_cmd();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -658,10 +664,14 @@ void LoRaMac::on_radio_rx_done(uint8_t *payload, uint16_t size, int16_t rssi,
|
|||
} else {
|
||||
if (fctrl.bits.fopts_len > 0) {
|
||||
// Decode Options field MAC commands
|
||||
if (mac_commands.process_mac_commands(payload, 8, app_payload_start_index, snr,
|
||||
mlme.get_confirmation(),
|
||||
_params.sys_params, *lora_phy) != LORAWAN_STATUS_OK) {
|
||||
if (LORAWAN_STATUS_OK != mac_commands.process_mac_commands(
|
||||
payload, 8, app_payload_start_index, snr,
|
||||
mlme.get_confirmation(),
|
||||
_params.sys_params, *lora_phy)) {
|
||||
mcps.get_indication().status = LORAMAC_EVENT_INFO_STATUS_ERROR;
|
||||
} else if (mac_commands.has_sticky_mac_cmd()) {
|
||||
set_mlme_schedule_ul_indication();
|
||||
mac_commands.clear_sticky_mac_cmd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1657,7 +1667,7 @@ lorawan_status_t LoRaMac::initialize(loramac_primitives_t *primitives,
|
|||
lora_phy = phy;
|
||||
|
||||
// Activate MLME subsystem
|
||||
mlme.activate_mlme_subsystem(this, lora_phy, &mac_commands);
|
||||
mlme.activate_mlme_subsystem(this, lora_phy);
|
||||
|
||||
// Activate MCPS subsystem
|
||||
mcps.activate_mcps_subsystem(this, lora_phy);
|
||||
|
@ -1961,7 +1971,11 @@ lorawan_status_t LoRaMac::multicast_channel_unlink(
|
|||
|
||||
lorawan_status_t LoRaMac::mlme_request( loramac_mlme_req_t *mlmeRequest )
|
||||
{
|
||||
return mlme.set_request(mlmeRequest, &_params);
|
||||
lorawan_status_t status = mlme.set_request(mlmeRequest, &_params);
|
||||
if (MLME_LINK_CHECK == mlmeRequest->type) {
|
||||
status = mac_commands.add_mac_command(MOTE_MAC_LINK_CHECK_REQ, 0, 0);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
lorawan_status_t LoRaMac::mcps_request( loramac_mcps_req_t *mcpsRequest )
|
||||
|
|
|
@ -39,10 +39,10 @@ SPDX-License-Identifier: BSD-3-Clause
|
|||
static const uint8_t max_eirp_table[] = { 8, 10, 12, 13, 14, 16, 18, 20, 21, 24, 26, 27, 29, 30, 33, 36 };
|
||||
|
||||
|
||||
LoRaMacCommand::LoRaMacCommand(LoRaMac& lora_mac)
|
||||
: _lora_mac(lora_mac)
|
||||
LoRaMacCommand::LoRaMacCommand()
|
||||
{
|
||||
mac_cmd_in_next_tx = false;
|
||||
sticky_mac_cmd = false;
|
||||
mac_cmd_buf_idx = 0;
|
||||
mac_cmd_buf_idx_to_repeat = 0;
|
||||
|
||||
|
@ -91,7 +91,8 @@ lorawan_status_t LoRaMacCommand::add_mac_command(uint8_t cmd, uint8_t p1,
|
|||
// Status: Datarate ACK, Channel ACK
|
||||
mac_cmd_buffer[mac_cmd_buf_idx++] = p1;
|
||||
// This is a sticky MAC command answer. Setup indication
|
||||
_lora_mac.set_mlme_schedule_ul_indication();
|
||||
// _lora_mac.set_mlme_schedule_ul_indication();
|
||||
sticky_mac_cmd = true;
|
||||
status = LORAWAN_STATUS_OK;
|
||||
}
|
||||
break;
|
||||
|
@ -118,7 +119,8 @@ lorawan_status_t LoRaMacCommand::add_mac_command(uint8_t cmd, uint8_t p1,
|
|||
mac_cmd_buffer[mac_cmd_buf_idx++] = cmd;
|
||||
// No payload for this answer
|
||||
// This is a sticky MAC command answer. Setup indication
|
||||
_lora_mac.set_mlme_schedule_ul_indication();
|
||||
// _lora_mac.set_mlme_schedule_ul_indication();
|
||||
sticky_mac_cmd = true;
|
||||
status = LORAWAN_STATUS_OK;
|
||||
}
|
||||
break;
|
||||
|
@ -135,7 +137,8 @@ lorawan_status_t LoRaMacCommand::add_mac_command(uint8_t cmd, uint8_t p1,
|
|||
// Status: Uplink frequency exists, Channel frequency OK
|
||||
mac_cmd_buffer[mac_cmd_buf_idx++] = p1;
|
||||
// This is a sticky MAC command answer. Setup indication
|
||||
_lora_mac.set_mlme_schedule_ul_indication();
|
||||
// _lora_mac.set_mlme_schedule_ul_indication();
|
||||
sticky_mac_cmd = true;
|
||||
status = LORAWAN_STATUS_OK;
|
||||
}
|
||||
break;
|
||||
|
@ -216,7 +219,6 @@ void LoRaMacCommand::clear_repeat_buffer()
|
|||
|
||||
void LoRaMacCommand::copy_repeat_commands_to_buffer()
|
||||
{
|
||||
// Copy the MAC commands which must be re-send into the MAC command buffer
|
||||
memcpy(&mac_cmd_buffer[mac_cmd_buf_idx], mac_cmd_buffer_to_repeat, mac_cmd_buf_idx_to_repeat);
|
||||
mac_cmd_buf_idx += mac_cmd_buf_idx_to_repeat;
|
||||
}
|
||||
|
@ -236,10 +238,18 @@ bool LoRaMacCommand::is_mac_command_in_next_tx() const
|
|||
return mac_cmd_in_next_tx;
|
||||
}
|
||||
|
||||
lorawan_status_t LoRaMacCommand::process_mac_commands(uint8_t *payload,
|
||||
uint8_t mac_index,
|
||||
uint8_t commands_size,
|
||||
uint8_t snr,
|
||||
void LoRaMacCommand::clear_sticky_mac_cmd()
|
||||
{
|
||||
sticky_mac_cmd = false;
|
||||
}
|
||||
|
||||
bool LoRaMacCommand::has_sticky_mac_cmd() const
|
||||
{
|
||||
return sticky_mac_cmd;
|
||||
}
|
||||
|
||||
lorawan_status_t LoRaMacCommand::process_mac_commands(uint8_t *payload, uint8_t mac_index,
|
||||
uint8_t commands_size, uint8_t snr,
|
||||
loramac_mlme_confirm_t& mlme_conf,
|
||||
lora_mac_system_params_t &mac_sys_params,
|
||||
LoRaPHY &lora_phy)
|
||||
|
@ -416,8 +426,8 @@ lorawan_status_t LoRaMacCommand::process_mac_commands(uint8_t *payload,
|
|||
|
||||
bool LoRaMacCommand::is_sticky_mac_command_pending()
|
||||
{
|
||||
//DEAD CODE: mac_cmd_buf_idx_to_repeat is never set
|
||||
if (mac_cmd_buf_idx_to_repeat > 0) {
|
||||
// Sticky MAC commands pending
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -54,7 +54,7 @@ class LoRaMac;
|
|||
class LoRaMacCommand {
|
||||
|
||||
public:
|
||||
LoRaMacCommand(LoRaMac &lora_mac);
|
||||
LoRaMacCommand();
|
||||
~LoRaMacCommand();
|
||||
|
||||
/**
|
||||
|
@ -129,6 +129,18 @@ public:
|
|||
*/
|
||||
bool is_mac_command_in_next_tx() const;
|
||||
|
||||
/**
|
||||
* @brief Clear sticky MAC commands.
|
||||
*/
|
||||
void clear_sticky_mac_cmd();
|
||||
|
||||
/**
|
||||
* @brief Check if MAC command buffer contains sticky commands
|
||||
*
|
||||
* @return status True: buffer has sticky MAC commands in it, false: no sticky commands in buffer]
|
||||
*/
|
||||
bool has_sticky_mac_cmd() const;
|
||||
|
||||
/**
|
||||
* @brief Decodes MAC commands in the fOpts field and in the payload
|
||||
*
|
||||
|
@ -148,13 +160,16 @@ public:
|
|||
bool is_sticky_mac_command_pending();
|
||||
|
||||
private:
|
||||
LoRaMac& _lora_mac;
|
||||
|
||||
/**
|
||||
* Indicates if the MAC layer wants to send MAC commands
|
||||
*/
|
||||
bool mac_cmd_in_next_tx;
|
||||
|
||||
/**
|
||||
* Indicates if there are any pending sticky MAC commands
|
||||
*/
|
||||
bool sticky_mac_cmd;
|
||||
|
||||
/**
|
||||
* Contains the current Mac command buffer index in 'mac_cmd_buffer'
|
||||
*/
|
||||
|
|
|
@ -27,7 +27,7 @@ SPDX-License-Identifier: BSD-3-Clause
|
|||
#include "lorastack/mac/LoRaMacMlme.h"
|
||||
|
||||
LoRaMacMlme::LoRaMacMlme()
|
||||
: _lora_mac(NULL), _lora_phy(NULL), _mac_cmd(NULL)
|
||||
: _lora_mac(NULL), _lora_phy(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -35,18 +35,16 @@ LoRaMacMlme::~LoRaMacMlme()
|
|||
{
|
||||
}
|
||||
|
||||
void LoRaMacMlme::activate_mlme_subsystem(LoRaMac *mac, LoRaPHY *phy,
|
||||
LoRaMacCommand *cmd)
|
||||
void LoRaMacMlme::activate_mlme_subsystem(LoRaMac *mac, LoRaPHY *phy)
|
||||
{
|
||||
_lora_mac = mac;
|
||||
_lora_phy = phy;
|
||||
_mac_cmd = cmd;
|
||||
}
|
||||
|
||||
lorawan_status_t LoRaMacMlme::set_request(loramac_mlme_req_t *request,
|
||||
loramac_protocol_params *params)
|
||||
{
|
||||
if (request && params && _lora_mac && _lora_phy && _mac_cmd) {
|
||||
if (request && params && _lora_mac && _lora_phy) {
|
||||
|
||||
lorawan_status_t status = LORAWAN_STATUS_SERVICE_UNKNOWN;
|
||||
loramac_mhdr_t machdr;
|
||||
|
@ -118,7 +116,7 @@ lorawan_status_t LoRaMacMlme::set_request(loramac_mlme_req_t *request,
|
|||
// LoRaMac will send this command piggy-backed
|
||||
confirmation.req_type = request->type;
|
||||
|
||||
status = _mac_cmd->add_mac_command(MOTE_MAC_LINK_CHECK_REQ, 0, 0);
|
||||
status = LORAWAN_STATUS_OK;
|
||||
break;
|
||||
}
|
||||
case MLME_TXCW: {
|
||||
|
|
|
@ -28,7 +28,6 @@ SPDX-License-Identifier: BSD-3-Clause
|
|||
|
||||
#include "lorawan/system/lorawan_data_structures.h"
|
||||
#include "lorastack/phy/LoRaPHY.h"
|
||||
#include "lorastack/mac/LoRaMacCommand.h"
|
||||
|
||||
// forward declaration
|
||||
class LoRaMac;
|
||||
|
@ -56,9 +55,8 @@ public:
|
|||
*
|
||||
* @param mac pointer to MAC layer
|
||||
* @param phy pointer to PHY layer
|
||||
* @param cmd pointer to MAC commands
|
||||
*/
|
||||
void activate_mlme_subsystem(LoRaMac *mac, LoRaPHY *phy, LoRaMacCommand *cmd);
|
||||
void activate_mlme_subsystem(LoRaMac *mac, LoRaPHY *phy);
|
||||
|
||||
/** Sets up an MLME Request
|
||||
*
|
||||
|
@ -99,7 +97,6 @@ private:
|
|||
*/
|
||||
LoRaMac *_lora_mac;
|
||||
LoRaPHY *_lora_phy;
|
||||
LoRaMacCommand *_mac_cmd;
|
||||
|
||||
/**
|
||||
* Structure to hold MLME indication data.
|
||||
|
|
Loading…
Reference in New Issue