Skip to content

Commit 5f174b2

Browse files
authoredFeb 19, 2025··
Merge pull request #731 from migillett/464/0x-prefix
464: allow for 0x node prefix values
2 parents acc4714 + 23ea19c commit 5f174b2

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed
 

‎meshtastic/__main__.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def setPref(config, comp_name, raw_val) -> bool:
226226
logging.debug(f"valStr:{raw_val} val:{val}")
227227

228228
if snake_name == "wifi_psk" and len(str(raw_val)) < 8:
229-
print(f"Warning: network.wifi_psk must be 8 or more characters.")
229+
print("Warning: network.wifi_psk must be 8 or more characters.")
230230
return False
231231

232232
enumType = pref.enum_type
@@ -1365,7 +1365,8 @@ def addSelectionArgs(parser: argparse.ArgumentParser) -> argparse.ArgumentParser
13651365

13661366
group.add_argument(
13671367
"--dest",
1368-
help="The destination node id for any sent commands, if not set '^all' or '^local' is assumed as appropriate",
1368+
help="The destination node id for any sent commands. If not set '^all' or '^local' is assumed."
1369+
"Use the node ID with a '!' or '0x' prefix or the node number.",
13691370
default=None,
13701371
metavar="!xxxxxxxx",
13711372
)
@@ -1676,7 +1677,7 @@ def addRemoteActionArgs(parser: argparse.ArgumentParser) -> argparse.ArgumentPar
16761677
"--traceroute",
16771678
help="Traceroute from connected node to a destination. "
16781679
"You need pass the destination ID as argument, like "
1679-
"this: '--traceroute !ba4bf9d0' "
1680+
"this: '--traceroute !ba4bf9d0' | '--traceroute 0xba4bf9d0'"
16801681
"Only nodes with a shared channel can be traced.",
16811682
metavar="!xxxxxxxx",
16821683
)
@@ -1757,27 +1758,32 @@ def addRemoteAdminArgs(parser: argparse.ArgumentParser) -> argparse.ArgumentPars
17571758

17581759
group.add_argument(
17591760
"--remove-node",
1760-
help="Tell the destination node to remove a specific node from its DB, by node number or ID",
1761+
help="Tell the destination node to remove a specific node from its NodeDB. "
1762+
"Use the node ID with a '!' or '0x' prefix or the node number.",
17611763
metavar="!xxxxxxxx"
17621764
)
17631765
group.add_argument(
17641766
"--set-favorite-node",
1765-
help="Tell the destination node to set the specified node to be favorited on the NodeDB on the devicein its DB, by number or ID",
1767+
help="Tell the destination node to set the specified node to be favorited on the NodeDB. "
1768+
"Use the node ID with a '!' or '0x' prefix or the node number.",
17661769
metavar="!xxxxxxxx"
17671770
)
17681771
group.add_argument(
17691772
"--remove-favorite-node",
1770-
help="Tell the destination node to set the specified node to be un-favorited on the NodeDB on the device, by number or ID",
1773+
help="Tell the destination node to set the specified node to be un-favorited on the NodeDB. "
1774+
"Use the node ID with a '!' or '0x' prefix or the node number.",
17711775
metavar="!xxxxxxxx"
17721776
)
17731777
group.add_argument(
17741778
"--set-ignored-node",
1775-
help="Tell the destination node to set the specified node to be ignored on the NodeDB on the devicein its DB, by number or ID",
1779+
help="Tell the destination node to set the specified node to be ignored on the NodeDB. "
1780+
"Use the node ID with a '!' or '0x' prefix or the node number.",
17761781
metavar="!xxxxxxxx"
17771782
)
17781783
group.add_argument(
17791784
"--remove-ignored-node",
1780-
help="Tell the destination node to set the specified node to be un-ignored on the NodeDB on the device, by number or ID",
1785+
help="Tell the destination node to set the specified node to be un-ignored on the NodeDB. "
1786+
"Use the node ID with a '!' or '0x' prefix or the node number.",
17811787
metavar="!xxxxxxxx"
17821788
)
17831789
group.add_argument(

‎meshtastic/mesh_interface.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def getNode(
395395
if new_index != last_index:
396396
retries_left = requestChannelAttempts - 1
397397
if retries_left <= 0:
398-
our_exit(f"Error: Timed out waiting for channels, giving up")
398+
our_exit("Error: Timed out waiting for channels, giving up")
399399
print("Timed out trying to retrieve channel info, retrying")
400400
n.requestChannels(startingIndex=new_index)
401401
last_index = new_index
@@ -942,8 +942,10 @@ def _sendPacket(
942942
else:
943943
our_exit("Warning: No myInfo found.")
944944
# A simple hex style nodeid - we can parse this without needing the DB
945-
elif destinationId.startswith("!"):
946-
nodeNum = int(destinationId[1:], 16)
945+
elif isinstance(destinationId, str) and len(destinationId) >= 8:
946+
# assuming some form of node id string such as !1234578 or 0x12345678
947+
# always grab the last 8 items of the hexadecimal id str and parse to integer
948+
nodeNum = int(destinationId[-8:], 16)
947949
else:
948950
if self.nodes:
949951
node = self.nodes.get(destinationId)
@@ -977,7 +979,7 @@ def _sendPacket(
977979
toRadio.packet.CopyFrom(meshPacket)
978980
if self.noProto:
979981
logging.warning(
980-
f"Not sending packet because protocol use is disabled by noProto"
982+
"Not sending packet because protocol use is disabled by noProto"
981983
)
982984
else:
983985
logging.debug(f"Sending packet: {stripnl(meshPacket)}")
@@ -1166,7 +1168,7 @@ def _sendToRadio(self, toRadio: mesh_pb2.ToRadio) -> None:
11661168
"""Send a ToRadio protobuf to the device"""
11671169
if self.noProto:
11681170
logging.warning(
1169-
f"Not sending packet because protocol use is disabled by noProto"
1171+
"Not sending packet because protocol use is disabled by noProto"
11701172
)
11711173
else:
11721174
# logging.debug(f"Sending toRadio: {stripnl(toRadio)}")

0 commit comments

Comments
 (0)
Please sign in to comment.