SlaveIdentifierConfig.h
Go to the documentation of this file.
1#pragma once
2
3#include <inttypes.h>
4
5#include <string>
6
8
10{
11 /**
12 * @brief Data structure holding the information necessary to create a SlaveIdentifier.
13 * Can be printed to streams and compared for equality.
14 */
16 {
17 friend class ConfigParser;
18
19 public:
21
22 std::uint32_t getVendorID();
23 std::uint32_t getProductCode();
24 std::uint32_t getSerialNumber();
25 std::string getName();
26
27 /**
28 * @brief Check if the SlaveIdentifierConfig is complete and valid.
29 * @param errorMessages vector that receives the messages describing the cause if invalid.
30 * If true is returned then no message is appended to the vector.
31 * @return iff this SlaveIdentifierConfig is valid
32 */
33 bool isValid(std::vector<std::string>& errorMessages);
34
35 friend std::ostream&
36 operator<<(std::ostream& stream, const SlaveIdentifierConfig& rhs)
37 {
38 stream << "Name: " << rhs.name;
39
40 if (rhs.vendorTag != ConfigTag::Invalid)
41 {
42 stream << ", VendorID: 0x" << std::hex << rhs.vendorID << std::dec << " ("
43 << rhs.vendorID << ")";
44 }
45 if (rhs.productTag != ConfigTag::Invalid)
46 {
47 stream << ", ProductCode: 0x" << std::hex << rhs.productCode << std::dec << " ("
48 << rhs.productCode << ")";
49 }
50 if (rhs.serialTag != ConfigTag::Invalid)
51 {
52 stream << ", SerialNumber: 0x" << std::hex << rhs.serialNumber << std::dec << " ("
53 << rhs.serialNumber << ")";
54 }
55 return stream;
56 }
57
58 bool
60 {
61 return vendorID == other.vendorID && productCode == other.productCode &&
62 serialNumber == other.serialNumber;
63 }
64
65 private:
66 std::uint32_t vendorID;
67 std::uint32_t productCode;
68 std::uint32_t serialNumber;
69 std::string name = "unknown";
70 ConfigTag vendorTag = ConfigTag::Invalid;
71 ConfigTag productTag = ConfigTag::Invalid;
72 ConfigTag serialTag = ConfigTag::Invalid;
74
75 private:
76 void setVendorID(std::uint32_t vendorID, ConfigTag tag);
77 void setProductCode(std::uint32_t productCode, ConfigTag tag);
78 void setSerialNumber(std::uint32_t serial, ConfigTag tag);
79 void setName(std::string name, ConfigTag tag);
80
81 template <typename T>
82 void
83 set(T value, ConfigTag tag, T& field, ConfigTag& tagField)
84 {
85 if (tagField == tag)
86 {
87 throw ConfigInsertError("Config Node with name " + name +
88 " is defined multiple times in " + tagName(tag) + " nodes");
89 }
90 else if (tagField > tag)
91 {
92 // The config nodes have been parsed in the wrong order.
93 // But the new node should not overwrite the old one
94 // So we just return and don't change the entry
95 return;
96 }
97
98 field = value;
99 tagField = tag;
100 }
101 };
102
103} // namespace armarx::control::hardware_config
The ConfigInsertError class represents an error that is thrown if an attempt is mode to set a config ...
Definition Errors.h:13
bool operator==(const SlaveIdentifierConfig &other) const
bool isValid(std::vector< std::string > &errorMessages)
Check if the SlaveIdentifierConfig is complete and valid.
friend std::ostream & operator<<(std::ostream &stream, const SlaveIdentifierConfig &rhs)
ConfigTag
The ConfigTag is used when setting a config value.
Definition Config.h:62
std::string tagName(ConfigTag tag)
Definition Config.cpp:301