BAOS SDK v2  1.0.1
An SDK providing access to IP-BAOS devices through BAOS binary protocol version 2.x
BaosDevice Class Referenceabstract

This class represents a BAOS device. More...

#include <baos/device/BaosDevice.h>

+ Inheritance diagram for BaosDevice:

Public Types

using ServerItemIndicationCb = std::function< void(const protocol::ServerItems &)>
 The function signature for the callback on changed server items.
 
using DatapointValueCb = std::function< void(const protocol::DatapointValues &)>
 The function signature for the callback on changed datapoint values.
 

Public Member Functions

virtual void close ()
 
ServerItemReadStrategy setServerItemReadStrategy (ServerItemReadStrategy strategy)
 Set the strategy to use for reading the serveritems. More...
 
bool enableCaching (bool state)
 Enable or Disable the internal caching for datapoint and parameter bytes. More...
 
bool isCachingEnabled () const
 Return the current caching state. More...
 
void clearCaches ()
 Clear the internal caches for datapoints and parameter bytes.
 
bool wasCacheHit ()
 Returns if the last request could be statisfied by the cache or not. More...
 
std::optional< DeviceMetagetMetaInfo ()
 Get the metadata set for this device if available. More...
 
void setMetaInfo (DeviceMeta &&meta)
 Set the meta data for this device. More...
 
void registerServerItemCallback (ServerItemIndicationCb)
 Register one or more functions ascallbacks, invoked on serveritem changes.
 
void registerDPValueCallback (DatapointValueCb)
 Register one or more functions ascallbacks, invoked on datapoint value changes.
 
virtual BaosConnection_UPtr getConnection ()=0
 Pure virtual function to get a BaosConnection to the device. More...
 
Device information

Information about the device via serveritems

DeviceStaticInfo getStaticInfo (bool reload=false)
 Get the information about a connected BAOS device that is never changed. Like serial number. More...
 
DeviceConfigInfo getConfigInfo (bool reload=false)
 Get the information about a connected BAOS device that is typically only changed during configuration. More...
 
DeviceRuntimeInfo getRuntimeInfo (bool reload=false)
 Get the information about a connected BAOS device that may change during runtime. More...
 
void setBoolServerItem (protocol::ServerItemId id, bool value)
 Set the a bool value to a server item. More...
 
Parameter bytes related methods

Methods to retrieve the parameter bytes from the device

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. More...
 
protocol::ParameterBytes getAllParameterBytes (bool reload=false)
 Load all the parameter bytes and cache them. More...
 
Datapoint related methods

All methods for setting and retrieving information and values of datapoints

