From a65223c3c1fd0e28d7225bfae6ed68c83879d5e4 Mon Sep 17 00:00:00 2001 From: Jason Reiss Date: Wed, 18 Nov 2020 11:54:30 -0600 Subject: Add tx power limit in global_conf.json --- lora_pkt_fwd/src/lora_pkt_fwd.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/lora_pkt_fwd/src/lora_pkt_fwd.c b/lora_pkt_fwd/src/lora_pkt_fwd.c index e72671f..34996d4 100644 --- a/lora_pkt_fwd/src/lora_pkt_fwd.c +++ b/lora_pkt_fwd/src/lora_pkt_fwd.c @@ -175,9 +175,9 @@ static bool duty_cycle_enabled = false; static uint32_t duty_cycle_time_avail = 0; static uint32_t duty_cycle_period = 3600; // seconds in one hour static double duty_cycle_ratio = 0.10; // 10% -static uint32_t duty_cycle_time_max = 3600 * 0.10 * 1000u; // max time-on-air in window - +static uint32_t duty_cycle_time_max = 3600 * 0.10 * 1000u; // max time-on-air in window +static int max_tx_power = -99; // limit tx power sent from a network server /* statistics collection configuration variables */ static unsigned stat_interval = DEFAULT_STAT; /* time interval (in sec) at which statistics are collected and displayed */ @@ -946,7 +946,7 @@ static int parse_gateway_configuration(const char * conf_file) { MSG("INFO: upstream PUSH_DATA time-out is configured to %u ms\n", (unsigned)(push_timeout_half.tv_usec / 500)); } - + /* duty-cycle limiting */ val = json_object_get_value(conf_obj, "duty_cycle_enabled"); if (json_value_get_type(val) == JSONBoolean) { @@ -970,6 +970,12 @@ static int parse_gateway_configuration(const char * conf_file) { duty_cycle_time_max = duty_cycle_period * 1000u * duty_cycle_ratio; } + /* max tx power */ + val = json_object_get_value(conf_obj, "max_tx_power"); + if (val != NULL) { + max_tx_power = (int)json_value_get_number(val); + MSG("INFO: max tx power %d\n", (max_tx_power)); + } /* packet filtering parameters */ val = json_object_get_value(conf_obj, "best_packet_filter"); @@ -1580,7 +1586,7 @@ int main(int argc, char** argv) exit(EXIT_FAILURE); } } - + i = pthread_create( &thrid_valid, NULL, (void * (*)(void *))thread_valid, NULL); if (i != 0) { MSG("ERROR: [main] impossible to create validation thread\n"); @@ -1731,7 +1737,7 @@ int main(int argc, char** argv) printf("# BEACON sent so far: %u\n", cp_nb_beacon_sent); printf("# BEACON rejected: %u\n", cp_nb_beacon_rejected); printf("### [JIT] ###\n"); - + /* get timestamp captured on PPM pulse */ pthread_mutex_lock(&mx_concent); i = lgw_get_trigcnt(&trig_tstamp); @@ -1791,7 +1797,7 @@ int main(int argc, char** argv) pthread_cancel(thrid_jit); /* don't wait for jit thread */ pthread_cancel(thrid_timersync); /* don't wait for timer sync thread */ pthread_cancel(thrid_valid); /* don't wait for validation thread */ - + if (gps_enabled == true) { pthread_cancel(thrid_gps); /* don't wait for GPS thread */ @@ -2859,6 +2865,13 @@ void thread_down(void) { val = json_object_get_value(txpk_obj,"powe"); if (val != NULL) { txpkt.rf_power = (int8_t)json_value_get_number(val) - antenna_gain; + + if (max_tx_power != -99) { + if (txpkt.rf_power > max_tx_power - antenna_gain) { + MSG("INFO: [down] tx power reduced tx power: % dBm attn gain: %d dBi\n", max_tx_power, antenna_gain); + txpkt.rf_power = max_tx_power - antenna_gain; + } + } } /* Parse modulation (mandatory) */ @@ -3111,7 +3124,7 @@ 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(&pkt); /* in ms */ @@ -3348,7 +3361,7 @@ void thread_valid(void) { if (last.tv_sec != 0) { // uint64(now.tv_sec) * 1000 + now.tv_nsec / 1000000 - + duty_cycle_time_avail += difftimespec(now, last) * 1000u * duty_cycle_ratio; if (duty_cycle_time_avail > duty_cycle_time_max) { @@ -3358,7 +3371,7 @@ void thread_valid(void) { last = now; } - + if (gps_enabled != true) { continue; } -- cgit v1.2.3