ros2_control - humble
Loading...
Searching...
No Matches
interface_schema.hpp
1// Copyright 2026 kamal2730
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14#ifndef ZENBEDDED_SCHEMA__INTERFACE_SCHEMA_HPP_
15#define ZENBEDDED_SCHEMA__INTERFACE_SCHEMA_HPP_
16
17#include <cstdint>
18#include <string>
19#include <vector>
20
21namespace zenbedded
22{
23
24enum class FieldType : uint8_t
25{
26 FLOAT32,
27 FLOAT64,
28 INT32,
29 UINT64,
30 INT16,
31 UINT8,
32};
33
35{
36 std::string name;
37 FieldType type;
38 size_t byte_size;
39 size_t byte_offset;
40};
41
43{
44 std::string name;
45 std::vector<FieldDescriptor> state_fields;
46 std::vector<FieldDescriptor> command_fields;
47 size_t state_size;
48 size_t command_size;
49};
50
52{
53 std::string component;
54 std::string field;
55 FieldType type;
56 size_t byte_offset;
57};
58
60{
61public:
62 static InterfaceSchema from_yaml(const std::string & yaml_text);
63 static InterfaceSchema from_yaml_file(const std::string & file_path);
64
65 bool valid() const { return valid_; }
66 std::string error() const { return error_; }
67
68 size_t state_buffer_size() const { return state_buffer_size_; }
69 size_t command_buffer_size() const { return command_buffer_size_; }
70 size_t total_state_interfaces() const { return state_flat_fields_.size(); }
71 size_t total_command_interfaces() const { return command_flat_fields_.size(); }
72
73 const auto & state_fields() const { return state_flat_fields_; }
74 const auto & command_fields() const { return command_flat_fields_; }
75
76 bool write_c_header(const std::string & output_path) const;
77
78 double read_state_field(const uint8_t * buffer, size_t field_index) const;
79 double read_command_field(const uint8_t * buffer, size_t field_index) const;
80 void write_command_field(uint8_t * buffer, size_t field_index, double value) const;
81
82 static size_t field_byte_size(FieldType type);
83
84 InterfaceSchema() = default;
85
86 bool valid_ = false;
87 std::string error_;
88 size_t state_buffer_size_ = 0;
89 size_t command_buffer_size_ = 0;
90 std::vector<FlatField> state_flat_fields_;
91 std::vector<FlatField> command_flat_fields_;
92};
93
94} // namespace zenbedded
95
96#endif // ZENBEDDED_SCHEMA__INTERFACE_SCHEMA_HPP_
Definition interface_schema.hpp:60
Definition interface_schema.hpp:43
Definition interface_schema.hpp:35
Definition interface_schema.hpp:52