send udp message to feeder

inform the history feeder in case of a SECoP server without
UDP mechanism
This commit is contained in:
2025-04-29 07:57:49 +02:00
parent b96a7dec1c
commit 43853ae49c

View File

@ -27,6 +27,8 @@ connected to a SEC node
""" """
import threading import threading
import socket
import json
from nicos import config, session from nicos import config, session
from nicos.core import Override, Param, Moveable, status, POLLER, SIMULATION, DeviceAlias, \ from nicos.core import Override, Param, Moveable, status, POLLER, SIMULATION, DeviceAlias, \
Device, anytype, listof, MASTER Device, anytype, listof, MASTER
@ -38,6 +40,8 @@ from nicos.commands.basic import AddSetup, CreateAllDevices, CreateDevice
from nicos.utils import loggers from nicos.utils import loggers
from servicemanager import FrappyManager, SeaManager, Reconnect, Keep from servicemanager import FrappyManager, SeaManager, Reconnect, Keep
SECOP_UDP_PORT = 10767
SERVICES = FrappyManager.services SERVICES = FrappyManager.services
@ -113,6 +117,21 @@ def get_frappy_config():
return None return None
def send_other_udp(uri, instrument, device=None):
"""inform the feeder about the start of a frappy server"""
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
msg = {
'SECoP': 'for_other_node',
'uri': uri,
'instrument': instrument,
}
if device:
msg['device'] = device
msg = json.dumps(msg, ensure_ascii=False, separators=(',', ':')).encode('utf-8')
sock.sendto(msg, ('255.255.255.255', SECOP_UDP_PORT))
class FrappyConfig(Device): class FrappyConfig(Device):
# respect the order: e.g. temperature_regulation must be after temperature # respect the order: e.g. temperature_regulation must be after temperature
# because it will not be added to envlist when temperature is the same device # because it will not be added to envlist when temperature is the same device
@ -830,8 +849,10 @@ class FrappyNode(SecNodeDevice, Moveable):
if available_cfg is not None: if available_cfg is not None:
raise ValueError('use "frappy_list()" to get a list of valid frappy configurations') raise ValueError('use "frappy_list()" to get a list of valid frappy configurations')
uri = 'localhost:%d' % info[self.service] uri = 'localhost:%d' % info[self.service]
send_other_udp(uri, config.instrument, device=cfg)
else: else:
uri = cfg uri = cfg
send_other_udp(uri, config.instrument)
if uri != self.uri: if uri != self.uri:
self._disconnect(keeptarget=True) self._disconnect(keeptarget=True)
if uri: if uri: