Skip to content

Commit af5b992

Browse files
committed
cleanup mux to not use bufs anymore
1 parent f1df4bb commit af5b992

File tree

1 file changed

+5
-26
lines changed

1 file changed

+5
-26
lines changed

msp_displayport_mux.c

+5-26
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ static uint8_t frame_buffer[4196]; // buffer a whole frame of MSP commands until
2828
static uint32_t fb_cursor = 0;
2929

3030
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 rx_cursor = 0;
32-
3331
static uint8_t tx_message_buffer[256];
34-
static uint8_t tx_cursor = 0;
3532

3633
int pty_fd;
3734
int serial_fd;
@@ -111,27 +108,21 @@ static void rx_msp_callback(msp_msg_t *msp_message)
111108
uint16_t size = msp_data_from_msg(rx_message_buffer, msp_message);
112109
// This isn't an MSP DisplayPort message, so send it to either DJI directly or to the cache.
113110
if(serial_passthrough) {
114-
// Serial passthrough is on, so send it straight to DJI.
115-
for (int i = 0; i < rx_cursor; i++) {
116-
DEBUG_PRINT("%02X ", rx_message_buffer[i]);
117-
}
118-
DEBUG_PRINT("\n");
119111
write(pty_fd, rx_message_buffer, size);
120112
} else {
121113
// Serial passthrough is off, so cache the response we got.
122114
if(cache_msp_message(msp_message)) {
123115
// 1 -> cache miss, so this message expired or hasn't been seen.
124116
// this means DJI is waiting for it, so send it over
125117
DEBUG_PRINT("DJI was waiting, got msg %d\n", msp_message->cmd);
126-
for (int i = 0; i < rx_cursor; i++) {
118+
for (int i = 0; i < size; i++) {
127119
DEBUG_PRINT("%02X ", rx_message_buffer[i]);
128120
}
129121
DEBUG_PRINT("\n");
130122
write(pty_fd, rx_message_buffer, size);
131123
}
132124
}
133125
}
134-
rx_cursor = 0;
135126
}
136127

137128
static void tx_msp_callback(msp_msg_t *msp_message)
@@ -152,9 +143,9 @@ static void tx_msp_callback(msp_msg_t *msp_message)
152143
} else {
153144
// cache miss, so write the DJI request to serial and wait for the FC to come back.
154145
DEBUG_PRINT("DJI->FC MSP CACHE MISS msg %d\n",msp_message->cmd);
155-
write(serial_fd, tx_message_buffer, tx_cursor);
146+
uint16_t size = msp_data_from_msg(tx_message_buffer, msp_message);
147+
write(serial_fd, tx_message_buffer, size);
156148
}
157-
tx_cursor = 0;
158149
}
159150

160151
int main(int argc, char *argv[]) {
@@ -218,13 +209,7 @@ int main(int argc, char *argv[]) {
218209
if (0 < (serial_data_size = read(serial_fd, serial_data, sizeof(serial_data)))) {
219210
DEBUG_PRINT("RECEIVED data! length %d\n", serial_data_size);
220211
for (ssize_t i = 0; i < serial_data_size; i++) {
221-
if(msp_process_data(rx_msp_state, serial_data[i]) == MSP_ERR_NONE) {
222-
// 0 -> MSP data was valid, so buffer it to forward on to either goggles or DJI later
223-
rx_message_buffer[rx_cursor] = serial_data[i];
224-
rx_cursor++;
225-
} else {
226-
rx_cursor = 0;
227-
}
212+
msp_process_data(rx_msp_state, serial_data[i]);
228213
}
229214
}
230215
// We got data from DJI (the pty), so see what to do next:
@@ -241,13 +226,7 @@ int main(int argc, char *argv[]) {
241226
// Otherwise, queue it up for processing by the MSP layer.
242227
DEBUG_PRINT("SEND data to MSP buffer! length %d\n", serial_data_size);
243228
for (ssize_t i = 0; i < serial_data_size; i++) {
244-
if(msp_process_data(tx_msp_state, serial_data[i]) == MSP_ERR_NONE) {
245-
// 0 -> MSP data was valid, so buffer it to forward on later
246-
tx_message_buffer[tx_cursor] = serial_data[i];
247-
tx_cursor++;
248-
} else {
249-
tx_cursor = 0;
250-
}
229+
msp_process_data(tx_msp_state, serial_data[i]);
251230
}
252231
}
253232
}

0 commit comments

Comments
 (0)