Skip to content

Commit c0895cb

Browse files
author
Cruz Monrreal
authored
Merge pull request #6910 from hasnainvirk/metadata
LoRaWAN: Adding acquisition of metadata, backoff and a cancel_send() API
2 parents 5371c10 + 9973eb3 commit c0895cb

File tree

9 files changed

+565
-121
lines changed

9 files changed

+565
-121
lines changed

features/lorawan/LoRaWANBase.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,71 @@ 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;
356+
357+
/** Get hold of RX meta-data
358+
*
359+
* Use this method to acquire any RX meta-data related to current
360+
* reception.
361+
* RX meta-data is only available right after the reception is completed.
362+
* In other words, you can check for RX meta-data right after receiving the
363+
* RX_DONE event.
364+
*
365+
* @param metadata the inbound structure that will be filled if the meta-data
366+
* is available.
367+
*
368+
* @return LORAWAN_STATUS_OK if the meta-data is available, otherwise
369+
* LORAWAN_STATUS_METADATA_NOT_AVAILABLE is returned.
370+
*/
371+
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;
392+
393+
/** Cancel outgoing transmission
394+
*
395+
* This API is used to cancel any outstanding transmission in the TX pipe.
396+
* If an event for transmission is not already queued at the end of backoff timer,
397+
* the system can cancel the outstanding outgoing packet. Otherwise, the system is
398+
* busy sending and can't be held back.
399+
*
400+
* @return LORAWAN_STATUS_OK if the sending is cancelled.
401+
* LORAWAN_STATUS_BUSY otherwise.
402+
*
403+
*/
404+
virtual lorawan_status_t cancel_sending(void) = 0;
340405
};
341406

342407
#endif /* LORAWAN_BASE_H_ */

features/lorawan/LoRaWANInterface.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,30 @@ 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::cancel_sending(void)
126+
{
127+
Lock lock(*this);
128+
return _lw_stack.stop_sending();
129+
}
130+
131+
lorawan_status_t LoRaWANInterface::get_tx_metadata(lorawan_tx_metadata &metadata)
132+
{
133+
Lock lock(*this);
134+
return _lw_stack.acquire_tx_metadata(metadata);
135+
}
136+
137+
lorawan_status_t LoRaWANInterface::get_rx_metadata(lorawan_rx_metadata &metadata)
138+
{
139+
Lock lock(*this);
140+
return _lw_stack.acquire_rx_metadata(metadata);
141+
}
142+
143+
lorawan_status_t LoRaWANInterface::get_backoff_metadata(int &backoff)
144+
{
145+
Lock lock(*this);
146+
return _lw_stack.acquire_backoff_metadata(backoff);
147+
}
148+
125149
int16_t LoRaWANInterface::receive(uint8_t port, uint8_t* data, uint16_t length, int flags)
126150
{
127151
Lock lock(*this);

features/lorawan/LoRaWANInterface.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,72 @@ 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+
455+
/** Get hold of RX meta-data
456+
*
457+
* Use this method to acquire any RX meta-data related to current
458+
* reception.
459+
* RX meta-data is only available right after the reception is completed.
460+
* In other words, you can check for RX meta-data right after receiving the
461+
* RX_DONE event.
462+
*
463+
* @param metadata the inbound structure that will be filled if the meta-data
464+
* is available.
465+
*
466+
* @return LORAWAN_STATUS_OK if the meta-data is available, otherwise
467+
* LORAWAN_STATUS_METADATA_NOT_AVAILABLE is returned.
468+
*/
469+
virtual lorawan_status_t get_rx_metadata(lorawan_rx_metadata &metadata);
470+
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+
491+
/** Cancel outgoing transmission
492+
*
493+
* This API is used to cancel any outstanding transmission in the TX pipe.
494+
* If an event for transmission is not already queued at the end of backoff timer,
495+
* the system can cancel the outstanding outgoing packet. Otherwise, the system is
496+
* busy sending and can't be held back. The system will not try to re-send if the
497+
* outgoing message was a CONFIRMED message even if the ack is not received.
498+
*
499+
* @return LORAWAN_STATUS_OK if the sending is cancelled.
500+
* LORAWAN_STATUS_BUSY otherwise.
501+
*
502+
*/
503+
virtual lorawan_status_t cancel_sending(void);
504+
439505
void lock(void) { _lw_stack.lock(); }
440506
void unlock(void) { _lw_stack.unlock(); }
441507

0 commit comments

Comments
 (0)