Ejemplo n.º 1
0
def badgeScanThread(threadName, delay):
    retcode = SCAN.scanInit()
    if retcode == "SUCCESS":
        print "%s: %s" % (threadName, time.ctime(time.time()) )
    else:
        print "FAILED ScanInit %s/n%s" % (retcode, time.ctime(time.time()) )
        LCD.lcd_string(retcode,LCD.LCD_LINE_1)
        LCD.lcd_string(time.ctime(time.time()),LCD.LCD_LINE_2)
        
    while 1:
        time.sleep(delay)
        badgeId = SCAN.watchPort()  # wait here until a badge is scanned
        userName = DB.queryUserNameFromBadgeId(badgeId)
        print "badgeScanThread %s: %s" % (userName.text, badgeId )        
        LCD.lcd_string(userName.text,LCD.LCD_LINE_1)
        LCD.lcd_string(time.ctime(time.time()),LCD.LCD_LINE_2)
        a_lock.release()
Ejemplo n.º 2
0
def state_user_logged_in(eventMsg):
    print "state_user_logged_in = ", eventMsg
    if eventMsg[0] == EVENT_MSG_RESET:
        deviceAccessQ.put( ("LOGGING OFF", ("00:00") ) )
        nextState = STATE_LOGGING_OFF
    elif eventMsg[0] == EVENT_MSG_USER_GRANTED_ACCESS:
        logged_in_user_name = eventMsg[1]
        tempname = logged_in_user_name
        time_end = eventMsg[2]
        if time_end < time.time():
          time_remaining = 0;
        else:
          time_remaining = time_end-time.time()

        print " time remaining",(time.ctime( time_remaining ) )[14:19]
        if (time.ctime( time_remaining ) )[14:19] == EXPIRED:
          LcdQ.put( (logged_in_user_name, (time.ctime( time_remaining ) )[14:19]) )
          deviceAccessQ.put( (logged_in_user_name, (time.ctime( time_remaining ) )[14:19]) )
          nextState = STATE_LOGGING_OFF
        else:
          LcdQ.put( (logged_in_user_name, (time.ctime( time_remaining ) )[14:19]) )
          deviceAccessQ.put( (logged_in_user_name, (time.ctime( time_remaining ) )[14:19]) )
          nextState = STATE_USER_LOGGED_IN

    elif eventMsg[0] == EVENT_MSG_BADGE_SCAN:
        dbUserValues = {}
        dbUserValues = DB.queryUserNameFromBadgeId(eventMsg[1])
        if (float(dbUserValues['time']) > 0 ):
          nextState = STATE_VALIDATE_BADGE
        else:
          LcdQ.put( (dbUserValues['username'], "NOT AUTH TO USE" ) )
          time.sleep(5)
          nextState = STATE_INVALID_USER

    elif eventMsg[0] == EVENT_MSG_TIMER_EXPIRE:
        nextState = STATE_LOGGING_OFF
    else:
        nextState = STATE_IDLE
    return nextState
Ejemplo n.º 3
0
def state_validate_user_badge(eventMsg):
    print "state_validate_user_badge = ", eventMsg
    LcdQ.put( ("CHECKING BADGE", time.ctime(time.time())) )
    if eventMsg[0] == EVENT_MSG_NULL:
        nextState = STATE_IDLE
    elif eventMsg[0] == EVENT_MSG_RESET:
        nextState = STATE_INIT
    elif eventMsg[0] == EVENT_MSG_BADGE_SCAN:
        dbUserValues = {}
        dbUserValues = DB.queryUserNameFromBadgeId(eventMsg[1])
        if (float(dbUserValues['time']) > 0 ):
          timeend = float(dbUserValues['time']) +time.time()
          eventQ.put( (EVENT_MSG_USER_GRANTED_ACCESS, dbUserValues['username'], timeend ) )
          nextState = STATE_USER_LOGGED_IN
        else:
          LcdQ.put( (dbUserValues['username'], ("NOT PERMITTED") ) )
          time.sleep(5)
          nextState = STATE_IDLE

    elif eventMsg[0] == EVENT_MSG_TIMER_EXPIRE:
        nextState = STATE_IDLE
    else:
        nextState = STATE_IDLE
    return nextState