diff options
author | Jason Reiss <jreiss@multitech.com> | 2020-11-18 11:54:30 -0600 |
---|---|---|
committer | Jason Reiss <jreiss@multitech.com> | 2020-11-18 11:54:30 -0600 |
commit | a65223c3c1fd0e28d7225bfae6ed68c83879d5e4 (patch) | |
tree | 9d0bf97b7e9b11c93e952e73d8fec8714c2ea4df | |
parent | 3dbb7af1b51b48428e61618d7ab64d303bc7d753 (diff) | |
download | packet_forwarder_mtac_full-a65223c3c1fd0e28d7225bfae6ed68c83879d5e4.tar.gz packet_forwarder_mtac_full-a65223c3c1fd0e28d7225bfae6ed68c83879d5e4.tar.bz2 packet_forwarder_mtac_full-a65223c3c1fd0e28d7225bfae6ed68c83879d5e4.zip |
Add tx power limit in global_conf.json4.0.1-mts-10
-rw-r--r-- | lora_pkt_fwd/src/lora_pkt_fwd.c | 31 |
1 files 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; } |