cli,hitl: allow more settings per invokation, expand example

This commit is contained in:
Robert Jördens 2021-04-08 17:11:44 +02:00
parent a3511f5223
commit 7329d0f241
2 changed files with 10 additions and 9 deletions

View File

@ -22,4 +22,6 @@ python3 -m pip install -r requirements.txt
ping -c 5 -w 20 stabilizer-hitl ping -c 5 -w 20 stabilizer-hitl
# Test the MQTT interface. # Test the MQTT interface.
python3 miniconf.py dt/sinara/stabilizer afe/0 '"G2"' python3 miniconf.py dt/sinara/stabilizer afe/0='"G2"'
python3 miniconf.py dt/sinara/stabilizer afe/0='"G1"' iir_ch/0/0=\
'{"y_min": -32767, "y_max": 32767, "y_offset": 0, "ba": [1.0, 0, 0, 0, 0]}'

View File

@ -85,8 +85,7 @@ def main():
description='Miniconf command line interface.', description='Miniconf command line interface.',
formatter_class=argparse.RawDescriptionHelpFormatter, formatter_class=argparse.RawDescriptionHelpFormatter,
epilog='''Examples: epilog='''Examples:
%(prog)s dt/sinara/stabilizer afe/0 '"G10"' %(prog)s dt/sinara/stabilizer afe/0='"G2"' iir_ch/0/0=\
%(prog)s dt/sinara/stabilizer iir_ch/0/0 \
'{"y_min": -32767, "y_max": 32767, "y_offset": 0, "ba": [1.0, 0, 0, 0, 0]}' '{"y_min": -32767, "y_max": 32767, "y_offset": 0, "ba": [1.0, 0, 0, 0, 0]}'
''') ''')
parser.add_argument('-v', '--verbose', action='count', default=0, parser.add_argument('-v', '--verbose', action='count', default=0,
@ -95,10 +94,8 @@ def main():
help='The MQTT broker address') help='The MQTT broker address')
parser.add_argument('prefix', type=str, parser.add_argument('prefix', type=str,
help='The MQTT topic prefix of the target') help='The MQTT topic prefix of the target')
parser.add_argument('path', type=str, parser.add_argument('settings', metavar="KEY=VALUE", nargs='+',
help='The setting path to configure') help='JSON encoded values for settings path keys.')
parser.add_argument('value', type=str,
help='The value of setting in JSON format')
args = parser.parse_args() args = parser.parse_args()
@ -110,8 +107,10 @@ def main():
async def configure_settings(): async def configure_settings():
interface = await Miniconf.create(args.prefix, args.broker) interface = await Miniconf.create(args.prefix, args.broker)
response = await interface.command(args.path, json.loads(args.value)) for kv in args.settings:
print(response) path, value = kv.split("=", 1)
response = await interface.command(path, json.loads(value))
print(response)
loop.run_until_complete(configure_settings()) loop.run_until_complete(configure_settings())