Skip to content

Commit

Permalink
Modify Basic example to use both service call APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
romainreignier committed Nov 7, 2018
1 parent 27ef4f7 commit 5a25212
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions test/Basic/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,40 @@ void Node::onTimer()
chatter.publish(str_msg);

roscpp::GetLoggersRequest req;
serviceClient.call(req, [this](const roscpp::GetLoggers::Response &loggers, bool ok, uint8_t callResult){
switch(callResult)
{
case rosserial_msgs::ServiceCallResult::NO_EXISTENCE:
std::cout << "Service " << serviceClient.topic_ << " does not exist" << std::endl;
break;
case rosserial_msgs::ServiceCallResult::CALL_FAILED:
std::cout << "Call to service " << serviceClient.topic_ << " failed" << std::endl;

if(i % 2 == 0)
{
std::cout << "Service client call with bool and uint8_t results API" << std::endl;
serviceClient.call(req, [this](const roscpp::GetLoggers::Response &loggers, bool ok, uint8_t callResult){
(void)ok;
switch(callResult)
{
case rosserial_msgs::ServiceCallResult::NO_EXISTENCE:
std::cout << "Service " << serviceClient.topic_ << " does not exist" << std::endl;
break;
case rosserial_msgs::ServiceCallResult::CALL_FAILED:
std::cout << "Call to service " << serviceClient.topic_ << " failed" << std::endl;
break;
case rosserial_msgs::ServiceCallResult::SUCCESS:
std::cout << "loggers : " << QJsonDocument(loggers.serializeAsJson()).toJson(QJsonDocument::Indented).toStdString() << std::endl;
break;
case rosserial_msgs::ServiceCallResult::SUCCESS:
std::cout << "loggers : " << QJsonDocument(loggers.serializeAsJson()).toJson(QJsonDocument::Indented).toStdString() << std::endl;
break;
}
});
}
});
}
else
{
std::cout << "Service client call with only bool result API" << std::endl;
serviceClient.call(req, [this](const roscpp::GetLoggers::Response &loggers, bool ok){
if(ok)
{
std::cout << "loggers : " << QJsonDocument(loggers.serializeAsJson()).toJson(QJsonDocument::Indented).toStdString() << std::endl;
}
else
{
std::cout << "Call to service " << serviceClient.topic_ << " failed" << std::endl;
}
});
}
}

void Node::addTwoInts(const roscpp_tutorials::TwoIntsRequest &req, roscpp_tutorials::TwoIntsResponse &res)
Expand Down

0 comments on commit 5a25212

Please sign in to comment.