Beispiel #1
0
 def request_port(msg, _used_ports=[], default=None):
     while True:
         default_port = default or next(iter(_used_ports), 8499) + 1
         port = input(msg % default_port)
         if not port:
             port = default_port
         try:
             port = check_port(port, _used_ports)
             _used_ports.insert(0, port)
             return port
         except ValueError as e:
             print(e)
Beispiel #2
0
def fake_generic_sensor(args):
    try:
        port = check_port(args.port)
    except ValueError as e:
        sys.exit(e)

    data_file = io.StringIO(newline='\r\n')
    uids = (uuid.uuid4().hex + "\r\n" for x in range(10))
    data_file.writelines(uids)
    data_file.seek(0)

    run_dummy_sensor("generic", port, data_file)
Beispiel #3
0
def fake_aanderaa_cmd(args):
    try:
        port = check_port(args.port)
    except ValueError as e:
        sys.exit(e)

    if args.data_file:
        try:
            data_file = check_file(args.data_file)
            data_file = data_file.open()
        except ValidationError as e:
            sys.exit(e)
    else:
        fixtures = 'test_tools/fixtures/aanderaa_fake_data.txt'
        data_file = text_resource_stream(fixtures,
                                         "nmea_converter_proxy",
                                         newline='\r\n')

    run_dummy_sensor("aanderaa", port, data_file)
Beispiel #4
0
def fake_concentrator_cmd(args):
    try:
        port = check_port(args.port)
    except ValueError as e:
        sys.exit(e)
    run_dummy_concentrator(port)
Beispiel #5
0
def load_config(config_file):

    optiplex_port = None
    aanderaa_port = None
    concentrator_port = None
    concentrator_ip = None
    magnetic_declination = None
    optiplex_ip = None
    aanderaa_ip = None

    if not config_file.is_file():
        raise ConfigurationError('You must provide a configuration file')

    log.debug('Loading config file "%s"' % config_file)

    try:
        cfg = configparser.ConfigParser()
        cfg.read(str(config_file))

        try:
            log.debug('Getting concentrator IP')
            concentrator_ip = check_ipv4(cfg.get('concentrator', 'ip'))
            log.debug('Getting concentrator port')
            concentrator_port = check_port(cfg.get('concentrator', 'port'))
        except (configparser.NoSectionError, configparser.NoOptionError) as e:
            raise ConfigurationError('The configuration file is incomplete: %s' % e)

        try:
            log.debug('Getting optiplex port')
            optiplex_port = check_port(cfg.get('optiplex', 'port'))
            log.debug('Getting optiplex IP')
            optiplex_ip = check_ipv4(cfg.get('optiplex', 'ip'))
        except configparser.NoOptionError as e:
            raise ConfigurationError('The configuration file is incomplete: %s' % e)
        except configparser.NoSectionError:
            optiplex_port = None

        try:
            log.debug('Getting aanderaa port')
            aanderaa_port = check_port(cfg.get('aanderaa', 'port'))
            log.debug('Getting magnetic declination')
            magnetic_declination = float(cfg.get('aanderaa', 'magnetic_declination'))
            msg = "Declination must be a number between -50 and 50"
            assert -50 <= magnetic_declination <= 50, msg
            log.debug('Getting aanderaa IP')
            aanderaa_ip = check_ipv4(cfg.get('aanderaa', 'ip'))
        except configparser.NoOptionError as e:
            raise ConfigurationError('The configuration file is incomplete: %s' % e)
        except configparser.NoSectionError:
            aanderaa_port = None
            magnetic_declination = None

    except (ValueError, AssertionError, EnvironmentError, configparser.ParsingError, configparser.DuplicateSectionError) as e:
        raise ConfigurationError('Error while loading config file "%s": %s' % (config_file, e))

    additional_sensors = {}
    for section in cfg.sections():
        if section not in ('concentrator', 'optiplex', 'aanderaa'):
            if section.startswith('sensor:'):
                name = section.replace('sensor:', '')

                try:
                    log.debug('Getting %s port' % name)
                    port = check_port(cfg.get(section, 'port'))
                    log.debug('Getting %s IP' % name)
                    ip = check_ipv4(cfg.get(section, 'ip'))
                except configparser.NoOptionError as e:
                    raise ConfigurationError('The configuration file is incomplete: %s' % e)

                additional_sensors[name] = {'port': port, 'ip': ip}

    return {
       "optiplex_port": optiplex_port,
       "aanderaa_port": aanderaa_port,
       "concentrator_port": concentrator_port,
       "concentrator_ip": concentrator_ip,
       "magnetic_declination": magnetic_declination,
       "optiplex_ip": optiplex_ip,
       "aanderaa_ip": aanderaa_ip,
       "additional_sensors": additional_sensors
    }
