Skip to content

Commit

Permalink
Adding TOA and Channel info in RX metadata
Browse files Browse the repository at this point in the history
We provide now downlink channel frequency and time on air for the
received frame in the RX metadata.
Previously the channel information in both TX and RX metada contained
the index number of the channel. That information wasn't very useful
except the index numbers of default channels. To make more sense of the
meta data, we now store the channel frequency in the channel parameter
rather than the index number of the channel.

RX time on air is collected from the radio driver and it is assumed that
the downlink frame had 8 downlink preamble symbols (plus 4.25 of the
preambles added by the chip) for LoRa modulation.

This commit also include a bit of tidying of RX frequency storage in rx
configuration parameters storage. Previously we were missing filling in
the RX1 frequency correctly.
  • Loading branch information
Hasnain Virk committed Mar 25, 2019
1 parent b29b55a commit c4facaf
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 17 deletions.
2 changes: 2 additions & 0 deletions features/lorawan/LoRaWANStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,8 @@ void LoRaWANStack::make_rx_metadata_available(void)
_rx_metadata.rx_datarate = _loramac.get_mcps_indication()->rx_datarate;
_rx_metadata.rssi = _loramac.get_mcps_indication()->rssi;
_rx_metadata.snr = _loramac.get_mcps_indication()->snr;
_rx_metadata.channel = _loramac.get_mcps_indication()->channel;
_rx_metadata.rx_toa = _loramac.get_mcps_indication()->rx_toa;
}

bool LoRaWANStack::is_port_valid(const uint8_t port, bool allow_port_0)
Expand Down
17 changes: 17 additions & 0 deletions features/lorawan/lorastack/mac/LoRaMac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,17 @@ void LoRaMac::handle_data_frame(const uint8_t *const payload,
if (_mcps_confirmation.ack_received) {
_lora_time.stop(_params.timers.ack_timeout_timer);
}

channel_params_t *list = _lora_phy->get_phy_channels();
_mcps_indication.channel = list[_params.channel].frequency;

if (get_current_slot() == RX_SLOT_WIN_1) {
_mcps_indication.rx_toa = _lora_phy->get_rx_time_on_air(_params.rx_window1_config.modem_type,
_mcps_indication.buffer_size);
} else {
_mcps_indication.rx_toa = _lora_phy->get_rx_time_on_air(_params.rx_window2_config.modem_type,
_mcps_indication.buffer_size);
}
}

void LoRaMac::set_batterylevel_callback(mbed::Callback<uint8_t(void)> battery_level)
Expand Down Expand Up @@ -891,7 +902,13 @@ void LoRaMac::open_rx1_window(void)
_lora_time.stop(_params.timers.rx_window1_timer);
_params.rx_slot = RX_SLOT_WIN_1;

channel_params_t *active_channel_list = _lora_phy->get_phy_channels();
_params.rx_window1_config.channel = _params.channel;
_params.rx_window1_config.frequency = active_channel_list[_params.channel].frequency;
// Apply the alternative RX 1 window frequency, if it is available
if (active_channel_list[_params.channel].rx1_frequency != 0) {
_params.rx_window1_config.frequency = active_channel_list[_params.channel].rx1_frequency;
}
_params.rx_window1_config.dr_offset = _params.sys_params.rx1_dr_offset;
_params.rx_window1_config.dl_dwell_time = _params.sys_params.downlink_dwell_time;
_params.rx_window1_config.is_repeater_supported = _params.is_repeater_supported;
Expand Down
34 changes: 17 additions & 17 deletions features/lorawan/lorastack/phy/LoRaPHY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -853,22 +853,22 @@ void LoRaPHY::compute_rx_win_params(int8_t datarate, uint8_t min_rx_symbols,
rx_conf_params->datarate);
}

uint32_t LoRaPHY::get_rx_time_on_air(uint8_t modem, uint16_t pkt_len)
{
uint32_t toa = 0;

_radio->lock();
toa = _radio->time_on_air((radio_modems_t) modem, pkt_len);
_radio->unlock();

return toa;
}

