Skip to content
This repository was archived by the owner on Nov 13, 2025. It is now read-only.

Commit 7070a1e

Browse files
committed
moved metadata encoding to run()
1 parent f056b62 commit 7070a1e

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

modules/communications/communications.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from ..common.modules import position_local
1010
from ..common.modules.logger import logger
1111
from ..common.modules.data_encoding import message_encoding_decoding
12+
from ..common.modules.data_encoding import metadata_encoding_decoding
1213
from ..common.modules.data_encoding import worker_enum
1314
from ..common.modules.mavlink import local_global_conversion
1415

@@ -53,7 +54,7 @@ def __init__(
5354
def run(
5455
self,
5556
objects_in_world: list[object_in_world.ObjectInWorld],
56-
) -> tuple[True, list[bytes]] | tuple[False, None]:
57+
) -> tuple[True, list[bytes], bytes] | tuple[False, None, None]:
5758

5859
objects_in_world_global = []
5960
for object_in_world in objects_in_world:
@@ -71,7 +72,7 @@ def run(
7172
self.__logger.warning(
7273
f"Could not convert ObjectInWorld to PositionLocal:\nobject in world: {object_in_world}"
7374
)
74-
return False, None
75+
return False, None, None
7576

7677
result, object_in_world_global = (
7778
local_global_conversion.position_global_from_position_local(
@@ -83,7 +84,7 @@ def run(
8384
self.__logger.warning(
8485
f"position_global_from_position_local conversion failed:\nhome_position: {self.__home_position}\nobject_position_local: {object_position_local}"
8586
)
86-
return False, None
87+
return False, None, None
8788

8889
objects_in_world_global.append(object_in_world_global)
8990

@@ -97,8 +98,15 @@ def run(
9798
)
9899
if not result:
99100
self.__logger.warning("Conversion from PositionGlobal to bytes failed", True)
100-
return False, None
101+
return False, None, None
101102

102103
encoded_position_global_objects.append(message)
103104

104-
return True, encoded_position_global_objects
105+
result, metadata = metadata_encoding_decoding.encode_metadata(
106+
worker_enum.WorkerEnum.COMMUNICATIONS_WORKER, len(encoded_position_global_objects)
107+
)
108+
if not result:
109+
self.__logger.error("Failed to encode metadata", True)
110+
return False, None, None
111+
112+
return True, encoded_position_global_objects, metadata

modules/communications/communications_worker.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,10 @@ def communications_worker(
8484
if is_invalid:
8585
continue
8686

87-
result, list_of_messages = comm.run(input_data)
87+
result, list_of_messages, metadata = comm.run(input_data)
8888
if not result:
8989
continue
9090

91-
result, metadata = metadata_encoding_decoding.encode_metadata(
92-
worker_enum.WorkerEnum.COMMUNICATIONS_WORKER, len(list_of_messages)
93-
)
94-
if not result:
95-
local_logger.error("Failed to encode metadata", True)
96-
continue
97-
9891
output_queue.queue.put(metadata)
9992
message_output_queue.queue.put(metadata)
10093

modules/flight_interface/flight_interface.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def get_home_position(self) -> position_global.PositionGlobal:
7373
"""
7474
return self.__home_position
7575

76-
def run(self, message: bytes) -> "tuple[bool, odometry_and_time.OdometryAndTime | None]":
76+
def run(self, message: bytes | None) -> "tuple[bool, odometry_and_time.OdometryAndTime | None]":
7777
"""
7878
Returns a possible OdometryAndTime with current timestamp.
7979
"""
@@ -103,7 +103,8 @@ def run(self, message: bytes) -> "tuple[bool, odometry_and_time.OdometryAndTime
103103

104104
self.__logger.info(str(odometry_and_time_object), True)
105105

106-
self.controller.send_statustext_msg(message)
106+
if message:
107+
self.controller.send_statustext_msg(message)
107108

108109
return True, odometry_and_time_object
109110

0 commit comments

Comments
 (0)