@@ -56,7 +56,7 @@ static uint8_t cache_msp_message(msp_msg_t *msp_message) {
56
56
msp_message_cache [msp_message -> cmd ] = cache_message ;
57
57
retval = 1 ;
58
58
}
59
- memcpy (& cache_message -> message , msp_message , sizeof (msp_message ));
59
+ memcpy (& cache_message -> message , msp_message , sizeof (msp_msg_t ));
60
60
clock_gettime (CLOCK_MONOTONIC , & cache_message -> time );
61
61
return retval ;
62
62
}
@@ -77,11 +77,13 @@ static int16_t msp_msg_from_cache(uint8_t msg_buffer[], uint8_t cmd_id) {
77
77
clock_gettime (CLOCK_MONOTONIC , & now );
78
78
if (now .tv_sec > cache_message -> time .tv_sec ) {
79
79
// message is too old, invalidate cache and force a resend
80
+ DEBUG_PRINT ("MSP cache EXPIRED %d\n" , cmd_id );
80
81
free (cache_message );
81
82
msp_message_cache [cmd_id ] = 0 ;
82
83
return -1 ;
83
84
}
84
85
}
86
+ // message existed and was not stale, send it back
85
87
return msp_data_from_msg (msg_buffer , & cache_message -> message );
86
88
}
87
89
}
@@ -97,7 +99,6 @@ static void rx_msp_callback(msp_msg_t *msp_message)
97
99
}
98
100
memcpy (& frame_buffer [fb_cursor ], rx_message_buffer , rx_cursor );
99
101
fb_cursor += rx_cursor ;
100
- rx_cursor = 0 ;
101
102
if (msp_message -> payload [0 ] == 4 ) {
102
103
// Once we have a whole frame of data, send it to the goggles.
103
104
write (socket_fd , frame_buffer , fb_cursor );
@@ -112,28 +113,29 @@ static void rx_msp_callback(msp_msg_t *msp_message)
112
113
} else {
113
114
// Serial passthrough is off, so cache the response we got.
114
115
if (cache_msp_message (msp_message )) {
115
- // 1 -> cache miss, so this message expired or hasn't been seen. this means DJI is waiting for it, so send it over
116
+ // 1 -> cache miss, so this message expired or hasn't been seen.
117
+ // this means DJI is waiting for it, so send it over
116
118
write (pty_fd , rx_message_buffer , rx_cursor );
117
119
}
118
120
}
119
- rx_cursor = 0 ;
120
121
}
122
+ rx_cursor = 0 ;
121
123
}
122
124
123
125
static void tx_msp_callback (msp_msg_t * msp_message )
124
126
{
125
127
// We got a valid message from DJI asking for something. See if there's a response in the cache or not.
126
128
// We can only get here if serial passthrough is off and caching is on, so no need to check again.
127
- DEBUG_PRINT ("DJI->FC MSP msg %d with data len %d \n" , msp_message -> cmd , msp_message -> size );
129
+ DEBUG_PRINT ("DJI->FC MSP msg %d with request len %d \n" , msp_message -> cmd , msp_message -> size );
128
130
uint8_t send_buffer [256 ];
129
- uint16_t size ;
131
+ int16_t size ;
130
132
if (0 < (size = msp_msg_from_cache (send_buffer , msp_message -> cmd ))) {
131
133
// cache hit, so write the cached message straight back to DJI
132
- DEBUG_PRINT ("DJI->FC MSP CACHE HIT %d with data len %d \n" , msp_message -> cmd , size );
134
+ DEBUG_PRINT ("DJI->FC MSP CACHE HIT msg %d with response len %d \n" , msp_message -> cmd , size );
133
135
write (pty_fd , send_buffer , size );
134
136
} else {
135
137
// cache miss, so write the DJI request to serial and wait for the FC to come back.
136
- DEBUG_PRINT ("DJI->FC MSP CACHE MISS %d\n" ,msp_message -> cmd );
138
+ DEBUG_PRINT ("DJI->FC MSP CACHE MISS msg %d\n" ,msp_message -> cmd );
137
139
write (serial_fd , tx_message_buffer , tx_cursor );
138
140
}
139
141
tx_cursor = 0 ;
0 commit comments