| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -129,6 +129,7 @@ def onConnection(interface, topic=pub.AUTO_TOPIC): # called when we (re)connect | |||
| 129 | 129 | ||
| 130 | 130 | publishingThread = DeferredExecution("publishing") | |
| 131 | 131 | ||
| 132 | + logger = logging.getLogger(__name__) | ||
| 132 | 133 | ||
| 133 | 134 | class ResponseHandler(NamedTuple): | |
| 134 | 135 | """A pending response callback, waiting for a response to one of our messages""" | |
@@ -160,31 +161,31 @@ def _onTextReceive(iface, asDict): | |||
| 160 | 161 | # | |
| 161 | 162 | # Usually btw this problem is caused by apps sending binary data but setting the payload type to | |
| 162 | 163 | # text. | |
| 163 | - logging.debug(f"in _onTextReceive() asDict:{asDict}") | ||
| 164 | + logger.debug(f"in _onTextReceive() asDict:{asDict}") | ||
| 164 | 165 | try: | |
| 165 | 166 | asBytes = asDict["decoded"]["payload"] | |
| 166 | 167 | asDict["decoded"]["text"] = asBytes.decode("utf-8") | |
| 167 | 168 | except Exception as ex: | |
| 168 | - logging.error(f"Malformatted utf8 in text message: {ex}") | ||
| 169 | + logger.error(f"Malformatted utf8 in text message: {ex}") | ||
| 169 | 170 | _receiveInfoUpdate(iface, asDict) | |
| 170 | 171 | ||
| 171 | 172 | ||
| 172 | 173 | def _onPositionReceive(iface, asDict): | |
| 173 | 174 | """Special auto parsing for received messages""" | |
| 174 | - logging.debug(f"in _onPositionReceive() asDict:{asDict}") | ||
| 175 | + logger.debug(f"in _onPositionReceive() asDict:{asDict}") | ||
| 175 | 176 | if "decoded" in asDict: | |
| 176 | 177 | if "position" in asDict["decoded"] and "from" in asDict: | |
| 177 | 178 | p = asDict["decoded"]["position"] | |
| 178 | - logging.debug(f"p:{p}") | ||
| 179 | + logger.debug(f"p:{p}") | ||
| 179 | 180 | p = iface._fixupPosition(p) | |
| 180 | - logging.debug(f"after fixup p:{p}") | ||
| 181 | + logger.debug(f"after fixup p:{p}") | ||
| 181 | 182 | # update node DB as needed | |
| 182 | 183 | iface._getOrCreateByNum(asDict["from"])["position"] = p | |
| 183 | 184 | ||
| 184 | 185 | ||
| 185 | 186 | def _onNodeInfoReceive(iface, asDict): | |
| 186 | 187 | """Special auto parsing for received messages""" | |
| 187 | - logging.debug(f"in _onNodeInfoReceive() asDict:{asDict}") | ||
| 188 | + logger.debug(f"in _onNodeInfoReceive() asDict:{asDict}") | ||
| 188 | 189 | if "decoded" in asDict: | |
| 189 | 190 | if "user" in asDict["decoded"] and "from" in asDict: | |
| 190 | 191 | p = asDict["decoded"]["user"] | |
@@ -198,7 +199,7 @@ def _onNodeInfoReceive(iface, asDict): | |||
| 198 | 199 | ||
| 199 | 200 | def _onTelemetryReceive(iface, asDict): | |
| 200 | 201 | """Automatically update device metrics on received packets""" | |
| 201 | - logging.debug(f"in _onTelemetryReceive() asDict:{asDict}") | ||
| 202 | + logger.debug(f"in _onTelemetryReceive() asDict:{asDict}") | ||
| 202 | 203 | if "from" not in asDict: | |
| 203 | 204 | return | |
| 204 | 205 | ||
@@ -222,7 +223,7 @@ def _onTelemetryReceive(iface, asDict): | |||
| 222 | 223 | updateObj = telemetry.get(toUpdate) | |
| 223 | 224 | newMetrics = node.get(toUpdate, {}) | |
| 224 | 225 | newMetrics.update(updateObj) | |
| 225 | - logging.debug(f"updating {toUpdate} metrics for {asDict['from']} to {newMetrics}") | ||
| 226 | + logger.debug(f"updating {toUpdate} metrics for {asDict['from']} to {newMetrics}") | ||
| 226 | 227 | node[toUpdate] = newMetrics | |
| 227 | 228 | ||
| 228 | 229 | def _receiveInfoUpdate(iface, asDict): | |
@@ -234,7 +235,7 @@ def _receiveInfoUpdate(iface, asDict): | |||
| 234 | 235 | ||
| 235 | 236 | def _onAdminReceive(iface, asDict): | |
| 236 | 237 | """Special auto parsing for received messages""" | |
| 237 | - logging.debug(f"in _onAdminReceive() asDict:{asDict}") | ||
| 238 | + logger.debug(f"in _onAdminReceive() asDict:{asDict}") | ||
| 238 | 239 | if "decoded" in asDict and "from" in asDict and "admin" in asDict["decoded"]: | |
| 239 | 240 | adminMessage = asDict["decoded"]["admin"]["raw"] | |
| 240 | 241 | iface._getOrCreateByNum(asDict["from"])["adminSessionPassKey"] = adminMessage.session_passkey | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,10 @@ | |||
| 9 | 9 | from types import ModuleType | |
| 10 | 10 | ||
| 11 | 11 | import argparse | |
| 12 | + import logging | ||
| 13 | + | ||
| 14 | + logger = logging.getLogger(__name__) | ||
| 15 | + | ||
| 12 | 16 | argcomplete: Union[None, ModuleType] = None | |
| 13 | 17 | try: | |
| 14 | 18 | import argcomplete # type: ignore | |
@@ -67,7 +71,7 @@ def onReceive(packet, interface) -> None: | |||
| 67 | 71 | args = mt_config.args | |
| 68 | 72 | try: | |
| 69 | 73 | d = packet.get("decoded") | |
| 70 | - logging.debug(f"in onReceive() d:{d}") | ||
| 74 | + logger.debug(f"in onReceive() d:{d}") | ||
| 71 | 75 | ||
| 72 | 76 | # Exit once we receive a reply | |
| 73 | 77 | if ( | |
@@ -101,7 +105,7 @@ def onConnection(interface, topic=pub.AUTO_TOPIC) -> None: # pylint: disable=W0 | |||
| 101 | 105 | def checkChannel(interface: MeshInterface, channelIndex: int) -> bool: | |
| 102 | 106 | """Given an interface and channel index, return True if that channel is non-disabled on the local node""" | |
| 103 | 107 | ch = interface.localNode.getChannelByChannelIndex(channelIndex) | |
| 104 | - logging.debug(f"ch:{ch}") | ||
| 108 | + logger.debug(f"ch:{ch}") | ||
| 105 | 109 | return ch and ch.role != channel_pb2.Channel.Role.DISABLED | |
| 106 | 110 | ||
| 107 | 111 | ||
@@ -114,7 +118,7 @@ def _printSetting(config_type, uni_name, pref_value, repeated): | |||
| 114 | 118 | else: | |
| 115 | 119 | pref_value = meshtastic.util.toStr(pref_value) | |
| 116 | 120 | print(f"{str(config_type.name)}.{uni_name}: {str(pref_value)}") | |
| 117 | - logging.debug(f"{str(config_type.name)}.{uni_name}: {str(pref_value)}") | ||
| 121 | + logger.debug(f"{str(config_type.name)}.{uni_name}: {str(pref_value)}") | ||
| 118 | 122 | ||
| 119 | 123 | name = splitCompoundName(comp_name) | |
| 120 | 124 | wholeField = name[0] == name[1] # We want the whole field | |
@@ -123,8 +127,8 @@ def _printSetting(config_type, uni_name, pref_value, repeated): | |||
| 123 | 127 | # Note: protobufs has the keys in snake_case, so snake internally | |
| 124 | 128 | snake_name = meshtastic.util.camel_to_snake(name[1]) | |
| 125 | 129 | uni_name = camel_name if mt_config.camel_case else snake_name | |
| 126 | - logging.debug(f"snake_name:{snake_name} camel_name:{camel_name}") | ||
| 127 | - logging.debug(f"use camel:{mt_config.camel_case}") | ||
| 130 | + logger.debug(f"snake_name:{snake_name} camel_name:{camel_name}") | ||
| 131 | + logger.debug(f"use camel:{mt_config.camel_case}") | ||
| 128 | 132 | ||
| 129 | 133 | # First validate the input | |
| 130 | 134 | localConfig = node.localConfig | |
@@ -198,8 +202,8 @@ def setPref(config, comp_name, raw_val) -> bool: | |||
| 198 | 202 | snake_name = meshtastic.util.camel_to_snake(name[-1]) | |
| 199 | 203 | camel_name = meshtastic.util.snake_to_camel(name[-1]) | |
| 200 | 204 | uni_name = camel_name if mt_config.camel_case else snake_name | |
| 201 | - logging.debug(f"snake_name:{snake_name}") | ||
| 202 | - logging.debug(f"camel_name:{camel_name}") | ||
| 205 | + logger.debug(f"snake_name:{snake_name}") | ||
| 206 | + logger.debug(f"camel_name:{camel_name}") | ||
| 203 | 207 | ||
| 204 | 208 | objDesc = config.DESCRIPTOR | |
| 205 | 209 | config_part = config | |
@@ -223,7 +227,7 @@ def setPref(config, comp_name, raw_val) -> bool: | |||
| 223 | 227 | val = meshtastic.util.fromStr(raw_val) | |
| 224 | 228 | else: | |
| 225 | 229 | val = raw_val | |
| 226 | - logging.debug(f"valStr:{raw_val} val:{val}") | ||
| 230 | + logger.debug(f"valStr:{raw_val} val:{val}") | ||
| 227 | 231 | ||
| 228 | 232 | if snake_name == "wifi_psk" and len(str(raw_val)) < 8: | |
| 229 | 233 | print("Warning: network.wifi_psk must be 8 or more characters.") | |
@@ -603,7 +607,7 @@ def onConnected(interface): | |||
| 603 | 607 | time.sleep(1) | |
| 604 | 608 | if interface.gotResponse: | |
| 605 | 609 | break | |
| 606 | - logging.debug(f"end of gpio_rd") | ||
| 610 | + logger.debug(f"end of gpio_rd") | ||
| 607 | 611 | ||
| 608 | 612 | if args.gpio_watch: | |
| 609 | 613 | bitmask = int(args.gpio_watch, 16) | |
@@ -1059,7 +1063,7 @@ def setSimpleConfig(modem_preset): | |||
| 1059 | 1063 | # Even if others said we could close, stay open if the user asked for a tunnel | |
| 1060 | 1064 | closeNow = False | |
| 1061 | 1065 | if interface.noProto: | |
| 1062 | - logging.warning(f"Not starting Tunnel - disabled by noProto") | ||
| 1066 | + logger.warning(f"Not starting Tunnel - disabled by noProto") | ||
| 1063 | 1067 | else: | |
| 1064 | 1068 | if args.tunnel_net: | |
| 1065 | 1069 | tunnel.Tunnel(interface, subnet=args.tunnel_net) | |
@@ -1250,14 +1254,14 @@ def create_power_meter(): | |||
| 1250 | 1254 | meter = SimPowerSupply() | |
| 1251 | 1255 | ||
| 1252 | 1256 | if meter and v: | |
| 1253 | - logging.info(f"Setting power supply to {v} volts") | ||
| 1257 | + logger.info(f"Setting power supply to {v} volts") | ||
| 1254 | 1258 | meter.v = v | |
| 1255 | 1259 | meter.powerOn() | |
| 1256 | 1260 | ||
| 1257 | 1261 | if args.power_wait: | |
| 1258 | 1262 | input("Powered on, press enter to continue...") | |
| 1259 | 1263 | else: | |
| 1260 | - logging.info("Powered-on, waiting for device to boot") | ||
| 1264 | + logger.info("Powered-on, waiting for device to boot") | ||
| 1261 | 1265 | time.sleep(5) | |
| 1262 | 1266 | ||
| 1263 | 1267 | ||
@@ -1312,7 +1316,7 @@ def common(): | |||
| 1312 | 1316 | args.seriallog = "none" # assume no debug output in this case | |
| 1313 | 1317 | ||
| 1314 | 1318 | if args.deprecated is not None: | |
| 1315 | - logging.error( | ||
| 1319 | + logger.error( | ||
| 1316 | 1320 | "This option has been deprecated, see help below for the correct replacement..." | |
| 1317 | 1321 | ) | |
| 1318 | 1322 | parser.print_help(sys.stderr) | |
@@ -1331,18 +1335,18 @@ def common(): | |||
| 1331 | 1335 | logfile = sys.stdout | |
| 1332 | 1336 | elif args.seriallog == "none": | |
| 1333 | 1337 | args.seriallog = None | |
| 1334 | - logging.debug("Not logging serial output") | ||
| 1338 | + logger.debug("Not logging serial output") | ||
| 1335 | 1339 | logfile = None | |
| 1336 | 1340 | else: | |
| 1337 | - logging.info(f"Logging serial output to {args.seriallog}") | ||
| 1341 | + logger.info(f"Logging serial output to {args.seriallog}") | ||
| 1338 | 1342 | # Note: using "line buffering" | |
| 1339 | 1343 | # pylint: disable=R1732 | |
| 1340 | 1344 | logfile = open(args.seriallog, "w+", buffering=1, encoding="utf8") | |
| 1341 | 1345 | mt_config.logfile = logfile | |
| 1342 | 1346 | ||
| 1343 | 1347 | subscribe() | |
| 1344 | 1348 | if args.ble_scan: | |
| 1345 | - logging.debug("BLE scan starting") | ||
| 1349 | + logger.debug("BLE scan starting") | ||
| 1346 | 1350 | for x in BLEInterface.scan(): | |
| 1347 | 1351 | print(f"Found: name='{x.name}' address='{x.address}'") | |
| 1348 | 1352 | meshtastic.util.our_exit("BLE scan finished", 0) | |
@@ -1433,7 +1437,7 @@ def common(): | |||
| 1433 | 1437 | while True: | |
| 1434 | 1438 | time.sleep(1000) | |
| 1435 | 1439 | except KeyboardInterrupt: | |
| 1436 | - logging.info("Exiting due to keyboard interrupt") | ||
| 1440 | + logger.info("Exiting due to keyboard interrupt") | ||
| 1437 | 1441 | ||
| 1438 | 1442 | # don't call exit, background threads might be running still | |
| 1439 | 1443 | # sys.exit(0) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,6 +23,7 @@ | |||
| 23 | 23 | FROMNUM_UUID = "ed9da18c-a800-4f66-a670-aa7547e34453" | |
| 24 | 24 | LEGACY_LOGRADIO_UUID = "6c6fd238-78fa-436b-aacf-15c5be1ef2e2" | |
| 25 | 25 | LOGRADIO_UUID = "5a3d6e49-06e6-4423-9944-e9de8cdf9547" | |
| 26 | + logger = logging.getLogger(__name__) | ||
| 26 | 27 | ||
| 27 | 28 | ||
| 28 | 29 | class BLEInterface(MeshInterface): | |
@@ -44,19 +45,19 @@ def __init__( | |||
| 44 | 45 | ||
| 45 | 46 | self.should_read = False | |
| 46 | 47 | ||
| 47 | - logging.debug("Threads starting") | ||
| 48 | + logger.debug("Threads starting") | ||
| 48 | 49 | self._want_receive = True | |
| 49 | 50 | self._receiveThread: Optional[Thread] = Thread( | |
| 50 | 51 | target=self._receiveFromRadioImpl, name="BLEReceive", daemon=True | |
| 51 | 52 | ) | |
| 52 | 53 | self._receiveThread.start() | |
| 53 | - logging.debug("Threads running") | ||
| 54 | + logger.debug("Threads running") | ||
| 54 | 55 | ||
| 55 | 56 | self.client: Optional[BLEClient] = None | |
| 56 | 57 | try: | |
| 57 | - logging.debug(f"BLE connecting to: {address if address else 'any'}") | ||
| 58 | + logger.debug(f"BLE connecting to: {address if address else 'any'}") | ||
| 58 | 59 | self.client = self.connect(address) | |
| 59 | - logging.debug("BLE connected") | ||
| 60 | + logger.debug("BLE connected") | ||
| 60 | 61 | except BLEInterface.BLEError as e: | |
| 61 | 62 | self.close() | |
| 62 | 63 | raise e | |
@@ -69,13 +70,13 @@ def __init__( | |||
| 69 | 70 | if self.client.has_characteristic(LOGRADIO_UUID): | |
| 70 | 71 | self.client.start_notify(LOGRADIO_UUID, self.log_radio_handler) | |
| 71 | 72 | ||
| 72 | - logging.debug("Mesh configure starting") | ||
| 73 | + logger.debug("Mesh configure starting") | ||
| 73 | 74 | self._startConfig() | |
| 74 | 75 | if not self.noProto: | |
| 75 | 76 | self._waitConnected(timeout=60.0) | |
| 76 | 77 | self.waitForConfig() | |
| 77 | 78 | ||
| 78 | - logging.debug("Register FROMNUM notify callback") | ||
| 79 | + logger.debug("Register FROMNUM notify callback") | ||
| 79 | 80 | self.client.start_notify(FROMNUM_UUID, self.from_num_handler) | |
| 80 | 81 | ||
| 81 | 82 | # We MUST run atexit (if we can) because otherwise (at least on linux) the BLE device is not disconnected | |
@@ -99,7 +100,7 @@ def from_num_handler(self, _, b: bytes) -> None: # pylint: disable=C0116 | |||
| 99 | 100 | Note: this method does not need to be async because it is just setting a bool. | |
| 100 | 101 | """ | |
| 101 | 102 | from_num = struct.unpack("<I", bytes(b))[0] | |
| 102 | - logging.debug(f"FROMNUM notify: {from_num}") | ||
| 103 | + logger.debug(f"FROMNUM notify: {from_num}") | ||
| 103 | 104 | self.should_read = True | |
| 104 | 105 | ||
| 105 | 106 | async def log_radio_handler(self, _, b): # pylint: disable=C0116 | |
@@ -114,7 +115,7 @@ async def log_radio_handler(self, _, b): # pylint: disable=C0116 | |||
| 114 | 115 | ) | |
| 115 | 116 | self._handleLogLine(message) | |
| 116 | 117 | except google.protobuf.message.DecodeError: | |
| 117 | - logging.warning("Malformed LogRecord received. Skipping.") | ||
| 118 | + logger.warning("Malformed LogRecord received. Skipping.") | ||
| 118 | 119 | ||
| 119 | 120 | async def legacy_log_radio_handler(self, _, b): # pylint: disable=C0116 | |
| 120 | 121 | log_radio = b.decode("utf-8").replace("\n", "") | |
@@ -124,7 +125,7 @@ async def legacy_log_radio_handler(self, _, b): # pylint: disable=C0116 | |||
| 124 | 125 | def scan() -> List[BLEDevice]: | |
| 125 | 126 | """Scan for available BLE devices.""" | |
| 126 | 127 | with BLEClient() as client: | |
| 127 | - logging.info("Scanning for BLE devices (takes 10 seconds)...") | ||
| 128 | + logger.info("Scanning for BLE devices (takes 10 seconds)...") | ||
| 128 | 129 | response = client.discover( | |
| 129 | 130 | timeout=10, return_adv=True, service_uuids=[SERVICE_UUID] | |
| 130 | 131 | ) | |
@@ -186,19 +187,19 @@ def _receiveFromRadioImpl(self) -> None: | |||
| 186 | 187 | retries: int = 0 | |
| 187 | 188 | while self._want_receive: | |
| 188 | 189 | if self.client is None: | |
| 189 | - logging.debug(f"BLE client is None, shutting down") | ||
| 190 | + logger.debug(f"BLE client is None, shutting down") | ||
| 190 | 191 | self._want_receive = False | |
| 191 | 192 | continue | |
| 192 | 193 | try: | |
| 193 | 194 | b = bytes(self.client.read_gatt_char(FROMRADIO_UUID)) | |
| 194 | 195 | except BleakDBusError as e: | |
| 195 | 196 | # Device disconnected probably, so end our read loop immediately | |
| 196 | - logging.debug(f"Device disconnected, shutting down {e}") | ||
| 197 | + logger.debug(f"Device disconnected, shutting down {e}") | ||
| 197 | 198 | self._want_receive = False | |
| 198 | 199 | except BleakError as e: | |
| 199 | 200 | # We were definitely disconnected | |
| 200 | 201 | if "Not connected" in str(e): | |
| 201 | - logging.debug(f"Device disconnected, shutting down {e}") | ||
| 202 | + logger.debug(f"Device disconnected, shutting down {e}") | ||
| 202 | 203 | self._want_receive = False | |
| 203 | 204 | else: | |
| 204 | 205 | raise BLEInterface.BLEError("Error reading BLE") from e | |
@@ -208,15 +209,15 @@ def _receiveFromRadioImpl(self) -> None: | |||
| 208 | 209 | retries += 1 | |
| 209 | 210 | continue | |
| 210 | 211 | break | |
| 211 | - logging.debug(f"FROMRADIO read: {b.hex()}") | ||
| 212 | + logger.debug(f"FROMRADIO read: {b.hex()}") | ||
| 212 | 213 | self._handleFromRadio(b) | |
| 213 | 214 | else: | |
| 214 | 215 | time.sleep(0.01) | |
| 215 | 216 | ||
| 216 | 217 | def _sendToRadioImpl(self, toRadio) -> None: | |
| 217 | 218 | b: bytes = toRadio.SerializeToString() | |
| 218 | 219 | if b and self.client: # we silently ignore writes while we are shutting down | |
| 219 | - logging.debug(f"TORADIO write: {b.hex()}") | ||
| 220 | + logger.debug(f"TORADIO write: {b.hex()}") | ||
| 220 | 221 | try: | |
| 221 | 222 | self.client.write_gatt_char( | |
| 222 | 223 | TORADIO_UUID, b, response=True | |
@@ -234,7 +235,7 @@ def close(self) -> None: | |||
| 234 | 235 | try: | |
| 235 | 236 | MeshInterface.close(self) | |
| 236 | 237 | except Exception as e: | |
| 237 | - logging.error(f"Error closing mesh interface: {e}") | ||
| 238 | + logger.error(f"Error closing mesh interface: {e}") | ||
| 238 | 239 | ||
| 239 | 240 | if self._want_receive: | |
| 240 | 241 | self._want_receive = False # Tell the thread we want it to stop | |
@@ -263,7 +264,7 @@ def __init__(self, address=None, **kwargs) -> None: | |||
| 263 | 264 | self._eventThread.start() | |
| 264 | 265 | ||
| 265 | 266 | if not address: | |
| 266 | - logging.debug("No address provided - only discover method will work.") | ||
| 267 | + logger.debug("No address provided - only discover method will work.") | ||
| 267 | 268 | return | |
| 268 | 269 | ||
| 269 | 270 | self.bleak_client = BleakClient(address, **kwargs) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments