Changeset 13916 for trunk/FACT++/src/mcp.cc
- Timestamp:
- 05/26/12 14:49:54 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/mcp.cc
r13847 r13916 14 14 #include "HeadersFTM.h" 15 15 #include "HeadersFAD.h" 16 16 #include "HeadersMCP.h" 17 #include "HeadersRateControl.h" 17 18 18 19 namespace ba = boost::asio; … … 32 33 { 33 34 private: 34 enum states_t35 {36 kStateDimNetworkNA = 1,37 kStateDisconnected,38 kStateConnecting,39 kStateConnected,40 kStateIdle,41 kStateDummy, // Doesn't exist, kept to keep the numbers42 kStateConfiguring1,43 kStateConfiguring2,44 kStateConfiguring3,45 kStateConfigured,46 kStateTriggerOn,47 kStateTakingData,48 // kStateRunInProgress,49 };50 51 35 DimVersion fDim; 52 36 DimDescribedState fDimFTM; … … 59 43 int Print() const 60 44 { 61 Out() << fDim << endl;45 Out() << fDim << endl; 62 46 Out() << fDimFTM << endl; 63 47 Out() << fDimFAD << endl; 64 48 Out() << fDimLog << endl; 65 Out() << fDimRC << endl;49 Out() << fDimRC << endl; 66 50 67 51 return GetCurrentState(); … … 75 59 int StopRun(const EventImp &) 76 60 { 77 if (fDimFTM.state()==FTM:: kTriggerOn)61 if (fDimFTM.state()==FTM::State::kTriggerOn) 78 62 { 79 63 Message("Stopping FTM"); 80 Dim::SendCommand ("FTM_CONTROL/STOP_TRIGGER");64 Dim::SendCommandNB("FTM_CONTROL/STOP_TRIGGER"); 81 65 } 82 66 83 67 // FIXME: Do step 2 only when FTM is stopped 84 if (fDimFAD.state()==FAD:: kConnected)68 if (fDimFAD.state()==FAD::State::kConnected) 85 69 { 86 70 //Dim::SendCommand("FAD_CONTROL/ENABLE_TRIGGER_LINE", bool(false)); 87 71 Message("Stopping FAD"); 88 Dim::SendCommand ("FAD_CONTROL/ENABLE_CONTINOUS_TRIGGER", bool(false));72 Dim::SendCommandNB("FAD_CONTROL/ENABLE_CONTINOUS_TRIGGER", bool(false)); 89 73 } 90 74 … … 96 80 fRunType = ""; 97 81 Message("Reseting configuration states of FAD and FTM"); 98 Dim::SendCommand ("FTM_CONTROL/RESET_CONFIGURE");99 Dim::SendCommand ("FAD_CONTROL/RESET_CONFIGURE");100 Update( kStateIdle);101 return kStateIdle;82 Dim::SendCommandNB("FTM_CONTROL/RESET_CONFIGURE"); 83 Dim::SendCommandNB("FAD_CONTROL/RESET_CONFIGURE"); 84 Update(MCP::State::kIdle); 85 return MCP::State::kIdle; 102 86 /* 103 87 // FIMXE: Handle error states! … … 108 92 Dim::SendCommand("DATA_LOGGER/WAIT_FOR_RUN_NUMBER"); 109 93 110 if (fDimFAD.state()==FAD:: kConnected)94 if (fDimFAD.state()==FAD::State::kConnected) 111 95 { 112 96 Dim::SendCommand("FAD_CONTROL/ENABLE_TRIGGER_LINE", bool(false)); … … 114 98 } 115 99 116 if (fDimFTM.state()==FTM:: kTakingData)100 if (fDimFTM.state()==FTM::State::kTakingData) 117 101 Dim::SendCommand("FTM_CONTROL/STOP"); 118 102 … … 126 110 int StartRun(const EventImp &evt) 127 111 { 128 if ( fDimFTM.state()==-2)112 if (!fDimFTM.online()) 129 113 { 130 114 Error("No connection to ftmcontrol (see PRINT)."); 131 115 return GetCurrentState(); 132 116 } 133 if ( fDimFAD.state()==-2)117 if (!fDimFAD.online()) 134 118 { 135 119 Warn("No connection to fadcontrol (see PRINT)."); 136 120 return GetCurrentState(); 137 121 } 138 if ( fDimLog.state()==-2)122 if (!fDimLog.online()) 139 123 { 140 124 Warn("No connection to datalogger (see PRINT)."); 141 125 return GetCurrentState(); 142 126 } 143 if ( fDimRC.state()==-2)127 if (!fDimRC.online()) 144 128 { 145 129 Warn("No connection to ratecontrol (see PRINT)."); … … 165 149 Message(str); 166 150 167 Update( kStateConfiguring1);168 169 return kStateConfiguring1;151 Update(MCP::State::kConfiguring1); 152 153 return MCP::State::kConfiguring1; 170 154 } 171 155 … … 207 191 208 192 Message("Configuring FAD"); 209 Dim::SendCommand ("FAD_CONTROL/CONFIGURE", buf, sizeof(Value)+fRunType.length()+1);193 Dim::SendCommandNB("FAD_CONTROL/CONFIGURE", buf, sizeof(Value)+fRunType.length()+1); 210 194 211 195 delete buf; 212 196 } 213 197 214 int Execute() 215 { 216 // Dispatch (execute) at most one handler from the queue. In contrary 217 // to run_one(), it doesn't wait until a handler is available 218 // which can be dispatched, so poll_one() might return with 0 219 // handlers dispatched. The handlers are always dispatched/executed 220 // synchronously, i.e. within the call to poll_one() 221 //poll_one(); 222 198 int HandleStateChange() 199 { 223 200 if (!fDim.online()) 224 return kStateDimNetworkNA;225 226 if (fDimFTM.state() >= FTM:: kConnected &&227 fDimFAD.state() >= FAD:: kConnected &&201 return MCP::State::kDimNetworkNA; 202 203 if (fDimFTM.state() >= FTM::State::kConnected && 204 fDimFAD.state() >= FAD::State::kConnected && 228 205 fDimLog.state() >= kSM_Ready) 229 206 { 230 if (GetCurrentState()== kStateConfiguring1)207 if (GetCurrentState()==MCP::State::kConfiguring1) 231 208 { 232 209 if (fDimLog.state()<30/*kSM_WaitForRun*/) 233 210 { 234 211 Message("Starting datalogger"); 235 Dim::SendCommand ("DATA_LOGGER/START_RUN_LOGGING");212 Dim::SendCommandNB("DATA_LOGGER/START_RUN_LOGGING"); 236 213 } 237 214 Message("Configuring Trigger (FTM)"); 238 Dim::SendCommand ("FTM_CONTROL/CONFIGURE", fRunType);239 Update( kStateConfiguring2);240 return kStateConfiguring2;241 } 242 243 if (GetCurrentState()== kStateConfiguring2)215 Dim::SendCommandNB("FTM_CONTROL/CONFIGURE", fRunType); 216 Update(MCP::State::kConfiguring2); 217 return MCP::State::kConfiguring2; 218 } 219 220 if (GetCurrentState()==MCP::State::kConfiguring2) 244 221 { 245 222 // FIMXE: Reset in case of error 246 if ((/*fDimFTM.state() != FTM:: kConfiguring2 &&*/247 fDimFTM.state() != FTM:: kConfigured) ||223 if ((/*fDimFTM.state() != FTM::State::kConfiguring2 &&*/ 224 fDimFTM.state() != FTM::State::kConfigured) || 248 225 fDimLog.state()<30 || fDimLog.state()>0xff) 249 226 return GetCurrentState(); … … 254 231 255 232 Message("Starting Rate Control"); 256 Dim::SendCommand ("RATE_CONTROL/CALIBRATE");233 Dim::SendCommandNB("RATE_CONTROL/CALIBRATE"); 257 234 258 235 ConfigureFAD(); 259 Update( kStateConfiguring3);260 return kStateConfiguring3;261 } 262 263 if (GetCurrentState()== kStateConfiguring3)264 { 265 if (fDimFTM.state() != FTM:: kConfigured ||266 fDimFAD.state() != FAD:: kConfigured ||267 fDimRC.state() < 6)236 Update(MCP::State::kConfiguring3); 237 return MCP::State::kConfiguring3; 238 } 239 240 if (GetCurrentState()==MCP::State::kConfiguring3) 241 { 242 if (fDimFTM.state() != FTM::State::kConfigured || 243 fDimFAD.state() != FAD::State::kConfigured || 244 fDimRC.state() < RateControl::State::kSettingGlobalThreshold) 268 245 return GetCurrentState(); 269 246 270 247 Message("Starting Trigger (FTM)"); 271 Dim::SendCommand ("FTM_CONTROL/START_TRIGGER");272 Update( kStateConfigured);273 return kStateConfigured;274 } 275 276 if (GetCurrentState()== kStateConfigured)277 { 278 if (fDimFTM.state() != FTM:: kTriggerOn)248 Dim::SendCommandNB("FTM_CONTROL/START_TRIGGER"); 249 Update(MCP::State::kConfigured); 250 return MCP::State::kConfigured; 251 } 252 253 if (GetCurrentState()==MCP::State::kConfigured) 254 { 255 if (fDimFTM.state() != FTM::State::kTriggerOn) 279 256 return GetCurrentState(); 280 257 281 Update( kStateTriggerOn);282 283 return kStateTriggerOn;284 } 285 286 if (GetCurrentState()== kStateTriggerOn)287 { 288 if (fDimFAD.state() != FAD:: kWritingData)258 Update(MCP::State::kTriggerOn); 259 260 return MCP::State::kTriggerOn; 261 } 262 263 if (GetCurrentState()==MCP::State::kTriggerOn) 264 { 265 if (fDimFAD.state() != FAD::State::kWritingData) 289 266 return GetCurrentState(); 290 267 291 Update( kStateTakingData);292 293 return kStateTakingData;294 } 295 296 if (GetCurrentState()== kStateTakingData)297 { 298 if (fDimFTM.state()==FTM:: kTriggerOn &&299 fDimFAD.state()==FAD:: kWritingData)300 return kStateTakingData;301 302 Update( kStateIdle);303 } 304 305 return kStateIdle;268 Update(MCP::State::kTakingData); 269 270 return MCP::State::kTakingData; 271 } 272 273 if (GetCurrentState()==MCP::State::kTakingData) 274 { 275 if (fDimFTM.state()==FTM::State::kTriggerOn && 276 fDimFAD.state()==FAD::State::kWritingData) 277 return MCP::State::kTakingData; 278 279 Update(MCP::State::kIdle); 280 } 281 282 return MCP::State::kIdle; 306 283 } 307 284 308 285 /* 309 if (fDimFTM.state() >= FTM:: kConnected &&310 fDimFAD.state() >= FAD:: kConnected &&286 if (fDimFTM.state() >= FTM::State::kConnected && 287 fDimFAD.state() >= FAD::State::kConnected && 311 288 fDimLog.state() >= kSM_Ready) 312 return kStateIdle;289 return MCP::State::kIdle; 313 290 */ 314 291 if (fDimFTM.state() >-2 && … … 316 293 fDimLog.state() >-2 && 317 294 fDimRC.state() >-2) 318 return kStateConnected;295 return MCP::State::kConnected; 319 296 320 297 if (fDimFTM.state() >-2 || … … 322 299 fDimLog.state() >-2 || 323 300 fDimRC.state() >-2) 324 return kStateConnecting;325 326 return kStateDisconnected;301 return MCP::State::kConnecting; 302 303 return MCP::State::kDisconnected; 327 304 } 328 305 … … 351 328 fDimRC.Subscribe(*this); 352 329 330 fDim.SetCallback(bind(&StateMachineMCP::HandleStateChange, this)); 331 fDimFTM.SetCallback(bind(&StateMachineMCP::HandleStateChange, this)); 332 fDimFAD.SetCallback(bind(&StateMachineMCP::HandleStateChange, this)); 333 fDimLog.SetCallback(bind(&StateMachineMCP::HandleStateChange, this)); 334 fDimRC.SetCallback(bind(&StateMachineMCP::HandleStateChange, this)); 335 353 336 // State names 354 AddStateName( kStateDimNetworkNA, "DimNetworkNotAvailable",337 AddStateName(MCP::State::kDimNetworkNA, "DimNetworkNotAvailable", 355 338 "DIM dns server not available."); 356 339 357 AddStateName( kStateDisconnected, "Disconnected",340 AddStateName(MCP::State::kDisconnected, "Disconnected", 358 341 "Neither ftmctrl, fadctrl, datalogger nor rate control online."); 359 342 360 AddStateName( kStateConnecting, "Connecting",343 AddStateName(MCP::State::kConnecting, "Connecting", 361 344 "Either ftmctrl, fadctrl, datalogger or rate control not online."); 362 345 363 AddStateName( kStateConnected, "Connected",346 AddStateName(MCP::State::kConnected, "Connected", 364 347 "All needed subsystems online."); 365 348 366 AddStateName( kStateIdle, "Idle",349 AddStateName(MCP::State::kIdle, "Idle", 367 350 "Waiting for next configuration command"); 368 351 369 AddStateName( kStateConfiguring1, "Configuring1",352 AddStateName(MCP::State::kConfiguring1, "Configuring1", 370 353 "Starting configuration procedure, checking Datalogger state"); 371 354 372 AddStateName( kStateConfiguring2, "Configuring2",355 AddStateName(MCP::State::kConfiguring2, "Configuring2", 373 356 "Waiting for FTM and Datalogger to get ready"); 374 357 375 AddStateName( kStateConfiguring3, "Configuring3",358 AddStateName(MCP::State::kConfiguring3, "Configuring3", 376 359 "Waiting for FADs and rate control to get ready"); 377 360 378 AddStateName( kStateConfigured, "Configured",361 AddStateName(MCP::State::kConfigured, "Configured", 379 362 "Everything is configured, trigger will be switched on now"); 380 363 381 AddStateName( kStateTriggerOn, "TriggerOn",364 AddStateName(MCP::State::kTriggerOn, "TriggerOn", 382 365 "The trigger is switched on, waiting for FAD to receive data"); 383 366 384 AddStateName( kStateTakingData, "TakingData",367 AddStateName(MCP::State::kTakingData, "TakingData", 385 368 "The trigger is switched on, FADs are sending data"); 386 369 387 370 388 AddEvent("START", "X:2;C")//, kStateIdle)371 AddEvent("START", "X:2;C")//, MCP::State::kIdle) 389 372 (bind(&StateMachineMCP::StartRun, this, placeholders::_1)) 390 373 ("Start the configuration and data taking for a run-type of a pre-defined setup" … … 397 380 ("Stops the trigger (either disables the FTM trigger or the internal DRS trigger)"); 398 381 399 AddEvent("RESET", kStateConfiguring1, kStateConfiguring2, kStateConfiguring3, kStateConfigured)382 AddEvent("RESET", MCP::State::kConfiguring1, MCP::State::kConfiguring2, MCP::State::kConfiguring3, MCP::State::kConfigured) 400 383 (bind(&StateMachineMCP::Reset, this, placeholders::_1)) 401 384 ("If a configuration blockes because a system cannot configure itself properly, "
Note:
See TracChangeset
for help on using the changeset viewer.