added prep to read forza data

This commit is contained in:
Seth Samuel 2024-11-10 16:30:00 +13:00
parent e55927dbe2
commit 5d676828d4
4 changed files with 23 additions and 5 deletions

View file

View file

@ -0,0 +1 @@
FROZA_DATA_FORMAT = '<iIfffffffffffffffffffffffffffffffffffffffffffffffffffiiiiifffffffffffffffffHBBBBBBbbb'

View file

@ -1 +1 @@
__all__= ["BEAMNG_METHODS"]
__all__= ["BEAMNG_METHODS","FORZA_METHODS"]

View file

@ -7,18 +7,35 @@ from GAME_METHODS import *
COM_PORT = 'COM5'
UDP_IP = "127.0.0.1"
UDP_PORT = 4444
BEAMNG_UDP_PORT = 4444
FORZA_UDP_PORT= 4843
connectedArduino = False
connectedWebSocket = False
gameSelected = False
portToConnect= 0
dataFormat = ""
while gameSelected == False:
gameNo = input("1:BEAMNG\n2:FORZA")
if gameNo == 1:
portToConnect = BEAMNG_UDP_PORT
dataFormat =BEAMNG_METHODS.BEAMNG_DATA_FORMAT
gameSelected = True
elif gameNo ==2:
portToConnect = FORZA_UDP_PORT
dataFormat = FORZA_METHODS.FROZA_DATA_FORMAT
else:
print("please select a number from the list")
while connectedWebSocket == False:
try:
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
sock.bind((UDP_IP,UDP_PORT))
sock.bind((UDP_IP,portToConnect))
connectedWebSocket = True
except:
print("please check you are able to open the socket on this system")
print("please check you are able to open the socket on this system\ntired to open port: "+portToConnect)
exit()
while connectedArduino == False:
@ -34,7 +51,7 @@ print("ready:\n")
while True:
data, addr = sock.recvfrom(1024)
unpackedData = struct.unpack(BEAMNG_METHODS.BEAMNG_DATA_FORMAT,data)
unpackedData = struct.unpack(dataFormat,data)
carData = BEAMNG_METHODS.unpackData(unpackedData)
kmh=carData["speed"]*3.6
toPi.write(str(kmh).encode()+":".encode())