23 lines
565 B
Python
23 lines
565 B
Python
import socket
|
|
import struct
|
|
import serial
|
|
from GAME_METHODS import *
|
|
##import BEAMNG_FILES as BEAM
|
|
|
|
|
|
toPi=serial.Serial('COM5',115200) #connect to arduino
|
|
UDP_IP = "127.0.0.1"
|
|
UDP_PORT = 4444
|
|
|
|
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(BEAMNG_METHODS.BEAMNG_DATA_FORMAT,data)
|
|
carData = BEAMNG_METHODS.unpackData(unpackedData)
|
|
kmh=carData["speed"]*3.6
|
|
toPi.write(str(kmh).encode()+":".encode())
|
|
|