示例#1
0
sys.path.remove('cars')


Threads = []

if 'watchdog' in config and config['watchdog'].get('enable') == True:
    import watchdog
    Watchdog = watchdog.Watchdog(config['watchdog'])
else:
    Watchdog = None

# Init dongle
dongle = DONGLE(config['dongle'], watchdog = Watchdog)

# Init GPS interface
gps = GpsPoller()
Threads.append(gps)

# Init car
car = CAR(config['car'], dongle, gps)
Threads.append(car)

# Init EVNotify
EVNotify = evnotify.EVNotify(config['evnotify'], car)
Threads.append(EVNotify)

# Init WiFi control
if 'wifi' in config and config['wifi'].get('enable') == True:
    from wifi_ctrl import WiFiCtrl
    wifi = WiFiCtrl()
else:
示例#2
0
    def follow_stream(self,
                      SPS=40000,
                      dispFFT=False,
                      axis=[0, 15000, -1e12, 1e12],
                      FFTchannels=[1, 2, 3],
                      selected_freq=None,
                      raw_file=""):
        if raw_file != "":
            # Disable displaying anything if we're writing to a file
            dispFFT = False
            self._ofile = open(raw_file, "w")
            self._gpsp = GpsPoller()
            self._gpsp.start()

        if dispFFT:
            import matplotlib
            matplotlib.use('GTKCairo')
            import matplotlib.pyplot as plt
            plt.ion()
            plt.show()
        quit = False
        samples_count = 4096
        bytes_in_block = samples_count * 16  #4 channels, 4B per sample

        fftfreq = np.fft.rfftfreq(
            samples_count,
            d=1.0 / SPS)  # /16 -> /4 channels /4 bytes per channel
        if selected_freq:
            selected_index = np.argmin(np.abs(fftfreq - selected_freq))

        self._tail = struct.unpack_from("l", self._data,
                                        self.PRU0_OFFSET_DRAM_HEAD)[0]

        while (not quit):
            samples = self.get_sample_block(bytes_in_block)
            #Invert dimensions
            channels = np.transpose(samples)
            if raw_file != "":
                np.save(
                    self._ofile, {
                        "time": time.time(),
                        "lat": self._gpsp.gpsd.fix.latitude,
                        "lon": self._gpsp.gpsd.fix.longitude,
                        "chans": channels
                    })
                continue
            if axis != None and dispFFT and self._spare:
                plt.axis(axis)
            ostring = ""
            for chan in FFTchannels:
                fft = np.fft.rfft(channels[chan]) / samples_count

                #Disregard the DC component.
                fft[0] = 0

                if selected_freq == None:
                    selected_index = np.argmax(np.absolute(fft))
                ostring += "Channel " + str(chan) + ": %-*sHz = %-*s\t" % (
                    5, int(fftfreq[selected_index]), 12,
                    int(np.absolute(fft[selected_index])))
                if dispFFT and self._spare:
                    plt.plot(fftfreq,
                             np.absolute(fft),
                             label="Channel %d" % chan)
                    #plt.plot(channels[chan], label="Channel %d"%chan)
                #print fftfreq[np.argmax(np.absolute(fft))]
            print ostring
            if dispFFT and self._spare:
                plt.legend()
                plt.draw()
                plt.pause(0.001)
                plt.cla()