+void
+ao_log_list(void) __reentrant
+{
+ uint8_t slot;
+ uint8_t slots;
+ uint16_t flight;
+
+ slots = ao_log_slots();
+ for (slot = 0; slot < slots; slot++)
+ {
+ flight = ao_log_flight(slot);
+ if (flight)
+ printf ("flight %d start %x end %x\n",
+ flight,
+ (uint16_t) (ao_log_pos(slot) >> 8),
+ (uint16_t) (ao_log_pos(slot+1) >> 8));
+ }
+ printf ("done\n");
+}
+
+void
+ao_log_delete(void) __reentrant
+{
+ uint8_t slot;
+ uint8_t slots;
+
+ ao_cmd_decimal();
+ if (ao_cmd_status != ao_cmd_success)
+ return;
+
+ slots = ao_log_slots();
+ /* Look for the flight log matching the requested flight */
+ if (ao_cmd_lex_i) {
+ for (slot = 0; slot < slots; slot++) {
+ if (ao_log_flight(slot) == ao_cmd_lex_i) {
+ ao_log_erase_mark();
+ ao_log_current_pos = ao_log_pos(slot);
+ ao_log_end_pos = ao_log_current_pos + ao_config.flight_log_max;
+ while (ao_log_current_pos < ao_log_end_pos) {
+ uint8_t i;
+ static __xdata uint8_t b;
+
+ /*
+ * Check to see if we've reached the end of
+ * the used memory to avoid re-erasing the same
+ * memory over and over again
+ */
+ for (i = 0; i < 16; i++) {
+ if (ao_storage_read(ao_log_current_pos + i, &b, 1))
+ if (b != 0xff)
+ break;
+ }
+ if (i == 16)
+ break;
+ ao_storage_erase(ao_log_current_pos);
+ ao_log_current_pos += ao_storage_block;
+ }
+ puts("Erased");
+ return;
+ }
+ }
+ }
+ printf("No such flight: %d\n", ao_cmd_lex_i);
+}
+
+__code struct ao_cmds ao_log_cmds[] = {
+ { ao_log_list, "l\0List flight logs" },
+ { ao_log_delete, "d <flight-number>\0Delete flight" },
+ { 0, NULL },
+};
+