navsat_rtk_relay.py
Go to the documentation of this file.
00001 # Software License Agreement (BSD) 
00002 #
00003 # @author    Mike Purvis <mpurvis@clearpathrobotics.com>
00004 # @copyright (c) 2015, Clearpath Robotics, Inc., All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without modification, are permitted provided that
00007 # the following conditions are met:
00008 # * Redistributions of source code must retain the above copyright notice, this list of conditions and the
00009 #   following disclaimer.
00010 # * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
00011 #   following disclaimer in the documentation and/or other materials provided with the distribution.
00012 # * Neither the name of Clearpath Robotics nor the names of its contributors may be used to endorse or
00013 #   promote products derived from this software without specific prior written permission.
00014 #
00015 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
00016 # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00017 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
00018 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00019 # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00020 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00021 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00022 # POSSIBILITY OF SUCH DAMAGE.
00023 
00024 import argparse
00025 import multicast
00026 import serial
00027 import sys
00028 import time
00029 
00030 
00031 def get_option_parser():
00032     parser = argparse.ArgumentParser()
00033     parser.add_argument("--group",
00034                         help="multicast IP", metavar="IP", default="224.1.1.1")
00035     parser.add_argument("--port", type=int,
00036                         help="multicast port", metavar="PORT", default=20001)
00037     parser.add_argument("--device",
00038                         help="multicast device", metavar="ETH", default="eth0")
00039     parser.add_argument("--serial-port",
00040                         help="serial port", metavar="SER", default=None)
00041     parser.add_argument("--baud", type=int,
00042                         help="serial baud rate", metavar="RATE", default=57600)
00043     parser.add_argument("--verbose", action="store_true",
00044                         help="echo received messages to stdout")
00045     return parser
00046 
00047 
00048 def main():
00049     args, _ = get_option_parser().parse_known_args()
00050 
00051     # This loop is necessary for when the script starts with ROS on the local-filesystems
00052     # event, it can run before the network devices are established.
00053     while True:
00054         try:
00055             receiver = multicast.MulticastUDPReceiver(args.device, args.group, args.port)
00056             print "Created multicast receiver on %s:%s, device %s." % (args.group, args.port, args.device)
00057             break
00058         except multicast.Receiver.InterfaceNotFound:
00059             print "Unable to find network interface %s, retrying." % args.device
00060             time.sleep(1.0)
00061 
00062     ser = None
00063     if args.serial_port:
00064         print "Will transmit to %s at %d baud." % (args.serial_port, args.baud)
00065     else:
00066         print "No serial port set, listening only."
00067 
00068     try:
00069         while True:
00070             s = receiver.read(10240)
00071             if args.serial_port and not ser:
00072                 try:
00073                     ser = serial.Serial(port=args.serial_port, baudrate=args.baud, timeout=0)
00074                     print "Opened serial port."
00075                 except Exception as e:
00076                     ser = None
00077                     print "Error opening serial port: %s" % str(e)
00078             if ser:
00079                 ser.write(s)
00080                 ser.flush()
00081             if args.verbose:
00082                 sys.stdout.write(str(s).encode("string_escape"))
00083                 sys.stdout.flush()
00084 
00085     except:
00086         if ser:
00087             ser.close()
00088             print "Closed serial port."
00089         raise


jackal_bringup
Author(s):
autogenerated on Thu Jul 4 2019 19:49:01