14 rpcServerPort_Name =
"/ControllerServer/rpc:i";
15 outputPort_Name =
"/ControllerServer:o";
26 res &= rpcServerPort.open(rpcServerPort_Name.c_str());
27 rpcServerPort.setReader(*
this);
28 res &= outputPort.open(outputPort_Name.c_str());
33 rpcServerPort.close();
39 yarp::os::Bottle input, reply;
41 if (!input.read(connection)){
45 yarp::os::ConnectionWriter* returnToSender = connection.getWriter();
46 if (returnToSender!=NULL) {
47 if (!reply.write(*returnToSender)) {
57 int btlSize = input.size();
58 for (
int i=0; i<btlSize; ++i)
60 switch (input.get(i).asInt()) {
63 std::cout <<
"Got message: GET_CONTROLLER_STATUS." << std::endl;
69 std::cout <<
"Got message: GET_WBI_CONFIG_FILE_PATH." << std::endl;
75 std::cout <<
"Got message: GET_ROBOT_NAME." << std::endl;
81 OCRA_INFO(
"Got message: GET_IS_FLOATING_BASE.");
82 reply.addInt(!model->hasFixedRoot());
87 std::cout <<
"Got message: START_CONTROLLER." << std::endl;
94 std::cout <<
"Got message: STOP_CONTROLLER." << std::endl;
100 std::cout <<
"Got message: PAUSE_CONTROLLER." << std::endl;
107 OCRA_INFO(
"Got message: CHANGE_FIXED_LINK_RIGHT.");
108 this->controller->setFixedLinkForOdometry(
"r_sole");
109 int isInLeftSupport = input.get(++i).asInt();
110 OCRA_INFO(
"Got message: " << isInLeftSupport);
111 int isInRightSupport = input.get(++i).asInt();
112 OCRA_INFO(
"Got message: " << isInRightSupport);
113 this->controller->setContactState(isInLeftSupport, isInRightSupport);
119 OCRA_INFO(
"Got message: CHANGE_FIXED_LINK_LEFT.");
120 this->controller->setFixedLinkForOdometry(
"l_sole");
121 int isInLeftSupport = input.get(++i).asInt();
122 OCRA_INFO(
"Got message: " << isInLeftSupport);
123 int isInRightSupport = input.get(++i).asInt();
124 OCRA_INFO(
"Got message: " << isInRightSupport);
125 this->controller->setContactState(isInLeftSupport, isInRightSupport);
132 int numberOfTasks = input.get(++i).asInt();
135 std::vector<ocra::TaskBuilderOptions> taskOptionsVector;
136 for (
int j=0; j<numberOfTasks; ++j)
138 int sizeOfOptions = 0;
142 taskOptionsVector.push_back(taskOptions);
152 std::cout <<
"Got message: ADD_TASK_FROM_FILE." << std::endl;
159 std::string taskToRemove = input.get(i).asString();
160 controller->removeTask(taskToRemove);
163 yarp::os::Bottle outputMessage;
165 outputMessage.addString(taskToRemove);
166 outputPort.write(outputMessage);
175 std::cout <<
"Got message: REMOVE_TASKS." << std::endl;
180 OCRA_INFO(
"Got message: GET_TASK_LIST.");
181 for(
auto taskName : controller->getTaskNames()) {
182 reply.addString(taskName);
188 OCRA_INFO(
"Got message: GET_TASK_PORT_LIST.");
189 for(
auto taskPort : controller->getTaskPortNames()) {
190 reply.addString(taskPort);
196 std::string taskName = input.get(++i).asString();
197 OCRA_INFO(
"Got message: GET_TASK_PORT_NAME.");
198 reply.addString(controller->getTaskPortName(taskName));
203 std::cout <<
"Got message: HELP." << std::endl;
208 std::cout <<
"Got message: UNKNOWN." << std::endl;
yarp::os::Bottle trimBottle(const yarp::os::Bottle &bottle, int startIndex, int endIndex=-1)
virtual ~ServerCommunications()
bool extractFromBottle(yarp::os::Bottle &bottle, int &sizeOfOptions)
virtual bool read(yarp::os::ConnectionReader &connection)
void parseMessage(yarp::os::Bottle &input, yarp::os::Bottle &reply)