diff --git a/mainwindow.py b/mainwindow.py index 1eabcd0..37301f5 100644 --- a/mainwindow.py +++ b/mainwindow.py @@ -8,7 +8,7 @@ from typing import Tuple, Optional import matplotlib import matplotlib.pyplot as plt from PyQt5.QtCore import QTimer -from PyQt5.QtWidgets import QFrame, QStatusBar, QSizePolicy, QFileDialog +from PyQt5.QtWidgets import QFrame, QStatusBar, QSizePolicy, QFileDialog, QApplication, QMainWindow, QWidget from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas, NavigationToolbar2QT from scipy.fft import fft, fftfreq @@ -189,7 +189,7 @@ class SocketClientApp(QMainWindow): self.ipv4_config_button.setEnabled(False) self.calibration_config_button.setEnabled(False) self.get_version_button.setEnabled(False) - self.ip_input.setText("192.168.0.199") + self.ip_input.setText("192.168.0.191") self.port_input.setText("12345") # 预留绘图区域 @@ -470,7 +470,7 @@ class SocketClientApp(QMainWindow): end_time = time.time() execution_time = end_time - self.start_time print(f"结束时间戳: {end_time}") - print(f"代码执行时间: {execution_time} 秒") + print(f"代码执行时间: {round(execution_time, 3)} 秒") print(f"speed :{round((self.sampling_rate * 4 * 8) / execution_time, 3)} Kbps") self.process_wave_packet(bytes(self.partial_data)) self.recv_state = 'WAIT_HEADER' @@ -534,8 +534,8 @@ class SocketClientApp(QMainWindow): def process_wave_packet(self, wave_data): data = wave_data # 接收所有数据 data = np.frombuffer(data, dtype=np.int32) # 根据实际数据格式转换 - for i in range(min(100, len(data))): # 确保不超过数据长度 - print(f"{data[i]:1f}", end=" ") + for i in range(min(5, len(data))): # 确保不超过数据长度 + print(f"{data[i]:.3f}", end=" ") print() # 换行 LSB_32BIT = (2.8 / (2 ** 31)) * ((750 + 287) / 287) * 1000 / 10.2 # LSB_32BIT = (2.8 / (2 ** 31)) * ((750 + 287) / 287) * 1000 @@ -561,16 +561,16 @@ class SocketClientApp(QMainWindow): # 速度有效值 speed_rms_value = calc_vel_pass_rms(self.scaled_data, self.sampling_rate) - print("速度有效值:", speed_rms_value) + print("速度有效值:", round(speed_rms_value, 1)) # 速度峰值 speed_vel_p = calc_vel_p(self.scaled_data, self.sampling_rate) - print("速度峰值:", speed_vel_p) + print("速度峰值:", round(speed_vel_p, 1)) # 加速度有效值 acc_rms = calc_acc_rms(self.scaled_data, self.sampling_rate) - print("加速度有效值:", acc_rms) + print("加速度有效值:", round(acc_rms, 1)) # 加速度峰值 acc_p = calc_acc_p(self.scaled_data, self.sampling_rate) - print("加速度峰值:", acc_p) + print("加速度峰值:", round(acc_p, 1)) self.acceleration_label_rms.setText(f"加速度有效值:{round(acc_rms, 3)} m/s^2") self.acceleration_label_pp.setText(f"加速度峰值:{round(acc_p, 3)} m/s^2") self.velocity_label_rms.setText(f"速度有效值:{round(speed_rms_value, 3)} mm/s") @@ -657,7 +657,23 @@ class SocketClientApp(QMainWindow): print(f"Upgrade length: {upgrade_len}, CRC: {crc}") print(f"Total packet size: {len(full_packet)} bytes") - self.socket.write(full_packet) + # 分包处理:每包最大1500字节 + max_packet_size = 1500 + total_size = len(full_packet) + num_packets = (total_size // max_packet_size) + (1 if total_size % max_packet_size != 0 else 0) + + print(f"Total packets: {num_packets}, each up to {max_packet_size} bytes") + + # 分包并发送 + for i in range(num_packets): + start_index = i * max_packet_size + end_index = min((i + 1) * max_packet_size, total_size) + packet_chunk = full_packet[start_index:end_index] + + print(f"Sending packet {i + 1}/{num_packets}, size: {len(packet_chunk)} bytes") + self.socket.write(packet_chunk) + print(f"Packet {i + 1} sent successfully") + time.sleep(0.05) print("Upgrade packet ready to send (commented out actual send code)") except Exception as e: print(f"Upgrade failed: {str(e)}")