Beispiel #1
0
class Sensors(object):
    def __init__(self, server):
        from gpsd import gpsd
        from rudder import Rudder
        from nmea import Nmea

        self.server = server
        self.nmea = Nmea(server, self)
        self.gps = gpsd(server, self)
        self.wind = Wind(server)
        self.rudder = Rudder(server)
        self.apb = APB(server)

        self.sensors = {
            'gps': self.gps,
            'wind': self.wind,
            'rudder': self.rudder,
            'apb': self.apb
        }

    def poll(self):
        self.gps.poll()
        self.nmea.poll()
        self.rudder.poll()

        # timeout sources
        t = time.time()
        for name in self.sensors:
            sensor = self.sensors[name]
            if sensor.source.value == 'none':
                continue
            if t - sensor.lastupdate > 8:
                self.lostsensor(sensor)

    def lostsensor(self, sensor):
        print('sensor', sensor.name, 'lost', sensor.source.value,
              sensor.device)
        sensor.source.set('none')
        sensor.reset()
        sensor.device = None

    def write(self, sensor, data, source):
        if not sensor in self.sensors:
            print('unknown data parsed!', sensor)
            return
        self.sensors[sensor].write(data, source)

    def lostdevice(self, device):
        # optional routine  useful when a device is
        # unplugged to skip the normal data timeout
        for name in self.sensors:
            sensor = self.sensors[name]
            if sensor.device and sensor.device[2:] == device:
                self.lostsensor(sensor)
Beispiel #2
0
class Sensors(object):
    def __init__(self, server):
        from gpsd import Gpsd
        from rudder import Rudder
        from nmea import Nmea

        self.server = server
        self.nmea = Nmea(server, self)
        self.gps = Gpsd(server, self)
        self.wind = Wind(server)
        self.rudder = Rudder(server)

        self.sensors = {
            'gps': self.gps,
            'wind': self.wind,
            'rudder': self.rudder
        }

    def poll(self):
        self.gps.poll()
        self.nmea.poll()
        self.rudder.poll()

        # timeout sources
        t = time.time()
        for name in self.sensors:
            sensor = self.sensors[name]
            if sensor.source.value == 'none':
                continue
            if t - sensor.lastupdate > 8:
                print 'sensor timeout for', name, 'source', sensor.source.value, t - sensor.lastupdate
                sensor.source.set('none')
                sensor.device = None

    def write(self, sensor, data, source):
        if not sensor in self.sensors:
            print 'unknown data parsed!', sensor
            return

        self.sensors[sensor].write(data, source)
Beispiel #3
0
class Sensors(object):
    def __init__(self, client):
        from rudder import Rudder
        from nmea import Nmea
        from signalk import signalk

        self.client = client

        # services that can receive sensor data
        self.nmea = Nmea(self)
        self.signalk = signalk(self)
        self.gpsd = gpsd(self)

        # actual sensors supported
        self.gps = gps(client)
        self.wind = Wind(client)
        self.rudder = Rudder(client)
        self.apb = APB(client)

        self.sensors = {
            'gps': self.gps,
            'wind': self.wind,
            'rudder': self.rudder,
            'apb': self.apb
        }

    def poll(self):
        self.nmea.poll()
        self.signalk.poll()
        self.gpsd.poll()
        self.rudder.poll()

        # timeout sources
        t = time.monotonic()
        for name in self.sensors:
            sensor = self.sensors[name]
            if sensor.source.value == 'none':
                continue
            if t - sensor.lastupdate > 8:
                self.lostsensor(sensor)

    def lostsensor(self, sensor):
        print('sensor', sensor.name, 'lost', sensor.source.value,
              sensor.device)
        sensor.source.set('none')
        sensor.reset()
        sensor.device = None

    def lostgpsd(self):
        if self.gps.source.value == 'gpsd':
            self.lostsensor(self.gps)

    def write(self, sensor, data, source):
        if not sensor in self.sensors:
            print('unknown data parsed!', sensor)
            return
        self.sensors[sensor].write(data, source)

    def lostdevice(self, device):
        # optional routine  useful when a device is
        # unplugged to skip the normal data timeout
        for name in self.sensors:
            sensor = self.sensors[name]
            if sensor.device and sensor.device[2:] == device:
                self.lostsensor(sensor)