Skip to content

Commit 1a50377

Browse files
authored
Merge pull request #865 from ianmcorvidae/device-metadata-details
Add a bunch more detail to --device-metadata output, from fields we weren't formerly using in the output.
2 parents 776debc + 2a44be9 commit 1a50377

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

meshtastic/node.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from typing import Optional, Union, List
99

10-
from meshtastic.protobuf import admin_pb2, apponly_pb2, channel_pb2, localonly_pb2, mesh_pb2, portnums_pb2
10+
from meshtastic.protobuf import admin_pb2, apponly_pb2, channel_pb2, config_pb2, localonly_pb2, mesh_pb2, portnums_pb2
1111
from meshtastic.util import (
1212
Timeout,
1313
camel_to_snake,
@@ -18,6 +18,7 @@
1818
message_to_json,
1919
generate_channel_hash,
2020
to_node_num,
21+
flags_to_list,
2122
)
2223

2324
logger = logging.getLogger(__name__)
@@ -54,6 +55,16 @@ def __repr__(self):
5455
r += ")"
5556
return r
5657

58+
@staticmethod
59+
def position_flags_list(position_flags: int) -> List[str]:
60+
"Return a list of position flags from the given flags integer"
61+
return flags_to_list(config_pb2.Config.PositionConfig.PositionFlags, position_flags)
62+
63+
@staticmethod
64+
def excluded_modules_list(excluded_modules: int) -> List[str]:
65+
"Return a list of excluded modules from the given flags integer"
66+
return flags_to_list(mesh_pb2.ExcludedModules, excluded_modules)
67+
5768
def module_available(self, excluded_bit: int) -> bool:
5869
"""Check DeviceMetadata.excluded_modules to see if a module is available."""
5970
meta = getattr(self.iface, "metadata", None)
@@ -902,6 +913,18 @@ def onRequestGetMetadata(self, p):
902913
logger.debug(f"Received metadata {stripnl(c)}")
903914
print(f"\nfirmware_version: {c.firmware_version}")
904915
print(f"device_state_version: {c.device_state_version}")
916+
if c.role in config_pb2.Config.DeviceConfig.Role.values():
917+
print(f"role: {config_pb2.Config.DeviceConfig.Role.Name(c.role)}")
918+
else:
919+
print(f"role: {c.role}")
920+
print(f"position_flags: {self.position_flags_list(c.position_flags)}")
921+
if c.hw_model in mesh_pb2.HardwareModel.values():
922+
print(f"hw_model: {mesh_pb2.HardwareModel.Name(c.hw_model)}")
923+
else:
924+
print(f"hw_model: {c.hw_model}")
925+
print(f"hasPKC: {c.hasPKC}")
926+
if c.excluded_modules > 0:
927+
print(f"excluded_modules: {self.excluded_modules_list(c.excluded_modules)}")
905928

906929
def onResponseRequestChannel(self, p):
907930
"""Handle the response packet for requesting a channel _requestChannel()"""

meshtastic/util.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,3 +735,16 @@ def to_node_num(node_id: Union[int, str]) -> int:
735735
return int(s, 10)
736736
except ValueError:
737737
return int(s, 16)
738+
739+
def flags_to_list(flag_type, flags: int) -> List[str]:
740+
"""Given a flag_type that's a protobuf EnumTypeWrapper, and a flag int, give a list of flags enabled."""
741+
ret = []
742+
for key in flag_type.keys():
743+
if key == "EXCLUDED_NONE":
744+
continue
745+
if flags & flag_type.Value(key):
746+
ret.append(key)
747+
flags = flags - flag_type.Value(key)
748+
if flags > 0:
749+
ret.append(f"UNKNOWN_ADDITIONAL_FLAGS({flags})")
750+
return ret

0 commit comments

Comments
 (0)