Skip to content

Commit 7e0f047

Browse files
committed
bugfix: gigantic OSD configurations can blow through buffer
1 parent 62b60a1 commit 7e0f047

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

msp_displayport_mux.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ typedef struct msp_cache_entry_s {
2424

2525
static msp_cache_entry_t *msp_message_cache[256]; // make a slot for all possible messages
2626

27-
static uint8_t frame_buffer[4196]; // buffer a whole frame of MSP commands until we get a draw command
27+
static uint8_t frame_buffer[8192]; // buffer a whole frame of MSP commands until we get a draw command
2828
static uint32_t fb_cursor = 0;
2929

30-
static uint8_t rx_message_buffer[256]; // only needs to be the maximum size of an MSP packet, we only care to fwd MSP
31-
static uint8_t tx_message_buffer[256];
30+
static uint8_t message_buffer[256]; // only needs to be the maximum size of an MSP packet, we only care to fwd MSP
3231

3332
int pty_fd;
3433
int serial_fd;
@@ -94,9 +93,10 @@ static void rx_msp_callback(msp_msg_t *msp_message)
9493
// This was an MSP DisplayPort message, so buffer it until we get a whole frame.
9594
if(fb_cursor > sizeof(frame_buffer)) {
9695
printf("Exhausted frame buffer!\n");
96+
return;
9797
}
98-
uint16_t size = msp_data_from_msg(rx_message_buffer, msp_message);
99-
memcpy(&frame_buffer[fb_cursor], rx_message_buffer, size);
98+
uint16_t size = msp_data_from_msg(message_buffer, msp_message);
99+
memcpy(&frame_buffer[fb_cursor], message_buffer, size);
100100
fb_cursor += size;
101101
if(msp_message->payload[0] == 4) {
102102
// Once we have a whole frame of data, send it to the goggles.
@@ -105,21 +105,21 @@ static void rx_msp_callback(msp_msg_t *msp_message)
105105
fb_cursor = 0;
106106
}
107107
} else {
108-
uint16_t size = msp_data_from_msg(rx_message_buffer, msp_message);
108+
uint16_t size = msp_data_from_msg(message_buffer, msp_message);
109109
// This isn't an MSP DisplayPort message, so send it to either DJI directly or to the cache.
110110
if(serial_passthrough) {
111-
write(pty_fd, rx_message_buffer, size);
111+
write(pty_fd, message_buffer, size);
112112
} else {
113113
// Serial passthrough is off, so cache the response we got.
114114
if(cache_msp_message(msp_message)) {
115115
// 1 -> cache miss, so this message expired or hasn't been seen.
116116
// this means DJI is waiting for it, so send it over
117117
DEBUG_PRINT("DJI was waiting, got msg %d\n", msp_message->cmd);
118118
for (int i = 0; i < size; i++) {
119-
DEBUG_PRINT("%02X ", rx_message_buffer[i]);
119+
DEBUG_PRINT("%02X ", message_buffer[i]);
120120
}
121121
DEBUG_PRINT("\n");
122-
write(pty_fd, rx_message_buffer, size);
122+
write(pty_fd, message_buffer, size);
123123
}
124124
}
125125
}
@@ -143,8 +143,8 @@ static void tx_msp_callback(msp_msg_t *msp_message)
143143
} else {
144144
// cache miss, so write the DJI request to serial and wait for the FC to come back.
145145
DEBUG_PRINT("DJI->FC MSP CACHE MISS msg %d\n",msp_message->cmd);
146-
uint16_t size = msp_data_from_msg(tx_message_buffer, msp_message);
147-
write(serial_fd, tx_message_buffer, size);
146+
uint16_t size = msp_data_from_msg(message_buffer, msp_message);
147+
write(serial_fd, message_buffer, size);
148148
}
149149
}
150150

@@ -169,7 +169,7 @@ int main(int argc, char *argv[]) {
169169
}
170170

171171
if((argc - optind) < 2) {
172-
printf("usage: msp_displayport_mux [-f] [-s] [-p] ipaddr serial_port [pty_target]\n-s : enable serial caching\n-f : 230400 baud serial\n");
172+
printf("usage: msp_displayport_mux [-f] [-s] ipaddr serial_port [pty_target]\n-s : enable serial caching\n-f : 230400 baud serial\n");
173173
return 0;
174174
}
175175

osd_dji_udp.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
#define SDCARD_FONT_PATH "/storage/sdcard0/font.bin"
4747
#define FONT_FILE_SIZE 1990656
4848

49+
#define EV_CODE_BACK 0xc9
50+
51+
#define BACK_BUTTON_DELAY 4
52+
4953
#ifdef DEBUG
5054
#define DEBUG_PRINT(fmt, args...) fprintf(stderr, fmt, ## args)
5155
#else
@@ -222,7 +226,7 @@ int main(int argc, char *argv[])
222226
start_display(is_v2_goggles);
223227
display_mode = DISPLAY_RUNNING;
224228
}
225-
if(button_start.tv_sec > 0 && ((now.tv_sec - button_start.tv_sec) > 4)) {
229+
if(button_start.tv_sec > 0 && ((now.tv_sec - button_start.tv_sec) > BACK_BUTTON_DELAY)) {
226230
// We held the back button down for 5 seconds.
227231
memset(&button_start, 0, sizeof(button_start));
228232
if (display_mode == DISPLAY_DISABLED) {
@@ -248,7 +252,7 @@ int main(int argc, char *argv[])
248252

249253
if(poll_fds[1].revents) {
250254
read(event_fd, &ev, sizeof(struct input_event));
251-
if(ev.code == 0xc9) {
255+
if(ev.code == EV_CODE_BACK) {
252256
if(ev.value == 1) {
253257
clock_gettime(CLOCK_MONOTONIC, &button_start);
254258
} else {

0 commit comments

Comments
 (0)