@@ -51,11 +51,12 @@ static uint8_t cache_msp_message(msp_msg_t *msp_message) {
51
51
uint8_t retval = 0 ;
52
52
msp_cache_entry_t * cache_message = msp_message_cache [msp_message -> cmd ];
53
53
if (cache_message == NULL ) {
54
- DEBUG_PRINT ("no entry for msg %d, allocating\n" , msp_message -> cmd );
54
+ DEBUG_PRINT ("FC -> AU CACHE: no entry for msg %d, allocating\n" , msp_message -> cmd );
55
55
cache_message = calloc (1 , sizeof (msp_cache_entry_t ));
56
56
msp_message_cache [msp_message -> cmd ] = cache_message ;
57
57
retval = 1 ;
58
58
}
59
+ DEBUG_PRINT ("FC -> AU CACHE: refreshing %d\n" , msp_message -> cmd );
59
60
memcpy (& cache_message -> message , msp_message , sizeof (msp_msg_t ));
60
61
clock_gettime (CLOCK_MONOTONIC , & cache_message -> time );
61
62
return retval ;
@@ -97,25 +98,36 @@ static void rx_msp_callback(msp_msg_t *msp_message)
97
98
if (fb_cursor > sizeof (frame_buffer )) {
98
99
printf ("Exhausted frame buffer!\n" );
99
100
}
100
- memcpy (& frame_buffer [fb_cursor ], rx_message_buffer , rx_cursor );
101
- fb_cursor += rx_cursor ;
101
+ uint16_t size = msp_data_from_msg (rx_message_buffer , msp_message );
102
+ memcpy (& frame_buffer [fb_cursor ], rx_message_buffer , size );
103
+ fb_cursor += size ;
102
104
if (msp_message -> payload [0 ] == 4 ) {
103
105
// Once we have a whole frame of data, send it to the goggles.
104
106
write (socket_fd , frame_buffer , fb_cursor );
105
107
DEBUG_PRINT ("DRAW! wrote %d bytes\n" , fb_cursor );
106
108
fb_cursor = 0 ;
107
109
}
108
110
} else {
111
+ uint16_t size = msp_data_from_msg (rx_message_buffer , msp_message );
109
112
// This isn't an MSP DisplayPort message, so send it to either DJI directly or to the cache.
110
113
if (serial_passthrough ) {
111
114
// Serial passthrough is on, so send it straight to DJI.
112
- write (pty_fd , rx_message_buffer , rx_cursor );
115
+ for (int i = 0 ; i < rx_cursor ; i ++ ) {
116
+ DEBUG_PRINT ("%02X " , rx_message_buffer [i ]);
117
+ }
118
+ DEBUG_PRINT ("\n" );
119
+ write (pty_fd , rx_message_buffer , size );
113
120
} else {
114
121
// Serial passthrough is off, so cache the response we got.
115
122
if (cache_msp_message (msp_message )) {
116
123
// 1 -> cache miss, so this message expired or hasn't been seen.
117
124
// this means DJI is waiting for it, so send it over
118
- write (pty_fd , rx_message_buffer , rx_cursor );
125
+ DEBUG_PRINT ("DJI was waiting, got msg %d\n" , msp_message -> cmd );
126
+ for (int i = 0 ; i < rx_cursor ; i ++ ) {
127
+ DEBUG_PRINT ("%02X " , rx_message_buffer [i ]);
128
+ }
129
+ DEBUG_PRINT ("\n" );
130
+ write (pty_fd , rx_message_buffer , size );
119
131
}
120
132
}
121
133
}
@@ -132,6 +144,10 @@ static void tx_msp_callback(msp_msg_t *msp_message)
132
144
if (0 < (size = msp_msg_from_cache (send_buffer , msp_message -> cmd ))) {
133
145
// cache hit, so write the cached message straight back to DJI
134
146
DEBUG_PRINT ("DJI->FC MSP CACHE HIT msg %d with response len %d \n" , msp_message -> cmd , size );
147
+ for (int i = 0 ; i < size ; i ++ ) {
148
+ DEBUG_PRINT ("%02X " , send_buffer [i ]);
149
+ }
150
+ DEBUG_PRINT ("\n" );
135
151
write (pty_fd , send_buffer , size );
136
152
} else {
137
153
// cache miss, so write the DJI request to serial and wait for the FC to come back.
@@ -202,7 +218,7 @@ int main(int argc, char *argv[]) {
202
218
if (0 < (serial_data_size = read (serial_fd , serial_data , sizeof (serial_data )))) {
203
219
DEBUG_PRINT ("RECEIVED data! length %d\n" , serial_data_size );
204
220
for (ssize_t i = 0 ; i < serial_data_size ; i ++ ) {
205
- if (msp_process_data (rx_msp_state , serial_data [i ]) == 0 ) {
221
+ if (msp_process_data (rx_msp_state , serial_data [i ]) == MSP_ERR_NONE ) {
206
222
// 0 -> MSP data was valid, so buffer it to forward on to either goggles or DJI later
207
223
rx_message_buffer [rx_cursor ] = serial_data [i ];
208
224
rx_cursor ++ ;
@@ -225,7 +241,7 @@ int main(int argc, char *argv[]) {
225
241
// Otherwise, queue it up for processing by the MSP layer.
226
242
DEBUG_PRINT ("SEND data to MSP buffer! length %d\n" , serial_data_size );
227
243
for (ssize_t i = 0 ; i < serial_data_size ; i ++ ) {
228
- if (msp_process_data (tx_msp_state , serial_data [i ]) == 0 ) {
244
+ if (msp_process_data (tx_msp_state , serial_data [i ]) == MSP_ERR_NONE ) {
229
245
// 0 -> MSP data was valid, so buffer it to forward on later
230
246
tx_message_buffer [tx_cursor ] = serial_data [i ];
231
247
tx_cursor ++ ;
0 commit comments