28 headerLen1 = *
reinterpret_cast<const NetInt32*
>(header.
get());
29 headerLen2 = *
reinterpret_cast<const NetInt32*
>(header.
get() + 4);
36 setParameters(header);
37 if (!(headerLen1<60000&&headerLen1>0 &&
38 headerLen2<60000&&headerLen2>0)) {
54 md5sum =
t.readProperties().find(
"md5sum").asString();
55 message_definition =
t.readProperties().find(
"message_definition").asString();
57 if (typ==
"yarp/image") {
58 wire_type =
"sensor_msgs/Image";
60 }
else if (typ==
"yarp/bottle") {
62 if (rtyp ==
"yarp/image") {
63 rtyp =
"sensor_msgs/Image";
72 std::string mode =
"topic";
73 std::string modeValue = n.getCarrierModifier(
"topic");
76 modeValue = n.getCarrierModifier(
"service");
79 std::string
package = n.getCarrierModifier("package");
81 rtyp =
package + "/" + modeValue;
94 std::string mode =
"topic";
104 modeValue =
"notopic";
111 }
else if (rawValue==
"1") {
114 }
else if (rawValue==
"0") {
123 std::string rtyp = getRosType(proto);
125 header.
data[
"type"] = rtyp;
127 header.
data[mode] = modeValue;
128 header.
data[
"md5sum"] = (md5sum!=
"")?md5sum:
"*";
129 if (message_definition!=
"") {
130 header.
data[
"message_definition"] = message_definition;
134 header.
data[
"persistent"] =
"1";
136 std::string header_len(4,
'\0');
137 char *at = (
char*)header_len.c_str();
141 (
int)header_len.length());
143 Bytes b1((
char*)header_len.c_str(),header_len.length());
147 (
int)header_serial.length());
148 Bytes b2((
char*)header_serial.c_str(),header_serial.length());
159 Bytes mlen_buf(mlen,4);
181 if (header.
data.find(
"type")!=header.
data.end()) {
182 rosname = header.
data[
"type"];
185 if (header.
data.find(
"callerid")!=header.
data.end()) {
186 std::string name = header.
data[
"callerid"];
196 isService = (header.
data.find(
"request_type")!=header.
data.end());
198 if (rosname!=
"" && (user_type != wire_type || user_type ==
"")) {
210 processRosHeader(header);
219 if (stream==
nullptr) {
return false; }
236 memcpy(m.
get(),(
char*)(&ni), 4);
240 if (res!=(
int)mrem.
length()) {
254 if (header.
data.find(
"type")!=header.
data.end()) {
255 rosname = header.
data[
"type"];
257 std::string rtyp = getRosType(proto);
260 header.
data[
"type"] = rosname;
261 header.
data[
"md5sum"] = (md5sum!=
"")?md5sum:
"*";
262 if (message_definition!=
"") {
263 header.
data[
"message_definition"] = message_definition;
269 if (header.
data.find(
"callerid")!=header.
data.end()) {
283 std::string header_len(4,
'\0');
284 char *at = (
char*)header_len.c_str();
288 (
int)header_len.length());
290 Bytes b1((
char*)header_len.c_str(),header_len.length());
294 (
int)header_serial.length());
295 Bytes b2((
char*)header_serial.c_str(),header_serial.length());
298 if (header.
data.find(
"probe")!=header.
data.end()) {
305 isService = (header.
data.find(
"service")!=header.
data.end());
307 if (rosname!=
"" && (user_type != wire_type || user_type ==
"")) {
308 if (wire_type!=
"sensor_msgs/Image") {
318 processRosHeader(header);
327 if (stream==
nullptr) {
return false; }
345 if (user_type==
"yarp/image"||user_type==
"yarp/bottle") {
346 img = wi.checkForImage(writer);
350 std::string frame =
"/frame";
353 if (WireBottle::extractBlobFromBottle(writer,wt)) {
369 FlexImage *img = wi.checkForImage(writer);
382 if (!WireBottle::extractBlobFromBottle(writer,wt)) {
392 twiddler_output.attach(writer,twiddler);
393 if (twiddler_output.update()) {
394 flex_writer = &twiddler_output;
396 flex_writer =
nullptr;
408 if (flex_writer ==
nullptr) {
413 for (
size_t i=0; i<flex_writer->
length(); i++) {
414 len += (int)flex_writer->
length(i);
417 (
int)flex_writer->
length(),
420 std::string header_len(4,
'\0');
421 char *at = (
char*)header_len.c_str();
423 Bytes b1((
char*)header_len.c_str(),header_len.length());
425 flex_writer->
write(proto.
os());
443 Bytes twiddle_buf(twiddle,1);
445 return write(proto,writer);
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");
#define YARP_ENACT_DISCONNECT
#define YARP_ENACT_EXISTS
#define TCPROS_TRANSLATE_UNKNOWN
#define TCPROS_TRANSLATE_BOTTLE_BLOB
#define TCPROS_TRANSLATE_TWIDDLER
#define TCPROS_TRANSLATE_IMAGE
#define TCPROS_TRANSLATE_INHIBIT
const yarp::os::LogComponent & TCPROSCARRIER()
yarp::os::Contact where()
void start(const char *hostname, int portnum)
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.
bool reply(yarp::os::ConnectionState &proto, yarp::os::SizedWriter &writer) override
void setParameters(const yarp::os::Bytes &header) override
Configure this carrier based on the first 8 bytes of the connection.
bool write(yarp::os::ConnectionState &proto, yarp::os::SizedWriter &writer) override
Write a message.
bool expectSenderSpecifier(yarp::os::ConnectionState &proto) override
Expect the name of the sending port.
bool sendHeader(yarp::os::ConnectionState &proto) override
Write a header appropriate to the carrier to the connection, followed by any carrier-specific data.
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...
bool expectReplyToHeader(yarp::os::ConnectionState &proto) override
Process reply to header, if one is expected for this carrier.
static std::map< std::string, std::string > rosToKind()
static bool configureTwiddler(yarp::wire_rep_utils::WireTwiddler &twiddler, const char *txt, const char *prompt, bool sender, bool reply)
A simple collection of objects that can be described and transmitted in a portable way.
Bottle & addList()
Places an empty nested list 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.
A simple abstraction for a block of bytes.
The basic state of a connection - route, streams in use, etc.
virtual Contactable * getContactable() const =0
Get the port associated with the connection.
virtual TwoWayStream & getStreams()=0
Access the streams associated with the connection.
virtual const Route & getRoute() const =0
Get the route associated with this connection.
virtual TwoWayStream * giveStreams()=0
Take ownership of the streams associated with the connection.
virtual void takeStreams(TwoWayStream *streams)=0
Provide streams to be used with the connection.
InputStream & is()
Shorthand for getInputStream()
OutputStream & os()
Shorthand for getOutputStream()
virtual void setRoute(const Route &route)=0
Set the route associated with this connection.
An abstraction for a block of bytes, with optional responsibility for allocating/destroying that bloc...
const Bytes & bytes() const
Simple abstraction for a YARP port name.
std::string getCarrierModifier(const char *mod, bool *hasModifier=nullptr)
static int netInt(const yarp::os::Bytes &code)
static Contact queryName(const std::string &name)
Find out information about a registered name.
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.
virtual bool isOk() const =0
Check if the stream is ok or in an error state.
virtual void write(char ch)
Write a single byte to the stream.
virtual void close()=0
Terminate the stream.
Information about a connection between two ports.
const std::string & getToName() const
Get the destination of the route.
const std::string & getCarrierName() const
Get the carrier type of the route.
void setToName(const std::string &toName)
Set the destination of the route.
std::string toString() const
Render a text form of the route, "source->carrier->dest".
const std::string & getFromName() const
Get the source of the route.
void setFromName(const std::string &fromName)
Set the source of the route.
Minimal requirements for an efficient Writer.
virtual void write(OutputStream &os)
virtual size_t length() const =0
virtual const Contact & getLocalAddress() const =0
Get the address of the local side of the stream.
virtual const Contact & getRemoteAddress() const =0
Get the address of the remote side of the stream.
virtual bool isOk() const =0
Check if the stream is ok or in an error state.
std::string getNameOnWire() const
Image class with user control of representation details.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCTrace(component,...)
#define yCWarning(component,...)
double now()
Return the current time in seconds, relative to an arbitrary starting point.
An interface to the operating system, including Port based communication.
std::int32_t NetInt32
Definition of the NetInt32 type.
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)