use better config ids

This commit is contained in:
Kevin Hester
2021-03-11 11:49:05 +08:00
parent 26c4715ac9
commit eeff6f95ce
2 changed files with 24 additions and 11 deletions

View File

@@ -89,8 +89,6 @@ LOCAL_ADDR = "^local"
# if using 8 bit nodenums this will be shortend on the target
BROADCAST_NUM = 0xffffffff
MY_CONFIG_ID = 42
"""The numeric buildnumber (shared with android apps) specifying the level of device code we are guaranteed to understand
format is Mmmss (where M is 1+the numeric major number. i.e. 20120 means 1.1.20
@@ -357,11 +355,20 @@ class MeshInterface:
def showInfo(self):
"""Show human readable summary about this object"""
print(self.myInfo)
self.localNode.showInfo()
print("Nodes in mesh:")
for n in self.nodes.values():
print(stripnl(n))
def getNode(self, nodeId):
"""Return a node object which contains device settings and channel info"""
if nodeId == LOCAL_ADDR:
return self.localNode
else:
n = Node(self, nodeId)
n.requestConfig()
n.waitForConfig()
return n
def sendText(self, text: AnyStr,
destinationId=BROADCAST_ADDR,
wantAck=False,
@@ -569,7 +576,8 @@ class MeshInterface:
self.nodesByNum = {} # nodes keyed by nodenum
startConfig = mesh_pb2.ToRadio()
startConfig.want_config_id = MY_CONFIG_ID # we don't use this value
self.configId = random.randint(0, 0xffffffff)
startConfig.want_config_id = self.configId
self._sendToRadio(startConfig)
def _sendToRadio(self, toRadio):
@@ -632,7 +640,7 @@ class MeshInterface:
self.nodes[node["user"]["id"]] = node
pub.sendMessage("meshtastic.node.updated",
node=node, interface=self)
elif fromRadio.config_complete_id == MY_CONFIG_ID:
elif fromRadio.config_complete_id == self.configId:
# we ignore the config_complete_id, it is unneeded for our stream API fromRadio.config_complete_id
self._handleConfigComplete()
elif fromRadio.HasField("packet"):

View File

@@ -174,7 +174,9 @@ def onConnected(interface):
try:
global args
print("Connected to radio")
prefs = interface.localNode.radioConfig.preferences
def getNode():
return interface.getNode(args.destOrLocal)
if args.settime or args.setlat or args.setlon or args.setalt:
closeNow = True
@@ -183,6 +185,7 @@ def onConnected(interface):
lat = 0.0
lon = 0.0
time = 0
prefs = interface.localNode.radioConfig.preferences
if args.settime:
time = int(args.settime)
if args.setalt:
@@ -201,7 +204,7 @@ def onConnected(interface):
print("Setting device time/position")
# can include lat/long/alt etc: latitude = 37.5, longitude = -122.1
interface.sendPosition(lat, lon, alt, time)
interface.writeConfig()
interface.localNode.writeConfig()
if args.setowner:
closeNow = True
@@ -246,6 +249,7 @@ def onConnected(interface):
# handle settings
if args.set:
closeNow = True
prefs = getNode().radioConfig.preferences
# Handle the int/float/bool arguments
for pref in args.set:
@@ -253,17 +257,17 @@ def onConnected(interface):
prefs, pref[0], pref[1])
print("Writing modified preferences to device")
interface.localNode.writeConfig()
getNode().writeConfig()
if args.seturl:
closeNow = True
interface.localNode.setURL(args.seturl)
getNode().setURL(args.seturl)
# handle changing channels
if args.setchan or args.setch_longslow or args.setch_shortfast:
closeNow = True
ch = interface.localNode.channels[channelIndex]
ch = getNode().channels[channelIndex]
def setSimpleChannel(modem_config):
"""Set one of the simple modem_config only based channels"""
@@ -289,11 +293,12 @@ def onConnected(interface):
setPref(ch.settings, pref[0], pref[1])
print("Writing modified channels to device")
interface.localNode.writeChannel(channelIndex)
getNode().writeChannel(channelIndex)
if args.info:
closeNow = True
interface.showInfo()
getNode().showInfo()
if args.nodes:
closeNow = True