Пример #1
0
    def __init__(self, config):
        self.logger = logging.getLogger('logger')
        self.logger.info('Starting lockd')

        #add_custom_print_exception()

        serialdevice = config.get('Master Controller', 'serialdevice')
        baudrate = config.get('Master Controller', 'baudrate')

        self.serial_interface = serialinterface.SerialInterface(serialdevice, baudrate, timeout=.1)

        self.input_queue = Queue.Queue()

        udpcommand = UDPCommand('127.0.0.1', 2323, self.input_queue)

        self.doors = {}

        self.master = None

        display = None
        
        self.display_controller = None

        self.logic = DoorLogic()

        for section in config.sections():
            if config.has_option(section, 'type'):
                t = config.get(section, 'type')
                if t == 'door':
                    door_name = section
                    self.logger.debug('Adding door "%s"'%door_name)
                    buttons = {1: 'manual_control', 2: 'bell_code'}
                    door = Door(door_name, config, self.serial_interface, self.input_queue, buttons)
                    door_address = config.get(door_name, 'address')
                    self.doors[door_address] = door
                    self.logic.add_door(door)
                else:
                    self.logger.warning('Unknown entry type "%s"', t)
            elif section == 'Master Controller':
                #txseq = int(config.get(section, 'txsequence'))
                #rxseq = int(config.get(section, 'rxsequence'))
                #key = config.get(section, 'key')
                
                buttons_section = 'Master Controller Buttons'
                buttons = {}
                for button_name in config.options(buttons_section):
                    button_pin = int(config.get(buttons_section, button_name))
                    buttons[button_pin] = button_name

                leds_section = 'Master Controller LEDs'
                leds = {}
                for led_name in config.options(leds_section):
                    led_pin = int(config.get(leds_section, led_name))
                    leds[led_name] = led_pin
                
                self.master = MasterController(self.serial_interface, self.input_queue, buttons, leds) 
            
            elif section == 'Display':
                display_type = config.get(section, 'display_type') 
                max_update_rate = float(config.get(section, 'max_update_rate'))
                if display_type == "Nokia_1600":
                    from display import Display
                    display = Display(self.serial_interface)
                elif display_type == 'simulation':
                    from display_pygame import Display
                    display = Display()
                elif display_type == 'network':
                    from display_network import Display
                    display = Display()
                elif display_type == 'None':
                    display = None
                else:
                    self.logger.warning('Unknown display type "%s"', display_type)
            elif section == 'Status Receiver':
                host = config.get(section, 'host')
                port = int(config.get(section, 'port'))
                self.announcer = Announcer(host, port)
                self.logic.add_state_listener(self.announcer.update_state)
        
        if self.master == None:
            self.logger.error('Please specify a self.master controller')
            sys.exit(1)

        self.interface_logic = UserInterfaceLogic(self.master)
        self.logic.add_state_listener(self.interface_logic.update_state)
        
        if display != None:
            self.display_controller = DisplayController(display, max_update_rate)
            self.display_logic = DisplayLogic(self.display_controller)
            self.logic.add_state_listener(self.display_logic.update_state)
            for door in self.doors.values():
                self.display_logic.add_door(door)

        else:
            self.logger.warning('No display specified.')

        self.input_queue.put({'origin_name': 'init',
                        'origin_type': DoorLogic.Origin.INTERNAL,
                        'input_name': '',
                        'input_type': DoorLogic.Input.COMMAND,
                        'input_value': 'down'})
Пример #2
0
                if initial_unlock == 'True':
                    initial_unlock = True
                else:
                    initial_unlock = False

                key = config.get(section, 'key')
                logger.debug('Adding door "%s"'%section)
                door = Door(name, address, txseq, rxseq, key, ser, initial_unlock)
                doors[address] = door
            else:
                logger.warning('Unknown entry type "%s"', t)
        elif section == 'Master Controller':
            txseq = int(config.get(section, 'txsequence'))
            rxseq = int(config.get(section, 'rxsequence'))
            key = config.get(section, 'key')
            master = MasterController('0', txseq, rxseq, key, ser, command_queue) 
    
    if master == None:
        logger.error('Please specify a master controller')
        sys.exit(1)

    command_queue.put('announce_closed')
    
    while True:
        timeout = False
        while not timeout:
            address, message = ser.readMessage()
            if address != False:
                logger.debug('Received data from address %s :%s'%(address, str(list(message))))
            else:
                timeout = True
Пример #3
0
                    initial_unlock = True
                else:
                    initial_unlock = False

                key = config.get(section, 'key')
                logger.debug('Adding door "%s"' % section)
                door = Door(name, address, txseq, rxseq, key, ser,
                            initial_unlock)
                doors[address] = door
            else:
                logger.warning('Unknown entry type "%s"', t)
        elif section == 'Master Controller':
            txseq = int(config.get(section, 'txsequence'))
            rxseq = int(config.get(section, 'rxsequence'))
            key = config.get(section, 'key')
            master = MasterController('0', txseq, rxseq, key, ser,
                                      command_queue)

    if master == None:
        logger.error('Please specify a master controller')
        sys.exit(1)

    command_queue.put('announce_closed')

    while True:
        timeout = False
        while not timeout:
            address, message = ser.readMessage()
            if address != False:
                logger.debug('Received data from address %s :%s' %
                             (address, str(list(message))))
            else: