1 | #include "ros/ros.h"
|
---|
2 |
|
---|
3 | #include <string>
|
---|
4 | #include <iostream>
|
---|
5 |
|
---|
6 | #include "serial.h"
|
---|
7 |
|
---|
8 | Serial *serial;
|
---|
9 |
|
---|
10 | std::string toHex(std::string input) {
|
---|
11 | std::stringstream ss;
|
---|
12 | for(unsigned int i = 0; i != input.length(); i++) {
|
---|
13 | char temp[4];
|
---|
14 | sprintf(temp, "%.2X", input[i]);
|
---|
15 | ss << " ";
|
---|
16 | if(input[i] == 0x0A)
|
---|
17 | ss << "LF";
|
---|
18 | else if(input[i] == 0x0D)
|
---|
19 | ss << "NL";
|
---|
20 | else
|
---|
21 | ss << input[i];
|
---|
22 | ss << " " << std::hex << temp;
|
---|
23 | }
|
---|
24 | return ss.str();
|
---|
25 | };
|
---|
26 |
|
---|
27 | int main(int argc, char **argv)
|
---|
28 | {
|
---|
29 | ros::init(argc, argv, "serial_test_node");
|
---|
30 |
|
---|
31 | ros::NodeHandle n;
|
---|
32 |
|
---|
33 | std::string port("/dev/tty.usbserial-A900cfJA");
|
---|
34 | // std::string port("/dev/tty.usbmodemfa141");
|
---|
35 |
|
---|
36 | serial = new Serial(port, 9600, 250);
|
---|
37 |
|
---|
38 | ros::Rate loop_rate(0.5);
|
---|
39 |
|
---|
40 | int count = 0;
|
---|
41 | while (ros::ok() and count != 30) {
|
---|
42 | // serial->write("Testing.");
|
---|
43 | // ROS_INFO("Out of write");
|
---|
44 | std::string result = serial->read(1);
|
---|
45 | std::cout << ">" << result << std::endl;
|
---|
46 |
|
---|
47 |
|
---|
48 | // ROS_INFO("Here.");
|
---|
49 |
|
---|
50 | // ROS_INFO(result.c_str());
|
---|
51 | // ROS_INFO("%d,%s", result.length(), toHex(result).c_str());
|
---|
52 |
|
---|
53 |
|
---|
54 | ros::spinOnce();
|
---|
55 |
|
---|
56 | // loop_rate.sleep();
|
---|
57 | // count += 1;
|
---|
58 | }
|
---|
59 |
|
---|
60 | return 0;
|
---|
61 | }
|
---|