Skip to content

LoRaWAN: Adding TOA and Channel info in RX metadata #10214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions UNITTESTS/features/lorawan/loramac/Test_LoRaMac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ TEST_F(Test_LoRaMac, initialize)
conn.connection_u.otaa.nb_trials = 2;
object->prepare_join(&conn, true);

channel_params_t params[] = {868300000, 0, { ((DR_5 << 4) | DR_0) }, 1};
LoRaPHY_stub::channel_params_ptr = params;

LoRaWANTimer_stub::call_cb_immediately = true;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize(NULL, my_cb));
}
Expand Down
4 changes: 4 additions & 0 deletions UNITTESTS/stubs/LoRaPHY_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,4 +416,8 @@ uint8_t LoRaPHY::apply_DR_offset(int8_t dr, int8_t dr_offset)
return LoRaPHY_stub::uint8_value;
}

uint32_t LoRaPHY::get_rx_time_on_air(uint8_t modem, uint16_t pkt_len)
{
return LoRaPHY_stub::uint32_value;
}

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 @@ -626,6 +626,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 @@ -889,7 +900,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 @@ -855,22 +855,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 @@ -881,17 +881,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 @@ -903,7 +903,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