Skip to content

Commit 555d945

Browse files
author
Hasnain Virk
committed
Adding acquisition of TX Meta-data
An API is added to fetch any meta-data available after a succesful transmission. The stack will make the meta data available after the TX interrupt is processed. User can get the tx meta data after receiving TX_DONE event.
1 parent 1863400 commit 555d945

File tree

6 files changed

+135
-0
lines changed

6 files changed

+135
-0
lines changed

features/lorawan/LoRaWANBase.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,22 @@ class LoRaWANBase {
337337
* or other negative error code if request failed.
338338
*/
339339
virtual lorawan_status_t set_device_class(device_class_t device_class) = 0;
340+
341+
/** Get hold of TX meta-data
342+
*
343+
* Use this method to acquire any TX meta-data related to previous
344+
* transmission.
345+
* TX meta-data is only available right after the transmission is completed.
346+
* In other words, you can check for TX meta-data right after receiving the
347+
* TX_DONE event.
348+
*
349+
* @param metadata the inbound structure that will be filled if the meta-data
350+
* is available.
351+
*
352+
* @return LORAWAN_STATUS_OK if the meta-data is available, otherwise
353+
* LORAWAN_STATUS_METADATA_NOT_AVAILABLE is returned.
354+
*/
355+
virtual lorawan_status_t get_tx_metadata(lorawan_tx_metadata& metadata) = 0;
340356
};
341357

342358
#endif /* LORAWAN_BASE_H_ */

features/lorawan/LoRaWANInterface.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ int16_t LoRaWANInterface::send(uint8_t port, const uint8_t* data, uint16_t lengt
122122
return _lw_stack.handle_tx(port, data, length, flags);
123123
}
124124

