Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra error info and getIOSignals() #5

Merged
merged 3 commits into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ endif()
# We need at least 1.4.3 because of WebSocket support.
find_package(Poco 1.4.3 REQUIRED COMPONENTS Foundation Net Util XML)

## Find boost exception library
find_package(Boost REQUIRED COMPONENTS exception)

###########
## Build ##
###########
Expand Down Expand Up @@ -56,10 +59,11 @@ target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include;${CMAKE_CURRENT_BINARY_DIR}>"
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>
${Poco_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
)

target_link_libraries(${PROJECT_NAME} PUBLIC
${Poco_LIBRARIES}
target_link_libraries(${PROJECT_NAME}
PUBLIC ${Poco_LIBRARIES}
)

if(NOT BUILD_SHARED_LIBS)
Expand Down
155 changes: 84 additions & 71 deletions include/abb_librws/rws_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,56 @@
#include "rws_poco_client.h"
#include "rws_resource.h"

#include <boost/exception/info.hpp>


namespace abb
{
namespace rws
{

/**
* \brief Indicates an RWS error
*/
class RWSError
: public std::runtime_error
, public boost::exception
{
public:
RWSError();
};


/**
* \brief Error info containing IO signal name.
*/
using IoSignalErrorInfo = boost::error_info<struct IoSignalErrorInfoTag, std::string>;


/**
* \brief Error info containing HTTPStatus.
*/
using HttpStatusErrorInfo = boost::error_info<struct HttpStatusErrorInfoTag, Poco::Net::HTTPResponse::HTTPStatus>;


/**
* \brief Error info containing an HTTP method.
*/
using HttpMethodErrorInfo = boost::error_info<struct HttpMethodErrorInfoTag, std::string>;


/**
* \brief Error info containing an HTTP response.
*/
using HttpResponseErrorInfo = boost::error_info<struct HttpResponseErrorInfoTag, POCOResult>;


/**
* \brief Error info containing an URI.
*/
using UriErrorInfo = boost::error_info<struct UriErrorInfoTag, std::string>;


/**
* \brief A struct for containing an evaluated communication result.
*/
Expand Down Expand Up @@ -92,13 +137,7 @@ class RWSClient : public POCOClient
*
* \throw \a std::exception if something goes wrong.
*/
RWSClient(const std::string& ip_address)
:
POCOClient(ip_address,
SystemConstants::General::DEFAULT_PORT_NUMBER,
SystemConstants::General::DEFAULT_USERNAME,
SystemConstants::General::DEFAULT_PASSWORD)
{}
RWSClient(const std::string& ip_address);

/**
* \brief A constructor.
Expand All @@ -109,13 +148,7 @@ class RWSClient : public POCOClient
*
* \throw \a std::exception if something goes wrong.
*/
RWSClient(const std::string& ip_address, const std::string& username, const std::string& password)
:
POCOClient(ip_address,
SystemConstants::General::DEFAULT_PORT_NUMBER,
username,
password)
{}
RWSClient(const std::string& ip_address, const std::string& username, const std::string& password);

/**
* \brief A constructor.
Expand All @@ -125,13 +158,7 @@ class RWSClient : public POCOClient
*
* \throw \a std::exception if something goes wrong.
*/
RWSClient(const std::string& ip_address, const unsigned short port)
:
POCOClient(ip_address,
port,
SystemConstants::General::DEFAULT_USERNAME,
SystemConstants::General::DEFAULT_PASSWORD)
{}
RWSClient(const std::string& ip_address, const unsigned short port);

/**
* \brief A constructor.
Expand All @@ -146,13 +173,7 @@ class RWSClient : public POCOClient
RWSClient(const std::string& ip_address,
const unsigned short port,
const std::string& username,
const std::string& password)
:
POCOClient(ip_address,
port,
username,
password)
{}
const std::string& password);

/**
* \brief Logs out the currently active RWS session.
Expand Down Expand Up @@ -508,71 +529,63 @@ class RWSClient : public POCOClient
const std::string& application = SystemConstants::General::EXTERNAL_APPLICATION,
const std::string& location = SystemConstants::General::EXTERNAL_LOCATION);


private:
/**
* \brief Method for parsing a communication result into a XML document.
* \brief Method for parsing a communication result into an XML document.
*
* \param result containing the result of the parsing.
* \param poco_result containing the POCO result.
*
* \return parsed content of \a poco_result.
*
* \throw \a std::exception if something goes wrong.
*/
static void parseMessage(RWSResult& result, const POCOResult& poco_result);
static RWSResult parseContent(const POCOResult& poco_result);


private:
/**
* \brief A struct for representing conditions, for the evaluation of an attempted RWS communication.
* \brief A method for sending a HTTP GET request and checking response status.
*
* \param uri for the URI (path and query).
*
* \return POCOResult containing the result.
*/
struct EvaluationConditions
{
/**
* \brief A default constructor.
*/
EvaluationConditions() : parse_message_into_xml(false) {};

/**
* \brief A method for reseting the conditions.
*/
void reset()
{
parse_message_into_xml = false;
accepted_outcomes.clear();
}

/**
* \brief Indication for if the received message should be parsed into a xml document.
*/
bool parse_message_into_xml;

/**
* \brief Vector containing the accepted HTTP outcomes.
*/
std::vector<Poco::Net::HTTPResponse::HTTPStatus> accepted_outcomes;
};

POCOResult httpGet(const std::string& uri);

/**
* \brief A method for logging out the currently active RWS session.
* \brief A method for sending a HTTP POST request and checking response status.
*
* \param uri for the URI (path and query).
* \param content for the request's content.
*
* \return POCOResult containing the result.
*/
void logout();
POCOResult httpPost(const std::string& uri, const std::string& content = "");

/**
* \brief Method for checking a communication result against the accepted outcomes.
* \brief A method for sending a HTTP PUT request and checking response status.
*
* \param poco_result containing the POCO result.
* \param conditions containing the conditions for the evaluation.
* \param uri for the URI (path and query).
* \param content for the request's content.
*
* \return POCOResult containing the result.
*/
void checkAcceptedOutcomes(const POCOResult& poco_result, const EvaluationConditions& conditions);
POCOResult httpPut(const std::string& uri, const std::string& content = "");

/**
* \brief Method for evaluating the result from a POCO communication.
* \brief A method for sending a HTTP DELETE request and checking response status.
*
* \param poco_result for the POCO result to evaluate.
* \param conditions specifying the conditions for the evaluation.
* \param uri for the URI (path and query).
*
* \return RWSResult containing the evaluated result.
* \return POCOResult containing the result.
*/
POCOResult httpDelete(const std::string& uri);


/**
* \brief A method for logging out the currently active RWS session.
*/
RWSResult evaluatePOCOResult(const POCOResult& poco_result, const EvaluationConditions& conditions);
void logout();

/**
* \brief Method for generating a configuration URI path.
Expand Down
20 changes: 20 additions & 0 deletions include/abb_librws/rws_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
#include "rws_client.h"
#include "rws_subscription.h"

#include <map>
#include <variant>


namespace abb
{
namespace rws
Expand Down Expand Up @@ -340,6 +344,14 @@ struct RuntimeInfo
*/
bool rws_connected;
};


/**
* \brief Mapping from IO signal name to a value.
*
* The value of a digital signal is a \a bool, the value of an analog signal is a \a float.
*/
using IOSignalInfo = std::map<std::string, std::variant<bool, float>>;


/**
Expand Down Expand Up @@ -519,6 +531,14 @@ class RWSInterface
/// @return Value of the requested analog signal
///
float getAnalogSignal(std::string const& signal_name);


/**
* \brief Get values of all IO signals.
*
* \return Mapping from IO signal names to values.
*/
IOSignalInfo getIOSignals();


/**
Expand Down
Loading