// // fetest_tmfe.cxx // // Frontend for test and example of tmfe c++ frontend // #include #include // SIGPIPE #include // assert() #include // malloc() #include "midas.h" #include "tmfe.h" class Myfe : public TMFeRpcHandlerInterface, public TMFePeriodicHandlerInterface { public: TMFE* fMfe; TMFeEquipment* fEq; int fEventSize; char* fEventBuf; Myfe(TMFE* mfe, TMFeEquipment* eq) // ctor { fMfe = mfe; fEq = eq; fEventSize = 0; fEventBuf = NULL; } ~Myfe() // dtor { if (fEventBuf) { free(fEventBuf); fEventBuf = NULL; } } void Init() { fEventSize = 100; fEq->fOdbEqSettings->RI("event_size", &fEventSize, true); if (fEventBuf) { free(fEventBuf); } fEventBuf = (char*)malloc(fEventSize); } void SendEvent(double dvalue) { fEq->ComposeEvent(fEventBuf, fEventSize); fEq->BkInit(fEventBuf, fEventSize); double* ptr = (double*)fEq->BkOpen(fEventBuf, "test", TID_DOUBLE); *ptr = dvalue; fEq->BkClose(fEventBuf, ptr+1); fEq->SendEvent(fEventBuf); } std::string HandleRpc(const char* cmd, const char* args) { fMfe->Msg(MINFO, "HandleRpc", "RPC cmd [%s], args [%s]", cmd, args); return "OK"; } void HandleBeginRun() { fMfe->Msg(MINFO, "HandleBeginRun", "Begin run!"); fEq->SetStatus("Running", "#00FF00"); } void HandleEndRun() { fMfe->Msg(MINFO, "HandleEndRun", "End run!"); fEq->SetStatus("Stopped", "#00FF00"); } //void HandleStartAbortRun() //{ // fMfe->Msg(MINFO, "HandleStartAbortRun", "Begin run aborted!"); // fEq->SetStatus("Stopped", "#00FF00"); //} void HandlePeriodic() { printf("periodic!\n"); //char buf[256]; //sprintf(buf, "buffered %d (max %d), dropped %d, unknown %d, max flushed %d", gUdpPacketBufSize, fMaxBuffered, fCountDroppedPackets, fCountUnknownPackets, fMaxFlushed); //fEq->SetStatus(buf, "#00FF00"); //fEq->WriteStatistics(); } }; static void usage() { fprintf(stderr, "Usage: fetest_tmfe ...\n"); exit(1); } int main(int argc, char* argv[]) { setbuf(stdout, NULL); setbuf(stderr, NULL); signal(SIGPIPE, SIG_IGN); std::string name = ""; if (argc == 2) { name = argv[1]; } else { usage(); // DOES NOT RETURN } TMFE* mfe = TMFE::Instance(); TMFeError err = mfe->Connect("fetest_tmfe", __FILE__); if (err.error) { printf("Cannot connect, bye.\n"); return 1; } //mfe->SetWatchdogSec(0); TMFeCommon *common = new TMFeCommon(); common->EventID = 1; common->LogHistory = 1; //common->Buffer = "SYSTEM"; TMFeEquipment* eq = new TMFeEquipment(mfe, "tmfe", common); eq->Init(); eq->SetStatus("Starting...", "white"); eq->ZeroStatistics(); eq->WriteStatistics(); mfe->RegisterEquipment(eq); Myfe* myfe = new Myfe(mfe, eq); mfe->RegisterRpcHandler(myfe); //mfe->SetTransitionSequenceStart(910); //mfe->SetTransitionSequenceStop(90); //mfe->DeregisterTransitionPause(); //mfe->DeregisterTransitionResume(); //mfe->RegisterTransitionStartAbort(); myfe->Init(); mfe->RegisterPeriodicHandler(eq, myfe); eq->SetStatus("Started...", "white"); while (!mfe->fShutdownRequested) { mfe->PollMidas(10); } mfe->Disconnect(); return 0; } /* emacs * Local Variables: * tab-width: 8 * c-basic-offset: 3 * indent-tabs-mode: nil * End: */