From 4e7b647c1e48d1162aa9eba050052a1dd333ae42 Mon Sep 17 00:00:00 2001 From: Nicholas Sherlock Date: Mon, 18 May 2015 18:57:50 +1200 Subject: [PATCH 1/2] Fix missing blackbox logging of synchronisation beep --- src/main/blackbox/blackbox.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/main/blackbox/blackbox.c b/src/main/blackbox/blackbox.c index 602beff5a6..18282c54ae 100644 --- a/src/main/blackbox/blackbox.c +++ b/src/main/blackbox/blackbox.c @@ -250,7 +250,6 @@ typedef enum BlackboxState { BLACKBOX_STATE_SEND_GPS_H_HEADERS, BLACKBOX_STATE_SEND_GPS_G_HEADERS, BLACKBOX_STATE_SEND_SYSINFO, - BLACKBOX_STATE_PRERUN, BLACKBOX_STATE_RUNNING, BLACKBOX_STATE_SHUTTING_DOWN } BlackboxState; @@ -268,6 +267,8 @@ extern uint32_t currentTime; static BlackboxState blackboxState = BLACKBOX_STATE_DISABLED; +static uint32_t blackboxLastArmingBeep = 0; + static struct { uint32_t headerIndex; @@ -684,6 +685,12 @@ void startBlackbox(void) */ 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); } } @@ -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 -static void blackboxLogArmingBeep() +/* 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 blackboxCheckAndLogArmingBeep() { flightLogEvent_syncBeep_t eventData; - // Get time of last arming beep (in system-uptime microseconds) - eventData.time = getArmingBeepTimeMicros(); + // Use != so that we can still detect a change if the counter wraps + if (getArmingBeepTimeMicros() != blackboxLastArmingBeep) { + blackboxLastArmingBeep = getArmingBeepTimeMicros(); - // Write the time to the log - blackboxLogEvent(FLIGHT_LOG_EVENT_SYNC_BEEP, (flightLogEventData_t *) &eventData); + eventData.time = blackboxLastArmingBeep; + + 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 if (blackboxWriteSysinfo()) { - blackboxSetState(BLACKBOX_STATE_PRERUN); + blackboxSetState(BLACKBOX_STATE_RUNNING); } break; - case BLACKBOX_STATE_PRERUN: - blackboxSetState(BLACKBOX_STATE_RUNNING); - - blackboxLogArmingBeep(); - break; case BLACKBOX_STATE_RUNNING: // On entry to this state, blackboxIteration, blackboxPFrameIndex and blackboxIFrameIndex are reset to 0 @@ -1099,6 +1104,8 @@ void handleBlackbox(void) loadBlackboxState(); writeIntraframe(); } else { + blackboxCheckAndLogArmingBeep(); + /* 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: */ From 94faf58e4328e94378b720f6151613265ceb444e Mon Sep 17 00:00:00 2001 From: Nicholas Sherlock Date: Thu, 21 May 2015 16:32:51 +1200 Subject: [PATCH 2/2] Update Blackbox docs to reflect new arming beep --- docs/Blackbox.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/Blackbox.md b/docs/Blackbox.md index 49486183aa..a25db22f63 100644 --- a/docs/Blackbox.md +++ b/docs/Blackbox.md @@ -203,9 +203,9 @@ flight problems like vibration or PID setting issues. The Blackbox starts recording data as soon as you arm your craft, and stops when you disarm. -If your craft has a buzzer attached, a short beep will be played when you arm and recording begins. You can later use -this beep to synchronize your recorded flight video with the rendered flight data log (the beep is shown as a blue line -in the flight data log, which you can sync against the beep in your recorded audio track). +If your craft has a buzzer attached, you can use Cleanflight's arming beep to synchronize your Blackbox log with your +flight video. Cleanflight's arming beep is a "long, short" pattern. The beginning of the first long beep will be shown +as a blue line in the flight data log, which you can sync against your recorded audio track. You should wait a few seconds after disarming your craft to allow the Blackbox to finish saving its data. @@ -224,8 +224,9 @@ minutes. ![Dataflash tab in Configurator](Screenshots/blackbox-dataflash.png) After downloading the log, be sure to erase the chip to make it ready for reuse by clicking the "erase flash" button. -If you try to start recording a new flight when the dataflash is already full, the Blackbox will not make its regular -arming beep and nothing will be recorded. + +If you try to start recording a new flight when the dataflash is already full, Blackbox logging will be disabled and +nothing will be recorded. ## Converting logs to CSV or PNG After your flights, you'll have a series of flight log files with a .TXT extension. You'll need to decode these with