From 85704aead255357463df478780d04e7dbc19d646 Mon Sep 17 00:00:00 2001 From: STT <8894457+sttdo@user.noreply.gitee.com> Date: Wed, 1 Dec 2021 10:25:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=AE=80=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: STT --- ground_control_station.py | 116 +++++++++++++------------------------- 1 file changed, 39 insertions(+), 77 deletions(-) diff --git a/ground_control_station.py b/ground_control_station.py index 907a2fa..a814b1a 100644 --- a/ground_control_station.py +++ b/ground_control_station.py @@ -4,8 +4,6 @@ import struct from PySide2.QtGui import QPolygon import socket -from SelfBuiltModul.func import to_signed_number - class GroundControlStation: def __init__(self, com): @@ -14,7 +12,6 @@ class GroundControlStation: 'desired_latitude': 0.0, 'desired_longitude': 0.0, 'rudder': 0, 'thrust': 0, 'ignition': 0, 'buffer_err': 0} self.gcs = serial.Serial(com, 57600, timeout=0, write_timeout=0) - self.buffer = [] self.errors = 0 @@ -32,6 +29,7 @@ class GroundControlStation: packet_data_length = self.buffer[2] packet_length = packet_data_length + 5 + if len(self.buffer) < packet_length: break if (self.buffer[3] | self.buffer[4] << 8) != calculate_crc16_ccitt(self.buffer[5:], packet_data_length): @@ -43,55 +41,44 @@ class GroundControlStation: packet_data = self.buffer[5:packet_length] if packet_id == 0 and packet_data_length == 8: # 心跳包 - print('心跳包'+str(time.time())) + print('心跳包' + str(time.time())) self.heart_beat['timestamp'] = time.time() self.heart_beat['buffer_err'] = self.errors del self.buffer[:packet_length] continue + elif (packet_data[0] | packet_data[1] << 8) != usv.control.pid['id']: # 数据过滤 print('数据过滤') del self.buffer[:packet_length] continue + elif packet_id == 1 and packet_data_length == 40: # Command print('命令包') + command = struct.unpack('