Пример #1
0
 def __init__(self, cards_file):
     clear_log()
     self.card_reader = CardReader()
     self.cards_file = cards_file
     # Use RPi pin numbering
     GPIO.setmode(GPIO.BOARD)
     GPIO.setwarnings(False)
     # setup output pin
     GPIO.setup(OUT_PIN, GPIO.OUT)
Пример #2
0
class AccessSystem(object):
    def __init__(self, cards_file):
        clear_log()
        self.card_reader = CardReader()
        self.cards_file = cards_file
        # Use RPi pin numbering
        GPIO.setmode(GPIO.BOARD)
        GPIO.setwarnings(False)
        # setup output pin
        GPIO.setup(OUT_PIN, GPIO.OUT)

    def run_access_control(self):
        printd('Starting access control system ...')
        while True:
            # read RFID card reader
            card_num = self.card_reader.read_card()
            # read cards file
            cards_dic = self._read_cards_file()
            # check permission
            if card_num in cards_dic.keys():
                name = cards_dic[card_num]
                self._grant_access(name)
            elif card_num is not None:
                self._deny_access(card_num)

    def _read_cards_file(self):
        cards_dic = {}
        with open(self.cards_file) as f:
            for line in f:
                line_vals = [s.strip() for s in line.split(',')]
                if len(line_vals) != 2:
                    printd(
                        'ERROR: invalid line in cards file: {}'.format(line))
                else:
                    try:
                        num = int(line_vals[0])
                        name = line_vals[1]
                    except ValueError as e:
                        printd('ERROR: invalid card number on line: {}'.format(
                            line))
                    cards_dic[num] = name
        return cards_dic

    def _grant_access(self, name):
        printd('Access Granted for {}'.format(name))
        GPIO.output(OUT_PIN, True)
        time.sleep(UNLOCK_TIME)
        GPIO.output(OUT_PIN, False)

    def _deny_access(self, num):
        printd('Access Denied for card: {}'.format(num))
        GPIO.output(OUT_PIN, False)
Пример #3
0
    def tryInitCardReader(self):
        statusIcon = self.get('client_status')
        try:
            self.cardReader = CardReader()
        except RuntimeError:
            statusIcon.set_tooltip_markup('找不到讀卡機,請檢查是否妥善連接')
        except Exception as err:
            # discard the object QQ
            self.cardReader = None
            statusIcon.set_tooltip_markup('讀卡機初始化失敗,請關閉程式後再試一次')
            print('Card reader general failure', err)

        iconName = 'emblem-default'
        if self.cardReader is None:
            iconName = 'emblem-important'
        self.get('client_status').set_from_icon_name(iconName, -1)
Пример #4
0
def main():
    card_reader = CardReader()
    card_num = card_reader.read_card()
    name = raw_input('Enter name: ')
    with open(CARDS_FILE, 'a') as f:
        f.write('{}, {}\n'.format(card_num, name))
Пример #5
0
from card_reader import CardReader
from database_manager import DatabaseManager

if __name__ == '__main__':
    cr = CardReader()
    print()
    cr.read_idm()
    new_idm = str(cr.idm)
    new_idm = new_idm[2:-1]
    print("カードのID: ", end=' ')
    print(new_idm)

    while True:
        text = input('登録名を入力してください >> ')
        print()
        is_inp = input(text + "さんでよろしいですか? 'y/n' >> ")
        if is_inp is ('n' or 'no' or 'N'):
            print("N")
            break
        elif is_inp is not ('y' or 'yes' or 'Y'):
            print("y/n で入力してください")
            continue
        else:
            print("Y")
            with DatabaseManager() as dm:
                dm.subscribe(new_idm, text)
            break
Пример #6
0
def one_card_reader(cards):
    """ 카드리더 fixture 생성 """
    # 임의로 하나의 카드만 선택
    card = CardReader([list(cards.keys())[1]])
    return card
Пример #7
0
from Queue import Queue
from card_reader import CardReader
from remote_listener import RemoteListener
from dispatcher import Dispatcher

print "Welcome to Jeremy's Jukebox 3.0"
print ''

q = Queue()

CardReader(q).start()
RemoteListener(q).start()
Dispatcher(q, "/mnt/bigdaddy").start()
Пример #8
0
from timeout import Timeout
from leds import LEDs

if __name__ == "__main__":
    logging.basicConfig(filename = "./log/file_{t}.log".format(t = time.strftime("%Y_%m_%d_%H_%M_%S", time.localtime())),
                        level=logging.DEBUG, 
                        format="%(asctime)s:" + logging.BASIC_FORMAT)
    console = logging.StreamHandler()
    console.setLevel(logging.DEBUG)
    console.setFormatter(logging.Formatter("%(asctime)s:" + logging.BASIC_FORMAT))
    logging.getLogger().addHandler(console)
    logger = logging.getLogger(__name__)
    logger.info("Student Logger has started")
    while(True):# Loop created for retry purposes
        try:    
            card_reader = CardReader();
            access_list = AccessList("allowed_students.txt",logger.getChild("access_list"));
            with LEDs() as leds:
                while(True):
                    tag_id = card_reader.get_tag_id();
                    with Timeout(seconds=20) as t:
                        leds.orange();
                        student = Student(tag_id, logger.getChild("student"))
                        access_status = access_list.check_allowed(student.info[0])
                        logger.info("Student Number: {name} Access Given: {status}".format(
                            name = student.info[0],
                            status = access_status))
                        if(True==access_status):
                            leds.green();
                        else:
                            leds.red();