Skip to content

Commit c4facaf

Browse files
author
Hasnain Virk
committed
Adding TOA and Channel info in RX metadata
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.
1 parent b29b55a commit c4facaf

File tree

6 files changed

+62
-17
lines changed

6 files changed

+62
-17
lines changed

features/lorawan/LoRaWANStack.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,8 @@ void LoRaWANStack::make_rx_metadata_available(void)
795795
_rx_metadata.rx_datarate = _loramac.get_mcps_indication()->rx_datarate;
796796
_rx_metadata.rssi = _loramac.get_mcps_indication()->rssi;
797797
_rx_metadata.snr = _loramac.get_mcps_indication()->snr;
798+
_rx_metadata.channel = _loramac.get_mcps_indication()->channel;
799+
_rx_metadata.rx_toa = _loramac.get_mcps_indication()->rx_toa;
798800
}
799801

800802
bool LoRaWANStack::is_port_valid(const uint8_t port, bool allow_port_0)

features/lorawan/lorastack/mac/LoRaMac.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,17 @@ void LoRaMac::handle_data_frame(const uint8_t *const payload,
629629
if (_mcps_confirmation.ack_received) {
630630
_lora_time.stop(_params.timers.ack_timeout_timer);
631631
}
632+
633+
channel_params_t *list = _lora_phy->get_phy_channels();
634+
_mcps_indication.channel = list[_params.channel].frequency;
635+
636+
if (get_current_slot() == RX_SLOT_WIN_1) {
637+
_mcps_indication.rx_toa = _lora_phy->get_rx_time_on_air(_params.rx_window1_config.modem_type,
638+
_mcps_indication.buffer_size);
639+
} else {
640+
_mcps_indication.rx_toa = _lora_phy->get_rx_time_on_air(_params.rx_window2_config.modem_type,
641+
_mcps_indication.buffer_size);
642+
}
632643
}
633644

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

905+
channel_params_t *active_channel_list = _lora_phy->get_phy_channels();
894906
_params.rx_window1_config.channel = _params.channel;
907+
_params.rx_window1_config.frequency = active_channel_list[_params.channel].frequency;
908+
// Apply the alternative RX 1 window frequency, if it is available
909+
if (active_channel_list[_params.channel].rx1_frequency != 0) {
910+
_params.rx_window1_config.frequency = active_channel_list[_params.channel].rx1_frequency;
911+
}
895912
_params.rx_window1_config.dr_offset = _params.sys_params.rx1_dr_offset;
896913
_params.rx_window1_config.dl_dwell_time = _params.sys_params.downlink_dwell_time;
897914
_params.rx_window1_config.is_repeater_supported = _params.is_repeater_supported;

features/lorawan/lorastack/phy/LoRaPHY.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -853,22 +853,22 @@ void LoRaPHY::compute_rx_win_params(int8_t datarate, uint8_t min_rx_symbols,
853853
rx_conf_params->datarate);
854854
}
855855

856+
uint32_t LoRaPHY::get_rx_time_on_air(uint8_t modem, uint16_t pkt_len)
857+
{
858+
uint32_t toa = 0;
859+
860+
_radio->lock();
861+
toa = _radio->time_on_air((radio_modems_t) modem, pkt_len);
862+
_radio->unlock();
863+
864+
return toa;
865+
}
866+
856867
bool LoRaPHY::rx_config(rx_config_params_t *rx_conf)
857868
{
858-
radio_modems_t modem;
859869
uint8_t dr = rx_conf->datarate;
860870
uint8_t max_payload = 0;
861871
uint8_t phy_dr = 0;
862-
uint32_t frequency = rx_conf->frequency;
863-
864-
if (rx_conf->rx_slot == RX_SLOT_WIN_1) {
865-
// Apply window 1 frequency
866-
frequency = phy_params.channels.channel_list[rx_conf->channel].frequency;
867-
// Apply the alternative RX 1 window frequency, if it is available
868-
if (phy_params.channels.channel_list[rx_conf->channel].rx1_frequency != 0) {
869-
frequency = phy_params.channels.channel_list[rx_conf->channel].rx1_frequency;
870-
}
871-
}
872872

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

880880
_radio->lock();
881881

882-
_radio->set_channel(frequency);
882+
_radio->set_channel(rx_conf->frequency);
883883

884884
// Radio configuration
885885
if (dr == DR_7 && phy_params.fsk_supported) {
886-
modem = MODEM_FSK;
887-
_radio->set_rx_config(modem, 50000, phy_dr * 1000, 0, 83333, MAX_PREAMBLE_LENGTH,
886+
rx_conf->modem_type = MODEM_FSK;
887+
_radio->set_rx_config((radio_modems_t) rx_conf->modem_type, 50000, phy_dr * 1000, 0, 83333, MAX_PREAMBLE_LENGTH,
888888
rx_conf->window_timeout, false, 0, true, 0, 0,
889889
false, rx_conf->is_rx_continuous);
890890
} else {
891-
modem = MODEM_LORA;
892-
_radio->set_rx_config(modem, rx_conf->bandwidth, phy_dr, 1, 0,
891+
rx_conf->modem_type = MODEM_LORA;
892+
_radio->set_rx_config((radio_modems_t) rx_conf->modem_type, rx_conf->bandwidth, phy_dr, 1, 0,
893893
MAX_PREAMBLE_LENGTH,
894894
rx_conf->window_timeout, false, 0, false, 0, 0,
895895
true, rx_conf->is_rx_continuous);
@@ -901,7 +901,7 @@ bool LoRaPHY::rx_config(rx_config_params_t *rx_conf)
901901
max_payload = payload_table[dr];
902902
}
903903

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

906906
_radio->unlock();
907907

features/lorawan/lorastack/phy/LoRaPHY.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,12 @@ class LoRaPHY : private mbed::NonCopyable<LoRaPHY> {
520520
*/
521521
bool is_custom_channel_plan_supported();
522522

523+
/**
524+
* @brief get_rx_time_on_air(...) calculates the time the received spent on air
525+
* @return time spent on air in milliseconds
526+
*/
527+
uint32_t get_rx_time_on_air(uint8_t modem, uint16_t pkt_len);
528+
523529
public: //Verifiers
524530

525531
/**

features/lorawan/lorawan_types.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,14 @@ typedef struct {
666666
* A boolean to mark if the meta data is stale
667667
*/
668668
bool stale;
669+
/**
670+
* Frequency for the downlink channel
671+
*/
672+
uint32_t channel;
673+
/**
674+
* Time spent on air by the RX frame
675+
*/
676+
uint32_t rx_toa;
669677
} lorawan_rx_metadata;
670678

671679
#endif /* MBED_LORAWAN_TYPES_H_ */

features/lorawan/system/lorawan_data_structures.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,14 @@ typedef struct {
681681
* The downlink counter value for the received frame.
682682
*/
683683
uint32_t dl_frame_counter;
684+
/*!
685+
* The downlink channel
686+
*/
687+
uint32_t channel;
688+
/*!
689+
* The time on air of the received frame.
690+
*/
691+
lorawan_time_t rx_toa;
684692
} loramac_mcps_indication_t;
685693

686694
/*!
@@ -986,6 +994,10 @@ typedef struct lorawan_session {
986994
* The parameter structure for the function for regional rx configuration.
987995
*/
988996
typedef struct {
997+
/*!
998+
* Type of modulation used (LoRa or FSK)
999+
*/
1000+
uint8_t modem_type;
9891001
/*!
9901002
* The RX channel.
9911003
*/

0 commit comments

Comments
 (0)