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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
use super::*;
use byteorder::{LittleEndian, WriteBytesExt};
pub trait Message {
fn serialize(&self) -> Vec<u8>;
}
pub struct SetAcsMode {
pub id: u8,
pub mode: u8,
pub qbi_cmd: [i16; 4],
}
impl Default for SetAcsMode {
fn default() -> Self {
SetAcsMode {
id: 0,
mode: 0,
qbi_cmd: [0; 4],
}
}
}
impl Message for SetAcsMode {
fn serialize(&self) -> Vec<u8> {
let mut vec = SYNC.to_vec();
vec.push(self.id);
vec.push(self.mode);
vec.write_i16::<LittleEndian>(self.qbi_cmd[0]).unwrap();
vec.write_i16::<LittleEndian>(self.qbi_cmd[1]).unwrap();
vec.write_i16::<LittleEndian>(self.qbi_cmd[2]).unwrap();
vec.write_i16::<LittleEndian>(self.qbi_cmd[3]).unwrap();
vec.append(&mut vec![0; 26]);
vec
}
}
pub struct SetAcsModeSun {
pub id: u8,
pub mode: u8,
pub sun_angle_enable: i16,
pub sun_rot_angle: f32,
}
impl Default for SetAcsModeSun {
fn default() -> Self {
SetAcsModeSun {
id: 0,
mode: 0,
sun_angle_enable: 0,
sun_rot_angle: 0.0,
}
}
}
impl Message for SetAcsModeSun {
fn serialize(&self) -> Vec<u8> {
let mut vec = SYNC.to_vec();
vec.push(self.id);
vec.push(self.mode);
vec.write_i16::<LittleEndian>(self.sun_angle_enable)
.unwrap();
vec.write_f32::<LittleEndian>(self.sun_rot_angle).unwrap();
vec.append(&mut vec![0; 28]);
vec
}
}
pub struct SetGPSTime {
pub id: u8,
pub gps_time: u32,
}
impl Default for SetGPSTime {
fn default() -> Self {
SetGPSTime {
id: 0x44,
gps_time: 0,
}
}
}
impl Message for SetGPSTime {
fn serialize(&self) -> Vec<u8> {
let mut vec = SYNC.to_vec();
vec.push(self.id);
vec.write_u32::<LittleEndian>(self.gps_time).unwrap();
vec.append(&mut vec![0; 31]);
vec
}
}
pub struct SetRV {
pub id: u8,
pub eci_pos: [f32; 3],
pub eci_vel: [f32; 3],
pub time_epoch: u32,
}
impl Default for SetRV {
fn default() -> Self {
SetRV {
id: 0x41,
eci_pos: [0.0, 0.0, 0.0],
eci_vel: [0.0, 0.0, 0.0],
time_epoch: 0,
}
}
}
impl Message for SetRV {
fn serialize(&self) -> Vec<u8> {
let mut vec = SYNC.to_vec();
vec.push(self.id);
vec.write_f32::<LittleEndian>(self.eci_pos[0]).unwrap();
vec.write_f32::<LittleEndian>(self.eci_pos[1]).unwrap();
vec.write_f32::<LittleEndian>(self.eci_pos[2]).unwrap();
vec.write_f32::<LittleEndian>(self.eci_vel[0]).unwrap();
vec.write_f32::<LittleEndian>(self.eci_vel[1]).unwrap();
vec.write_f32::<LittleEndian>(self.eci_vel[2]).unwrap();
vec.write_u32::<LittleEndian>(self.time_epoch).unwrap();
vec.append(&mut vec![0; 7]);
vec
}
}
pub struct RequestReset(pub [u8; 38]);
impl Default for RequestReset {
fn default() -> Self {
let mut array = [0; 38];
array[0] = 0x90;
array[1] = 0xEB;
array[2] = 0x5A;
RequestReset(array)
}
}
impl Message for RequestReset {
fn serialize(&self) -> Vec<u8> {
self.0.to_vec()
}
}
pub struct ConfirmReset([u8; 38]);
impl Default for ConfirmReset {
fn default() -> Self {
let mut array = [0; 38];
array[0] = 0x90;
array[1] = 0xEB;
array[2] = 0xF1;
ConfirmReset(array)
}
}
impl Message for ConfirmReset {
fn serialize(&self) -> Vec<u8> {
self.0.to_vec()
}
}