gondola_core/packets/
bfsw_ack_packet.rs

1// This file is part of gaps-online-software and published 
2// under the GPLv3 license
3
4use crate::prelude::*;
5
6/// The acknowledgement packet used within the 
7/// bfsw code
8#[cfg_attr(feature="pybindings", pyclass)]
9pub struct AckBfsw {
10  pub header    : TelemetryPacketHeader,
11  pub ack_type  : u8,
12  pub ret_code1 : u8,
13  pub ret_code2 : u8,
14  pub body      : Vec<u8>
15}
16
17impl AckBfsw {
18  pub fn new() -> Self {
19    //let mut header = TelemetryHeader::new(),
20
21    Self {
22      header    : TelemetryPacketHeader::new(),
23      ack_type  : 1,
24      ret_code1 : 0,
25      ret_code2 : 0,
26      body      : Vec::<u8>::new()
27    }
28  }
29  
30  //pub fn to_bytestream(&self) -> Vec<u8> {
31  //  let mut stream = Vec::<u8>::new();
32  //  let mut s_head = self.header.to_bytestream();
33  //  stream.append(&mut s_head);
34  //  stream.extend_from_slice(self.payload.as_slice());
35  //  //stream.append(&mut self.payload);
36  //  stream
37  //}
38}
39
40impl Serialization for AckBfsw {
41  
42  const HEAD : u16 = 0x90eb;
43  const TAIL : u16 = 0x0000; // there is no tail for telemetry packets
44  const SIZE : usize = 13; 
45
46  fn from_bytestream(stream : &Vec<u8>,
47                     pos    : &mut usize)
48    -> Result<Self, SerializationError> {
49    if stream.len() < *pos + 3 {
50      return Err(SerializationError::StreamTooShort);
51    }
52    let mut ack   = AckBfsw::new();
53    ack.ack_type  = parse_u8(stream, pos);
54    ack.ret_code1 = parse_u8(stream, pos);
55    ack.ret_code2 = parse_u8(stream, pos);
56    Ok(ack)
57  }
58  
59  fn to_bytestream(&self) -> Vec<u8> {
60    let mut stream = Vec::<u8>::new();
61    stream.push(self.ack_type);
62    stream.push(self.ret_code1);
63    stream.push(self.ret_code2);
64    stream
65  }
66}
67
68impl TofPackable for AckBfsw {
69  const TOF_PACKET_TYPE : TofPacketType = TofPacketType::BfswAckPacket;
70}
71
72impl fmt::Display for AckBfsw {
73  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
74    let mut repr = String::from("<AckBfsw:");
75    //repr += &(format!("\n  Header      : {}" ,self.sync));
76    //repr += &(format!("\n  Packet Type : {}" ,self.ptype));
77    //repr += &(format!("\n  Timestamp   : {}" ,self.timestamp));
78    repr += &(format!("\n  Ack Type    : {}" ,self.ack_type));
79    repr += &(format!("\n  Ret Code1   : {}" ,self.ret_code1));
80    repr += &(format!("\n  Ret Code2   : {}>",self.ret_code2));
81    write!(f, "{}", repr)
82  }
83}
84
85//-----------------------------------------------------
86
87#[cfg(feature="pybindings")]
88#[pymethods]
89impl AckBfsw {
90  #[getter]
91  fn get_header(&self)    -> TelemetryPacketHeader {
92    self.header.clone()
93  }
94  
95  #[getter]
96  fn get_ack_type(&self)  -> u8 {
97    self.ack_type
98  }
99
100  #[getter]
101  fn get_ret_code1(&self) -> u8 {
102    self.ret_code1
103  }
104
105  #[getter]
106  fn get_ret_code2(&self) -> u8 {
107    self.ret_code2
108  }
109 
110  #[getter]
111  fn get_body(&self)      -> Vec<u8> {
112    self.body.clone()
113  }
114}
115
116#[cfg(feature="pybindings")]
117pythonize!(AckBfsw);
118