def __init__(self, parent):
        """
        Perform preliminary init of all child classes, DB, etc.
        """

        # make sure GPSd is running. init the gpsd class, make sure were getting data
        # connect to the OBD interface, init it, get some sample data
        # init the database or flat file, wherever we put our data

        # assuming both of those worked, return true/ok/whatever

        # setup a filename for this data
        dt = datetime.now()
        s = dt.strftime("%Y-%m-%d_%H-%M-%S")
        self.DATA_FILE_NAME = "obdlog_" + s + ".csv"

        # set data path
        if self.DATA_FILE_PATH == "":
            self.DATA_FILE_PATH = os.path.expanduser("~")

        # intialize SunSPOT
        self.accelQueue = TuxTruck_Thread_Queue(3)
        self.accel = TuxTruck_OBDlog_SunSPOT_Reader(self, self.accelQueue,
                                                    self.SUNSPOT_PORT)

        # initialize the GPS
        self.gpsQueue = TuxTruck_Thread_Queue(3)
        self.gps = TuxTruck_OBDlog_GPS(self, self.gpsQueue)

        # initialize the OBD reader
        self.obdQueue = TuxTruck_Thread_Queue(3)
        self.obd = TuxTruck_OBDlog_OBDreader(self, self.obdQueue,
                                             self.ELMSCAN_PORT)

        # initialize the LCD
        self.lcdQueue = TuxTruck_Thread_Queue(3)
        if os.path.exists(self.LCD_PORT) and os.access(self.LCD_PORT, os.W_OK):
            self.lcd = TuxTruck_OBDlog_LCD(self, self.lcdQueue, self.LCD_PORT)
        else:
            print "LCD Port " + self.LCD_PORT + " does not exist or is not writable."
Example #2
0
    def __init__(self, parent):
        """
        Perform preliminary init of all child classes, DB, etc.
        """
        
        # make sure GPSd is running. init the gpsd class, make sure were getting data
        # connect to the OBD interface, init it, get some sample data
        # init the database or flat file, wherever we put our data

        # assuming both of those worked, return true/ok/whatever

        # setup a filename for this data
        dt = datetime.now()
        s = dt.strftime("%Y-%m-%d_%H-%M-%S")
        self.DATA_FILE_NAME = "obdlog_" + s + ".csv"

        # set data path
        if self.DATA_FILE_PATH == "":
            self.DATA_FILE_PATH = os.path.expanduser("~")

        # intialize SunSPOT
        self.accelQueue = TuxTruck_Thread_Queue(3)
        self.accel = TuxTruck_OBDlog_SunSPOT_Reader(self, self.accelQueue, self.SUNSPOT_PORT)

        # initialize the GPS
        self.gpsQueue = TuxTruck_Thread_Queue(3)
        self.gps = TuxTruck_OBDlog_GPS(self, self.gpsQueue)

        # initialize the OBD reader
        self.obdQueue = TuxTruck_Thread_Queue(3)
        self.obd = TuxTruck_OBDlog_OBDreader(self, self.obdQueue, self.ELMSCAN_PORT)

        # initialize the LCD
        self.lcdQueue = TuxTruck_Thread_Queue(3)
        if os.path.exists(self.LCD_PORT) and os.access(self.LCD_PORT, os.W_OK):
            self.lcd = TuxTruck_OBDlog_LCD(self, self.lcdQueue, self.LCD_PORT)
        else:
            print "LCD Port " + self.LCD_PORT + " does not exist or is not writable."
