Exemple #1
0
    def setUp(self):
        """Get config, set simulation pins to known state, set test flag."""
        # Load config and logger
        self.config = lib.get_config("bot/config.yaml")
        self.logger = lib.get_logger()

        # Set testing flag in config
        self.orig_test_state = self.config["testing"]
        lib.set_testing(True)
Exemple #2
0
    def setUp(self):
        """Get config, set simulation pins to known state, set test flag."""
        # Load config and logger
        self.config = lib.get_config("bot/config.yaml")
        self.logger = lib.get_logger()

        # Set testing flag in config
        self.orig_test_state = self.config["testing"]
        lib.set_testing(True)
Exemple #3
0
    def setUp(self):
        """Get config, set simulation pins to known state, set test flag."""
        # Load config and logger
        self.config = lib.get_config("bot/config.yaml")
        self.logger = lib.get_logger()

        # Set testing flag in config
        self.orig_test_state = self.config["testing"]
        lib.set_testing(True)

        # Write known values to all simulated hardware files
        self.setup_turret_servos()
        self.setup_laser()
        self.setup_gun_trigger()
        self.setup_ir_select_gpios()
        self.setup_ir_analog_input_gpios()
Exemple #4
0
    def __init__(self, testing=None, config_file="bot/config.yaml"):
        """Build ZMQ REP socket and instantiate bot systems.

        :param testing: True if running on simulated HW, False if on bot.
        :type testing: boolean
        :param config_file: Name of file to read configuration from.
        :type config_file: string

        """
        # Register signal handler, shut down cleanly (think motors)
        signal.signal(signal.SIGINT, self.signal_handler)

        # Load configuration and logger
        self.config = lib.get_config(config_file)
        self.logger = lib.get_logger()

        # Testing flag will cause objects to run on simulated hardware
        if testing is True or testing == "True":
            self.logger.info("CtrlServer running in test mode")
            lib.set_testing(True)
        elif testing is None:
            self.logger.info(
                "Defaulting to config testing flag: {}".format(
                    self.config["testing"]))
            lib.set_testing(self.config["testing"])
        else:
            self.logger.info("CtrlServer running in non-test mode")
            lib.set_testing(False)

        # Build socket to listen for requests
        self.context = zmq.Context()
        self.ctrl_sock = self.context.socket(zmq.REP)
        self.server_bind_addr = "{protocol}://{host}:{port}".format(
            protocol=self.config["server_protocol"],
            host=self.config["server_bind_host"],
            port=self.config["ctrl_server_port"])
        try:
            self.ctrl_sock.bind(self.server_bind_addr)
        except zmq.ZMQError:
            self.logger.error("ZMQ error. Is a server already running?")
            self.logger.warning("May be connected to an old server instance.")
            sys.exit(1)

        self.systems = self.assign_subsystems()
        self.logger.info("Control server initialized")

        # Don't spawn pub_server until told to
        self.pub_server = None
Exemple #5
0
    def __init__(self, testing=None, config_file="bot/config.yaml"):
        """Build ZMQ REP socket and instantiate bot systems.

        :param testing: True if running on simulated HW, False if on bot.
        :type testing: boolean
        :param config_file: Name of file to read configuration from.
        :type config_file: string

        """
        # Register signal handler, shut down cleanly (think motors)
        signal.signal(signal.SIGINT, self.signal_handler)

        # Load configuration and logger
        self.config = lib.get_config(config_file)
        self.logger = lib.get_logger()

        # Testing flag will cause objects to run on simulated hardware
        if testing is True or testing == "True":
            self.logger.info("CtrlServer running in test mode")
            lib.set_testing(True)
        elif testing is None:
            self.logger.info("Defaulting to config testing flag: {}".format(
                self.config["testing"]))
            lib.set_testing(self.config["testing"])
        else:
            self.logger.info("CtrlServer running in non-test mode")
            lib.set_testing(False)

        # Build socket to listen for requests
        self.context = zmq.Context()
        self.ctrl_sock = self.context.socket(zmq.REP)
        self.server_bind_addr = "{protocol}://{host}:{port}".format(
            protocol=self.config["server_protocol"],
            host=self.config["server_bind_host"],
            port=self.config["ctrl_server_port"])
        try:
            self.ctrl_sock.bind(self.server_bind_addr)
        except zmq.ZMQError:
            self.logger.error("ZMQ error. Is a server already running?")
            self.logger.warning("May be connected to an old server instance.")
            sys.exit(1)

        self.systems = self.assign_subsystems()
        self.logger.info("Control server initialized")

        # Don't spawn pub_server until told to
        self.pub_server = None
Exemple #6
0
 def tearDown(self):
     """Restore testing flag state in config file."""
     lib.set_testing(self.orig_test_state)
Exemple #7
0
 def test_invalid_config(self):
     """Test passing an invalid path to the config file."""
     with self.assertRaises(IOError):
         lib.set_testing(False, config_file="fake.yaml")
Exemple #8
0
 def test_invalid_state(self):
     """Test passing a non-boolean value for state param."""
     with self.assertRaises(TypeError):
         lib.set_testing("not_bool")
     new_config = lib.get_config()
     assert self.orig_config == new_config
Exemple #9
0
 def test_same(self):
     """Test writing the current value of testing flag."""
     lib.set_testing(self.orig_config["testing"])
     new_config = lib.get_config()
     assert new_config == self.orig_config
Exemple #10
0
 def tearDown(self):
     """Restore original testing flag."""
     lib.set_testing(self.orig_config["testing"])
Exemple #11
0
 def tearDown(self):
     """Restore testing flag state in config file."""
     lib.set_testing(self.orig_test_state)
Exemple #12
0
 def test_invalid_config(self):
     """Test passing an invalid path to the config file."""
     with self.assertRaises(IOError):
         lib.set_testing(False, config_file="fake.yaml")
Exemple #13
0
 def test_invalid_state(self):
     """Test passing a non-boolean value for state param."""
     with self.assertRaises(TypeError):
         lib.set_testing("not_bool")
     new_config = lib.get_config()
     assert self.orig_config == new_config
Exemple #14
0
 def test_same(self):
     """Test writing the current value of testing flag."""
     lib.set_testing(self.orig_config["testing"])
     new_config = lib.get_config()
     assert new_config == self.orig_config
Exemple #15
0
 def tearDown(self):
     """Restore original testing flag."""
     lib.set_testing(self.orig_config["testing"])