From b2a7a1fd9ddfa53f377b4eb6a6702e5c8dec052e Mon Sep 17 00:00:00 2001 From: Jason Reiss Date: Thu, 9 Apr 2020 13:35:04 -0500 Subject: add time-on-air check before transmitting --- VERSION | 2 +- lora_pkt_fwd/src/lora_pkt_fwd.c | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index b33ec60..8f9b697 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.0.1-mts-2 +4.0.1-mts-4 diff --git a/lora_pkt_fwd/src/lora_pkt_fwd.c b/lora_pkt_fwd/src/lora_pkt_fwd.c index 5aae335..5b2da71 100644 --- a/lora_pkt_fwd/src/lora_pkt_fwd.c +++ b/lora_pkt_fwd/src/lora_pkt_fwd.c @@ -3098,6 +3098,7 @@ void thread_jit(void) { enum jit_error_e jit_result; enum jit_pkt_type_e pkt_type; uint8_t tx_status; + uint32_t time_on_air = 0; while (!exit_sig && !quit_sig) { wait_ms(10); @@ -3124,6 +3125,17 @@ void thread_jit(void) { pthread_mutex_unlock(&mx_meas_dw); MSG("INFO: Beacon dequeued (count_us=%u)\n", pkt.count_us); } + + if (duty_cycle_enabled) { + time_on_air = (uint32_t)lgw_time_on_air(packet); /* in ms */ + + if (duty_cycle_time_avail >= time_on_air) { + duty_cycle_time_avail -= time_on_air; + } else { + printf( "WARNING: DUTY-CYCLE-LIMIT | Not enough time-on-air available to allow transmission PKT: %lu ms AVAILABLE: %lu ms\n", time_on_air, duty_cycle_time_avail); + continue; + } + } /* check if concentrator is free for sending new packet */ pthread_mutex_lock(&mx_concent); /* may have to wait for a fetch to finish */ -- cgit v1.2.3