我电脑上的模拟软件通过2000端口传输数据,如何将原始数据转换为可用数据?
注意:我并不是程序员,只是被分配了这个任务。任何帮助都非常感谢。
这个在2000端口输出数据的软件是一个飞行模拟器,它会自动以某种编码输出飞行数据。
我用来接收数据的代码是用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))
我收到的数据示例如下:
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'
还有
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"
我尝试了多种解码方法,比如UTF-8、ASCII和Latin-1,但我不知道如何将这些数据转换成可用的数据。它应该提供来自软件的遥测数据,比如纬度、经度、空速和其他各种数据值。我希望收到的数据示例如下:
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
如果你能帮忙或者需要更多信息来帮助我,请告诉我。真的非常感谢!
0 个回答
暂无回答