Skip to content

Commit 80f54b9

Browse files
committed
faster UART speed, improve readme, cleanup
1 parent b42c145 commit 80f54b9

File tree

5 files changed

+51
-27
lines changed

5 files changed

+51
-27
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
This takes Betaflight MSP DisplayPort (so-called "canvas" although this is a misnomer as there is another Betaflight "canvas" mode for Pixel OSDs) messages through UDP and, using a font provided at `font.bin`, renders them to a framebuffer.
44

5+
A custom `font.bin` may be placed on the root of the SD card, at which point it will override the font in /blackbox.
6+
57
SFML and DJI viewports available, as well as a mux which creates a pty and provides filtered MSP access, and reroutes DisplayPort messages to UDP.
68

7-
To build for DJI, install the Android NDK and add it to your path, then use make -f Makefile.dji .
9+
To build for DJI, install the Android NDK and add the NDK toolchain to your PATH, then use make -f Makefile.dji . Set DJI_LIB_PATH to a path to the content of `/system/lib` pulled from your DJI hardware or a firmware dump, so that the linker can find `libduml_hal.so`. On Windows, note that `make` and the actual `armv7a-linux-*` compiler binaries may be installed in different directories.
810

911
To build for UNIXes, install CSFML and make -f Makefile.unix .
1012

@@ -16,6 +18,13 @@ Provided targets and tools are:
1618

1719
# Installation
1820

21+
On your flight controller:
22+
23+
* Ensure that the correct UART is set to use MSP.
24+
* Enable MSP DisplayPort. On Betaflight, this is done using the following commands:
25+
* `set osd_displayport_device = MSP`
26+
* `set displayport_msp_serial = <ConfiguratorUART - 1>` - for example, if the Configurator says UART2, the value here is `1`.
27+
1928
On Air Unit / Air Unit Lite (Vista):
2029
```
2130
adb push msp_displayport_mux /blackbox
@@ -25,6 +34,8 @@ nohup /blackbox/msp_displayport_mux 192.168.41.2 /dev/ttyS1_moved /dev/ttyS1
2534
```
2635
This tells the displayport mux to send data from /dev/ttyS1_moved to 192.168.41.2 (goggles) and to create a fake serial port at /dev/ttyS1 with the displayport messages filtered out.
2736

37+
Optionally, you can add `-f`, like `nohup /blackbox/msp_displayport_mux -f 192.168.41.2 /dev/ttyS1_moved /dev/ttyS1` to put the serial port in a faster 230400 baud mode, and set the MSP serial port in your flight controller to 230400 to try to improve the framerate.
38+
2839
Now you can try `setprop dji.hdvt_uav_service 1` - depending on your FC it may or may not be able to handle the volume of MSP messages as well as DisplayPort at the same time.
2940

3041
On goggles:

dji_services.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,28 @@
33
#include <sys/system_properties.h>
44
#endif
55

6+
#define V2_SERVICE_NAME "dji.glasses_wm150_service"
7+
#define V1_SERVICE_NAME "dji.glasses_service"
8+
#define DEVICE_PROPERTY_NAME "ro.product.device"
9+
#define V2_GOGGLES_DEVICE "pigeon_wm170_gls"
10+
611
void dji_stop_goggles(int is_v2) {
712
#ifdef __ANDROID_API__
8-
if(is_v2) {
9-
__system_property_set("dji.glasses_wm150_service", "0");
10-
} else {
11-
__system_property_set("dji.glasses_service", "0");
12-
}
13+
__system_property_set(is_v2 ? V2_SERVICE_NAME : V1_SERVICE_NAME, "0");
1314
#endif
1415
}
1516

1617
void dji_start_goggles(int is_v2) {
1718
#ifdef __ANDROID_API__
18-
if(is_v2) {
19-
__system_property_set("dji.glasses_wm150_service", "1");
20-
} else {
21-
__system_property_set("dji.glasses_service", "1");
22-
}
19+
__system_property_set(is_v2 ? V2_SERVICE_NAME : V1_SERVICE_NAME, "1");
2320
#endif
2421
}
2522

