Update drivers
This commit is contained in:
20
source/common.py
Normal file
20
source/common.py
Normal file
@ -0,0 +1,20 @@
|
||||
from typing import Literal
|
||||
|
||||
|
||||
def format_comm_debug(
|
||||
prefix: Literal["RX", "TX"], data: bytes, include_ascii: bool = False
|
||||
) -> str:
|
||||
hex_representation = " ".join(f"{byte:02X}" for byte in data)
|
||||
|
||||
output = [
|
||||
f"{prefix}: ",
|
||||
hex_representation,
|
||||
]
|
||||
|
||||
if include_ascii:
|
||||
ascii_representation = "".join(
|
||||
(chr(byte) if 32 <= byte <= 126 else ".") for byte in data
|
||||
)
|
||||
output.append(" // ASCII: " + ascii_representation)
|
||||
|
||||
return "".join(output)
|
||||
Reference in New Issue
Block a user