-
Notifications
You must be signed in to change notification settings - Fork 37
Using message_encode_decode to send MAVlink messages #245
Changes from 4 commits
009e142
255b589
57455b2
996a86c
38a7bf3
0268fa1
e556f56
dc4e8c5
530b8fd
6ba167f
e5a8e4a
3160476
3a1d5b7
76a742e
396417d
121e82e
bf06786
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| from . import communications | ||
| from utilities.workers import queue_proxy_wrapper | ||
| from utilities.workers import worker_controller | ||
| from ..common.modules.data_encoding import metadata_encoding_decoding | ||
| from ..common.modules.logger import logger | ||
|
|
||
|
|
||
|
|
@@ -49,7 +50,7 @@ def communications_worker( | |
|
|
||
| local_logger.info(f"Home position received: {home_position}", True) | ||
|
|
||
| result, comm = communications.Communications.create(home_position, local_logger) | ||
| result, comm = communications.Communications.create(home_position, local_logger, worker_name) | ||
| if not result: | ||
| local_logger.error("Worker failed to create class object", True) | ||
| return | ||
|
|
@@ -79,8 +80,18 @@ def communications_worker( | |
| if is_invalid: | ||
| continue | ||
|
|
||
| result, value = comm.run(input_data) | ||
| result, list_of_messages = comm.run(input_data) | ||
| if not result: | ||
| continue | ||
|
|
||
| output_queue.queue.put(value) | ||
| result, metadata = metadata_encoding_decoding.encode_metadata( | ||
| f"{worker_name}", len(list_of_messages) | ||
|
||
| ) | ||
| if not result: | ||
| local_logger.error("Failed to encode metadata", True) | ||
| continue | ||
|
|
||
| output_queue.queue.put(metadata) | ||
maxlou05 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| for message in list_of_messages: | ||
| output_queue.queue.put(message) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,7 +73,7 @@ def get_home_position(self) -> position_global.PositionGlobal: | |
| """ | ||
| return self.__home_position | ||
|
|
||
| def run(self) -> "tuple[bool, odometry_and_time.OdometryAndTime | None]": | ||
| def run(self, message: bytes) -> "tuple[bool, odometry_and_time.OdometryAndTime | None]": | ||
| """ | ||
| Returns a possible OdometryAndTime with current timestamp. | ||
| """ | ||
|
|
@@ -103,6 +103,11 @@ def run(self) -> "tuple[bool, odometry_and_time.OdometryAndTime | None]": | |
|
|
||
| self.__logger.info(str(odometry_and_time_object), True) | ||
|
|
||
| result = self.controller.send_statustext_msg(message) | ||
| if not result: | ||
| self.__logger.error("Failed to send statustext message", True) | ||
| return False, None | ||
|
||
|
|
||
| return True, odometry_and_time_object | ||
|
|
||
| def apply_decision(self, cmd: decision_command.DecisionCommand) -> bool: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,14 +20,17 @@ def flight_interface_worker( | |
| input_queue: queue_proxy_wrapper.QueueProxyWrapper, | ||
| output_queue: queue_proxy_wrapper.QueueProxyWrapper, | ||
| communications_output_queue: queue_proxy_wrapper.QueueProxyWrapper, | ||
| coordinates_input_queue: queue_proxy_wrapper.QueueProxyWrapper, | ||
| controller: worker_controller.WorkerController, | ||
| ) -> None: | ||
| """ | ||
| Worker process. | ||
|
|
||
| address, timeout is initial setting. | ||
| period is minimum period between loops. | ||
| output_queue is the data queue. | ||
| input_queue and output_queue are the data queues. | ||
| communications_output_queue is a one time queue that sends communications worker the home address. | ||
| coordinates_input_queue provides the flight interface worker with a list of GPS coordinates. | ||
| controller is how the main process communicates to this worker process. | ||
| """ | ||
| # TODO: Error handling | ||
|
|
@@ -62,7 +65,16 @@ def flight_interface_worker( | |
|
|
||
| time.sleep(period) | ||
|
|
||
| result, value = interface.run() | ||
| coordinate = coordinates_input_queue.queue.get() | ||
|
||
| if coordinate is None: | ||
| local_logger.info("Received type None, exiting") | ||
| break | ||
|
||
|
|
||
| if not isinstance(coordinate, bytes): | ||
| local_logger.warning(f"Skipping unexpected input: {coordinate}") | ||
| continue | ||
|
|
||
| result, value = interface.run(coordinate) | ||
| if not result: | ||
| continue | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add this queue to communication's output queue