@@ -28,10 +28,7 @@ static uint8_t frame_buffer[4196]; // buffer a whole frame of MSP commands until
28
28
static uint32_t fb_cursor = 0 ;
29
29
30
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 rx_cursor = 0 ;
32
-
33
31
static uint8_t tx_message_buffer [256 ];
34
- static uint8_t tx_cursor = 0 ;
35
32
36
33
int pty_fd ;
37
34
int serial_fd ;
@@ -111,27 +108,21 @@ static void rx_msp_callback(msp_msg_t *msp_message)
111
108
uint16_t size = msp_data_from_msg (rx_message_buffer , msp_message );
112
109
// This isn't an MSP DisplayPort message, so send it to either DJI directly or to the cache.
113
110
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" );
119
111
write (pty_fd , rx_message_buffer , size );
120
112
} else {
121
113
// Serial passthrough is off, so cache the response we got.
122
114
if (cache_msp_message (msp_message )) {
123
115
// 1 -> cache miss, so this message expired or hasn't been seen.
124
116
// this means DJI is waiting for it, so send it over
125
117
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 ++ ) {
127
119
DEBUG_PRINT ("%02X " , rx_message_buffer [i ]);
128
120
}
129
121
DEBUG_PRINT ("\n" );
130
122
write (pty_fd , rx_message_buffer , size );
131
123
}
132
124
}
133
125
}
134
- rx_cursor = 0 ;
135
126
}
136
127
137
128
static void tx_msp_callback (msp_msg_t * msp_message )
@@ -152,9 +143,9 @@ static void tx_msp_callback(msp_msg_t *msp_message)
152
143
} else {
153
144
// cache miss, so write the DJI request to serial and wait for the FC to come back.
154
145
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 );
156
148
}
157
- tx_cursor = 0 ;
158
149
}
159
150
160
151
int main (int argc , char * argv []) {
@@ -218,13 +209,7 @@ int main(int argc, char *argv[]) {
218
209
if (0 < (serial_data_size = read (serial_fd , serial_data , sizeof (serial_data )))) {
219
210
DEBUG_PRINT ("RECEIVED data! length %d\n" , serial_data_size );
220
211
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 ]);
228
213
}
229
214
}
230
215
// We got data from DJI (the pty), so see what to do next:
@@ -241,13 +226,7 @@ int main(int argc, char *argv[]) {
241
226
// Otherwise, queue it up for processing by the MSP layer.
242
227
DEBUG_PRINT ("SEND data to MSP buffer! length %d\n" , serial_data_size );
243
228
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 ]);
251
230
}
252
231
}
253
232
}
0 commit comments