LCM支持多种语言,也有很多版本,这里只介绍C++的几个类以及方法。
类型简介
C++的API,LC提供了三个类以及两个结构体来封装LCM,他们分别是:
class lcm::LCM
struct lcm::ReceiveBuffer
class lcm::Subscription
struct lcm::LogEvent
class lcm::LogFile
两个struct是配合类来使用的。前三个可以看成一组,后面两个是配合使用的。
lcm::ReceiveBuffer
这个结构体很眼熟,就是我们需要写的回调函数的第一个参数的指针类型,先看一下其定义:
/**
* @brief Stores the raw bytes and timestamp of a received message.
*
* @headerfile lcm/lcm-cpp.hpp
*/
struct ReceiveBuffer {
/**
* Message payload data, represented as a raw byte buffer.
*/
void *data;
/**
* Length of message payload, in bytes.
*/
uint32_t data_size;
/**
* Timestamp identifying when the message was received. Specified in
* microseconds since the UNIX epoch.
*/
int64_t recv_utime;
};
只有三个成员,data是我们的接收到的数据转换成字节流后的指针,也就是recvfrom调用收到的原始数据,第二个成员是数据大小,第三个是接收到数据时的时间戳。(LCM内部使用,我们一般不会用到)
lcm::Subscription
这个类其实是一个与文件描述符类似的东西,先看定义:
class Subscription {
public:
virtual ~Subscription() {}
/**
* @brief Adjusts the maximum number of received messages that can be
* queued up for this subscription.
*
* @param num_messages the maximum queue size, in messa