Files
sehistory/feeder.py
l_samenv 335d0a5078 strip leading underscore from secop parameter names
+ other fixes and debugging prints
2025-03-28 11:37:11 +01:00

46 lines
1.3 KiB
Python

import sys
import socket
from streams import EventStream
from nicoscache import NicosStream
from secop import ScanStream, ScanReply, TrySecopConnect, send_fake_udp
from seinflux import SEHistory
from servicemanager import FrappyManager
def main():
# egen = EventStream(ScanReply(), ScanStream(), n=NicosStream('localhost:14002'))
egen = EventStream(ScanReply(), ScanStream())
db = SEHistory(access='write')
db.enable_write_access()
fm = FrappyManager()
fm.get_info()
host = socket.gethostname().split('.')[0]
cfginfo = {}
for ins, procs in fm.get_procs(cfginfo=cfginfo).items():
for service in procs:
if service in procs:
port = fm.info.get(ins, {}).get(service, {})
if port:
uri = f'{host}:{port}'
print('CREATE', uri, cfginfo.get((ins, service)))
TrySecopConnect(uri)
event_map = {'value': db.add_float, 'error': db.add_error, 'stream': db.add_stream}
try:
while 1:
for kind, *args in egen.get_events():
event_map[kind](*args)
db.flush()
finally:
for kind, *args in egen.finish():
event_map[kind](*args)
db.disconnect()
if len(sys.argv) > 1:
send_fake_udp(*sys.argv[1:])
else:
main()