'--set' works as well, also chained commands

This commit is contained in:
GUVWAF
2023-03-18 21:12:05 +01:00
parent 802768e0cc
commit b2cfebc5a7
2 changed files with 53 additions and 30 deletions

View File

@@ -6,7 +6,7 @@ import base64
import time
from google.protobuf.json_format import MessageToJson
from meshtastic import portnums_pb2, apponly_pb2, admin_pb2, channel_pb2, localonly_pb2
from meshtastic.util import pskToString, stripnl, Timeout, our_exit, fromPSK
from meshtastic.util import pskToString, stripnl, Timeout, our_exit, fromPSK, camel_to_snake
class Node:
@@ -80,29 +80,43 @@ class Node:
self.iface._acknowledgment.receivedAck = True
print("")
if "getConfigResponse" in p["decoded"]["admin"]:
prefs = stripnl(p["decoded"]["admin"]["getConfigResponse"])
print(f"Preferences: {prefs}\n")
resp = p["decoded"]["admin"]["getConfigResponse"]
field = list(resp.keys())[0]
config_type = self.localConfig.DESCRIPTOR.fields_by_name.get(field)
config_values = getattr(self.localConfig, config_type.name)
else:
prefs = stripnl(p["decoded"]["admin"]["getModuleConfigResponse"])
print(f"Module preferences: {prefs}\n")
resp = p["decoded"]["admin"]["getModuleConfigResponse"]
field = list(resp.keys())[0]
config_type = self.moduleConfig.DESCRIPTOR.fields_by_name.get(field)
config_values = getattr(self.moduleConfig, config_type.name)
for key, value in resp[field].items():
setattr(config_values, camel_to_snake(key), value)
print(f"{str(field)}:\n{str(config_values)}")
def requestConfig(self, configType):
print("Requesting config from remote node (this can take a while).")
print("Be sure:")
print(" 1. There is a SECONDARY channel named 'admin'.")
print(" 2. The '--seturl' was used to configure.")
print(" 3. All devices have the same modem config. (i.e., '--ch-longfast')")
localOnly = False
if self == self.iface.localNode:
localOnly = True
onResponse = None
else:
onResponse = self.onResponseRequestSettings
print("Requesting config from remote node (this can take a while).")
print("Be sure:")
print(" 1. There is a SECONDARY channel named 'admin'.")
print(" 2. The '--seturl' was used to configure.")
print(" 3. All devices have the same modem config. (i.e., '--ch-longfast')")
msgIndex = configType.index
if configType.containing_type.full_name == "LocalConfig":
p = admin_pb2.AdminMessage()
p.get_config_request = msgIndex
self._sendAdmin(p, wantResponse=True, onResponse=self.onResponseRequestSettings)
self._sendAdmin(p, wantResponse=True, onResponse=onResponse)
else:
p = admin_pb2.AdminMessage()
p.get_module_config_request = msgIndex
self._sendAdmin(p, wantResponse=True, onResponse=self.onResponseRequestSettings)
self.iface.waitForAckNak()
self._sendAdmin(p, wantResponse=True, onResponse=onResponse)
if not localOnly:
self.iface.waitForAckNak()
def turnOffEncryptionOnPrimaryChannel(self):
"""Turn off encryption on primary channel."""