Compare commits
No commits in common. "9ec76323d7a4b461b17944097809693dca142283" and "e55927dbe27db96cd5e95b22747d2ca9e4871568" have entirely different histories.
9ec76323d7
...
e55927dbe2
6 changed files with 6 additions and 26 deletions
0
FORZA_METHODS
Normal file
0
FORZA_METHODS
Normal file
|
|
@ -1 +0,0 @@
|
||||||
FROZA_DATA_FORMAT = '<iIfffffffffffffffffffffffffffffffffffffffffffffffffffiiiiifffffffffffffffffHBBBBBBbbb'
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
__all__= ["BEAMNG_METHODS","FORZA_METHODS"]
|
__all__= ["BEAMNG_METHODS"]
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -7,38 +7,18 @@ from GAME_METHODS import *
|
||||||
|
|
||||||
COM_PORT = 'COM5'
|
COM_PORT = 'COM5'
|
||||||
UDP_IP = "127.0.0.1"
|
UDP_IP = "127.0.0.1"
|
||||||
BEAMNG_UDP_PORT = 4444
|
UDP_PORT = 4444
|
||||||
FORZA_UDP_PORT= 4843
|
|
||||||
|
|
||||||
connectedArduino = False
|
connectedArduino = False
|
||||||
connectedWebSocket = 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:
|
while connectedWebSocket == False:
|
||||||
try:
|
try:
|
||||||
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
|
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
|
||||||
sock.bind((UDP_IP,portToConnect))
|
sock.bind((UDP_IP,UDP_PORT))
|
||||||
connectedWebSocket = True
|
connectedWebSocket = True
|
||||||
except:
|
except:
|
||||||
print("please check you are able to open the socket on this system\ntired to open port: "+portToConnect)
|
print("please check you are able to open the socket on this system")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
while connectedArduino == False:
|
while connectedArduino == False:
|
||||||
|
|
@ -51,9 +31,10 @@ while connectedArduino == False:
|
||||||
|
|
||||||
print("ready:\n")
|
print("ready:\n")
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
data, addr = sock.recvfrom(1024)
|
data, addr = sock.recvfrom(1024)
|
||||||
unpackedData = struct.unpack(dataFormat,data)
|
unpackedData = struct.unpack(BEAMNG_METHODS.BEAMNG_DATA_FORMAT,data)
|
||||||
carData = BEAMNG_METHODS.unpackData(unpackedData)
|
carData = BEAMNG_METHODS.unpackData(unpackedData)
|
||||||
kmh=carData["speed"]*3.6
|
kmh=carData["speed"]*3.6
|
||||||
toPi.write(str(kmh).encode()+":".encode())
|
toPi.write(str(kmh).encode()+":".encode())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue