BAOS SDK v2
1.0.1
An SDK providing access to IP-BAOS devices through BAOS binary protocol version 2.x
|
Represents a connection to a BAOS device. More...
#include <baos/connection/BaosConnection.h>
Public Types | |
using | Clock = std::chrono::system_clock |
An alias for the clock internaly used. | |
using | BaosFrame = Buffer |
An alias for the container type to store frame/packets/telegrams in. | |
using | BaosFrame_UPtr = std::unique_ptr< BaosFrame > |
An alias for a std::unique_ptr holding a BaosFrame. | |
using | UPtr = std::unique_ptr< BaosConnection > |
An alias for an unqiue pointer to this class. | |
using | ServerItemIndicationCb = std::function< void(const protocol::ServerItems &)> |
Function signature for serveritem indication callbacks. | |
using | DatapointValueCb = std::function< void(const protocol::DatapointValueStates &)> |
Function signature for datapoint value indication callbacks. | |
Public Member Functions | |
BaosConnection () | |
Default constructor. | |
virtual | ~BaosConnection () |
Default destructor. | |
void | start () |
Start the client side of the connection. | |
void | stop () |
Stop the client side of the connection. | |
virtual void | reopen ()=0 |
Reopens the underlying connection, has to be implemented by derived classes. | |
void | close () |
Close the connection to the BAOS device. | |
bool | isOpen () |
Returns the open state of the connection. More... | |
void | setServerItemsIndCallback (ServerItemIndicationCb callback) |
void | setDatapointValueIndCallback (DatapointValueCb callback) |
Synchronous API | |
Set of functions to provide the typical BAOS interaction in a synchronous way | |
std::optional< protocol::ServerItem > | getServerItem (protocol::ServerItemId id) |
Get a single the ServerItem. More... | |
protocol::ServerItems | getServerItems (std::uint16_t startItem, std::uint16_t numberOfItems) |
Get a list of serveritems from the device. More... | |
void | setServerItem (const protocol::ServerItem &serverItem) |
void | setServerItem (protocol::ServerItem &&serverItem) |
void | setServerItems (protocol::ServerItems &&serverItems) |
std::optional< protocol::DatapointDescription > | getDpDescription (std::uint16_t dpId) |
Get the datapoint description for one datapoint. More... | |
protocol::DatapointDescriptions | getDpDescriptions (std::uint16_t startDpId, std::uint16_t numberOfItems) |
Get a list of DatapointDescriptions. More... | |
std::optional< protocol::DatapointDescriptionString > | getDpDescriptionString (std::uint16_t dpId) |
Get the datapoint description string for one datapoint. More... | |
protocol::DatapointDescriptionStrings | getDpDescriptionStrings (std::uint16_t startDpId, std::uint16_t numberOfStrings) |
Get a list of DatapointDescriptionsStrings. More... | |
std::optional< std::uint8_t > | getParameterByte (std::uint16_t byteIndex) |
Get a single parameter byte. | |
protocol::ParameterBytes | getParameterBytes (std::uint16_t byteIndex, std::uint16_t numberOfBytes) |
Get a list of parameter bytes. More... | |
std::optional< protocol::DatapointValueState > | getDpValue (std::uint16_t dpId) |
Get a single datapoint value with its associated state. | |
protocol::DatapointValueStates | getDpValues (std::uint16_t startDpId, std::uint16_t numberOfValues, protocol::DatapointValueFilter filter=protocol::DatapointValueFilter::ALL) |
Get a map with the datapoint id as key and the DatapointValueState as value. More... | |
void | setDpValue (std::uint16_t dpId, protocol::DatapointChangeValue &&dpValue) |
Send a SetDatapointValue request to the BAOS device for one datapoint. More... | |
void | setDpValues (std::map< std::uint16_t, protocol::DatapointChangeValue > &&dpValues) |
Send a SetDatapointValue request to the BAOS device with given datapoint values. More... | |
Asynchronous API | |
Set of functions to provide the typical BAOS interaction in a asynchronous way. Every function returns a future. | |
protocol::ResponseFuture | getServerItemAsync (protocol::ServerItemId id) |
protocol::ResponseFuture | getServerItemsAsync (std::uint16_t startItem, std::uint16_t numberOfItems) |
Get a list of serveritems from the device. More... | |
protocol::ResponseFuture | setServerItemAsync (protocol::ServerItem &&serverItem) |
protocol::ResponseFuture | setServerItemsAsync (protocol::ServerItems &&serverItems) |
protocol::ResponseFuture | getDpDescriptionAsync (std::uint16_t dpId) |
Get the datapoint description for one datapoint. More... | |
protocol::ResponseFuture | getDpDescriptionsAsync (std::uint16_t startDpId, std::uint16_t numberOfItems) |
Get a list of DatapointDescriptions. More... | |
protocol::ResponseFuture | getDpDescriptionStringAsync (std::uint16_t dpId) |
Get the datapoint description string for one datapoint. More... | |
protocol::ResponseFuture | getDpDescriptionStringsAsync (std::uint16_t startDpId, std::uint16_t numberOfStrings) |
Get a list of DatapointDescriptionsStrings. More... | |
protocol::ResponseFuture | getParameterByteAsync (std::uint16_t byteIndex) |
Get a single parameter byte. | |
protocol::ResponseFuture | getParameterBytesAsync (std::uint16_t byteIndex, std::uint16_t numberOfBytes) |
Get a list of parameter bytes. More... | |
protocol::ResponseFuture | getDpValueAsync (std::uint16_t dpId) |
Get a single datapoint value with its associated state. | |
protocol::ResponseFuture | getDpValuesAsync (std::uint16_t startDpId, std::uint16_t numberOfValues, protocol::DatapointValueFilter filter=protocol::DatapointValueFilter::ALL) |
Get a map with the datapoint id as key and the DatapointValueState as value. More... | |
protocol::ResponseFuture | setDpValueAsync (std::uint16_t dpId, protocol::DatapointChangeValue &&dpValue) |
Send a SetDatapointValue request to the BAOS device for one datapoint. More... | |
protocol::ResponseFuture | setDpValuesAsync (std::map< std::uint16_t, protocol::DatapointChangeValue > &&dpValues) |
Send a SetDatapointValue request to the BAOS device with given datapoint values. More... | |
protocol::ResponseFuture | closeAsync () |
Close the connection. More... | |
Protected Types | |
enum class | State { RUNNING , STOPPING , STOPPED , SENDING , SENDCOMPLETE , WAITRESPONSE , IDLE , CONERROR , CONCLOSED } |
Represents the internal state of this connection. More... | |
enum class | PromiseState { UNUSED , SET , RESOLVED } |
The asynchronous functions return a promise to keep internal track of their state this enum is used. | |
Protected Member Functions | |
protocol::ResponseFuture | send (BaosFrame &&frame) |
Sends a generic frame( a byte list) to the BAOS device. More... | |
BaosParseStatus | handleBaosFrame (BaosFrame_UPtr &&frame) |
For every received BAOS frame this handler is internally called. More... | |
BaosParseStatus | handleBaosIndication (BaosFrame_UPtr &&frame) |
For every received BAOS indication this handler is internally called. More... | |
protocol::BaosResponseCode | handleBaosResponse (BaosFrame_UPtr &&frame) |
For every received BAOS response this handler is internally called. More... | |
State | setState (State newState) |
Set the internal state of this connections state machine. More... | |
State | getState () const |
Get the current internal state of this connections state machine. More... | |
protocol::BaosBaseResponse::SPtr | decodeResponse (BaosFrame_UPtr &&frame) |
Decodes the baos response. More... | |
virtual protocol::ResponseFuture | closeImplAsync () |
The implementation function for closing a connection. | |
virtual void | startImpl () |
The implementation function for starting the connection class. | |
virtual void | stopImpl () |
The implementation function for stopping the connection class. | |
virtual bool | isOpenImpl () |
The implementation function for getting the opened state of the connection. More... | |
virtual protocol::ResponseFuture | sendImpl (BaosFrame &&frame)=0 |
The implementation function for sending bytes to the connected device. | |
virtual void | onStateChange (State oldState, State newState) |
Invoked if the internal connection state should be changed. | |
virtual void | onTimerExpired (std::vector< std::uint64_t > ids) |
Invoked if on of the timers has expired. | |
Static Protected Member Functions | |
static std::string | stateToString (State state) |
Get human readable string from internal state. | |
Protected Attributes | |
std::atomic< bool > | shouldStop_ {false} |
Flag to indicate that the connection should stop at the next opportunity. | |
std::atomic< bool > | isRunning_ {false} |
Keep track if the connection is in running state or stopping / stopped. More... | |
wzcpp::ThreadPoolExecutor | executor_ {4} |
wzcpp::TimerManager< Clock > | timerManager_ |
Manages the timers for this connection. | |
wzcpp::Timer< Clock > | respTimeoutTimer_ |
The actual timer objects for respone timeouts. | |
wzcpp::Timer< Clock > | heartBeatTimer_ |
The actual timer objects for heartbeats. | |
Buffer | waitResponse_ |
While waiting for a response this holds the pattern of the response we expect. | |
protocol::ResponsePromise | responsePromise_ |
If a packet is send out via handleTxTcp the corresponding promise is stored here. | |
PromiseState | responsePromiseState_ {PromiseState::UNUSED} |
The state of the responsePromise_. | |
std::uint64_t | currentMessageId_ {0} |
For internal use a unique message id. | |
std::queue< IOEvent > | txQueue_ |
Holds the packets to send waiting to be processed. | |
BaosMsgQueue | bMsgQ_ |
Hold the event for the main connection loop. | |
protocol::BaosIndQueue | bIndQ_ |
Holds the indication to be send out to clients. | |
BaosIndicationSender | indSender_ |
Responsible for sending out the indications. | |
Represents a connection to a BAOS device.
The connection runs in a separate thread and receives events from either the user or from underlying socket.
|
strongprotected |
Represents the internal state of this connection.
bool isOpen | ( | ) |
Returns the open state of the connection.
std::optional<protocol::ServerItem> getServerItem | ( | protocol::ServerItemId | id | ) |
Get a single the ServerItem.
id | The ServerItem id |
protocol::ServerItems getServerItems | ( | std::uint16_t | startItem, |
std::uint16_t | numberOfItems | ||
) |
Get a list of serveritems from the device.
startItem | The id of the first serveritem to load |
numberOfItems | Maximal number of items to return |
void setServerItem | ( | const protocol::ServerItem & | serverItem | ) |
Set a single serveritem
void setServerItem | ( | protocol::ServerItem && | serverItem | ) |
Set a single serveritem
void setServerItems | ( | protocol::ServerItems && | serverItems | ) |
Set a list of serveritems
std::optional<protocol::DatapointDescription> getDpDescription | ( | std::uint16_t | dpId | ) |
Get the datapoint description for one datapoint.
dpId | The 1 based id of the datapoint |
protocol::DatapointDescriptions getDpDescriptions | ( | std::uint16_t | startDpId, |
std::uint16_t | numberOfItems | ||
) |
Get a list of DatapointDescriptions.
startDpId | The 1 based id of the first datapoint |
numberOfItems | Maximal number of descriptions to return |
std::optional<protocol::DatapointDescriptionString> getDpDescriptionString | ( | std::uint16_t | dpId | ) |
Get the datapoint description string for one datapoint.
dpId | The 1 based id of the datapoint |
protocol::DatapointDescriptionStrings getDpDescriptionStrings | ( | std::uint16_t | startDpId, |
std::uint16_t | numberOfStrings | ||
) |
Get a list of DatapointDescriptionsStrings.
startDpId | The 1 based id of the first datapoint |
numberOfStrings | Maximal number of descriptions to return |
protocol::ParameterBytes getParameterBytes | ( | std::uint16_t | byteIndex, |
std::uint16_t | numberOfBytes | ||
) |
Get a list of parameter bytes.
byteIndex | The 1 based index of the first parameter byte to read |
numberOfBytes | Maximum number of bytes to return |
protocol::DatapointValueStates getDpValues | ( | std::uint16_t | startDpId, |
std::uint16_t | numberOfValues, | ||
protocol::DatapointValueFilter | filter = protocol::DatapointValueFilter::ALL |
||
) |
Get a map with the datapoint id as key and the DatapointValueState as value.
startDpId | The 1 based id of the first datapoint |
numberOfValues | Maximal number of value to return |
filter | [optional] Filter for the requested datapoints |
void setDpValue | ( | std::uint16_t | dpId, |
protocol::DatapointChangeValue && | dpValue | ||
) |
Send a SetDatapointValue request to the BAOS device for one datapoint.
dpId | The 1 based id of the datapoint |
dpValue | The new value to set and the command for it |
void setDpValues | ( | std::map< std::uint16_t, protocol::DatapointChangeValue > && | dpValues | ) |
Send a SetDatapointValue request to the BAOS device with given datapoint values.
dpValues | a map with datapoint ids as keys and command and new value as value |
protocol::ResponseFuture getServerItemAsync | ( | protocol::ServerItemId | id | ) |
Get a single serveritem specified by its id from the device
protocol::ResponseFuture getServerItemsAsync | ( | std::uint16_t | startItem, |
std::uint16_t | numberOfItems | ||
) |
Get a list of serveritems from the device.
startItem | The id of the first serveritem to load |
numberOfItems | Maximal number of items to return |
protocol::ResponseFuture setServerItemAsync | ( | protocol::ServerItem && | serverItem | ) |
Set a single serveritem
protocol::ResponseFuture setServerItemsAsync | ( | protocol::ServerItems && | serverItems | ) |
Set a list of serveritems
protocol::ResponseFuture getDpDescriptionAsync | ( | std::uint16_t | dpId | ) |
Get the datapoint description for one datapoint.
dpId | The 1 based id of the datapoint |
protocol::ResponseFuture getDpDescriptionsAsync | ( | std::uint16_t | startDpId, |
std::uint16_t | numberOfItems | ||
) |
Get a list of DatapointDescriptions.
startDpId | The 1 based id of the first datapoint |
numberOfItems | Maximal number of descriptions to return |
protocol::ResponseFuture getDpDescriptionStringAsync | ( | std::uint16_t | dpId | ) |
Get the datapoint description string for one datapoint.
dpId | The 1 based id of the datapoint |
protocol::ResponseFuture getDpDescriptionStringsAsync | ( | std::uint16_t | startDpId, |
std::uint16_t | numberOfStrings | ||
) |
Get a list of DatapointDescriptionsStrings.
startDpId | The 1 based id of the first datapoint |
numberOfStrings | Maximal number of descriptions to return |
protocol::ResponseFuture getParameterBytesAsync | ( | std::uint16_t | byteIndex, |
std::uint16_t | numberOfBytes | ||
) |
Get a list of parameter bytes.
byteIndex | The 1 based index of the first parameter byte to read |
numberOfBytes | Maximum number of bytes to return |
protocol::ResponseFuture getDpValuesAsync | ( | std::uint16_t | startDpId, |
std::uint16_t | numberOfValues, | ||
protocol::DatapointValueFilter | filter = protocol::DatapointValueFilter::ALL |
||
) |
Get a map with the datapoint id as key and the DatapointValueState as value.
startDpId | The 1 based id of the first datapoint |
numberOfValues | Maximal number of value to return |
filter | [optional] Filter for the requested datapoints |
protocol::ResponseFuture setDpValueAsync | ( | std::uint16_t | dpId, |
protocol::DatapointChangeValue && | dpValue | ||
) |
Send a SetDatapointValue request to the BAOS device for one datapoint.
dpId | The 1 based id of the datapoint |
dpValue | The new value to set and the command for it |
protocol::ResponseFuture setDpValuesAsync | ( | std::map< std::uint16_t, protocol::DatapointChangeValue > && | dpValues | ) |
Send a SetDatapointValue request to the BAOS device with given datapoint values.
dpValues | a map with datapoint ids as keys and command and new value as value |
protocol::ResponseFuture closeAsync | ( | ) |
Close the connection.
|
inline |
Sets the function callback to be invoked in every serveritem indication from the device
callback | strong typed std::function object |
|
inline |
Sets the function callback to be invoked in every datapoint value indication from the device
callback | strong typed std::function object |
|
inlineprotected |
Sends a generic frame( a byte list) to the BAOS device.
frame | a generic list of bytes |
|
protected |
For every received BAOS frame this handler is internally called.
frame | an rvalue of the frame to handle |
|
protected |
For every received BAOS indication this handler is internally called.
frame | an rvalue of the frame to handle |
|
protected |
For every received BAOS response this handler is internally called.
frame | an rvalue of the frame to handle |
Set the internal state of this connections state machine.
newState | The new state to set |
|
inlineprotected |
Get the current internal state of this connections state machine.
|
protected |
Decodes the baos response.
frame | an rvalue of the frame to decode |
|
inlineprotectedvirtual |
The implementation function for getting the opened state of the connection.
Reimplemented in BaosTcpConnection.
|
protected |
Keep track if the connection is in running state or stopping / stopped.
It is also used be start and stop function to protect against starting a running or stopping a stopped connection.
|
protected |
The main executor thread pool with 4 threads : The read thread and the indication thread, the connection thread and the timer thread