root / scout / usb_serial / src / usb_serial.cpp @ 4069a378
History | View | Annotate | Download (3.51 KB)
1 |
/**
|
---|---|
2 |
* Copyright (c) 2011 Colony Project
|
3 |
*
|
4 |
* Permission is hereby granted, free of charge, to any person
|
5 |
* obtaining a copy of this software and associated documentation
|
6 |
* files (the "Software"), to deal in the Software without
|
7 |
* restriction, including without limitation the rights to use,
|
8 |
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
* copies of the Software, and to permit persons to whom the
|
10 |
* Software is furnished to do so, subject to the following
|
11 |
* conditions:
|
12 |
*
|
13 |
* The above copyright notice and this permission notice shall be
|
14 |
* included in all copies or substantial portions of the Software.
|
15 |
*
|
16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
20 |
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
21 |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
22 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
23 |
* OTHER DEALINGS IN THE SOFTWARE.
|
24 |
*/
|
25 |
|
26 |
/**
|
27 |
* @file usb_serial.cpp
|
28 |
* @brief USB_Serial
|
29 |
*
|
30 |
* Implementation of functions for USB/Serial use.
|
31 |
*
|
32 |
* @author Colony Project, CMU Robotics Club
|
33 |
* @author Lalitha Ganesan
|
34 |
**/
|
35 |
|
36 |
#include <ros/ros.h> |
37 |
|
38 |
#include "usb_serial.h" |
39 |
|
40 |
/**
|
41 |
* @defgroup usb_serial USB_Serial
|
42 |
* @brief Functions for using the USB/Serial Ports
|
43 |
*
|
44 |
* @{
|
45 |
**/
|
46 |
|
47 |
/* USB/Serial state variables */
|
48 |
int data; /**< The USB serial data received. */ |
49 |
//int num_data_bits; /**< The number of bits that store data. */
|
50 |
//int num_stop_bits; /**< The number of bits that indicate the end of data. */
|
51 |
//int parity_type; /**< The parity type of the data being sent over. */
|
52 |
//int baud_rate; /**< The baud rate of the USB/Serial (bits/sec). */
|
53 |
|
54 |
/**
|
55 |
* @brief Sends USB/Serial data.
|
56 |
*
|
57 |
* Sets the state vars based on subscription to the serial_data_out topic.
|
58 |
*/
|
59 |
void send_serial_data(const usb_serial::serial_data::ConstPtr& msg) |
60 |
{ |
61 |
data = msg->data; |
62 |
//num_data_bits = msg->num_data_bits;
|
63 |
//num_stop_bits = msg->num_stop_bits;
|
64 |
//parity_type = msg->parity_type;
|
65 |
//baud_rate = msg->baud_rate;
|
66 |
|
67 |
// Write the data to hardware here
|
68 |
} |
69 |
|
70 |
/**
|
71 |
* @brief USB_Serial driver. This is a ROS node that controls USB/Serial
|
72 |
* port data.
|
73 |
*
|
74 |
* This is the main function for the usb_serial node. It is run when the node
|
75 |
* starts and initializes USB/Serial ports. It then subscribes to the
|
76 |
* serial_data_out topic, and publishes to the serial_data_in message.
|
77 |
*/
|
78 |
int main(int argc, char **argv) |
79 |
{ |
80 |
/* Initialize in ROS the usb_serial driver node */
|
81 |
ros::init(argc, argv, "usb_serial_driver");
|
82 |
|
83 |
ros::NodeHandle n; |
84 |
|
85 |
/* Subscribe to the topic of outgoing serial data (which will be written
|
86 |
* to the hardware) and if we receive any, send it via serial_data_out. */
|
87 |
ros::Subscriber sub = n.subscribe("serial_data_out",
|
88 |
QUEUE_SIZE, send_serial_data); |
89 |
|
90 |
/* Publish ingoing serial data messages back to the library. As part of
|
91 |
* its main() function, this node reads hardware data and if a new
|
92 |
* serial message is found, this publisher sends it inbound over ROS */
|
93 |
ros::Publisher pub = n.advertise<usb_serial::serial_data>("serial_data_in", QUEUE_SIZE);
|
94 |
|
95 |
// Initialize hardware for USB/Serial ports
|
96 |
|
97 |
ROS_INFO("Ready to set USB/Serial. [Unimplemented]");
|
98 |
|
99 |
// Get and publish serial data here.
|
100 |
|
101 |
ros::spin(); |
102 |
|
103 |
return 0; |
104 |
} |
105 |
|
106 |
/** @} */
|
107 |
|