47 lines
843 B
C++
47 lines
843 B
C++
#include "test_topic/minPublisher.h"
|
|
|
|
MinPublisher::MinPublisher()
|
|
{
|
|
_sender = this->advertise<MsgType>("test_topic", 200);
|
|
}
|
|
|
|
MinPublisher::~MinPublisher()
|
|
{
|
|
_serial.close();
|
|
}
|
|
|
|
void MinPublisher::run(const char *device)
|
|
{
|
|
_serial.open(device, 115200, 1, 8, 'N');
|
|
char *read_buf = new char[500];
|
|
|
|
while (ros::ok())
|
|
{
|
|
std_msgs::String msg;
|
|
std::stringstream ss;
|
|
|
|
memset(read_buf, 0, 500);
|
|
|
|
int len = _serial.read_data(read_buf, 500);
|
|
if (len <= 0)
|
|
{
|
|
continue;
|
|
}
|
|
ss << read_buf;
|
|
msg.data = ss.str();
|
|
|
|
ROS_INFO("send: '%s'", msg.data.c_str());
|
|
_sender.publish(msg);
|
|
}
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
ros::init(argc, argv, "test_pub_node");
|
|
MinPublisher nh;
|
|
|
|
nh.run("/dev/ttyUSB0");
|
|
|
|
return 0;
|
|
}
|