glue/
types.rs

1//! All public facing glue `*Msg` types.
2
3// External Crates
4use chrono::{DateTime, Utc};
5use serde::de::Error;
6use serde::{Deserialize, Serialize};
7// Local Modules
8use crate::util::{ByteArraySerializeDeserialize, JsonSerializeDeserialize};
9// Local Derive Macros
10use glue_derive::{ByteArrayToFromZMQ, JsonToFromZMQ};
11
12// Collection of all `glue` related types in a single enum.
13#[derive(Serialize, Deserialize, Debug, ByteArrayToFromZMQ)]
14pub enum GlueMsg {
15    Form(Form),
16    Image(Image),
17    ImageTagged(ImageTagged),
18    GPS(Gps),
19    Target(Target),
20    Offboard(Offboard),
21    Heartbeat(Heartbeat),
22    GlueError(String),
23    SauronProphecy(SauronProphecy),
24    SauronResult(SauronResult),
25}
26
27/// Standard message
28#[derive(Serialize, Deserialize, Debug, JsonToFromZMQ)]
29pub struct Form {
30    pub state: String,
31}
32
33/// Image message (ODLC)
34#[derive(Serialize, Deserialize, Debug, ByteArrayToFromZMQ)]
35pub struct Image {
36    pub image: String,
37    pub time: DateTime<Utc>,
38}
39
40/// Dad and Pipeline message (ODLC)
41#[derive(Serialize, Deserialize, Debug, ByteArrayToFromZMQ)]
42pub struct ImageTagged {
43    pub image: String,
44    pub long: f64,
45    pub lat: f64,
46    pub time: DateTime<Utc>,
47}
48
49#[derive(Serialize, Deserialize, Debug, Clone, JsonToFromZMQ)]
50pub struct SauronProphecy {
51    pub image_path: String,
52    pub in_bounds: bool,
53    pub gps: Gps,
54}
55
56#[derive(Serialize, Deserialize, Debug, Clone, JsonToFromZMQ)]
57pub struct SauronResult {
58    pub image_path: String,
59    pub detections: Detections,
60    pub target_gps: Target,
61}
62
63#[derive(Serialize, Deserialize, Debug, Clone, JsonToFromZMQ)]
64pub struct ImagePathGPS {
65    pub image_path: String,  // path where the image is located
66    pub image_gps_data: Gps, // The GPS data for the image
67    pub heading: f64,        // The Heading of the plane during picture
68}
69
70#[derive(Serialize, Deserialize, Debug, Clone, JsonToFromZMQ)]
71pub struct DetectToLocalData {
72    pub image_path: String,
73    pub image_gps_data: Gps,    // The GPS data for the image
74    pub heading: f64,           // The Heading of the plane during picture
75    pub detections: Detections, // Weird "vector" of Detections. Should be fixed in main
76}
77
78#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
79pub struct BoxDetection {
80    pub x1: f32,            // bounding box left-top x
81    pub y1: f32,            // bounding box left-top y
82    pub x2: f32,            // bounding box right-bottom x
83    pub y2: f32,            // bounding box right-bottom y
84    pub class_index: usize, // class index
85    pub conf: f32,          // confidence score
86}
87pub type Detections = Vec<BoxDetection>;
88
89/// GPS message (GNC)
90#[derive(Serialize, Deserialize, Debug, ByteArrayToFromZMQ, Clone, Copy)]
91pub struct Gps {
92    pub lat: f64,
93    pub long: f64,
94    pub alt: f64,
95    pub heading: f64,
96
97    #[serde(with = "chrono::serde::ts_milliseconds")]
98    pub time: DateTime<Utc>,
99}
100
101/// Target Message (GNC)
102#[derive(Serialize, Deserialize, Debug, ByteArrayToFromZMQ, Clone, Copy)]
103pub struct Target {
104    pub lat: f64,
105    pub long: f64,
106}
107
108/// Offboard Message (GNC)
109#[derive(Serialize, Deserialize, Debug, JsonToFromZMQ)]
110pub struct Offboard {
111    pub latitude: f64,
112    pub longitude: f64,
113    pub altitude: f64,
114    pub is_servo: bool,
115    pub id: u32,
116}
117
118/// Heartbeat/Keep-Alive Message (Ground Station)
119#[derive(Serialize, Deserialize, Debug, JsonToFromZMQ)]
120pub struct Heartbeat {
121    pub time: DateTime<Utc>,
122}