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

Represents a BAOS IP4 device with an underlying TCP connection. More...

#include <baos/ip/BaosIpv4Device.h>

+ Inheritance diagram for BaosIp4Device:

Public Member Functions

 BaosIp4Device (const std::string &ip4Address, std::uint16_t port=12004)
 Construct a new Baos Ip 4 Device object from an ip address and a port. More...
 
void setConnectionData (const std::string &ip4Address, std::uint16_t port=12004)
 Construct a new Baos Ip 4 Device object from an ip address and a port. More...
 
BaosConnection_UPtr getConnection () override
 Get a BaosConnection to the device. More...
 
- Public Member Functions inherited from BaosDevice
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.
 
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...
 
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...
 
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...
 

Additional Inherited Members

- Public Types inherited from BaosDevice
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.
 
- Protected Member Functions inherited from BaosDevice
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 inherited from BaosDevice
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

Represents a BAOS IP4 device with an underlying TCP connection.

The connection information like ip address and the port can either be set in the constructor or later with setConnectionData. This has to be done before opening a the connection to the device.

Constructor & Destructor Documentation

◆ BaosIp4Device()

BaosIp4Device ( const std::string &  ip4Address,
std::uint16_t  port = 12004 
)
inline

Construct a new Baos Ip 4 Device object from an ip address and a port.

Parameters
ip4AddressThe IPv4 Address as string in the form "xxx.xxx.xxx.xxx"
portThe tcp port of the remote device

Member Function Documentation

◆ setConnectionData()

void setConnectionData ( const std::string &  ip4Address,
std::uint16_t  port = 12004 
)
inline

Construct a new Baos Ip 4 Device object from an ip address and a port.

Parameters
ip4AddressThe IPv4 Address as string in the form "xxx.xxx.xxx.xxx"
portThe tcp port of the remote device
Remarks
The connection information is NOT automatically used. To apply it a manual call to close is required. The connection will then be reopened on the next request.

◆ getConnection()

BaosConnection_UPtr getConnection ( )
overridevirtual

Get a BaosConnection to the device.

Returns
BaosConnection_UPtr A BaosConnection to the device

Implements BaosDevice.


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