Note: I am by no means a coder, but this is just a task I have been assigned. Any help is greatly appreciated. The software outputting on port 2000 is a flight simulator, which automatically outputs flight data in some sort of encoding. The code I am using to receive the data is in Python.
import socket
import logging
import os
def portLogger(port):
# Configure logging
logging.basicConfig(filename=f'LOGS\\test_from_port_{port}.txt', level=logging.INFO, format='%(message)s')
# Specify the host and port to connect to
host = 'localhost' # Change this to the appropriate host
# Create a socket object
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Connect to the server
client_socket.connect((host, port))
# Receive data from the server and log it
while True:
data = client_socket.recv(1024) # Adjust the buffer size as needed
if not data:
break
decoded_data = data
logging.info(decoded_data)
print(decoded_data)
# Close the socket
client_socket.close()
if __name__ == '__main__':
port = input('Enter port number: ')
portLogger(int(port))
An example of data that I receive is as follows: b'Z\xa5\xff\xfe\x13\x83\x00\x00\x00\x00\x03\x00\xe6\x8b\x00\x00\x00\x00\x00\x00\x00\x00\xbf\x16\x08\xab\xc1;\xff\xb1\x00\x1e\xff\xd3\x00K\x00\x00\xf8G\xf8\x16\xfab\x0f\xf9g\xd4\x00\n\x00\x19\xff\xf4\x02X\x008\x00\x08\x00\x00\x00\x07H\xd5\x00\x00d\x01\xe4\x80\xf1"\xa0\x05Ef\xfe\x07\xa0O\x00\x14d\xf1\x07\x13\x7f'\xe7z\xfd]\x01\xdc\xee\x00!J\x00\x00\x00\x01\x00\x02\xe0\x00\t\x01\x0f\x0f\x12\xfa\x00\x12\x01\x95g\xc2\x07\x90\x00\x00\x00\x00\x00\x00\x00\x00\xbf\x16\x08\x8e\xc1=\x00$\x00\x1b\xff\xd3\x00R\xff\xfc\xf8J\xf8\x14\xfac\x0f\xf9g\xde\x00\n\x00\x19\xff\xf4\x02X\x008\x00\x04\x00\x00\x00\x07H\xd5\x00\x00d\x01\xe4~/\x86\xa0\x05\x1d#\x00\x02\x00\x08\x00!J\xe0\x00\xfc\x00\x10\x0c\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x16\xa8\x06\x01\x00\x00d\xe2\xa0\x05Ef\xfe\x07\xa0O\x00\x14e\xb9\x07\x13\x7f'\xe7z\xfd]\x01\xd8\t'
and
b"Z\xa5\xff\xfe\x13\x83\x00\x00\x00\x00\x03\x00\xe6\x8b\xdc\xed\x00!J\x00\x00\x00\x02\x00\x02\xe0\x00\t\x01\x0f\x0f\x13\xc2\x00\x1a\x01\x96g\xc9\x07\x91\x00\x00\x00\x00\x00\x00\x00\x00\xbf\x16\x08\xbd\xc19\xff\xd2\x00\x0e\x00\x17\x00Q\xff\xf2\xf8J\xf8\x17\xfac\x0f\xf7g\xd4\x00\n\x00 \xff\xfa\x02X\x00C\x00\x04\x00\x00\x00\x0fH\xd5\x00\x00d\x01\xe4}0\xa8\xa0\x05Ef\xfe\x07\xa0O\x00\x14f\x81\x07\x13\x7f'\xe7z\xfd^\x01\xdc\xed\x00!J\x00\x01\x00\x04\x00\x02\xe0\x00\t\x01\x0f\x0f\x14\x8a\x00\x13\x01\x93g\xc7\x07\x93\x00\x00\x00\x00\x00\x00\x00\x00\xbf\x16\x08\x98\xc1:\xff\xdc\xff\xf9\xff\xf1\x00J\xff\xf7\xf8H\xf8\x10\xfaj\x0f\xf9h\n\x00\n\x00\x19\xff\xf4\x02X\x008\x00\x04\x00\x00\x00\x07H\xd5\x00\x00d\x01\xe4\x80\xff\xd7\xa0\x05Ef\xfe\x07\xa0O\x00\x14gI\x07\x13\x7f'\xe7z\xfd^\x01\xdc\xed\x00!J\x00\x03\x00\x04\x00\x02\xe0\x00\t\xba\xf4"
I have tried various methods of decoding, such as UTF-8, ASCII, and Latin-1, but I have no idea how to turn this data into usable data. It is supposed to give telemetry data from the software, such as latitude, longitude, Airspeed, and various other data values. An example of what I would like to receive is something along the lines of this:
5987161 2024 3 21 19 53 9.09 0.5755009939 -1.9944146531 218.100000 1.470000 2.160000 0.050000 2.612757 0.973240 0XE000 11.690000 0.278000 4.960000 0.120000 0 0 0 0 0 42.000000 213.119995 0.360997 28.000000 99334.000000 0.075031 0.069200 0.053800 0.022800 -0.105000 0.445000 -9.974999 0.002300 0.077800 0.871500 0.860900 0.150000 2368 0 136.500000 1026.000000 0.000000 0.000000 100 -59 0.002500 -0.002500 0.062300 0.106500 0.000800 0.403100 0.050700 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.009000 0.012000 0.002000 0.000000 0.000000 -0.150000 174.199997 -166.800003 396.399994 OFF 3 0 1.00 ON 92 0 AUTO 29.003012 AUTO 519.000000 AUTO 0.000000 AUTO 0.174533 AUTO -0.103410 AUTO -0.257222 AUTO 0.000000 OFF 0.000000 B 27757.049634 415.058652 1310.869939 2.301440 -1.236936 -0.048633 1.000000 4666.632324 3903.174316 3477.648438 GPSINS 1 1 1 1 1 1 1 1 1 1 1 1 2306 417189091 NA NA NA NA NA NA NA NA NA NA NA NA 0.0000000000 0.0000000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0X6008 -54 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 0x0 100.0 16.6 100.0 16.8
Please let me know if you could help or if you need more information to help me out. Really appreciate it!