LCM logger (c++)

361 views
Skip to first unread message

Kumius

unread,
Dec 11, 2016, 9:49:39 AM12/11/16
to Lightweight Communications and Marshalling
Hello, I'm learning to use LCM (C++) to accomplish a project. I have got a problem when tyring to record the broadcast data, and then replay it. I haven't find any useful C++ cases.

lcm::LCM lcm("file://log.txt?mode=w");
if (!lcm.good())
{
   
return 1;
}
Handler handler;
lcm
.subscribe("EXAMPLE", &Handler::handleMessage, &handler);
 
if (0 == lcm.handle());

It seems that the code above doesn't work. Can somebody help me?

Many thanks!

Matthew Tesch

unread,
Dec 11, 2016, 12:48:15 PM12/11/16
to lcm-...@googlegroups.com
I'm not on a system right now that I can compile at test this on, but my first guess would be the path you are passing to the LCM constructor needs to be a full file path, not just a local path.  (Even if a local path is accepted, make sure that you are running the program with the correct environment so that the file you think is local really is local)

Looking at the documentation for the url parameter:

The examples here are of the form:
 "file:///home/albert/path/to/logfile?speed=4"

(Note the three forward slashes to give a full path of /home/albert/path/to/logfile).

If giving the full path does not solve your problem, could you provide more information about what doesn't work?

Best,
Matt

--
You received this message because you are subscribed to the Google Groups "Lightweight Communications and Marshalling" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lcm-users+...@googlegroups.com.
To post to this group, send email to lcm-...@googlegroups.com.
Visit this group at https://groups.google.com/group/lcm-users.
For more options, visit https://groups.google.com/d/optout.

Kumius

unread,
Dec 11, 2016, 10:41:15 PM12/11/16
to Lightweight Communications and Marshalling, matthe...@gmail.com
Hi Matt,

Thanks for your response! That's very kind of you.

The program is running on a Win10 (x64) PC. If I don't set the the log path, it works and the 'receiver' can receive messages from the 'sender'.
 lcm::LCM lcm("");

 
if (!lcm.good())
 
{
   
return 1;
 
}
 
Handler handler;
 lcm
.subscribe("EXAMPLE", &Handler::handleMessage, &handler);

 
while (0 == lcm.handle());
 cout
<< "done..." << endl;


However, once I set the log path (local path or full file path), the function 'lcm.handle()' returns -1.
lcm::LCM lcm("file://d:/data/text/log.txt?mode=w");

Do I have to record the broadcast data by myself? I used to think tha the lcm instance will do tha for me if I set the file path of log.
Sorry to bother you again, but I'm really confused.

Best,
Kumius

Jonathan Bendes

unread,
Dec 11, 2016, 11:01:06 PM12/11/16
to Lightweight Communications and Marshalling, matthe...@gmail.com
Hi Kumius,

I think there's a fundamental misunderstanding of the API here. When you create a new instance of lcm, you pass in a URL. That URL indicates the transport to be used for that instance of lcm.

The "file://" syntax is a way to get lcm to read or write from a log. So if you create a new instance of lcm with a "file://" URL in mode "w", you can "publish" events into the file. That instance of lcm will have no other traffic that it processes other than the messages you publish into the file. It seems like maybe you thought the instance would also have access to UDP lcm traffic? It would not unless initialized with a URL indicating it should set up a UDP transport.

What is the ultimate goal here? What exactly are you trying to do? Just log data coming over a transport? Take a look at lcm-logger if that's what you're trying to do. If not, feel free to provide a few more details.

Best,
Jonathan


--
You received this message because you are subscribed to the Google Groups "Lightweight Communications and Marshalling" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lcm-users+...@googlegroups.com.
To post to this group, send email to lcm-...@googlegroups.com.
Visit this group at https://groups.google.com/group/lcm-users.
For more options, visit https://groups.google.com/d/optout.
--
Jonathan Bendes
Vice President of Product Development

Kumius

unread,
Dec 11, 2016, 11:50:59 PM12/11/16
to Lightweight Communications and Marshalling, matthe...@gmail.com
Thanks a lot!

Logging data coming over a transport is exactly what I want. I've been reading the lcm-logger.
I really appreciate the help from you and your team!

Best,
Kumius


在 2016年12月12日星期一 UTC+8下午12:01:06,Jonathan Bendes写道:
Reply all
Reply to author
Forward
0 new messages