def __init__(self):
        # Initialize process framework attributes so we can start using them
        RPiProcessFramework.__init__(self, default_log_level='INFO')

        # Initialize all installed PiFace boards
        self.logger_instance.debug("RPiOutputVentilator - Initializing PiFace boards")
        RPiPiface.__init__(self)
        # Let's share some log information
        if RPiPiface.get_number_of_boards(self) == 0:
            self.logger_instance.critical(
                "RPiOutputVentilator - No PiFace boards detected. \
                Unable to process input signals"
                )
            self.run_process = False    # No need to continue
        elif RPiPiface.get_number_of_boards(self) == 1:
            self.logger_instance.info("RPiOutputVentilator - One PiFace boards detected")
        else:
            self.logger_instance.warning(
                "RPiOutputVentilator - More than one PiFace board detected." +\
                "Address of last detected board = {}".format(RPiPiface.get_number_of_boards(self)-1))

        # Initialize the output relay dictionary
        self.output_relays = self.create_output_relay_list(self.process_attributes.__repr__())
        # Initialize the relay timer dictionary
        self.relays_timer = self.create_relay_timer_list(self.process_attributes.__repr__())
        # Initialize the process logic dictionary
        self.process_logic = self.create_process_logic_dictionary()
    def create_output_relay_list(self, process_attribute_list):
        '''
        Return value is a dictionary where
          - The key is set as the address consisting of the board and relay number
          - The corresponding values a list structure containing following attributes:
            - State => integer that is either 0 =>Relay in 'released' state or
              1 => Relay in 'pulled' state
            - Description => String value
            - Logic => logic that indicates what should happen based on the message
              send by an input handler (for example input buttons)
            - Pulse => integer that is either 0 (=Nothing going on) or 1 (=Pulse action ongoing)
            - PulseTimeStamp => timestamp when the pulse state was changed
        '''
        reply = {}

        for board in range(0, RPiPiface.get_number_of_boards(self)):
            for pin in range(0, 2):
                key = "Relay" + str(board) + str(pin)
                if key in process_attribute_list:
                    value = process_attribute_list[key]
                    attribute_key, description, logic = value.split(
                        ";")
                    logic_list = []
                    logic_list = logic.split(',')
                    if description != "Not Used":
                        reply[attribute_key] = [
                            0,  # State
                            description,
                            logic_list,
                            0,  # Pulse
                            0]  # Timestamp when pulse status was change
                        self.logger_instance.debug(
                            "RPiOutputVentilator - Initializing output_relay: {}".format(
                                attribute_key) +\
                            " - State: {}".format(
                                reply[attribute_key][0]) +\
                            " - Description: {}".format(
                                reply[attribute_key][1]) +\
                            " - Logic: {}".format(
                                reply[attribute_key][2]) +\
                            " - Pulse: {}".format(
                                reply[attribute_key][3]) +\
                            " - Pulse Time Stamp: {}".format(
                                reply[attribute_key][4])
                            )

        return reply
Example #3
0
    def __str__(self):
        long_string = RPiProcessFramework.__str__(self)
        long_string += "Number of PiFace boards detected: {}\n".format(
            RPiPiface.get_number_of_boards(self))
        if self.output_relays != {}:
            long_string += "output_relays:\n"
            for key, value in self.output_relays.items():
                long_string += "{} = {}\n".format(key, value)
        else:
            long_string += "No output_relays information found!\n"
        if self.process_logic != {}:
            long_string += "process_logic:\n"
            for key, value in self.process_logic.items():
                long_string += "{} = {}\n".format(key, value)
        else:
            long_string += "No output_relays process logic found!\n"

        return long_string
    def create_relay_timer_list(self, process_attribute_list):
        '''
        Return value is a dictionary where
          - The key is set as the address consisting of the board and relay number
          - The corresponding values a list structure containing following attributes:
            - State => integer that is either 0 => Timer is not running or
              1 => Timer is running
            - Description => String value
            - lagtime => Number of seconds the ventilator will remain active after
                         "stop" event is received
            - runtime => Maximum number of seconds the ventilator should run
        '''
        reply = {}

        for board in range(0, RPiPiface.get_number_of_boards(self)):
            for pin in range(0, 2):
                key = "RelayTimer" + str(board) + str(pin)
                if key in process_attribute_list:
                    value = process_attribute_list[key]
                    attribute_key, description, lagtime, runtime = value.split(
                        ";")
                    if description != "Not Used":
                        reply[attribute_key] = [
                            0,  # State
                            description,
                            int(lagtime),
                            int(runtime),
                            0, # start_time
                            0] # stop_time
                        self.logger_instance.debug(
                            "RPiOutputVentilator - Initializing relay_timer: {}".format(
                                attribute_key) +\
                            " - State: {}".format(
                                reply[attribute_key][0]) +\
                            " - Description: {}".format(
                                reply[attribute_key][1]) +\
                            " - LagTime: {}".format(
                                reply[attribute_key][2]) +\
                            " - RunTime: {}".format(
                                reply[attribute_key][3])
                            )

        return reply
 def __repr__(self):
     return str(RPiPiface.get_number_of_boards(self))