-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDecode_CodeMasters.py
More file actions
69 lines (59 loc) · 2.41 KB
/
Copy pathDecode_CodeMasters.py
File metadata and controls
69 lines (59 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# ----------------------------------------------------------------------------------------------------------------------
# Test tool to receive packed values.
# Assumes packed data is of fixed size.
# ----------------------------------------------------------------------------------------------------------------------
#Check http://forums.codemasters.com/discussion/46726/d-box-and-udp-telemetry-information
#command line to generate traffic : C:\Users\vthinselin\Google Drive\Loisirs\Playseat\Python_UDP_Receiver>python UDPSend_timed.py -s 127.0.0.1 -p 20777 -f f1_2016_ps4.bin
import sys
import struct
import socket
# Configure listener IP & Port for UDP transmission of packed values
udp_ip = "0.0.0.0"
udp_port = 20777
def net_rx(UDP_IP, UDP_PORT):
# Receive packet from wire
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))
data, addr = sock.recvfrom(1024) # receiving from socket
return data
def displaygear(gear):
# | car gear | data gear | Required to adjust for gear float mapping as shown
# | R | 0 |
# | N | 1 |
# | 1 | 2 |
# | 2 | 3 |
# | 3 | 4 |
# | 4 | 5 |
# | 5 | 6 |
# | 6 | 7 |
# | 7 | 8 |
# ------------------------
if (gear > 1): # Forward gear requires minus adjustment
gear -=1
print("Current Gear :%d" % gear) # print forward gear
elif (gear == 1):
print("Current Gear :N") # print neutral
elif (gear == 0):
print("Current Gear :R") # print reverse
return
def displaymph(mph):
print("Current MPH :%f" % mph)
return
def receiver():
fmt = '<' + '70' + 'f' # define structure of packed data
s = struct.Struct(fmt) # declare structure
packetCounter = 0
recordedData = []
# Infinite receiving loops
while True:
rx_data = net_rx(udp_ip, udp_port)
unpacked_data = s.unpack(rx_data) # unpack data into tuple, requires correct 'fmt'
displaygear(unpacked_data[33])
print("Current RPM :%d" % unpacked_data[37])
displaymph(unpacked_data[7])
return
def main():
receiver()
return
if __name__ == '__main__':
main()