Goby Underwater Autonomy Project
Series: 1.1, revision: 163, released on 2013-02-06 14:23:27 -0500
|
00001 // copyright 2010 t. schneider tes@mit.edu 00002 // 00003 // This program is free software: you can redistribute it and/or modify 00004 // it under the terms of the GNU General Public License as published by 00005 // the Free Software Foundation, either version 3 of the License, or 00006 // (at your option) any later version. 00007 // 00008 // This software is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 // GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with this software. If not, see <http://www.gnu.org/licenses/>. 00015 00016 #include <iostream> 00017 00018 #include "goby/util/linebasedcomms.h" 00019 #include "goby/util/string.h" 00020 00021 using goby::util::as; 00022 00023 int main(int argc, char* argv[]) 00024 { 00025 std::string server_port; 00026 std::string serial_port; 00027 std::string serial_baud; 00028 00029 if(argc != 4) 00030 { 00031 std::cout << "usage: serial2tcp_server server_port serial_port serial_baud" << std::endl; 00032 return 1; 00033 } 00034 00035 server_port = argv[1]; 00036 serial_port = argv[2]; 00037 serial_baud = argv[3]; 00038 00039 goby::util::TCPServer tcp_server(as<unsigned>(server_port)); 00040 goby::util::SerialClient serial_client(serial_port, as<unsigned>(serial_baud)); 00041 00042 tcp_server.start(); 00043 serial_client.start(); 00044 00045 for(;;) 00046 { 00047 std::string s; 00048 while(serial_client.readline(&s)) 00049 { 00050 std::cout << "serial->tcp: " << s << std::flush; 00051 tcp_server.write(s); 00052 } 00053 while(tcp_server.readline(&s)) 00054 { 00055 std::cout << "tcp->serial: " << s << std::flush; 00056 serial_client.write(s); 00057 } 00058 00059 usleep(1000); 00060 } 00061 } 00062