Skip to main content

gondola_core/monitoring/
wastie.rs

1// This file is part of gaps-online-software and published 
2// under the GPLv3 license
3
4use crate::prelude::*;
5
6// Sip (CSBF provided Gps position data
7#[derive(Debug, Copy, Clone, PartialEq)]
8#[cfg_attr(feature="pybindings", pyclass)] 
9pub struct WastieMoniData {
10  elapsed_time     : u16,
11  threshold_mode   : u8 ,
12  threshold_value  : u32,
13  hits_processed   : u32,
14  hits_removed     : u32,
15  events_processed : u32,
16  spectrum         : [u32;5],
17  // not serialized 
18  timestamp        : u64,
19  board_id         : u8, 
20}
21
22impl WastieMoniData {
23
24  pub fn new() -> Self {
25    Self { 
26      elapsed_time     : 0,
27      threshold_mode   : 0,
28      threshold_value  : 0,
29      hits_processed   : 0,
30      hits_removed     : 0,
31      events_processed : 0,
32      spectrum         : [0;5],
33      timestamp        : 0,
34      board_id         : 0,
35    } 
36  }
37}
38
39#[cfg(feature = "random")]
40impl FromRandom for WastieMoniData {    
41  fn from_random() -> Self {
42    let mut moni          = Self::new();
43    let mut rng           = rand::rng();
44    moni.elapsed_time     = rng.random::<u16>();
45    moni.threshold_mode   = rng.random::<u8>();
46    moni.threshold_value  = rng.random::<u32>();
47    moni.hits_processed   = rng.random::<u32>();
48    moni.hits_removed     = rng.random::<u32>();
49    moni.events_processed = rng.random::<u32>();
50    for k in 0..5 {
51      moni.spectrum[k]    = rng.random::<u32>();
52    }
53    //moni.spectrum         : [0;5]
54    moni.timestamp        = rng.random::<u64>();
55    moni.board_id         = rng.random::<u8>();
56    moni
57  } 
58} 
59
60impl Default for WastieMoniData {
61  fn default() -> Self {
62    Self::new()
63  }
64}
65
66impl Serialization for WastieMoniData { 
67  // FIXME - add size field
68
69  fn from_bytestream(stream : &Vec<u8>,
70                     pos    : &mut usize)
71    -> Result<Self, SerializationError> {
72    if stream.len() < Self::SIZE {
73      return Err(SerializationError::StreamTooShort);
74    }
75    let mut moni    = Self::new();
76    moni.elapsed_time     = parse_u16(stream, pos); 
77    moni.threshold_mode   = parse_u8(stream, pos); 
78    moni.threshold_value  = parse_u32(stream, pos); 
79    moni.hits_processed   = parse_u32(stream, pos); 
80    moni.hits_removed     = parse_u32(stream, pos); 
81    moni.events_processed = parse_u32(stream, pos); 
82    for k in 0..5 {
83      moni.spectrum[k] = parse_u32(stream, pos); 
84    }
85    Ok(moni)
86  }
87}
88
89impl MoniData for WastieMoniData {
90  
91  fn get_board_id(&self) -> u8 {
92    return self.board_id;
93  }
94
95  fn get_timestamp(&self) -> u64 {
96    self.timestamp 
97  }
98
99  fn set_timestamp(&mut self, ts: u64) {
100    self.timestamp = ts;
101  }
102
103  fn keys() -> Vec<&'static str> {
104    vec!["board_id",
105         "elapsed_time",
106         "threshold_mode",
107         "threshold_value",
108         "hits_processed",
109         "hits_removed",
110         "events_processed",
111         "spectrum0",
112         "spectrum1",
113         "spectrum2",
114         "spectrum3",
115         "spectrum4",
116         "timestamp"]
117  }
118
119  fn get(&self, varname : &str) -> Option<f32> {
120    match varname {
121      "board_id"          => Some(self.board_id as f32),
122      "timestamp"         => Some(self.timestamp as f32),
123      "elapsed_time"      => Some(self.elapsed_time as f32),
124      "threshold_mode"    => Some(self.threshold_mode as f32),
125      "threshold_value"   => Some(self.threshold_value as f32),
126      "hits_processed"    => Some(self.hits_processed as f32),
127      "hits_removed"      => Some(self.hits_removed as f32),
128      "events_processed"  => Some(self.events_processed as f32),
129      "spectrum0"         => Some(self.spectrum[0] as f32),
130      "spectrum1"         => Some(self.spectrum[1] as f32),
131      "spectrum2"         => Some(self.spectrum[2] as f32),
132      "spectrum3"         => Some(self.spectrum[3] as f32),
133      "spectrum4"         => Some(self.spectrum[4] as f32),
134      _            => None
135    }
136  }  
137}
138
139impl TelemetryPackable for WastieMoniData {
140  const TEL_PACKET_TYPE : TelemetryPacketType = TelemetryPacketType::WastieHK;
141}
142
143impl fmt::Display for WastieMoniData {
144  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
145    let mut repr = String::from("<WastieMoniData: ");
146    repr        += &(format!("\n elapsed_time     : {} ", self.elapsed_time    ));
147    repr        += &(format!("\n threshold_mode   : {} ", self.threshold_mode  ));
148    repr        += &(format!("\n threshold_value  : {} ", self.threshold_value ));
149    repr        += &(format!("\n hits_processed   : {} ", self.hits_processed  ));
150    repr        += &(format!("\n hits_removed     : {} ", self.hits_removed    ));
151    repr        += &(format!("\n events_processed : {} ", self.events_processed));
152    repr        += &(format!("\n spectrum0        : {} ", self.spectrum[0]     ));
153    repr        += &(format!("\n spectrum1        : {} ", self.spectrum[1]     ));
154    repr        += &(format!("\n spectrum2        : {} ", self.spectrum[2]     ));
155    repr        += &(format!("\n spectrum3        : {} ", self.spectrum[3]     ));
156    repr        += &(format!("\n spectrum4        : {}>", self.spectrum[4]     ));
157    write!(f, "{}", repr)
158  }
159}
160
161moniseries_telemetry!(WastieMoniDataSeries, WastieMoniData);
162
163#[cfg(feature="pybindings")]
164pythonize_monidata!(WastieMoniData);
165
166#[cfg(feature="pybindings")]
167pythonize_telemetry_only!(WastieMoniData);
168