Hi there
I've just returned to B4x after a couple of years so I'm a little out of practice.
I created program on my raspberry pi to read telemetry data from a game to create a dashboard with speed lap times etc.
It works quite well so I want to adapt the code to B4a and im struggling with the first two hurdles (not a great start I know).
Firstly: I need to read the data stream so obviously I need to initialize the socket, Ive tried a few examples and adapted them to the port (5060), doesnt matter whjat piece of code I try i get the error (Addresses already in use)
Second: I need to breakdown and decode the packet from binaray into individual variables ranging through ints, floats and strings ,it then needs to be decoded from binary.
Each variable ranges in size, I have the locations of where I can find each variable and I know what data types they need to be converted to, Im just not sure how to break it down in B4a.
this is a snippet of code that works in python which reads the data decodes the best lap time and prints it in the debug window.
Im looking for any insight or examples I might be able to adapt for my project.
Thanks for your consideration
I've just returned to B4x after a couple of years so I'm a little out of practice.
I created program on my raspberry pi to read telemetry data from a game to create a dashboard with speed lap times etc.
It works quite well so I want to adapt the code to B4a and im struggling with the first two hurdles (not a great start I know).
Firstly: I need to read the data stream so obviously I need to initialize the socket, Ive tried a few examples and adapted them to the port (5060), doesnt matter whjat piece of code I try i get the error (Addresses already in use)
Second: I need to breakdown and decode the packet from binaray into individual variables ranging through ints, floats and strings ,it then needs to be decoded from binary.
Each variable ranges in size, I have the locations of where I can find each variable and I know what data types they need to be converted to, Im just not sure how to break it down in B4a.
this is a snippet of code that works in python which reads the data decodes the best lap time and prints it in the debug window.
project cars udp socket reader:
import socket
import struct
import time
personalbestlap=0.0
package_type=-1
UDP_IP_ADDRESS = "0.0.0.0"
UDP_PORT_NO = 5606
running=True
serverSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
serverSock.bind((UDP_IP_ADDRESS, UDP_PORT_NO))
def check_package_type(package):
return (struct.unpack('B', package[2:3])[0] & 0x3)
while running:
data, addr = serverSock.recvfrom(10000)
if data is not None:
package_type=check_package_type(data)
if (package_type==0):
print(package_type)
sd=struct.unpack('f', data[40:44])[0]
if (sd>=1.0):
personalbestlap=sd
print(personalbestlap)
Im looking for any insight or examples I might be able to adapt for my project.
Thanks for your consideration