-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrontend_ucn2_temp.c
208 lines (158 loc) · 5.79 KB
/
frontend_ucn2_temp.c
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/********************************************************************\
Name: frontend.c
Created by: Stefan Ritt
Contents: Example Slow Control Frontend for equipment control
through EPICS channel access.
$Id$
\********************************************************************/
#include <stdio.h>
#include "midas.h"
#include "mfe.h"
#include "generic.h"
#include "epics_ca.h"
/*-- Globals -------------------------------------------------------*/
BOOL equipment_common_overwrite = FALSE;
/* The frontend name (client name) as seen by other MIDAS clients */
const char *frontend_name = "feUCN2TemperaturesEpics";
/* The frontend file name, don't change it */
const char *frontend_file_name = __FILE__;
/* frontend_loop is called periodically if this variable is TRUE */
BOOL frontend_call_loop = TRUE;
/* a frontend status page is displayed with this frequency in ms */
INT display_period = 2000;
/* maximum event size for fragmented events (EQ_FRAGMENTED) */
INT max_event_size_frag = 5 * 1024 * 1024;
/* maximum event size produced by this frontend */
INT max_event_size = 10000000;
/* buffer size to hold events */
INT event_buffer_size = 20000000;
const char *bank_name = "EP2T";
/*-- Equipment list ------------------------------------------------*/
/*
The following statement allocates 33 channels for the beamline
control through the epics channel access device driver. The
EPICS channel names are stored under
/Equipment/Beamline/Settings/Devices/Beamline
while the channel names as the midas slow control sees them are
under
/Equipment/Beamline/Settings/Names
An example set of channel names is saved in the triumf.odb file
in this directory and can be loaded into the ODB with the odbedit
command
load beamline.xml
before the frontend is started. The CMD_SET_LABEL statement
actually defines who determines the label name. If this flag is
set, the CMD_SET_LABEL command in the device driver is disabled,
therefore the label is taken from EPICS, otherwise the label is
taken from MIDAS and set in EPICS.
The same can be done with the demand values. If the command
CMD_SET_DEMAND is disabled, the demand value is always determied
by EPICS.
*/
/* device driver list */
DEVICE_DRIVER epics_driver[] = {
{"UCN2Temperatures", epics_ca, 102, NULL}, /* disable CMD_SET_LABEL */
//{"UCN2Temperatures", epics_ca, 1, NULL}, /* disable CMD_SET_LABEL */
{""}
};
EQUIPMENT equipment[] = {
{"UCN2EpicsTemperature", /* equipment name */
{3, 0, /* event ID, trigger mask */
"SYSTEM", /* event buffer */
EQ_SLOW, /* equipment type */
0, /* event source */
"FIXED", /* format */
TRUE, /* enabled */
RO_RUNNING | RO_TRANSITIONS, /* read when running and on transitions */
10000, /* read every 10 sec */
0, /* stop run after this event limit */
0, /* number of sub events */
1, /* log history every event */
"", "", ""},
cd_gen_read, /* readout routine */
cd_gen, /* class driver main routine */
epics_driver, /* device driver list */
NULL, /* init string */
},
{""}
};
/*-- Dummy routines ------------------------------------------------*/
INT poll_event(INT source, INT count, BOOL test)
{
return 1;
};
INT interrupt_configure(INT cmd, INT source, PTYPE adr)
{
return 1;
};
/*-- Frontend Init -------------------------------------------------*/
INT frontend_init()
{
/* anable/disable certain command in device driver */
return CM_SUCCESS;
}
/*-- Frontend Exit -------------------------------------------------*/
INT frontend_exit()
{
return CM_SUCCESS;
}
/*-- Frontend Loop -------------------------------------------------*/
/* Issue a watchdog counter every second for the Epics world
for R/W access control.
This counter will appear in the measured variable under index 50.
*/
INT frontend_loop()
{
int status, size;
static HNDLE hDB, hWatch=0, hRespond;
static DWORD watchdog_time=0;
static float dog=0.f, cat=0.f;
/* slow down frontend not to eat all CPU cycles */
/* ss_sleep(50); */
cm_yield(500); /* 15Feb05 */
if (ss_time() - watchdog_time > 1)
{
watchdog_time = ss_time();
if (!hWatch)
{
cm_get_experiment_database(&hDB, NULL);
status = db_find_key(hDB, 0, "/equipment/UCN2EpicsTemperature/variables/demand", &hWatch);
status = db_find_key(hDB, 0, "/equipment/UCN2EpicsTemperature/variables/measured", &hRespond);
if (status != DB_SUCCESS) {
cm_msg(MERROR, "frontend_loop", "key not found");
return FE_ERR_HW;
}
}
if (hWatch) {
/* Check if Epics alive */
size = sizeof(float);
db_get_data_index(hDB, hRespond, &cat, &size, 101, TID_FLOAT);
//if (abs(cat - dog) > 10.f)
//cm_msg(MINFO,"feEpics","R/W Access to Epics is in jeopardy!");
db_set_data_index(hDB, hWatch, &dog, sizeof(float), 101, TID_FLOAT);
}
if (!((INT)++dog % 100)) dog = 0.f;
}
return CM_SUCCESS;
}
/*-- Begin of Run --------------------------------------------------*/
INT begin_of_run(INT run_number, char *error)
{
return CM_SUCCESS;
}
/*-- End of Run ----------------------------------------------------*/
INT end_of_run(INT run_number, char *error)
{
return CM_SUCCESS;
}
/*-- Pause Run -----------------------------------------------------*/
INT pause_run(INT run_number, char *error)
{
return CM_SUCCESS;
}
/*-- Resume Run ----------------------------------------------------*/
INT resume_run(INT run_number, char *error)
{
return CM_SUCCESS;
}
/*------------------------------------------------------------------*/