class TuxTruck_OBDlog_Main():
    """
    Master class that handles all OBD logging functions.

    """

    #
    # CONFIGURATION
    #
    ELMSCAN_PORT = "/dev/ttyS0"  # path to the serial port for the ElmScan
    #SUNSPOT_PORT = "/dev/ttyACM0" # path to the SunSPOT
    SUNSPOT_PORT = "/tmp/accelfifo"  # path to the SunSPOT # DEBUG
    LCD_PORT = "/dev/ttyUSB0"  # path to the LCD display
    DATA_INTERVAL = 0.5  # interval at which to collect data, in seconds (float)
    DATA_FILE_NAME = ""  # what to call the data file
    DATA_FILE_PATH = "/home/jantman/"  # where to put the data file

    # tell threads to die if killed...
    KILLED = False

    # Queues
    gpsQueue = None  # queue for the GPSd data
    obdQueue = None  # queue for the OBD data
    accelQueue = None  # queue for the accelerometer (SunSPOT) data
    lcdQueue = None  # queue going to LCD

    # data source objects
    gps = None  # the TuxTruck_OBDlog_gpsd object
    obd = None  # the TuxTruck_OBDlog_obd object
    accel = None  # the TuxTruck_OBDlog_accel object

    # output objects
    lcd = None  # the CrystalFontz LCD thread

    def __init__(self, parent):
        """
        Perform preliminary init of all child classes, DB, etc.
        """

        # make sure GPSd is running. init the gpsd class, make sure were getting data
        # connect to the OBD interface, init it, get some sample data
        # init the database or flat file, wherever we put our data

        # assuming both of those worked, return true/ok/whatever

        # setup a filename for this data
        dt = datetime.now()
        s = dt.strftime("%Y-%m-%d_%H-%M-%S")
        self.DATA_FILE_NAME = "obdlog_" + s + ".csv"

        # set data path
        if self.DATA_FILE_PATH == "":
            self.DATA_FILE_PATH = os.path.expanduser("~")

        # intialize SunSPOT
        self.accelQueue = TuxTruck_Thread_Queue(3)
        self.accel = TuxTruck_OBDlog_SunSPOT_Reader(self, self.accelQueue,
                                                    self.SUNSPOT_PORT)

        # initialize the GPS
        self.gpsQueue = TuxTruck_Thread_Queue(3)
        self.gps = TuxTruck_OBDlog_GPS(self, self.gpsQueue)

        # initialize the OBD reader
        self.obdQueue = TuxTruck_Thread_Queue(3)
        self.obd = TuxTruck_OBDlog_OBDreader(self, self.obdQueue,
                                             self.ELMSCAN_PORT)

        # initialize the LCD
        self.lcdQueue = TuxTruck_Thread_Queue(3)
        if os.path.exists(self.LCD_PORT) and os.access(self.LCD_PORT, os.W_OK):
            self.lcd = TuxTruck_OBDlog_LCD(self, self.lcdQueue, self.LCD_PORT)
        else:
            print "LCD Port " + self.LCD_PORT + " does not exist or is not writable."

    def run(self):
        """
        Once init is finished, start logging...
        """

        DATA_FILE = open(self.DATA_FILE_PATH + "/" + self.DATA_FILE_NAME, "w")

        self.accel.start()
        self.gps.start()
        self.obd.start()

        if self.lcd != None:
            self.lcd.start()

        # every self.DATA_INTERVAL seconds, write the data to the data sink
        while True:
            try:
                a = None
                g = None
                o = None
                while a == None or g == None or o == None:
                    if a == None:
                        a = self.accelQueue.pop()
                    if g == None:
                        g = self.gpsQueue.pop()
                    if o == None:
                        o = self.obdQueue.pop()
                DATA_FILE.write(a + "," + g + "," + o)
                print "Accel=" + a + "\nGPS=" + g + "\nOBD=" + o + "\n=========\n"  # DEBUG
                self.lcdQueue.append(a + "," + g + "," + o)
                time.sleep(self.DATA_INTERVAL)
            except KeyboardInterrupt:
                self.KILLED = True
