wpilog/
lib.rs

1use std::path::{Path, PathBuf};
2
3#[macro_use]
4pub mod macros;
5#[macro_use]
6extern crate bitflags;
7
8pub mod error;
9pub mod log;
10pub(crate) mod records;
11pub(crate) mod util;
12
13#[cfg(test)]
14mod test;
15
16pub use error::DatalogError;
17
18///Microseconds
19type WpiTimestamp = u64;
20///A unique identifier for a data entry
21type EntryId = u32;
22///A string representing a data entry name
23type EntryName = String;
24///A string representing a data entry type
25type EntryType = String;
26///A string in json format representing data entry metadata
27type EntryMetadata = String;
28///an array of little endian bytes
29type LeBytes = Vec<u8>;
30///A little endian byte
31type LeByte = u8;
32///A hash map of entry id to entry types
33type EntryTypeMap = std::collections::HashMap<EntryId, EntryType>;
34///A hash map of entry id to entry names
35type EntryIdToNameMap = bimap::BiMap<EntryId, EntryName>;
36
37pub fn sec_from_micros(micros: WpiTimestamp) -> f64 {
38    micros as f64 / 1_000_000.0
39}
40
41pub fn now() -> WpiTimestamp {
42    let now = std::time::SystemTime::now();
43    let duration = now.duration_since(std::time::UNIX_EPOCH).unwrap();
44    duration.as_micros() as WpiTimestamp
45}
46
47pub fn absolute_path(rel_path: &Path) -> PathBuf {
48    //get the current working directory
49    let cwd = std::env::current_dir().unwrap();
50    //append the path to the current working directory
51    cwd.join(rel_path)
52}