update gui
This commit is contained in:
@@ -397,6 +397,12 @@ class DroneMonitor(Node):
|
||||
# ================================================================================
|
||||
self.drone_gps = {} # {drone_id: {'lat': ..., 'lon': ..., 'alt': ...}}
|
||||
# ================================================================================
|
||||
|
||||
# ================================================================================
|
||||
# 【新增】儲存 sys_id 到 actual_drone_id 的映射 (從 summary 獲取)
|
||||
# ================================================================================
|
||||
self.sys_to_actual_id = {} # {sys_id: actual_drone_id} e.g. {'sys11': 's0_11'}
|
||||
# ================================================================================
|
||||
self.serial_receivers = []
|
||||
|
||||
# 主题检测定时器
|
||||
@@ -553,7 +559,13 @@ class DroneMonitor(Node):
|
||||
}
|
||||
|
||||
def battery_callback(self, drone_id, msg):
|
||||
self.latest_data[(drone_id, 'battery')] = {
|
||||
# 使用映射獲取實際的 drone_id
|
||||
actual_drone_id = self.sys_to_actual_id.get(drone_id, None)
|
||||
# 如果還沒有從 summary 獲取到映射,則不處理
|
||||
if actual_drone_id is None:
|
||||
return
|
||||
|
||||
self.latest_data[(actual_drone_id, 'battery')] = {
|
||||
'voltage': msg.voltage
|
||||
}
|
||||
|
||||
@@ -580,6 +592,15 @@ class DroneMonitor(Node):
|
||||
if socket_id is not None and sysid is not None:
|
||||
# 使用 socket_id 作為前綴
|
||||
actual_drone_id = f's{socket_id}_{sysid}'
|
||||
|
||||
# ================================================================================
|
||||
# 【關鍵】保存 sys_id 到 actual_drone_id 的映射
|
||||
# ================================================================================
|
||||
sys_key = f'sys{sysid}'
|
||||
self.sys_to_actual_id[sys_key] = actual_drone_id
|
||||
# 也保存原始的 s0_ 格式到實際 ID 的映射
|
||||
self.sys_to_actual_id[drone_id] = actual_drone_id
|
||||
# ================================================================================
|
||||
else:
|
||||
actual_drone_id = drone_id
|
||||
|
||||
@@ -600,7 +621,13 @@ class DroneMonitor(Node):
|
||||
print(f"Error in summary_callback for {drone_id}: {e}")
|
||||
|
||||
def gps_callback(self, drone_id, msg):
|
||||
self.latest_data[(drone_id, 'gps')] = {
|
||||
# 使用映射獲取實際的 drone_id
|
||||
actual_drone_id = self.sys_to_actual_id.get(drone_id, None)
|
||||
# 如果還沒有從 summary 獲取到映射,則不處理
|
||||
if actual_drone_id is None:
|
||||
return
|
||||
|
||||
self.latest_data[(actual_drone_id, 'gps')] = {
|
||||
'lat': msg.latitude,
|
||||
'lon': msg.longitude,
|
||||
'alt': msg.altitude
|
||||
@@ -609,7 +636,7 @@ class DroneMonitor(Node):
|
||||
# ================================================================================
|
||||
# 【新增】儲存 GPS 資料到 drone_gps 字典
|
||||
# ================================================================================
|
||||
self.drone_gps[drone_id] = {
|
||||
self.drone_gps[actual_drone_id] = {
|
||||
'lat': msg.latitude,
|
||||
'lon': msg.longitude,
|
||||
'alt': msg.altitude
|
||||
@@ -636,7 +663,13 @@ class DroneMonitor(Node):
|
||||
}
|
||||
|
||||
def hud_callback(self, drone_id, msg):
|
||||
self.latest_data[(drone_id, 'hud')] = {
|
||||
# 使用映射獲取實際的 drone_id
|
||||
actual_drone_id = self.sys_to_actual_id.get(drone_id, None)
|
||||
# 如果還沒有從 summary 獲取到映射,則不處理
|
||||
if actual_drone_id is None:
|
||||
return
|
||||
|
||||
self.latest_data[(actual_drone_id, 'hud')] = {
|
||||
'airspeed': msg.airspeed,
|
||||
'groundspeed': msg.groundspeed,
|
||||
'heading': msg.heading,
|
||||
|
||||
Reference in New Issue
Block a user