Skip to content

Commit b6e7a4b

Browse files
committed
Add some debug messages to SITL
Great to diagnose your msp messages are actually being delivered. :)
1 parent 2a40913 commit b6e7a4b

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/main/fc/fc_msp.c

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <ctype.h>
1919
#include <stdbool.h>
2020
#include <stdint.h>
21+
#include <stdio.h>
2122
#include <string.h>
2223
#include <math.h>
2324

@@ -3290,9 +3291,11 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src)
32903291
#endif
32913292
case MSP2_INAV_GPS_UBLOX_COMMAND:
32923293
if(dataSize < 8 || !isGpsUblox()) {
3294+
SD(fprintf(stderr, "[GPS] Not ublox!\n"));
32933295
return MSP_RESULT_ERROR;
32943296
}
32953297

3298+
SD(fprintf(stderr, "[GPS] Sending ubx command: %i!\n", dataSize));
32963299
gpsUbloxSendCommand(src->ptr, dataSize, 0);
32973300
break;
32983301

@@ -4142,6 +4145,7 @@ mspResult_e mspFcProcessCommand(mspPacket_t *cmd, mspPacket_t *reply, mspPostPro
41424145
// initialize reply by default
41434146
reply->cmd = cmd->cmd;
41444147

4148+
SD(fprintf(stderr, "[MSP] CommandId: 0x%04x bytes: %i!\n", cmdMSP, sbufBytesRemaining(src)));
41454149
if (MSP2_IS_SENSOR_MESSAGE(cmdMSP)) {
41464150
ret = mspProcessSensorCommand(cmdMSP, src);
41474151
} else if (mspFcProcessOutCommand(cmdMSP, dst, mspPostProcessFn)) {

src/main/msp/msp_serial.c

+8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#include <stdbool.h>
1919
#include <stdint.h>
20+
#include <stdio.h>
21+
#include <ctype.h>
2022
#include <string.h>
2123

2224
#include "platform.h"
@@ -171,8 +173,10 @@ static bool mspSerialProcessReceivedData(mspPort_t *mspPort, uint8_t c)
171173
case MSP_CHECKSUM_V1:
172174
if (mspPort->checksum1 == c) {
173175
mspPort->c_state = MSP_COMMAND_RECEIVED;
176+
SD(fprintf(stderr, "[MSPV1] Command received\n"));
174177
} else {
175178
mspPort->c_state = MSP_IDLE;
179+
SD(fprintf(stderr, "[MSPV1] Checksum error!\n"));
176180
}
177181
break;
178182

@@ -225,6 +229,7 @@ static bool mspSerialProcessReceivedData(mspPort_t *mspPort, uint8_t c)
225229
// Check for potential buffer overflow
226230
if (hdrv2->size > MSP_PORT_INBUF_SIZE) {
227231
mspPort->c_state = MSP_IDLE;
232+
SD(fprintf(stderr, "[MSPV2] Potential buffer overflow!\n"));
228233
}
229234
else {
230235
mspPort->dataSize = hdrv2->size;
@@ -248,7 +253,9 @@ static bool mspSerialProcessReceivedData(mspPort_t *mspPort, uint8_t c)
248253
case MSP_CHECKSUM_V2_NATIVE:
249254
if (mspPort->checksum2 == c) {
250255
mspPort->c_state = MSP_COMMAND_RECEIVED;
256+
SD(fprintf(stderr, "[MSPV2] command received!\n"));
251257
} else {
258+
SD(fprintf(stderr, "[MSPV2] Checksum error!\n"));
252259
mspPort->c_state = MSP_IDLE;
253260
}
254261
break;
@@ -472,6 +479,7 @@ void mspSerialProcessOnePort(mspPort_t * const mspPort, mspEvaluateNonMspData_e
472479
const uint8_t c = serialRead(mspPort->port);
473480
const bool consumed = mspSerialProcessReceivedData(mspPort, c);
474481

482+
//SD(fprintf(stderr, "[MSP]: received char: %02x (%c) state: %i\n", c, isprint(c) ? c : '.', mspPort->c_state));
475483
if (!consumed && evaluateNonMspData == MSP_EVALUATE_NON_MSP_DATA) {
476484
mspEvaluateNonMspData(mspPort, c);
477485
}

0 commit comments

Comments
 (0)