Beispiel #6
0
def load_config(config_file):

    optiplex_port = None
    aanderaa_port = None
    concentrator_port = None
    concentrator_ip = None
    magnetic_declination = None
    optiplex_ip = None
    aanderaa_ip = None

    if not config_file.is_file():
        raise ConfigurationError('You must provide a configuration file')

    log.debug('Loading config file "%s"' % config_file)

    try:
        cfg = configparser.ConfigParser()
        cfg.read(str(config_file))

        try:
            log.debug('Getting concentrator IP')
            concentrator_ip = check_ipv4(cfg.get('concentrator', 'ip'))
            log.debug('Getting concentrator port')
            concentrator_port = check_port(cfg.get('concentrator', 'port'))
        except (configparser.NoSectionError, configparser.NoOptionError) as e:
            raise ConfigurationError(
                'The configuration file is incomplete: %s' % e)

        try:
            log.debug('Getting optiplex port')
            optiplex_port = check_port(cfg.get('optiplex', 'port'))
            log.debug('Getting optiplex IP')
            optiplex_ip = check_ipv4(cfg.get('optiplex', 'ip'))
        except configparser.NoOptionError as e:
            raise ConfigurationError(
                'The configuration file is incomplete: %s' % e)
        except configparser.NoSectionError:
            optiplex_port = None

        try:
            log.debug('Getting aanderaa port')
            aanderaa_port = check_port(cfg.get('aanderaa', 'port'))
            log.debug('Getting magnetic declination')
            magnetic_declination = float(
                cfg.get('aanderaa', 'magnetic_declination'))
            msg = "Declination must be a number between -50 and 50"
            assert -50 <= magnetic_declination <= 50, msg
            log.debug('Getting aanderaa IP')
            aanderaa_ip = check_ipv4(cfg.get('aanderaa', 'ip'))
        except configparser.NoOptionError as e:
            raise ConfigurationError(
                'The configuration file is incomplete: %s' % e)
        except configparser.NoSectionError:
            aanderaa_port = None
            magnetic_declination = None

    except (ValueError, AssertionError, EnvironmentError,
            configparser.ParsingError,
            configparser.DuplicateSectionError) as e:
        raise ConfigurationError('Error while loading config file "%s": %s' %
                                 (config_file, e))

    additional_sensors = {}
    for section in cfg.sections():
        if section not in ('concentrator', 'optiplex', 'aanderaa'):
            if section.startswith('sensor:'):
                name = section.replace('sensor:', '')

                try:
                    log.debug('Getting %s port' % name)
                    port = check_port(cfg.get(section, 'port'))
                    log.debug('Getting %s IP' % name)
                    ip = check_ipv4(cfg.get(section, 'ip'))
                except configparser.NoOptionError as e:
                    raise ConfigurationError(
                        'The configuration file is incomplete: %s' % e)

                additional_sensors[name] = {'port': port, 'ip': ip}

    return {
        "optiplex_port": optiplex_port,
        "aanderaa_port": aanderaa_port,
        "concentrator_port": concentrator_port,
        "concentrator_ip": concentrator_ip,
        "magnetic_declination": magnetic_declination,
        "optiplex_ip": optiplex_ip,
        "aanderaa_ip": aanderaa_ip,
        "additional_sensors": additional_sensors
    }