#include <stdio.h>
#include <netdb.h>
#include <string.h>
#include <errno.h>
#include <string>
#include <vector>
#include "midas.h"
#include "mfe.h"
#include "mstrlcpy.h"
#include <sys/time.h>
Go to the source code of this file.
|
int | interrupt_configure (INT cmd, INT source, PTYPE adr) |
|
INT | poll_event (INT source, INT count, BOOL test) |
|
int | frontend_init () |
| Frontend initialization.
|
|
int | frontend_exit () |
| Frontend exit.
|
|
int | begin_of_run (int run, char *err) |
| Begin of Run.
|
|
int | end_of_run (int run, char *err) |
| End of Run.
|
|
int | pause_run (int run, char *err) |
| Pause Run.
|
|
int | resume_run (int run, char *err) |
| Resume Run.
|
|
int | frontend_loop () |
| Frontend loop.
|
|
int | read_event (char *pevent, INT off) |
|
static double | GetTimeSec () |
|
int | open_udp_socket (int server_port) |
|
bool | addr_match (const Source *s, void *addr, int addr_len) |
|
int | wait_udp (int socket, int msec) |
|
int | find_source (Source *src, const sockaddr *paddr, int addr_len) |
|
int | read_udp (int socket, char *buf, int bufsize, char *pbankname) |
|
◆ EQ_EVID
◆ EQ_NAME
◆ MAX_UDP_SIZE
#define MAX_UDP_SIZE (0x10000) |
◆ addr_match()
Definition at line 150 of file feudp.cxx.
151{
153#if 0
157#endif
158 return v==0;
159}
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
◆ begin_of_run()
Begin of Run.
Called every run start transition. Set equipment status in ODB, start acquisition on the modules.
- Parameters
-
[in] | run_number | Number of the run being started |
[out] | error | Can be used to write a message string to midas.log |
Definition at line 361 of file feudp.cxx.
362{
366}
static int gUnknownPacketCount
static bool gSkipUnknownPackets
◆ end_of_run()
End of Run.
Called every stop run transition. Set equipment status in ODB, stop acquisition on the modules.
- Parameters
-
[in] | run_number | Number of the run being ended |
[out] | error | Can be used to write a message string to midas.log |
Definition at line 368 of file feudp.cxx.
◆ find_source()
Definition at line 198 of file feudp.cxx.
199{
201
203
206 return -1;
207 }
208
211
213
215 cm_msg(
MERROR,
"read_udp",
"UDP packet from unknown host \"%s\"", host);
216 cm_msg(
MINFO,
"read_udp",
"Register this host by running following commands:");
217 cm_msg(
MINFO,
"read_udp",
"odbedit -c \"create STRING /Equipment/%s/Settings/%s\"",
EQ_NAME, host);
218 cm_msg(
MINFO,
"read_udp",
"odbedit -c \"set /Equipment/%s/Settings/%s AAAA\", where AAAA is the MIDAS bank name for this host",
EQ_NAME, host);
219 return -1;
222 return -1;
223 }
224
226 cm_msg(
MERROR,
"read_udp",
"ODB \"/Equipment/%s/Settings/%s\" should be set to a 4 character MIDAS bank name",
EQ_NAME, host);
228 cm_msg(
MINFO,
"read_udp",
"odbedit -c \"set /Equipment/%s/Settings/%s AAAA\", where AAAA is the MIDAS bank name for this host",
EQ_NAME, host);
229 return -1;
230 }
231
232 cm_msg(
MINFO,
"read_udp",
"UDP packets from host \"%s\" will be stored in bank \"%s\"", host,
bankname);
233
237
238 return 0;
239}
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
INT db_get_value(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, void *data, INT *buf_size, DWORD type, BOOL create)
◆ frontend_exit()
Frontend exit.
Runs at frontend shutdown. Disconnect hardware and set equipment status in ODB
- Returns
- Midas status code
Definition at line 383 of file feudp.cxx.
◆ frontend_init()
Frontend initialization.
Runs once at application startup. We initialize the hardware and optical interfaces and set the equipment status in ODB. We also lock the frontend to once physical cpu core.
- Returns
- Midas status code
Definition at line 309 of file feudp.cxx.
310{
312
315 cm_msg(
MERROR,
"frontend_init",
"Cannot connect to ODB, cm_get_experiment_database() returned %d",
status);
317 }
318
319 std::string path;
320 path += "/Equipment";
321 path += "/";
323 path += "/Settings";
324
325 std::string
path1 = path +
"/udp_port";
326
330
334 }
335
337
339 cm_msg(
MERROR,
"frontend_init",
"Cannot find \"%s\", db_find_key() returned %d", path.c_str(),
status);
341 }
342
344
346 printf(
"frontend_init: cannot open udp socket\n");
349 }
350
353}
int open_udp_socket(int server_port)
INT cm_get_experiment_database(HNDLE *hDB, HNDLE *hKeyClient)
INT db_find_key(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
◆ frontend_loop()
Frontend loop.
If frontend_call_loop is true, this routine gets called when the frontend is idle or once between every event.
- Returns
- Midas status code
Definition at line 355 of file feudp.cxx.
356{
359}
INT ss_sleep(INT millisec)
◆ GetTimeSec()
Definition at line 66 of file feudp.cxx.
67{
70 return tv.tv_sec + 0.000001*
tv.tv_usec;
71}
int gettimeofday(struct timeval *tp, void *tzp)
◆ interrupt_configure()
◆ open_udp_socket()
int open_udp_socket |
( |
int |
server_port | ) |
|
Definition at line 90 of file feudp.cxx.
91{
93
95
96 if (fd < 0) {
98 return -1;
99 }
100
103
106 return -1;
107 }
108
110
111
113
116 return -1;
117 }
118
121
125
127
130 return -1;
131 }
132
135
137
138
139
142 return -1;
143 }
144
146
147 return fd;
148}
◆ pause_run()
Pause Run.
Called every pause run transition.
- Parameters
-
[in] | run_number | Number of the run being ended |
[out] | error | Can be used to write a message string to midas.log |
- Returns
- Midas status code
Definition at line 373 of file feudp.cxx.
◆ poll_event()
Definition at line 388 of file feudp.cxx.
389{
390
391
395 return 1;
396 }
397
398 return 1;
399}
◆ read_event()
Definition at line 403 of file feudp.cxx.
404{
407
410 return 0;
411
418}
int read_udp(int socket, char *buf, int bufsize, char *pbankname)
INT bk_close(void *event, void *pdata)
void bk_init32(void *event)
void bk_create(void *event, const char *name, WORD type, void **pdata)
INT bk_size(const void *event)
◆ read_udp()
Definition at line 241 of file feudp.cxx.
242{
244 return 0;
245
246#if 0
247 static int count = 0;
248 static double tt = 0;
250
256 }
258#endif
259
263
266 return -1;
267 }
268
269 for (
unsigned i=0;
i<
gSrc.size();
i++) {
272
274 }
275 }
276
278 return -1;
279
281
283
285
287
290 cm_msg(
MERROR,
"read_udp",
"further messages are now suppressed...");
291 return -1;
292 }
293
294 return -1;
295 }
296
298
300
302}
bool addr_match(const Source *s, void *addr, int addr_len)
int find_source(Source *src, const sockaddr *paddr, int addr_len)
static double GetTimeSec()
int wait_udp(int socket, int msec)
static std::vector< Source > gSrc
◆ resume_run()
Resume Run.
Called every resume run transition.
- Parameters
-
[in] | run_number | Number of the run being ended |
[out] | error | Can be used to write a message string to midas.log |
- Returns
- Midas status code
Definition at line 378 of file feudp.cxx.
◆ wait_udp()
Definition at line 161 of file feudp.cxx.
162{
166
169
170 timeout.tv_sec =
msec/1000;
171 timeout.tv_usec = (
msec%1000)*1000;
172
174
175#ifdef EINTR
177 return 0;
178 }
179#endif
180
183 return -1;
184 }
185
187 return 0;
188 }
189
191 return 1;
192 }
193
194
195 return 0;
196}
◆ display_period
◆ equipment
Initial value:= {
50, 0, 0, 0,
},
{""}
}
int read_event(char *pevent, INT off)
Definition at line 52 of file feudp.cxx.
52 {
57 50, 0, 0, 0,
59 },
60 {""}
61};
◆ equipment_common_overwrite
◆ event_buffer_size
int event_buffer_size = 8*1024*1024 |
◆ frontend_call_loop
◆ frontend_file_name
◆ frontend_name
◆ gDataSocket
◆ gSkipUnknownPackets
◆ gSrc
◆ gUnknownPacketCount
int gUnknownPacketCount = 0 |
|
static |
◆ hKeySet
◆ max_event_size
int max_event_size = 1*1024*1024 |
◆ max_event_size_frag
int max_event_size_frag = 5 * 1024 * 1024 |