Serial Communication Module
SerialCommunication
Bases: SerialCommunicationABC
, LoggerConsumerProtocol
Class to handle the serial communication through USB.
Source code in devices\raspberry_pi_5\src\serial_communication\__init__.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
|
__del__()
Destructor to clean up resources when the SerialCommunication instance is deleted.
Source code in devices\raspberry_pi_5\src\serial_communication\__init__.py
141 142 143 144 145 146 147 148 149 150 |
|
__init__(debug, challenge, start_event, stop_event, bno08x_yaw_deg, bno08x_turns, sender_messages_queue, writer_messages_queue, server_messages_queue=None, console_ports=RASPBERRY_PI_PICO_CONSOLE_PORTS, data_ports=RASPBERRY_PI_PICO_DATA_PORTS, baudrate=RASPBERRY_PI_PICO_BAUDRATE)
Initialize the serial communication class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
debug
|
bool
|
Flag to indicate if the receiver is in debug mode. |
required |
challenge
|
Value
|
Shared value to hold the current challenge. |
required |
start_event
|
Event
|
Event to signal when the serial communication has started. |
required |
stop_event
|
Event
|
Event to signal when the serial communication should stop sending and receiving messages. |
required |
bno08x_yaw_deg
|
Value
|
Shared value for the BNO08X yaw angle in degrees. |
required |
bno08x_turns
|
Value
|
Shared value for the BNO08X turns. |
required |
sender_messages_queue
|
Queue
|
Queue to hold outgoing messages of the serial port. |
required |
writer_messages_queue
|
Queue
|
Queue to hold log messages. |
required |
server_messages_queue
|
Optional[Queue]
|
Queue to broadcast the messages through the websockets server. |
None
|
console_ports
|
Optional[List[str]]
|
List of serial ports used for receiving data from Pico. |
RASPBERRY_PI_PICO_CONSOLE_PORTS
|
data_ports
|
Optional[List[str]]
|
List of serial ports used for sending data to Pico. |
RASPBERRY_PI_PICO_DATA_PORTS
|
baudrate
|
Optional[int]
|
Baud rate for the serial communication. |
RASPBERRY_PI_PICO_BAUDRATE
|
Source code in devices\raspberry_pi_5\src\serial_communication\__init__.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
|
abstracts
DispatcherABC
Abstract class for a dispatcher that handles incoming and outgoing messages.
Source code in devices\raspberry_pi_5\src\serial_communication\abstracts.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
|
send_confirmation_message()
abstractmethod
Send a confirmation message to the serial port.
Source code in devices\raspberry_pi_5\src\serial_communication\abstracts.py
182 183 184 185 186 187 |
|
send_motor_speed_message(speed)
abstractmethod
Send the motor speed to the serial port.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
speed
|
float
|
The speed of the motor. |
required |
Source code in devices\raspberry_pi_5\src\serial_communication\abstracts.py
162 163 164 165 166 167 168 169 170 |
|
send_servo_angle_message(angle)
abstractmethod
Send the servo angle to the serial port.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
angle
|
float
|
The angle of the servo. |
required |
Source code in devices\raspberry_pi_5\src\serial_communication\abstracts.py
172 173 174 175 176 177 178 179 180 |
|
send_stop_message()
abstractmethod
Send a stop message to the serial port.
Source code in devices\raspberry_pi_5\src\serial_communication\abstracts.py
189 190 191 192 193 194 |
|
ReceiverABC
Bases: ABC
Receiver abstract class to handle serial communication with the Raspberry Pi Pico.
Source code in devices\raspberry_pi_5\src\serial_communication\abstracts.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
logger()
abstractmethod
Get the logger instance for the Receiver.
Returns:
Name | Type | Description |
---|---|---|
Logger |
Logger
|
The logger instance. |
Source code in devices\raspberry_pi_5\src\serial_communication\abstracts.py
35 36 37 38 39 40 41 42 43 |
|
run()
abstractmethod
Handler to receive messages from the serial port.
Raises:
Type | Description |
---|---|
RuntimeError
|
If an error message is received or if the confirmation message is not received within a timeout. |
Source code in devices\raspberry_pi_5\src\serial_communication\abstracts.py
84 85 86 87 88 89 90 91 92 |
|
SenderABC
Bases: ABC
Sender abstract class to handle sending messages through serial communication.
Source code in devices\raspberry_pi_5\src\serial_communication\abstracts.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
logger()
abstractmethod
Get the logger instance for the Sender.
Returns:
Name | Type | Description |
---|---|---|
Logger |
Logger
|
The logger instance. |
Source code in devices\raspberry_pi_5\src\serial_communication\abstracts.py
100 101 102 103 104 105 106 107 108 |
|
run()
abstractmethod
Handler to send messages to the serial port.
Raises:
Type | Description |
---|---|
RuntimeError
|
If an error occurs while sending a message or if the confirmation message is not received within a timeout. |
Source code in devices\raspberry_pi_5\src\serial_communication\abstracts.py
136 137 138 139 140 141 142 143 144 |
|
SerialCommunicationABC
Bases: ABC
Abstract class to handle the serial communication through USB.
Source code in devices\raspberry_pi_5\src\serial_communication\abstracts.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
logger()
abstractmethod
Get the logger instance for the SerialCommunication.
Returns:
Name | Type | Description |
---|---|---|
Logger |
Logger
|
The logger instance. |
Source code in devices\raspberry_pi_5\src\serial_communication\abstracts.py
12 13 14 15 16 17 18 19 20 |
|
run()
abstractmethod
Run the serial communication by creating threads for receiving and sending messages.
Source code in devices\raspberry_pi_5\src\serial_communication\abstracts.py
22 23 24 25 26 27 |
|
dispatcher
Dispatcher
Bases: DispatcherABC
Class for a dispatcher that handles incoming and outgoing messages.
Source code in devices\raspberry_pi_5\src\serial_communication\dispatcher.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
__init__(serial_messages_queue)
Initializes the Dispatcher class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
serial_messages_queue
|
Queue
|
Queue to hold outgoing messages to the serial port. |
required |
Source code in devices\raspberry_pi_5\src\serial_communication\dispatcher.py
16 17 18 19 20 21 22 23 24 25 26 27 |
|
enums
IncomingCategory
Bases: Enum
Enum to represent the categories of incoming messages from the Raspberry Pi Pico 2W.
Source code in devices\raspberry_pi_5\src\serial_communication\enums.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
parsed_name
property
Get the category name in lowercase.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The category name in lowercase. |
from_string(category_str)
classmethod
Convert a string to an IncomingCategory enum value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
category_str
|
str
|
The string representation of the incoming category. |
required |
Returns:
IncomingCategory: The corresponding IncomingCategory enum value.
Source code in devices\raspberry_pi_5\src\serial_communication\enums.py
28 29 30 31 32 33 34 35 36 37 38 |
|
OutgoingCategory
Bases: Enum
Enum to represent the categories of outgoing messages sent to the Raspberry Pi Pico 2W.
Source code in devices\raspberry_pi_5\src\serial_communication\enums.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
parsed_name
property
Get the category name in lowercase.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The category name in lowercase. |
from_string(category_str)
classmethod
Convert a string to an OutgoingCategory enum value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
category_str
|
str
|
The string representation of the outgoing category. |
required |
Returns:
OutgoingCategory: The corresponding OutgoingCategory enum value.
Source code in devices\raspberry_pi_5\src\serial_communication\enums.py
93 94 95 96 97 98 99 100 101 102 103 |
|
Status
Bases: Enum
Enum to represent the status messages sent and received from the Raspberry Pi Pico 2W.
Source code in devices\raspberry_pi_5\src\serial_communication\enums.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
parsed_name
property
Get the status name in lowercase.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The status name in lowercase. |
from_string(status_str)
classmethod
Convert a string to a Status enum value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
status_str
|
str
|
The string representation of the status. |
required |
Returns:
Status: The corresponding Status enum value.
Source code in devices\raspberry_pi_5\src\serial_communication\enums.py
61 62 63 64 65 66 67 68 69 70 71 |
|
message
IncomingMessage
Class to handle the messages received from the Raspberry Pi Pico 2W.
Source code in devices\raspberry_pi_5\src\serial_communication\message.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
|
category
property
writable
Property to get the message category.
Returns:
Name | Type | Description |
---|---|---|
IncomingCategory |
IncomingCategory
|
The category of the message. |
content
property
writable
Get the message content.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The content of the message. |
__eq__(other)
Check equality of two IncomingMessage objects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
IncomingMessage
|
The other IncomingMessage object to compare with. |
required |
Returns:
bool: True if both messages have the same category and content, False otherwise.
Source code in devices\raspberry_pi_5\src\serial_communication\message.py
28 29 30 31 32 33 34 35 36 37 |
|
__init__(category, content)
Initialize the incoming message class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
category
|
IncomingCategory
|
The category of the message. |
required |
content
|
str
|
The content of the message. |
required |
Source code in devices\raspberry_pi_5\src\serial_communication\message.py
11 12 13 14 15 16 17 18 19 20 |
|
__str__()
String representation of the message.
Source code in devices\raspberry_pi_5\src\serial_communication\message.py
22 23 24 25 26 |
|
from_string(msg_str)
staticmethod
Create a Message object from a string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msg_str
|
str
|
The string representation of the message. |
required |
Returns:
Message: The Message object created from the string.
Raises:
ValueError: If the string does not match the expected format.
Source code in devices\raspberry_pi_5\src\serial_communication\message.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
is_bno08x_turns()
Check if the message is a BNO08X turns message.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the message is a BNO08X turns message, False otherwise. |
Source code in devices\raspberry_pi_5\src\serial_communication\message.py
161 162 163 164 165 166 167 168 |
|
is_bno08x_yaw_deg()
Check if the message is a BNO08X yaw degrees message.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the message is a BNO08X yaw degrees message, False otherwise. |
Source code in devices\raspberry_pi_5\src\serial_communication\message.py
152 153 154 155 156 157 158 159 |
|
is_challenge()
Check if the message is a challenge message.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the message is a challenge message, False otherwise. |
Source code in devices\raspberry_pi_5\src\serial_communication\message.py
125 126 127 128 129 130 131 132 |
|
is_confirmation()
Check if the message is a confirmation message.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the message is a confirmation message, False otherwise. |
Source code in devices\raspberry_pi_5\src\serial_communication\message.py
143 144 145 146 147 148 149 150 |
|
is_debug()
Check if the message is a debug message.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the message is a debug message, False otherwise. |
Source code in devices\raspberry_pi_5\src\serial_communication\message.py
170 171 172 173 174 175 176 177 |
|
is_error()
Check if the message is an error message.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the message is an error message, False otherwise. |
Source code in devices\raspberry_pi_5\src\serial_communication\message.py
134 135 136 137 138 139 140 141 |
|
is_start()
Check if the message is a start message.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the message is a start message, False otherwise. |
Source code in devices\raspberry_pi_5\src\serial_communication\message.py
116 117 118 119 120 121 122 123 |
|
OutgoingMessage
Class to handle the messages sent to the Raspberry Pi Pico 2W.
Source code in devices\raspberry_pi_5\src\serial_communication\message.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
|
category
property
writable
Property to get the message category.
Returns:
Name | Type | Description |
---|---|---|
OutgoingCategory |
OutgoingCategory
|
The category of the message. |
content
property
writable
Get the message content.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The content of the message. |
__eq__(other)
Check equality of two OutgoingMessage objects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
OutgoingMessage
|
The other OutgoingMessage object to compare with. |
required |
Returns:
bool: True if both messages have the same category and content, False otherwise.
Source code in devices\raspberry_pi_5\src\serial_communication\message.py
202 203 204 205 206 207 208 209 210 211 |
|
__init__(category, content)
Initialize the outgoing message class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
category
|
OutgoingCategory
|
The category of the message. |
required |
content
|
str
|
The content of the message. |
required |
Source code in devices\raspberry_pi_5\src\serial_communication\message.py
185 186 187 188 189 190 191 192 193 194 |
|
__str__()
String representation of the message.
Source code in devices\raspberry_pi_5\src\serial_communication\message.py
196 197 198 199 200 |
|
from_string(msg_str)
staticmethod
Create a Message object from a string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msg_str
|
str
|
The string representation of the message. |
required |
Returns:
Message: The Message object created from the string.
Source code in devices\raspberry_pi_5\src\serial_communication\message.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
|
multiprocessing
serial_communication_target(debug, challenge, start_event, stop_event, bno08x_yaw_deg, bno08x_turns, sender_messages_queue, writer_messages_queue, server_messages_queue=None, console_ports=RASPBERRY_PI_PICO_CONSOLE_PORTS, data_ports=RASPBERRY_PI_PICO_DATA_PORTS, baudrate=RASPBERRY_PI_PICO_BAUDRATE)
Target function for a multiprocessing process that handles the serial
communication.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
debug
|
bool
|
Flag to indicate if the receiver is in debug mode. |
required |
challenge
|
Value
|
Shared value to hold the current challenge. |
required |
start_event
|
Event
|
Event to signal when the serial communication has started. |
required |
stop_event
|
Event
|
Event to signal when the serial communication should stop sending and receiving messages. |
required |
bno08x_yaw_deg
|
Value
|
Shared value for the BNO08X yaw angle in degrees. |
required |
bno08x_turns
|
Value
|
Shared value for the BNO08X turns. |
required |
sender_messages_queue
|
Queue
|
Queue to hold outgoing messages of the serial port. |
required |
writer_messages_queue
|
Queue
|
Queue to hold log messages. |
required |
server_messages_queue
|
Optional[Queue]
|
Queue to broadcast the messages through the websockets server. |
None
|
console_ports
|
Optional[list[str]]
|
List of serial ports used for receiving data from Pico. |
RASPBERRY_PI_PICO_CONSOLE_PORTS
|
data_ports
|
Optional[list[str]]
|
List of serial ports used for sending data to Pico. |
RASPBERRY_PI_PICO_DATA_PORTS
|
baudrate
|
Optional[int]
|
Baud rate for the serial communication. |
RASPBERRY_PI_PICO_BAUDRATE
|
Source code in devices\raspberry_pi_5\src\serial_communication\multiprocessing.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
receiver
Receiver
Bases: ReceiverABC
, LoggerConsumerProtocol
Receiver class to handle serial communication with the Raspberry Pi Pico.
Source code in devices\raspberry_pi_5\src\serial_communication\receiver.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
|
__del__()
Destructor to clean up resources when the receiver is no longer needed.
Source code in devices\raspberry_pi_5\src\serial_communication\receiver.py
489 490 491 492 493 494 495 496 497 498 499 |
|
__init__(debug, challenge, start_event, stop_sent_event, stop_confirmation_event, stop_event, bno08x_yaw_deg, bno08x_turns, sender_messages_queue, writer_messages_queue, server_messages_queue=None, console_ports=RASPBERRY_PI_PICO_CONSOLE_PORTS, baudrate=RASPBERRY_PI_PICO_BAUDRATE)
Initialize the Receiver class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
debug
|
bool
|
Flag to indicate if the receiver is in debug mode. |
required |
challenge
|
Value
|
Shared value to hold the current challenge. |
required |
start_event
|
Event
|
Event to signal when the serial communication has started. |
required |
stop_sent_event
|
Event
|
Event to signal when the stop message has been sent. |
required |
stop_confirmation_event
|
Event
|
Event to signal when stop messages has been confirmed. |
required |
stop_event
|
Event
|
Event to signal when the serial communication should stop sending and receiving messages. |
required |
bno08x_yaw_deg
|
Value
|
Shared value for the BNO08X yaw angle in degrees. |
required |
bno08x_turns
|
Value
|
Shared value for the BNO08X turns. |
required |
sender_messages_queue
|
Queue
|
Queue to hold outgoing messages of the serial port. |
required |
writer_messages_queue
|
Queue
|
Queue to hold log messages. |
required |
server_messages_queue
|
Optional[Queue]
|
Queue to broadcast the messages through the websockets server. |
None
|
console_ports
|
Optional[List[str]]
|
List of serial ports used for receiving data from Pico. |
RASPBERRY_PI_PICO_CONSOLE_PORTS
|
baudrate
|
Optional[int]
|
Baud rate for the serial communication. |
RASPBERRY_PI_PICO_BAUDRATE
|
Source code in devices\raspberry_pi_5\src\serial_communication\receiver.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
sender
Sender
Bases: SenderABC
, LoggerConsumerProtocol
Sender class to handle serial communication with the Raspberry Pi Pico.
Source code in devices\raspberry_pi_5\src\serial_communication\sender.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
|
__del__()
Destructor to clean up resources when the sender is no longer needed.
Source code in devices\raspberry_pi_5\src\serial_communication\sender.py
280 281 282 283 284 285 286 287 288 289 290 |
|
__init__(debug, start_event, stop_sent_event, stop_confirmation_event, stop_event, messages_queue, writer_messages_queue, server_messages_queue=None, data_ports=RASPBERRY_PI_PICO_DATA_PORTS, baudrate=RASPBERRY_PI_PICO_BAUDRATE)
Initialize the Receiver class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
debug
|
bool
|
Flag to indicate if the receiver is in debug mode. |
required |
start_event
|
Event
|
Event to signal when the serial communication has started. |
required |
stop_sent_event
|
Event
|
Event to signal when the stop message has been sent. |
required |
stop_confirmation_event
|
Event
|
Event to signal when stop messages has been confirmed. |
required |
stop_event
|
Event
|
Event to signal when the serial communication should stop sending and receiving messages. |
required |
messages_queue
|
Queue
|
Queue to hold outgoing messages of the serial port. |
required |
writer_messages_queue
|
Queue
|
Queue to hold log messages. |
required |
server_messages_queue
|
Optional[Queue]
|
Queue to broadcast the messages through the websockets server. |
None
|
data_ports
|
Optional[list[str]]
|
List of serial ports used for sending data to Pico. |
RASPBERRY_PI_PICO_DATA_PORTS
|
baudrate
|
Optional[int]
|
Baud rate for the serial communication. |
RASPBERRY_PI_PICO_BAUDRATE
|
Source code in devices\raspberry_pi_5\src\serial_communication\sender.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|