Note: Goby version 1 (shown here) is now considered obsolete. Please use version 2 for new projects, and consider upgrading old projects.

Goby Underwater Autonomy Project  Series: 1.1, revision: 163, released on 2013-02-06 14:23:27 -0500
util/liblinebasedcomms/serial_client.h
00001 // copyright 2009, 2010 t. schneider tes@mit.edu
00002 // 
00003 // this file is part of comms, a library for handling various communications.
00004 //
00005 // This program is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // This software is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this software.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 // credit for much of this goes to Jeff Gray-3 (http://www.nabble.com/Simple-serial-port-demonstration-with-boost-asio-asynchronous-I-O-p19849520.html)
00019 
00020 #ifndef SerialClient20091211H
00021 #define SerialClient20091211H
00022 
00023 #include "client_base.h"
00024 
00025 namespace goby
00026 {
00027     namespace util
00028     {
00030         class SerialClient: public LineBasedClient<boost::asio::serial_port>
00031         {
00032           public:
00038             SerialClient(const std::string& name = "",
00039                          unsigned baud = 9600,
00040                          const std::string& delimiter = "\r\n");
00041             
00043             void set_name(const std::string& name) { name_ = name; }
00045             void set_baud(unsigned baud) { baud_ = baud; }
00046 
00048             std::string name() const { return name_; }
00049 
00051             unsigned baud() const { return baud_; }            
00052 
00053             boost::asio::serial_port& socket() { return serial_port_; }
00055             std::string local_endpoint() { return name_; }
00057             std::string remote_endpoint() { return ""; }
00058 
00059           private:
00060             bool start_specific();        
00061   
00062           private:
00063             static std::map<std::string, SerialClient*> inst_;
00064             boost::asio::serial_port serial_port_; // the serial port this instance is connected to
00065             std::string name_;
00066             unsigned baud_;
00067         
00068         }; 
00069     }
00070 }
00071 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends