Beispiel #1
0
def heartbeat():
    global status_reserv
    global reserv_id
    unique_random = binascii.b2a_hex(os.urandom(20))
    ws.send('[2, "' + unique_random + '", "Heartbeat", {}]')
    receive_heartbeat = json.loads(ws.recv())
    print receive_heartbeat
    if receive_heartbeat[0] == 2 and receive_heartbeat[2] == "ReserveNow":
        reserv_id = receive_heartbeat[3]['idTag']
        uniqueId = receive_heartbeat[1]
        ws.send('[3, "' + uniqueId + '",{"status":"Accepted"}]')
        receive = json.loads(ws.recv())
        print receive
        gui.pic_ev_reservation(1)
        gui.update()
        status_reserv = 1
    elif receive_heartbeat[0] == 2 and receive_heartbeat[
            2] == "CancelReservation":
        uniqueId = receive_heartbeat[1]
        ws.send('[3, "' + uniqueId + '",{"status":"Accepted"}]')
        receive = json.loads(ws.recv())
        print receive
        mian_start()
        reserv_id = ""
        status_reserv = 0
Beispiel #2
0
def mian_start():
    global MysCkWire
    global MysInsert
    gui.pic_main_start(1)
    gui.update()
    MysInsert = 0
    MysCkWire = 0
    print "Tag Card\n"
Beispiel #3
0
def switch_pic_charging():
    global rand
    if rand == 1:
        gui.pic_ev_charge1(1)
        gui.update()
        rand = 0
    else:
        gui.pic_ev_charge0(1)
        gui.update()
        rand = 1
Beispiel #4
0
def plug_In():
    global MysCkCardOO
    global MysCkStop
    global MysCkWire
    global MysInsert
    global MysCK
    global Send_Start

    MysCK = 0  # Check D5
    MysCkCardOO = 0
    MysCkStop = 1
    gui.pic_ev_insert_wire(1)
    gui.clear_card_label(1)
    gui.update()
    Mysinsert = 0
    MysCkWire = 1
    Send_Start = 1
    print "Plug In\n"
Beispiel #5
0
def stopTransaction(time_now, chargeType, energy, MysStartPrice2):
    global MysCkStop
    global MysCkWire
    global MysInsert
    global MysCK
    global MysCardid
    global MysText
    global Mystype
    global transactionId

    print "Show Card  Stop\n"
    print(transactionId)
    ws.send(
        '[2, "ZeERlwkKOEdm9qaCnTUpDXI95bxr1ot3", "StatusNotification", {"timestamp": "'
        + time_now + '", "status": "Available", "connectorId": ' + chargeType +
        ', "errorCode": "NoError"}]')
    receive_status_stop = json.loads(ws.recv())
    print("Received : ", receive_status_stop)
    ws.send(
        '[2, "xkgU2inssohvi7b3Im2BTjxZGkMEJgYk", "StopTransaction", {"transactionId": '
        + transactionId + ', "timestamp": "' + time_now + '", "idTag": "' +
        MysCardid + '","meterStop": ' + energy + '}]')
    receive_stop = json.loads(ws.recv())
    print("Received : ", receive_stop)

    gui.clear_card_label(1)
    gui.card_show(1)
    gui.set_energy(MysText, MysCardid, MysStartPrice2, Mystype)

    gui.pic_ev_card(1)
    gui.update()

    time.sleep(3)
    MysCkStop = 0

    MysCK = 0  # Check D5
    MysInsert = 0
    MysCkWire = 0
    gui.clear_card_label(1)
    gui.pic_ev_stop(1)
    gui.update()
    print "Push Stop\n"
    ser.write("CARD$1$end")  #Card correct
Beispiel #6
0
def autentication(card_id, amount, name_user):
    global MysCardid
    global MysText
    global Mystype
    global MysStartPrice
    gui.card_show(1)

    MysStartPrice = amount
    MysCardid = card_id
    MysText = name_user
    Mystype = "Prepaid"

    gui.set_energy(MysText, MysCardid, MysStartPrice, Mystype)

    gui.pic_ev_card(1)
    gui.update()
    print "Card Correct\n"

    time.sleep(3)
    ser.write("CARD$1$end")  #Card correct
Beispiel #7
0
def push_start():
    gui.pic_ev_start(1)  #Push Start
    gui.clear_card_label(1)
    gui.update()
    print "Push Start\n"
Beispiel #8
0
def non_autentication():
    gui.pic_ev_lnvalid(1)
    gui.update()
    ser.write("RE$end")  #RESET Command
Beispiel #9
0
def readSerial():
    global MysCK
    global MysStartPrice
    global MysCkCardOO
    global status_reserv
    global check_reser
    global stop_heartbeat
    global reserv_id

    while True:
        time_now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        serBuffer = ser.readline()
        heartbeat()

        if len(serBuffer) == 0:
            timer90()
            break

        else:
            print serBuffer
            message = serBuffer.split('$')
            length_message = len(message)

            if message[0] == 'D1' and status_reserv == 0:  #Tag Card
                mian_start()
                break

            elif message[0] == 'D1' and status_reserv == 1:  #Tag Card
                gui.pic_ev_reservation(1)
                gui.update()
                break

            elif message[0] == 'D2' and length_message == 3:  #Show Card
                card_id = message[1]
                keep_auten = check_autentication(card_id)
                print status_reserv
                print keep_auten
                print reserv_id
                if keep_auten[2]['idTagInfo'][
                        'status'] == "Accepted" and reserv_id == card_id and status_reserv == 1:
                    amount = keep_auten[2]['idTagInfo']['amount']
                    name_user = keep_auten[2]['idTagInfo']['name']
                    autentication(card_id, amount, name_user)
                    status_reserv = 0
                    reserv_id = ""
                elif keep_auten[2]['idTagInfo'][
                        'status'] == "Accepted" and status_reserv == 0:
                    amount = keep_auten[2]['idTagInfo']['amount']
                    name_user = keep_auten[2]['idTagInfo']['name']
                    autentication(card_id, amount, name_user)
                else:
                    non_autentication()

                break

            elif message[0] == 'D3':  #Push Start
                push_start()
                break

            elif message[0] == 'D4':  #Plug In
                plug_In()
                break

            elif message[0] == 'D5' and length_message == 8:  #Energy
                MysCK = MysCK + 1
                energy = message[1]
                current = message[2]
                price = message[3]
                commandCharge = message[4]
                chargeType = message[5]
                TagCard = message[6]
                MysStartPrice2 = float(MysStartPrice - (float(price)))

                send_start_one_time(time_now, chargeType)

                if MysCK > 15000:  #Mys Add
                    MysCk = 2

                if message[6] == '1':
                    if MysCkStop == 1:
                        stopTransaction(time_now, chargeType, energy,
                                        MysStartPrice2)
                        break

                if message[6] == '0':
                    send_metervalues(chargeType, energy, current, price)
                    switch_pic_charging()
                    break

    gui.restart(10, readSerial)