/*******************************************************************\
Name: fetest.cxx
Created by:
Contents: Front end for testing MIDAS. Just sets a variable to
the value of the frontend index.
\********************************************************************/
#undef NDEBUG // midas required assert() to be always enabled
#include <cassert>
#include "mfe.h"
/*-- Globals -------------------------------------------------------*/
/* The frontend name (client name) as seen by other MIDAS clients */
const char *frontend_name = "fedummy";
/* 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 = FALSE;
/* a frontend status page is displayed with this frequency in ms */
INT display_period = 0;
/* maximum event size produced by this frontend */
INT max_event_size = 4*1024*1024;
INT max_event_size_frag = 4*1024*1024;
/* buffer size to hold events */
INT event_buffer_size = 10*1024*1024;
/*-- Function declarations -----------------------------------------*/
INT frontend_init();
INT frontend_exit();
INT begin_of_run(INT run_number, char *error);
INT end_of_run(INT run_number, char *error);
INT pause_run(INT run_number, char *error);
INT resume_run(INT run_number, char *error);
INT frontend_loop();
INT poll_event(INT source, INT count, BOOL test);
INT interrupt_configure(INT cmd, INT source, PTYPE adr);
int read_dummy_event(char *pevent, int off);
/*-- Equipment list ------------------------------------------------*/
#ifndef FE_NAME
#define FE_NAME "fedummy"
#endif
#ifndef EQ_NAME
#define EQ_NAME "Dummy"
#endif
#ifndef EQ_EVID
#define EQ_EVID 1
#endif
char eq_name[256];
EQUIPMENT equipment[] = {
{ EQ_NAME "%02d" , /* equipment name */
{
EQ_EVID, (1<<EQ_EVID),/* event ID, trigger mask */
"SYSTEM", /* event buffer */
EQ_PERIODIC, /* equipment type */
0, /* event source */
"MIDAS", /* format */
TRUE, /* enabled */
RO_ALWAYS, /* Read when running */
1000, /* poll every so milliseconds */
0, /* stop run after this event limit */
0, /* number of sub events */
1, /* history period */
"", "", ""
},
read_dummy_event,/* readout routine */
NULL,
NULL,
NULL, /* bank list */
}
,
{""}
};
int event_size = 10*1024;
/*-- Frontend Init -------------------------------------------------*/
#include "msystem.h"
INT frontend_init()
{
sprintf(eq_name, "%s%02d", EQ_NAME, get_frontend_index());
return SUCCESS;
}
INT frontend_exit()
{
return SUCCESS;
}
INT begin_of_run(INT run_number, char *error)
{
return SUCCESS;
}
INT end_of_run(INT run_number, char *error)
{
return SUCCESS;
}
INT pause_run(INT run_number, char *error)
{
return SUCCESS;
}
INT resume_run(INT run_number, char *error)
{
return SUCCESS;
}
INT frontend_loop()
{
return SUCCESS;
}
INT poll_event(INT source, INT count, BOOL test)
{
return 0;
}
INT interrupt_configure(INT cmd, INT source, PTYPE adr)
{
return 0;
}
INT read_dummy_event(char *pevent, INT off)
{
static HNDLE hVar = 0;
if ( hVar == 0 ) {
char str[1024];
sprintf(str, "/Equipment/%s/Variables", eq_name);
int status = db_find_key(hDB, 0, str, &hVar);
if ( status == DB_NO_KEY ) {
status = db_create_key(hDB, 0, str, TID_KEY);
if (status == DB_SUCCESS) {
status = db_find_key(hDB, 0, str, &hVar);
}
}
if (status != SUCCESS) {
cm_msg(MERROR, frontend_name, "read_dummy_event: Can\'t find or create %s, status %d, exiting", str, status);
exit(1);
}
}
const float data = static_cast<float>(get_frontend_index());
const int status = db_set_value( hDB, hVar, "Data", &data,
sizeof(float), 1, TID_FLOAT);
assert(status == DB_SUCCESS);
return 0;
}
/* emacs
* Local Variables:
* tab-width: 8
* c-basic-offset: 3
* indent-tabs-mode: nil
* End:
*/
|