Skip to content

Commit 8fd791d

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 7e7f4f5 commit 8fd791d

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
@@ -626,6 +626,17 @@ void LoRaMac::handle_data_frame(const uint8_t *const payload,
626626
if (_mcps_confirmation.ack_received) {
627627
_lora_time.stop(_params.timers.ack_timeout_timer);
628628
}
629+
630+
channel_params_t *list = _lora_phy->get_phy_channels();
631+
_mcps_indication.channel = list[_params.channel].frequency;
632+
633+
if (get_current_slot() == RX_SLOT_WIN_1) {
634+
_mcps_indication.rx_toa = _lora_phy->get_rx_time_on_air(_params.rx_window1_config.modem_type,
635+
_mcps_indication.buffer_size);
636+
} else {
637+
_mcps_indication.rx_toa = _lora_phy->get_rx_time_on_air(_params.rx_window2_config.modem_type,
638+
_mcps_indication.buffer_size);
639+
}
629640
}
630641

631642
void LoRaMac::set_batterylevel_callback(mbed::Callback<uint8_t(void)> battery_level)
@@ -889,7 +900,13 @@ void LoRaMac::open_rx1_window(void)
889900
_lora_time.stop(_params.timers.rx_window1_timer);
890901
_params.rx_slot = RX_SLOT_WIN_1;
891902

903+
channel_params_t *active_channel_list = _lora_phy->get_phy_channels();
892904
_params.rx_window1_config.channel = _params.channel;
905+
_params.rx_window1_config.frequency = active_channel_list[_params.channel].frequency;
906+
// Apply the alternative RX 1 window frequency, if it is available
907+
if (active_channel_list[_params.channel].rx1_frequency != 0) {
908+
_params.rx_window1_config.frequency = active_channel_list[_params.channel].rx1_frequency;
909+
}
893910
_params.rx_window1_config.dr_offset = _params.sys_params.rx1_dr_offset;
894911
_params.rx_window1_config.dl_dwell_time = _params.sys_params.downlink_dwell_time;
895912
_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
@@ -855,22 +855,22 @@ void LoRaPHY::compute_rx_win_params(int8_t datarate, uint8_t min_rx_symbols,
855855
rx_conf_params->datarate);
856856
}
857857

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

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

882882
_radio->lock();
883883

884-
_radio->set_channel(frequency);
884+
_radio->set_channel(rx_conf->frequency);
885885

886886
// Radio configuration
887887
if (dr == DR_7 && phy_params.fsk_supported) {
888-
modem = MODEM_FSK;
889-
_radio->set_rx_config(modem, 50000, phy_dr * 1000, 0, 83333, MAX_PREAMBLE_LENGTH,
888+
rx_conf->modem_type = MODEM_FSK;
889+
_radio->set_rx_config((radio_modems_t) rx_conf->modem_type, 50000, phy_dr * 1000, 0, 83333, MAX_PREAMBLE_LENGTH,
890890
rx_conf->window_timeout, false, 0, true, 0, 0,
891891
false, rx_conf->is_rx_continuous);
892892
} else {
893-
modem = MODEM_LORA;
894-
_radio->set_rx_config(modem, rx_conf->bandwidth, phy_dr, 1, 0,
893+
rx_conf->modem_type = MODEM_LORA;
894+
_radio->set_rx_config((radio_modems_t) rx_conf->modem_type, rx_conf->bandwidth, phy_dr, 1, 0,
895895
MAX_PREAMBLE_LENGTH,
896896
rx_conf->window_timeout, false, 0, false, 0, 0,
897897
true, rx_conf->is_rx_continuous);
@@ -903,7 +903,7 @@ bool LoRaPHY::rx_config(rx_config_params_t *rx_conf)
903903
max_payload = payload_table[dr];
904904
}
905905

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

908908
_radio->unlock();
909909

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)