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")))
(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";
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);
(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;
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;
}
/* 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 */
/* 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);