Skip to content

Commit 8363311

Browse files
author
Hasnain Virk
committed
Adding acquisition of backoff time value
This API enables the application to get hold of remaining time after which the transmission will take place. User can query the backoff time whenever there is a packet in the TX pipe. If the event for the backoff expiry is already queued, the stack does not provide backoff metadata.
1 parent 387f56c commit 8363311

File tree

7 files changed

+81
-0
lines changed

7 files changed

+81
-0
lines changed

features/lorawan/LoRaWANBase.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,26 @@ class LoRaWANBase {
369369
* LORAWAN_STATUS_METADATA_NOT_AVAILABLE is returned.
370370
*/
371371
virtual lorawan_status_t get_rx_metadata(lorawan_rx_metadata& metadata) = 0;
372+
373+
/** Get hold of backoff time
374+
*
375+
* In the TX path, because of automatic duty cycling, the transmission is delayed
376+
* by a certain amount of time which is the backoff time. While the system schedules
377+
* application data to be sent, the application can inquire about how much time is
378+
* left in the actual transmission to happen.
379+
*
380+
* The system will provide you with a backoff time only if the application data is
381+
* in the TX pipe. If however, the event is already queued for the transmission, this
382+
* API returns a LORAWAN_STATUS_METADATA_NOT_AVAILABLE error code.
383+
*
384+
* @param backoff the inbound integer that will be carry the backoff time if it
385+
* is available.
386+
*
387+
* @return LORAWAN_STATUS_OK if the meta-data regarding backoff is available,
388+
* otherwise LORAWAN_STATUS_METADATA_NOT_AVAILABLE is returned.
389+
*
390+
*/
391+
virtual lorawan_status_t get_backoff_metadata(int& backoff) = 0;
372392
};
373393

374394
#endif /* LORAWAN_BASE_H_ */

features/lorawan/LoRaWANInterface.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ lorawan_status_t LoRaWANInterface::get_rx_metadata(lorawan_rx_metadata& metadata
134134
return _lw_stack.acquire_rx_metadata(metadata);
135135
}
136136

137+
lorawan_status_t LoRaWANInterface::get_backoff_metadata(int& backoff)
138+
{
139+
Lock lock(*this);
140+
return _lw_stack.acquire_backoff_metadata(backoff);
141+
}
142+
137143
int16_t LoRaWANInterface::receive(uint8_t port, uint8_t* data, uint16_t length, int flags)
138144
{
139145
Lock lock(*this);

features/lorawan/LoRaWANInterface.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,26 @@ class LoRaWANInterface: public LoRaWANBase {
468468
*/
469469
virtual lorawan_status_t get_rx_metadata(lorawan_rx_metadata& metadata);
470470

471+
/** Get hold of backoff time
472+
*
473+
* In the TX path, because of automatic duty cycling, the transmission is delayed
474+
* by a certain amount of time which is the backoff time. While the system schedules
475+
* application data to be sent, the application can inquire about how much time is
476+
* left in the actual transmission to happen.
477+
*
478+
* The system will provide you with a backoff time only if the application data is
479+
* in the TX pipe. If however, the event is already queued for the transmission, this
480+
* API returns a LORAWAN_STATUS_METADATA_NOT_AVAILABLE error code.
481+
*
482+
* @param backoff the inbound integer that will be carry the backoff time if it
483+
* is available.
484+
*
485+
* @return LORAWAN_STATUS_OK if the meta-data regarding backoff is available,
486+
* otherwise LORAWAN_STATUS_METADATA_NOT_AVAILABLE is returned.
487+
*
488+
*/
489+
virtual lorawan_status_t get_backoff_metadata(int& backoff);
490+
471491
void lock(void) { _lw_stack.lock(); }
472492
void unlock(void) { _lw_stack.unlock(); }
473493

features/lorawan/LoRaWANStack.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,19 @@ lorawan_status_t LoRaWANStack::acquire_rx_metadata(lorawan_rx_metadata& metadata
446446
return LORAWAN_STATUS_METADATA_NOT_AVAILABLE;
447447
}
448448

449+
lorawan_status_t LoRaWANStack::acquire_backoff_metadata(int& backoff)
450+
{
451+
int id = _loramac.get_backoff_timer_event_id();
452+
453+
if (_loramac.get_backoff_timer_event_id() > 0) {
454+
backoff = _queue->time_left(id);
455+
return LORAWAN_STATUS_OK;
456+
}
457+
458+
backoff = -1;
459+
return LORAWAN_STATUS_METADATA_NOT_AVAILABLE;
460+
}
461+
449462
/*****************************************************************************
450463
* Interrupt handlers *
451464
****************************************************************************/

features/lorawan/LoRaWANStack.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,18 @@ class LoRaWANStack: private mbed::NonCopyable<LoRaWANStack> {
403403
*/
404404
lorawan_status_t acquire_rx_metadata(lorawan_rx_metadata& metadata);
405405

406+
/** Acquire backoff meta-data
407+
*
408+
* Get hold of backoff time after which the transmission will take place.
409+
*
410+
* @param backoff A reference to the inbound integer which will be
411+
* filled with any backoff meta-data if available.
412+
*
413+
* @return LORAWAN_STATUS_OK if successful,
414+
* LORAWAN_STATUS_METADATA_NOT_AVAILABLE otherwise
415+
*/
416+
lorawan_status_t acquire_backoff_metadata(int& backoff);
417+
406418
void lock(void) { _loramac.lock(); }
407419
void unlock(void) { _loramac.unlock(); }
408420

features/lorawan/lorastack/mac/LoRaMac.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,11 @@ lorawan_status_t LoRaMac::send(loramac_mhdr_t *machdr, const uint8_t fport,
10081008
return status;
10091009
}
10101010

1011+
int LoRaMac::get_backoff_timer_event_id(void)
1012+
{
1013+
return _params.timers.backoff_timer.timer_id;
1014+
}
1015+
10111016
lorawan_status_t LoRaMac::schedule_tx()
10121017
{
10131018
channel_selection_params_t next_channel;

features/lorawan/lorastack/mac/LoRaMac.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,11 @@ class LoRaMac {
442442
*/
443443
void set_batterylevel_callback(mbed::Callback<uint8_t(void)> battery_level);
444444

445+
/**
446+
* Returns the event ID of backoff timer.
447+
*/
448+
int get_backoff_timer_event_id(void);
449+
445450
/**
446451
* These locks trample through to the upper layers and make
447452
* the stack thread safe.

0 commit comments

Comments
 (0)