Example #4
0
class TuxTruck_OBDlog_Main():
    """
    Master class that handles all OBD logging functions.

    """

    #
    # CONFIGURATION
    #
    ELMSCAN_PORT = "/dev/ttyS0" # path to the serial port for the ElmScan
    #SUNSPOT_PORT = "/dev/ttyACM0" # path to the SunSPOT
    SUNSPOT_PORT = "/tmp/accelfifo" # path to the SunSPOT # DEBUG
    LCD_PORT = "/dev/ttyUSB0" # path to the LCD display
    DATA_INTERVAL = 0.5 # interval at which to collect data, in seconds (float)
    DATA_FILE_NAME = "" # what to call the data file
    DATA_FILE_PATH = "/home/jantman/" # where to put the data file

    # tell threads to die if killed...
    KILLED = False

    # Queues
    gpsQueue = None # queue for the GPSd data
    obdQueue = None # queue for the OBD data
    accelQueue = None # queue for the accelerometer (SunSPOT) data
    lcdQueue = None # queue going to LCD

    # data source objects
    gps = None # the TuxTruck_OBDlog_gpsd object
    obd = None # the TuxTruck_OBDlog_obd object
    accel = None # the TuxTruck_OBDlog_accel object

    # output objects
    lcd = None # the CrystalFontz LCD thread

    def __init__(self, parent):
        """
        Perform preliminary init of all child classes, DB, etc.
        """
        
        # make sure GPSd is running. init the gpsd class, make sure were getting data
        # connect to the OBD interface, init it, get some sample data
        # init the database or flat file, wherever we put our data

        # assuming both of those worked, return true/ok/whatever

        # setup a filename for this data
        dt = datetime.now()
        s = dt.strftime("%Y-%m-%d_%H-%M-%S")
        self.DATA_FILE_NAME = "obdlog_" + s + ".csv"

        # set data path
        if self.DATA_FILE_PATH == "":
            self.DATA_FILE_PATH = os.path.expanduser("~")

        # intialize SunSPOT
        self.accelQueue = TuxTruck_Thread_Queue(3)
        self.accel = TuxTruck_OBDlog_SunSPOT_Reader(self, self.accelQueue, self.SUNSPOT_PORT)

        # initialize the GPS
        self.gpsQueue = TuxTruck_Thread_Queue(3)
        self.gps = TuxTruck_OBDlog_GPS(self, self.gpsQueue)

        # initialize the OBD reader
        self.obdQueue = TuxTruck_Thread_Queue(3)
        self.obd = TuxTruck_OBDlog_OBDreader(self, self.obdQueue, self.ELMSCAN_PORT)

        # initialize the LCD
        self.lcdQueue = TuxTruck_Thread_Queue(3)
        if os.path.exists(self.LCD_PORT) and os.access(self.LCD_PORT, os.W_OK):
            self.lcd = TuxTruck_OBDlog_LCD(self, self.lcdQueue, self.LCD_PORT)
        else:
            print "LCD Port " + self.LCD_PORT + " does not exist or is not writable."
        

    def run(self):
        """
        Once init is finished, start logging...
        """

        DATA_FILE = open(self.DATA_FILE_PATH + "/" + self.DATA_FILE_NAME, "w")

        self.accel.start()
        self.gps.start()
        self.obd.start()

        if self.lcd != None:
            self.lcd.start()

        # every self.DATA_INTERVAL seconds, write the data to the data sink
        while True:
            try:
                a = None
                g = None
                o = None
                while a == None or g == None or o == None:
                    if a == None:
                        a = self.accelQueue.pop()
                    if g == None:
                        g = self.gpsQueue.pop()
                    if o == None:
                        o = self.obdQueue.pop()
                DATA_FILE.write(a + "," + g + "," + o)
                print "Accel=" + a + "\nGPS=" + g + "\nOBD=" + o + "\n=========\n" # DEBUG
                self.lcdQueue.append(a + "," + g + "," + o)
                time.sleep(self.DATA_INTERVAL)
            except KeyboardInterrupt:
                self.KILLED = True