|
6 | 6 | import time |
7 | 7 | from threading import Event, Thread |
8 | 8 | from typing import Optional |
| 9 | +from print_color import print |
9 | 10 |
|
10 | 11 | from bleak import BleakClient, BleakScanner, BLEDevice |
11 | 12 |
|
|
16 | 17 | TORADIO_UUID = "f75c76d2-129e-4dad-a1dd-7866124401e7" |
17 | 18 | FROMRADIO_UUID = "2c55e69e-4993-11ed-b878-0242ac120002" |
18 | 19 | FROMNUM_UUID = "ed9da18c-a800-4f66-a670-aa7547e34453" |
| 20 | +LOGRADIO_UUID = "6c6fd238-78fa-436b-aacf-15c5be1ef2e2" |
| 21 | + |
19 | 22 |
|
20 | 23 |
|
21 | 24 | class BLEInterface(MeshInterface): |
@@ -75,12 +78,28 @@ def __init__( |
75 | 78 |
|
76 | 79 | logging.debug("Register FROMNUM notify callback") |
77 | 80 | self.client.start_notify(FROMNUM_UUID, self.from_num_handler) |
| 81 | + self.client.start_notify(LOGRADIO_UUID, self.log_radio_handler) |
78 | 82 |
|
79 | 83 | async def from_num_handler(self, _, b): # pylint: disable=C0116 |
80 | 84 | from_num = struct.unpack("<I", bytes(b))[0] |
81 | 85 | logging.debug(f"FROMNUM notify: {from_num}") |
82 | 86 | self.should_read = True |
83 | 87 |
|
| 88 | + async def log_radio_handler(self, _, b): # pylint: disable=C0116 |
| 89 | + log_radio = b.decode('utf-8').replace('\n', '') |
| 90 | + if log_radio.startswith("DEBUG"): |
| 91 | + print(log_radio, color="cyan", end=None) |
| 92 | + elif log_radio.startswith("INFO"): |
| 93 | + print(log_radio, color="white", end=None) |
| 94 | + elif log_radio.startswith("WARN"): |
| 95 | + print(log_radio, color="yellow", end=None) |
| 96 | + elif log_radio.startswith("ERROR"): |
| 97 | + print(log_radio, color="red", end=None) |
| 98 | + else: |
| 99 | + print(log_radio, end=None) |
| 100 | + |
| 101 | + self.should_read = False |
| 102 | + |
84 | 103 | @staticmethod |
85 | 104 | def scan() -> list[BLEDevice]: |
86 | 105 | """Scan for available BLE devices.""" |
|
0 commit comments