more remote node support

This commit is contained in:
Kevin Hester
2021-03-11 11:11:27 +08:00
parent b78cb73c51
commit 26c4715ac9
3 changed files with 33 additions and 15 deletions

2
.vscode/launch.json vendored
View File

@@ -18,7 +18,7 @@
"request": "launch",
"module": "meshtastic",
"justMyCode": true,
"args": ["--info"]
"args": ["--info", "--debug"]
},
{
"name": "meshtastic tunnel",

View File

@@ -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']

View File

@@ -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")