progress on remote settings

This commit is contained in:
Kevin Hester
2021-03-12 14:08:53 +08:00
parent 4393399b17
commit e5af632c28
3 changed files with 20 additions and 13 deletions

View File

@@ -367,6 +367,7 @@ class MeshInterface:
if nodeId == LOCAL_ADDR:
return self.localNode
else:
logging.info("Requesting configuration from remote node (this could take a while)")
n = Node(self, nodeId)
n.requestConfig()
if not n.waitForConfig(maxsecs = 60):
@@ -620,7 +621,7 @@ class MeshInterface:
fromRadio = mesh_pb2.FromRadio()
fromRadio.ParseFromString(fromRadioBytes)
asDict = google.protobuf.json_format.MessageToDict(fromRadio)
logging.debug(f"Received from radio: {fromRadio}")
# logging.debug(f"Received from radio: {fromRadio}")
if fromRadio.HasField("my_info"):
self.myInfo = fromRadio.my_info
self.localNode.nodeNum = self.myInfo.my_node_num
@@ -694,7 +695,7 @@ class MeshInterface:
try:
return self.nodesByNum[num]["user"]["id"]
except:
logging.warn(f"Node {num} not found for fromId")
logging.debug(f"Node {num} not found for fromId")
return None
def _getOrCreateByNum(self, nodeNum):
@@ -937,8 +938,8 @@ class StreamInterface(MeshInterface):
# logging.debug("reading character")
b = self._readBytes(1)
# logging.debug("In reader loop")
# logging.debug(f"read returned {b}")
if len(b) > 0:
# logging.debug(f"read returned {b}")
c = b[0]
ptr = len(self._rxBuf)

View File

@@ -167,6 +167,7 @@ def setPref(attributes, name, valStr):
except Exception as ex:
print(f"Can't set {name} due to {ex}")
targetNode = None
def onConnected(interface):
"""Callback invoked when we connect to a radio"""
@@ -176,7 +177,11 @@ def onConnected(interface):
print("Connected to radio")
def getNode():
return interface.getNode(args.destOrLocal)
"""This operation could be expensive, so we try to cache the results"""
global targetNode
if not targetNode:
targetNode = interface.getNode(args.destOrLocal)
return targetNode
if args.settime or args.setlat or args.setlon or args.setalt:
closeNow = True
@@ -249,7 +254,7 @@ def onConnected(interface):
# handle settings
if args.set:
closeNow = True
prefs = getNode().radioConfig.preferences
prefs = getNode().radioConfig.preferences
# Handle the int/float/bool arguments
for pref in args.set:
@@ -296,9 +301,11 @@ def onConnected(interface):
getNode().writeChannel(channelIndex)
if args.info:
closeNow = True
interface.showInfo()
if not args.destOrLocal: # If we aren't trying to talk to our local node, don't show it
interface.showInfo()
getNode().showInfo()
closeNow = True # FIXME, for now we leave the link up while talking to remote nodes
if args.nodes:
closeNow = True
@@ -318,7 +325,7 @@ def onConnected(interface):
tunnel.Tunnel(interface, subnet=args.tunnel_net)
except Exception as ex:
print(ex)
print(f"Exception while handling connection: {ex}")
# if the user didn't ask for serial debugging output, we might want to exit after we've done our operation
if (not args.seriallog) and closeNow:
@@ -353,7 +360,7 @@ def common():
args.destOrLocal = "^local"
else:
args.destOrAll = args.dest
args.destOrLocal = args.dest
args.destOrLocal = args.dest # FIXME, temp hack for debugging remove
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 \

View File

@@ -3,8 +3,7 @@ from collections import defaultdict
import serial
import serial.tools.list_ports
from queue import Queue
import threading
import logging
import threading, sys, logging
"""Some devices such as a seger jlink we never want to accidentally open"""
blacklistVids = dict.fromkeys([0x1366])
@@ -64,6 +63,6 @@ class DeferredExecution():
try:
o = self.queue.get()
o()
except Exception as ex:
except:
logging.error(
f"Unexpected exception in deferred execution {ex}")
f"Unexpected error in deferred execution {sys.exc_info()[0]}")