wpilog_rs/
lib.rs

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