Ejemplo n.º 1
0
Archivo: modv1.py Proyecto: bgerp/ztm
    def __init__(self, **config):
        """Constructor"""

        super().__init__(config)

        self._vendor = "POLYGONTeam"

        self._model = "Blind"

        self.__logger = get_logger(__name__)

        self.__blinds_state = StateMachine(BlindsState.Wait)

        self.__move_timer = Timer()

        self.__calibration_state = StateMachine(CalibrationState.NONE)

        options = self._config["options"]

        if "output_cw" in options:
            self.__output_cw = options["output_cw"]

        if "output_ccw" in options:
            self.__output_ccw = options["output_ccw"]

        if "feedback" in options:
            self.__input_fb = options["feedback"]

        if "feedback_tresh" in options:
            self.__feedback_treshold = options["feedback_tresh"]

        if "deg_per_sec" in options:
            self.__deg_per_sec = options["deg_per_sec"]
        

        # Set the feedback type.
        if self.__input_fb.startswith("AI"):
            self.__feedback_type = FeedbackType.Analog
        
        elif self.__input_fb.startswith("DI"):
            self.__feedback_type = FeedbackType.Digital

        else:
            GlobalErrorHandler.log_missing_resource(self.__logger, "{}: feedback not set correct or incomparable. Check feedback settings.".format(self.name))
Ejemplo n.º 2
0
def update(target_version: dict, current_version: dict):
    """Update the application.

    Args:
        target_version (dict): Dictionary that holds target version.
        current_version (dict): Dictionary that holds the current version.
    """

    # Updater job file.
    update_file_name = "ztm_auto_update.sh"

    logger = get_logger(__file__)

    # Check the consistency of the software version.
    if current_version != target_version:

        if target_version["repo"] != current_version["repo"]:
            logger.info("Changed repo: from {} to {}".format(
                current_version["repo"], target_version["repo"]))

        if target_version["branch"] != current_version["branch"]:
            logger.info("Changed branch: from {} to {}".format(
                current_version["branch"], target_version["branch"]))

        if target_version["commit"] != current_version["commit"]:
            logger.info("Changed commit: from {} to {}".format(
                current_version["commit"], target_version["commit"]))

        # Current file path. & Go to file.
        cwf = os.path.dirname(os.path.abspath(__file__))
        file_name = os.path.join(cwf, "..", "..", "sh", update_file_name)

        if not os.path.exists(file_name):
            GlobalErrorHandler.log_missing_resource(
                logger, "Automatic update procedure: {}".format(file_name))
            return

        # Run the job in background.
        response = os.system("{} {} {} {} &".format(file_name,
                                                    target_version["repo"],
                                                    target_version["branch"],
                                                    target_version["commit"]))
        logger.info(response)
Ejemplo n.º 3
0
    def digital_read(self, pin):
        """Read the digital input pin.

        Args:
            pin (int): Pin index.

        Returns:
            int: State of the pin.
        """

        if self.is_gpio_off(pin):
            return False

        if self.is_gpio_nothing(pin):
            raise ValueError("Pin can not be None or empty string.")

        response = False

        # Local GPIO.
        if self.is_gpio_local(pin):

            # Read device digital inputs.
            request = self.__black_island.generate_request("GetDigitalInputs")
            di_response = self.__modbus_rtu_clients[0].execute(request)
            if di_response is not None:
                if not di_response.isError():
                    self.__DI = di_response.bits
                else:
                    GlobalErrorHandler.log_hardware_malfunction(
                        self.__logger,
                        "GPIO: {} @ {} malfunctioning, check modbus cables and connections."
                        .format(pin, self))
            else:
                GlobalErrorHandler.log_hardware_malfunction(
                    self.__logger,
                    "GPIO: {} @ {} malfunctioning, check modbus cables and connections."
                    .format(pin, self))

            response = self.__DI[self._gpio_map[pin]]

            # Inversion
            if self.is_gpio_inverted(pin):
                response = not response

        # Remote GPIO.
        elif self.is_gpio_remote(pin):

            remote_gpio = self.parse_remote_gpio(pin)

            if not remote_gpio["uart"] in self.__modbus_rtu_clients:
                GlobalErrorHandler.log_missing_resource(
                    "Missing MODBUS-RTU UART{} interface".format(
                        remote_gpio["uart"]))
                return False

            read_response = self.self.__modbus_rtu_clients[
                remote_gpio["uart"]].read_discrete_inputs(
                    remote_gpio["io_reg"],
                    remote_gpio["io_index"] + 1,
                    unit=remote_gpio["mb_id"])

            if not read_response.isError():
                response = read_response.bits[remote_gpio["io_index"]]

                # Inversion
                if self.is_gpio_inverted(pin):
                    response = not response

        else:
            GlobalErrorHandler.log_missing_resource(
                "Pin does not exists in pin map.")

        return response