From 26c4715ac94a05b624c04e040d9c99627735b781 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Thu, 11 Mar 2021 11:11:27 +0800 Subject: [PATCH] more remote node support --- .vscode/launch.json | 2 +- meshtastic/__init__.py | 33 ++++++++++++++++++++++++--------- meshtastic/__main__.py | 13 ++++++++----- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 895b0ce..9b8efbe 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -18,7 +18,7 @@ "request": "launch", "module": "meshtastic", "justMyCode": true, - "args": ["--info"] + "args": ["--info", "--debug"] }, { "name": "meshtastic tunnel", diff --git a/meshtastic/__init__.py b/meshtastic/__init__.py index d4be93b..382eb31 100644 --- a/meshtastic/__init__.py +++ b/meshtastic/__init__.py @@ -57,7 +57,16 @@ interface = meshtastic.SerialInterface() import pygatt import google.protobuf.json_format -import serial, threading, logging, sys, random, traceback, time, base64, platform, socket +import serial +import threading +import logging +import sys +import random +import traceback +import time +import base64 +import platform +import socket from . import mesh_pb2, portnums_pb2, apponly_pb2, admin_pb2, environmental_measurement_pb2, remote_hardware_pb2, channel_pb2, radioconfig_pb2, util from .util import fixme, catchAndIgnore, stripnl from pubsub import pub @@ -71,7 +80,11 @@ HEADER_LEN = 4 MAX_TO_FROM_RADIO_SIZE = 512 defaultHopLimit = 3 -BROADCAST_ADDR = "^all" # A special ID that means broadcast +"""A special ID that means broadcast""" +BROADCAST_ADDR = "^all" + +"""A special ID that means the local node""" +LOCAL_ADDR = "^local" # if using 8 bit nodenums this will be shortend on the target BROADCAST_NUM = 0xffffffff @@ -126,7 +139,7 @@ class Node: def showInfo(self): """Show human readable description of our node""" - print(self.radioConfig) + print(self.radioConfig) print("Channels:") for c in self.channels: if c.role != channel_pb2.Channel.Role.DISABLED: @@ -254,9 +267,9 @@ class Node: """A closure to handle the response packet""" self.radioConfig = p["decoded"]["admin"]["raw"].get_radio_response - return self._sendAdmin(p, - wantResponse=True, - onResponse=onResponse) + return self._sendAdmin(p, + wantResponse=True, + onResponse=onResponse) def _requestChannel(self, channelNum: int): """ @@ -288,11 +301,11 @@ class Node: self._requestChannel(index + 1) return self._sendAdmin(p, - wantResponse=True, - onResponse=onResponse) + wantResponse=True, + onResponse=onResponse) def _sendAdmin(self, p: admin_pb2.AdminMessage, wantResponse=False, - onResponse=None): + onResponse=None): """Send an admin message to the specified node (or the local node if destNodeNum is zero)""" return self.iface.sendData(p, self.nodeNum, @@ -468,6 +481,8 @@ class MeshInterface: nodeNum = destinationId elif destinationId == BROADCAST_ADDR: nodeNum = BROADCAST_NUM + elif destinationId == LOCAL_ADDR: + nodeNum = self.myInfo.my_node_num else: nodeNum = self.nodes[destinationId]['num'] diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index 3251c4c..6d24327 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -253,7 +253,7 @@ def onConnected(interface): prefs, pref[0], pref[1]) print("Writing modified preferences to device") - interface.writeConfig() + interface.localNode.writeConfig() if args.seturl: closeNow = True @@ -342,10 +342,13 @@ def common(): parser.print_help(sys.stderr) sys.exit(1) else: - # Some commands require dest to be set, so we now use destOrAll for more lenient commands - args.destOrAll = args.dest - if not args.destOrAll: + # Some commands require dest to be set, so we now use destOrAll/destOrLocal for more lenient commands + if not args.dest: args.destOrAll = "^all" + args.destOrLocal = "^local" + else: + args.destOrAll = args.dest + args.destOrLocal = args.dest if not args.seriallog: if args.info or args.nodes or args.set or args.seturl or args.setowner or args.setlat or args.setlon or \ @@ -432,7 +435,7 @@ def initParser(): "--setowner", help="Set device owner name", action="store") parser.add_argument( - "--dest", help="The destination node id for any sent commands, if not set '^all' is assumed", default=None) + "--dest", help="The destination node id for any sent commands, if not set '^all' or '^local' is assumed as appropriate", default=None) parser.add_argument( "--sendtext", help="Send a text message")