Exemplo n.º 1
0
 def start(self):
     ModuleBase.start(self)
     
     for handler in self.__handlers:
         handler.start()
         
     RFModule.instance().register_device_handler(self.__radio_handler)
Exemplo n.º 2
0
 def stop(self):
     RFModule.instance().unregister_device_handler(self.__radio_handler)
     
     for handler in self.__handlers:
         handler.stop()
         
     ModuleBase.stop(self)
Exemplo n.º 3
0
    def load_and_configure_modules(cls, db):
        import_modules(['modules'], 'modules')

        for mod in ModuleBase.registered_modules():
            if isinstance(mod, ModuleBase):
                mod.initialize()
                mod.configure(db) 
Exemplo n.º 4
0
 def configure(self, database):
     ModuleBase.configure(self, database)
     
     # Checking database table
     try:
         database.select(Authentication.__exists_query)
     except:
         database.write(Authentication.__create_stmt)
         
     # Checking administrator user
     with database.writer():
         admin_username = database.select(Authentication.__admin_exists_query).fetchone()
         if not admin_username:
             database.write(
                    Authentication.__admin_insert_stmt, 
                    'admin', hashlib.md5('admin').hexdigest())
             print 'AUTH| Created default administrator user'
Exemplo n.º 5
0
 def configure(self, database):
     ModuleBase.configure(self, database)
     
     self.__radio_handler = RadioHandler()
     self.__handlers = []
     
     # register communication handlers
     for idx in xrange(len(sysargs.communication.modes)):
         mode = sysargs.communication.modes[idx]
         port = sysargs.communication.ports[idx]
         host = sysargs.communication.hosts[idx]
         
         if mode.lower() == 'mcast':
             if port is None: port = ClientModule.DEFAULT_PORT
             if host is None: host = ClientModule.DEFAULT_MCAST_GROUP
             
             handler = UDPHandler(host, port, handler=self.handle_received_message, multicast=True)
             self.__handlers.append(handler)
             
         elif mode.lower() == 'bcast':
             if port is None: port = ClientModule.DEFAULT_PORT
             if host is None: host = ClientModule.DEFAULT_BCAST_ADDRESS
             
             handler = UDPHandler(host, port, handler=self.handle_received_message, broadcast=True)
             self.__handlers.append(handler)
             
         elif mode.lower() == 'udp':
             if port is None: port = ClientModule.DEFAULT_PORT
             if host is None: host = ClientModule.DEFAULT_BIND_ADDRESS
             
             handler = UDPHandler(host, port, handler=self.handle_received_message)
             self.__handlers.append(handler)
             
         elif mode.lower() == 'tcp':
             if port is None: port = ClientModule.DEFAULT_PORT
             if host is None: host = ClientModule.DEFAULT_BIND_ADDRESS
             
             handler = TCPHandler(host, port, handler=self.handle_received_message)
             self.__handlers.append(handler)
             
         else:
             print 'Unsupported communication mode:', mode
Exemplo n.º 6
0
 def initialize(self):
     ModuleBase.initialize(self)
     self.__sessions = { }
Exemplo n.º 7
0
 def stop_modules(cls):
     for mod in reversed( ModuleBase.registered_modules() ):
         if isinstance(mod, ModuleBase):
             mod.stop()
Exemplo n.º 8
0
 def start_modules(cls):
     for mod in ModuleBase.registered_modules():
         if isinstance(mod, ModuleBase):
             mod.start()
Exemplo n.º 9
0
 def stop(self):
     try:
         self.__rf.stop()
         ModuleBase.stop(self)
     finally:
         self.__rf.cleanup()
Exemplo n.º 10
0
 def start(self):
     ModuleBase.start(self)
     self.__rf.start()
Exemplo n.º 11
0
 def configure(self, database):
     ModuleBase.configure(self, database)
     self.__rf.register_message_receiver(self)
Exemplo n.º 12
0
 def initialize(self):
     ModuleBase.initialize(self)
     self.__rf = NRF24L01P(payload_length=8, debug=False)
     self.__handlers = []