2022-01-11 07:27:16 -05:00
|
|
|
#!/bin/env python3
|
2024-02-29 21:55:49 +01:00
|
|
|
""" Example Python config
|
2022-01-11 07:27:16 -05:00
|
|
|
|
|
|
|
This example demonstrates how you can use Python to generate complex
|
|
|
|
configuration files.
|
|
|
|
|
|
|
|
To use this configuration, run the following commands:
|
|
|
|
|
|
|
|
villas node <(python3 etc/python/example.py)
|
|
|
|
|
2022-03-15 09:18:01 -04:00
|
|
|
Author: Steffen Vogel <post@steffenvogel.de>
|
2022-03-15 09:28:57 -04:00
|
|
|
SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
2022-07-04 18:20:03 +02:00
|
|
|
SPDX-License-Identifier: Apache-2.0
|
2024-02-29 21:55:49 +01:00
|
|
|
"""
|
2022-01-11 07:27:16 -05:00
|
|
|
|
|
|
|
import json
|
|
|
|
import sys
|
|
|
|
|
|
|
|
N = 10
|
|
|
|
|
|
|
|
nodes = {
|
2024-02-29 21:55:49 +01:00
|
|
|
"raspberry": {
|
|
|
|
"type": "socket",
|
|
|
|
"layer": "udp",
|
|
|
|
"format": "protobuf",
|
|
|
|
"in": {
|
|
|
|
"address": "*:12000",
|
2022-01-11 07:27:16 -05:00
|
|
|
},
|
2024-02-29 21:55:49 +01:00
|
|
|
"out": {"address": "1.2.3.4:12000"},
|
2022-01-11 07:27:16 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for i in range(N):
|
2024-02-29 21:55:49 +01:00
|
|
|
name = f"agent{i}"
|
2022-01-11 07:27:16 -05:00
|
|
|
port = 12000 + i
|
|
|
|
|
|
|
|
nodes[name] = {
|
2024-02-29 21:55:49 +01:00
|
|
|
"type": "socket",
|
|
|
|
"layer": "udp",
|
|
|
|
"format": "protobuf",
|
|
|
|
"in": {"address": "*:12000", "signals": [{"name": "in", "type": "float"}]},
|
|
|
|
"out": {"address": f"5.6.7.8:{port}"},
|
2022-01-11 07:27:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
paths = [
|
|
|
|
{
|
2024-02-29 21:55:49 +01:00
|
|
|
"in": [f"agent{i}" for i in range(N)],
|
|
|
|
"out": "raspberry",
|
|
|
|
"mode": "any",
|
|
|
|
"hooks": [{"type": "print"}],
|
2022-01-11 07:27:16 -05:00
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2024-02-29 21:55:49 +01:00
|
|
|
config = {"nodes": nodes, "paths": paths}
|
2022-01-11 07:27:16 -05:00
|
|
|
|
|
|
|
json.dump(config, sys.stdout, indent=2)
|