示例#1
0
    def run(self):
        botlog.info('RFIDReaderThread Running.')

        self.blinkPhase = False
        self.blinkTimer = QTimer()
        self.blinkTimer.timeout.connect(self.blink)        

        self.latchTimer = QTimer()
        self.latchTimer.timeout.connect(self.unlatch)
        self.latchTimer.setSingleShot(True)

        self.delayTimer = QTimer()
        self.delayTimer.timeout.connect(self.undelay)
        self.delayTimer.setSingleShot(True)
        
        self.notifier = QSocketNotifier(self.reader.fileno(), QSocketNotifier.Read)
        self.notifier.activated.connect(self.onData)
        
        self.blinkTimer.start(250)
        self.notifier.setEnabled(True)

        self.setStatus(Status.READY)
        self.exec()
        
        botlog.info('RFIDReaderThread Stopped.')
示例#2
0
    def load(self):
        "return a dictionary of dictionaries with member info indexed by hashed rfid"

        try:
            f = open(self.filename)
            lines = f.read().splitlines()
            f.close()
        except:
            botlog.critical("authenticate can't read CSV %s" % self.filename)
            return {}

        cd = {}
        for l in lines[1:]:
            try:
                (member, value, key, allowed, tagid,
                 lastAccessed) = [x[1] for x in self.csv_regexp.findall(l)]

                cd[tagid] = {
                    'member': member,
                    'allowed': allowed,
                    'tagid': tagid,
                    'warning': None,
                    'plan': None,
                    'nickname': None
                }

            except:
                botlog.error('authenticate CSV fail: %s %s' %
                             (l, sys.exc_info()))

        botlog.info("authenticate read CSV %s %d entries" %
                    (self.filename, len(cd)))
        return cd
示例#3
0
    def onConnect(self):
        botlog.info('New connection to SocketServer')

        try:
            self.client = self.server.nextPendingConnection()
            self.client.disconnected.connect(self.onDisconnect)

        except:
            botlog.error('exception creating client')

        self.connected = True
            
        self.sendReadStatus()
        self.sendCurrentSchedule()
示例#4
0
    def __init__(self, parent=None):
        QThread.__init__(self, parent)

        self.status = Status.INIT
        
        self.hw = DoorHW(red_pin=qsetup.RED_PIN, green_pin=qsetup.GREEN_PIN, door_pin=qsetup.DOOR_PIN, beep_pin=qsetup.BEEP_PIN)

        self.reader = rfid_reader.factory(qsetup.READER_TYPE)
        self.reader.initialize(baud_rate=qsetup.READER_BAUD_RATE)

        self.authenticate = Authenticate.factory(qsetup.AUTHENTICATE_TYPE, qsetup.AUTHENTICATE_FILE)

        botlog.info('authentication file date %s' % self.authenticate.get_file_time())
        botlog.info('RFIDReaderThread Initialized.')
示例#5
0
    def run(self):
        botlog.info('SocketServer Thread Running')

        if self.readerThread:
            self.readerThread.signalStatusChange.connect(self.onStatusChange)
            self.readerThread.signalAccess.connect(self.onAccess)
        
        self.server.newConnection.connect(self.onConnect)

        self.timer.timeout.connect(self.onTimer)
        self.timer.start(1000)
        
        self.exec()
        botlog.info('SocketServerThread Stopped.')
示例#6
0
    def __init__(self, parent=None, readerThread=None):
        QThread.__init__(self, parent)

        self.readerThread = readerThread;
        self.connected = False

        self.timer = QTimer()
        
        self.server = QLocalServer()
        QLocalServer.removeServer('doorbotgui')
        
        if not self.server.listen('doorbotgui'):
            print(self.server.errorString())
            return

        botlog.info('SocketServerThread Initialized.')
