Пример #1
0
    def _configure_switch(self, config: SwitchConfig, proc_num) -> PROCSwitch:
        """Configure a P3-ROC switch.

        Args:
            config: Dictionary of settings for the switch.
            proc_num: decoded switch number

        Returns a reference to the switch object that was just created.
        """
        if proc_num == -1:
            raise AssertionError("Switch {} cannot be controlled by the "
                                 "P-ROC/P3-ROC.".format(proc_num))

        switch = PROCSwitch(config, proc_num, config.debounce == "quick", self)
        # The P3-ROC needs to be configured to notify the host computers of
        # switch events. (That notification can be for open or closed,
        # debounced or nondebounced.)
        self.debug_log("Configuring switch's host notification settings. P3-ROC"
                       "number: %s, debounce: %s", proc_num,
                       config.debounce)
        if config.debounce == "quick":
            self.run_proc_cmd_no_wait("switch_update_rule", proc_num, 'closed_nondebounced',
                                      {'notifyHost': True, 'reloadActive': False}, [], False)
            self.run_proc_cmd_no_wait("switch_update_rule", proc_num, 'open_nondebounced',
                                      {'notifyHost': True, 'reloadActive': False}, [], False)
        else:
            self.run_proc_cmd_no_wait("switch_update_rule", proc_num, 'closed_debounced',
                                      {'notifyHost': True, 'reloadActive': False}, [], False)
            self.run_proc_cmd_no_wait("switch_update_rule", proc_num, 'open_debounced',
                                      {'notifyHost': True, 'reloadActive': False}, [], False)
        return switch
Пример #2
0
    def _configure_switch(self, config: SwitchConfig, proc_num):
        """Configure a P3-ROC switch.

        Args:
            config: Dictionary of settings for the switch.
            proc_num: decoded switch number

        Returns:
            switch : A reference to the switch object that was just created.
            proc_num : Integer of the actual hardware switch number the P3-ROC
                uses to refer to this switch. Typically your machine
                configuration files would specify a switch number like `SD12` or
                `7/5`. This `proc_num` is an int between 0 and 255.
        """
        if proc_num == -1:
            raise AssertionError("Switch {} cannot be controlled by the "
                                 "P-ROC/P3-ROC.".format(proc_num))

        switch = PROCSwitch(config, proc_num, config.debounce == "quick", self)
        # The P3-ROC needs to be configured to notify the host computers of
        # switch events. (That notification can be for open or closed,
        # debounced or nondebounced.)
        self.debug_log(
            "Configuring switch's host notification settings. P3-ROC"
            "number: %s, debounce: %s", proc_num, config.debounce)
        if config.debounce == "quick":
            self.run_proc_cmd_no_wait("switch_update_rule", proc_num,
                                      'closed_nondebounced', {
                                          'notifyHost': True,
                                          'reloadActive': False
                                      }, [], False)
            self.run_proc_cmd_no_wait("switch_update_rule", proc_num,
                                      'open_nondebounced', {
                                          'notifyHost': True,
                                          'reloadActive': False
                                      }, [], False)
        else:
            self.run_proc_cmd_no_wait("switch_update_rule", proc_num,
                                      'closed_debounced', {
                                          'notifyHost': True,
                                          'reloadActive': False
                                      }, [], False)
            self.run_proc_cmd_no_wait("switch_update_rule", proc_num,
                                      'open_debounced', {
                                          'notifyHost': True,
                                          'reloadActive': False
                                      }, [], False)
        return switch