BAOS SDK v2  1.0.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-2023 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/Formatter.h"
18 
19 
21 #include <array>
22 #include <cassert>
23 #include <cstdint>
24 #include <functional>
25 #include <map>
26 #include <string>
28 
34 namespace wz::baos
35 {
43 {
52  const protocol::ServerItem& applicationId,
53  const protocol::ServerItem& applicationVersion)
54  {
55  assert(manufacturerApp.id == protocol::ServerItemId::ManufactureCodeApp);
56  assert(applicationId.id == protocol::ServerItemId::ApplicationId);
57  assert(applicationVersion.id == protocol::ServerItemId::ApplicationVersion);
58 
59  deviceid[0] = static_cast<std::byte>(manufacturerApp.data[0] & 0xff);
60  deviceid[1] = static_cast<std::byte>(manufacturerApp.data[1] & 0xff);
61  deviceid[2] = static_cast<std::byte>(applicationId.data[0] & 0xff);
62  deviceid[3] = static_cast<std::byte>(applicationId.data[1] & 0xff);
63  deviceid[4] = static_cast<std::byte>(applicationVersion.data[0] & 0xff);
64  };
65 
73  DeviceGroupIdentifier(std::uint16_t manufacturerApp, std::uint16_t applicationId, std::uint8_t applicationVersion)
74  {
75  deviceid[0] = static_cast<std::byte>((manufacturerApp >> 8) & 0xff);
76  deviceid[1] = static_cast<std::byte>(manufacturerApp & 0xff);
77  deviceid[2] = static_cast<std::byte>((applicationId >> 8) & 0xff);
78  deviceid[3] = static_cast<std::byte>(applicationId & 0xff);
79  deviceid[4] = static_cast<std::byte>(applicationVersion & 0xff);
80  };
81 
83  bool operator==(const DeviceGroupIdentifier& other) const
84  {
85  return (deviceid == other.deviceid);
86  }
88  bool operator<(const DeviceGroupIdentifier& other) const
89  {
90  return (deviceid < other.deviceid);
91  }
92 
93  std::array<std::byte, 5> deviceid;
94 };
95 
97 struct DeviceMeta
98 {
99  using UPtr = std::unique_ptr<DeviceMeta>;
100  std::string name;
101  std::uint16_t maxServerItemId{0};
102  std::uint16_t maxParameterBytes{0};
103  std::uint16_t maxDatapoints{0};
104 };
105 
106 using DevicesMeta =
107  std::map<DeviceGroupIdentifier, DeviceMeta>;
108 
112 static DevicesMeta DevicesMetaLookup = {
113  {{0xC5, 0x0708, 0x10}, DeviceMeta{"771", 18, 250, 250}},
114  {{0xC5, 0x0709, 0x10}, DeviceMeta{"772", 18, 250, 1000}}, // despite having 1000 parameter bytes configurable in
115  // the ETS, the service only allows access to 250
116  {{0xC5, 0x0714, 0x10}, DeviceMeta{"773", 18, 250, 250}},
117  {{0xC5, 0x0715, 0x10}, DeviceMeta{"774", 18, 1000, 1000}}};
118 } // namespace wz::baos
119 
120 namespace std
121 {
122 
130 template<>
131 struct hash<wz::baos::DeviceGroupIdentifier>
132 {
139  std::size_t operator()(const wz::baos::DeviceGroupIdentifier& k) const
140  {
141  using std::hash;
142  using std::size_t;
143  using std::string;
144 
145  auto hexString = wzcpp::rangeToHex<std::array<std::byte, 5>>(k.deviceid);
146  return std::hash<std::string>()(hexString);
147  }
148 };
149 
150 } // namespace std
151 
152 #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:62
std::map< DeviceGroupIdentifier, DeviceMeta > DevicesMeta
Maps the unqiue device identifier to an metainformation entry.
Definition: BaosDevicesMeta.h:107
Unique identifier for a device.
Definition: BaosDevicesMeta.h:43
std::array< std::byte, 5 > deviceid
The unique inferfacegroup id.
Definition: BaosDevicesMeta.h:93
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:51
bool operator<(const DeviceGroupIdentifier &other) const
The lesser than operator of this class.
Definition: BaosDevicesMeta.h:88
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:73
bool operator==(const DeviceGroupIdentifier &other) const
The comparision operator for the class.
Definition: BaosDevicesMeta.h:83
Meta information about a device group, which is required be the device class.
Definition: BaosDevicesMeta.h:98
std::uint16_t maxDatapoints
The maximum of datapoints in this deivces.
Definition: BaosDevicesMeta.h:103
std::unique_ptr< DeviceMeta > UPtr
An alias for an unique pointer to this class.
Definition: BaosDevicesMeta.h:99
std::uint16_t maxParameterBytes
The maximum of parameter bytes in this devices.
Definition: BaosDevicesMeta.h:102
std::uint16_t maxServerItemId
The maximum amount if serveritems in this devices.
Definition: BaosDevicesMeta.h:101
std::string name
The name of the devices targeted with this metainformation block.
Definition: BaosDevicesMeta.h:100
Structure to hold information about a serveritem.
Definition: Defines.h:403
ServerItemId id
the serveritem id
Definition: Defines.h:416
Buffer data
the data
Definition: Defines.h:418