ED247 Library  VA2.3.0
Implementation of ED247-A standard
ed247_xml.h
1 /* -*- mode: c++; c-basic-offset: 2 -*- */
2 /******************************************************************************
3  * The MIT Licence
4  *
5  * Copyright (c) 2021 Airbus Operations S.A.S
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation
10  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  * and/or sell copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23  * OTHER DEALINGS IN THE SOFTWARE.
24  *****************************************************************************/
25 #ifndef _ED247_XML_H_
26 #define _ED247_XML_H_
27 #include "ed247.h"
28 #include <string>
29 #include <vector>
30 #include <memory>
31 
32 // Prevent include of libxml2 header
33 typedef struct _xmlNode *xmlNodePtr;
34 
35 namespace ed247 {
36  namespace xml {
37  struct Component;
38 
39  // Load ECIC and return an ed247::xml::Component node
40  std::unique_ptr<Component> load_filepath(const std::string & filepath);
41  std::unique_ptr<Component> load_content(const std::string & content);
42 
43 
44  struct Node
45  {
46  virtual void load(const xmlNodePtr xml_node) = 0;
47  };
48 
49  struct UdpSocket : public Node
50  {
51  std::string _dst_ip_address;
52  uint16_t _dst_ip_port;
53  std::string _src_ip_address;
54  uint16_t _src_ip_port;
55  std::string _mc_ip_address;
56  uint16_t _mc_ttl;
57  ed247_direction_t _direction;
58 
59  UdpSocket();
60  virtual void load(const xmlNodePtr xml_node) override final;
61  };
62 
63  struct ComInterface : public Node
64  {
65  std::vector<UdpSocket> _udp_sockets;
66  virtual void load(const xmlNodePtr xml_node) override final;
67  };
68 
69  struct DataTimestamp : public Node
70  {
71  ed247_yesno_t _enable;
72  ed247_yesno_t _enable_sample_offset;
73 
74  DataTimestamp();
75  virtual void load(const xmlNodePtr xml_node) override final;
76  };
77 
78  struct Errors : public Node
79  {
80  ed247_yesno_t _enable;
81 
82  Errors();
83  virtual void load(const xmlNodePtr xml_node) override final;
84  };
85 
86  struct Header: public Node
87  {
88  ed247_yesno_t _enable;
89  ed247_yesno_t _transport_timestamp;
90 
91  Header();
92  virtual void load(const xmlNodePtr xml_node) override final;
93  };
94 
95  //
96  // Signals
97  //
98  struct Signal : public Node
99  {
100  std::string _name;
101  ed247_signal_type_t _type;
102  std::string _comment;
103  std::string _icd;
104  uint32_t _byte_offset; // All signals except VNAD
105  std::string _analogue_electrical_unit;
106  ed247_nad_type_t _nad_type; // UINT8 for discrete and FLOAT32 for analogue
107  std::string _nad_unit; // NAD and VNAD
108  std::vector<uint32_t> _nad_dimensions;
109  uint32_t _vnad_position;
110  uint32_t _vnad_max_number;
111 
112  uint32_t get_sample_max_size_bytes() const;
113  inline uint32_t get_nad_type_size() const { return get_nad_type_size(_nad_type); }
114  static uint32_t get_nad_type_size(ed247_nad_type_t nad_type);
115 
117  virtual ~Signal() {}
118  };
119 
120  struct DISSignal : public Signal
121  {
122  DISSignal();
123  virtual void load(const xmlNodePtr xml_node) override final;
124  };
125 
126  struct ANASignal : public Signal
127  {
128  ANASignal();
129  virtual void load(const xmlNodePtr xml_node) override final;
130  };
131 
132  struct NADSignal : public Signal
133  {
134  NADSignal();
135  virtual void load(const xmlNodePtr xml_node) override final;
136  };
137 
138  struct VNADSignal : public Signal
139  {
140  VNADSignal();
141  virtual void load(const xmlNodePtr xml_node) override final;
142  };
143 
144  //
145  // Streams
146  //
147  struct Stream : public Node
148  {
149  std::string _name;
150  ed247_direction_t _direction;
151  ed247_stream_type_t _type;
152  std::string _comment;
153  std::string _icd;
154  ed247_uid_t _uid;
155  uint32_t _sample_max_number;
156  uint32_t _sample_max_size_bytes;
157  bool _sample_size_fixed;
158  DataTimestamp _data_timestamp;
159 
160  virtual bool is_signal_based() const = 0;
161  virtual void validate(const xmlNodePtr closest_node) = 0;
162  Stream(ed247_stream_type_t type, uint32_t sample_max_size_bytes, bool sample_size_fixed);
163  virtual ~Stream() {}
164  };
165 
166  struct StreamProtocoled : public Stream
167  {
168  Errors _errors;
169  virtual bool is_signal_based() const override final { return false; }
170  StreamProtocoled(ed247_stream_type_t type, uint32_t sample_max_size_bytes, bool sample_size_fixed = false);
171  };
172 
173  struct StreamSignals : public Stream
174  {
175  std::vector<std::unique_ptr<Signal>> _signal_list;
176  uint32_t _sampling_period_us;
177  virtual bool is_signal_based() const override final { return true; }
178  StreamSignals(ed247_stream_type_t type, uint32_t sample_max_size_bytes, bool sample_size_fixed = true);
179  };
180 
181  struct A429Stream : public StreamProtocoled
182  {
183  A429Stream();
184  virtual void load(const xmlNodePtr xml_node) override final;
185  virtual void validate(const xmlNodePtr closest_node) override final;
186  };
187 
188  struct A664Stream : public StreamProtocoled
189  {
190  ed247_yesno_t _enable_message_size;
191 
192  A664Stream();
193  virtual void load(const xmlNodePtr xml_node) override final;
194  virtual void validate(const xmlNodePtr closest_node) override final;
195  };
196 
197  struct A825Stream : public StreamProtocoled
198  {
199  A825Stream();
200  virtual void load(const xmlNodePtr xml_node) override final;
201  virtual void validate(const xmlNodePtr closest_node) override final;
202  };
203 
205  {
206  SERIALStream();
207  virtual void load(const xmlNodePtr xml_node) override final;
208  virtual void validate(const xmlNodePtr closest_node) override final;
209  };
210 
211  struct ETHStream : public StreamProtocoled
212  {
213  ed247_yesno_t _enable_message_size;
214  std::string _layer;
215 
216  ETHStream();
217  virtual void load(const xmlNodePtr xml_node) override final;
218  virtual void validate(const xmlNodePtr closest_node) override final;
219  };
220 
221  struct DISStream : public StreamSignals
222  {
223  DISStream();
224  virtual void load(const xmlNodePtr xml_node) override final;
225  virtual void validate(const xmlNodePtr closest_node) override final;
226  };
227 
228  struct ANAStream : public StreamSignals
229  {
230  ANAStream();
231  virtual void load(const xmlNodePtr xml_node) override final;
232  virtual void validate(const xmlNodePtr closest_node) override final;
233  };
234 
235  struct NADStream : public StreamSignals
236  {
237  NADStream();
238  virtual void load(const xmlNodePtr xml_node) override final;
239  virtual void validate(const xmlNodePtr closest_node) override final;
240  };
241 
242  struct VNADStream : public StreamSignals
243  {
244  VNADStream();
245  virtual void load(const xmlNodePtr xml_node) override final;
246  virtual void validate(const xmlNodePtr closest_node) override final;
247  };
248 
249  //
250  // Channels
251  //
252  struct Channel : public Node
253  {
254  std::string _name;
255  std::string _comment;
256  ed247_standard_t _frame_standard_revision;
257  ComInterface _com_interface;
258  Header _header;
259  std::vector<std::unique_ptr<Stream>> _stream_list;
260  bool _is_simple_channel;
261 
262  Channel();
263  virtual void load(const xmlNodePtr xml_node) override final;
264  };
265 
266  //
267  // Component (root)
268  //
269  struct Component: public Node
270  {
271  ed247_uid_t _identifier;
272  std::string _name;
273  std::string _version;
274  ed247_component_type_t _component_type;
275  ed247_standard_t _standard_revision;
276  std::string _comment;
277  std::string _file_producer_identifier;
278  std::string _file_producer_comment;
279  std::vector<Channel> _channel_list;
280 
281  Component();
282  virtual void load(const xmlNodePtr xml_node) override final;
283  };
284  }
285 }
286 
287 std::ostream& operator<<(std::ostream& stream, const ed247::xml::UdpSocket& socket);
288 
289 #endif
Definition: ed247_xml.h:221
Definition: ed247_xml.h:132
Definition: ed247_xml.h:49
Definition: ed247_xml.h:188
Definition: ed247_xml.h:63
ed247_standard_t
ED247 Standard revisions.
Definition: ed247.h:104
ed247_direction_t
Stream direction.
Definition: ed247.h:153
ed247_component_type_t
Component types.
Definition: ed247.h:121
Definition: ed247_xml.h:69
Definition: ed247_xml.h:126
Definition: ed247_xml.h:181
Definition: ed247_xml.h:235
ed247_signal_type_t
Signal types.
Definition: ed247.h:164
uint16_t ed247_uid_t
Unique identifier type.
Definition: ed247.h:115
Definition: ed247_xml.h:44
Definition: ed247_xml.cpp:115
Definition: ed247_xml.h:242
Definition: ed247_xml.h:98
Definition: ed247_xml.h:252
Definition: ed247_xml.h:78
Definition: ed247_xml.h:147
Definition: ed247_xml.h:120
Definition: ed247_xml.h:204
Definition: ed247_xml.h:269
ed247_nad_type_t
NAD type.
Definition: ed247.h:176
Definition: ed247_channel.cpp:37
ed247_stream_type_t
Stream types.
Definition: ed247.h:132
Definition: ed247_xml.h:86
Definition: ed247_xml.h:211
ed247_yesno_t
Yes / No.
Definition: ed247.h:94
Definition: ed247_xml.h:228
Definition: ed247_xml.h:197
Definition: ed247_xml.h:173
Definition: ed247_xml.h:166
Definition: ed247_xml.h:138