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))
}
});