Advertisement
phunkaeg

Overload > Yaw Emulator Python Script

Jul 26th, 2024
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | Gaming | 0 0
  1. import socket
  2. import struct
  3. import time
  4. import threading
  5.  
  6. def send_tcp_check_in(ip, port, udp_listening_port, game_name):
  7. """Send a TCP check-in command to the YAW device."""
  8. command_id = 0x01 # Assuming 0x01 is the command ID for CHECK_IN, adjust as necessary
  9. message = struct.pack('!I', udp_listening_port) + game_name.encode('ascii') + bytes([command_id])
  10. with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as tcp_sock:
  11. tcp_sock.connect((ip, port))
  12. tcp_sock.sendall(message)
  13. print("TCP Check-In command sent.")
  14.  
  15. def telemetry_listener(listen_port):
  16. """ Listens for telemetry data from Overload and prints it. """
  17. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  18. sock.bind(('0.0.0.0', listen_port))
  19. print(f"Listening for telemetry on port {listen_port}...")
  20.  
  21. try:
  22. while True:
  23. data, addr = sock.recvfrom(1024) # Buffer size is 1024 bytes
  24. telemetry_data = data.decode()
  25. print(f"Raw data from {addr}: {telemetry_data}")
  26. parsed_data = parse_telemetry(telemetry_data)
  27. if parsed_data:
  28. send_motion_data('192.168.0.101', 50010, parsed_data['yaw'], parsed_data['pitch'], parsed_data['roll'])
  29. except Exception as e:
  30. print(f"Listener error: {e}")
  31. finally:
  32. sock.close()
  33.  
  34. def parse_telemetry(data):
  35. """ Parses telemetry data to extract needed values. """
  36. try:
  37. parts = data.split(';')
  38. if len(parts) >= 14:
  39. roll = float(parts[0])
  40. pitch = float(parts[1])
  41. yaw = float(parts[2])
  42. return {'yaw': yaw, 'pitch': pitch, 'roll': roll}
  43. except ValueError:
  44. return "Error parsing data"
  45. return "Incomplete data"
  46.  
  47. def send_motion_data(udp_ip, udp_port, yaw, pitch, roll):
  48. """ Sends formatted motion data to the Yaw VR device. """
  49. with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as udp_sock:
  50. motion_data = f"Y[{yaw}]P[{pitch}]R[{roll}]".encode('ascii')
  51. udp_sock.sendto(motion_data, (udp_ip, udp_port))
  52. print(f"Sent to Yaw Device: Y[{yaw}]P[{pitch}]R[{roll}]")
  53.  
  54. def main():
  55. telemetry_port = 4123 # Port where Overload sends telemetry
  56. yaw_device_ip = '192.168.0.101' # YAW emulator IP
  57. yaw_device_udp_port = 50010 # UDP port for sending motion data
  58. yaw_device_tcp_port = 50020 # TCP port for check-in command
  59.  
  60. # Send TCP check-in command
  61. send_tcp_check_in(yaw_device_ip, yaw_device_tcp_port, telemetry_port, "OverloadSim")
  62.  
  63. # Start the telemetry listener in a separate thread
  64. listener_thread = threading.Thread(target=telemetry_listener, args=(telemetry_port,))
  65. listener_thread.start()
  66.  
  67. try:
  68. listener_thread.join() # Wait for the listener thread to end, which it won't unless there's an error
  69. except KeyboardInterrupt:
  70. print("Stopping data forwarding.")
  71.  
  72. if __name__ == "__main__":
  73. main()
  74.  
Tags: YAW VR
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement