#[derive(Clone, Copy, PartialEq, Debug)]
pub enum Error {
NoSuchRecording,
+ StorageError,
}
enum SectorFlag {
self.prepare_write_buffer(true);
- self.write_packet(0, tap.latitude, tap.longitude);
+ self.write_packet(0, tap.latitude_deg, tap.longitude_deg);
self.recording_id
}
// the intervals to full seconds.
let d_time_s = (d_time_ms + 500) / 1000;
- let d_lat = tap.latitude - prev_tap.latitude;
- let d_lon = tap.longitude - prev_tap.longitude;
+ let d_lat = tap.latitude_deg - prev_tap.latitude_deg;
+ let d_lon = tap.longitude_deg - prev_tap.longitude_deg;
if self.write_packet(d_time_s, d_lat, d_lon) {
self.flush_in_flight(false);
Err(Error::NoSuchRecording)
}
}
+
+ ///
+ /// Remove recording @p recording_id.
+ pub fn remove_recording(&mut self, recording_id: u16) -> Result<(), Error> {
+ if let Some(found_index) = (0..NUM_SECTORS).find(|&index| {
+ let sector_header = &self.sector_header[index as usize];
+
+ sector_header.recording_id == recording_id &&
+ sector_header.starts_recording()
+ }) {
+ let mut next_sector = found_index as usize;
+
+ for _ in 0..NUM_SECTORS {
+ let address = next_sector * SECTOR_SIZE;
+
+ if let Err(_) = self.storage.erase(address) {
+ return Err(Error::StorageError);
+ }
+
+ // Mark this sector as eligible for the next recording
+ // and ensure it won't be picked up by list_recordings().
+ self.read_sector_header(next_sector);
+
+ next_sector += 1;
+ next_sector &= NUM_SECTORS - 1;
+
+ if !self.sector_header[next_sector].belongs_to(recording_id) {
+ break;
+ }
+ }
+
+ Ok(())
+ } else {
+ Err(Error::NoSuchRecording)
+ }
+ }
}