125+
lorawan_status_t LoRaWANInterface::get_tx_metadata(lorawan_tx_metadata& metadata)
126+
{
127+
Lock lock(*this);
128+
return _lw_stack.acquire_tx_metadata(metadata);
129+
}
130+
125131
int16_t LoRaWANInterface::receive(uint8_t port, uint8_t* data, uint16_t length, int flags)
126132
{
127133
Lock lock(*this);

features/lorawan/LoRaWANInterface.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,22 @@ class LoRaWANInterface: public LoRaWANBase {
436436
*/
437437
virtual lorawan_status_t set_device_class(const device_class_t device_class);
438438

439+
/** Get hold of TX meta-data
440+
*
441+
* Use this method to acquire any TX meta-data related to previous
442+
* transmission.
443+
* TX meta-data is only available right after the transmission is completed.
444+
* In other words, you can check for TX meta-data right after receiving the
445+
* TX_DONE event.
446+
*
447+
* @param metadata the inbound structure that will be filled if the meta-data
448+
* is available.
449+
*
450+
* @return LORAWAN_STATUS_OK if the meta-data is available, otherwise
451+
* LORAWAN_STATUS_METADATA_NOT_AVAILABLE is returned.
452+
*/
453+
virtual lorawan_status_t get_tx_metadata(lorawan_tx_metadata& metadata);
454+
439455
void lock(void) { _lw_stack.lock(); }
440456
void unlock(void) { _lw_stack.unlock(); }
441457

features/lorawan/LoRaWANStack.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ LoRaWANStack::LoRaWANStack()
7373
_lw_session(),
7474
_tx_msg(),
7575
_rx_msg(),
76+
_tx_metadata(),
7677
_num_retry(1),
7778
_ctrl_flags(IDLE_FLAG),
7879
_app_port(INVALID_PORT),
@@ -81,6 +82,8 @@ LoRaWANStack::LoRaWANStack()
8182
_ready_for_rx(true),
8283
_queue(NULL)
8384
{
85+
_tx_metadata.stale = true;
86+
8487
#ifdef MBED_CONF_LORA_APP_PORT
8588
if (is_port_valid(MBED_CONF_LORA_APP_PORT)) {
8689
_app_port = MBED_CONF_LORA_APP_PORT;
@@ -419,6 +422,17 @@ lorawan_status_t LoRaWANStack::set_device_class(const device_class_t& device_cla
419422
return LORAWAN_STATUS_OK;
420423
}
421424

425+
lorawan_status_t LoRaWANStack::acquire_tx_metadata(lorawan_tx_metadata& tx_metadata)
426+
{
427+
if (!_tx_metadata.stale) {
428+
tx_metadata = _tx_metadata;
429+
_tx_metadata.stale = true;
430+
return LORAWAN_STATUS_OK;
431+
}
432+
433+
return LORAWAN_STATUS_METADATA_NOT_AVAILABLE;
434+
}
435+
422436
/*****************************************************************************
423437
* Interrupt handlers *
424438
****************************************************************************/
@@ -488,6 +502,8 @@ void LoRaWANStack::process_transmission(void)
488502
_loramac.on_radio_tx_done();
489503
tr_debug("Transmission completed");
490504

505+
make_tx_metadata_available();
506+
491507
if (_device_current_state == DEVICE_STATE_JOINING) {
492508
_device_current_state = DEVICE_STATE_AWAITING_JOIN_ACCEPT;
493509
}
@@ -609,6 +625,16 @@ void LoRaWANStack::process_reception_timeout(bool is_timeout)
609625
/*****************************************************************************
610626
* Private methods *
611627
****************************************************************************/
628+
void LoRaWANStack::make_tx_metadata_available(void)
629+
{
630+
_tx_metadata.stale = false;
631+
_tx_metadata.channel = _loramac.get_mcps_confirmation()->channel;
632+
_tx_metadata.data_rate = _loramac.get_mcps_confirmation()->data_rate;
633+
_tx_metadata.tx_power = _loramac.get_mcps_confirmation()->tx_power;
634+
_tx_metadata.tx_toa = _loramac.get_mcps_confirmation()->tx_toa;
635+
_tx_metadata.nb_retries = _loramac.get_mcps_confirmation()->nb_retries;
636+
}
637+
612638
bool LoRaWANStack::is_port_valid(const uint8_t port, bool allow_port_0)
613639
{
614640
//Application should not use reserved and illegal port numbers.

features/lorawan/LoRaWANStack.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,18 @@ class LoRaWANStack: private mbed::NonCopyable<LoRaWANStack> {
379379
*/
380380
lorawan_status_t set_device_class(const device_class_t& device_class);
381381

382+
/** Acquire TX meta-data
383+
*
384+
* Upon successful transmission, TX meta-data will be made available
385+
*
386+
* @param metadata A reference to the inbound structure which will be
387+
* filled with any TX meta-data if available.
388+
*
389+
* @return LORAWAN_STATUS_OK if successful,
390+
* LORAWAN_STATUS_METADATA_NOT_AVAILABLE otherwise
391+
*/
392+
lorawan_status_t acquire_tx_metadata(lorawan_tx_metadata& metadata);
393+
382394
void lock(void) { _loramac.lock(); }
383395
void unlock(void) { _loramac.unlock(); }
384396

@@ -473,6 +485,8 @@ class LoRaWANStack: private mbed::NonCopyable<LoRaWANStack> {
473485

474486
int convert_to_msg_flag(const mcps_type_t type);
475487

488+
void make_tx_metadata_available(void);
489+
476490
private:
477491
LoRaMac _loramac;
478492
radio_events_t radio_events;
@@ -481,6 +495,7 @@ class LoRaWANStack: private mbed::NonCopyable<LoRaWANStack> {
481495
lorawan_session_t _lw_session;
482496
loramac_tx_message_t _tx_msg;
483497
loramac_rx_message_t _rx_msg;
498+
lorawan_tx_metadata _tx_metadata;
484499
uint8_t _num_retry;
485500
uint32_t _ctrl_flags;
486501
uint8_t _app_port;

features/lorawan/lorawan_types.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ typedef enum lorawan_status {
101101
LORAWAN_STATUS_DUTYCYCLE_RESTRICTED = -1020,
102102
LORAWAN_STATUS_NO_CHANNEL_FOUND = -1021,
103103
LORAWAN_STATUS_NO_FREE_CHANNEL_FOUND = -1022,
104+
LORAWAN_STATUS_METADATA_NOT_AVAILABLE = -1023
104105
} lorawan_status_t;
105106

106107
/** The lorawan_connect_otaa structure.
@@ -344,4 +345,59 @@ typedef struct lora_channelplan {
344345
loramac_channel_t *channels;
345346
} lorawan_channelplan_t;
346347

348+
/**
349+
* Meta-data collection for a transmission
350+
*/
351+
typedef struct {
352+
/**
353+
* A boolean to mark if the meta data is stale
354+
*/
355+
bool stale;
356+
/**
357+
* The uplink channel used for transmission.
358+
*/
359+
uint32_t channel;
360+
/**
361+
* The uplink datarate.
362+
*/
363+
uint8_t data_rate;
364+
/**
365+
* The transmission power.
366+
*/
367+
int8_t tx_power;
368+
/**
369+
* Provides the number of retransmissions.
370+
*/
371+
uint8_t nb_retries;
372+
/**
373+
* The transmission time on air of the frame.
374+
*/
375+
uint32_t tx_toa;
376+
} lorawan_tx_metadata;
377+
378+
* Meta-data collection for the received packet
379+
*/
380+
typedef struct {
381+
/**
382+
* A boolean to mark if the meta data is stale
383+
*/
384+
bool stale;
385+
/**
386+
* Data rate of reception
387+
*/
388+
uint8_t rx_datarate;
389+
/**
390+
* Frame pending status.
391+
*/
392+
uint8_t fpending_status;
393+
/**
394+
* The RSSI for the received packet.
395+
*/
396+
int16_t rssi;
397+
/**
398+
* The SNR for the received packet.
399+
*/
400+
uint8_t snr;
401+
} lorawan_rx_metadata;
402+
347403
#endif /* MBED_LORAWAN_TYPES_H_ */

0 commit comments

Comments
 (0)