1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 08:15:30 +03:00

Fix missing blackbox logging of synchronisation beep

This commit is contained in:
Nicholas Sherlock 2015-05-18 18:57:50 +12:00
parent c174a52ebe
commit 4e7b647c1e

View file

@ -250,7 +250,6 @@ typedef enum BlackboxState {
BLACKBOX_STATE_SEND_GPS_H_HEADERS, BLACKBOX_STATE_SEND_GPS_H_HEADERS,
BLACKBOX_STATE_SEND_GPS_G_HEADERS, BLACKBOX_STATE_SEND_GPS_G_HEADERS,
BLACKBOX_STATE_SEND_SYSINFO, BLACKBOX_STATE_SEND_SYSINFO,
BLACKBOX_STATE_PRERUN,
BLACKBOX_STATE_RUNNING, BLACKBOX_STATE_RUNNING,
BLACKBOX_STATE_SHUTTING_DOWN BLACKBOX_STATE_SHUTTING_DOWN
} BlackboxState; } BlackboxState;
@ -268,6 +267,8 @@ extern uint32_t currentTime;
static BlackboxState blackboxState = BLACKBOX_STATE_DISABLED; static BlackboxState blackboxState = BLACKBOX_STATE_DISABLED;
static uint32_t blackboxLastArmingBeep = 0;
static struct { static struct {
uint32_t headerIndex; uint32_t headerIndex;
@ -684,6 +685,12 @@ void startBlackbox(void)
*/ */
blackboxBuildConditionCache(); blackboxBuildConditionCache();
/*
* Record the beeper's current idea of the last arming beep time, so that we can detect it changing when
* it finally plays the beep for this arming event.
*/
blackboxLastArmingBeep = getArmingBeepTimeMicros();
blackboxSetState(BLACKBOX_STATE_SEND_HEADER); blackboxSetState(BLACKBOX_STATE_SEND_HEADER);
} }
} }
@ -1012,16 +1019,19 @@ void blackboxLogEvent(FlightLogEvent event, flightLogEventData_t *data)
} }
} }
// Write the time of the last arming beep to the log as a synchronization point /* If an arming beep has played since it was last logged, write the time of the arming beep to the log as a synchronization point */
static void blackboxLogArmingBeep() static void blackboxCheckAndLogArmingBeep()
{ {
flightLogEvent_syncBeep_t eventData; flightLogEvent_syncBeep_t eventData;
// Get time of last arming beep (in system-uptime microseconds) // Use != so that we can still detect a change if the counter wraps
eventData.time = getArmingBeepTimeMicros(); if (getArmingBeepTimeMicros() != blackboxLastArmingBeep) {
blackboxLastArmingBeep = getArmingBeepTimeMicros();
// Write the time to the log eventData.time = blackboxLastArmingBeep;
blackboxLogEvent(FLIGHT_LOG_EVENT_SYNC_BEEP, (flightLogEventData_t *) &eventData);
blackboxLogEvent(FLIGHT_LOG_EVENT_SYNC_BEEP, (flightLogEventData_t *) &eventData);
}
} }
/** /**
@ -1082,14 +1092,9 @@ void handleBlackbox(void)
//Keep writing chunks of the system info headers until it returns true to signal completion //Keep writing chunks of the system info headers until it returns true to signal completion
if (blackboxWriteSysinfo()) { if (blackboxWriteSysinfo()) {
blackboxSetState(BLACKBOX_STATE_PRERUN); blackboxSetState(BLACKBOX_STATE_RUNNING);
} }
break; break;
case BLACKBOX_STATE_PRERUN:
blackboxSetState(BLACKBOX_STATE_RUNNING);
blackboxLogArmingBeep();
break;
case BLACKBOX_STATE_RUNNING: case BLACKBOX_STATE_RUNNING:
// On entry to this state, blackboxIteration, blackboxPFrameIndex and blackboxIFrameIndex are reset to 0 // On entry to this state, blackboxIteration, blackboxPFrameIndex and blackboxIFrameIndex are reset to 0
@ -1099,6 +1104,8 @@ void handleBlackbox(void)
loadBlackboxState(); loadBlackboxState();
writeIntraframe(); writeIntraframe();
} else { } else {
blackboxCheckAndLogArmingBeep();
/* Adding a magic shift of "masterConfig.blackbox_rate_num - 1" in here creates a better spread of /* Adding a magic shift of "masterConfig.blackbox_rate_num - 1" in here creates a better spread of
* recorded / skipped frames when the I frame's position is considered: * recorded / skipped frames when the I frame's position is considered:
*/ */