Exemplo n.º 1
0
def get_rfid(ser):
    global correlation_id, truck_plate, daily_count, monthly_count
    ser.flushInput()
    start = time.time()
    str_ = ser.read(10)
    ser.flushInput()
    end = int(time.time() - start)
    if end > 10:
        print('10 seconds')
        return 'time'
    else:  #15초 내에 카드 태그 된경우

        #str_=str_[1:9]
        message = ''
        for i in range(10):
            #a=format(str_[i],'#010b')
            #a=a[2:]
            a = hex(str_[i])
            c = str(a)[2:]
            if len(c) == 1:
                c = '0' + c
            message = message + c
        '''
        decimal_representation=int(message,2)
        card_key=hex(decimal_representation)
        card_key=card_key[2:]
        '''
        card_key = message
        print('card key : {}'.format(card_key))
        #카드키값 전송
        value = pc.post_cardkey(user_id, session_key, site_uuid, card_key)
        if value[0] == 'Y':  #성공시
            print('success communicating to server:card')
            correlation_id = value[1]
            truck_plate = value[2]
            daily_count = value[3]
            monthly_count = value[4]
            camera.capture(filename)
            val = pc.post_file(user_id, session_key, correlation_id, filename)
            if val == '0x0000':
                print('success communicating to server:photo')
                return 'success'
            else:
                print('photo sending fail')
                return 'photo'
        else:
            print('card api fail')
            return 'card'
Exemplo n.º 2
0
def get_rfid(ser):
    str_ = ser.read(10)
    str_ = str_[1:9]
    #print(str_)
    #print(type(str_))
    message = ''
    for i in range(8):
        a = format(str_[i], '#010b')
        a = a[2:]
        '''print(a)
        print(type(a))
        '''
        message = message + a
    decimal_representation = int(message, 2)
    card_key = hex(decimal_representation)
    card_key = card_key[2:]
    print(card_key)
    #카드키값 전송
    value = pc.post_cardkey(user_id, session_key, site_uuid, card_key)
    '''
    print(value[0]),    print(value[1]),    print(value[2]),    print(value[3])
    '''
    if value[0] == '0x0000':  #성공시
        #print('success communicating to server:card')
        driver_name = value[1]
        truck_plate = value[2]
        driver_message = value[3]
        correlation_id = value[4]
        ret, frame = cap.read()
        if ret:
            cv2.imwrite(filename, frame)
        cap.release()
        val = pc.post_file(user_id, session_key, correlation_id, filename)
        if val == '0x0000':
            #print('success communicating to server:photo')
            return driver_name, truck_plate, driver_message, correlation_id
        else:
            print('photo sending fail')
            return 'fail', 'fail', 'fail', 'fail'
    else:
        print('card api fail')
        return 'fail', 'fail', 'fail', 'fail'
Exemplo n.º 3
0
def start_rfid(ser):
    global flag_text, flag_status, flag_music, user_id, session_key, correlation_id, filename, truck_plate, daily_count, monthly_count, green, red, camera
    match_count = 0
    timeout_count = 0
    time.sleep(2)
    while True:

        now = time.strftime('%H', time.localtime(time.time()))
        now_m = time.strftime('%M', time.localtime(time.time()))
        now_m = int(now_m)
        int_now = int(now)
        if int_now >= 6 and int_now <= 18:
            if int_now == 18 and now_m > 29:
                continue
            value = get_rfid(ser)
            if value == 'success':  # 인증성공한 경우 사진촬영합니다.
                timeout_count = 0
                flag_music = 'stop'
                flag_text = 'stop'

                print('authenticated')
                gpio.output(green, True)
                gpio.output(red, False)
                try:

                    txt = 'success' + ',' + truck_plate + ',' + str(
                        daily_count) + ',' + str(monthly_count)
                    flag_status = txt
                    print(txt)
                    camera.capture(filename)
                    val = pc.post_file(user_id, session_key, correlation_id,
                                       filename)
                    if val == '0x0000':
                        print('success photo sending')
                        time.sleep(15)
                        reset_flagfiles()
                        gpio.output(green, False)
                        gpio.output(red, True)
                        timeout_count = 0
                        match_count = 0
                    else:
                        print('photo sending failed')
                except Exception as ext:
                    print(ext)
                    print(ext.args)
            elif value == 'time':
                gpio.output(red, True)
                timeout_count = timeout_count + 1
                if timeout_count > 1:
                    print('time out!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
                    flag_status = 'timeout'
                    time.sleep(5)
                    reset_flagfiles()
                    timeout_count = 0
                print('retry time out')
            elif value == 'notcard':
                timeout_count = 0
                flag_music = 'stop'
                flag_text = 'stop'

                print('card doesnt match')
                match_count = match_count + 1
                if match_count > 2:
                    print('4times failed error!!')  # 4번 햇을경우 관리자에게 문의
                    match_count = 0
                    flag_status = 'fail'

                    time.sleep(5)
                    reset_flagfiles()
                else:
                    flag_status = 'retry'

            elif value == 'network':
                timeout_count = 0
                print('network error')
        else:
            print('rfid sleep ...')
            time.sleep(60)
Exemplo n.º 4
0
def start_rfid(ser):
    global user_id,session_key,correlation_id,filename,truck_plate,daily_count,monthly_count,green,red
    match_count=0
    timeout_count=0
    time.sleep(5)
    while True:
        
        now=time.strftime('%H',time.localtime(time.time()))
        int_now=int(now)
        if int_now>=5 and int_now<=18:
            value=get_rfid(ser)
            if value=='success':#인증성공한 경우 사진촬영합니다.
                timeout_count=0
                with open('./flagfile/music.txt','w') as f:
                    f.write('stop')
                with open('./flagfile/text.txt','w') as f:
                    f.write('stop')
                print('authenticated')
                gpio.output(green,True)
                gpio.output(red,False)
                try:
                    with open('./flagfile/status.txt','w') as f:
                        txt='success'+','+truck_plate+','+str(daily_count)+','+str(monthly_count)
                        f.write(txt)
                        print(txt)
                    camera.capture(filename)
                    val=pc.post_file(user_id,session_key,correlation_id,filename)
                    if val=='0x0000':
                        print('success photo sending')
                        time.sleep(10)
                        reset_flagfiles()
                        gpio.output(green,False)
                        gpio.output(red,True)
                        timeout_count=0
                        match_count=0
                    else:
                        print('photo sending failed')
                except Exception as ext:
                    print(ext)
                    print(ext.args)
            elif value=='time':
                gpio.output(red,True)
                timeout_count=timeout_count+1
                if timeout_count>2:
                    reset_flagfiles()
                    with open('./flagfile/status.txt','w') as f:
                        f.write('timeout')
                    timeout_count=0
                print('retry time out')
            elif value=='notcard':
                timeout_count=0
                with open('./flagfile/music.txt','w') as f:
                    f.write('stop')
                with open('./flagfile/text.txt','w') as f:
                    f.write('stop')
                print('card doesnt match')
                match_count=match_count+1
                if match_count>3:
                    print('4times failed error!!')#4번 햇을경우 관리자에게 문의
                    match_count=0
                    with open('./flagfile/status.txt','w') as f:
                        f.write('fail')
                    time.sleep(5)
                    reset_flagfiles()
                else:
                    with open('./flagfile/status.txt','w') as f:
                        f.write('retry')

            elif value=='network':
                timeout_count=0
                print('network error')
        else:
            print('rfid sleep ...')
            time.sleep(60)