mirror of
https://github.com/meshtastic/python.git
synced 2026-01-15 03:07:57 -05:00
Add handler for new log-record BLE characteristic
This commit is contained in:
@@ -8,6 +8,10 @@ import time
|
||||
from threading import Thread
|
||||
from typing import List, Optional
|
||||
|
||||
from .protobuf import (
|
||||
mesh_pb2,
|
||||
)
|
||||
|
||||
import print_color # type: ignore[import-untyped]
|
||||
from bleak import BleakClient, BleakScanner, BLEDevice
|
||||
from bleak.exc import BleakDBusError, BleakError
|
||||
@@ -18,7 +22,8 @@ SERVICE_UUID = "6ba1b218-15a8-461f-9fa8-5dcae273eafd"
|
||||
TORADIO_UUID = "f75c76d2-129e-4dad-a1dd-7866124401e7"
|
||||
FROMRADIO_UUID = "2c55e69e-4993-11ed-b878-0242ac120002"
|
||||
FROMNUM_UUID = "ed9da18c-a800-4f66-a670-aa7547e34453"
|
||||
LOGRADIO_UUID = "6c6fd238-78fa-436b-aacf-15c5be1ef2e2"
|
||||
LEGACY_LOGRADIO_UUID = "6c6fd238-78fa-436b-aacf-15c5be1ef2e2"
|
||||
LOGRADIO_UUID = "5a3d6e49-06e6-4423-9944-e9de8cdf9547"
|
||||
|
||||
|
||||
class BLEInterface(MeshInterface):
|
||||
@@ -56,6 +61,7 @@ class BLEInterface(MeshInterface):
|
||||
self.close()
|
||||
raise e
|
||||
|
||||
#self.client.start_notify(LEGACY_LOGRADIO_UUID, self.legacy_log_radio_handler)
|
||||
self.client.start_notify(LOGRADIO_UUID, self.log_radio_handler)
|
||||
|
||||
logging.debug("Mesh configure starting")
|
||||
@@ -81,6 +87,22 @@ class BLEInterface(MeshInterface):
|
||||
self.should_read = True
|
||||
|
||||
async def log_radio_handler(self, _, b): # pylint: disable=C0116
|
||||
if b is not mesh_pb2.LogRecord:
|
||||
return
|
||||
|
||||
log_record = b
|
||||
if log_record.DEBUG:
|
||||
print_color.print(log_record.message, color="cyan", end=None)
|
||||
elif log_record.INFO:
|
||||
print_color.print(log_record.message, color="white", end=None)
|
||||
elif log_record.WARNING:
|
||||
print_color.print(log_record.message, color="yellow", end=None)
|
||||
elif log_record.ERROR:
|
||||
print_color.print(log_record.message, color="red", end=None)
|
||||
else:
|
||||
print_color.print(log_record.message, end=None)
|
||||
|
||||
async def legacy_log_radio_handler(self, _, b): # pylint: disable=C0116
|
||||
log_radio = b.decode("utf-8").replace("\n", "")
|
||||
if log_radio.startswith("DEBUG"):
|
||||
print_color.print(log_radio, color="cyan", end=None)
|
||||
|
||||
Reference in New Issue
Block a user