std::optional< DatapointConfiggetDpConfiguration (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 will be stored in cache. More...
 
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 cache. More...
 
DatapointConfigurations getAllDpConfigurations (bool reload=false)
 Load all the datapoint configurations and cache them. More...
 
void setDpValue (std::uint16_t dpId, Buffer dpData, protocol::DatapointSetCommand command=protocol::DatapointSetCommand::SetNewValueAndSendOnBus)
 Set the value of a single datapoint. More...
 
void setDpValues (std::map< std::uint16_t, Buffer > &&values, protocol::DatapointSetCommand command=protocol::DatapointSetCommand::SetNewValueAndSendOnBus)
 Set the value of multiple datapoints. More...
 
void readDpValueFromBus (std::uint16_t dpId)
 Triggers a read request for the datapoint on the bus. More...
 
void readDpValuesFromBus (std::vector< std::uint16_t > &&dpIds)
 Triggers read requests for a set of datapoints on the bus. More...
 
std::optional< protocol::DatapointValuegetDpValueRaw (std::uint16_t dpId, bool reload=false)
 Get the value of a single datapoint as raw bytes. More...
 
template<class T >
std::optional< T > getDatapointValue (std::uint16_t dpId, bool reload=false)
 Get the value of a single datapoint as type T. More...
 
protocol::DatapointValues getDpValuesRaw (std::vector< std::uint16_t > dpIds, bool reload=false)
 Get the values of multiple datapoints as raw bytes. More...
 
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. More...
 
protocol::DatapointValues getAllDpValuesRaw (bool reload=false, protocol::DatapointValueFilter filter=protocol::DatapointValueFilter::VALID)
 Load all the datapoint values and cache them. More...
 

Protected Member Functions

void ensureConnection ()
 Make sure that a connection to the underlying device exists and is open or throw an exception if this is not possible.
 
void onServerItemsUpdate (const protocol::ServerItems &serverItems)
 An update may occur as a response to a getServerItem request or via an indication. More...
 
void onDpValueUpdate (const protocol::DatapointValueStates &dpValueStates)
 An update may occur as a response to a getDatapointValue request or via an indication. More...
 
void clearDeviceConfigs ()
 Reset the device information, retrieved from serveritems and meta data to their default values.
 
protocol::ServerItems getAllServerItems ()
 Get all the serveritem values from the device. More...
 
template<class TGetter >
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 device. More...
 
 WZLOGGER ("BaosDevice", LVL_DEBUG)
 The name for the logger of this class.
 

Protected Attributes

DeviceClassConfig config_
 Configuration options for this class. More...
 
std::optional< DeviceMetametaInfo_
 Meta information set by the user.
 
bool cacheHit_ {false}
 Flag to indicate that the last operation could be statisfied with the cache content.
 
bool deviceInfoLoaded_ {false}
 Flag set of the device information is loaded from the device via serveritems.
 
DeviceStaticInfo staticInfo_
 Static information about the BAOS device.
 
DeviceConfigInfo configInfo_
 Config information about the BAOS device.
 
DeviceRuntimeInfo runtimeInfo_
 Runtime information about the BAOS device.
 
std::map< std::uint16_t, BufferdpCache_
 Cache to hold the last valid values for the datapoints.
 
bool dpCacheFilled_ {false}
 Flag to indicate that the cache is valid.
 
protocol::ParameterBytes paramBytes_
 Cache to hold the parameter bytes.
 
DatapointConfigurations dpConfig_
 Configuration information about the BAOS datapoints.
 
std::vector< ServerItemIndicationCbserverItemsCallbacks
 List of registered callback functions.
 
std::vector< DatapointValueCbdpValueCallbacks
 List of registered callback functions.
 
BaosConnection_UPtr baosCon_
 The internal connection used to coomunicate with the BAOS device.
 

Detailed Description

This class represents a BAOS device.

Maintining a BaosConnection to a physical BAOS device all interactions and information with and about said devices are stored in this class.

Member Function Documentation

◆ close()

virtual void close ( )
virtual

Close the connection to the baos device

◆ getStaticInfo()

DeviceStaticInfo getStaticInfo ( bool  reload = false)

Get the information about a connected BAOS device that is never changed. Like serial number.

Parameters
reloadtrue if the information should be directly loaded from the device, false(default) for using the cache if possible
Returns
A structure containing the static information

◆ getConfigInfo()

DeviceConfigInfo getConfigInfo ( bool  reload = false)

Get the information about a connected BAOS device that is typically only changed during configuration.

Parameters
reloadtrue if the information should be directly loaded from the device, false(default) for using the cache if possible
Returns
A structure containing the config information

◆ getRuntimeInfo()

DeviceRuntimeInfo getRuntimeInfo ( bool  reload = false)

Get the information about a connected BAOS device that may change during runtime.

Parameters
reloadtrue if the information should be directly loaded from the device, false(default) for using the cache if possible
Returns
A structure containing the runtime information

◆ setBoolServerItem()

void setBoolServerItem ( protocol::ServerItemId  id,
bool  value 
)

Set the a bool value to a server item.

Parameters
idThe id of the serveritem
valueThe new value to set

◆ getParameterBytes()

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.

Parameters
byteIndexThe first bytes to retrieve(1 based index)
numberOfBytesThe amount of bytes to retrieve
reload[opt] If true bypass the cache and force a reload from the device, defaults to false
Returns
ParameterBytes

◆ getAllParameterBytes()

protocol::ParameterBytes getAllParameterBytes ( bool  reload = false)

Load all the parameter bytes and cache them.

To detemine how many bytes are available the serverItem maxParameterBytes is used. If this is not available load 1-65535

Parameters
reload[opt] If true bypass the cache and force a reload from the device, defaults to false
Returns
The requested parameter bytes

◆ getDpConfiguration()

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 will be stored in cache.

Parameters
dpIdThe 1 based id of the datapoint to get
withDescStringsIf the description string should be loaded too or not
reload[opt] If true bypass the cache and force a reload from the device, defaults to false
Returns
The DatapointConfiguration for the given id or an empty optional of not value could be retrieved.

◆ getDpConfigurations()

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 cache.

Parameters
startDpIdThe 1 based id of the first datapoint to get
endDpIdThe 1 based id of the last datapoint to get
withDescStringsIf the description string should be loaded too or not
reload[opt] If true bypass the cache and force a reload from the device, defaults to false
Returns
DatapointConfigurations

◆ getAllDpConfigurations()

DatapointConfigurations getAllDpConfigurations ( bool  reload = false)

Load all the datapoint configurations and cache them.

To detemine how many datapoints are available the serverItem maxDatapoints is used. If this is not available load 1-65535.

Parameters
reload[opt] If true bypass the cache and force a reload from the device, defaults to false
Returns
DatapointConfigurations

◆ setDpValue()

void setDpValue ( std::uint16_t  dpId,
Buffer  dpData,
protocol::DatapointSetCommand  command = protocol::DatapointSetCommand::SetNewValueAndSendOnBus 
)

Set the value of a single datapoint.

Parameters
dpIdThe 1 based id of the datapoint
dpDataThe new value to set
command[in,opt] What type of change is requested

◆ setDpValues()

void setDpValues ( std::map< std::uint16_t, Buffer > &&  values,
protocol::DatapointSetCommand  command = protocol::DatapointSetCommand::SetNewValueAndSendOnBus 
)

Set the value of multiple datapoints.

Parameters
valuesa map with the datapoint ids as keys and the values as entries
command[in,opt] What type of change is requested

◆ readDpValueFromBus()

void readDpValueFromBus ( std::uint16_t  dpId)

Triggers a read request for the datapoint on the bus.

Parameters
dpIdThe 1 based id of the datapoint

◆ readDpValuesFromBus()

void readDpValuesFromBus ( std::vector< std::uint16_t > &&  dpIds)

Triggers read requests for a set of datapoints on the bus.

Parameters
dpIdsA vector containing the 1 based datapoints ids, for which the read request should be send out

◆ getDpValueRaw()

std::optional<protocol::DatapointValue> getDpValueRaw ( std::uint16_t  dpId,
bool  reload = false 
)

Get the value of a single datapoint as raw bytes.

Parameters
dpIdThe 1 based id of the datapoint
reloadIf true bypass the cache and force a reload from the device
Returns
DatapointValue

◆ getDatapointValue()

std::optional<T> getDatapointValue ( std::uint16_t  dpId,
bool  reload = false 
)
inline

Get the value of a single datapoint as type T.

Template Parameters
TThe type to which the raw Bytes should be converted to
Parameters
dpIdThe 1 based id of the datapoint
reloadIf true bypass the cache and force a reload from the device

◆ getDpValuesRaw() [1/2]

protocol::DatapointValues getDpValuesRaw ( std::vector< std::uint16_t >  dpIds,
bool  reload = false 
)

Get the values of multiple datapoints as raw bytes.

Parameters
dpIdsA list of datapoint ids
reloadIf true bypass the cache and force a reload from the device
Returns
DatapointValues

◆ getDpValuesRaw() [2/2]

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.

Parameters
startDpIdThe id of the first datapoint value to request
endDpIdThe id of the last datapoint value to request
reload[opt] If true bypass the cache and force a reload from the device, defaults to false
filter[opt] The filter to select a subset of datapoint values, defaults to DatapointValueFilter::VALID
Returns
protocol::DatapointValues

◆ getAllDpValuesRaw()

protocol::DatapointValues getAllDpValuesRaw ( bool  reload = false,
protocol::DatapointValueFilter  filter = protocol::DatapointValueFilter::VALID 
)

Load all the datapoint values and cache them.

To detemine how many serveritems are available the serverItem maxDatapoints is used. If this is not available load 1-65535.

Parameters
reload[opt] If true bypass the cache and force a reload from the device, defaults to false
filter[opt] The filter to select a subset of datapoint values, defaults to DatapointValueFilter::VALID
Returns
DatapointConfigurations

◆ setServerItemReadStrategy()

ServerItemReadStrategy setServerItemReadStrategy ( ServerItemReadStrategy  strategy)

Set the strategy to use for reading the serveritems.

Parameters
strategyThe strategy to use
Returns
The previous strategy

◆ enableCaching()

bool enableCaching ( bool  state)

Enable or Disable the internal caching for datapoint and parameter bytes.

Serveritems are always cached

Parameters
stateThe new state to set
Returns
The previous state is new state was different or the current unchanged state

◆ isCachingEnabled()

bool isCachingEnabled ( ) const
inline

Return the current caching state.

Returns
true if caching is enabled or false otherwise

◆ wasCacheHit()

bool wasCacheHit ( )
inline

Returns if the last request could be statisfied by the cache or not.

Returns
true request could be answered by cache, false otherwise

◆ getMetaInfo()

std::optional<DeviceMeta> getMetaInfo ( )

Get the metadata set for this device if available.

Returns
std::optional<DeviceMeta> The metadata or an empty std::optional

◆ setMetaInfo()

void setMetaInfo ( DeviceMeta &&  meta)

Set the meta data for this device.

In most cases this is not necessary. Gathering information from the serveritems an DeviceGroupIdentifier is generated and then a lookup in DevicesMetaLookup is performed. For devices groups not in this lookup table this function may be used to set the metainformation beforehand. If incorrect values are set the SDK wont work as expected.

Parameters
metaThe meta data for this device

◆ getConnection()

virtual BaosConnection_UPtr getConnection ( )
pure virtual

Pure virtual function to get a BaosConnection to the device.

Returns
BaosConnection_UPtr A BaosConnection to the device

Implemented in BaosIp4Device.

◆ onServerItemsUpdate()

void onServerItemsUpdate ( const protocol::ServerItems serverItems)
protected

An update may occur as a response to a getServerItem request or via an indication.

Parameters
serverItemsThe Serveritems that were changed

◆ onDpValueUpdate()

void onDpValueUpdate ( const protocol::DatapointValueStates dpValueStates)
protected

An update may occur as a response to a getDatapointValue request or via an indication.

Parameters
dpValueStatesThe datapoint values and their states that got changed

◆ getAllServerItems()

protocol::ServerItems getAllServerItems ( )
protected

Get all the serveritem values from the device.

If the wz::baos::ServerItemReadStrategy is set to ServerItemReadStrategy::ALLATONCE request as many serveritems from the device as it possible. If the ServerItemReadStrategy is set to ServerItemReadStrategy::METADATAREAD, first check if meta information is already set, e.g. by calling setMetaInfo. If the meta information is available use it to determine what the hightest server item id is and request all the serveritem including it. On the other hand if the meta information is not available, read the serveritems [ManufactureCodeApp, ApplicationId, ApplicationVersion] generate a DeviceGroupIdentifier from it and check if DevicesMetaLookup has an entry for it. If no entry is found throw an exception when ServerItemReadStrategy::METADATAREAD is set or fallback to ALLATONCE if METADATAREADWITHFALLBACK was configured as serveritem read strategy. If found use the maxServerItemId meta information to load the serveritems valus from id [1;maxServerItemId]

Returns
A list of ServerItem objects

◆ getElements()

auto getElements ( std::uint16_t  start,
std::uint16_t  count,
std::uint16_t  maxLengthElement,
TGetter  cb 
)
inlineprotected

Helper function to retrieve the elements(datapoint descriptions, string and parameter bytes) from the device.

Template Parameters
TGetterThe SDK function type used to get a chunk of data from the device
Parameters
startThe id of the first element
countThe last element is then id+count-1
maxLengthElementThe maximum of bytes one element may contain
cbThe callback invoked for every rquest to the BAOS device
Returns
The reponse as a list of bytes

Member Data Documentation

◆ config_

DeviceClassConfig config_
protected
Initial value:

Configuration options for this class.


The documentation for this class was generated from the following file: