Esempio n. 1
0
    def __init__(self,
                 number,
                 debug=False,
                 sanity_checks=True,
                 auto_load=True):
        from fpesocketconnection import FPESocketConnection

        # First sanity check: ping the observatory simulator
        if not ping():
            raise Exception("Cannot ping 192.168.100.1")
        self._debug = debug
        self._dir = os.path.dirname(os.path.realpath(__file__))
        self._reset_in_progress = False
        self._loading_wrapper = False
        self.fpe_number = number
        self.connection = FPESocketConnection(5554 + number, self._debug)

        # self.ops implemented with lazy getter
        self._ops = None

        frames_status = None
        if sanity_checks is True:
            from unit_tests import check_house_keeping_voltages
            from unit_tests import UnexpectedHousekeeping
            from fpesocketconnection import TimeOutError
            try:
                try:
                    frames_status = self.frames_running_status
                    assert frames_status is True or frames_status is False
                except Exception as e:
                    raise type(
                        e
                    )("Could not read if frames are running on the Observatory Simulator... {0}\n"
                      .format(str(e)) +
                      "Are you sure the firmware for the Observatory Simulator is properly installed?"
                      )
                try:
                    version = self.version
                    if self._debug:
                        print version
                except Exception as e:
                    raise type(
                        e
                    )("Could not read Observatory Simulator version... {0}\n".
                      format(str(e)) +
                      "Are you sure you firmware for the Observatory Simulator is properly installed?"
                      )
                if frames_status is not True:
                    try:
                        check_house_keeping_voltages(self)
                    except (UnexpectedHousekeeping, TimeOutError) as e:
                        if auto_load is True:
                            self.load_wrapper()
                        else:
                            raise e

            finally:
                if frames_status is not None:
                    self.frames_running_status = frames_status