Skip to content

Commit 4498efd

Browse files
setting vtx wip
1 parent 3eb7137 commit 4498efd

File tree

3 files changed

+108
-7
lines changed

3 files changed

+108
-7
lines changed

jni/msp/msp.h

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
// https://github.com/betaflight/betaflight/blob/master/src/main/msp/msp_protocol.h#L201C1-L202C50
2121
#define MSP_CMD_VTX_CONFIG 88 // from FC
2222
#define MSP_CMD_SET_VTX_CONFIG 89 // to FC
23+
#define MSP_CMD_SET_VTXTABLE_BAND 227 // to FC set vtxTable band/channel data (one band at a time)
24+
#define MSP_CMD_SET_VTXTABLE_POWERLEVEL 228 // to FC set vtxTable powerLevel data (one powerLevel at a time)
2325

2426
typedef enum {
2527
MSP_ERR_NONE,

jni/msp/msp_vtx.c

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#include <stdlib.h>
2+
#include <string.h>
3+
#include <stdio.h>
4+
#include <stdint.h>
5+
#include "msp.h"
6+
7+
static uint8_t message_buffer[256];
8+
9+
uint8_t total_bands = 1;
10+
uint8_t total_channels = 8;
11+
uint8_t total_powers = 6;
12+
13+
uint8_t * resetVTXTableMessage() {
14+
uint8_t payload_size = 15;
15+
uint8_t default_table[15] = {
16+
0, // idx LSB
17+
0, // idx MSB
18+
0, // 25mW Power idx
19+
0, // pitmode
20+
0, // lowPowerDisarm
21+
0, // pitModeFreq LSB
22+
0, // pitModeFreq MSB
23+
0, // band
24+
0, // channel
25+
0, // newFreq LSB
26+
0, // newFreq MSB
27+
total_bands, // bandCount,
28+
total_channels, // channelCount
29+
total_powers, // powerCount
30+
1 // vtxtable should be cleared
31+
};
32+
33+
construct_msp_command(message_buffer, MSP_CMD_SET_VTX_CONFIG, default_table, payload_size, MSP_OUTBOUND);
34+
35+
return message_buffer;
36+
}
37+
38+
uint8_t * setupVTXPowerMessage(int index, int value, char name[]) {
39+
uint8_t name_size = sizeof(name);
40+
uint8_t payload_size = 4 + name_size;
41+
uint8_t vtx_power[4 + 3] = {
42+
index, // idx
43+
value & 0xFF, // powerValue LSB
44+
(value >> 8) & 0xFF, // powerValue MSB
45+
sizeof(name), // label lenght
46+
};
47+
48+
for(int i = 0; i < sizeof(name); i++) {
49+
vtx_power[i] = name[i];
50+
}
51+
/*txPacket[8] = idx;
52+
txPacket[9] = saPowerLevelsLut[idx - 1] & 0xFF; // powerValue LSB
53+
txPacket[10] = (saPowerLevelsLut[idx - 1] >> 8) & 0xFF; // powerValue MSB
54+
txPacket[11] = POWER_LEVEL_LABEL_LENGTH;
55+
txPacket[12] = saPowerLevelsLabel[((idx - 1) * POWER_LEVEL_LABEL_LENGTH) + 0];
56+
txPacket[13] = saPowerLevelsLabel[((idx - 1) * POWER_LEVEL_LABEL_LENGTH) + 1];
57+
txPacket[14] = saPowerLevelsLabel[((idx - 1) * POWER_LEVEL_LABEL_LENGTH) + 2];*/
58+
59+
construct_msp_command(message_buffer, MSP_CMD_SET_VTXTABLE_POWERLEVEL, vtx_power, payload_size, MSP_OUTBOUND);
60+
61+
return message_buffer;
62+
}
63+
64+
uint8_t * setupVTXBandMessage() {
65+
uint8_t payload_size = 8 + total_channels;
66+
uint8_t vtx_band[8 + 8] = {
67+
0, // band
68+
3, // label lenght
69+
'D',
70+
'J',
71+
'I',
72+
'D', // band letter
73+
0, // is factory band
74+
total_channels, // total channel
75+
};
76+
77+
for(int i = 8; i < total_channels; i++) {
78+
vtx_band[i] = i & 0xFF;
79+
i++;
80+
vtx_band[i] = (i >> 8) & 0xFF;
81+
}
82+
83+
construct_msp_command(message_buffer, MSP_CMD_SET_VTXTABLE_POWERLEVEL, vtx_band, payload_size, MSP_OUTBOUND);
84+
85+
return message_buffer;
86+
}

jni/msp_displayport_mux.c

+20-7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "util/debug.h"
1717
#include "util/time_util.h"
1818
#include "util/fs_util.h"
19+
#include "./msp/msp_vtx.c"
1920

2021
#define CPU_TEMP_PATH "/sys/devices/platform/soc/f0a00000.apb/f0a71000.omc/temp1"
2122
#define AU_VOLTAGE_PATH "/sys/devices/platform/soc/f0a00000.apb/f0a71000.omc/voltage4"
@@ -153,9 +154,21 @@ static void send_vtx_config_request(int serial_fd) {
153154

154155
static void send_vtx_set_config_request(int serial_fd) {
155156
DEBUG_PRINT("Sending VTX READY message...\n");
156-
uint8_t buffer[6];
157-
construct_msp_command(buffer, MSP_CMD_SET_VTX_CONFIG, NULL, 0, MSP_OUTBOUND);
158-
write(serial_fd, &buffer, sizeof(buffer));
157+
158+
uint8_t *buffer = resetVTXTableMessage();
159+
write(serial_fd, buffer, sizeof(buffer));
160+
161+
buffer = setupVTXPowerMessage(0, 25, "25 ");
162+
write(serial_fd, buffer, sizeof(buffer));
163+
buffer = setupVTXPowerMessage(0, 200, "200 ");
164+
write(serial_fd, buffer, sizeof(buffer));
165+
buffer = setupVTXPowerMessage(0, 500, "500 ");
166+
write(serial_fd, buffer, sizeof(buffer));
167+
buffer = setupVTXPowerMessage(0, 700, "700 ");
168+
write(serial_fd, buffer, sizeof(buffer));
169+
170+
buffer = setupVTXBandMessage();
171+
write(serial_fd, buffer, sizeof(buffer));
159172
}
160173

161174
static void copy_to_msp_frame_buffer(void *buffer, uint16_t size) {
@@ -236,7 +249,7 @@ static void rx_msp_callback(msp_msg_t *msp_message)
236249
default: {
237250
uint16_t size = msp_data_from_msg(message_buffer, msp_message);
238251
if(serial_passthrough || cache_msp_message(msp_message)) {
239-
// Either serial passthrough was on, or the cache was enabled but missed (a response was not available).
252+
// Either serial passthrough was on, or the cache was enabled but missed (a response was not available).
240253
// Either way, this means we need to send the message through to DJI.
241254
write(pty_fd, message_buffer, size);
242255
}
@@ -390,8 +403,8 @@ int main(int argc, char *argv[]) {
390403
printf("Allocated PTY %s\n", pty_name_ptr);
391404
if ((argc - optind) > 2) {
392405
unlink(argv[optind + 2]);
393-
symlink(pty_name_ptr, argv[optind + 2]);
394-
printf("Relinked %s to %s\n", argv[optind + 2], pty_name_ptr);
406+
symlink(pty_name_ptr, argv[optind + 2]);
407+
printf("Relinked %s to %s\n", argv[optind + 2], pty_name_ptr);
395408
}
396409
socket_fd = connect_to_server(ip_address, MSP_PORT);
397410
compressed_fd = connect_to_server(ip_address, COMPRESSED_DATA_PORT);
@@ -425,7 +438,7 @@ int main(int argc, char *argv[]) {
425438
poll_fds[1].events = POLLIN;
426439

427440
poll(poll_fds, 2, ((MSEC_PER_SEC / update_rate_hz) / 2));
428-
441+
429442
// We got inbound serial data, process it as MSP data.
430443
if (0 < (serial_data_size = read(serial_fd, serial_data, sizeof(serial_data)))) {
431444
DEBUG_PRINT("RECEIVED data! length %d\n", serial_data_size);

0 commit comments

Comments
 (0)