1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
use crate::arnalisa::LoadableDevice; use crate::{file_load_json as load_json, LoadPathPattern, Result}; use arnalisa::bins::SourceSinkDescription; use indexmap::IndexSet; use std::path::PathBuf; #[derive(Clone, Debug)] pub struct Device { inner: crate::filesystem::Device, } impl Device { pub fn new(inner: crate::filesystem::Device) -> Self { Device { inner } } pub fn calibration_dir(&self, calibration_id: &str) -> PathBuf { self.inner .description_calibration_dir(calibration_id) .join("arnalisa") } pub fn calibration_bin_file( &self, calibration_id: &str, bin_id: &str, ) -> PathBuf { self.calibration_dir(calibration_id) .join(format!("{}.json", bin_id)) } pub fn sampling_dir(&self, sampling_id: &str) -> PathBuf { self.inner.sampling_dir(sampling_id).join("arnalisa") } pub fn sampling_bin_file( &self, sampling_id: &str, bin_id: &str, ) -> PathBuf { self.sampling_dir(sampling_id) .join(format!("{}.json", bin_id)) } } impl LoadableDevice for Device { fn load_calibration_bin_index( &self, calibration_id: &str, ) -> Result<IndexSet<String>> { IndexSet::load_path_pattern_from_dir( self.calibration_dir(calibration_id), "*.json", ) } fn load_calibration_bin( &self, calibration_id: &str, bin_id: &str, ) -> Result<SourceSinkDescription> { load_json(self.calibration_bin_file(calibration_id, bin_id)) } fn load_sampling_bin_index( &self, sampling_id: &str, ) -> Result<IndexSet<String>> { IndexSet::load_path_pattern_from_dir( self.sampling_dir(sampling_id), "*.json", ) } fn load_sampling_bin( &self, sampling_id: &str, bin_id: &str, ) -> Result<SourceSinkDescription> { load_json(self.sampling_bin_file(sampling_id, bin_id)) } }