From: Olivier Matz Date: Tue, 6 May 2014 20:51:22 +0000 (+0200) Subject: rc_proto: allow to disable computation of best power level X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=704c313fd4d921d356e6fe846554591b03e20de7;p=protos%2Fxbee-avr.git rc_proto: allow to disable computation of best power level --- diff --git a/commands.c b/commands.c index dc88a06..c6a6cc9 100644 --- a/commands.c +++ b/commands.c @@ -1742,6 +1742,12 @@ static void cmd_rc_proto_mode_parsed(void *parsed_result, void *data) else flags &= ~RC_PROTO_FLAGS_TX_POW_PROBE; } + else if (!strcmp_P(res->cmd, PSTR("compute_best_pow"))) { + if (on == 1) + flags |= RC_PROTO_FLAGS_COMPUTE_BEST_POW; + else + flags &= ~RC_PROTO_FLAGS_COMPUTE_BEST_POW; + } else if (!strcmp_P(res->cmd, PSTR("tx"))) { flags &= ~RC_PROTO_FLAGS_TX_MASK; if (!strcmp_P(res->val, PSTR("bypass"))) @@ -1766,6 +1772,8 @@ static void cmd_rc_proto_mode_parsed(void *parsed_result, void *data) (flags & RC_PROTO_FLAGS_TX_STATS) ? "on" : "off"); printf_P(PSTR("rc_proto_mode tx_power_probe %s\n"), (flags & RC_PROTO_FLAGS_TX_POW_PROBE) ? "on" : "off"); + printf_P(PSTR("rc_proto_mode compute_best_pow %s\n"), + (flags & RC_PROTO_FLAGS_COMPUTE_BEST_POW) ? "on" : "off"); } const char PROGMEM str_rc_proto_mode_arg0[] = "rc_proto_mode"; @@ -1774,7 +1782,7 @@ const parse_token_string_t PROGMEM cmd_rc_proto_mode_arg0 = str_rc_proto_mode_arg0); const char PROGMEM str_rc_proto_mode_cmd[] = - "rx_copy_spi#rx_autobypass#tx_stats#tx_power_probe"; + "rx_copy_spi#rx_autobypass#tx_stats#tx_power_probe#compute_best_pow"; const parse_token_string_t PROGMEM cmd_rc_proto_mode_cmd = TOKEN_STRING_INITIALIZER(struct cmd_rc_proto_mode_result, cmd, str_rc_proto_mode_cmd); diff --git a/rc_proto.c b/rc_proto.c index 8ea3767..4c09ac3 100644 --- a/rc_proto.c +++ b/rc_proto.c @@ -149,7 +149,7 @@ static void rc_proto_rx_power_probe(int power_level) (void *)(intptr_t)power_level); } -/* called every second */ +/* called every second to decide which power should be used */ static void compute_best_power(void) { int8_t best_power_level = -1; @@ -183,8 +183,13 @@ static void compute_best_power(void) power_level_global = best_power_level; } -static uint8_t get_best_power(void) +/* return the best power level, or -1 if best power level computation is + * disabled. */ +static int8_t get_best_power(void) { + if ((rc_proto_flags & RC_PROTO_FLAGS_COMPUTE_BEST_POW) == 0) + return -1; + /* special values */ if (power_level_global == -1) { power_level_global = -4; @@ -728,10 +733,12 @@ static void rc_proto_cb(struct callout_mgr *cm, struct callout *tim, void *arg) } /* send stats to peer every second */ - diff = t - prev_compute_pow; - if (diff >= 1000) { - compute_best_power(); - prev_compute_pow = t; + if (rc_proto_flags & RC_PROTO_FLAGS_COMPUTE_BEST_POW) { + diff = t - prev_compute_pow; + if (diff >= 1000) { + compute_best_power(); + prev_compute_pow = t; + } } /* send stats to peer every second */ diff --git a/rc_proto.h b/rc_proto.h index 3df4aaf..baf90f4 100644 --- a/rc_proto.h +++ b/rc_proto.h @@ -138,6 +138,9 @@ void rc_proto_dump_servos(void); /* if set, send power probe periodically to the peer (500 ms) */ #define RC_PROTO_FLAGS_TX_POW_PROBE 0x20 +/* if set, use received probes to compute best power level */ +#define RC_PROTO_FLAGS_COMPUTE_BEST_POW 0x40 + void rc_proto_set_mode(uint8_t flags); uint8_t rc_proto_get_mode(void);