|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
32 headerLen1 = *
reinterpret_cast<const NetInt32*
>(header.
get());
33 headerLen2 = *
reinterpret_cast<const NetInt32*
>(header.
get() + 4);
40 setParameters(header);
41 if (!(headerLen1<60000&&headerLen1>0 &&
42 headerLen2<60000&&headerLen2>0)) {
58 md5sum =
t.readProperties().find(
"md5sum").asString();
59 message_definition =
t.readProperties().find(
"message_definition").asString();
61 if (typ==
"yarp/image") {
62 wire_type =
"sensor_msgs/Image";
64 }
else if (typ==
"yarp/bottle") {
66 if (rtyp==
"yarp/image") rtyp =
"sensor_msgs/Image";
74 std::string mode =
"topic";
75 std::string modeValue = n.getCarrierModifier(
"topic");
78 modeValue = n.getCarrierModifier(
"service");
81 std::string
package = n.getCarrierModifier("package");
83 rtyp =
package + "/" + modeValue;
96 std::string mode =
"topic";
106 modeValue =
"notopic";
113 }
else if (rawValue==
"1") {
116 }
else if (rawValue==
"0") {
125 std::string rtyp = getRosType(proto);
127 header.
data[
"type"] = rtyp;
129 header.
data[mode] = modeValue;
130 header.
data[
"md5sum"] = (md5sum!=
"")?md5sum:
"*";
131 if (message_definition!=
"") {
132 header.
data[
"message_definition"] = message_definition;
136 header.
data[
"persistent"] =
"1";
138 string header_len(4,
'\0');
139 char *at = (
char*)header_len.c_str();
143 (
int)header_len.length());
145 Bytes b1((
char*)header_len.c_str(),header_len.length());
149 (
int)header_serial.length());
150 Bytes b2((
char*)header_serial.c_str(),header_serial.length());
161 Bytes mlen_buf(mlen,4);
183 if (header.
data.find(
"type")!=header.
data.end()) {
184 rosname = header.
data[
"type"];
187 if (header.
data.find(
"callerid")!=header.
data.end()) {
188 string name = header.
data[
"callerid"];
198 isService = (header.
data.find(
"request_type")!=header.
data.end());
200 if (rosname!=
"" && (user_type != wire_type || user_type ==
"")) {
212 processRosHeader(header);
221 if (stream==
nullptr) {
return false; }
238 memcpy(m.
get(),(
char*)(&ni), 4);
242 if (res!=(
int)mrem.
length()) {
256 if (header.
data.find(
"type")!=header.
data.end()) {
257 rosname = header.
data[
"type"];
259 std::string rtyp = getRosType(proto);
262 header.
data[
"type"] = rosname;
263 header.
data[
"md5sum"] = (md5sum!=
"")?md5sum:
"*";
264 if (message_definition!=
"") {
265 header.
data[
"message_definition"] = message_definition;
271 if (header.
data.find(
"callerid")!=header.
data.end()) {
285 string header_len(4,
'\0');
286 char *at = (
char*)header_len.c_str();
290 (
int)header_len.length());
292 Bytes b1((
char*)header_len.c_str(),header_len.length());
296 (
int)header_serial.length());
297 Bytes b2((
char*)header_serial.c_str(),header_serial.length());
300 if (header.
data.find(
"probe")!=header.
data.end()) {
307 isService = (header.
data.find(
"service")!=header.
data.end());
309 if (rosname!=
"" && (user_type != wire_type || user_type ==
"")) {
310 if (wire_type!=
"sensor_msgs/Image") {
320 processRosHeader(header);
329 if (stream==
nullptr) {
return false; }
347 if (user_type==
"yarp/image"||user_type==
"yarp/bottle") {
348 img = wi.checkForImage(writer);
352 std::string frame =
"/frame";
355 if (WireBottle::extractBlobFromBottle(writer,wt)) {
371 FlexImage *img = wi.checkForImage(writer);
384 if (!WireBottle::extractBlobFromBottle(writer,wt)) {
394 twiddler_output.attach(writer,twiddler);
395 if (twiddler_output.update()) {
396 flex_writer = &twiddler_output;
398 flex_writer =
nullptr;
410 if (flex_writer ==
nullptr) {
415 for (
size_t i=0; i<flex_writer->
length(); i++) {
416 len += (int)flex_writer->
length(i);
419 (
int)flex_writer->
length(),
422 string header_len(4,
'\0');
423 char *at = (
char*)header_len.c_str();
425 Bytes b1((
char*)header_len.c_str(),header_len.length());
427 flex_writer->
write(proto.
os());
445 Bytes twiddle_buf(twiddle,1);
447 return write(proto,writer);
467 if (!reversed)
return -1;
496 sprintf(buf,
"http://%s:%d/", addr_slave.
getHost().c_str(),
510 yCError(
TCPROSCARRIER,
"Problem: did not get a callback from ROS - can happen if connection already exists.");
518 void TcpRosCarrier::processRosHeader(
RosHeader& header) {
519 if (header.
data.find(
"persistent")!=header.
data.end()) {
520 persistent = (header.
data[
"persistent"]==
"1");
std::string toString() const
Render a text form of the route, "source->carrier->dest".
virtual const Contact & getLocalAddress() const =0
Get the address of the local side of the stream.
#define TCPROS_TRANSLATE_IMAGE
A simple collection of objects that can be described and transmitted in a portable way.
virtual size_t length() const =0
std::string toString() const override
Gives a human-readable textual representation of the bottle.
const std::string & getCarrierName() const
Get the carrier type of the route.
virtual void close()=0
Terminate the stream.
#define yCWarning(component,...)
virtual TwoWayStream * giveStreams()=0
Take ownership of the streams associated with the connection.
virtual void write(char ch)
Write a single byte to the stream.
static std::map< std::string, std::string > rosToKind()
static bool write(const Contact &contact, PortWriter &cmd, PortReader &reply, bool admin=false, bool quiet=false, double timeout=-1)
Send a single command to a port and await a single response.
#define TCPROS_TRANSLATE_INHIBIT
#define TCPROS_TRANSLATE_BOTTLE_BLOB
bool expectReplyToHeader(yarp::os::ConnectionState &proto) override
Process reply to header, if one is expected for this carrier.
virtual void write(OutputStream &os)
Information about a connection between two ports.
static bool configureTwiddler(yarp::wire_rep_utils::WireTwiddler &twiddler, const char *txt, const char *prompt, bool sender, bool reply)
double now()
Return the current time in seconds, relative to an arbitrary starting point.
const Bytes & bytes() const
static Contact queryName(const std::string &name)
Find out information about a registered name.
virtual void takeStreams(TwoWayStream *streams)=0
Provide streams to be used with the connection.
std::string getNameOnWire() const
OutputStream & os()
Shorthand for getOutputStream()
virtual const Route & getRoute() const =0
Get the route associated with this connection.
An abstraction for a block of bytes, with optional responsibility for allocating/destroying that bloc...
Bottle & addList()
Places an empty nested list in the bottle, at the end of the list.
Image class with user control of representation details.
virtual void setRoute(const Route &route)=0
Set the route associated with this connection.
bool expectSenderSpecifier(yarp::os::ConnectionState &proto) override
Expect the name of the sending port.
bool checkHeader(const yarp::os::Bytes &header) override
Given the first 8 bytes received on a connection, decide if this is the right carrier type to use for...
void start(const char *hostname, int portnum)
std::string getCarrierModifier(const char *mod, bool *hasModifier=nullptr)
#define YARP_ENACT_DISCONNECT
virtual const Contact & getRemoteAddress() const =0
Get the address of the remote side of the stream.
Simple abstraction for a YARP port name.
bool sendHeader(yarp::os::ConnectionState &proto) override
Write a header appropriate to the carrier to the connection, followed by any carrier-specific data.
virtual TwoWayStream & getStreams()=0
Access the streams associated with the connection.
void addString(const char *str)
Places a string in the bottle, at the end of the list.
A simple abstraction for a block of bytes.
bool write(yarp::os::ConnectionState &proto, yarp::os::SizedWriter &writer) override
Write a message.
The basic state of a connection - route, streams in use, etc.
#define yCError(component,...)
virtual bool isOk() const =0
Check if the stream is ok or in an error state.
virtual int connect(const yarp::os::Contact &src, const yarp::os::Contact &dest, const yarp::os::ContactStyle &style, int mode, bool reversed) override
Some carrier types may require special connection logic.
#define yCInfo(component,...)
An interface to the operating system, including Port based communication.
#define TCPROS_TRANSLATE_TWIDDLER
#define TCPROS_TRANSLATE_UNKNOWN
void setFromName(const std::string &fromName)
Set the source of the route.
InputStream & is()
Shorthand for getInputStream()
void setToName(const std::string &toName)
Set the destination of the route.
const std::string & getToName() const
Get the destination of the route.
virtual bool isOk() const =0
Check if the stream is ok or in an error state.
bool reply(yarp::os::ConnectionState &proto, yarp::os::SizedWriter &writer) override
#define yCTrace(component,...)
void setParameters(const yarp::os::Bytes &header) override
Configure this carrier based on the first 8 bytes of the connection.
virtual Contactable * getContactable() const =0
Get the port associated with the connection.
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
const std::string & getFromName() const
Get the source of the route.
static int netInt(const yarp::os::Bytes &code)
#define YARP_ENACT_EXISTS
Minimal requirements for an efficient Writer.
const yarp::os::LogComponent & TCPROSCARRIER()
yarp::os::Contact where()
std::int32_t NetInt32
Definition of the NetInt32 type.