forked from Cyphysecurity/NEFICS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch_src.py
More file actions
36 lines (34 loc) · 1.07 KB
/
Copy pathlaunch_src.py
File metadata and controls
36 lines (34 loc) · 1.07 KB
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
#!/usr/bin/env
import sys
import signal
from threading import Thread
from time import sleep
from rtu import Source, RTU_SOURCE
from simcomm import SimulationHandler
if __name__ == '__main__':
if sys.platform[:3] == 'win':
print('Intended to be executed in a mininet Linux environment.')
sys.exit()
srtu = Source(guid=int(sys.argv[1]), type=RTU_SOURCE, voltage=526315.79)
hrtu = SimulationHandler(srtu)
def catch_sigterm(s, e):
global hrtu
global srtu
hrtu.terminate = True
srtu.terminate = True
signal.signal(signal.SIGINT, catch_sigterm)
signal.signal(signal.SIGTERM, catch_sigterm)
mloop = Thread(target=srtu.loop)
mloop.start()
hrtu.start()
print('Source RTU - ID: %d' % srtu.guid)
while not hrtu.terminate:
try:
print('\rVout: {0:5.3f} V'.format(srtu.voltage), end='')
sleep(1)
except KeyboardInterrupt:
hrtu.terminate = True
srtu.terminate = True
print('')
mloop.join()
hrtu.join()