mirror of
https://github.com/meshtastic/python.git
synced 2025-12-31 03:47:55 -05:00
1.2.12
This commit is contained in:
@@ -258,15 +258,37 @@ class Node:
|
||||
self._sendAdmin(p)
|
||||
logging.debug("Wrote config")
|
||||
|
||||
def writeChannel(self, channelIndex):
|
||||
def writeChannel(self, channelIndex, adminIndex = 0):
|
||||
"""Write the current (edited) channel to the device"""
|
||||
|
||||
p = admin_pb2.AdminMessage()
|
||||
p.set_channel.CopyFrom(self.channels[channelIndex])
|
||||
|
||||
self._sendAdmin(p)
|
||||
self._sendAdmin(p, adminIndex=adminIndex)
|
||||
logging.debug("Wrote channel {channelIndex}")
|
||||
|
||||
def deleteChannel(self, channelIndex):
|
||||
"""Delete the specifed channelIndex and shift other channels up"""
|
||||
ch = self.channels[channelIndex]
|
||||
if ch.role != channel_pb2.Channel.Role.SECONDARY:
|
||||
raise Exception("Only SECONDARY channels can be deleted")
|
||||
|
||||
# we are careful here because if we move the "admin" channel the channelIndex we need to use
|
||||
# for sending admin channels will also change
|
||||
adminIndex = self.iface.localNode._getAdminChannelIndex()
|
||||
|
||||
self.channels.pop(channelIndex)
|
||||
self._fixupChannels() # expand back to 8 channels
|
||||
|
||||
index = channelIndex
|
||||
while index < self.iface.myInfo.max_channels:
|
||||
self.writeChannel(index, adminIndex=adminIndex)
|
||||
index += 1
|
||||
|
||||
# if we are updating the local node, we might end up *moving* the admin channel index as we are writing
|
||||
if (self.iface.localNode == self) and index >= adminIndex:
|
||||
adminIndex = 0 # We've now passed the old location for admin index (and writen it), so we can start finding it by name again
|
||||
|
||||
def getChannelByName(self, name):
|
||||
"""Try to find the named channel or return None"""
|
||||
for c in (self.channels or []):
|
||||
@@ -389,6 +411,27 @@ class Node:
|
||||
|
||||
return self._sendAdmin(p)
|
||||
|
||||
def _fixupChannels(self):
|
||||
"""Fixup indexes and add disabled channels as needed"""
|
||||
|
||||
# Add extra disabled channels as needed
|
||||
for index, ch in enumerate(self.channels):
|
||||
ch.index = index # fixup indexes
|
||||
|
||||
self._fillChannels()
|
||||
|
||||
def _fillChannels(self):
|
||||
"""Mark unused channels as disabled"""
|
||||
|
||||
# Add extra disabled channels as needed
|
||||
index = len(self.channels)
|
||||
while index < self.iface.myInfo.max_channels:
|
||||
ch = channel_pb2.Channel()
|
||||
ch.role = channel_pb2.Channel.Role.DISABLED
|
||||
ch.index = index
|
||||
self.channels.append(ch)
|
||||
index += 1
|
||||
|
||||
def _requestChannel(self, channelNum: int):
|
||||
"""
|
||||
Done with initial config messages, now send regular MeshPackets to ask for settings
|
||||
@@ -414,16 +457,9 @@ class Node:
|
||||
if quitEarly or index >= self.iface.myInfo.max_channels - 1:
|
||||
logging.debug("Finished downloading channels")
|
||||
|
||||
# Fill the rest of array with DISABLED channels
|
||||
index += 1
|
||||
while index < self.iface.myInfo.max_channels:
|
||||
ch = channel_pb2.Channel()
|
||||
ch.role = channel_pb2.Channel.Role.DISABLED
|
||||
ch.index = index
|
||||
self.partialChannels.append(ch)
|
||||
index += 1
|
||||
|
||||
self.channels = self.partialChannels
|
||||
self._fixupChannels()
|
||||
|
||||
# FIXME, the following should only be called after we have settings and channels
|
||||
self.iface._connected() # Tell everone else we are ready to go
|
||||
else:
|
||||
@@ -434,15 +470,19 @@ class Node:
|
||||
onResponse=onResponse)
|
||||
|
||||
def _sendAdmin(self, p: admin_pb2.AdminMessage, wantResponse=False,
|
||||
onResponse=None):
|
||||
onResponse=None,
|
||||
adminIndex=0):
|
||||
"""Send an admin message to the specified node (or the local node if destNodeNum is zero)"""
|
||||
|
||||
if adminIndex == 0: # unless a special channel index was used, we want to use the admin index
|
||||
adminIndex = self.iface.localNode._getAdminChannelIndex()
|
||||
|
||||
return self.iface.sendData(p, self.nodeNum,
|
||||
portNum=portnums_pb2.PortNum.ADMIN_APP,
|
||||
wantAck=True,
|
||||
wantResponse=wantResponse,
|
||||
onResponse=onResponse,
|
||||
channelIndex=self.iface.localNode._getAdminChannelIndex())
|
||||
channelIndex=adminIndex)
|
||||
|
||||
|
||||
class MeshInterface:
|
||||
@@ -2321,15 +2361,37 @@ wantResponse – True if you want the service on the other side to send an a
|
||||
self._sendAdmin(p)
|
||||
logging.debug("Wrote config")
|
||||
|
||||
def writeChannel(self, channelIndex):
|
||||
def writeChannel(self, channelIndex, adminIndex = 0):
|
||||
"""Write the current (edited) channel to the device"""
|
||||
|
||||
p = admin_pb2.AdminMessage()
|
||||
p.set_channel.CopyFrom(self.channels[channelIndex])
|
||||
|
||||
self._sendAdmin(p)
|
||||
self._sendAdmin(p, adminIndex=adminIndex)
|
||||
logging.debug("Wrote channel {channelIndex}")
|
||||
|
||||
def deleteChannel(self, channelIndex):
|
||||
"""Delete the specifed channelIndex and shift other channels up"""
|
||||
ch = self.channels[channelIndex]
|
||||
if ch.role != channel_pb2.Channel.Role.SECONDARY:
|
||||
raise Exception("Only SECONDARY channels can be deleted")
|
||||
|
||||
# we are careful here because if we move the "admin" channel the channelIndex we need to use
|
||||
# for sending admin channels will also change
|
||||
adminIndex = self.iface.localNode._getAdminChannelIndex()
|
||||
|
||||
self.channels.pop(channelIndex)
|
||||
self._fixupChannels() # expand back to 8 channels
|
||||
|
||||
index = channelIndex
|
||||
while index < self.iface.myInfo.max_channels:
|
||||
self.writeChannel(index, adminIndex=adminIndex)
|
||||
index += 1
|
||||
|
||||
# if we are updating the local node, we might end up *moving* the admin channel index as we are writing
|
||||
if (self.iface.localNode == self) and index >= adminIndex:
|
||||
adminIndex = 0 # We've now passed the old location for admin index (and writen it), so we can start finding it by name again
|
||||
|
||||
def getChannelByName(self, name):
|
||||
"""Try to find the named channel or return None"""
|
||||
for c in (self.channels or []):
|
||||
@@ -2452,6 +2514,27 @@ wantResponse – True if you want the service on the other side to send an a
|
||||
|
||||
return self._sendAdmin(p)
|
||||
|
||||
def _fixupChannels(self):
|
||||
"""Fixup indexes and add disabled channels as needed"""
|
||||
|
||||
# Add extra disabled channels as needed
|
||||
for index, ch in enumerate(self.channels):
|
||||
ch.index = index # fixup indexes
|
||||
|
||||
self._fillChannels()
|
||||
|
||||
def _fillChannels(self):
|
||||
"""Mark unused channels as disabled"""
|
||||
|
||||
# Add extra disabled channels as needed
|
||||
index = len(self.channels)
|
||||
while index < self.iface.myInfo.max_channels:
|
||||
ch = channel_pb2.Channel()
|
||||
ch.role = channel_pb2.Channel.Role.DISABLED
|
||||
ch.index = index
|
||||
self.channels.append(ch)
|
||||
index += 1
|
||||
|
||||
def _requestChannel(self, channelNum: int):
|
||||
"""
|
||||
Done with initial config messages, now send regular MeshPackets to ask for settings
|
||||
@@ -2477,16 +2560,9 @@ wantResponse – True if you want the service on the other side to send an a
|
||||
if quitEarly or index >= self.iface.myInfo.max_channels - 1:
|
||||
logging.debug("Finished downloading channels")
|
||||
|
||||
# Fill the rest of array with DISABLED channels
|
||||
index += 1
|
||||
while index < self.iface.myInfo.max_channels:
|
||||
ch = channel_pb2.Channel()
|
||||
ch.role = channel_pb2.Channel.Role.DISABLED
|
||||
ch.index = index
|
||||
self.partialChannels.append(ch)
|
||||
index += 1
|
||||
|
||||
self.channels = self.partialChannels
|
||||
self._fixupChannels()
|
||||
|
||||
# FIXME, the following should only be called after we have settings and channels
|
||||
self.iface._connected() # Tell everone else we are ready to go
|
||||
else:
|
||||
@@ -2497,15 +2573,19 @@ wantResponse – True if you want the service on the other side to send an a
|
||||
onResponse=onResponse)
|
||||
|
||||
def _sendAdmin(self, p: admin_pb2.AdminMessage, wantResponse=False,
|
||||
onResponse=None):
|
||||
onResponse=None,
|
||||
adminIndex=0):
|
||||
"""Send an admin message to the specified node (or the local node if destNodeNum is zero)"""
|
||||
|
||||
if adminIndex == 0: # unless a special channel index was used, we want to use the admin index
|
||||
adminIndex = self.iface.localNode._getAdminChannelIndex()
|
||||
|
||||
return self.iface.sendData(p, self.nodeNum,
|
||||
portNum=portnums_pb2.PortNum.ADMIN_APP,
|
||||
wantAck=True,
|
||||
wantResponse=wantResponse,
|
||||
onResponse=onResponse,
|
||||
channelIndex=self.iface.localNode._getAdminChannelIndex())</code></pre>
|
||||
channelIndex=adminIndex)</code></pre>
|
||||
</details>
|
||||
<h3>Instance variables</h3>
|
||||
<dl>
|
||||
@@ -2533,6 +2613,38 @@ def channelURL(self):
|
||||
</dl>
|
||||
<h3>Methods</h3>
|
||||
<dl>
|
||||
<dt id="meshtastic.Node.deleteChannel"><code class="name flex">
|
||||
<span>def <span class="ident">deleteChannel</span></span>(<span>self, channelIndex)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>Delete the specifed channelIndex and shift other channels up</p></div>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def deleteChannel(self, channelIndex):
|
||||
"""Delete the specifed channelIndex and shift other channels up"""
|
||||
ch = self.channels[channelIndex]
|
||||
if ch.role != channel_pb2.Channel.Role.SECONDARY:
|
||||
raise Exception("Only SECONDARY channels can be deleted")
|
||||
|
||||
# we are careful here because if we move the "admin" channel the channelIndex we need to use
|
||||
# for sending admin channels will also change
|
||||
adminIndex = self.iface.localNode._getAdminChannelIndex()
|
||||
|
||||
self.channels.pop(channelIndex)
|
||||
self._fixupChannels() # expand back to 8 channels
|
||||
|
||||
index = channelIndex
|
||||
while index < self.iface.myInfo.max_channels:
|
||||
self.writeChannel(index, adminIndex=adminIndex)
|
||||
index += 1
|
||||
|
||||
# if we are updating the local node, we might end up *moving* the admin channel index as we are writing
|
||||
if (self.iface.localNode == self) and index >= adminIndex:
|
||||
adminIndex = 0 # We've now passed the old location for admin index (and writen it), so we can start finding it by name again</code></pre>
|
||||
</details>
|
||||
</dd>
|
||||
<dt id="meshtastic.Node.exitSimulator"><code class="name flex">
|
||||
<span>def <span class="ident">exitSimulator</span></span>(<span>self)</span>
|
||||
</code></dt>
|
||||
@@ -2722,7 +2834,7 @@ def channelURL(self):
|
||||
</details>
|
||||
</dd>
|
||||
<dt id="meshtastic.Node.writeChannel"><code class="name flex">
|
||||
<span>def <span class="ident">writeChannel</span></span>(<span>self, channelIndex)</span>
|
||||
<span>def <span class="ident">writeChannel</span></span>(<span>self, channelIndex, adminIndex=0)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>Write the current (edited) channel to the device</p></div>
|
||||
@@ -2730,13 +2842,13 @@ def channelURL(self):
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def writeChannel(self, channelIndex):
|
||||
<pre><code class="python">def writeChannel(self, channelIndex, adminIndex = 0):
|
||||
"""Write the current (edited) channel to the device"""
|
||||
|
||||
p = admin_pb2.AdminMessage()
|
||||
p.set_channel.CopyFrom(self.channels[channelIndex])
|
||||
|
||||
self._sendAdmin(p)
|
||||
self._sendAdmin(p, adminIndex=adminIndex)
|
||||
logging.debug("Wrote channel {channelIndex}")</code></pre>
|
||||
</details>
|
||||
</dd>
|
||||
@@ -3258,6 +3370,7 @@ hostname {string} – Hostname/IP address of the device to connect to</p></d
|
||||
<h4><code><a title="meshtastic.Node" href="#meshtastic.Node">Node</a></code></h4>
|
||||
<ul class="two-column">
|
||||
<li><code><a title="meshtastic.Node.channelURL" href="#meshtastic.Node.channelURL">channelURL</a></code></li>
|
||||
<li><code><a title="meshtastic.Node.deleteChannel" href="#meshtastic.Node.deleteChannel">deleteChannel</a></code></li>
|
||||
<li><code><a title="meshtastic.Node.exitSimulator" href="#meshtastic.Node.exitSimulator">exitSimulator</a></code></li>
|
||||
<li><code><a title="meshtastic.Node.getChannelByName" href="#meshtastic.Node.getChannelByName">getChannelByName</a></code></li>
|
||||
<li><code><a title="meshtastic.Node.getDisabledChannel" href="#meshtastic.Node.getDisabledChannel">getDisabledChannel</a></code></li>
|
||||
|
||||
2
setup.py
2
setup.py
@@ -12,7 +12,7 @@ with open("README.md", "r") as fh:
|
||||
# This call to setup() does all the work
|
||||
setup(
|
||||
name="meshtastic",
|
||||
version="1.2.11",
|
||||
version="1.2.12",
|
||||
description="Python API & client shell for talking to Meshtastic devices",
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
|
||||
Reference in New Issue
Block a user