Esempio n. 1
0
    def load_conf(self, filename):
        config = ConfigParser.SafeConfigParser()
        try:
            config.read(filename)
            sections = config.sections()
            if len(sections):
                device = DeviceGPS()
                device.name = sections[0]
                device.type = config.getint(sections[0], 'type')
                device.resource = config.get(sections[0], 'resource')
                if device.type == DeviceGPS.NMEA_SERIAL:
                    if config.has_option(sections[0], 'baud'):
                        device.baud = config.getint(sections[0], 'baud')
                    if config.has_option(sections[0], 'bits'):
                        device.bytes = config.getint(sections[0], 'bits')
                    if config.has_option(sections[0], 'parity'):
                        device.parity = config.get(sections[0], 'parity')
                    if config.has_option(sections[0], 'stops'):
                        device.stops = config.getint(sections[0], 'stops')
                    if config.has_option(sections[0], 'soft'):
                        device.soft = config.getboolean(sections[0], 'soft')

                self.devicesGps.append(device)
                return self.__check_conf_serial(device)

        except ConfigParser.Error as e:
            return e.message
        except ValueError as e:
            return e.message
Esempio n. 2
0
    def load_conf(self, filename):
        config = ConfigParser.SafeConfigParser()
        try:
            config.read(filename)

            if config.has_section('gps'):
                device = DeviceGPS()
                device.type = DeviceGPS.NMEA_SERIAL

                if config.has_option('gps', 'port'):
                    device.resource = config.get('gps', 'port')
                else:
                    return '"Port" not found in config'

                if config.has_option('gps', 'baud'):
                    baud = config.getint('gps', 'baud')
                    if baud in device.get_bauds():
                        device.baud = baud
                    else:
                        return 'Baud "{}" should be one of:\n  {}'.format(baud,
                                                                          device.get_bauds())

                if config.has_option('gps', 'bits'):
                    bits = config.getint('gps', 'bits')
                    if bits in DeviceGPS.BYTES:
                        device.bytes = bits
                    else:
                        return 'Bits "{}" should be one of:\n  {}'.format(bits,
                                                                          DeviceGPS.BYTES)

                if config.has_option('gps', 'parity'):
                    parity = config.get('gps', 'parity')
                    if parity in DeviceGPS.PARITIES:
                        device.parity = parity
                    else:
                        return 'Parity "{}" should be one of:\n  {}'.format(parity,
                                                                            DeviceGPS.PARITIES)

                if config.has_option('gps', 'stops'):
                    stops = config.getfloat('gps', 'stops')
                    if stops in DeviceGPS.STOPS:
                        device.stops = stops
                    else:
                        return 'Stops "{}" should be one of:\n  {}'.format(stops,
                                                                           DeviceGPS.STOPS)

                if config.has_option('gps', 'soft'):
                    device.soft = config.getboolean('gps', 'soft')

                self.devicesGps.append(device)

        except ConfigParser.Error as e:
            return e
        except ValueError as e:
            return e

        return None
Esempio n. 3
0
    def load_conf(self, filename):
        config = ConfigParser.SafeConfigParser()
        try:
            config.read(filename)

            if config.has_section('gps'):
                device = DeviceGPS()
                device.type = DeviceGPS.NMEA_SERIAL

                if config.has_option('gps', 'port'):
                    device.resource = config.get('gps', 'port')
                else:
                    return '"Port" not found in config'

                if config.has_option('gps', 'baud'):
                    baud = config.getint('gps', 'baud')
                    if baud in device.get_bauds():
                        device.baud = baud
                    else:
                        return 'Baud "{}" should be one of:\n  {}'.format(baud,
                                                                          device.get_bauds())

                if config.has_option('gps', 'bits'):
                    bits = config.getint('gps', 'bits')
                    if bits in DeviceGPS.BYTES:
                        device.bytes = bits
                    else:
                        return 'Bits "{}" should be one of:\n  {}'.format(bits,
                                                                          DeviceGPS.BYTES)

                if config.has_option('gps', 'parity'):
                    parity = config.get('gps', 'parity')
                    if parity in DeviceGPS.PARITIES:
                        device.parity = parity
                    else:
                        return 'Parity "{}" should be one of:\n  {}'.format(parity,
                                                                            DeviceGPS.PARITIES)

                if config.has_option('gps', 'stops'):
                    stops = config.getfloat('gps', 'stops')
                    if stops in DeviceGPS.STOPS:
                        device.stops = stops
                    else:
                        return 'Stops "{}" should be one of:\n  {}'.format(stops,
                                                                           DeviceGPS.STOPS)

                if config.has_option('gps', 'soft'):
                    device.soft = config.getboolean('gps', 'soft')

                self.devicesGps.append(device)

        except ConfigParser.Error as e:
            return e
        except ValueError as e:
            return e

        return None
Esempio n. 4
0
 def __load_devices_gps(self):
     self.devicesGps = []
     self.cfg.SetPath("/DevicesGPS")
     group = self.cfg.GetFirstGroup()
     while group[0]:
         self.cfg.SetPath("/DevicesGPS/" + group[1])
         device = DeviceGPS()
         device.name = group[1]
         device.type = self.cfg.ReadInt("type", device.type)
         device.resource = self.cfg.Read("resource", device.resource)
         device.baud = self.cfg.ReadInt("baud", device.baud)
         device.bytes = self.cfg.ReadInt("bytes", device.bytes)
         device.parity = self.cfg.Read("parity", device.parity)
         device.stops = self.cfg.ReadInt("stops", device.stops)
         device.soft = self.cfg.ReadBool("soft", device.soft)
         self.devicesGps.append(device)
         self.cfg.SetPath("/DevicesGPS")
         group = self.cfg.GetNextGroup(group[2])
Esempio n. 5
0
 def __load_devices_gps(self):
     self.devicesGps = []
     self.cfg.SetPath("/DevicesGPS")
     group = self.cfg.GetFirstGroup()
     while group[0]:
         self.cfg.SetPath("/DevicesGPS/" + group[1])
         device = DeviceGPS()
         device.name = group[1]
         device.type = self.cfg.ReadInt('type', device.type)
         device.resource = self.cfg.Read('resource', device.resource)
         device.baud = self.cfg.ReadInt('baud', device.baud)
         device.bytes = self.cfg.ReadInt('bytes', device.bytes)
         device.parity = self.cfg.Read('parity', device.parity)
         device.stops = self.cfg.ReadInt('stops', device.stops)
         device.soft = self.cfg.ReadBool('soft', device.soft)
         self.devicesGps.append(device)
         self.cfg.SetPath("/DevicesGPS")
         group = self.cfg.GetNextGroup(group[2])