gondola_core/packets/
tracker_header.rs

1//! Re-implementation of the tracker header which is attached 
2//! to each telemetry packet.
3//! Re-implemented from bfsw
4// The following file is part of gaps-online-software and published 
5// under the GPLv3 license
6
7use crate::prelude::*;
8
9/// A header 
10#[derive(Clone)]
11#[cfg_attr(feature="pybindings", pyclass)]
12pub struct TrackerHeader {
13  pub sync        : u16,
14  pub crc         : u16,
15  pub sys_id      : u8,
16  pub packet_id   : u8,
17  pub length      : u16,
18  pub daq_count   : u16,
19  pub sys_time    : u64,
20  pub version     : u8,
21} 
22
23impl TrackerHeader {
24  
25  pub fn new() -> Self {
26    Self {
27      sync        : 0,
28      crc         : 0,
29      sys_id      : 0,
30      packet_id   : 0,
31      length      : 0,
32      daq_count   : 0,
33      sys_time    : 0,
34      version     : 0,
35    }
36  }
37} 
38
39impl Serialization for TrackerHeader { 
40  const SIZE : usize = 17;
41
42  fn from_bytestream(stream: &Vec<u8>,
43                     pos: &mut usize)
44    -> Result<Self, SerializationError> {
45    if stream.len() <= Self::SIZE {
46      error!("Unable to decode TrackerHeader!"); 
47      return Err(SerializationError::StreamTooShort);
48    }
49    let mut h     = TrackerHeader::new();
50    h.sync        = parse_u16(stream, pos);
51    h.crc         = parse_u16(stream, pos); 
52    h.sys_id      = parse_u8 (stream, pos);
53    h.packet_id   = parse_u8 (stream, pos);
54    h.length      = parse_u16(stream, pos);
55    h.daq_count   = parse_u16(stream, pos);
56    let lower     = parse_u32(stream, pos);
57    let upper     = parse_u16(stream, pos);
58    h.sys_time    = make_systime(lower, upper);
59    h.version     = parse_u8 (stream, pos);
60    Ok(h)
61  }
62}
63
64impl fmt::Display for TrackerHeader {
65  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
66    let mut repr = String::from("<TrackerHeader");
67    repr    += &(format!("\n  Sync     : {}", self.sync));
68    repr    += &(format!("\n  Crc      : {}", self.crc));
69    repr    += &(format!("\n  PacketID : {}", self.packet_id));
70    repr    += &(format!("\n  Length   : {}", self.length));
71    repr    += &(format!("\n  DAQ Cnt  : {}", self.daq_count));
72    repr    += &(format!("\n  Sys Time : {}", self.sys_time));
73    repr    += &(format!("\n  Version  : {}>", self.version));
74    write!(f, "{}", repr)
75  }
76}
77
78//------------------------------------------------------
79
80#[cfg(feature="pybindings")]
81#[pymethods]
82impl TrackerHeader { 
83
84  #[getter]
85  fn get_sync(&self)        -> u16 {
86    self.sync
87  }
88  
89  #[getter]
90  fn get_crc(&self)         -> u16 {
91    self.crc
92  }
93  
94  #[getter]
95  fn get_sys_id(&self)      -> u8 {
96    self.sys_id
97  }
98  
99  #[getter]
100  fn get_packet_id(&self)   -> u8 {
101    self.packet_id
102  }
103  
104  #[getter]
105  fn get_length(&self)      -> u16 {
106    self.length
107  }
108  
109  #[getter]
110  fn get_daq_count(&self)   -> u16 {
111    self.daq_count
112  }
113  
114  #[getter]
115  fn get_sys_time(&self)    -> u64 {
116    self.sys_time
117  }
118  
119  #[getter]
120  fn get_version(&self)     -> u8 {
121    self.version
122  }
123}
124
125
126
127#[cfg(feature="pybindings")]
128pythonize!(TrackerHeader);
129