#!/usr/bin/python

###############################################################################
# Script to record list of waypoints using data from GPS receiver attached
#   to USB port. Currently does not work on Windows.
#
# Based on handler.py from 
#   https://github.com/mw46d/Entdecker/tree/master/Laptop/GPS
#
# Command line arguments: output file path (defaults to /tmp/waypoints.txt)
# 
# Make sure WAYPOINT_RADIUS is set to what you want (~ line 177)
#
# Basic character command inputs:
#   "c[gpst] - Cone: Grass/Pavement/Grass-Stop/Pavement-Stop, l - land, w - waypoint, q - quit"
#
# Output: text file waypoint list readable by Mission Planner
#
###############################################################################

import csv
import math
import serial
import signal
import string
import subprocess
import sys
import termios
import threading
import time
import tty

class Getch:
    def __call__(self):
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch

class CSVDialect(csv.Dialect):
    delimiter = '\t'
    doublequote = False
    skipinitialspace = True
    lineterminator = '\r\n'