Skip to content

Commit f8d4174

Browse files
committed
feat: defined rust structs for ros2 std_msgs (serde)
1 parent 67a89be commit f8d4174

4 files changed

Lines changed: 144 additions & 0 deletions

File tree

src/comms/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub mod auv_control_board;
22
pub mod control_board;
33
pub mod meb;
4+
pub mod ros2;
45

56
#[macro_export]
67
macro_rules! write_stream_mutexed {

src/comms/ros2/diagnostic_msgs.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use crate::comms::ros2::std_msgs::Header;
2+
use serde::{Deserialize, Serialize};
3+
4+
#[derive(Debug, Serialize, Deserialize)]
5+
pub struct DiagnosticArray {
6+
pub header: Header,
7+
pub status: Vec<DiagnosticStatus>,
8+
}
9+
10+
pub const OK: u8 = 0;
11+
pub const WARN: u8 = 1;
12+
pub const ERROR: u8 = 2;
13+
pub const STALE: u8 = 3;
14+
15+
#[derive(Debug, Serialize, Deserialize)]
16+
pub struct DiagnosticStatus {
17+
pub level: u8,
18+
pub name: String,
19+
pub message: String,
20+
pub hardware_id: String,
21+
pub values: Vec<KeyValue>,
22+
}
23+
24+
#[derive(Debug, Serialize, Deserialize)]
25+
pub struct KeyValue {
26+
pub key: String,
27+
pub value: String,
28+
}

src/comms/ros2/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pub mod diagnostic_msgs;
2+
pub mod geometry_msgs;
3+
pub mod std_msgs;
4+
pub mod zed;

src/comms/ros2/std_msgs.rs

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
use std::os::raw::{c_long, c_ulong};
2+
3+
use serde::{Deserialize, Serialize};
4+
5+
#[derive(Debug, Serialize, Deserialize)]
6+
pub struct ByteMultiArray {
7+
pub layout: MultiArrayLayout,
8+
pub data: Vec<u8>,
9+
}
10+
11+
#[derive(Debug, Serialize, Deserialize)]
12+
pub struct ColorRGBA {
13+
pub r: f32,
14+
pub g: f32,
15+
pub b: f32,
16+
pub a: f32,
17+
}
18+
19+
#[derive(Debug, Serialize, Deserialize)]
20+
pub struct Duration {
21+
pub sec: c_long,
22+
pub nanosec: c_ulong,
23+
}
24+
25+
#[derive(Debug, Serialize, Deserialize)]
26+
pub struct Header {
27+
pub stamp: Time,
28+
pub frame_id: String,
29+
}
30+
31+
#[derive(Debug, Serialize, Deserialize)]
32+
pub struct Time {
33+
pub sec: c_long,
34+
pub nanosec: c_ulong,
35+
}
36+
37+
#[derive(Debug, Serialize, Deserialize)]
38+
pub struct Empty {}
39+
40+
#[derive(Debug, Serialize, Deserialize)]
41+
pub struct Float32MultiArray {
42+
pub layout: MultiArrayLayout,
43+
pub data: Vec<f32>,
44+
}
45+
46+
#[derive(Debug, Serialize, Deserialize)]
47+
pub struct Float64MultiArray {
48+
pub layout: MultiArrayLayout,
49+
pub data: Vec<f64>,
50+
}
51+
52+
#[derive(Debug, Serialize, Deserialize)]
53+
pub struct Int16MultiArray {
54+
pub layout: MultiArrayLayout,
55+
pub data: Vec<i16>,
56+
}
57+
58+
#[derive(Debug, Serialize, Deserialize)]
59+
pub struct Int32MultiArray {
60+
pub layout: MultiArrayLayout,
61+
pub data: Vec<i32>,
62+
}
63+
64+
#[derive(Debug, Serialize, Deserialize)]
65+
pub struct Int64MultiArray {
66+
pub layout: MultiArrayLayout,
67+
pub data: Vec<i64>,
68+
}
69+
70+
#[derive(Debug, Serialize, Deserialize)]
71+
pub struct Int8MultiArray {
72+
pub layout: MultiArrayLayout,
73+
pub data: Vec<i8>,
74+
}
75+
76+
#[derive(Debug, Serialize, Deserialize)]
77+
pub struct MultiArrayDimension {
78+
pub label: String,
79+
pub size: u32,
80+
pub stride: u32,
81+
}
82+
83+
#[derive(Debug, Serialize, Deserialize)]
84+
pub struct UInt16MultiArray {
85+
pub layout: MultiArrayLayout,
86+
pub data: Vec<u16>,
87+
}
88+
89+
#[derive(Debug, Serialize, Deserialize)]
90+
pub struct UInt32MultiArray {
91+
pub layout: MultiArrayLayout,
92+
pub data: Vec<u32>,
93+
}
94+
95+
#[derive(Debug, Serialize, Deserialize)]
96+
pub struct UInt64MultiArray {
97+
pub layout: MultiArrayLayout,
98+
pub data: Vec<u64>,
99+
}
100+
101+
#[derive(Debug, Serialize, Deserialize)]
102+
pub struct UInt8MultiArray {
103+
pub layout: MultiArrayLayout,
104+
pub data: Vec<u8>,
105+
}
106+
107+
#[derive(Debug, Serialize, Deserialize)]
108+
pub struct MultiArrayLayout {
109+
pub dim: Vec<MultiArrayDimension>,
110+
pub data_offset: u32,
111+
}

0 commit comments

Comments
 (0)