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
use serde::{Serialize, Deserialize};
use crate::{
dds::traits::key::Key,
structure::{guid::GUID, time::Timestamp},
};
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
pub struct Gid {
data: [u8; 24],
}
impl Gid {
pub fn from_guid(guid: GUID) -> Gid {
let mut data: [u8; 24] = [0; 24];
data[..12].clone_from_slice(&guid.guidPrefix.entityKey);
data[12..15].clone_from_slice(&guid.entityId.entityKey);
data[15..16].clone_from_slice(&[u8::from(guid.entityId.entityKind)]);
Gid { data }
}
}
impl Key for Gid {}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct NodeInfo {
node_namespace: String,
node_name: String,
reader_guid: Vec<Gid>,
writer_guid: Vec<Gid>,
}
impl NodeInfo {
pub fn new(name: String, namespace: String) -> NodeInfo {
NodeInfo {
node_namespace: namespace,
node_name: name,
reader_guid: Vec::new(),
writer_guid: Vec::new(),
}
}
pub fn get_namespace(&self) -> &str {
&self.node_namespace
}
pub fn get_name(&self) -> &str {
&self.node_name
}
pub fn get_full_name(&self) -> String {
let mut name = self.node_namespace.to_owned();
name.push_str(&self.node_name);
name
}
pub fn add_writer(&mut self, gid: Gid) {
if !self.writer_guid.contains(&gid) {
self.writer_guid.push(gid);
}
}
pub fn add_reader(&mut self, gid: Gid) {
if !self.reader_guid.contains(&gid) {
self.reader_guid.push(gid);
}
}
pub fn clear_all(&mut self) {
self.reader_guid.clear();
self.writer_guid.clear();
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ROSParticipantInfo {
guid: Gid,
nodes: Vec<NodeInfo>,
}
impl ROSParticipantInfo {
pub fn new(guid: Gid, nodes: Vec<NodeInfo>) -> ROSParticipantInfo {
ROSParticipantInfo { guid, nodes }
}
pub fn guid(&self) -> Gid {
self.guid
}
pub fn into_nodes(self) -> Vec<NodeInfo> {
self.nodes
}
pub fn nodes(&self) -> &Vec<NodeInfo> {
&self.nodes
}
pub fn nodes_mut(&mut self) -> &mut Vec<NodeInfo> {
&mut self.nodes
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ParameterEvents {
timestamp: Timestamp,
node: String,
new_parameters: Vec<Parameter>,
changed_parameters: Vec<Parameter>,
deleted_parameters: Vec<Parameter>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Parameter {
name: String,
value: ParameterValue,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ParameterValue {
ptype: u8,
boolean_value: bool,
int_value: i64,
double_value: f64,
string_value: String,
byte_array: Vec<u8>,
bool_array: Vec<bool>,
int_array: Vec<i64>,
double_array: Vec<f64>,
string_array: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Log {
timestamp: Timestamp,
level: u8,
name: String,
msg: String,
file: String,
function: String,
line: u32,
}
impl Log {
pub fn get_timestamp(&self) -> &Timestamp {
&self.timestamp
}
pub fn get_level(&self) -> u8 {
self.level
}
pub fn get_name(&self) -> &str {
&self.name
}
pub fn get_msg(&self) -> &str {
&self.msg
}
pub fn get_file(&self) -> &str {
&self.file
}
pub fn get_function(&self) -> &str {
&self.function
}
pub fn get_line(&self) -> u32 {
self.line
}
}