Compare commits

...

2 commits

Author SHA1 Message Date
9ec76323d7 made UI a little more clear 2024-11-10 16:36:38 +13:00
5d676828d4 added prep to read forza data 2024-11-10 16:30:00 +13:00
6 changed files with 26 additions and 6 deletions

View file

View file

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

View file

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

Binary file not shown.

View file

@ -7,18 +7,38 @@ 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\n")
if gameNo == "1":
portToConnect = BEAMNG_UDP_PORT
dataFormat =BEAMNG_METHODS.BEAMNG_DATA_FORMAT
gameSelected = True
print("BeamNG Selected")
elif gameNo == "2":
portToConnect = FORZA_UDP_PORT
dataFormat = FORZA_METHODS.FROZA_DATA_FORMAT
print("Forza Selected")
gameSelected=True
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:
@ -31,10 +51,9 @@ while connectedArduino == False:
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())