+}
+
+uint8_t
+ao_log_scan(void) __reentrant
+{
+ uint8_t log_slot;
+ uint8_t log_slots;
+#if FLIGHT_LOG_APPEND
+ uint8_t ret;
+#else
+ uint8_t log_want;
+#endif
+
+ ao_config_get();
+
+ /* Get any existing flight number */
+ ao_flight_number = ao_log_max_flight();
+
+#if FLIGHT_LOG_APPEND
+
+ /* Deal with older OS versions which stored multiple
+ * flights in rom by erasing everything after the first
+ * slot
+ */
+ if (ao_config.flight_log_max != ao_storage_log_max) {
+ log_slots = ao_log_slots();
+ for (log_slot = 1; log_slot < log_slots; log_slot++) {
+ if (ao_log_flight(log_slot) != 0)
+ ao_log_erase(log_slot);
+ }
+ ao_config_log_fix_append();
+ }
+ ao_log_current_pos = ao_log_pos(0);
+ ao_log_end_pos = ao_log_current_pos + ao_storage_log_max;
+
+ if (ao_flight_number) {
+ uint32_t full = ao_log_current_pos;
+ uint32_t empty = ao_log_end_pos - ao_log_size;
+
+ /* If there's already a flight started, then find the
+ * end of it
+ */
+ for (;;) {
+ ao_log_current_pos = (full + empty) >> 1;
+ ao_log_current_pos -= ao_log_current_pos % ao_log_size;
+
+ if (ao_log_current_pos == full) {
+ if (ao_log_check(ao_log_current_pos))
+ ao_log_current_pos += ao_log_size;
+ break;
+ }
+ if (ao_log_current_pos == empty)
+ break;
+
+ if (ao_log_check(ao_log_current_pos)) {
+ full = ao_log_current_pos;
+ } else {
+ empty = ao_log_current_pos;
+ }
+ }
+ ret = 1;
+ } else {
+ ao_log_find_max_erase_flight();
+ ret = 0;
+ }
+ ao_wakeup(&ao_flight_number);
+ return ret;
+#else
+
+ if (ao_flight_number)
+ if (++ao_flight_number == 0)
+ ao_flight_number = 1;
+
+ ao_log_find_max_erase_flight();