bool LoRaPHY::rx_config(rx_config_params_t *rx_conf)
{
radio_modems_t modem;
uint8_t dr = rx_conf->datarate;
uint8_t max_payload = 0;
uint8_t phy_dr = 0;
uint32_t frequency = rx_conf->frequency;

if (rx_conf->rx_slot == RX_SLOT_WIN_1) {
// Apply window 1 frequency
frequency = phy_params.channels.channel_list[rx_conf->channel].frequency;
// Apply the alternative RX 1 window frequency, if it is available
if (phy_params.channels.channel_list[rx_conf->channel].rx1_frequency != 0) {
frequency = phy_params.channels.channel_list[rx_conf->channel].rx1_frequency;
}
}

// Read the physical datarate from the datarates table
uint8_t *datarate_table = (uint8_t *) phy_params.datarates.table;
Expand All @@ -879,17 +879,17 @@ bool LoRaPHY::rx_config(rx_config_params_t *rx_conf)

_radio->lock();

_radio->set_channel(frequency);
_radio->set_channel(rx_conf->frequency);

// Radio configuration
if (dr == DR_7 && phy_params.fsk_supported) {
modem = MODEM_FSK;
_radio->set_rx_config(modem, 50000, phy_dr * 1000, 0, 83333, MAX_PREAMBLE_LENGTH,
rx_conf->modem_type = MODEM_FSK;
_radio->set_rx_config((radio_modems_t) rx_conf->modem_type, 50000, phy_dr * 1000, 0, 83333, MAX_PREAMBLE_LENGTH,
rx_conf->window_timeout, false, 0, true, 0, 0,
false, rx_conf->is_rx_continuous);
} else {
modem = MODEM_LORA;
_radio->set_rx_config(modem, rx_conf->bandwidth, phy_dr, 1, 0,
rx_conf->modem_type = MODEM_LORA;
_radio->set_rx_config((radio_modems_t) rx_conf->modem_type, rx_conf->bandwidth, phy_dr, 1, 0,
MAX_PREAMBLE_LENGTH,
rx_conf->window_timeout, false, 0, false, 0, 0,
true, rx_conf->is_rx_continuous);
Expand All @@ -901,7 +901,7 @@ bool LoRaPHY::rx_config(rx_config_params_t *rx_conf)
max_payload = payload_table[dr];
}

_radio->set_max_payload_length(modem, max_payload + LORA_MAC_FRMPAYLOAD_OVERHEAD);
_radio->set_max_payload_length((radio_modems_t) rx_conf->modem_type, max_payload + LORA_MAC_FRMPAYLOAD_OVERHEAD);

_radio->unlock();

Expand Down
6 changes: 6 additions & 0 deletions features/lorawan/lorastack/phy/LoRaPHY.h
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,12 @@ class LoRaPHY : private mbed::NonCopyable<LoRaPHY> {
*/
bool is_custom_channel_plan_supported();

/**
* @brief get_rx_time_on_air(...) calculates the time the received spent on air
* @return time spent on air in milliseconds
*/
uint32_t get_rx_time_on_air(uint8_t modem, uint16_t pkt_len);

public: //Verifiers

/**
Expand Down
8 changes: 8 additions & 0 deletions features/lorawan/lorawan_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,14 @@ typedef struct {
* A boolean to mark if the meta data is stale
*/
bool stale;
/**
* Frequency for the downlink channel
*/
uint32_t channel;
/**
* Time spent on air by the RX frame
*/
uint32_t rx_toa;
} lorawan_rx_metadata;

#endif /* MBED_LORAWAN_TYPES_H_ */
12 changes: 12 additions & 0 deletions features/lorawan/system/lorawan_data_structures.h
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,14 @@ typedef struct {
* The downlink counter value for the received frame.
*/
uint32_t dl_frame_counter;
/*!
* The downlink channel
*/
uint32_t channel;
/*!
* The time on air of the received frame.
*/
lorawan_time_t rx_toa;
} loramac_mcps_indication_t;

/*!
Expand Down Expand Up @@ -986,6 +994,10 @@ typedef struct lorawan_session {
* The parameter structure for the function for regional rx configuration.
*/
typedef struct {
/*!
* Type of modulation used (LoRa or FSK)
*/
uint8_t modem_type;
/*!
* The RX channel.
*/
Expand Down

0 comments on commit c4facaf

Please sign in to comment.