Beispiel #1
0
def handler_cast(websocket, path):
    while True:
        while (not ir_session.ir.startup()) | (ir_session.initialized == 0):
            time.sleep(1)

        datasjs = ""

        cmd = yield from websocket.recv()
        if (cmd == "none") | (not websocket.open):
            break
        if cmd == "send_statics":  # The client ask for all the datas
            print("Message from javascript broadcast > " + cmd)
            datasjs = json.dumps(recupere_donnees(1, ir_session))
        if cmd == "2":
            ir_session.datas_to_send_typ2 = recupere_donnees(2, ir_session)
            datasjs = json.dumps(ir_session.datas_to_send_typ2)
        if cmd == "3":
            ir_session.datas_to_send_typ3 = recupere_donnees(3, ir_session)
            datasjs = json.dumps(ir_session.datas_to_send_typ3)
        yield from websocket.send(datasjs)
Beispiel #2
0
def handler_loc(websocket, path):
    tick = 0
    timestart = 0
    datasjs = json.dumps(recupere_donnees(1, ir_session))
    timeclockold = 0

    while True:
        #while (not ir_session.ir.startup()) | (ir_session.initialized == 0):
        #    time.sleep(1)

        cmd = yield from websocket.recv()
        if (cmd == "none") | (not websocket.open):
            break

        # Si iRacing n'est pas lancé on le dit au client en envoyant -2
        if (not ir_session.ir.startup()) | (ir_session.initialized == 0):
            if tick == 0:
                datasjs = "-3"
            else:
                datasjs = "-2"

        else:
            if (cmd != "2") & (cmd != "3"):
                print("Message from javascript local > " + cmd)
            if cmd == "send_statics":
                ir_session.statics_sent = 0

            # Traitement des commandes du client
            if cmd == "refuel":
                ir_session.refuel = 1
            if cmd == "tires_all":
                ir_session.tires_all = 1
            if cmd == "tires_none":
                ir_session.tires_none = 1

            if (ir_session.statics_sent == 0):
                #time.sleep(1)
                while ir_session.initialized == 0:
                    time.sleep(1)
                ir_session.datas_to_send_typ1 = recupere_donnees(1, ir_session)
                datasjs = json.dumps(ir_session.datas_to_send_typ1)
                ir_session.reload = 0  # Indique au client que ce ne sera plus la peine de recharger la page jusqu'au changement de session
                print("Statics Datas sent to the client")
                ir_session.statics_sent = 1
            else:
                if cmd == "send_statics":  # The client ask for all the datas
                    datasjs = json.dumps(recupere_donnees(1, ir_session))
                if cmd == "2":

                    #print(ir_session.timeremain)

                    ir_session.datas_to_send_typ2 = recupere_donnees(2, ir_session)
                    datasjs = json.dumps(ir_session.datas_to_send_typ2)
                if cmd == "3":
                    ir_session.datas_to_send_typ3 = recupere_donnees(3, ir_session)
                    datasjs = json.dumps(ir_session.datas_to_send_typ3)

        yield from websocket.send(datasjs)

        #print(ir_session.tank_capacity, ir_session.refuelspeed, ir_session.pittimelost1, ir_session.pittimelost3, ir_session.tires_and_fuel)

        tick += 1
Beispiel #3
0
def lance_boucle_datas():
    global ir_session
    tick = 0
    ir_session = obj_ir_session()
    ir_session.ir.startup()
    while True:
        # Waiting for iRacing to start
        print("Waiting for iRacing to start ...")

        ir_session_new = obj_ir_session()
        while not ir_session_new.ir.startup():
            time.sleep(1)

        print("")
        print("-------------------------------------------------------------------------------")
        print("iRacing started !")
        print("")

        sessiontype_old = ir_session.sessiontype
        sessionnum_old = ir_session.sessionnum
        sessionid_old = ir_session.sessionid

        if tick != 0:
            # Does we have changed session ?
            if (ir_session_new.ir["SessionInfo"]["Sessions"][ir_session_new.ir["SessionNum"]]["SessionType"] != sessiontype_old) \
                    | (sessionnum_old != ir_session_new.ir["SessionNum"]) \
                    | (sessionid_old != ir_session_new.ir["WeekendInfo"]["SubSessionID"]):  # When we change session
                print("Changement de session ...")
                #ir_session = obj_ir_session()
                ir_session = ir_session_new
                while not ir_session.ir.startup():
                    time.sleep(1)
                init_session(ir_session)
        else:
            while not ir_session.ir.startup():
                time.sleep(1)
            init_session(ir_session)

        timestart = 0
        sessiontimeold = 0
        while ir_session.ir.startup() & ir_session.initialized:
            pause = 1 / fps_ - (time.clock() - timestart)
            if pause < 0:
                pause = 0
            time.sleep(pause)  # Define the refresh rate for calculations of datas

            """ C'est dangereux car ça peut provoquer une boucle sans fin
            # We are waiting for new iRacing datas
            while ir_session.ir.startup() & (ir_session.ir["SessionTime"] - sessiontimeold == 0) & (
                        ir_session.ir["ReplayPlaySpeed"] != 0):
                pass
            sessiontimeold = ir_session.ir["SessionTime"]
            """

            timestart = time.clock()

            # Update datas
            typ = 3
            if (fps_ // 10) != 0:
                if tick % (fps_ // 10) == 0:
                    typ = 4
            if tick % (fps_ // fps) == 0:
                typ = 2

            # Updates for the broadcast
            if tick % (5 * fps_) == 0:  # 1 time every 5 seconds
                ir_session.datas_to_send_typ2 = recupere_donnees(2, ir_session)
            else:
                if tick % fps_ == 0:  # 1 time per second
                    ir_session.datas_to_send_typ3 = recupere_donnees(3, ir_session)

            tick += 1

            ir_session = calc_donnees(typ, ir_session)

        print("")
        print("*********************")
        print("iRacing has stopped !")
        print("*********************")
        print("")