feat: add logging and initial prototype
This commit is contained in:
parent
9070db4a14
commit
5bcbfa3b6d
@ -1,12 +1,39 @@
|
||||
import sys
|
||||
|
||||
from loguru import logger
|
||||
|
||||
from scii.mq import MessageQueue
|
||||
|
||||
logger.catch
|
||||
def main():
|
||||
setup_logging("TRACE", True)
|
||||
logger.info("welcome to the SCI Interface")
|
||||
with MessageQueue(rx="/sci_tx", tx="/sci_rx") as qu:
|
||||
with MessageQueue(rx="/sci_tx", tx="/sci_rx") as queue:
|
||||
while True:
|
||||
r = qu.receive()
|
||||
r = queue.receive()
|
||||
if r is None:
|
||||
break
|
||||
logger.info("msg: {}", r)
|
||||
|
||||
queue.send("list")
|
||||
r = queue.receive()
|
||||
if r is None:
|
||||
break
|
||||
logger.info("list: {}", r)
|
||||
|
||||
|
||||
def setup_logging(level: str, use_colors: bool) -> None:
|
||||
"""Setup logging.
|
||||
|
||||
Args:
|
||||
level: The logging level.
|
||||
use_colors: Whether to use colors in the log output.
|
||||
|
||||
"""
|
||||
logger.remove() # A fresh start
|
||||
_ = logger.add(
|
||||
sys.stderr,
|
||||
colorize=use_colors,
|
||||
format="{time:HH:mm:ss} <level>{level}</level> <fg #888>{file}:{line}:</fg #888> <bold>{message}</bold>",
|
||||
level=level,
|
||||
)
|
||||
|
@ -43,7 +43,7 @@ class MessageQueue:
|
||||
def receive(self) -> str | None:
|
||||
if not self._is_rx_valid():
|
||||
raise RuntimeError(f"rx queue is invalid {self._rx_queue}")
|
||||
result = create_string_buffer(b'\0' * 32)
|
||||
result = create_string_buffer(b'\0' * 64)
|
||||
res = libc.mq_receive(self._rx_queue, result, 8192, None)
|
||||
if res == -1:
|
||||
libc.perror(b"mq_receive")
|
||||
|
Loading…
x
Reference in New Issue
Block a user