BAOS SDK v2  1.2.1
An SDK providing access to IP-BAOS devices through BAOS binary protocol version 2.x
BaosDevicesMeta.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2002-2026 WEINZIERL ENGINEERING GmbH
3 // All rights reserved.
4 //
5 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7 // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
8 // SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY,
9 // WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
10 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
11 //
12 #ifndef __BAOSLIB_INTERFACE_META_H__
13 #define __BAOSLIB_INTERFACE_META_H__
14 
15 #include "baos/protocol/Defines.h"
16 
17 #include "wzcpp/features/utils/ByteArray.h"
18 
19 
21 #include <array>
22 #include <cassert>
23 #include <cstdint>
24 #include <functional>
25 #include <map>
26 #include <optional>
27 #include <string>
29 
35 namespace wz::baos
36 {
44 {
53  const protocol::ServerItem& applicationId,
54  const protocol::ServerItem& applicationVersion)
55  {
56  assert(manufacturerApp.id == protocol::ServerItemId::ManufactureCodeApp);
57  assert(applicationId.id == protocol::ServerItemId::ApplicationId);
58  assert(applicationVersion.id == protocol::ServerItemId::ApplicationVersion);
59 
60  deviceid[0] = static_cast<std::byte>(manufacturerApp.data[0] & 0xff);
61  deviceid[1] = static_cast<std::byte>(manufacturerApp.data[1] & 0xff);
62  deviceid[2] = static_cast<std::byte>(applicationId.data[0] & 0xff);
63  deviceid[3] = static_cast<std::byte>(applicationId.data[1] & 0xff);
64  deviceid[4] = static_cast<std::byte>(applicationVersion.data[0] & 0xff);
65  };
66 
74  DeviceGroupIdentifier(std::uint16_t manufacturerApp, std::uint16_t applicationId, std::uint8_t applicationVersion)
75  {
76  deviceid[0] = static_cast<std::byte>((manufacturerApp >> 8) & 0xff);
77  deviceid[1] = static_cast<std::byte>(manufacturerApp & 0xff);
78  deviceid[2] = static_cast<std::byte>((applicationId >> 8) & 0xff);
79  deviceid[3] = static_cast<std::byte>(applicationId & 0xff);
80  deviceid[4] = static_cast<std::byte>(applicationVersion & 0xff);
81  };
82 
84  bool operator==(const DeviceGroupIdentifier& other) const
85  {
86  return (deviceid == other.deviceid);
87  }
89  bool operator<(const DeviceGroupIdentifier& other) const
90  {
91  return (deviceid < other.deviceid);
92  }
93 
94  std::array<std::byte, 5> deviceid;
95 };
96 
98 struct DeviceMeta
99 {
100  using UPtr = std::unique_ptr<DeviceMeta>;
101  std::string name;
102  std::uint16_t maxServerItemId{0};
103  std::uint16_t maxParameterBytes{0};
104  std::uint16_t maxDatapoints{0};
105 };
106 
107 using DevicesMeta =
108  std::map<DeviceGroupIdentifier, DeviceMeta>;
109 
113 static DevicesMeta DevicesMetaLookup = {
114  {{0xC5, 0x0708, 0x10}, DeviceMeta{"771", 18, 250, 250}},
115  {{0xC5, 0x0709, 0x10}, DeviceMeta{"772", 18, 250, 1000}}, // despite having 1000 parameter bytes configurable in
116  // the ETS, the service only allows access to 250
117  {{0xC5, 0x0714, 0x10}, DeviceMeta{"773", 18, 250, 250}},
118  {{0xC5, 0x0715, 0x10}, DeviceMeta{"774", 18, 1000, 1000}}};
119 
120 
124 BAOSLIB_EXPORT std::optional<std::uint16_t> getAvailableBufferSizeFromMeta(const wzcpp::SixByteArray& hardwareType);
125 
126 } // namespace wz::baos
127 
128 namespace std
129 {
130 
138 template<>
139 struct hash<wz::baos::DeviceGroupIdentifier>
140 {
147  std::size_t operator()(const wz::baos::DeviceGroupIdentifier& k) const
148  {
149  using std::hash;
150  using std::size_t;
151  using std::string;
152 
153  std::ostringstream stream;
154 
155  auto first = begin(k.deviceid);
156  auto last = end(k.deviceid);
157  if (first != last)
158  { // initial check
159  while (true)
160  {
161  stream << std::uppercase << std::setw(2) << std::setfill('0') << std::hex
162  << static_cast<short>(*first++); // Write to stream in format 0F
163  if (first == last) break;
164  stream << " ";
165  }
166  }
167 
168  return std::hash<std::string>()(stream.str());
169  }
170 };
171 
172 } // namespace std
173 
174 #endif // end ifdef __BAOSLIB_INTERFACE_META_H__
Global BAOS protocol defines and types.
@ ApplicationVersion
(Read Only; 1 bytes)
@ ManufactureCodeApp
(Read Only; 2 bytes)
@ ApplicationId
(Read Only; 2 bytes)
Global BAOS sdk namespace.
Definition: config.h:69
BAOSLIB_EXPORT std::optional< std::uint16_t > getAvailableBufferSizeFromMeta(const wzcpp::SixByteArray &hardwareType)
std::map< DeviceGroupIdentifier, DeviceMeta > DevicesMeta
Maps the unqiue device identifier to an metainformation entry.
Definition: BaosDevicesMeta.h:108
Unique identifier for a device.
Definition: BaosDevicesMeta.h:44
std::array< std::byte, 5 > deviceid
The unique inferfacegroup id.
Definition: BaosDevicesMeta.h:94
DeviceGroupIdentifier(const protocol::ServerItem &manufacturerApp, const protocol::ServerItem &applicationId, const protocol::ServerItem &applicationVersion)
Construct a new Device Identifier object build from baos::protocol::ServerItem elements.
Definition: BaosDevicesMeta.h:52
bool operator<(const DeviceGroupIdentifier &other) const
The lesser than operator of this class.
Definition: BaosDevicesMeta.h:89
DeviceGroupIdentifier(std::uint16_t manufacturerApp, std::uint16_t applicationId, std::uint8_t applicationVersion)
Construct a new Device Identifier object from intergral values.
Definition: BaosDevicesMeta.h:74
bool operator==(const DeviceGroupIdentifier &other) const
The comparision operator for the class.
Definition: BaosDevicesMeta.h:84
Meta information about a device group, which is required be the device class.
Definition: BaosDevicesMeta.h:99
std::uint16_t maxDatapoints
The maximum of datapoints in this deivces.
Definition: BaosDevicesMeta.h:104
std::unique_ptr< DeviceMeta > UPtr
An alias for an unique pointer to this class.
Definition: BaosDevicesMeta.h:100
std::uint16_t maxParameterBytes
The maximum of parameter bytes in this devices.
Definition: BaosDevicesMeta.h:103
std::uint16_t maxServerItemId
The maximum amount if serveritems in this devices.
Definition: BaosDevicesMeta.h:102
std::string name
The name of the devices targeted with this metainformation block.
Definition: BaosDevicesMeta.h:101
Structure to hold information about a serveritem.
Definition: Defines.h:404
ServerItemId id
the serveritem id
Definition: Defines.h:435
Buffer data
the data
Definition: Defines.h:437