BAOS SDK v2
1.0.1
An SDK providing access to IP-BAOS devices through BAOS binary protocol version 2.x
|
This class represents a BAOS device. More...
#include <baos/device/BaosDevice.h>
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< DeviceMeta > | getMetaInfo () |
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< 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. 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::DatapointValue > | getDpValueRaw (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< DeviceMeta > | metaInfo_ |
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, Buffer > | dpCache_ |
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< ServerItemIndicationCb > | serverItemsCallbacks |
List of registered callback functions. | |
std::vector< DatapointValueCb > | dpValueCallbacks |
List of registered callback functions. | |
BaosConnection_UPtr | baosCon_ |
The internal connection used to coomunicate with the BAOS device. | |
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.
|
virtual |
Close the connection to the baos device
DeviceStaticInfo getStaticInfo | ( | bool | reload = false | ) |
Get the information about a connected BAOS device that is never changed. Like serial number.
reload | true if the information should be directly loaded from the device, false(default) for using the cache if possible |
DeviceConfigInfo getConfigInfo | ( | bool | reload = false | ) |
Get the information about a connected BAOS device that is typically only changed during configuration.
reload | true if the information should be directly loaded from the device, false(default) for using the cache if possible |
DeviceRuntimeInfo getRuntimeInfo | ( | bool | reload = false | ) |
Get the information about a connected BAOS device that may change during runtime.
reload | true if the information should be directly loaded from the device, false(default) for using the cache if possible |
void setBoolServerItem | ( | protocol::ServerItemId | id, |
bool | value | ||
) |
Set the a bool value to a server item.
id | The id of the serveritem |
value | The new value to set |
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.
byteIndex | The first bytes to retrieve(1 based index) |
numberOfBytes | The amount of bytes to retrieve |
reload | [opt] If true bypass the cache and force a reload from the device, defaults to false |
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
reload | [opt] If true bypass the cache and force a reload from the device, defaults to false |
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.
dpId | The 1 based id of the datapoint to get |
withDescStrings | If 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 |
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.
startDpId | The 1 based id of the first datapoint to get |
endDpId | The 1 based id of the last datapoint to get |
withDescStrings | If 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 |
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.
reload | [opt] If true bypass the cache and force a reload from the device, defaults to false |
void setDpValue | ( | std::uint16_t | dpId, |
Buffer | dpData, | ||
protocol::DatapointSetCommand | command = protocol::DatapointSetCommand::SetNewValueAndSendOnBus |
||
) |
Set the value of a single datapoint.
dpId | The 1 based id of the datapoint |
dpData | The new value to set |
command | [in,opt] What type of change is requested |
void setDpValues | ( | std::map< std::uint16_t, Buffer > && | values, |
protocol::DatapointSetCommand | command = protocol::DatapointSetCommand::SetNewValueAndSendOnBus |
||
) |
Set the value of multiple datapoints.
values | a map with the datapoint ids as keys and the values as entries |
command | [in,opt] What type of change is requested |
void readDpValueFromBus | ( | std::uint16_t | dpId | ) |
Triggers a read request for the datapoint on the bus.
dpId | The 1 based id of the datapoint |
void readDpValuesFromBus | ( | std::vector< std::uint16_t > && | dpIds | ) |
Triggers read requests for a set of datapoints on the bus.
dpIds | A vector containing the 1 based datapoints ids, for which the read request should be send out |
std::optional<protocol::DatapointValue> getDpValueRaw | ( | std::uint16_t | dpId, |
bool | reload = false |
||
) |
Get the value of a single datapoint as raw bytes.
dpId | The 1 based id of the datapoint |
reload | If true bypass the cache and force a reload from the device |
|
inline |
Get the value of a single datapoint as type T.
T | The type to which the raw Bytes should be converted to |
dpId | The 1 based id of the datapoint |
reload | If true bypass the cache and force a reload from the device |
protocol::DatapointValues getDpValuesRaw | ( | std::vector< std::uint16_t > | dpIds, |
bool | reload = false |
||
) |
Get the values of multiple datapoints as raw bytes.
dpIds | A list of datapoint ids |
reload | If true bypass the cache and force a reload from the device |
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.
startDpId | The id of the first datapoint value to request |
endDpId | The 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 |
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.
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 |
ServerItemReadStrategy setServerItemReadStrategy | ( | ServerItemReadStrategy | strategy | ) |
Set the strategy to use for reading the serveritems.
strategy | The strategy to use |
bool enableCaching | ( | bool | state | ) |
Enable or Disable the internal caching for datapoint and parameter bytes.
Serveritems are always cached
state | The new state to set |
|
inline |
Return the current caching state.
|
inline |
Returns if the last request could be statisfied by the cache or not.
std::optional<DeviceMeta> getMetaInfo | ( | ) |
Get the metadata set for this device if available.
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.
meta | The meta data for this device |
|
pure virtual |
Pure virtual function to get a BaosConnection to the device.
Implemented in BaosIp4Device.
|
protected |
An update may occur as a response to a getServerItem request or via an indication.
serverItems | The Serveritems that were changed |
|
protected |
An update may occur as a response to a getDatapointValue request or via an indication.
dpValueStates | The datapoint values and their states that got changed |
|
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]
|
inlineprotected |
Helper function to retrieve the elements(datapoint descriptions, string and parameter bytes) from the device.
TGetter | The SDK function type used to get a chunk of data from the device |
start | The id of the first element |
count | The last element is then id+count-1 |
maxLengthElement | The maximum of bytes one element may contain |
cb | The callback invoked for every rquest to the BAOS device |
|
protected |
Configuration options for this class.