melvin_ob/http_handler/http_response/observation.rs
1use crate::http_handler::http_response::response_common::SerdeJSONBodyHTTPResponseType;
2use chrono::{DateTime, Utc};
3
4/// Response type for the /observation endpoint
5#[derive(serde::Deserialize, Debug)]
6pub(crate) struct ObservationResponse {
7 /// The current `FlightState` encoded as a string (e.g. "acquisition" or "safe").
8 state: String,
9 /// The current `CameraAngle` encoded as a string (e.g. "normal" or "narrow").
10 angle: String,
11 /// The current simulation speed factor.
12 simulation_speed: u32,
13 /// The current position on the x-axis.
14 width_x: u16,
15 /// The current position on the y-axis.
16 height_y: u16,
17 /// The current velocity in x-direction.
18 vx: f64,
19 /// The current velocity in y-direction.
20 vy: f64,
21 /// The current charge level of the battery.
22 battery: f64,
23 /// The current maximum charge level of the battery.
24 max_battery: f64,
25 /// The amount of fuel thats left.
26 fuel: f64,
27 /// The distance MELVIN already covered.
28 distance_covered: f64,
29 /// The mapping coverage per lens.
30 area_covered: AreaCoveredByLens,
31 /// The received and sent data volume.
32 data_volume: DataVolume,
33 /// The number of images that were already shot.
34 images_taken: u32,
35 /// The time melvin has been active.
36 active_time: f64,
37 /// The number of objectives that are already finished.
38 objectives_done: u16,
39 /// The number of points that were awarded for the finished objectives.
40 objectives_points: u32,
41 /// The current UTC Timestamp.
42 timestamp: DateTime<Utc>,
43}
44
45impl SerdeJSONBodyHTTPResponseType for ObservationResponse {}
46
47impl ObservationResponse {
48 /// Returns the current flight state as a string.
49 pub(crate) fn state(&self) -> &str { self.state.as_str() }
50 /// Returns the current camera lens as a string.
51 pub(crate) fn angle(&self) -> &str { self.angle.as_str() }
52 /// Returns the current simulation speed factor.
53 pub(crate) fn simulation_speed(&self) -> u32 { self.simulation_speed }
54 /// Returns the current position on the x-axis.
55 pub(crate) fn pos_x(&self) -> u16 { self.width_x }
56 /// Returns the current position on the y-axis.
57 pub(crate) fn pos_y(&self) -> u16 { self.height_y }
58 /// Returns the velocity in x-direction.
59 pub(crate) fn vel_x(&self) -> f64 { self.vx }
60 /// Returns the velocity in y-direction.
61 pub(crate) fn vel_y(&self) -> f64 { self.vy }
62 /// Returns the current battery level.
63 pub(crate) fn battery(&self) -> f64 { self.battery }
64 /// Returns the current maximum battery level.
65 pub(crate) fn max_battery(&self) -> f64 { self.max_battery }
66 /// Returns the remaining amount of fuel.
67 pub(crate) fn fuel(&self) -> f64 { self.fuel }
68 /// Returns the current timestamp in UTC.
69 pub(crate) fn timestamp(&self) -> DateTime<Utc> { self.timestamp }
70}
71
72/// Struct holding coverage information per camera lens
73#[derive(serde::Deserialize, Debug)]
74pub(crate) struct AreaCoveredByLens {
75 /// The coverage from `CameraAngle::Narrow`.
76 narrow: f64,
77 /// The coverage from `CameraAngle::Normal`.
78 normal: f64,
79 /// The coverage from `CameraAngle::Wide`.
80 wide: f64,
81}
82
83/// Struct containing information on the received and sent number of bytes
84#[derive(serde::Deserialize, Debug)]
85pub(crate) struct DataVolume {
86 /// Number of bytes that were already sent.
87 data_volume_sent: u32,
88 /// Number of bytes that were already received
89 data_volume_received: u32,
90}