25 const unsigned int line,
30 const char* comp_name,
42 static const char* err_str =
"[ERROR] ";
43 static const char* warn_str =
"[WARNING] ";
44 static const char* no_str =
"";
51 "yarp.carrier.tcpros.yarpros",
59std::string
addPart(std::string
t, std::string name,
int code,
Value *val, std::string orig, std::string mode=
"") {
62 sprintf(buf,
"%s %s # suggested length: %d",
t.c_str(), name.c_str(), code);
63 }
else if (mode==
"string") {
64 sprintf(buf,
"%s %s # value seen: \"%s\"",
t.c_str(), name.c_str(), orig.c_str());
65 }
else if (mode==
"vocab") {
66 char char4 = (code>>24)%256;
67 char char3 = (code>>16)%256;
68 char char2 = (code>>8)%256;
69 char char1 = code%256;
72 r +=
'\''; r += char1; r +=
"\'*256^3";
78 r +=
'\''; r += char2; r +=
"\'*256^2";
84 r +=
'\''; r += char3; r +=
"\'*256";
90 r +=
'\''; r += char4; r +=
'\'';
95 sprintf(buf,
"%s %s # set to %d (=%s=%s)",
t.c_str(), name.c_str(), code, r.c_str(), orig.c_str());
98 sprintf(buf,
"%s %s # set to %s (%s)",
t.c_str(), name.c_str(), val->
toString().c_str(), orig.c_str());
100 sprintf(buf,
"%s %s # set to %d (%s)",
t.c_str(), name.c_str(), code, orig.c_str());
111 bool specialized = (code>0);
113 r +=
addPart(
"int32[]",root,b.
size(),
nullptr,
"length",
"length");
116 r +=
" # integers seen: ";
117 for (
size_t i=0; i<b.
size(); i++) {
127 r +=
addPart(
"float64[]",root,b.
size(),
nullptr,
"length",
"length");
130 r +=
" # floats seen: ";
131 for (
size_t i=0; i<b.
size(); i++) {
140 r +=
addPart(
"int32",root +
"_len",b.
size(),
nullptr,
"elements in list");
142 for (
size_t i=0; i<b.
size(); i++) {
146 sprintf(tag_name,
"%s%zu_tag", root.c_str(), i);
147 sprintf(val_name,
"%s%zu", root.c_str(), i);
151 "BOTTLE_TAG_VOCAB32");
167 "BOTTLE_TAG_FLOAT64");
184 "BOTTLE_TAG_STRING");
200 const char *example =
nullptr,
201 const char *explanation =
nullptr) {
202 yCInfo(YARPROS,
"\n yarpros %s", action);
203 yCInfo(YARPROS,
" %s\n", msg);
204 if (example!=
nullptr) {
205 yCInfo(YARPROS,
" $ yarpros %s", example);
207 if (explanation!=
nullptr) {
208 yCInfo(YARPROS,
" # %s", explanation);
213 yCInfo(YARPROS,
"Welcome to yarpros. Here are the most useful commands available:");
214 usage(
"sniff out <port>",
"suggest .msg for output from <port> ",
"sniff out /grabber");
215 usage(
"sniff in <port>",
"suggest .msg for input to <port> ",
"sniff in /grabber");
216 usage(
"type <name>",
"(MOVED to yarpidl_rosmsg) generate YARP header files from <name>.msg",
"type PointCloud2");
217 usage(
"help",
"show this help",
nullptr);
220 yCInfo(YARPROS,
"YARP clients can use the ROS name server. If you'd prefer to stick");
221 yCInfo(YARPROS,
"with the native YARP name server, the following commands are useful:");
222 usage(
"roscore",
"register port /roscore to refer to ROS_MASTER_URI",
"roscore");
223 usage(
"roscore <hostname> <port number>",
"manually register port /roscore to point to the ros master",
"roscore 192.168.0.1 11311");
224 usage(
"pub[lisher] <node> <topic>",
"register a ROS publisher <node>/<topic> pair as a port called <node><topic>",
"publisher /talker /chatter",
"this registers a port called /talker/chatter");
225 usage(
"pub[lisher] <port> <node> <topic>",
"register a ROS publisher <node>/<topic> pair as a port called <port>",
"publisher /talker /talker /chatter");
226 usage(
"sub[scriber] <node> <topic>",
"register a ROS subscriber <node>/<topic> pair as a port called <node><topic>",
"subscriber /listener /chatter",
"this registers a port called /listener/chatter");
227 usage(
"sub[scriber] <yarp> <node> <topic>",
"register a ROS subscriber <node>/<topic> pair as a port called <port>",
"subscriber /listener /listener /chatter");
228 usage(
"service <yarp> <node> <service>",
"register a ROS service <node>/<service> pair as a port called <port>",
"service /adder /add_two_ints_server /add_two_ints");
229 usage(
"node <name>",
"register a ROS node name with YARP",
"node /talker");
244 const char *hostname,
247 std::string ip = Contact::convertHostToIp(hostname);
265int main(
int argc,
char *argv[]) {
270 if (std::string(argv[1])==
"help" ||
271 std::string(argv[1])==
"--help") {
280 for (
int i=1; i<argc; i++) {
283 if (argv[i][0]!=
'-') {
292 if (options.
check(
"verbose")) {
293 yCWarning(YARPROS,
"The 'verbose' option is deprecated");
300 if (tag==
"roscore") {
303 yCError(YARPROS,
"wrong syntax, run with no arguments for help");
315 yCError(YARPROS,
"cannot find roscore, is ROS_MASTER_URI set?");
324 }
else if (tag==
"node") {
327 yCError(YARPROS,
"wrong syntax, run with no arguments for help");
331 yCError(YARPROS,
"wrong syntax, run with no arguments for help");
345 }
else if (tag==
"publisher"||tag==
"pub"||tag==
"service"||tag==
"srv") {
346 bool service = (tag==
"service"||tag==
"srv");
348 if (cmd.
size()!=3 && cmd.
size()!=4) {
349 yCError(YARPROS,
"wrong syntax, run with no arguments for help");
356 std::string yarp_port = cmd.
get(1+offset).
asString();
357 std::string ros_port = cmd.
get(2+offset).
asString();
360 yarp_port = ros_port + topic;
363 yCDebug(YARPROS,
" * looking up ros node %s", ros_port.c_str());
368 yCDebug(YARPROS,
" * found ros node %s", ros_port.c_str());
369 yCDebug(YARPROS,
" * looking up topic %s", topic.c_str());
374 yCDebug(YARPROS,
" * found topic %s", topic.c_str());
375 std::string carrier =
"tcpros+role.pub+topic.";
377 carrier =
"rossrv+service.";
380 (carrier+topic).c_str(),
386 }
else if (tag==
"subscriber"||tag==
"sub") {
388 if (cmd.
size()!=3 && cmd.
size()!=4) {
389 yCError(YARPROS,
"wrong syntax, run with no arguments for help");
396 std::string yarp_port = cmd.
get(1+offset).
asString();
397 std::string ros_port = cmd.
get(2+offset).
asString();
400 yarp_port = ros_port + topic;
403 yCDebug(YARPROS,
" * looking up ros node %s", ros_port.c_str());
408 yCDebug(YARPROS,
" * found ros node %s", ros_port.c_str());
410 (std::string(
"tcpros+role.sub+topic.")+topic).c_str(),
416 }
else if (tag==
"type") {
417 yCError(YARPROS,
"MOVED: 'yarpros type' is now 'yarpidl_rosmsg'");
419 }
else if (tag==
"sniff") {
421 yCError(YARPROS,
"Show the format of a YARP bottle-compatible message in ROS syntax.");
428 }
else if (dir ==
"out") {
431 yCError(YARPROS,
"Please specify one of 'in' or 'out'.");
436 if (!p.
open(
"...")) {
440 if (!Network::connect(pname, p.
getName(),
"tcp+log.in")) {
444 if (!Network::connect(pname, p.
getName())) {
457 yCInfo(YARPROS,
"Got message: [%s]",r.c_str());
460 yCError(YARPROS,
"unknown command, run with no arguments for help");
#define BOTTLE_TAG_FLOAT64
#define BOTTLE_TAG_STRING
#define BOTTLE_TAG_VOCAB32
bool lookupTopic(const std::string &name)
bool lookupCore(const std::string &name)
static yarp::os::Contact getRosCoreAddressFromEnv()
A simple collection of objects that can be described and transmitted in a portable way.
void add(const Value &value)
Add a Value to the bottle, at the end of the list.
int getSpecialization()
Get numeric bottle code for this bottle.
size_type size() const
Gets the number of elements in the bottle.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
void addString(const char *str)
Places a string in the bottle, at the end of the list.
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Utilities for manipulating the YARP network, including initialization and shutdown.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
A mini-server for network communication.
bool read(PortReader &reader, bool willReply=false) override
Read an object from the port.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
A class for storing options and configuration information.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
void fromCommand(int argc, char *argv[], bool skipFirst=true, bool wipe=true)
Interprets a list of command arguments as a list of properties.
A single value (typically within a Bottle).
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
virtual bool isString() const
Checks if value is a string.
virtual yarp::conf::vocab32_t asVocab32() const
Get vocabulary identifier as an integer.
virtual std::int32_t asInt32() const
Get 32-bit integer value.
virtual size_t asBlobLength() const
Get binary data length.
virtual bool isList() const
Checks if value is a list.
virtual Bottle * asList() const
Get list value.
virtual bool isBlob() const
Checks if value is a binary object.
virtual bool isFloat64() const
Checks if value is a 64-bit floating point number.
std::string toString() const override
Return a standard text representation of the content of the object.
virtual bool isInt32() const
Checks if value is a 32-bit integer.
virtual bool isVocab32() const
Checks if value is a vocabulary identifier.
void fromString(const char *str)
Set value to correspond to a textual representation.
virtual std::string asString() const
Get string value.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
void print_callback(yarp::os::Log::LogType type, const char *msg, const char *file, const unsigned int line, const char *func, double systemtime, double networktime, double externaltime, const char *comp_name)
An interface to the operating system, including Port based communication.
constexpr yarp::conf::vocab32_t createVocab32(char a, char b=0, char c=0, char d=0)
Create a vocab from chars.
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
The main, catch-all namespace for YARP.
std::string showFormat(Bottle &b, std::string root)
std::string addPart(std::string t, std::string name, int code, Value *val, std::string orig, std::string mode="")
int main(int argc, char *argv[])
bool register_port(const char *name, const char *carrier, const char *hostname, int portnum, PortReader &reply)
bool announce_port(const char *name, PortReader &reply)
void usage(const char *action, const char *msg, const char *example=nullptr, const char *explanation=nullptr)