Compare commits
2 commits
a5c526e3dd
...
cec09d6bcb
| Author | SHA1 | Date | |
|---|---|---|---|
| cec09d6bcb | |||
| 73d7cf6d0b |
7 changed files with 58 additions and 46 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
/build
|
||||
/dist
|
||||
OutGaugeInterpreter.spec
|
||||
47
GAME_METHODS/BEAMNG_METHODS.py
Normal file
47
GAME_METHODS/BEAMNG_METHODS.py
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
BEAMNG_DATA_FORMAT = "I4sHBBfffffffIIfff16s16sxxxx"
|
||||
|
||||
def decodeFlag(flag):
|
||||
flagBin = str(bin(flag))
|
||||
flags = {"showTurbo":newBool(flagBin[2]),"showKM":not newBool(flagBin[1]),"showBAR":not newBool(flagBin[0])}
|
||||
return flags
|
||||
|
||||
def newBool(string):
|
||||
if(string == "0"):
|
||||
return False
|
||||
if(string == "1"):
|
||||
return True
|
||||
|
||||
|
||||
def decodeLights(lightsAvailable,lightsActive):
|
||||
lightsAvBin = str(bin(lightsAvailable))[2:][::-1]
|
||||
lightsActBin = str(bin(lightsActive))[2:][::-1]
|
||||
lights = {}
|
||||
totalLights = ["shift_light","full_beam","handbrake","pit_limiter","tc","left_turn","right_turn","both_turns","oil_warn","battery_warn","abs","spare_light"]
|
||||
for i in range(0,12):
|
||||
try:
|
||||
lights[totalLights[i]] = newBool(lightsActBin[i])
|
||||
except Exception:
|
||||
lights[totalLights[i]] = False
|
||||
return lights
|
||||
|
||||
def unpackData(unpackedData):
|
||||
carData = {"time":unpackedData[0],
|
||||
"carName":unpackedData[1].decode("utf-8"),
|
||||
"flags": decodeFlag(unpackedData[2]),
|
||||
"gear": unpackedData[3],
|
||||
"PLID": unpackedData[4],
|
||||
"speed": unpackedData[5],
|
||||
"rpm": unpackedData[6],
|
||||
"turboPressure":unpackedData[7],
|
||||
"engTemp":unpackedData[8],
|
||||
"fuel":unpackedData[9],
|
||||
"oilPressure":unpackedData[10],
|
||||
"oilTemp":unpackedData[11],
|
||||
"lights":decodeLights(unpackedData[12],unpackedData[13]),
|
||||
"throttle": unpackedData[14],
|
||||
"brake": unpackedData[15],
|
||||
"clutch": unpackedData[16],
|
||||
"misc1": unpackedData[17],
|
||||
"misc2": unpackedData[18]
|
||||
}
|
||||
return carData
|
||||
1
GAME_METHODS/__init__.py
Normal file
1
GAME_METHODS/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
__all__= ["BEAMNG_METHODS"]
|
||||
BIN
GAME_METHODS/__pycache__/BEAMNG_METHODS.cpython-311.pyc
Normal file
BIN
GAME_METHODS/__pycache__/BEAMNG_METHODS.cpython-311.pyc
Normal file
Binary file not shown.
BIN
GAME_METHODS/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
GAME_METHODS/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
|
|
@ -1,33 +1,11 @@
|
|||
import socket
|
||||
import struct
|
||||
import serial
|
||||
from GAME_METHODS import *
|
||||
##import BEAMNG_FILES as BEAM
|
||||
|
||||
toPi=serial.Serial('COM5',115200)
|
||||
|
||||
def decodeFlag(flag):
|
||||
flagBin = str(bin(flag))
|
||||
flags = {"showTurbo":newBool(flagBin[2]),"showKM":not newBool(flagBin[1]),"showBAR":not newBool(flagBin[0])}
|
||||
return flags
|
||||
|
||||
def newBool(string):
|
||||
if(string == "0"):
|
||||
return False
|
||||
if(string == "1"):
|
||||
return True
|
||||
|
||||
|
||||
def decodeLights(lightsAvailable,lightsActive):
|
||||
lightsAvBin = str(bin(lightsAvailable))[2:][::-1]
|
||||
lightsActBin = str(bin(lightsActive))[2:][::-1]
|
||||
lights = {}
|
||||
totalLights = ["shift_light","full_beam","handbrake","pit_limiter","tc","left_turn","right_turn","both_turns","oil_warn","battery_warn","abs","spare_light"]
|
||||
for i in range(0,12):
|
||||
try:
|
||||
lights[totalLights[i]] = newBool(lightsActBin[i])
|
||||
except Exception:
|
||||
lights[totalLights[i]] = False
|
||||
return lights
|
||||
|
||||
toPi=serial.Serial('COM5',115200) #connect to arduino
|
||||
UDP_IP = "127.0.0.1"
|
||||
UDP_PORT = 4444
|
||||
|
||||
|
|
@ -35,29 +13,11 @@ sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
|
|||
sock.bind((UDP_IP,UDP_PORT))
|
||||
print("waiting for data:\n")
|
||||
|
||||
|
||||
while True:
|
||||
data, addr = sock.recvfrom(1024)
|
||||
unpackedData = struct.unpack("I4sHBBfffffffIIfff16s16sxxxx",data)
|
||||
carData = {"time":unpackedData[0],
|
||||
"carName":unpackedData[1].decode("utf-8"),
|
||||
"flags": decodeFlag(unpackedData[2]),
|
||||
"gear": unpackedData[3],
|
||||
"PLID": unpackedData[4],
|
||||
"speed": unpackedData[5],
|
||||
"rpm": unpackedData[6],
|
||||
"turboPressure":unpackedData[7],
|
||||
"engTemp":unpackedData[8],
|
||||
"fuel":unpackedData[9],
|
||||
"oilPressure":unpackedData[10],
|
||||
"oilTemp":unpackedData[11],
|
||||
"lights":decodeLights(unpackedData[12],unpackedData[13]),
|
||||
"throttle": unpackedData[14],
|
||||
"brake": unpackedData[15],
|
||||
"clutch": unpackedData[16],
|
||||
"misc1": unpackedData[17],
|
||||
"misc2": unpackedData[18]
|
||||
}
|
||||
#print("speed: %s" % (carData["speed"]*3.6))
|
||||
unpackedData = struct.unpack(BEAMNG_METHODS.BEAMNG_DATA_FORMAT,data)
|
||||
carData = BEAMNG_METHODS.unpackData(unpackedData)
|
||||
kmh=carData["speed"]*3.6
|
||||
toPi.write(str(kmh).encode()+":".encode())
|
||||
|
||||
|
|
|
|||
1
requirements.txt
Normal file
1
requirements.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
pyserial==3.5
|
||||
Loading…
Add table
Add a link
Reference in a new issue