Low-Energy Muon (LEM) Experiment  0.5.2
mirror.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include "midas.h"
#include "mirror.h"
#include "ets_logout.h"
Include dependency graph for mirror.c:

Go to the source code of this file.

Data Structures

struct  MIRROR_DD_SETTINGS
 stores internal informations within the DD. More...
 
struct  MIRROR_INFO
 This structure contains private variables for the device driver. More...
 

Macros

#define MIRROR_ETS_LOGOUT_SLEEP   10000
 sleep time (us) between the telnet commands of the ets_logout More...
 
#define MIRROR_SETTINGS_DD_STR   "\ETS_IN_USE = INT : 1\n\TCPIPTimeOut = INT : 500\n\MirrorADC45 = INT : 1976\n\Names = STRING[2] :\n\[32] Reset\n\[32] Angle\n\"
 initializing string for MIRROR_DD_SETTINGS More...
 

Functions

INT mirror_init (HNDLE hKey, void **pinfo, INT channels, INT(*bd)(INT cmd,...))
 
INT mirror_exit (MIRROR_INFO *info)
 
INT mirror_get_current_position (MIRROR_INFO *info, char *str)
 
INT mirror_move_to_position (MIRROR_INFO *info, char *cmd, char *str, int max_try)
 
BOOL reset_mirror_position (MIRROR_INFO *info)
 
BOOL mirror_position_reached (MIRROR_INFO *info, char *cmd, float value)
 
INT mirror_set (MIRROR_INFO *info, INT channel, float value)
 
INT mirror_get (MIRROR_INFO *info, INT channel, float *pvalue)
 
INT mirror_get_label (MIRROR_INFO *info, INT channel, char *name)
 
INT mirror (INT cmd,...)
 

Variables

int histo [MIRROR_MAX_TRY]
 

Macro Definition Documentation

#define MIRROR_ETS_LOGOUT_SLEEP   10000

sleep time (us) between the telnet commands of the ets_logout

Definition at line 37 of file mirror.c.

Referenced by mirror_get().

#define MIRROR_SETTINGS_DD_STR   "\ETS_IN_USE = INT : 1\n\TCPIPTimeOut = INT : 500\n\MirrorADC45 = INT : 1976\n\Names = STRING[2] :\n\[32] Reset\n\[32] Angle\n\"

initializing string for MIRROR_DD_SETTINGS

Definition at line 50 of file mirror.c.

Referenced by mirror_init().

Function Documentation

INT mirror ( INT  cmd,
  ... 
)

mirror device driver (DD). It is handling the communication between the mirror and midas. The mirror is used to deflect the low energy muons in the $\mathrm{LE-\mu SR}$ beamline. The device driver can remotly rotated the mirror.

Definition at line 635 of file mirror.c.

References hKey, info, mirror_exit(), mirror_get(), mirror_get_label(), mirror_init(), and mirror_set().

INT mirror_exit ( MIRROR_INFO info)

terminates the bus driver and free's the memory allocated for the info structure MIRROR_INFO.

Return: FE_SUCCESS

Parameters
infois a pointer to the DD specific info structure

Definition at line 178 of file mirror.c.

References MIRROR_INFO::bd, and MIRROR_INFO::bd_info.

Referenced by mirror().

INT mirror_get ( MIRROR_INFO info,
INT  channel,
float *  pvalue 
)

tries to read back the current position

Return:

  • current position if the mirror is not moving
  • -111 if the controller didn't react or was too busy
  • -222 if the mirror is still moving
Parameters
infois a pointer to the DD specific info structure.
channelnumber
pvaluepoint to the read back value

Definition at line 519 of file mirror.c.

References MIRROR_INFO::bd, MIRROR_INFO::bd_connected, MIRROR_INFO::bd_info, MIRROR_INFO::errorcount, MIRROR_DD_SETTINGS::ets_in_use, ets_logout(), MIRROR_INFO::hDB, histo, MIRROR_INFO::hkey, MIRROR_INFO::hKeyInfo, MIRROR_INFO::last_reconnect, MIRROR_INFO::last_value, MIRROR_INFO::lasterrtime, MIRROR_INFO::mirror_dd_settings, MIRROR_DEBUG, MIRROR_DELTA_TIME_ERROR, MIRROR_ETS_LOGOUT_SLEEP, mirror_get_current_position(), MIRROR_MAX_STR, MIRROR_MAX_TRY, MIRROR_INFO::reconnection_failures, and MIRROR_INFO::startup_error.

Referenced by mirror().

INT mirror_get_current_position ( MIRROR_INFO info,
char *  str 
)

Since the mirror controller does not always reply, this routine was introduced. It loops for maximal MAX_TRY trying to get a reply from the mirror controller. The mirror controller sends a 'HS' (handshake) if it is back ready from moving, LCD updating, ... in order to reply properly. It sends a 'ES' if the end switches were reached.

Return: number of read characters

Parameters
infois a pointer to the DD specific info structure.
stris the readback string

Definition at line 202 of file mirror.c.

