Skip to content

Commit

Permalink
Merge pull request #731 from migillett/464/0x-prefix
Browse files Browse the repository at this point in the history
464: allow for 0x node prefix values
  • Loading branch information
ianmcorvidae authored Feb 19, 2025
2 parents acc4714 + 23ea19c commit 5f174b2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
22 changes: 14 additions & 8 deletions meshtastic/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def setPref(config, comp_name, raw_val) -> bool:
logging.debug(f"valStr:{raw_val} val:{val}")

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

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

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

group.add_argument(
"--remove-node",
help="Tell the destination node to remove a specific node from its DB, by node number or ID",
help="Tell the destination node to remove a specific node from its NodeDB. "
"Use the node ID with a '!' or '0x' prefix or the node number.",
metavar="!xxxxxxxx"
)
group.add_argument(
"--set-favorite-node",
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",
help="Tell the destination node to set the specified node to be favorited on the NodeDB. "
"Use the node ID with a '!' or '0x' prefix or the node number.",
metavar="!xxxxxxxx"
)
group.add_argument(
"--remove-favorite-node",
help="Tell the destination node to set the specified node to be un-favorited on the NodeDB on the device, by number or ID",
help="Tell the destination node to set the specified node to be un-favorited on the NodeDB. "
"Use the node ID with a '!' or '0x' prefix or the node number.",
metavar="!xxxxxxxx"
)
group.add_argument(
"--set-ignored-node",
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",
help="Tell the destination node to set the specified node to be ignored on the NodeDB. "
"Use the node ID with a '!' or '0x' prefix or the node number.",
metavar="!xxxxxxxx"
)
group.add_argument(
"--remove-ignored-node",
help="Tell the destination node to set the specified node to be un-ignored on the NodeDB on the device, by number or ID",
help="Tell the destination node to set the specified node to be un-ignored on the NodeDB. "
"Use the node ID with a '!' or '0x' prefix or the node number.",
metavar="!xxxxxxxx"
)
group.add_argument(
Expand Down
12 changes: 7 additions & 5 deletions meshtastic/mesh_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def getNode(
if new_index != last_index:
retries_left = requestChannelAttempts - 1
if retries_left <= 0:
our_exit(f"Error: Timed out waiting for channels, giving up")
our_exit("Error: Timed out waiting for channels, giving up")
print("Timed out trying to retrieve channel info, retrying")
n.requestChannels(startingIndex=new_index)
last_index = new_index
Expand Down Expand Up @@ -942,8 +942,10 @@ def _sendPacket(
else:
our_exit("Warning: No myInfo found.")
# A simple hex style nodeid - we can parse this without needing the DB
elif destinationId.startswith("!"):
nodeNum = int(destinationId[1:], 16)
elif isinstance(destinationId, str) and len(destinationId) >= 8:
# assuming some form of node id string such as !1234578 or 0x12345678
# always grab the last 8 items of the hexadecimal id str and parse to integer
nodeNum = int(destinationId[-8:], 16)
else:
if self.nodes:
node = self.nodes.get(destinationId)
Expand Down Expand Up @@ -977,7 +979,7 @@ def _sendPacket(
toRadio.packet.CopyFrom(meshPacket)
if self.noProto:
logging.warning(
f"Not sending packet because protocol use is disabled by noProto"
"Not sending packet because protocol use is disabled by noProto"
)
else:
logging.debug(f"Sending packet: {stripnl(meshPacket)}")
Expand Down Expand Up @@ -1166,7 +1168,7 @@ def _sendToRadio(self, toRadio: mesh_pb2.ToRadio) -> None:
"""Send a ToRadio protobuf to the device"""
if self.noProto:
logging.warning(
f"Not sending packet because protocol use is disabled by noProto"
"Not sending packet because protocol use is disabled by noProto"
)
else:
# logging.debug(f"Sending toRadio: {stripnl(toRadio)}")
Expand Down

0 comments on commit 5f174b2

Please sign in to comment.