hilink: reflect WFB runtime in MSP VTX
This commit is contained in:
@@ -80,7 +80,7 @@ index a8b756e..7e5ca2a 100644
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
diff --git a/osd/msp/msp.c b/osd/msp/msp.c
|
diff --git a/osd/msp/msp.c b/osd/msp/msp.c
|
||||||
index b1a538c..ad9d55d 100644
|
index b1a538c..d834780 100644
|
||||||
--- a/osd/msp/msp.c
|
--- a/osd/msp/msp.c
|
||||||
+++ b/osd/msp/msp.c
|
+++ b/osd/msp/msp.c
|
||||||
@@ -5,6 +5,7 @@
|
@@ -5,6 +5,7 @@
|
||||||
@@ -108,7 +108,7 @@ index b1a538c..ad9d55d 100644
|
|||||||
|
|
||||||
uint16_t msp_data_from_msg(uint8_t message_buffer[], msp_msg_t *msg) {
|
uint16_t msp_data_from_msg(uint8_t message_buffer[], msp_msg_t *msg) {
|
||||||
// return size
|
// return size
|
||||||
@@ -46,50 +46,94 @@ uint16_t msp_data_from_msg(uint8_t message_buffer[], msp_msg_t *msg) {
|
@@ -46,50 +46,103 @@ uint16_t msp_data_from_msg(uint8_t message_buffer[], msp_msg_t *msg) {
|
||||||
return msg->size + 6;
|
return msg->size + 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,6 +165,10 @@ index b1a538c..ad9d55d 100644
|
|||||||
- payload[12] = CHANNEL_COUNT; // newChannelCount
|
- payload[12] = CHANNEL_COUNT; // newChannelCount
|
||||||
- payload[13] = NUM_POWER_LEVELS; // newPowerCount
|
- payload[13] = NUM_POWER_LEVELS; // newPowerCount
|
||||||
- payload[14] = 0; // vtxtable should be cleared
|
- payload[14] = 0; // vtxtable should be cleared
|
||||||
|
+static bool wfb_runtime_active(void) {
|
||||||
|
+ return system("pidof wfb_tx wfb_rx wfb_tun wifilink >/dev/null 2>&1") == 0;
|
||||||
|
+}
|
||||||
|
+
|
||||||
+static uint8_t power_index_for_txpower(int txpower) {
|
+static uint8_t power_index_for_txpower(int txpower) {
|
||||||
+ uint8_t best = 0;
|
+ uint8_t best = 0;
|
||||||
+ int smallest_delta = 101;
|
+ int smallest_delta = 101;
|
||||||
@@ -181,7 +185,7 @@ index b1a538c..ad9d55d 100644
|
|||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
+static int get_wfb_vtx_config(int *band, int *channel, int *configured_frequency,
|
+static int get_wfb_vtx_config(int *band, int *channel, int *configured_frequency,
|
||||||
+ uint8_t *power_index) {
|
+ uint8_t *power_index, bool *pit_mode) {
|
||||||
+ *configured_frequency = read_wfb_frequency();
|
+ *configured_frequency = read_wfb_frequency();
|
||||||
+ if (*configured_frequency < 0) {
|
+ if (*configured_frequency < 0) {
|
||||||
+ fprintf(stderr, "mspVTX: cannot read /etc/wfb.yaml channel\n");
|
+ fprintf(stderr, "mspVTX: cannot read /etc/wfb.yaml channel\n");
|
||||||
@@ -193,6 +197,11 @@ index b1a538c..ad9d55d 100644
|
|||||||
+ fprintf(stderr, "mspVTX: cannot read /etc/wfb.yaml txpower\n");
|
+ fprintf(stderr, "mspVTX: cannot read /etc/wfb.yaml txpower\n");
|
||||||
+ return -1;
|
+ return -1;
|
||||||
+ }
|
+ }
|
||||||
|
+ bool active = wfb_runtime_active();
|
||||||
|
+ *pit_mode = !active;
|
||||||
|
+ if (!active) {
|
||||||
|
+ txpower = 0;
|
||||||
|
+ }
|
||||||
+ *power_index = power_index_for_txpower(txpower);
|
+ *power_index = power_index_for_txpower(txpower);
|
||||||
+
|
+
|
||||||
+ *band = 1;
|
+ *band = 1;
|
||||||
@@ -210,12 +219,12 @@ index b1a538c..ad9d55d 100644
|
|||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
+static void send_vtx_config(int serial_fd, int band, int channel, int configured_frequency,
|
+static void send_vtx_config(int serial_fd, int band, int channel, int configured_frequency,
|
||||||
+ uint8_t power_index, bool clear_table) {
|
+ uint8_t power_index, bool pit_mode, bool clear_table) {
|
||||||
+ uint8_t payload[15] = {
|
+ uint8_t payload[15] = {
|
||||||
+ configured_frequency & 0xFF,
|
+ configured_frequency & 0xFF,
|
||||||
+ (configured_frequency >> 8) & 0xFF,
|
+ (configured_frequency >> 8) & 0xFF,
|
||||||
+ power_index, // nearest configured 0..100 WFB txpower table entry
|
+ power_index, // nearest configured 0..100 WFB txpower table entry
|
||||||
+ 0, // pit mode
|
+ pit_mode, // management standby is represented as VTX pit mode
|
||||||
+ 0, // low power when disarmed
|
+ 0, // low power when disarmed
|
||||||
+ 0, 0, // pit frequency
|
+ 0, 0, // pit frequency
|
||||||
+ band,
|
+ band,
|
||||||
@@ -235,15 +244,15 @@ index b1a538c..ad9d55d 100644
|
|||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
+static void wipeVtxTable(int serial_fd, int band, int channel, int configured_frequency,
|
+static void wipeVtxTable(int serial_fd, int band, int channel, int configured_frequency,
|
||||||
+ uint8_t power_index) {
|
+ uint8_t power_index, bool pit_mode) {
|
||||||
+ // First tell Betaflight to discard any stale table, then publish the
|
+ // First tell Betaflight to discard any stale table, then publish the
|
||||||
+ // configured WFB frequency and the table dimensions.
|
+ // configured WFB frequency and the table dimensions.
|
||||||
+ send_vtx_config(serial_fd, band, channel, configured_frequency, power_index, true);
|
+ send_vtx_config(serial_fd, band, channel, configured_frequency, power_index, pit_mode, true);
|
||||||
+ send_vtx_config(serial_fd, band, channel, configured_frequency, power_index, false);
|
+ send_vtx_config(serial_fd, band, channel, configured_frequency, power_index, pit_mode, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setVtxTableBand(int serial_fd, uint8_t band) {
|
void setVtxTableBand(int serial_fd, uint8_t band) {
|
||||||
@@ -119,7 +163,7 @@ void setVtxTableBand(int serial_fd, uint8_t band) {
|
@@ -119,7 +172,7 @@ void setVtxTableBand(int serial_fd, uint8_t band) {
|
||||||
}
|
}
|
||||||
|
|
||||||
construct_msp_command(buffer, MSP_SET_VTXTABLE_BAND, payload2, sizeof(payload2), MSP_OUTBOUND);
|
construct_msp_command(buffer, MSP_SET_VTXTABLE_BAND, payload2, sizeof(payload2), MSP_OUTBOUND);
|
||||||
@@ -252,7 +261,7 @@ index b1a538c..ad9d55d 100644
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setVtxTablePowerLevel(int serial_fd, uint8_t idx) {
|
void setVtxTablePowerLevel(int serial_fd, uint8_t idx) {
|
||||||
@@ -139,31 +183,25 @@ void setVtxTablePowerLevel(int serial_fd, uint8_t idx) {
|
@@ -139,31 +192,26 @@ void setVtxTablePowerLevel(int serial_fd, uint8_t idx) {
|
||||||
|
|
||||||
construct_msp_command(
|
construct_msp_command(
|
||||||
buffer, MSP_SET_VTXTABLE_POWERLEVEL, payload2, sizeof(payload2), MSP_OUTBOUND);
|
buffer, MSP_SET_VTXTABLE_POWERLEVEL, payload2, sizeof(payload2), MSP_OUTBOUND);
|
||||||
@@ -265,15 +274,17 @@ index b1a538c..ad9d55d 100644
|
|||||||
+ int channel;
|
+ int channel;
|
||||||
+ int configured_frequency;
|
+ int configured_frequency;
|
||||||
+ uint8_t power_index;
|
+ uint8_t power_index;
|
||||||
|
+ bool pit_mode;
|
||||||
|
+
|
||||||
|
+ if (get_wfb_vtx_config(&band, &channel, &configured_frequency, &power_index, &pit_mode) != 0) {
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
|
||||||
- // mspVTX read current frequency setting
|
- // mspVTX read current frequency setting
|
||||||
- query_interface_for_available_frequencies();
|
- query_interface_for_available_frequencies();
|
||||||
-
|
-
|
||||||
- frequency = read_current_freq_from_interface(read_setting("/etc/wfb.conf", "wlan"));
|
- frequency = read_current_freq_from_interface(read_setting("/etc/wfb.conf", "wlan"));
|
||||||
+ if (get_wfb_vtx_config(&band, &channel, &configured_frequency, &power_index) != 0) {
|
-
|
||||||
+ return;
|
|
||||||
+ }
|
|
||||||
|
|
||||||
- int band = 6;
|
- int band = 6;
|
||||||
- int channel = 3;
|
- int channel = 3;
|
||||||
- for (int index = 0; index < FREQ_TABLE_SIZE; index++) {
|
- for (int index = 0; index < FREQ_TABLE_SIZE; index++) {
|
||||||
@@ -292,11 +303,11 @@ index b1a538c..ad9d55d 100644
|
|||||||
}
|
}
|
||||||
|
|
||||||
- wipeVtxTable(serial_fd, band, channel);
|
- wipeVtxTable(serial_fd, band, channel);
|
||||||
+ wipeVtxTable(serial_fd, band, channel, configured_frequency, power_index);
|
+ wipeVtxTable(serial_fd, band, channel, configured_frequency, power_index, pit_mode);
|
||||||
|
|
||||||
for (int i = 1; i <= BAND_COUNT; i++) {
|
for (int i = 1; i <= BAND_COUNT; i++) {
|
||||||
setVtxTableBand(serial_fd, i);
|
setVtxTableBand(serial_fd, i);
|
||||||
@@ -174,6 +212,19 @@ void msp_set_vtx_config(int serial_fd) {
|
@@ -174,6 +222,20 @@ void msp_set_vtx_config(int serial_fd) {
|
||||||
vtxInitDone = true;
|
vtxInitDone = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,12 +316,13 @@ index b1a538c..ad9d55d 100644
|
|||||||
+ int channel;
|
+ int channel;
|
||||||
+ int configured_frequency;
|
+ int configured_frequency;
|
||||||
+ uint8_t power_index;
|
+ uint8_t power_index;
|
||||||
|
+ bool pit_mode;
|
||||||
+
|
+
|
||||||
+ if (get_wfb_vtx_config(&band, &channel, &configured_frequency, &power_index) != 0) {
|
+ if (get_wfb_vtx_config(&band, &channel, &configured_frequency, &power_index, &pit_mode) != 0) {
|
||||||
+ return;
|
+ return;
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ send_vtx_config(serial_fd, band, channel, configured_frequency, power_index, false);
|
+ send_vtx_config(serial_fd, band, channel, configured_frequency, power_index, pit_mode, false);
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
msp_error_e construct_msp_command(uint8_t message_buffer[], uint8_t command, uint8_t payload[],
|
msp_error_e construct_msp_command(uint8_t message_buffer[], uint8_t command, uint8_t payload[],
|
||||||
|
|||||||
Reference in New Issue
Block a user