13#ifndef __BAOSLIB_INTERFACE_H__
14#define __BAOSLIB_INTERFACE_H__
22#include "BlockReader.h"
24#include "wzcpp/features/algorithm/append.h"
25#include "wzcpp/features/utils/ByteArray.h"
26#include "wzcpp/features/utils/Memory.h"
145 std::uint16_t numberOfBytes = UINT16_MAX,
146 bool reload =
false);
177 bool withDescStrings =
true,
178 bool reload =
false);
190 std::uint16_t endDpId = UINT16_MAX,
191 bool withDescStrings =
true,
192 bool reload =
false);
255 std::optional<protocol::DatapointValue>
getDpValueRaw(std::uint16_t dpId,
bool reload =
false);
267 auto value = getDpValueRaw(dpId);
268 if (value.has_value())
297 std::uint16_t startDpId,
298 std::uint16_t endDpId,
342 return config_.cacheEnabled;
415 baosCon_ = std::move(conn);
428 throw WzSocketException(WZ_SL,
"No internal connection available");
495 template<
class TGetter>
496 auto getElements(std::uint16_t start, std::uint16_t count, std::uint16_t maxLengthElement, TGetter cb)
498 if (config_.blockReadEnabled)
501 if (!deviceInfoLoaded_)
505 assert(configInfo_.currentBufferSize > 16);
509 assert(payloadAvailSize > 0);
511 std::uint16_t blockSize = payloadAvailSize;
512 return utility::BlockReader::read(start, count, std::min(payloadAvailSize, blockSize), cb);
516 return cb(start, count);
523 true,
true, ServerItemReadStrategy::METADATAREADWITHFALLBACK};
526 bool cacheHit_{
false};
529 bool deviceInfoLoaded_{
false};
535 bool dpCacheFilled_{
false};
Specific datatypes used by the device classes.
Global BAOS protocol defines and types.
Represents a connection to a BAOS device.
Definition BaosConnection.h:67
This class represents a BAOS device.
Definition BaosDevice.h:72
std::optional< DeviceMeta > getMetaInfo()
Get the metadata set for this device if available.
std::vector< ConnectionEventCb > connectionEventCallbacks
List of registered connection lifecycle callbacks.
Definition BaosDevice.h:542
std::function< void(ConnectionEvent &)> ConnectionEventCb
Function signature for connection events callbacks.
Definition BaosDevice.h:74
DeviceStaticInfo getStaticInfo(bool reload=false)
Get the information about a connected BAOS device that is never changed. Like serial number.
void registerConnectionEventCallback(ConnectionEventCb callback)
Register one or more functions as callbacks, invoked on connection lifecycle events.
void onConnectionEvent(ConnectionEvent event)
Forwarded callback from underlying connection for lifecycle events.
auto getElements(std::uint16_t start, std::uint16_t count, std::uint16_t maxLengthElement, TGetter cb)
Helper function to retrieve the elements(datapoint descriptions, string and parameter bytes) from the...
Definition BaosDevice.h:496
protocol::ParameterBytes getParameterBytes(std::uint16_t byteIndex=1, std::uint16_t numberOfBytes=UINT16_MAX, bool reload=false)
Get the parameter bytes If caching is enabled, the result of this call will be stored in cache.
DeviceConfigInfo getConfigInfo(bool reload=false)
Get the information about a connected BAOS device that is typically only changed during configuration...
BaosConnection_UPtr baosCon_
The internal connection used to coomunicate with the BAOS device.
Definition BaosDevice.h:544
DeviceRuntimeInfo getRuntimeInfo(bool reload=false)
Get the information about a connected BAOS device that may change during runtime.
protocol::DatapointValues getDpValuesRaw(std::vector< std::uint16_t > dpIds, bool reload=false)
Get the values of multiple datapoints as raw bytes.
DeviceRuntimeInfo runtimeInfo_
Runtime information about the BAOS device.
Definition BaosDevice.h:532
DeviceConfigInfo configInfo_
Config information about the BAOS device.
Definition BaosDevice.h:531
bool enableCaching(bool state)
Enable or Disable the internal caching for datapoint and parameter bytes.
std::vector< DatapointValueCb > dpValueCallbacks
List of registered callback functions.
Definition BaosDevice.h:541
void onServerItemsUpdate(const protocol::ServerItems &serverItems)
An update may occur as a response to a getServerItem request or via an indication.
void setDpValues(std::map< std::uint16_t, Buffer > &&values, protocol::DatapointSetCommand command=protocol::DatapointSetCommand::SetNewValueAndSendOnBus)
Set the value of multiple datapoints.
std::vector< ServerItemIndicationCb > serverItemsCallbacks
List of registered callback functions.
Definition BaosDevice.h:540
std::map< std::uint16_t, Buffer > dpCache_
Cache to hold the last valid values for the datapoints.
Definition BaosDevice.h:534
void readDpValueFromBus(std::uint16_t dpId)
Triggers a read request for the datapoint on the bus.
std::optional< T > getDatapointValue(std::uint16_t dpId, bool reload=false)
Get the value of a single datapoint as type T.
Definition BaosDevice.h:265
std::optional< DeviceMeta > metaInfo_
Meta information set by the user.
Definition BaosDevice.h:524
DatapointConfigurations dpConfig_
Configuration information about the BAOS datapoints.
Definition BaosDevice.h:538
void setBoolServerItem(protocol::ServerItemId id, bool value)
Set the a bool value to a server item.
std::function< void(const protocol::DatapointValues &)> DatapointValueCb
The function signature for the callback on changed datapoint values.
Definition BaosDevice.h:78
protocol::DatapointValues getDpValuesRaw(std::uint16_t startDpId, std::uint16_t endDpId, bool reload=false, protocol::DatapointValueFilter filter=protocol::DatapointValueFilter::VALID)
Get the values of multiple datapoints as raw bytes.
std::function< void(const protocol::ServerItems &)> ServerItemIndicationCb
The function signature for the callback on changed server items.
Definition BaosDevice.h:76
void readDpValuesFromBus(std::vector< std::uint16_t > &&dpIds)
Triggers read requests for a set of datapoints on the bus.
void clearDeviceConfigs()
Reset the device information, retrieved from serveritems and meta data to their default values.
protocol::DatapointValues getAllDpValuesRaw(bool reload=false, protocol::DatapointValueFilter filter=protocol::DatapointValueFilter::VALID)
Load all the datapoint values and cache them.
void onDpValueUpdate(const protocol::DatapointValueStates &dpValueStates)
An update may occur as a response to a getDatapointValue request or via an indication.
protocol::ParameterBytes paramBytes_
Cache to hold the parameter bytes.
Definition BaosDevice.h:536
std::optional< DatapointConfig > getDpConfiguration(std::uint16_t dpId=1, bool withDescStrings=true, bool reload=false)
Get the datapoint configuration of a single datapoint If caching is enabled, the result of this call ...
void clearCaches()
Clear the internal caches for datapoints and parameter bytes.
DatapointConfigurations getDpConfigurations(std::uint16_t startDpId=1, std::uint16_t endDpId=UINT16_MAX, bool withDescStrings=true, bool reload=false)
Get the datapoint configurations If caching is enabled, the result of this call will be stored in cac...
protocol::ParameterBytes getAllParameterBytes(bool reload=false)
Load all the parameter bytes and cache them.
DatapointConfigurations getAllDpConfigurations(bool reload=false)
Load all the datapoint configurations and cache them.
void setMetaInfo(DeviceMeta &&meta)
Set the meta data for this device.
virtual BaosConnection_UPtr getConnection()=0
Pure virtual function to get a BaosConnection to the device.
bool wasCacheHit()
Returns if the last request could be statisfied by the cache or not.
Definition BaosDevice.h:355
void ensureConnection()
Make sure that a connection to the underlying device exists and is open or throw an exception if this...
void readDpValuesFromBus(const std::vector< std::uint16_t > &dpIds)
Triggers read requests for a set of datapoints on the bus.
bool isCachingEnabled() const
Return the current caching state.
Definition BaosDevice.h:340
protocol::ServerItems getAllServerItems()
Get all the serveritem values from the device.
ServerItemReadStrategy setServerItemReadStrategy(ServerItemReadStrategy strategy)
Set the strategy to use for reading the serveritems.
std::optional< protocol::DatapointValue > getDpValueRaw(std::uint16_t dpId, bool reload=false)
Get the value of a single datapoint as raw bytes.
void registerServerItemCallback(ServerItemIndicationCb)
Register one or more functions ascallbacks, invoked on serveritem changes.
DeviceStaticInfo staticInfo_
Static information about the BAOS device.
Definition BaosDevice.h:530
void setDpValue(std::uint16_t dpId, Buffer dpData, protocol::DatapointSetCommand command=protocol::DatapointSetCommand::SetNewValueAndSendOnBus)
Set the value of a single datapoint.
void registerDPValueCallback(DatapointValueCb)
Register one or more functions ascallbacks, invoked on datapoint value changes.
Global types and configuration for the whole SDK.
std::map< std::uint16_t, DatapointValue > DatapointValues
A map with datapoint ids as keys and DatapointValue as values.
Definition Defines.h:36
ServerItemId
An enum class to provide conveniant names to the serveritem ids.
Definition Defines.h:199
std::map< std::uint16_t, DatapointValueState > DatapointValueStates
Definition Defines.h:607
DatapointSetCommand
Setting a datapoint value there are different modes supported. This enum class gives those modes name...
Definition Defines.h:61
std::vector< std::uint8_t > ParameterBytes
Strong type for a list of parameter bytes.
Definition Defines.h:635
DatapointValueFilter
Requested datapoint value can be filtered by this criteria.
Definition Defines.h:51
std::vector< ServerItem > ServerItems
Type for a list of ServerItems.
Definition Defines.h:440
Global BAOS sdk namespace.
Definition config.h:69
std::vector< std::uint8_t > Buffer
An alias type for a byte buffer.
Definition config.h:71
BAOSLIB_EXPORT std::uint16_t getAvailableBufferSize(const DeviceStaticInfo &staticInfo, const DeviceConfigInfo &configInfo)
std::map< std::uint16_t, DatapointConfig > DatapointConfigurations
Definition BaosDeviceDataTypes.h:212
BAOSLIB_EXPORT std::uint16_t getAvailablePayloadSize(const DeviceStaticInfo &staticInfo, const DeviceConfigInfo &configInfo)
std::unique_ptr< BaosConnection > BaosConnection_UPtr
Alias for a std::unique pointer of a BaosConnection.
Definition BaosDevice.h:43
ServerItemReadStrategy
Strategy type on how to handle reading the serveritems.
Definition BaosDeviceDataTypes.h:216
Definition ConnectionEvent.h:37
Configuration options for the cpp device class behaviour.
Definition BaosDeviceDataTypes.h:226
A collection of fields representing those serveritems which may change if the configuration of the de...
Definition BaosDeviceDataTypes.h:94
A collection of fields representing those serveritems which may change during "normal" operation of t...
Definition BaosDeviceDataTypes.h:174
A collection of fields representing those serveritems which won't ever change in a device.
Definition BaosDeviceDataTypes.h:49