2623
int dji_goggles_are_v2() {
2724
#ifdef __ANDROID_API__
2825
char goggles_version_response[255];
29-
int len = __system_property_get("ro.product.device", &goggles_version_response);
30-
return(strcmp(goggles_version_response, "pigeon_wm170_gls") == 0);
26+
int len = __system_property_get(DEVICE_PROPERTY_NAME, &goggles_version_response);
27+
return(strcmp(goggles_version_response, V2_GOGGLES_DEVICE) == 0);
3128
#else
3229
return 0;
3330
#endif

msp_displayport_mux.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,43 @@ static void msp_callback(msp_msg_t *msp_message)
5353
}
5454

5555
int main(int argc, char *argv[]) {
56-
if(argc < 3) {
57-
printf("usage: msp_displayport_mux ipaddr serial_port [pty_target]");
56+
int opt;
57+
uint8_t fast_serial = 0;
58+
while((opt = getopt(argc, argv, "f")) != -1){
59+
switch(opt){
60+
case 'f':
61+
fast_serial = 1;
62+
printf("Configuring serial to 230400 baud\n");
63+
break;
64+
case '?':
65+
printf("unknown option: %c\n", optopt);
66+
break;
67+
}
68+
}
69+
70+
if((argc - optind) < 2) {
71+
printf("usage: msp_displayport_mux [-f] ipaddr serial_port [pty_target]");
5872
return 0;
5973
}
60-
char *ip_address = argv[1];
61-
char *serial_port = argv[2];
74+
75+
char *ip_address = argv[optind];
76+
char *serial_port = argv[optind + 1];
6277
signal(SIGINT, sig_handler);
6378
struct pollfd poll_fds[2];
6479
const char *pty_name_ptr;
6580
msp_state_t *msp_state = calloc(1, sizeof(msp_state_t));
6681
msp_state->cb = &msp_callback;
67-
serial_fd = open_serial_port(serial_port);
82+
serial_fd = open_serial_port(serial_port, fast_serial ? B230400 : B115200);
6883
if (serial_fd <= 0) {
6984
printf("Failed to open serial port!\n");
7085
return 1;
7186
}
7287
pty_fd = open_pty(&pty_name_ptr);
7388
printf("Allocated PTY %s\n", pty_name_ptr);
74-
if (argc > 3) {
75-
unlink(argv[3]);
76-
symlink(pty_name_ptr, argv[3]);
77-
printf("Relinked %s to %s\n", argv[3], pty_name_ptr);
89+
if ((argc - optind) > 2) {
90+
unlink(argv[optind + 2]);
91+
symlink(pty_name_ptr, argv[optind + 2]);
92+
printf("Relinked %s to %s\n", argv[optind + 2], pty_name_ptr);
7893
}
7994
socket_fd = connect_to_server(ip_address, PORT);
8095
uint8_t serial_data[256];
@@ -99,7 +114,6 @@ int main(int argc, char *argv[]) {
99114
if(0 < (serial_data_size = read(pty_fd, serial_data, sizeof(serial_data)))) {
100115
write(serial_fd, &serial_data, serial_data_size);
101116
}
102-
103117
}
104118
close(serial_fd);
105119
close(pty_fd);

serial.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#endif
1313
#include "serial.h"
1414

15-
int open_serial_port(const char *device)
15+
int open_serial_port(const char *device, speed_t baudrate)
1616
{
1717
struct termios tio;
1818
int tty_fd;
@@ -26,8 +26,8 @@ int open_serial_port(const char *device)
2626
tio.c_cc[VTIME] = 0;
2727

2828
tty_fd = open(device, O_RDWR | O_NONBLOCK);
29-
cfsetospeed(&tio, B115200);
30-
cfsetispeed(&tio, B115200);
29+
cfsetospeed(&tio, baudrate);
30+
cfsetispeed(&tio, baudrate);
3131
tcsetattr(tty_fd, TCSANOW, &tio);
3232
return tty_fd;
3333
}

serial.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
int open_serial_port(const char *device);
1+
#include <termios.h>
2+
3+
int open_serial_port(const char *device, speed_t baudrate);
24
int open_pty(const char **pty_name);
35
#ifdef __ANDROID__
46
int

0 commit comments

Comments
 (0)