Compare commits
2 commits
e55927dbe2
...
9ec76323d7
| Author | SHA1 | Date | |
|---|---|---|---|
| 9ec76323d7 | |||
| 5d676828d4 |
6 changed files with 26 additions and 6 deletions
1
GAME_METHODS/FORZA_METHODS.py
Normal file
1
GAME_METHODS/FORZA_METHODS.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
FROZA_DATA_FORMAT = '<iIfffffffffffffffffffffffffffffffffffffffffffffffffffiiiiifffffffffffffffffHBBBBBBbbb'
|
||||
|
|
@ -1 +1 @@
|
|||
__all__= ["BEAMNG_METHODS"]
|
||||
__all__= ["BEAMNG_METHODS","FORZA_METHODS"]
|
||||
BIN
GAME_METHODS/__pycache__/FORZA_METHODS.cpython-311.pyc
Normal file
BIN
GAME_METHODS/__pycache__/FORZA_METHODS.cpython-311.pyc
Normal file
Binary file not shown.
Binary file not shown.
|
|
@ -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())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue