mirror of https://github.com/ARMmbed/mbed-os.git
LoRA: Code cleanup + doxygen updates
- Internal changes only - reset function is created to LoRaPHY to reset LoRaMAC parameters with default values - Doxygen updates for newly created functionspull/6279/head
parent
2ac73a6cac
commit
488cf03d1e
|
@ -87,21 +87,15 @@ lorawan_status_t LoRaWANStack::set_application_port(uint8_t port)
|
|||
LoRaWANStack::LoRaWANStack()
|
||||
: _loramac(_lora_time), _lora_phy(_lora_time),
|
||||
_device_current_state(DEVICE_STATE_NOT_INITIALIZED), _mac_handlers(NULL),
|
||||
_num_retry(1), _queue(NULL), _duty_cycle_on(MBED_CONF_LORA_DUTY_CYCLE_ON)
|
||||
_num_retry(1), _queue(NULL), _duty_cycle_on(MBED_CONF_LORA_DUTY_CYCLE_ON),
|
||||
_app_port(INVALID_PORT)
|
||||
{
|
||||
#ifdef MBED_CONF_LORA_APP_PORT
|
||||
// is_port_valid() is not virtual, so we can call it in constructor
|
||||
if (is_port_valid(MBED_CONF_LORA_APP_PORT)) {
|
||||
_app_port = MBED_CONF_LORA_APP_PORT;
|
||||
} else {
|
||||
tr_error("User defined port in .json is illegal.");
|
||||
_app_port = INVALID_PORT;
|
||||
}
|
||||
|
||||
#else
|
||||
// initialize it to INVALID_PORT (255) an illegal port number.
|
||||
// user should set the port
|
||||
_app_port = INVALID_PORT;
|
||||
#endif
|
||||
|
||||
memset(&_lw_session, 0, sizeof(_lw_session));
|
||||
|
|
|
@ -455,10 +455,10 @@ private:
|
|||
lorawan_session_t _lw_session;
|
||||
loramac_tx_message_t _tx_msg;
|
||||
loramac_rx_message_t _rx_msg;
|
||||
uint8_t _app_port;
|
||||
uint8_t _num_retry;
|
||||
events::EventQueue *_queue;
|
||||
bool _duty_cycle_on;
|
||||
uint8_t _app_port;
|
||||
|
||||
|
||||
#if defined(LORAWAN_COMPLIANCE_TEST)
|
||||
|
|
|
@ -1274,21 +1274,7 @@ void LoRaMac::reset_mac_parameters(void)
|
|||
|
||||
_params.is_rx_window_enabled = true;
|
||||
|
||||
_params.sys_params.channel_tx_power = lora_phy->get_default_tx_power();
|
||||
|
||||
_params.sys_params.channel_data_rate = lora_phy->get_default_tx_datarate();
|
||||
|
||||
_params.sys_params.rx1_dr_offset = lora_phy->get_default_datarate1_offset();
|
||||
|
||||
_params.sys_params.rx2_channel.frequency = lora_phy->get_default_rx2_frequency();
|
||||
|
||||
_params.sys_params.rx2_channel.datarate = lora_phy->get_default_rx2_datarate();
|
||||
|
||||
_params.sys_params.uplink_dwell_time = lora_phy->get_default_uplink_dwell_time();
|
||||
|
||||
_params.sys_params.max_eirp = lora_phy->get_default_max_eirp();
|
||||
|
||||
_params.sys_params.antenna_gain = lora_phy->get_default_antenna_gain();
|
||||
lora_phy->reset_to_default_values(&_params, false);
|
||||
|
||||
_params.is_node_ack_requested = false;
|
||||
_params.is_srv_ack_requested = false;
|
||||
|
@ -1632,35 +1618,7 @@ lorawan_status_t LoRaMac::initialize(loramac_primitives_t *primitives,
|
|||
_params.timers.aggregated_last_tx_time = 0;
|
||||
_params.timers.aggregated_timeoff = 0;
|
||||
|
||||
_params.is_dutycycle_on = lora_phy->duty_cycle_enabled();
|
||||
|
||||
_params.sys_params.channel_tx_power = lora_phy->get_default_tx_power();
|
||||
|
||||
_params.sys_params.channel_data_rate = lora_phy->get_default_tx_datarate();
|
||||
|
||||
_params.sys_params.max_rx_win_time = lora_phy->get_maximum_receive_window_duration();
|
||||
|
||||
_params.sys_params.recv_delay1 = lora_phy->get_window1_receive_delay();
|
||||
|
||||
_params.sys_params.recv_delay2 = lora_phy->get_window2_receive_delay();
|
||||
|
||||
_params.sys_params.join_accept_delay1 = lora_phy->get_window1_join_accept_delay();
|
||||
|
||||
_params.sys_params.join_accept_delay2 = lora_phy->get_window2_join_accept_delay();
|
||||
|
||||
_params.sys_params.rx1_dr_offset = lora_phy->get_default_datarate1_offset();
|
||||
|
||||
_params.sys_params.rx2_channel.frequency = lora_phy->get_default_rx2_frequency();
|
||||
|
||||
_params.sys_params.rx2_channel.datarate = lora_phy->get_default_rx2_datarate();
|
||||
|
||||
_params.sys_params.uplink_dwell_time = lora_phy->get_default_uplink_dwell_time();
|
||||
|
||||
_params.sys_params.downlink_dwell_time = lora_phy->get_default_downlink_dwell_time();
|
||||
|
||||
_params.sys_params.max_eirp = lora_phy->get_default_max_eirp();
|
||||
|
||||
_params.sys_params.antenna_gain = lora_phy->get_default_antenna_gain();
|
||||
lora_phy->reset_to_default_values(&_params, true);
|
||||
|
||||
// Init parameters which are not set in function ResetMacParameters
|
||||
_params.sys_params.max_sys_rx_error = 10;
|
||||
|
@ -1909,7 +1867,7 @@ lorawan_status_t LoRaMac::mlme_request( loramac_mlme_req_t *mlmeRequest )
|
|||
|
||||
if (!lora_phy->verify_nb_join_trials(mlmeRequest->req.join.nb_trials)) {
|
||||
// Value not supported, get default
|
||||
_params.max_join_request_trials = lora_phy->get_nb_join_trials(true);
|
||||
_params.max_join_request_trials = MBED_CONF_LORA_NB_TRIALS;
|
||||
}
|
||||
// Reset variable JoinRequestTrials
|
||||
_params.join_request_trial_counter = 0;
|
||||
|
|
|
@ -54,7 +54,6 @@ public:
|
|||
* Stores pointers to PHY layer MIB subsystem
|
||||
*
|
||||
* @param phy pointer to PHY layer
|
||||
* @param mib pointer to MIB subsystem
|
||||
*/
|
||||
void activate_channelplan_subsystem(LoRaPHY *phy);
|
||||
|
||||
|
@ -75,13 +74,13 @@ public:
|
|||
*
|
||||
* Used to get active channel plan.
|
||||
*
|
||||
* @param plan a reference to application provided channel plan structure
|
||||
* which gets filled in with active channel plan data.
|
||||
* @param plan a reference to application provided channel plan structure
|
||||
* which gets filled in with active channel plan data.
|
||||
*
|
||||
* @param params pointer to active MAC layer parameters.
|
||||
* @param mib_confirm pointer to MIB request structure containing channel information
|
||||
*
|
||||
* @return LORAWAN_STATUS_OK if everything goes well otherwise
|
||||
* a negative error code is returned.
|
||||
* @return LORAWAN_STATUS_OK if everything goes well otherwise
|
||||
* a negative error code is returned.
|
||||
*/
|
||||
lorawan_status_t get_plan(lorawan_channelplan_t& plan, const loramac_mib_req_confirm_t *mib_confirm);
|
||||
|
||||
|
|
|
@ -125,7 +125,7 @@ public:
|
|||
/**
|
||||
* @brief Check if MAC command buffer has commands to be sent in next TX
|
||||
*
|
||||
* @return status True: buffer has MAC commands to be sent, false: no commands in buffer]
|
||||
* @return status True: buffer has MAC commands to be sent, false: no commands in buffer
|
||||
*/
|
||||
bool is_mac_command_in_next_tx() const;
|
||||
|
||||
|
@ -137,7 +137,7 @@ public:
|
|||
/**
|
||||
* @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]
|
||||
* @return status True: buffer has sticky MAC commands in it, false: no sticky commands in buffer
|
||||
*/
|
||||
bool has_sticky_mac_cmd() const;
|
||||
|
||||
|
|
|
@ -57,9 +57,6 @@ public:
|
|||
/** Activating MCPS subsystem
|
||||
*
|
||||
* Stores pointers to MAC and PHY layer handles
|
||||
*
|
||||
* @param mac pointer to MAC layer
|
||||
* @param phy pointer to PHY layer
|
||||
*/
|
||||
void activate_mcps_subsystem();
|
||||
|
||||
|
|
|
@ -53,7 +53,6 @@ public:
|
|||
*
|
||||
* Stores pointers to MAC and PHY layer handles
|
||||
*
|
||||
* @param mac pointer to MAC layer
|
||||
* @param phy pointer to PHY layer
|
||||
*/
|
||||
void activate_mib_subsystem(LoRaPHY *phy);
|
||||
|
|
|
@ -58,7 +58,6 @@ public:
|
|||
*
|
||||
* Stores pointers to MAC and PHY layer handles
|
||||
*
|
||||
* @param mac pointer to MAC layer
|
||||
* @param phy pointer to PHY layer
|
||||
*/
|
||||
void activate_mlme_subsystem(LoRaPHY *phy);
|
||||
|
@ -75,6 +74,15 @@ public:
|
|||
*/
|
||||
loramac_mlme_indication_t& get_indication();
|
||||
|
||||
/**
|
||||
* @brief set_tx_continuous_wave Puts the system in continuous transmission mode
|
||||
* @param [in] channel A Channel to use
|
||||
* @param [in] datarate A datarate to use
|
||||
* @param [in] tx_power A RF output power to use
|
||||
* @param [in] max_eirp A maximum possible EIRP to use
|
||||
* @param [in] antenna_gain Antenna gain to use
|
||||
* @param [in] timeout Time in seconds while the radio is kept in continuous wave mode
|
||||
*/
|
||||
void set_tx_continuous_wave(uint8_t channel, int8_t datarate, int8_t tx_power,
|
||||
float max_eirp, float antenna_gain, uint16_t timeout);
|
||||
|
||||
|
|
|
@ -487,14 +487,48 @@ uint8_t LoRaPHY::enabled_channel_count(bool joined, uint8_t datarate,
|
|||
return count;
|
||||
}
|
||||
|
||||
uint32_t LoRaPHY::get_next_lower_tx_datarate(int8_t datarate)
|
||||
void LoRaPHY::reset_to_default_values(loramac_protocol_params *params, bool init)
|
||||
{
|
||||
if (init) {
|
||||
params->is_dutycycle_on = phy_params.duty_cycle_enabled;
|
||||
|
||||
params->sys_params.max_rx_win_time = phy_params.max_rx_window;
|
||||
|
||||
params->sys_params.recv_delay1 = phy_params.recv_delay1;
|
||||
|
||||
params->sys_params.recv_delay2 = phy_params.recv_delay2;
|
||||
|
||||
params->sys_params.join_accept_delay1 = phy_params.join_accept_delay1;
|
||||
|
||||
params->sys_params.join_accept_delay2 = phy_params.join_accept_delay2;
|
||||
|
||||
params->sys_params.downlink_dwell_time = phy_params.dl_dwell_time_setting;
|
||||
}
|
||||
|
||||
params->sys_params.channel_tx_power = get_default_tx_power();
|
||||
|
||||
params->sys_params.channel_data_rate = get_default_tx_datarate();
|
||||
|
||||
params->sys_params.rx1_dr_offset = phy_params.default_rx1_dr_offset;
|
||||
|
||||
params->sys_params.rx2_channel.frequency = get_default_rx2_frequency();
|
||||
|
||||
params->sys_params.rx2_channel.datarate = get_default_rx2_datarate();
|
||||
|
||||
params->sys_params.uplink_dwell_time = phy_params.ul_dwell_time_setting;
|
||||
|
||||
params->sys_params.max_eirp = phy_params.default_max_eirp;
|
||||
|
||||
params->sys_params.antenna_gain = phy_params.default_antenna_gain;
|
||||
}
|
||||
|
||||
int8_t LoRaPHY::get_next_lower_tx_datarate(int8_t datarate)
|
||||
{
|
||||
if (phy_params.ul_dwell_time_setting == 0) {
|
||||
return get_next_lower_dr(datarate, phy_params.min_tx_datarate);
|
||||
}
|
||||
|
||||
return get_next_lower_dr(
|
||||
datarate, phy_params.dwell_limit_datarate);
|
||||
return get_next_lower_dr(datarate, phy_params.dwell_limit_datarate);
|
||||
|
||||
}
|
||||
|
||||
|
@ -540,36 +574,6 @@ uint8_t LoRaPHY::get_max_payload(uint8_t datarate, bool use_repeater)
|
|||
return payload_table[datarate];
|
||||
}
|
||||
|
||||
bool LoRaPHY::duty_cycle_enabled()
|
||||
{
|
||||
return phy_params.duty_cycle_enabled;
|
||||
}
|
||||
|
||||
uint16_t LoRaPHY::get_maximum_receive_window_duration()
|
||||
{
|
||||
return phy_params.max_rx_window;
|
||||
}
|
||||
|
||||
uint16_t LoRaPHY::get_window1_receive_delay()
|
||||
{
|
||||
return phy_params.recv_delay1;
|
||||
}
|
||||
|
||||
uint16_t LoRaPHY::get_window2_receive_delay()
|
||||
{
|
||||
return phy_params.recv_delay2;
|
||||
}
|
||||
|
||||
uint16_t LoRaPHY::get_window1_join_accept_delay()
|
||||
{
|
||||
return phy_params.join_accept_delay1;
|
||||
}
|
||||
|
||||
uint16_t LoRaPHY::get_window2_join_accept_delay()
|
||||
{
|
||||
return phy_params.join_accept_delay2;
|
||||
}
|
||||
|
||||
uint16_t LoRaPHY::get_maximum_frame_counter_gap()
|
||||
{
|
||||
return phy_params.max_fcnt_gap;
|
||||
|
@ -582,11 +586,6 @@ uint32_t LoRaPHY::get_ack_timeout()
|
|||
+ get_random(-ack_timeout_rnd, ack_timeout_rnd));
|
||||
}
|
||||
|
||||
uint8_t LoRaPHY::get_default_datarate1_offset()
|
||||
{
|
||||
return phy_params.default_rx1_dr_offset;
|
||||
}
|
||||
|
||||
uint32_t LoRaPHY::get_default_rx2_frequency()
|
||||
{
|
||||
return phy_params.rx_window2_frequency;
|
||||
|
@ -620,32 +619,6 @@ bool LoRaPHY::is_custom_channel_plan_supported()
|
|||
return phy_params.custom_channelplans_supported;
|
||||
}
|
||||
|
||||
uint8_t LoRaPHY::get_default_uplink_dwell_time()
|
||||
{
|
||||
return phy_params.ul_dwell_time_setting;
|
||||
}
|
||||
|
||||
uint8_t LoRaPHY::get_default_downlink_dwell_time()
|
||||
{
|
||||
return phy_params.dl_dwell_time_setting;
|
||||
}
|
||||
|
||||
float LoRaPHY::get_default_max_eirp()
|
||||
{
|
||||
return phy_params.default_max_eirp;
|
||||
}
|
||||
|
||||
float LoRaPHY::get_default_antenna_gain()
|
||||
{
|
||||
return phy_params.default_antenna_gain;
|
||||
}
|
||||
|
||||
uint8_t LoRaPHY::get_nb_join_trials(bool get_default)
|
||||
{
|
||||
(void)get_default;
|
||||
return MBED_CONF_LORA_NB_TRIALS;
|
||||
}
|
||||
|
||||
void LoRaPHY::restore_default_channels()
|
||||
{
|
||||
// Restore channels default mask
|
||||
|
|
|
@ -377,69 +377,138 @@ public:
|
|||
*/
|
||||
virtual uint8_t apply_DR_offset(int8_t dr, int8_t dr_offset);
|
||||
|
||||
public: //Getters
|
||||
uint32_t get_next_lower_tx_datarate(int8_t datarate);
|
||||
/**
|
||||
* @brief reset_to_default_values resets some parameters to default values
|
||||
* @param params Pointer to MAC protocol parameters which will be reset
|
||||
* @param init If true, most of the values will be modified
|
||||
*/
|
||||
void reset_to_default_values(loramac_protocol_params *params, bool init = false);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief get_next_lower_tx_datarate Gets the next lower datarate
|
||||
* @param datarate Current TX datarate
|
||||
* @return Lower datarate than given one or minimum if lower cannot be found anymore
|
||||
*/
|
||||
int8_t get_next_lower_tx_datarate(int8_t datarate);
|
||||
|
||||
/**
|
||||
* @brief get_minimum_rx_datarate Gets the minimum RX datarate supported by a device
|
||||
* @return Minimum RX datarate
|
||||
*/
|
||||
uint8_t get_minimum_rx_datarate();
|
||||
|
||||
/**
|
||||
* @brief get_minimum_tx_datarate Gets the minimum TX datarate supported by a device
|
||||
* @return Minimum TX datarate
|
||||
*/
|
||||
uint8_t get_minimum_tx_datarate();
|
||||
|
||||
/**
|
||||
* @brief get_default_tx_datarate Gets the default TX datarate
|
||||
* @return default TX datarate
|
||||
*/
|
||||
uint8_t get_default_tx_datarate();
|
||||
|
||||
/**
|
||||
* @brief get_default_tx_power Gets the default TX power
|
||||
* @return Default TX power
|
||||
*/
|
||||
uint8_t get_default_tx_power();
|
||||
|
||||
/**
|
||||
* @brief get_max_payload Gets maximum amount in bytes which device can send
|
||||
* @param datarate A datarate to use
|
||||
* @param use_repeater If true repeater table is used, otherwise payloads table is used
|
||||
* @return Maximum number of bytes for payload
|
||||
*/
|
||||
uint8_t get_max_payload(uint8_t datarate, bool use_repeater = false);
|
||||
|
||||
bool duty_cycle_enabled();
|
||||
|
||||
uint16_t get_maximum_receive_window_duration();
|
||||
|
||||
uint16_t get_window1_receive_delay();
|
||||
|
||||
uint16_t get_window2_receive_delay();
|
||||
|
||||
uint16_t get_window1_join_accept_delay();
|
||||
|
||||
uint16_t get_window2_join_accept_delay();
|
||||
|
||||
/**
|
||||
* @brief get_maximum_frame_counter_gap Gets maximum frame counter gap
|
||||
* @return Maximum frame counter gap
|
||||
*/
|
||||
uint16_t get_maximum_frame_counter_gap();
|
||||
|
||||
/**
|
||||
* @brief get_ack_timeout Gets timeout value for ACK to be received
|
||||
* @return ACK timeout
|
||||
*/
|
||||
uint32_t get_ack_timeout();
|
||||
|
||||
uint8_t get_default_datarate1_offset();
|
||||
|
||||
/**
|
||||
* @brief get_default_rx2_frequency Gets default RX2 frequency
|
||||
* @return RX2 frequency
|
||||
*/
|
||||
uint32_t get_default_rx2_frequency();
|
||||
|
||||
/**
|
||||
* @brief get_default_rx2_datarate Gets default RX2 datarate
|
||||
* @return RX2 datarate
|
||||
*/
|
||||
uint8_t get_default_rx2_datarate();
|
||||
|
||||
/**
|
||||
* @brief get_channel_mask Gets the channel mask
|
||||
* @param get_default If true the default mask is returned, otherwise the current mask is returned
|
||||
* @return A channel mask
|
||||
*/
|
||||
uint16_t* get_channel_mask(bool get_default = false);
|
||||
|
||||
/**
|
||||
* @brief get_max_nb_channels Gets maximum number of channels supported
|
||||
* @return Number of channels
|
||||
*/
|
||||
uint8_t get_max_nb_channels();
|
||||
|
||||
/**
|
||||
* @brief get_phy_channels Gets PHY channels
|
||||
* @return PHY channels
|
||||
*/
|
||||
channel_params_t* get_phy_channels();
|
||||
|
||||
/**
|
||||
* @brief is_custom_channel_plan_supported Checks if custom channel plan is supported
|
||||
* @return True if custom channel plan is supported, false otherwise
|
||||
*/
|
||||
bool is_custom_channel_plan_supported();
|
||||
|
||||
uint8_t get_default_uplink_dwell_time();
|
||||
|
||||
uint8_t get_default_downlink_dwell_time();
|
||||
|
||||
float get_default_max_eirp();
|
||||
|
||||
float get_default_antenna_gain();
|
||||
|
||||
uint8_t get_nb_join_trials(bool get_default = false);
|
||||
|
||||
public: //Verifiers
|
||||
|
||||
/**
|
||||
* @brief verify_rx_datarate Verifies that given RX datarate is valid
|
||||
* @param datarate Datarate to check
|
||||
* @return true if given datarate is valid, false otherwise
|
||||
*/
|
||||
bool verify_rx_datarate(uint8_t datarate);
|
||||
|
||||
/**
|
||||
* @brief verify_tx_datarate Verifies that given TX datarate is valid
|
||||
* @param datarate Datarate to check
|
||||
* @param use_default If true validation is done against default value
|
||||
* @return true if given datarate is valid, false otherwise
|
||||
*/
|
||||
bool verify_tx_datarate(uint8_t datarate, bool use_default = false);
|
||||
|
||||
/**
|
||||
* @brief verify_tx_power Verifies that given TX power is valid
|
||||
* @param tx_power Power to check
|
||||
* @return True if valid, false otherwise
|
||||
*/
|
||||
bool verify_tx_power(uint8_t tx_power);
|
||||
|
||||
/**
|
||||
* @brief verify_duty_cycle Verifies that given cycle is valid
|
||||
* @param cycle Cycle to check
|
||||
* @return True if valid, false otherwise
|
||||
*/
|
||||
bool verify_duty_cycle(bool cycle);
|
||||
|
||||
/**
|
||||
* @brief verify_nb_join_trials Verifies that given number of trials is valid
|
||||
* @param nb_join_trials Number to check
|
||||
* @return True if valid, false otherwise
|
||||
*/
|
||||
bool verify_nb_join_trials(uint8_t nb_join_trials);
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Reference in New Issue