示例#7
0
    def load(self):
        "return a dictionary of dictionaries with member info indexed by hashed rfid"

        try:
            f = open(self.filename)
            lines = f.read().splitlines()
            f.close()
        except:
            botlog.critical( "authenticate can't read CSV %s" % self.filename)
            return {}
    
        cd = {}
        for l in lines[1:] :
            try :
                (member,value,key,allowed,tagid,lastAccessed) = [x[1] for x in self.csv_regexp.findall(l)]

                cd[tagid] = {'member': member, 'allowed': allowed, 'tagid':tagid, 'warning':None, 'plan':None, 'nickname':None}

            except:
                botlog.error( 'authenticate CSV fail: %s %s' % (l, sys.exc_info()))

        botlog.info( "authenticate read CSV %s %d entries" % (self.filename, len(cd)))
        return cd
示例#8
0
 def __del__(self):
     botlog.info('SocketServer Thread Deletion')
示例#9
0
    def onData(self):
        rfid_str = self.reader.get_card()
        if not rfid_str:
            return
        
        botlog.debug( 'RFID string >>%s<<' % rfid_str)

        # Several things can happen:
        # 1. some error in reading.
        # 2. good card, not allowed
        # 3. good card, allowed:
        # 3a.  schedule permits access at this time, so open door
        # 3b.  schedule does not permit access at this time.
        # 4. bad card from some reason
        # 5. unknown card
        try :
            self.setStatus(Status.READING)
            rfid = int(rfid_str)
            
            access = self.authenticate.get_access(rfid)
                    
            if access:
                allowed = access['allowed']
                member = access['member']
                plan = access['plan']
                
                print(allowed)
                print(access)
                print(plan)
                
                if 'allowed' in allowed :
                    if qsetup.schedule.isAllowed(plan):
                        # 3a. open the door
                        #
                        botlog.info('%s allowed' % member)

                        self.setStatus(Status.ALLOWED)
                        self.setStatus(Status.LATCHED)
                    
                        self.hw.latch(open=True)
                        self.notifier.setEnabled(False)
                        self.latchTimer.start(4000)
                    else:
                        # 3b. denied due to local schedule
                        botlog.warning('%s DENIED due to schedule restriction' % member)

                        allowed = 'denied'

                        if member['warning'] is None or member['warning'] == '':
                            member['warning'] = qsetup.schedule.scheduleDesc()
                        else:
                            member['warning'] += '\n%s' % qsetup.schedule.scheduleDesc()
                            
                        self.setStatus(Status.DENIED)
                        self.notifier.setEnabled(False)
                        self.delayTimer.start(3000)
                else :
                    #2
                    # access failed.  blink the red
                    #
                    botlog.warning('%s DENIED' % member)
                    self.setStatus(Status.DENIED)
                    self.notifier.setEnabled(False)
                    self.delayTimer.start(3000)


            else :
                #5
                botlog.warning('Unknown card %s ' % rfid_str)
                self.setStatus(Status.UNKNOWN)
                self.signalAccess.emit('denied', {'member':'Unknown.RFID.Tag', 'plan':None, 'tagid':'', 'allowed':'denied', 'nickname':None, 'warning':'This RFID tag is not recognized.  Be sure you are using the correct tag and hold it steady over the read antenna.\n\nContact [email protected] if you continue to have problems.'})

                self.notifier.setEnabled(False)
                self.delayTimer.start(3000)

            self.signalAccess.emit(allowed, access)


        except :
            #4
            # bad input catcher, also includes bad cards
            #
            botlog.warning('bad card %s ' % rfid_str)
            # other exception?
            e = traceback.format_exc().splitlines()[-1]
            botlog.error('door loop unexpected exception: %s' % e)
            self.setStatus(Status.ERROR)
            self.notifier.setEnabled(False)
            self.delayTimer.start(3000)
示例#10
0
 def __del__(self):
     botlog.info('RFIDReaderThread Thread Deletion.')
     self.wait()
示例#11
0
 def onDisconnect(self):
     self.connected = False
     self.client.deleteLater()
     botlog.info('SocketServer disconnected')