Skip to content

Commit

Permalink
added robot time to the logs.
Browse files Browse the repository at this point in the history
  • Loading branch information
gbin committed Jun 16, 2024
1 parent b241fee commit 1839bd4
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
5 changes: 0 additions & 5 deletions copper_datalogger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,13 @@ impl MmapStream {

impl WriteStream for MmapStream {
fn log(&mut self, obj: &impl Encode) -> CuResult<()> {
println!("Write Stream: log");
let result = encode_into_slice(
obj,
&mut self.current_slice[self.current_position..],
standard(),
);
match result {
Ok(nb_bytes) => {
println!(
"Write Stream: Encoded bytes : {:?}",
&self.current_slice[self.current_position..self.current_position + nb_bytes]
);
self.current_position += nb_bytes;
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion copper_log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl CuLogEntry {

/// Rebuild a log line from the interned strings and the CuLogEntry.
/// This basically translates the world of copper logs to text logs.
pub fn rebuild_logline(all_interned_strings: &Vec<String>, entry: CuLogEntry) -> CuResult<String> {
pub fn rebuild_logline(all_interned_strings: &Vec<String>, entry: &CuLogEntry) -> CuResult<String> {
let mut format_string = all_interned_strings[entry.msg_index as usize].clone();
let mut vars = HashMap::new();

Expand Down
6 changes: 3 additions & 3 deletions copper_log_reader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ pub fn full_log_dump(mut src: impl Read, index: &Path) -> CuResult<()> {
break;
}

let result = rebuild_logline(&all_strings, entry);
let result = rebuild_logline(&all_strings, &entry);
if result.is_err() {
println!("Failed to rebuild log line: {:?}", result);
continue;
}
println!("Copper: {}", result.unwrap());
println!("Culog: [{}] {}", entry.time, result.unwrap());
}
Ok(())
}
Expand Down Expand Up @@ -81,7 +81,7 @@ mod tests {

#[test]
fn test_extract_low_level_copper_log() {
let hex_string = "01 01 01 00 01 0C 05 7A 61 72 6D 61";
let hex_string = "01 01 00 01 0C 05 7A 61 72 6D 61";
let bytes: Vec<u8> = hex_string
.split_whitespace()
.map(|s| u8::from_str_radix(s, 16).expect("Parse error"))
Expand Down
5 changes: 3 additions & 2 deletions copper_log_runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl LoggerRuntime {
if let Ok(mut cu_log_entry) = receiver.recv() {
// We don't need to be precise on this clock.
// If the user wants to really log a clock they should add it as a structured field.
cu_log_entry.time = clock.recent();
cu_log_entry.time = clock.now();
if let Err(err) = destination.log(&cu_log_entry) {
eprintln!("Failed to log data: {}", err);
}
Expand All @@ -86,9 +86,10 @@ impl LoggerRuntime {
#[cfg(debug_assertions)]
if let Some(index) = &index {
if let Some(ref logger) = extra_text_logger {
let stringified = copper_log::rebuild_logline(index, cu_log_entry);
let stringified = copper_log::rebuild_logline(index, &cu_log_entry);
match stringified {
Ok(s) => {
let s = format!("[{}] {}", cu_log_entry.time, s);
logger.log(
&Record::builder()
// TODO: forward this info in the CuLogEntry
Expand Down

0 comments on commit 1839bd4

Please sign in to comment.