allow passing multiple --setpref args in a single run

This commit is contained in:
geeksville
2020-06-26 15:42:48 -07:00
parent 7457d3340c
commit 8fe323f7fe
2 changed files with 20 additions and 6 deletions

11
.vscode/launch.json vendored
View File

@@ -4,7 +4,6 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "meshtastic BLE",
"type": "python",
@@ -21,6 +20,14 @@
"justMyCode": true,
"args": ["--debug", "--info"]
},
{
"name": "meshtastic setpref",
"type": "python",
"request": "launch",
"module": "meshtastic",
"justMyCode": true,
"args": ["--debug", "--setpref", "a", "1", "--setpref", "b", "2"]
},
{
"name": "meshtastic shell",
"type": "python",
@@ -35,7 +42,7 @@
"request": "launch",
"module": "meshtastic",
"justMyCode": true,
"args": [ "--debug", "--test"]
"args": ["--debug", "--test"]
},
{
"name": "meshtastic sendtext",

View File

@@ -36,9 +36,15 @@ def onConnected(interface):
wantAck=True, wantResponse=True)
if args.setpref:
name = args.setpref[0]
val = int(args.setpref[1])
setattr(interface.radioConfig.preferences, name, val)
for pref in args.setpref:
name = pref[0]
print(f"Setting preference {name} to {pref[1]}")
# FIXME, currently this tool only supports setting integers
try:
val = int(pref[1])
setattr(interface.radioConfig.preferences, name, val)
except Exception as ex:
print(f"Can't set {name} due to {ex}")
print("Writing modified preferences to device...")
interface.writeConfig()
@@ -85,7 +91,8 @@ def main():
parser.add_argument("--info", help="Read and display the radio config information",
action="store_true")
parser.add_argument("--setpref", help="Set a preferences field", nargs=2)
parser.add_argument(
"--setpref", help="Set a preferences field", nargs=2, action='append')
parser.add_argument(
"--dest", help="The destination node id for the --send commands, if not set '^all' is assumed", default="^all")