18 namespace ba = boost::asio;
19 namespace bs = boost::system;
20 namespace dummy = ba::placeholders;
58 return GetCurrentState();
60 const uint8_t *ptr = d.
Ptr<uint8_t>();
63 fFadConnected.assign(40,
false);
65 vector<bool>
reset(4);
67 for (
int i=0;
i<40;
i++)
69 const uint8_t stat1 = ptr[
i]&3;
70 const uint8_t stat2 = ptr[
i]>>3;
73 if (stat1==0 && stat2==0)
76 fFadConnected[
i] =
true;
78 if (stat1>=2 && stat2==8)
82 if (stat1>2 && stat2==8)
89 return GetCurrentState();
95 return GetCurrentState();
100 for (
int i=0;
i<40;
i++)
105 return GetCurrentState();
110 Out() << fDim << endl;
111 Out() << fDimFTM << endl;
112 Out() << fDimFAD << endl;
113 Out() << fDimLog << endl;
114 Out() << fDimRC << endl;
116 return GetCurrentState();
121 return GetCurrentState();
128 Message(
"Stopping FTM");
136 Message(
"Stopping FAD");
138 if (fDimFAD.
state()==FAD::State::kRunInProgress)
142 return GetCurrentState();
149 return GetCurrentState();
152 Message(
"Reseting configuration states of FAD and FTM");
188 Error(
"No connection to ftmcontrol (see PRINT).");
189 return GetCurrentState();
193 Warn(
"No connection to fadcontrol (see PRINT).");
194 return GetCurrentState();
198 Warn(
"No connection to datalogger (see PRINT).");
199 return GetCurrentState();
203 Warn(
"No connection to ratecontrol (see PRINT).");
204 return GetCurrentState();
207 fMaxTime = evt.
Get<int64_t>();
208 fNumEvents = evt.
Get<int64_t>(8);
209 fRunType = evt.
Ptr<
char>(16);
214 str <<
"Starting configuration '" << fRunType <<
"' for new run";
215 if (fNumEvents>0 || fMaxTime>0)
218 str << fNumEvents <<
" events";
219 if (fNumEvents>0 && fMaxTime>0)
222 str << fMaxTime <<
"s";
223 if (fNumEvents>0 || fMaxTime>0)
234 Message(
"Stopping ratecontrol");
237 if (fDimLog.
state()<30)
240 Message(
"Starting datalogger");
256 const size_t len =
sizeof(
Value)+fRunType.length()+1;
258 char *buf =
new char[len];
262 val->
time = fMaxTime;
263 val->
nevts = fNumEvents;
265 strcpy(val->
type, fRunType.c_str());
272 Value *buf = GetBuffer();
274 fService.
setData(buf,
sizeof(
Value)+fRunType.length()+1);
281 Value *buf = GetBuffer();
284 Message(
"Configuring FAD");
296 fDimLog.
state() >= kSM_Ready)
299 if (fDimFTM.
state() >-2 &&
300 fDimFAD.
state() >-2 &&
301 fDimLog.
state() >-2 &&
305 if (fDimFTM.
state() >-2 ||
306 fDimFAD.
state() >-2 ||
307 fDimLog.
state() >-2 ||
324 Message(
"Configuring Trigger (FTM)");
343 Message(
"Starting Rate Control");
347 fFadTimeout =
Time();
380 Message(
"Starting Trigger (FTM)");
407 if (fDimFAD.
state() != FAD::State::kRunInProgress)
419 fDimFAD.
state()==FAD::State::kRunInProgress)
506 return GetCurrentState();
511 fFadNeedsReset(4), fNumConnectedFtu(40),
512 fDimFTM(
"FTM_CONTROL"),
513 fDimFAD(
"FAD_CONTROL"),
514 fDimLog(
"DATA_LOGGER"),
515 fDimRC(
"RATE_CONTROL"),
516 fService(
"MCP/CONFIGURATION",
"X:1;X:1;C",
"Run configuration information" 517 "|MaxTime[s]:Maximum time before the run gets stopped" 518 "|MaxEvents[num]:Maximum number of events before the run gets stopped" 519 "|Name[text]:Name of the chosen configuration")
540 Subscribe(
"FAD_CONTROL/CONNECTIONS")
542 Subscribe(
"FTM_CONTROL/STATIC_DATA")
547 "DIM dns server not available.");
549 "Neither ftmctrl, fadctrl, datalogger nor rate control online.");
551 "Either ftmctrl, fadctrl, datalogger or rate control not online.");
553 "All needed subsystems online.");
555 "Waiting for next configuration command");
557 "Starting configuration procedure, checking datalogger/ratecontrol state");
559 "Starting ratecontrol, waiting for FTM to get configured and Datalogger to get ready");
561 "Waiting for FADs and ratecontrol to get ready");
573 "Everything is configured, trigger will be switched on now");
575 "The trigger is switched on, waiting for FAD to receive data");
577 "The trigger is switched on, FADs are sending data");
580 AddEvent(
"START",
"X:2;C")
582 (
"Start the configuration and data taking for a run-type of a pre-defined setup" 583 "|TimeMax[s]:Maximum number of seconds before the run will be closed automatically" 584 "|NumMax[count]:Maximum number events before the run will be closed automatically" 585 "|Name[text]:Name of the configuration to be used for taking data");
589 (
"Stops the trigger (either disables the FTM trigger or the internal DRS trigger)");
593 (
"If a configuration blockes because a system cannot configure itself properly, " 594 "this command can be called to leave the configuration procedure. The command " 595 "is also propagated to FTM and FAD");
599 (
"Print the states and connection status of all systems connected to the MCP.");
615 return Main::execute<T, StateMachineMCP>(conf);
630 "The ftmctrl controls the FSC (FACT Slow Control) board.\n" 632 "The default is that the program is started without user intercation. " 633 "All actions are supposed to arrive as DimCommands. Using the -c " 634 "option, a local shell can be initialized. With h or help a short " 635 "help message about the usuage can be brought to the screen.\n" 637 "Usage: fscctrl [-c type] [OPTIONS]\n" 638 " or: fscctrl [OPTIONS]\n";
644 Main::PrintHelp<StateMachineMCP>();
664 int main(
int argc,
const char* argv[])
676 if (!conf.
Has(
"console"))
681 return RunShell<LocalStream>(conf);
693 if (conf.
Get<
int>(
"console")==0)
694 return RunShell<LocalShell>(conf);
696 return RunShell<LocalConsole>(conf);
StateMachineMCP(ostream &out=cout)
vector< bool > fFadBoardsForConnection
virtual void Subscribe(StateMachineImp &imp)
int HandleFadConnections(const EventImp &d)
vector< bool > fFadNeedsReset
A general base-class describing events issues in a state machine.
void SetupConfiguration(Configuration &conf)
int StartRun(const EventImp &evt)
void setQuality(int quality)
Adds some functionality to boost::posix_time::ptime for our needs.
void SetPrintUsage(const std::function< void(void)> &func)
T Get(const std::string &var)
DimDescribedState fDimFTM
const int32_t & state() const
vector< bool > fFadCratesForReset
int RunShell(Configuration &conf)
int Execute()
Is called continously to execute actions in the current state.
bool Has(const std::string &var)
void setData(const void *ptr, size_t sz)
int EvalOptions(Configuration &)
DimDescribedService fService
DimDescribedState fDimFAD
void Update(int newstate)
void SendCommandNB(const std::string &command)
Commandline parsing, resource file parsing and database access.
vector< bool > fFadConnected
uint16_t fNumConnectedFad
virtual void Subscribe(StateMachineImp &imp)
int main(int argc, const char *argv[])
Class for a state machine implementation within a DIM network.
bool IsActive(int i) const
DimDescribedState fDimLog
uint16_t fNumConnectedFtu
T Get(size_t offset=0) const
bool DoParse(int argc, const char **argv, const std::function< void()> &func=std::function< void()>())
const T & Ref(size_t offset=0) const
void SetCallback(const callback &cb)
const T * Ptr(size_t offset=0) const
int HandleFtmStaticData(const EventImp &d)
virtual size_t GetSize() const