MIDAS
Loading...
Searching...
No Matches
fetest_tmfe.cxx
Go to the documentation of this file.
1//
2// fetest_tmfe.cxx
3//
4// Frontend for test and example of tmfe c++ frontend
5//
6
7#include <stdio.h>
8#include <signal.h> // SIGPIPE
9#include <assert.h> // assert()
10#include <stdlib.h> // malloc()
11
12#include "midas.h"
13#include "tmfe.h"
14
15class Myfe :
18{
19public:
22
24 char* fEventBuf;
25
27 {
28 fMfe = mfe;
29 fEq = eq;
30 fEventSize = 0;
32 }
33
34 ~Myfe() // dtor
35 {
36 if (fEventBuf) {
37 free(fEventBuf);
39 }
40 }
41
42 void Init()
43 {
44 fEventSize = 100;
45 fEq->fOdbEqSettings->RI("event_size", &fEventSize, true);
46 if (fEventBuf) {
47 free(fEventBuf);
48 }
49 fEventBuf = (char*)malloc(fEventSize);
50 }
51
52 void SendEvent(double dvalue)
53 {
56
57 double* ptr = (double*)fEq->BkOpen(fEventBuf, "test", TID_DOUBLE);
58 *ptr = dvalue;
59 fEq->BkClose(fEventBuf, ptr+1);
60
62 }
63
64 std::string HandleRpc(const char* cmd, const char* args)
65 {
66 fMfe->Msg(MINFO, "HandleRpc", "RPC cmd [%s], args [%s]", cmd, args);
67 return "OK";
68 }
69
71 {
72 fMfe->Msg(MINFO, "HandleBeginRun", "Begin run!");
73 fEq->SetStatus("Running", "#00FF00");
74 }
75
77 {
78 fMfe->Msg(MINFO, "HandleEndRun", "End run!");
79 fEq->SetStatus("Stopped", "#00FF00");
80 }
81
82 //void HandleStartAbortRun()
83 //{
84 // fMfe->Msg(MINFO, "HandleStartAbortRun", "Begin run aborted!");
85 // fEq->SetStatus("Stopped", "#00FF00");
86 //}
87
89 {
90 printf("periodic!\n");
91 //char buf[256];
92 //sprintf(buf, "buffered %d (max %d), dropped %d, unknown %d, max flushed %d", gUdpPacketBufSize, fMaxBuffered, fCountDroppedPackets, fCountUnknownPackets, fMaxFlushed);
93 //fEq->SetStatus(buf, "#00FF00");
94 //fEq->WriteStatistics();
95 }
96};
97
98static void usage()
99{
100 fprintf(stderr, "Usage: fetest_tmfe ...\n");
101 exit(1);
102}
103
104int main(int argc, char* argv[])
105{
108
110
111 std::string name = "";
112
113 if (argc == 2) {
114 name = argv[1];
115 } else {
116 usage(); // DOES NOT RETURN
117 }
118
120
121 TMFeError err = mfe->Connect("fetest_tmfe", __FILE__);
122 if (err.error) {
123 printf("Cannot connect, bye.\n");
124 return 1;
125 }
126
127 //mfe->SetWatchdogSec(0);
128
130 common->EventID = 1;
131 common->LogHistory = 1;
132 //common->Buffer = "SYSTEM";
133
134 TMFeEquipment* eq = new TMFeEquipment(mfe, "tmfe", common);
135 eq->Init();
136 eq->SetStatus("Starting...", "white");
137 eq->ZeroStatistics();
138 eq->WriteStatistics();
139
140 mfe->RegisterEquipment(eq);
141
142 Myfe* myfe = new Myfe(mfe, eq);
143
144 mfe->RegisterRpcHandler(myfe);
145
146 //mfe->SetTransitionSequenceStart(910);
147 //mfe->SetTransitionSequenceStop(90);
148 //mfe->DeregisterTransitionPause();
149 //mfe->DeregisterTransitionResume();
150 //mfe->RegisterTransitionStartAbort();
151
152 myfe->Init();
153
154 mfe->RegisterPeriodicHandler(eq, myfe);
155
156 eq->SetStatus("Started...", "white");
157
158 while (!mfe->fShutdownRequested) {
159 mfe->PollMidas(10);
160 }
161
162 mfe->Disconnect();
163
164 return 0;
165}
166
167/* emacs
168 * Local Variables:
169 * tab-width: 8
170 * c-basic-offset: 3
171 * indent-tabs-mode: nil
172 * End:
173 */
Myfe(TMFE *mfe, TMFeEquipment *eq)
TMFeEquipment * fEq
void SendEvent(double dvalue)
char * fEventBuf
TMFE * fMfe
int fEventSize
void HandleBeginRun()
void HandlePeriodic()
std::string HandleRpc(const char *cmd, const char *args)
void HandleEndRun()
void Init()
Definition tmfe.h:381
void Msg(int message_type, const char *filename, int line, const char *routine, const char *format,...) MATTRPRINTF(6
Definition tmfe.cxx:991
static TMFE * Instance()
Definition tmfe.cxx:57
void * BkOpen(char *pevent, const char *bank_name, int bank_type) const
Definition tmfe.cxx:2201
TMFeResult BkInit(char *pevent, size_t size) const
Definition tmfe.cxx:2195
MVOdb * fOdbEqSettings
ODB Equipment/EQNAME/Settings.
Definition tmfe.h:213
TMFeResult BkClose(char *pevent, void *ptr) const
Definition tmfe.cxx:2208
TMFeResult ComposeEvent(char *pevent, size_t size) const
Definition tmfe.cxx:1995
TMFeError SendEvent(const char *pevent)
TMFeError SetStatus(const char *status, const char *color)
int error
Definition tmfe_rev0.h:87
static void usage()
#define TID_DOUBLE
Definition midas.h:343
#define MINFO
Definition midas.h:560
int main()
Definition hwtest.cxx:23
std::vector< FMT_ID > eq
Definition mdump.cxx:55
#define name(x)
Definition midas_macro.h:24
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24