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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
use juniper::FieldResult;
use mai400_api::*;
#[derive(GraphQLObject)]
pub struct GenericResponse {
pub errors: String,
pub success: bool,
}
#[derive(GraphQLEnum, Clone, Copy)]
pub enum AckCommand {
None,
Noop,
ControlPower,
ConfigureHardware,
TestHardware,
IssueRawCommand,
SetMode,
Update,
}
#[derive(GraphQLObject)]
pub struct ConfigureHardwareResponse {
pub errors: String,
pub success: bool,
}
#[derive(GraphQLEnum, Clone, Eq, PartialEq, Debug)]
pub enum PowerState {
On,
Off,
Reset,
}
#[derive(GraphQLObject)]
pub struct GetPowerResponse {
pub state: PowerState,
pub uptime: i32,
}
#[derive(GraphQLObject)]
pub struct ControlPowerResponse {
pub errors: String,
pub success: bool,
pub power: PowerState,
}
#[derive(GraphQLEnum)]
pub enum TestType {
Integration,
Hardware,
}
pub enum TestResults {
Integration(IntegrationTestResults),
Hardware(HardwareTestResults),
}
graphql_union!(TestResults: () |&self| {
instance_resolvers: |&_| {
&IntegrationTestResults => match *self {
TestResults::Integration(ref i) => Some(i),
_ => None
},
&HardwareTestResults => match *self { TestResults::Hardware(ref h) => Some(h), _ => None},
}
});
#[derive(GraphQLObject)]
pub struct IntegrationTestResults {
pub errors: String,
pub success: bool,
pub telemetry_nominal: StdTelem,
pub telemetry_debug: TelemetryDebug,
}
#[derive(GraphQLObject)]
pub struct HardwareTestResults {
pub errors: String,
pub success: bool,
pub data: String,
}
#[derive(GraphQLEnum, Clone, Copy)]
pub enum Mode {
TestMode = 0,
RateNulling = 1,
Reserved1 = 2,
NadirPointing = 3,
LatLongPointing = 4,
QbxMode = 5,
Reserved2 = 6,
NormalSun = 7,
LatLongSun = 8,
Qintertial = 9,
Reserved3 = 10,
Qtable = 11,
SunRam = 12,
Unknown = 0xFF,
}
impl From<u8> for Mode {
fn from(raw: u8) -> Mode {
match raw {
0 => Mode::TestMode,
1 => Mode::RateNulling,
2 => Mode::Reserved1,
3 => Mode::NadirPointing,
4 => Mode::LatLongPointing,
5 => Mode::QbxMode,
6 => Mode::Reserved2,
7 => Mode::NormalSun,
8 => Mode::LatLongSun,
9 => Mode::Qintertial,
10 => Mode::Reserved3,
11 => Mode::Qtable,
12 => Mode::SunRam,
_ => Mode::Unknown,
}
}
}
#[derive(GraphQLInputObject)]
pub struct RVInput {
pub eci_pos: Vec<f64>,
pub eci_vel: Vec<f64>,
pub time_epoch: i32,
}
#[derive(GraphQLObject)]
pub struct Spin {
pub x: f64,
pub y: f64,
pub z: f64,
}
#[derive(GraphQLObject)]
pub struct Telemetry {
pub nominal: StdTelem,
pub debug: TelemetryDebug,
}
#[derive(Debug, Default, PartialEq)]
pub struct StdTelem(pub StandardTelemetry);
graphql_object!(StdTelem: () |&self| {
field tlm_counter() -> FieldResult<i32> {
Ok(i32::from(self.0.tlm_counter))
}
field gps_time() -> FieldResult<i32> {
Ok(self.0.gps_time as i32)
}
field time_subsec() -> FieldResult<i32> {
Ok(i32::from(self.0.time_subsec))
}
field cmd_valid_cntr() -> FieldResult<i32> {
Ok(i32::from(self.0.cmd_valid_cntr))
}
field cmd_invalid_cntr() -> FieldResult<i32> {
Ok(i32::from(self.0.cmd_invalid_cntr))
}
field cmd_invalid_chksum_cntr() -> FieldResult<i32> {
Ok(i32::from(self.0.cmd_invalid_chksum_cntr))
}
field last_command() -> FieldResult<i32> {
Ok(i32::from(self.0.last_command))
}
field acs_mode() -> FieldResult<Mode> {
Ok(Mode::from(self.0.acs_mode))
}
field css() -> FieldResult<Vec<i32>> {
Ok(self.0.css.iter().map(|&elem| i32::from(elem)).collect())
}
field eclipse_flag() -> FieldResult<i32> {
Ok(i32::from(self.0.eclipse_flag))
}
field sun_vec_b() -> FieldResult<Vec<i32>> {
Ok(self.0.sun_vec_b.iter().map(|&elem| i32::from(elem)).collect())
}
field i_b_field_meas() -> FieldResult<Vec<i32>> {
Ok(self.0.i_b_field_meas.iter().map(|&elem| i32::from(elem)).collect())
}
field bd() -> FieldResult<Vec<f64>> {
Ok(self.0.bd.iter().map(|&elem| f64::from(elem)).collect())
}
field rws_speed_cmd() -> FieldResult<Vec<i32>> {
Ok(self.0.rws_speed_cmd.iter().map(|&elem| i32::from(elem)).collect())
}
field rws_speed_tach() -> FieldResult<Vec<i32>> {
Ok(self.0.rws_speed_tach.iter().map(|&elem| i32::from(elem)).collect())
}
field rwa_torque_cmd() -> FieldResult<Vec<f64>> {
Ok(self.0.rwa_torque_cmd.iter().map(|&elem| f64::from(elem)).collect())
}
field gc_rwa_torque_cmd() -> FieldResult<Vec<i32>> {
Ok(self.0.gc_rwa_torque_cmd.iter().map(|&elem| i32::from(elem)).collect())
}
field torque_coil_cmd() -> FieldResult<Vec<f64>> {
Ok(self.0.torque_coil_cmd.iter().map(|&elem| f64::from(elem)).collect())
}
field gc_torque_coil_cmd() -> FieldResult<Vec<i32>> {
Ok(self.0.gc_torque_coil_cmd.iter().map(|&elem| i32::from(elem)).collect())
}
field qbo_cmd() -> FieldResult<Vec<i32>> {
Ok(self.0.qbo_cmd.iter().map(|&elem| i32::from(elem)).collect())
}
field qbo_hat() -> FieldResult<Vec<i32>> {
Ok(self.0.qbo_hat.iter().map(|&elem| i32::from(elem)).collect())
}
field angle_to_go() -> FieldResult<f64> {
Ok(f64::from(self.0.angle_to_go))
}
field q_error() -> FieldResult<Vec<i32>> {
Ok(self.0.q_error.iter().map(|&elem| i32::from(elem)).collect())
}
field omega_b() -> FieldResult<Vec<f64>> {
Ok(self.0.omega_b.iter().map(|&elem| f64::from(elem)).collect())
}
field rotating_variable_a() -> FieldResult<i32> {
Ok(self.0.rotating_variable_a as i32)
}
field rotating_variable_b() -> FieldResult<i32> {
Ok(self.0.rotating_variable_b as i32)
}
field rotating_variable_c() -> FieldResult<i32> {
Ok(self.0.rotating_variable_c as i32)
}
field nb() -> FieldResult<Vec<i32>> {
Ok(self.0.nb.iter().map(|&elem| i32::from(elem)).collect())
}
field neci() -> FieldResult<Vec<i32>> {
Ok(self.0.neci.iter().map(|&elem| i32::from(elem)).collect())
}
});
#[derive(GraphQLObject)]
pub struct TelemetryDebug {
pub irehs: IREHSTelem,
pub raw_imu: RawIMUTelem,
pub rotating: Rotating,
}
#[derive(Debug, Default, PartialEq)]
pub struct IREHSTelem(pub IREHSTelemetry);
#[derive(GraphQLObject)]
pub struct ThermopileStruct {
dip_angle: i32,
earth_limb: ThermopileSensor,
earth_ref: ThermopileSensor,
space_ref: ThermopileSensor,
wide_fov: ThermopileSensor,
}
#[derive(GraphQLObject)]
pub struct ThermopileSensor {
adc: i32,
temp: i32,
errors: bool,
flags: Vec<String>,
}
graphql_object!(IREHSTelem: () |&self| {
field thermopile_struct_a() -> FieldResult<ThermopileStruct> {
Ok(ThermopileStruct {
dip_angle: self.0.dip_angle_a as i32,
earth_limb: ThermopileSensor {
adc: self.0.thermopiles_a[0] as i32,
temp: self.0.temp_a[0] as i32,
errors: !self.0.solution_degraded[0].is_empty(),
flags: self.0.solution_degraded[0].to_vec()
},
earth_ref: ThermopileSensor {
adc: self.0.thermopiles_a[1] as i32,
temp: self.0.temp_a[1] as i32,
errors: !self.0.solution_degraded[1].is_empty(),
flags: self.0.solution_degraded[1].to_vec()
},
space_ref: ThermopileSensor {
adc: self.0.thermopiles_a[2] as i32,
temp: self.0.temp_a[2] as i32,
errors: !self.0.solution_degraded[2].is_empty(),
flags: self.0.solution_degraded[2].to_vec()
},
wide_fov: ThermopileSensor {
adc: self.0.thermopiles_a[3] as i32,
temp: self.0.temp_a[3] as i32,
errors: !self.0.solution_degraded[3].is_empty(),
flags: self.0.solution_degraded[3].to_vec()
}
}
)
}
field thermopile_struct_b() -> FieldResult<ThermopileStruct> {
Ok(ThermopileStruct {
dip_angle: self.0.dip_angle_b as i32,
earth_limb: ThermopileSensor {
adc: self.0.thermopiles_b[0] as i32,
temp: self.0.temp_b[0] as i32,
errors: !self.0.solution_degraded[4].is_empty(),
flags: self.0.solution_degraded[4].to_vec()
},
earth_ref: ThermopileSensor {
adc: self.0.thermopiles_b[1] as i32,
temp: self.0.temp_b[1] as i32,
errors: !self.0.solution_degraded[5].is_empty(),
flags: self.0.solution_degraded[5].to_vec()
},
space_ref: ThermopileSensor {
adc: self.0.thermopiles_b[2] as i32,
temp: self.0.temp_b[2] as i32,
errors: !self.0.solution_degraded[6].is_empty(),
flags: self.0.solution_degraded[6].to_vec()
},
wide_fov: ThermopileSensor {
adc: self.0.thermopiles_b[3] as i32,
temp: self.0.temp_b[3] as i32,
errors: !self.0.solution_degraded[7].is_empty(),
flags: self.0.solution_degraded[7].to_vec()
}
}
)
}
field thermopiles_a() -> FieldResult<Vec<i32>> {
Ok(self.0.thermopiles_a.iter().map(|&elem| i32::from(elem)).collect())
}
field thermopiles_b() -> FieldResult<Vec<i32>> {
Ok(self.0.thermopiles_b.iter().map(|&elem| i32::from(elem)).collect())
}
field temp_a() -> FieldResult<Vec<i32>> {
Ok(self.0.temp_a.iter().map(|&elem| i32::from(elem)).collect())
}
field temp_b() -> FieldResult<Vec<i32>> {
Ok(self.0.temp_b.iter().map(|&elem| i32::from(elem)).collect())
}
field dip_angle_a() -> FieldResult<i32> {
Ok(i32::from(self.0.dip_angle_a))
}
field dip_angle_b() -> FieldResult<i32> {
Ok(i32::from(self.0.dip_angle_b))
}
field solution_degraded() -> FieldResult<Vec<Vec<String>>> {
let mut parent = vec![];
for elem in self.0.solution_degraded.iter() {
if elem.is_empty() {
parent.push(vec![]);
} else {
parent.push(elem.to_vec());
}
}
Ok(parent)
}
});
#[derive(Debug, Default, PartialEq)]
pub struct RawIMUTelem(pub RawIMU);
graphql_object!(RawIMUTelem: () |&self| {
field accel() -> FieldResult<Vec<i32>> {
Ok(self.0.accel.iter().map(|&elem| i32::from(elem)).collect())
}
field gyro() -> FieldResult<Vec<i32>> {
Ok(self.0.gyro.iter().map(|&elem| i32::from(elem)).collect())
}
field gyro_temp() -> FieldResult<i32> {
Ok(i32::from(self.0.gyro_temp))
}
});
#[derive(Debug, Default, PartialEq)]
pub struct Rotating(pub RotatingTelemetry);
graphql_object!(Rotating: () |&self| {
field b_field_igrf() -> FieldResult<Vec<f64>> {
Ok(self.0.b_field_igrf.iter().map(|&elem| f64::from(elem)).collect())
}
field sun_vec_eph() -> FieldResult<Vec<f64>> {
Ok(self.0.sun_vec_eph.iter().map(|&elem| f64::from(elem)).collect())
}
field sc_pos_eci() -> FieldResult<Vec<f64>> {
Ok(self.0.sc_pos_eci.iter().map(|&elem| f64::from(elem)).collect())
}
field sc_vel_eci() -> FieldResult<Vec<f64>> {
Ok(self.0.sc_vel_eci.iter().map(|&elem| f64::from(elem)).collect())
}
field kepler_elem() -> FieldResult<Kepler> {
Ok(Kepler(self.0.kepler_elem.clone()))
}
field k_bdot() -> FieldResult<Vec<f64>> {
Ok(self.0.k_bdot.iter().map(|&elem| f64::from(elem)).collect())
}
field kp() -> FieldResult<Vec<f64>> {
Ok(self.0.kp.iter().map(|&elem| f64::from(elem)).collect())
}
field kd() -> FieldResult<Vec<f64>> {
Ok(self.0.kd.iter().map(|&elem| f64::from(elem)).collect())
}
field k_unload() -> FieldResult<Vec<f64>> {
Ok(self.0.k_unload.iter().map(|&elem| f64::from(elem)).collect())
}
field css_bias() -> FieldResult<Vec<i32>> {
Ok(self.0.css_bias.iter().map(|&elem| i32::from(elem)).collect())
}
field mag_bias() -> FieldResult<Vec<i32>> {
Ok(self.0.mag_bias.iter().map(|&elem| i32::from(elem)).collect())
}
field rws_volt() -> FieldResult<i32> {
Ok(i32::from(self.0.rws_volt))
}
field rws_press() -> FieldResult<i32> {
Ok(i32::from(self.0.rws_press))
}
field att_det_mode() -> FieldResult<i32> {
Ok(i32::from(self.0.att_det_mode))
}
field rws_reset_cntr() -> FieldResult<Vec<i32>> {
Ok(self.0.rws_reset_cntr.iter().map(|&elem| i32::from(elem)).collect())
}
field sun_mag_aligned() -> FieldResult<i32> {
Ok(i32::from(self.0.sun_mag_aligned))
}
field minor_version() -> FieldResult<i32> {
Ok(i32::from(self.0.minor_version))
}
field mai_sn() -> FieldResult<i32> {
Ok(i32::from(self.0.mai_sn))
}
field orbit_prop_mode() -> FieldResult<i32> {
Ok(i32::from(self.0.orbit_prop_mode))
}
field acs_op_mode() -> FieldResult<i32> {
Ok(i32::from(self.0.acs_op_mode))
}
field proc_reset_cntr() -> FieldResult<i32> {
Ok(i32::from(self.0.proc_reset_cntr))
}
field major_version() -> FieldResult<i32> {
Ok(i32::from(self.0.major_version))
}
field ads_op_mode() -> FieldResult<i32> {
Ok(i32::from(self.0.ads_op_mode))
}
field css_gain() -> FieldResult<Vec<f64>> {
Ok(self.0.css_gain.iter().map(|&elem| f64::from(elem)).collect())
}
field mag_gain() -> FieldResult<Vec<f64>> {
Ok(self.0.mag_gain.iter().map(|&elem| f64::from(elem)).collect())
}
field orbit_epoch() -> FieldResult<i32> {
Ok(self.0.orbit_epoch as i32)
}
field true_anomoly_epoch() -> FieldResult<f64> {
Ok(f64::from(self.0.true_anomoly_epoch))
}
field orbit_epoch_next() -> FieldResult<i32> {
Ok(self.0.orbit_epoch_next as i32)
}
field sc_pos_eci_epoch() -> FieldResult<Vec<f64>> {
Ok(self.0.sc_pos_eci_epoch.iter().map(|&elem| f64::from(elem)).collect())
}
field sc_vel_eci_epoch() -> FieldResult<Vec<f64>> {
Ok(self.0.sc_vel_eci_epoch.iter().map(|&elem| f64::from(elem)).collect())
}
field qb_x_wheel_speed() -> FieldResult<i32> {
Ok(i32::from(self.0.qb_x_wheel_speed))
}
field qb_x_filter_gain() -> FieldResult<f64> {
Ok(f64::from(self.0.qb_x_filter_gain))
}
field qb_x_dipole_gain() -> FieldResult<f64> {
Ok(f64::from(self.0.qb_x_dipole_gain))
}
field dipole_gain() -> FieldResult<Vec<f64>> {
Ok(self.0.dipole_gain.iter().map(|&elem| f64::from(elem)).collect())
}
field wheel_speed_bias() -> FieldResult<Vec<i32>> {
Ok(self.0.wheel_speed_bias.iter().map(|&elem| i32::from(elem)).collect())
}
field cos_sun_mag_align_thresh() -> FieldResult<f64> {
Ok(f64::from(self.0.cos_sun_mag_align_thresh))
}
field unload_ang_thresh() -> FieldResult<f64> {
Ok(f64::from(self.0.unload_ang_thresh))
}
field q_sat() -> FieldResult<f64> {
Ok(f64::from(self.0.q_sat))
}
field rwa_trq_max() -> FieldResult<f64> {
Ok(f64::from(self.0.rwa_trq_max))
}
field rws_motor_current() -> FieldResult<Vec<i32>> {
Ok(self.0.rws_motor_current.iter().map(|&elem| i32::from(elem)).collect())
}
field rws_motor_temp() -> FieldResult<i32> {
Ok(i32::from(self.0.rws_motor_temp))
}
});
#[derive(Debug, Default, PartialEq)]
pub struct Kepler(pub KeplerElem);
graphql_object!(Kepler: () |&self| {
field semi_major_axis() -> FieldResult<f64> {
Ok(f64::from(self.0.semi_major_axis))
}
field eccentricity() -> FieldResult<f64> {
Ok(f64::from(self.0.eccentricity))
}
field inclination() -> FieldResult<f64> {
Ok(f64::from(self.0.inclination))
}
field raan() -> FieldResult<f64> {
Ok(f64::from(self.0.raan))
}
field arg_parigee() -> FieldResult<f64> {
Ok(f64::from(self.0.arg_parigee))
}
field true_anomoly() -> FieldResult<f64> {
Ok(f64::from(self.0.true_anomoly))
}
});