add commandline option for setting radio configs

This commit is contained in:
geeksville
2020-05-03 20:14:11 -07:00
parent 8254a2b481
commit dbbf14c4bf
3 changed files with 36 additions and 9 deletions

View File

@@ -2,7 +2,6 @@
## Before beta
- make command line options for displaying/changing config
- update nodedb as nodes change
- radioConfig - getter/setter syntax: https://www.python-course.eu/python3_properties.php
- let user change radio params via commandline options
@@ -35,3 +34,4 @@
- DONE keep everything in dicts
- DONE have device send a special packet at boot so the serial client can detect if it rebooted
- DONE add fromId and toId to received messages dictionaries
- make command line options for displaying/changing config

View File

@@ -121,6 +121,15 @@ class MeshInterface:
toRadio.packet.CopyFrom(meshPacket)
self._sendToRadio(toRadio)
def writeConfig(self):
"""Write the current (edited) radioConfig to the device"""
if self.radioConfig == None:
raise Exception("No RadioConfig has been read")
t = mesh_pb2.ToRadio()
t.set_radio.CopyFrom(self.radioConfig)
self._sendToRadio(t)
def _disconnected(self):
"""Called by subclasses to tell clients this interface has disconnected"""
self.isConnected = False

View File

@@ -20,14 +20,27 @@ def onConnection(interface, topic=pub.AUTO_TOPIC):
"""Callback invoked when we connect/disconnect from a radio"""
print(f"Connection changed: {topic.getName()}")
global args
if topic.getName() == "meshtastic.connection.established" and args.info:
print(interface.myInfo)
print(interface.radioConfig)
interface.close()
print("Nodes in mesh:")
for n in interface.nodes.values():
asDict = google.protobuf.json_format.MessageToJson(n)
print(asDict)
if topic.getName() == "meshtastic.connection.established":
try:
if args.setpref:
name = args.setpref[0]
val = int(args.setpref[1])
setattr(interface.radioConfig.preferences, name, val)
print("Writing modified preferences to device...")
interface.writeConfig()
if args.info:
print(interface.myInfo)
print(interface.radioConfig)
print("Nodes in mesh:")
for n in interface.nodes.values():
asDict = google.protobuf.json_format.MessageToJson(n)
print(asDict)
except Exception as ex:
print(ex)
if args.info or args.setpref:
interface.close() # after running command then exit
def onNode(node):
@@ -59,6 +72,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("--debug", help="Show API library debug log messages",
action="store_true")
@@ -69,6 +84,9 @@ def main():
args = parser.parse_args()
logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO)
if args.info or args.setpref:
args.seriallog = "none" # assume no debug output in this case
if args.test:
test.testAll()
else: