def __init__(self, param_config=None):
        self.cm = configuration_manager.Configuration(
            param_config=param_config)
        global cm
        cm = self.cm

        # list to store the Channels instances in
        self.channels = list()

        # network setup if used
        self.network = networking.Networking(cm)
        self.server = self.network.networking == "server" or self.network.networking == "serverjson"
        self.broadcast = self.network.broadcast

        self.led = None
        if self.cm.configs.led:
            self.led = list()
            if self.cm.configs.led_multiprocess:
                LEDManager.register('LED', led_module.Led)
                for lc in self.cm.configs.led:
                    self.cm.set_led(config_file=lc)
                    self.ledmanager = LEDManager()
                    self.ledmanager.start()
                    self.cm.led.multiprocess = True
                    self.led.append(self.ledmanager.LED(self.cm.led))
            else:
                for lc in self.cm.configs.led:
                    self.cm.set_led(config_file=lc)
                    self.cm.led.multiprocess = False
                    self.led.append(led_module.Led(self.cm.led))

        self.create_lights()
        self.set_overrides()
    def __init__(self):
        self.cm = cm

        # list to store the Channels instances in
        self.channels = list()

        # network setup if used
        self.network = networking.Networking(cm)
        self.server = self.network.networking == "server"
        self.playing = self.network.playing
        self.broadcast = self.network.broadcast

        self.led = None
        if self.cm.configs.led:
            self.led = list()
            if self.cm.configs.led_multiprocess:
                LEDManager.register('LED', led_module.Led)
                for lc in self.cm.configs.led:
                    self.cm.set_led(config_file=lc)
                    self.ledmanager = LEDManager()
                    self.ledmanager.start()
                    self.led.append(self.ledmanager.LED(self.cm.led))
            else:
                for lc in self.cm.configs.led:
                    self.cm.set_led(config_file=lc)
                    self.led.append(led_module.Led(self.cm.led))

        self.create_lights()
        self.set_overrides()
Exemple #3
0
 def __init__(self):
     self.make_logger()
     self.__pcaps = pcaps.pcaps(logging)
     self.__networking = networking.Networking(logging)
     self.__primerEngine = primer_engine.PrimerEngine(
         self.__networking, logging)
Exemple #4
0
    """
    network.unset_playing()
    turn_off_lights()
    set_pins_as_inputs()


def initialize():
    """Set pins as outputs and start all lights in the off state."""
    wiringpi.wiringPiSetup()
    enable_device()
    set_pins_as_outputs()

    turn_off_lights()

# network setup if used
network = networking.Networking(cm)
server = network.networking == "server"


# test functions
def light_on(pins, override=False, brightness=1.0):
    """work around to make custom channel mapping work with hardware tests"""
    if ccm:
        pins = ccm_map[pins]
    else:
        pins = [pins]

    if len(pins) == 0:
        return

    for pin in pins:
Exemple #5
0
    def __init__(self, etbconfig):
        """
        Create an ETB node based on `etbconfig` (see :class:`etb.ETBConfig`)

        :parameters:
            - `etbconfig`: An instance of :class:`etb.ETBConfig`

        :members:
        
            - `self.config`: the etbconfig parameter
            - `self.log`: the object used for logging Engine related messages
            - `self.interpret_state`: an instance of :class:`etb.InterpretState`
            - `self.engine`: an instance of :class:`etb.datalog.engine.Engine`
            - `self.etb_dir`: the directory etbd was started in - used
               for `put_file` from wrappers
            - `self.git`: an instance of :class:`etb.git_interface.ETBGIT`
            - `self.cron`: an instance of :class:`etb.utils.CronJob`
            - `self.short_pool`: an instace of :class:`etb.utils.ThreadPool`
               for quick tasks
            - `self.long_pool`: an instace of :class:`etb.utils.ThreadPool`
               for potentially long tasks, e.g., wrappers
            - `self.task_worker`: an instance of :class:`etb.TaskWorker`,
               the main ETB thread for this node
            - `self.networking`: an instance of :class:`etb.networking.Networking`,
               providing the XML-RPC API
            - `self.subscriptions`: a set of goals this node is subscribed to
            - `self.active_local_queries`: the set of active local queries
            - `self.active_remote_queries`: the set of active remote queries
        """
        self.config = etbconfig
        #logging.basicConfig(format="%(asctime)s %(levelname)s %(name)s %(process)d/%(threadName)s: %(message)s")
        self.log = logging.getLogger('etb')

        # Save the starting ETB directory (usually also the etbsh directory)
        # This is used by wrappers using get_file.
        self.etb_dir = os.getcwd()

        self._rlock = threading.RLock()

        # We set up the ETB filesystem and move to its root
        # Rules and wrappers will be imported, and read from the
        # Git working directory.
        self.git = git_interface.ETBGIT(self.config.git_dir)
        os.chdir(self.git.git_dir)

        # This will add/update the 'rules' and 'wrappers' directories in Git
        changed = self.add_rules_and_wrappers_to_git()

        # Create interpret_state
        self.interpret_state = interpret_state.InterpretState(self)
        self.interpret_state.load_wrappers()

        # Start the engine
        self.engine = datalog.engine.Engine(self.interpret_state)

        # to run tasks periodically (also used by networking)
        self.cron = utils.CronJob(self, period=self.config.cron_period)
        # self.cron.onIteration.add_handler(self.update_done_queries)

        # different threads/thread pools
        self.short_pool = utils.ThreadPool(self)     # for quick tasks
        self.long_pool = utils.ThreadPool(self)      # for long running tasks
        self.task_worker = TaskWorker(self, daemon=True)    # main etb thread

        # networking component using xml-rpc
        self.networking = networking.Networking(self, self.config.port)

        # goals we subscribed to
        self.subscriptions = set()

        self.engine.load_default_rules()

        # Now load the logic_file
        if not changed:
            self.engine.load_logic_file()

        # queries
        self._queries = {}
        self._done_queries = {}
        self.active_local_queries = set()
        self.active_remote_queries = {}

        import atexit
        atexit.register(self.stop)