mirror of
https://github.com/meshtastic/python.git
synced 2026-08-02 10:07:06 -04:00
use better config ids
This commit is contained in:
@@ -89,8 +89,6 @@ LOCAL_ADDR = "^local"
|
|||||||
# if using 8 bit nodenums this will be shortend on the target
|
# if using 8 bit nodenums this will be shortend on the target
|
||||||
BROADCAST_NUM = 0xffffffff
|
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
|
"""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
|
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):
|
def showInfo(self):
|
||||||
"""Show human readable summary about this object"""
|
"""Show human readable summary about this object"""
|
||||||
print(self.myInfo)
|
print(self.myInfo)
|
||||||
self.localNode.showInfo()
|
|
||||||
print("Nodes in mesh:")
|
print("Nodes in mesh:")
|
||||||
for n in self.nodes.values():
|
for n in self.nodes.values():
|
||||||
print(stripnl(n))
|
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,
|
def sendText(self, text: AnyStr,
|
||||||
destinationId=BROADCAST_ADDR,
|
destinationId=BROADCAST_ADDR,
|
||||||
wantAck=False,
|
wantAck=False,
|
||||||
@@ -569,7 +576,8 @@ class MeshInterface:
|
|||||||
self.nodesByNum = {} # nodes keyed by nodenum
|
self.nodesByNum = {} # nodes keyed by nodenum
|
||||||
|
|
||||||
startConfig = mesh_pb2.ToRadio()
|
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)
|
self._sendToRadio(startConfig)
|
||||||
|
|
||||||
def _sendToRadio(self, toRadio):
|
def _sendToRadio(self, toRadio):
|
||||||
@@ -632,7 +640,7 @@ class MeshInterface:
|
|||||||
self.nodes[node["user"]["id"]] = node
|
self.nodes[node["user"]["id"]] = node
|
||||||
pub.sendMessage("meshtastic.node.updated",
|
pub.sendMessage("meshtastic.node.updated",
|
||||||
node=node, interface=self)
|
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
|
# we ignore the config_complete_id, it is unneeded for our stream API fromRadio.config_complete_id
|
||||||
self._handleConfigComplete()
|
self._handleConfigComplete()
|
||||||
elif fromRadio.HasField("packet"):
|
elif fromRadio.HasField("packet"):
|
||||||
|
|||||||
@@ -174,7 +174,9 @@ def onConnected(interface):
|
|||||||
try:
|
try:
|
||||||
global args
|
global args
|
||||||
print("Connected to radio")
|
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:
|
if args.settime or args.setlat or args.setlon or args.setalt:
|
||||||
closeNow = True
|
closeNow = True
|
||||||
@@ -183,6 +185,7 @@ def onConnected(interface):
|
|||||||
lat = 0.0
|
lat = 0.0
|
||||||
lon = 0.0
|
lon = 0.0
|
||||||
time = 0
|
time = 0
|
||||||
|
prefs = interface.localNode.radioConfig.preferences
|
||||||
if args.settime:
|
if args.settime:
|
||||||
time = int(args.settime)
|
time = int(args.settime)
|
||||||
if args.setalt:
|
if args.setalt:
|
||||||
@@ -201,7 +204,7 @@ def onConnected(interface):
|
|||||||
print("Setting device time/position")
|
print("Setting device time/position")
|
||||||
# can include lat/long/alt etc: latitude = 37.5, longitude = -122.1
|
# can include lat/long/alt etc: latitude = 37.5, longitude = -122.1
|
||||||
interface.sendPosition(lat, lon, alt, time)
|
interface.sendPosition(lat, lon, alt, time)
|
||||||
interface.writeConfig()
|
interface.localNode.writeConfig()
|
||||||
|
|
||||||
if args.setowner:
|
if args.setowner:
|
||||||
closeNow = True
|
closeNow = True
|
||||||
@@ -246,6 +249,7 @@ def onConnected(interface):
|
|||||||
# handle settings
|
# handle settings
|
||||||
if args.set:
|
if args.set:
|
||||||
closeNow = True
|
closeNow = True
|
||||||
|
prefs = getNode().radioConfig.preferences
|
||||||
|
|
||||||
# Handle the int/float/bool arguments
|
# Handle the int/float/bool arguments
|
||||||
for pref in args.set:
|
for pref in args.set:
|
||||||
@@ -253,17 +257,17 @@ def onConnected(interface):
|
|||||||
prefs, pref[0], pref[1])
|
prefs, pref[0], pref[1])
|
||||||
|
|
||||||
print("Writing modified preferences to device")
|
print("Writing modified preferences to device")
|
||||||
interface.localNode.writeConfig()
|
getNode().writeConfig()
|
||||||
|
|
||||||
if args.seturl:
|
if args.seturl:
|
||||||
closeNow = True
|
closeNow = True
|
||||||
interface.localNode.setURL(args.seturl)
|
getNode().setURL(args.seturl)
|
||||||
|
|
||||||
# handle changing channels
|
# handle changing channels
|
||||||
if args.setchan or args.setch_longslow or args.setch_shortfast:
|
if args.setchan or args.setch_longslow or args.setch_shortfast:
|
||||||
closeNow = True
|
closeNow = True
|
||||||
|
|
||||||
ch = interface.localNode.channels[channelIndex]
|
ch = getNode().channels[channelIndex]
|
||||||
|
|
||||||
def setSimpleChannel(modem_config):
|
def setSimpleChannel(modem_config):
|
||||||
"""Set one of the simple modem_config only based channels"""
|
"""Set one of the simple modem_config only based channels"""
|
||||||
@@ -289,11 +293,12 @@ def onConnected(interface):
|
|||||||
setPref(ch.settings, pref[0], pref[1])
|
setPref(ch.settings, pref[0], pref[1])
|
||||||
|
|
||||||
print("Writing modified channels to device")
|
print("Writing modified channels to device")
|
||||||
interface.localNode.writeChannel(channelIndex)
|
getNode().writeChannel(channelIndex)
|
||||||
|
|
||||||
if args.info:
|
if args.info:
|
||||||
closeNow = True
|
closeNow = True
|
||||||
interface.showInfo()
|
interface.showInfo()
|
||||||
|
getNode().showInfo()
|
||||||
|
|
||||||
if args.nodes:
|
if args.nodes:
|
||||||
closeNow = True
|
closeNow = True
|
||||||
|
|||||||
Reference in New Issue
Block a user