X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Fcommon%2Flogger.rs;h=8a1c05cd75f89b676635b7a37c991cde1c84688b;hb=8131a71527b5279bca9b80aac37596f6264ea2a1;hp=c355bb3d47d1d3ab62cbd7dd893fd672925dd959;hpb=79f647cb1795e62c1b04113834ff13b0193dfa6a;p=gps-watch.git diff --git a/src/common/logger.rs b/src/common/logger.rs index c355bb3..8a1c05c 100644 --- a/src/common/logger.rs +++ b/src/common/logger.rs @@ -144,10 +144,22 @@ fn cmp_sector_header_indices(a: u16, b: u16, let header_a = §or_header[a as usize]; let header_b = §or_header[b as usize]; - // Latest entries come first. - if header_a.start_time > header_b.start_time { + if header_a.starts_recording() && header_b.starts_recording() { + // Latest entries come first. + if header_a.start_time > header_b.start_time { + -1 + } else if header_a.start_time < header_b.start_time { + 1 + } else { + 0 + } + } else if header_a.starts_recording() { -1 - } else if header_a.start_time < header_b.start_time { + } else if header_b.starts_recording() { + 1 + } else if a < b { + -1 + } else if a > b { 1 } else { 0 @@ -187,73 +199,30 @@ impl<'a> SectorHeaderIter<'a> { indices: [0; NUM_SECTORS] }; - let mut num_used = 0; - - // Put the indices of the used directory entries at the beginning - // of the array. Ignore the unused ones since we are not going - // to sort them anyway. for i in 0..NUM_SECTORS { - let sector_header = &iter.sector_header[i]; - - if sector_header.starts_recording() { - iter.indices[num_used] = i as u16; - num_used += 1; - } + iter.indices[i] = i as u16; } - let num_elts_to_sort = num_used; + iter.sort(NUM_SECTORS); - if num_elts_to_sort != 0 { - // Sort the used directory entries. - for i in (1..((num_elts_to_sort + 1) / 2) + 1).rev() { - downheap(&mut iter.indices, i - 1, num_elts_to_sort - 1, - iter.sector_header); - } + // XXX: + // Need to handle those sectors that don't start recordings + // but that are still used. - for i in (1..num_elts_to_sort).rev() { - let t = iter.indices[0]; - iter.indices[0] = iter.indices[i]; - iter.indices[i] = t; + iter + } - downheap(&mut iter.indices, 0, i - 1, iter.sector_header); - } + fn sort(&mut self, num_elts_to_sort: usize) { + for i in (1..((num_elts_to_sort + 1) / 2) + 1).rev() { + downheap(&mut self.indices, i - 1, num_elts_to_sort - 1, + self.sector_header); } - // Now put the indices of the unused directory entries in the array. - if num_used == 0 { - for i in 0..NUM_SECTORS { - iter.indices[i] = i as u16; - } - } else { - let latest_used = iter.indices[0] as usize; - let mut offset_unused = num_used; - - // First put the entries that come after the latest one in use... - for i in (latest_used + 1)..NUM_SECTORS { - let sector_header = &iter.sector_header[i]; - - if !sector_header.is_in_use() { - iter.indices[offset_unused] = i as u16; - offset_unused += 1; - } - } - - // ... then wrap around if necessary. - for i in 0..latest_used { - let sector_header = &iter.sector_header[i]; + for i in (1..num_elts_to_sort).rev() { + self.indices.swap(0, i); - if !sector_header.is_in_use() { - iter.indices[offset_unused] = i as u16; - offset_unused += 1; - } - } + downheap(&mut self.indices, 0, i - 1, self.sector_header); } - - // XXX: - // Need to handle those sectors that don't start recordings - // but that are still used. - - iter } } @@ -391,7 +360,7 @@ impl<'a> Logger<'a> { 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 } @@ -407,8 +376,8 @@ impl<'a> Logger<'a> { // 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); @@ -585,6 +554,17 @@ impl<'a> Logger<'a> { continue; } + let mut num_data_sectors = 0; + + for d in 1..NUM_SECTORS { + let wrapped_index = ((index + d) & (NUM_SECTORS - 1)) as usize; + let other_sector_header = &self.sector_header[wrapped_index]; + + if other_sector_header.belongs_to(sector_header.recording_id) { + num_data_sectors += 1; + } + } + let mut date_time_s = [b' '; 19]; if let Some(tm) = Time::from_unix_time(sector_header.start_time) { @@ -592,6 +572,13 @@ impl<'a> Logger<'a> { tm.fmt_time(&mut date_time_s[11..]); } + let recording_size = (num_data_sectors + 1) * (SECTOR_SIZE >> 10); + + let mut recording_size_s = [b'0'; 9]; + let recording_size_s_len = fmt_u32_pad(&mut recording_size_s, + recording_size as u32, + 8, b' '); + let mut recording_id_s = [b'0'; 9]; let recording_id_s_len = fmt_u32_pad(&mut recording_id_s, @@ -599,7 +586,8 @@ impl<'a> Logger<'a> { 8, b' '); tx_buf.write(&date_time_s); - tx_buf.write(b" "); + tx_buf.write(&recording_size_s[0..recording_size_s_len]); + tx_buf.write(b"K"); tx_buf.write(&recording_id_s[0..recording_id_s_len]); tx_buf.write(b"\n");