diff --git a/tangostationcontrol/tangostationcontrol/devices/sdp/beamlet.py b/tangostationcontrol/tangostationcontrol/devices/sdp/beamlet.py index e6db319a5b1838bf307e4f56df0d6922c1f17e1b..ae61d77bd51299d8dba44e77422d09d324d1ec53 100644 --- a/tangostationcontrol/tangostationcontrol/devices/sdp/beamlet.py +++ b/tangostationcontrol/tangostationcontrol/devices/sdp/beamlet.py @@ -8,10 +8,10 @@ """ # PyTango imports -from tango.server import device_property -from tango import AttrWriteType -# Additional import +from tango.server import device_property, command +from tango import AttrWriteType, DevVarFloatArray, DevVarULongArray +# Additional import from tangostationcontrol.common.entrypoint import entry from tangostationcontrol.clients.attribute_wrapper import attribute_wrapper from tangostationcontrol.devices.opcua_device import opcua_device @@ -140,9 +140,33 @@ class Beamlet(opcua_device): # Overloaded functions # -------- + # -------- + # internal functions + # -------- + def _calculate_bf_weights(self, phases: numpy.ndarray): + """ Helper function that converts a difference in phase (in radiants) + to a FPGA weight (in complex number) """ + + # Convert array values in complex numbers + unit = numpy.power(2,14) + real = numpy.array(unit * numpy.cos(phases), dtype=numpy.short) + imag = numpy.array(unit * numpy.sin(phases), dtype=numpy.short) + # join 16 bits of imaginary part (MSB) with 16 bits of real part (LSB) + bf_weights = numpy.array( numpy.frombuffer( b''.join([imag,real]), dtype=numpy.uint32 ) ) + + return bf_weights + # -------- # Commands # -------- + @command(dtype_in=DevVarFloatArray, dtype_out=DevVarULongArray) + def calculate_bf_weights(self, phases: numpy.ndarray): + """ converts a difference in phase (in radiants) to a FPGA weight (in complex number) """ + + # Calculate the FPGA weight array + bf_weights = self._calculate_bf_weights(phases) + + return bf_weights # ---------- # Run server