References MIRROR_INFO::mirror_dd_settings, MIRROR_DEBUG, MIRROR_MAX_STR, MIRROR_MAX_TRY, MIRROR_WAIT, and MIRROR_DD_SETTINGS::time_out.

Referenced by mirror_get(), mirror_position_reached(), mirror_set(), and reset_mirror_position().

INT mirror_get_label ( MIRROR_INFO info,
INT  channel,
char *  name 
)

at startup, after initialization of the DD, this routine allows to write default names of the channels into the ODB.

Return: FE_SUCCESS

Parameters
infois a pointer to the DD specific info structure
channelof the name to be set
namepointer to the ODB name

Definition at line 628 of file mirror.c.

References MIRROR_INFO::mirror_dd_settings, and MIRROR_DD_SETTINGS::names.

Referenced by mirror().

INT mirror_init ( HNDLE  hKey,
void **  pinfo,
INT  channels,
INT(*)(INT cmd,...)  bd 
)

Initializes the mirror device driver, i.e. generates all the necessary structures in the ODB if necessary, initializes the bus driver and the mirror controller.

Return:

  • FE_SUCCESS if everything went smooth
  • FE_ERR_ODB otherwise
Parameters
hKeyis the device driver handle given from the class driver
pinfois needed to store the internal info structure
channelsis the number of channels of the device (from the class driver)
bdis a pointer to the bus driver

Definition at line 95 of file mirror.c.

References MIRROR_INFO::bd, MIRROR_INFO::bd_connected, MIRROR_INFO::bd_info, MIRROR_INFO::errorcount, MIRROR_INFO::hDB, hDB, histo, MIRROR_INFO::hkey, hKey, MIRROR_INFO::hKeyDemand, MIRROR_INFO::hKeyInfo, info, MIRROR_INFO::last_reconnect, MIRROR_INFO::lasterrtime, MIRROR_INFO::mirror_dd_settings, MIRROR_DEBUG, MIRROR_MAX_TRY, MIRROR_SETTINGS_DD_STR, MIRROR_INFO::reconnection_failures, and MIRROR_INFO::startup_error.

Referenced by mirror().

INT mirror_move_to_position ( MIRROR_INFO info,
char *  cmd,
char *  str,
int  max_try 
)

This routine moves the mirror to the new position and stays in the routine until this new position is indeed reached or 'max_try' attempts are carried out.

Return: number of characters read

Parameters
infois a pointer to the DD specific info structure.
cmdis the command string
stris the read back position
max_tryis the maximal number to attempt to do the job

Definition at line 244 of file mirror.c.

References MIRROR_INFO::mirror_dd_settings, MIRROR_MAX_STR, MIRROR_WAIT, and MIRROR_DD_SETTINGS::time_out.

Referenced by mirror_position_reached(), and reset_mirror_position().

BOOL mirror_position_reached ( MIRROR_INFO info,
char *  cmd,
float  value 
)

checks if the mirror reached the requested position.

Return:

  • TRUE if the mirror position is reached
  • FALSE otherwise.
Parameters
infois a pointer to the DD specific info structure.
cmdis the command string
valueis the requested position

Definition at line 366 of file mirror.c.

References MIRROR_DEBUG, mirror_get_current_position(), MIRROR_MAX_STR, MIRROR_MAX_TRY, and mirror_move_to_position().

Referenced by mirror_set().

INT mirror_set ( MIRROR_INFO info,
INT  channel,
float  value 
)

This routine is used to set a new angle, but further it is abused as a reset position routine (see code). Furthermore, if the demand value is less than 0.1 devating from the measured value, NOTHING is going to be done.

Return:

  • FE_SUCCESS is everything went smooth
  • FE_ERR_HW otherwise
Parameters
infois a pointer to the DD specific info structure.
channelnumber
valueto be set

Definition at line 411 of file mirror.c.

References MIRROR_DD_SETTINGS::adc_45, MIRROR_INFO::hDB, MIRROR_INFO::hKeyDemand, MIRROR_INFO::mirror_dd_settings, mirror_get_current_position(), MIRROR_MAX_STR, mirror_position_reached(), and reset_mirror_position().

Referenced by mirror().

BOOL reset_mirror_position ( MIRROR_INFO info)

This routine resets the mirror position, i.e. the following:

  • it moves to negative angles till the end switches are reached
  • it moves back to the position given in the ODB DD structure with the name 'MirrorADC45' where the ADC value (NOT angle) of the 45 position should be written.

Return: TRUE if reset was performed properly, otherwise FALSE

Parameters
infois a pointer to the DD specific info structure.

Definition at line 271 of file mirror.c.

References MIRROR_DD_SETTINGS::adc_45, MIRROR_INFO::mirror_dd_settings, MIRROR_DEBUG, mirror_get_current_position(), MIRROR_MAX_STR, MIRROR_MAX_TRY, and mirror_move_to_position().

Referenced by mirror_set().

Variable Documentation

int histo[MIRROR_MAX_TRY]

Definition at line 78 of file mirror.c.

Referenced by mirror_get(), and mirror_init().