shmem-cigre-mv-pf-profiles.py 1.88 KB
Newer Older
Markus Mirz's avatar
Markus Mirz committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#build/Examples/Cxx/Shmem_CIGRE_MV_PowerFlowTest_LoadProfiles
#villas-node Configs/shmem_CIGRE_MV_PF/Shmem_CIGRE_MV.conf

import asyncio
import time

async def run(cmd):
    proc = await asyncio.create_subprocess_shell(
        cmd,
        stdout=asyncio.subprocess.PIPE,
        stderr=asyncio.subprocess.PIPE)

    time.sleep(30)
    proc.kill()
    stdout, stderr = await proc.communicate()

    print(f'[{cmd!r} exited with {proc.returncode}]')
    if stdout:
        print(f'[stdout]\n{stdout.decode()}')
    if stderr:
        print(f'[stderr]\n{stderr.decode()}')

async def main():
    
    await asyncio.gather(
        run('villas-node villas-node.conf'),
        run('sleep 1; echo "hello"'))

villas_conf = """
    nodes = {
        broker1 = {
            type = "mqtt"

            format = "json"
            host = "172.17.0.1"

            in = {
                subscribe = "/powerflow-dpsim"
            }
            out = {
                publish = "/dpsim-powerflow"
            }
        }

        dpsim1 = {
            type = "shmem"

            in = {
                name = "/dpsim1-villas",	# Name of shared memory segment for sending side

                hooks = (
                    {
                        type = "stats"
                    }
                ),
                signals = {
                    count = 30
                    type = "float"
                }
            },
            out = {
                name = "/villas-dpsim1"	# Name of shared memory segment for receiving side
            }
        }
    }

    paths = (
        {
            in = "dpsim1"
            out = "broker1"

            hooks = (
                {
                    type = "limit_rate"
                    rate = 50
                }
            )
        }
    )"""

with open("villas-node.conf", "w") as text_file:
    text_file.write("%s" % villas_conf)

#asyncio.run(main())