Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import struct
- import time
- import threading
- def send_tcp_check_in(ip, port, udp_listening_port, game_name):
- """Send a TCP check-in command to the YAW device."""
- command_id = 0x01 # Assuming 0x01 is the command ID for CHECK_IN, adjust as necessary
- message = struct.pack('!I', udp_listening_port) + game_name.encode('ascii') + bytes([command_id])
- with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as tcp_sock:
- tcp_sock.connect((ip, port))
- tcp_sock.sendall(message)
- print("TCP Check-In command sent.")
- def telemetry_listener(listen_port):
- """ Listens for telemetry data from Overload and prints it. """
- sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- sock.bind(('0.0.0.0', listen_port))
- print(f"Listening for telemetry on port {listen_port}...")
- try:
- while True:
- data, addr = sock.recvfrom(1024) # Buffer size is 1024 bytes
- telemetry_data = data.decode()
- print(f"Raw data from {addr}: {telemetry_data}")
- parsed_data = parse_telemetry(telemetry_data)
- if parsed_data:
- send_motion_data('192.168.0.101', 50010, parsed_data['yaw'], parsed_data['pitch'], parsed_data['roll'])
- except Exception as e:
- print(f"Listener error: {e}")
- finally:
- sock.close()
- def parse_telemetry(data):
- """ Parses telemetry data to extract needed values. """
- try:
- parts = data.split(';')
- if len(parts) >= 14:
- roll = float(parts[0])
- pitch = float(parts[1])
- yaw = float(parts[2])
- return {'yaw': yaw, 'pitch': pitch, 'roll': roll}
- except ValueError:
- return "Error parsing data"
- return "Incomplete data"
- def send_motion_data(udp_ip, udp_port, yaw, pitch, roll):
- """ Sends formatted motion data to the Yaw VR device. """
- with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as udp_sock:
- motion_data = f"Y[{yaw}]P[{pitch}]R[{roll}]".encode('ascii')
- udp_sock.sendto(motion_data, (udp_ip, udp_port))
- print(f"Sent to Yaw Device: Y[{yaw}]P[{pitch}]R[{roll}]")
- def main():
- telemetry_port = 4123 # Port where Overload sends telemetry
- yaw_device_ip = '192.168.0.101' # YAW emulator IP
- yaw_device_udp_port = 50010 # UDP port for sending motion data
- yaw_device_tcp_port = 50020 # TCP port for check-in command
- # Send TCP check-in command
- send_tcp_check_in(yaw_device_ip, yaw_device_tcp_port, telemetry_port, "OverloadSim")
- # Start the telemetry listener in a separate thread
- listener_thread = threading.Thread(target=telemetry_listener, args=(telemetry_port,))
- listener_thread.start()
- try:
- listener_thread.join() # Wait for the listener thread to end, which it won't unless there's an error
- except KeyboardInterrupt:
- print("Stopping data forwarding.")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement