- Timestamp:
- 05/23/12 17:06:08 (13 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/RemoteControl.h
r13743 r13838 119 119 } 120 120 121 void infoHandler()122 { 123 RemoteControlImp::infoHandler();124 if ( !fCurrentServer.empty() && !HasServer(fCurrentServer))121 void RemoveServer(std::string s) 122 { 123 DimNetwork::RemoveServer(s); 124 if (fCurrentServer==s) 125 125 { 126 126 fCurrentServer = ""; 127 127 T::UpdatePrompt(); 128 128 } 129 } 130 131 void RemoveAllServers() 132 { 133 DimNetwork::RemoveAllServers(); 134 fCurrentServer = ""; 135 T::UpdatePrompt(); 129 136 } 130 137 -
trunk/FACT++/src/datalogger.cc
r13670 r13838 196 196 }; 197 197 198 class DataLogger : public StateMachineDim, DimServiceInfoList 198 class DataLogger : public StateMachineDim, DimServiceInfoListImp 199 199 { 200 200 public: … … 262 262 ***************************************************/ 263 263 ///Reporting method for the services info received 264 void Report Please(DimInfo* I, SubscriptionType& sub);264 void Report(DimInfo* I, SubscriptionType& sub); 265 265 266 266 ///Configuration of the nightly file path 267 267 int ConfigureFilePath(const Event& evt); 268 268 ///print the current state of the dataLogger 269 int PrintState Please(const Event& evt);269 int PrintState(const Event& evt); 270 270 ///checks whether or not the current info being treated is a run number 271 271 void CheckForRunNumber(DimInfo* I); 272 272 /// start transition 273 int Start Please();273 int Start(); 274 274 ///from waiting to logging transition 275 //int StartRun Please();275 //int StartRun(); 276 276 // from logging to waiting transition 277 277 int StopRunLogging(); 278 278 ///stop and reset transition 279 int GoToReady Please();279 int GoToReady(); 280 280 ///from NightlyOpen to waiting transition 281 int NightlyToWaitRun Please();281 int NightlyToWaitRun(); 282 282 ///from wait for run number to nightly open 283 int BackToNightlyOpen Please();283 int BackToNightlyOpen(); 284 284 #ifdef HAVE_FITS 285 285 ///Open fits files 286 void OpenFITSFiles Please(SubscriptionType& sub, RunNumberType* cRunNumber);286 void OpenFITSFiles(SubscriptionType& sub, RunNumberType* cRunNumber); 287 287 ///Write data to FITS files 288 288 void WriteToFITS(SubscriptionType& sub); … … 355 355 bool ShouldSubscribe(const string& server, const string& service); 356 356 ///Subscribe to a given server and service 357 DimStampedInfo* SubscribeTo Please(const string& server, const string& service);357 DimStampedInfo* SubscribeTo(const string& server, const string& service); 358 358 ///Open a text file and checks for ofstream status 359 bool OpenTextFile Please(ofstream& stream, const string& name);359 bool OpenTextFile(ofstream& stream, const string& name); 360 360 ///Checks if the input osftream is in error state, and if so close it. 361 361 bool CheckForOfstreamError(ofstream& out, bool isDailyStream); … … 370 370 bool CreateDirectory(string path); 371 371 /*************************************************** 372 * INHERITED FROM D IMSERVICEINFOLIST372 * INHERITED FROM DimServiceInfoList 373 373 ***************************************************/ 374 374 ///Add a new service subscription … … 480 480 } 481 481 482 list[service].dimInfo.reset(SubscribeTo Please(server, service));482 list[service].dimInfo.reset(SubscribeTo(server, service)); 483 483 list[service].server = server; 484 484 list[service].service = service; … … 615 615 //! @name the file name 616 616 // 617 bool DataLogger::OpenTextFile Please(ofstream& stream, const string& name)617 bool DataLogger::OpenTextFile(ofstream& stream, const string& name) 618 618 { 619 619 return OpenStreamImp(stream, name, true); … … 626 626 //! @param service the service name 627 627 // 628 DimStampedInfo* DataLogger::SubscribeTo Please(const string& server, const string& service)628 DimStampedInfo* DataLogger::SubscribeTo(const string& server, const string& service) 629 629 { 630 630 if (fDebugIsOn) … … 780 780 781 781 // Add the possible transitions for this machine 782 AddEvent( kSM_NightlyOpen,"START", kSM_Ready, kSM_BadFolder)783 (bind(&DataLogger::Start Please, this))782 AddEvent("START", kSM_Ready, kSM_BadFolder) 783 (bind(&DataLogger::Start, this)) 784 784 ("Start the nightly logging. Nightly file location must be specified already"); 785 785 786 AddEvent( kSM_Ready,"STOP", kSM_NightlyOpen, kSM_WaitingRun, kSM_Logging, kSM_DailyWriteError, kSM_RunWriteError)787 (bind(&DataLogger::GoToReady Please, this))786 AddEvent("STOP", kSM_NightlyOpen, kSM_WaitingRun, kSM_Logging, kSM_DailyWriteError, kSM_RunWriteError) 787 (bind(&DataLogger::GoToReady, this)) 788 788 ("Stop all data logging, close all files."); 789 789 /* 790 790 AddEvent(kSM_Logging, "START_RUN", kSM_WaitingRun, kSM_BadRunConfig) 791 (bind(&DataLogger::StartRun Please, this))791 (bind(&DataLogger::StartRun, this)) 792 792 ("Start the run logging. Run file location must be specified already."); 793 793 … … 796 796 ("Wait for a run to be started, open run-files as soon as a run number arrives."); 797 797 */ 798 AddEvent( kSM_Ready,"RESET", kSM_Error, kSM_BadFolder, kSM_DailyWriteError, kSM_RunWriteError)799 (bind(&DataLogger::GoToReady Please, this))798 AddEvent("RESET", kSM_Error, kSM_BadFolder, kSM_DailyWriteError, kSM_RunWriteError) 799 (bind(&DataLogger::GoToReady, this)) 800 800 ("Transition to exit error states. Closes the any open file."); 801 801 802 AddEvent( kSM_WaitingRun,"START_RUN_LOGGING", /*kSM_Logging,*/ kSM_NightlyOpen, kSM_Ready)803 (bind(&DataLogger::NightlyToWaitRun Please, this))802 AddEvent("START_RUN_LOGGING", /*kSM_Logging,*/ kSM_NightlyOpen, kSM_Ready) 803 (bind(&DataLogger::NightlyToWaitRun, this)) 804 804 ("Go to waiting for run number state. In this state with any received run-number a new file is opened."); 805 805 806 AddEvent( kSM_NightlyOpen,"STOP_RUN_LOGGING", kSM_WaitingRun, kSM_Logging)807 (bind(&DataLogger::BackToNightlyOpen Please, this))806 AddEvent("STOP_RUN_LOGGING", kSM_WaitingRun, kSM_Logging) 807 (bind(&DataLogger::BackToNightlyOpen, this)) 808 808 ("Go from the wait for run to nightly open state."); 809 809 … … 822 822 // Provide a print command 823 823 AddEvent("PRINT_INFO") 824 (bind(&DataLogger::PrintState Please, this, placeholders::_1))824 (bind(&DataLogger::PrintState, this, placeholders::_1)) 825 825 ("Print information about the internal status of the data logger."); 826 826 … … 931 931 } 932 932 //go to the ready state. i.e. close all files, run-wise first 933 GoToReady Please();933 GoToReady(); 934 934 935 935 … … 944 944 // messageBackup.reset(); 945 945 946 if (fNightlyLogFile.is_open())//this file is the only one that has not been closed by GoToReady Please946 if (fNightlyLogFile.is_open())//this file is the only one that has not been closed by GoToReady 947 947 { 948 948 // dim_lock(); … … 982 982 { 983 983 fAutoStarted = true; 984 SetCurrentState(Start Please());984 SetCurrentState(Start()); 985 985 } 986 986 else {if (GetCurrentState() > kSM_Ready) … … 1009 1009 } 1010 1010 if (!found) 1011 {1012 DimServiceInfoList::infoHandler();1013 1011 return; 1014 } 1012 1015 1013 if (I->getSize() <= 0 || I->getData()==NULL) 1016 1014 { … … 1040 1038 CheckForRunNumber(I); 1041 1039 1042 Report Please(I, y->second);1040 Report(I, y->second); 1043 1041 1044 1042 //remove old run numbers … … 1167 1165 //! The dataLogger's subscription corresponding to this DimInfo 1168 1166 // 1169 void DataLogger::Report Please(DimInfo* I, SubscriptionType& sub)1167 void DataLogger::Report(DimInfo* I, SubscriptionType& sub) 1170 1168 { 1171 1169 const string fmt(I->getFormat()); … … 1236 1234 1237 1235 fFullNightlyLogFileName = CompileFileNameWithPath(fFilePath, "", "log"); 1238 if (!OpenTextFile Please(fNightlyLogFile, fFullNightlyLogFileName))1239 { 1240 GoToReady Please();1236 if (!OpenTextFile(fNightlyLogFile, fFullNightlyLogFileName)) 1237 { 1238 GoToReady(); 1241 1239 SetCurrentState(kSM_BadFolder); 1242 1240 return; … … 1245 1243 1246 1244 fFullNightlyReportFileName = CompileFileNameWithPath(fFilePath, "", "rep"); 1247 if (!OpenTextFile Please(fNightlyReportFile, fFullNightlyReportFileName))1248 { 1249 GoToReady Please();1245 if (!OpenTextFile(fNightlyReportFile, fFullNightlyReportFileName)) 1246 { 1247 GoToReady(); 1250 1248 SetCurrentState(kSM_BadFolder); 1251 1249 return; … … 1377 1375 if (!sub.nightlyFile.IsOpen() || !sub.runFile.IsOpen() || sub.runNumber != sub.runFile.fRunNumber) 1378 1376 if (GetCurrentState() != kSM_Ready) 1379 OpenFITSFiles Please(sub, cRunNumber);1377 OpenFITSFiles(sub, cRunNumber); 1380 1378 WriteToFITS(sub); 1381 1379 #endif … … 1427 1425 if (!sub.nightlyFile.IsOpen() || !sub.runFile.IsOpen() || sub.runNumber != sub.runFile.fRunNumber) 1428 1426 if (GetCurrentState() != kSM_Ready) 1429 OpenFITSFiles Please(sub, cRunNumber);1427 OpenFITSFiles(sub, cRunNumber); 1430 1428 WriteToFITS(sub); 1431 1429 } … … 1441 1439 //! the new state. Which, in that case, is the current state 1442 1440 //! 1443 int DataLogger::PrintState Please(const Event& )1441 int DataLogger::PrintState(const Event& ) 1444 1442 { 1445 1443 Message("------------------------------------------"); … … 1738 1736 //! @returns 1739 1737 //! kSM_NightlyOpen if success, kSM_BadFolder if failure 1740 int DataLogger::Start Please()1738 int DataLogger::Start() 1741 1739 { 1742 1740 if (fDebugIsOn) … … 1746 1744 fFullNightlyLogFileName = CompileFileNameWithPath(fFilePath, "", "log"); 1747 1745 bool nightlyLogOpen = fNightlyLogFile.is_open(); 1748 if (!OpenTextFile Please(fNightlyLogFile, fFullNightlyLogFileName))1746 if (!OpenTextFile(fNightlyLogFile, fFullNightlyLogFileName)) 1749 1747 return kSM_BadFolder; 1750 1748 if (!nightlyLogOpen) … … 1752 1750 1753 1751 fFullNightlyReportFileName = CompileFileNameWithPath(fFilePath, "", "rep"); 1754 if (!OpenTextFile Please(fNightlyReportFile, fFullNightlyReportFileName))1752 if (!OpenTextFile(fNightlyReportFile, fFullNightlyReportFileName)) 1755 1753 { 1756 1754 fNightlyLogFile.close(); … … 1776 1774 //! @param sub 1777 1775 //! the current DimInfo subscription being examined 1778 void DataLogger::OpenFITSFiles Please(SubscriptionType& sub, RunNumberType* cRunNumber)1776 void DataLogger::OpenFITSFiles(SubscriptionType& sub, RunNumberType* cRunNumber) 1779 1777 { 1780 1778 string serviceName(sub.dimInfo->getName()); … … 1993 1991 //! @returns 1994 1992 //! kSM_Logging if success, kSM_BadRunConfig if failure. 1995 int DataLogger::StartRun Please()1993 int DataLogger::StartRun() 1996 1994 { 1997 1995 if (fDebugIsOn) … … 2003 2001 if (OpenRunFile(*it) != 0) 2004 2002 { 2005 StopRun Please();2003 StopRun(); 2006 2004 return kSM_BadRunConfig; 2007 2005 } … … 2219 2217 //! @returns 2220 2218 //! kSM_Ready 2221 int DataLogger::GoToReady Please()2219 int DataLogger::GoToReady() 2222 2220 { 2223 2221 if (fDebugIsOn) … … 2264 2262 //! @returns 2265 2263 //! kSM_WaitingRun or kSM_BadFolder 2266 int DataLogger::NightlyToWaitRun Please()2264 int DataLogger::NightlyToWaitRun() 2267 2265 { 2268 2266 int cState = GetCurrentState(); … … 2272 2270 2273 2271 if (cState == kSM_Ready) 2274 cState = Start Please();2272 cState = Start(); 2275 2273 2276 2274 if (cState != kSM_NightlyOpen) … … 2289 2287 //! @returns 2290 2288 //! kSM_WaitingRun 2291 int DataLogger::BackToNightlyOpen Please()2289 int DataLogger::BackToNightlyOpen() 2292 2290 { 2293 2291 if (GetCurrentState()==kSM_Logging) … … 2349 2347 fFilePath = folder; 2350 2348 fFullNightlyLogFileName = CompileFileNameWithPath(fFilePath, "", "log"); 2351 if (!OpenTextFile Please(fNightlyLogFile, fFullNightlyLogFileName))2349 if (!OpenTextFile(fNightlyLogFile, fFullNightlyLogFileName)) 2352 2350 return 3; 2353 2351 -
trunk/FACT++/src/feedback.cc
r13721 r13838 28 28 29 29 #include "DimDescriptionService.h" 30 #include "DimState.h" 30 31 31 32 // ------------------------------------------------------------------------ 32 33 33 class StateMachineFeedback : public StateMachineDim , public DimInfoHandler34 class StateMachineFeedback : public StateMachineDim 34 35 { 35 /*36 int Wrap(boost::function<void()> f)37 {38 f();39 return T::GetCurrentState();40 }41 42 boost::function<int(const EventImp &)> Wrapper(boost::function<void()> func)43 {44 return bind(&StateMachineMCP::Wrap, this, func);45 }*/46 47 36 private: 48 37 enum states_t … … 76 65 PixelMap fMap; 77 66 78 DimServiceInfoList fNetwork; 79 80 pair<Time, int> fStatusDim; 81 pair<Time, int> fStatusFAD; 82 pair<Time, int> fStatusFSC; 83 pair<Time, int> fStatusBias; 84 85 DimStampedInfo fDim; 86 DimStampedInfo fFAD; 87 DimStampedInfo fFSC; 88 DimStampedInfo fBias; 89 DimStampedInfo fBiasA; 90 91 DimStampedInfo fBiasData; 92 DimStampedInfo fBiasNom; 93 DimStampedInfo fCameraTemp; 67 DimServiceInfoListImp fNetwork; 68 69 DimVersion fDim; 70 DimState fDimFAD; 71 DimState fDimFSC; 72 DimState fDimBias; 94 73 95 74 DimDescribedService fDimReference; … … 133 112 bool fOutputEnabled; 134 113 135 pair<Time, int> GetNewState(DimStampedInfo &info) const 136 { 137 const bool disconnected = info.getSize()==0; 138 139 // Make sure getTimestamp is called _before_ getTimestampMillisecs 140 const int tsec = info.getTimestamp(); 141 const int tms = info.getTimestampMillisecs(); 142 143 return make_pair(Time(tsec, tms*1000), 144 disconnected ? -2 : info.getQuality()); 145 } 146 147 void HandleCameraTemp() 148 { 149 if (fCameraTemp.getSize()!=60*sizeof(float)) 150 return; 151 152 const float *ptr = static_cast<float*>(fCameraTemp.getData()); 114 int HandleCameraTemp(const EventImp &evt) 115 { 116 if (fControlType!=kTemp && fControlType!=kCurrents) 117 return GetCurrentState(); 118 119 if (evt.GetSize()!=60*sizeof(float)) 120 return GetCurrentState(); 121 122 const float *ptr = evt.Ptr<float>(); 153 123 154 124 double avgt = 0; … … 164 134 { 165 135 Warn("Received sensor temperatures all invalid."); 166 return ;136 return GetCurrentState(); 167 137 } 168 138 … … 177 147 Warn("Trying to calibrate above G-APD breakdown volatge!"); 178 148 Warn(msg); 179 return ;149 return GetCurrentState(); 180 150 } 181 151 … … 206 176 { 207 177 //DimClient::sendCommandNB("BIAS_CONTROL/REQUEST_STATUS", NULL, 0); 208 return ;178 return GetCurrentState(); 209 179 } 210 180 … … 275 245 vec[i+BIAS::kNumChannels] += dU; 276 246 247 // Angelegte Spannung: U0+dU 248 // Gemessener Strom: Im - Iavg 249 // Strom offset: (U0+dU) / Ravg 250 // Fliessender Strom: Im-Iavg - (U0+dU)/Ravg 251 // Korrektur: [ Im-Iavg - (U0+dU)/Ravg ] * Rg 252 253 // Aufgeloest nach dU: dU = ( Im-Iavg - dU/Ravg ) / ( 1/Rg + 1/Ravg ) 254 // Equivalent zu: dU = ( I*Ravg - U0 ) / ( Ravg/Rg+1 ) 255 277 256 // Calculate statistics only for channels with a valid calibration 278 257 if (Iavg[i]>0) … … 299 278 fDimDeviation.Update(vec); 300 279 301 if (!fOutputEnabled || f StatusBias.second!=BIAS::kVoltageOn)302 return ;280 if (!fOutputEnabled || fDimBias.state()!=BIAS::kVoltageOn) 281 return GetCurrentState(); 303 282 304 283 // Trigger calibration … … 306 285 { 307 286 DimClient::sendCommandNB("BIAS_CONTROL/REQUEST_STATUS", NULL, 0); 308 return ;287 return GetCurrentState(); 309 288 } 310 289 … … 336 315 337 316 fCursorTemp++; 338 } 339 340 int AverageCurrents() 341 { 342 if (fBiasA.getSize()!=BIAS::kNumChannels*sizeof(int16_t)) 317 318 return GetCurrentState(); 319 } 320 321 int AverageCurrents(const EventImp &evt) 322 { 323 if (evt.GetSize()!=BIAS::kNumChannels*sizeof(int16_t)) 343 324 return -1; 344 325 345 if (f StatusBias.second!=BIAS::kVoltageOn)326 if (fDimBias.state()!=BIAS::kVoltageOn) 346 327 return false; 347 328 … … 349 330 return true; 350 331 351 const int16_t *ptr = static_cast<int16_t*>(fBiasA.getData());332 const int16_t *ptr = evt.Ptr<int16_t>(); 352 333 353 334 for (int i=0; i<BIAS::kNumChannels; i++) … … 361 342 362 343 363 void HandleCalibration( )364 { 365 const int rc = AverageCurrents( );344 void HandleCalibration(const EventImp &evt) 345 { 346 const int rc = AverageCurrents(evt); 366 347 if (rc<0) 367 348 return; … … 369 350 if (fCursorCur<fNumCalibRequests) 370 351 { 371 if (f StatusBias.second==BIAS::kVoltageOn)352 if (fDimBias.state()==BIAS::kVoltageOn) 372 353 DimClient::sendCommandNB("BIAS_CONTROL/REQUEST_STATUS", NULL, 0); 373 354 return; … … 401 382 Info("Calibration successfully done."); 402 383 403 if (f StatusBias.second==BIAS::kVoltageOn)384 if (fDimBias.state()==BIAS::kVoltageOn) 404 385 DimClient::sendCommandNB("BIAS_CONTROL/REQUEST_STATUS", NULL, 0); 405 386 } 406 387 407 void HandleFeedback( )408 { 409 if ( fBiasData.getSize()!=1440*sizeof(float))388 void HandleFeedback(const EventImp &evt) 389 { 390 if (evt.GetSize()!=1440*sizeof(float)) 410 391 return; 411 392 412 393 // -------- Check age of last stored event -------- 413 394 414 // Must be called in this order 415 const int tsec = fBiasData.getTimestamp(); 416 const int tms = fBiasData.getTimestampMillisecs(); 417 418 const Time tm(tsec, tms*1000); 395 const Time tm(evt.GetTime()); 419 396 420 397 if (Time()-fBiasLast>boost::posix_time::seconds(30)) … … 427 404 // -------- Store new event -------- 428 405 429 fData[fCursorAmpl%fData.size()].assign(reinterpret_cast<float*>(fBiasData.getData()), 430 reinterpret_cast<float*>(fBiasData.getData())+1440); 431 406 fData[fCursorAmpl%fData.size()].assign(evt.Ptr<float>(), evt.Ptr<float>()+1440); 432 407 if (++fCursorAmpl<fData.size()) 433 408 return; … … 610 585 fDimDeviation.Update(vec); 611 586 612 if (!fOutputEnabled || f StatusBias.second!=BIAS::kVoltageOn)587 if (!fOutputEnabled || fDimBias.state()!=BIAS::kVoltageOn) 613 588 return; 614 589 … … 619 594 } 620 595 621 void HandleGlobalFeedback( )622 { 623 if ( fBiasData.getSize()!=1440*sizeof(float))596 void HandleGlobalFeedback(const EventImp &evt) 597 { 598 if (evt.GetSize()!=1440*sizeof(float)) 624 599 return; 625 600 626 601 // -------- Store new event -------- 627 602 628 vector<float> arr(reinterpret_cast<float*>(fBiasData.getData()), 629 reinterpret_cast<float*>(fBiasData.getData())+1440); 603 vector<float> arr(evt.Ptr<float>(), evt.Ptr<float>()+1440); 630 604 631 605 sort(arr.begin(), arr.end()); … … 744 718 fDimDeviation.Update(vec); 745 719 746 if (!fOutputEnabled || f StatusBias.second!=BIAS::kVoltageOn)720 if (!fOutputEnabled || fDimBias.state()!=BIAS::kVoltageOn) 747 721 return; 748 722 … … 753 727 } 754 728 755 void infoHandler() 756 { 757 DimInfo *curr = getInfo(); // get current DimInfo address 758 if (!curr) 759 return; 760 761 if (curr==&fBias) 762 { 763 fStatusBias = GetNewState(fBias); 764 return; 765 } 766 767 if (curr==&fFAD) 768 { 769 fStatusFAD = GetNewState(fFAD); 770 return; 771 } 772 773 if (curr==&fFSC) 774 { 775 fStatusFSC = GetNewState(fFSC); 776 return; 777 } 778 779 if (curr==&fDim) 780 { 781 fStatusDim = GetNewState(fDim); 782 fStatusDim.second = curr->getSize()==4 ? curr->getInt() : 0; 783 return; 784 } 785 786 if (curr==&fBiasNom) 787 { 788 const float *ptr = reinterpret_cast<float*>(fBiasNom.getData()); 789 fVoltGapd.assign(ptr, ptr+416); 790 Info("Nominal bias voltages received."); 791 return; 792 } 793 794 if (curr==&fCameraTemp && (fControlType==kTemp || fControlType==kCurrents)) 795 HandleCameraTemp(); 796 797 if (curr==&fBiasA && fControlType==kTemp && GetCurrentState()==kStateCalibrating) 798 HandleCalibration(); 799 800 if (curr==&fBiasA && (fControlType==kFeedbackGlobal || fControlType==kCurrents)) 801 AverageCurrents(); 802 803 if (curr==&fBiasData && fControlType==kFeedback) 804 HandleFeedback(); 805 806 if (curr==&fBiasData && fControlType==kFeedbackGlobal) 807 HandleGlobalFeedback(); 729 int HandleBiasCurrent(const EventImp &evt) 730 { 731 if (fControlType==kTemp && GetCurrentState()==kStateCalibrating) 732 HandleCalibration(evt); 733 734 if (fControlType==kFeedbackGlobal || fControlType==kCurrents) 735 AverageCurrents(evt); 736 737 return GetCurrentState(); 738 } 739 740 int HandleBiasData(const EventImp &evt) 741 { 742 if (fControlType==kFeedback) 743 HandleFeedback(evt); 744 745 if (fControlType==kFeedbackGlobal) 746 HandleGlobalFeedback(evt); 747 748 return GetCurrentState(); 749 } 750 751 int HandleBiasNom(const EventImp &evt) 752 { 753 fVoltGapd.assign(evt.Ptr<float>(), evt.Ptr<float>()+416); 754 755 Info("Nominal bias voltages received."); 756 757 return GetCurrentState(); 808 758 } 809 759 … … 819 769 } 820 770 771 const State GetState(const DimState &s) const 772 { 773 return fNetwork.GetState(s.name(), s.state()); 774 } 775 776 void PrintState(const DimState &state) const 777 { 778 const State rc = GetState(state); 779 780 Out() << state.time().GetAsStr("%H:%M:%S.%f").substr(0, 12) << " - "; 781 Out() << kBold << state.name() << ": "; 782 if (rc.index==-3) 783 { 784 Out() << kReset << "Offline" << endl; 785 return; 786 } 787 if (rc.index==-2) 788 Out() << state.state(); 789 else 790 Out() << rc.name << "[" << rc.index << "]"; 791 Out() << kReset << " - " << kBlue << rc.comment << endl; 792 } 793 794 int Print() const 795 { 796 Out() << fDim.time().GetAsStr("%H:%M:%S.%f").substr(0, 12) << " - "; 797 Out() << kBold << "DIM_DNS: " << fDim.version() << endl; 798 799 PrintState(fDimFAD); 800 PrintState(fDimFSC); 801 PrintState(fDimBias); 802 803 return GetCurrentState(); 804 } 805 /* 821 806 void PrintState(const pair<Time,int> &state, const char *server) 822 807 { … … 844 829 return GetCurrentState(); 845 830 } 846 831 */ 847 832 int PrintCalibration() 848 833 { … … 886 871 void WarnState(bool needfsc, bool needfad) 887 872 { 888 const bool bias = f StatusBias.second>= BIAS::kConnecting;889 const bool fsc = f StatusFSC.second>= 2;890 const bool fad = f StatusFAD.second>= FAD::kConnected;873 const bool bias = fDimBias.state() >= BIAS::kConnecting; 874 const bool fsc = fDimFSC.state() >= 2; 875 const bool fad = fDimFAD.state() >= FAD::kConnected; 891 876 892 877 if (!bias) … … 1000 985 Message(out); 1001 986 1002 if (f StatusBias.second==BIAS::kVoltageOn)987 if (fDimBias.state()==BIAS::kVoltageOn) 1003 988 DimClient::sendCommandNB("BIAS_CONTROL/REQUEST_STATUS", NULL, 0); 1004 989 … … 1091 1076 // return kSM_FatalError; 1092 1077 1093 if (f StatusBias.second==BIAS::kRamping)1078 if (fDimBias.state()==BIAS::kRamping) 1094 1079 { 1095 1080 Warn("Calibration cannot be started when biasctrl is in state Ramping."); … … 1143 1128 //poll_one(); 1144 1129 1145 if ( fStatusDim.second==0)1130 if (!fDim.online()) 1146 1131 return kStateDimNetworkNA; 1147 1132 1148 const bool bias = f StatusBias.second>= BIAS::kConnecting;1149 const bool fad = f StatusFAD.second>= FAD::kConnected;1150 const bool fsc = f StatusFSC.second>= 2;1133 const bool bias = fDimBias.state() >= BIAS::kConnecting; 1134 const bool fad = fDimFAD.state() >= FAD::kConnected; 1135 const bool fsc = fDimFSC.state() >= 2; 1151 1136 1152 1137 // All subsystems are not connected … … 1220 1205 if (fCurrentRequestInterval>0 && Time()-past>boost::posix_time::milliseconds(fCurrentRequestInterval)) 1221 1206 { 1222 if (f StatusBias.second==BIAS::kVoltageOn)1207 if (fDimBias.state()==BIAS::kVoltageOn) 1223 1208 DimClient::sendCommandNB("BIAS_CONTROL/REQUEST_STATUS", NULL, 0); 1224 1209 past = Time(); … … 1240 1225 public: 1241 1226 StateMachineFeedback(ostream &out=cout) : StateMachineDim(out, "FEEDBACK"), 1242 fStatusDim(make_pair(Time(), -2)), 1243 fStatusFAD(make_pair(Time(), -2)), 1244 fStatusBias(make_pair(Time(), -2)), 1245 fDim("DIS_DNS/VERSION_NUMBER", (void*)NULL, 0, this), 1246 fFAD("FAD_CONTROL/STATE", (void*)NULL, 0, this), 1247 fFSC("FSC_CONTROL/STATE", (void*)NULL, 0, this), 1248 fBias("BIAS_CONTROL/STATE", (void*)NULL, 0, this), 1249 fBiasA("BIAS_CONTROL/CURRENT", (void*)NULL, 0, this), 1250 fBiasData("FAD_CONTROL/FEEDBACK_DATA", (void*)NULL, 0, this), 1251 fBiasNom("BIAS_CONTROL/NOMINAL", (void*)NULL, 0, this), 1252 fCameraTemp("FSC_CONTROL/TEMPERATURE", (void*)NULL, 0, this), 1227 //--- 1228 fDimFAD("FAD_CONTROL"), 1229 fDimFSC("FSC_CONTROL"), 1230 fDimBias("BIAS_CONTROL"), 1231 //--- 1253 1232 fDimReference("FEEDBACK/REFERENCE", "F:416", 1254 1233 "Amplitude reference value(s)" … … 1280 1259 // deletion and creation of threads and more. 1281 1260 1282 // fSP.resize(416); 1261 fDim.Subscribe(*this); 1262 fDimFAD.Subscribe(*this); 1263 fDimFSC.Subscribe(*this); 1264 fDimBias.Subscribe(*this); 1265 1266 Subscribe("BIAS_CONTROL/CURRENT") 1267 (bind(&StateMachineFeedback::HandleBiasCurrent, this, placeholders::_1)); 1268 Subscribe("BIAS_CONTROL/FEEDBACK_DATA") 1269 (bind(&StateMachineFeedback::HandleBiasData, this, placeholders::_1)); 1270 Subscribe("FSC_CONTROL/TEMPERATURE") 1271 (bind(&StateMachineFeedback::HandleCameraTemp, this, placeholders::_1)); 1283 1272 1284 1273 // State names -
trunk/FACT++/src/logtime.cc
r12853 r13838 14 14 DimServer::start("TIME"); 15 15 16 17 16 18 // Some info on the console 17 19 std::cout << "Offering TIME/MESSAGE...\n" << std::endl; … … 26 28 // wait approximately one second 27 29 usleep(1000000); 30 31 //std::cout << DimServer::getClientName() << std::endl; 32 //std::cout << DimServer::getClientId() << std::endl; 33 //std::cout << DimServer::getDnsPort() << std::endl; 34 std::cout << "con: " << dis_get_conn_id() << std::endl; 35 36 char **ids = DimServer::getClientServices(); 37 38 while (*ids) 39 { 40 std::cout << *ids << std::endl; 41 ids++; 42 } 28 43 } 29 44 -
trunk/FACT++/src/mcp.cc
r13794 r13838 26 26 27 27 #include "DimDescriptionService.h" 28 #include "DimState.h" 28 29 29 30 // ------------------------------------------------------------------------ 30 31 31 class StateMachineMCP : public StateMachineDim , public DimInfoHandler32 class StateMachineMCP : public StateMachineDim 32 33 { 33 /*34 int Wrap(boost::function<void()> f)35 {36 f();37 return T::GetCurrentState();38 }39 40 boost::function<int(const EventImp &)> Wrapper(boost::function<void()> func)41 {42 return bind(&StateMachineMCP::Wrap, this, func);43 }*/44 45 34 private: 46 35 enum states_t … … 61 50 }; 62 51 63 DimServiceInfoList fNetwork; 64 65 pair<Time, int> fStatusDim; 66 pair<Time, int> fStatusFTM; 67 pair<Time, int> fStatusFAD; 68 pair<Time, int> fStatusLog; 69 pair<Time, int> fStatusRC; 70 71 DimStampedInfo fDim; 72 DimStampedInfo fFTM; 73 DimStampedInfo fFAD; 74 DimStampedInfo fLog; 75 DimStampedInfo fRC; 52 DimServiceInfoListImp fNetwork; 53 54 DimVersion fDim; 55 DimState fDimFTM; 56 DimState fDimFAD; 57 DimState fDimLog; 58 DimState fDimRC; 76 59 77 60 DimDescribedService fService; 78 61 79 pair<Time, int> GetNewState(DimStampedInfo &info) const 80 { 81 const bool disconnected = info.getSize()==0; 82 83 // Make sure getTimestamp is called _before_ getTimestampMillisecs 84 const int tsec = info.getTimestamp(); 85 const int tms = info.getTimestampMillisecs(); 86 87 return make_pair(Time(tsec, tms*1000), 88 disconnected ? -2 : info.getQuality()); 89 } 90 91 void infoHandler() 92 { 93 DimInfo *curr = getInfo(); // get current DimInfo address 94 if (!curr) 62 const State GetState(const DimState &s) const 63 { 64 return fNetwork.GetState(s.name(), s.state()); 65 } 66 67 void PrintState(const DimState &state) const 68 { 69 const State rc = GetState(state); 70 71 Out() << state.time().GetAsStr("%H:%M:%S.%f").substr(0, 12) << " - "; 72 Out() << kBold << state.name() << ": "; 73 if (rc.index==-3) 74 { 75 Out() << kReset << "Offline" << endl; 95 76 return; 96 97 if (curr==&fFTM) 98 { 99 fStatusFTM = GetNewState(fFTM); 100 return; 101 } 102 103 if (curr==&fFAD) 104 { 105 fStatusFAD = GetNewState(fFAD); 106 return; 107 } 108 109 if (curr==&fLog) 110 { 111 fStatusLog = GetNewState(fLog); 112 return; 113 } 114 115 if (curr==&fRC) 116 { 117 fStatusRC = GetNewState(fRC); 118 return; 119 } 120 121 if (curr==&fDim) 122 { 123 fStatusDim = GetNewState(fDim); 124 fStatusDim.second = curr->getSize()==4 ? curr->getInt() : 0; 125 return; 126 } 127 } 128 129 bool CheckEventSize(size_t has, const char *name, size_t size) 130 { 131 if (has==size) 132 return true; 133 134 ostringstream msg; 135 msg << name << " - Received event has " << has << " bytes, but expected " << size << "."; 136 Fatal(msg); 137 return false; 138 } 139 140 int SetVerbosity(const EventImp &) 141 { 142 /* 143 if (!CheckEventSize(evt.GetSize(), "SetVerbosity", 1)) 144 return T::kSM_FatalError; 145 146 fFSC.SetVerbose(evt.GetBool()); 147 148 */ 77 } 78 if (rc.index==-2) 79 Out() << state.state(); 80 else 81 Out() << rc.name << "[" << rc.index << "]"; 82 Out() << kReset << " - " << kBlue << rc.comment << endl; 83 } 84 85 int Print() const 86 { 87 Out() << fDim.time().GetAsStr("%H:%M:%S.%f").substr(0, 12) << " - "; 88 Out() << kBold << "DIM_DNS: " << fDim.version() << endl; 89 90 PrintState(fDim); 91 PrintState(fDimFTM); 92 PrintState(fDimFAD); 93 PrintState(fDimLog); 94 PrintState(fDimRC); 149 95 150 96 return GetCurrentState(); 151 97 } 152 98 153 154 void PrintState(const pair<Time,int> &state, const char *server) 155 { 156 const State rc = fNetwork.GetState(server, state.second); 157 158 Out() << state.first.GetAsStr("%H:%M:%S.%f").substr(0, 12) << " - "; 159 Out() << kBold << server << ": "; 160 Out() << rc.name << "[" << rc.index << "]"; 161 Out() << kReset << " - " << kBlue << rc.comment << endl; 162 } 163 164 int Print() 165 { 166 Out() << fStatusDim.first.GetAsStr("%H:%M:%S.%f").substr(0, 12) << " - "; 167 Out() << kBold << "DIM_DNS: "; 168 if (fStatusDim.second==0) 169 Out() << "Offline" << endl; 170 else 171 Out() << "V" << fStatusDim.second/100 << 'r' << fStatusDim.second%100 << endl; 172 173 PrintState(fStatusFTM, "FTM_CONTROL"); 174 PrintState(fStatusFAD, "FAD_CONTROL"); 175 PrintState(fStatusLog, "DATA_LOGGER"); 176 PrintState(fStatusRC, "RATE_CONTROL"); 177 99 int GetReady() 100 { 178 101 return GetCurrentState(); 179 102 } 180 103 181 int GetReady()182 {183 return GetCurrentState();184 }185 186 104 int StopRun(const EventImp &) 187 105 { 188 if (f StatusFTM.second==FTM::kTriggerOn)106 if (fDimFTM.state()==FTM::kTriggerOn) 189 107 { 190 108 Message("Stopping FTM"); … … 193 111 194 112 // FIXME: Do step 2 only when FTM is stopped 195 if (f StatusFAD.second==FAD::kConnected)113 if (fDimFAD.state()==FAD::kConnected) 196 114 { 197 115 //Dim::SendCommand("FAD_CONTROL/ENABLE_TRIGGER_LINE", bool(false)); … … 213 131 /* 214 132 // FIMXE: Handle error states! 215 if (f StatusLog.second>=20)//kSM_NightlyOpen133 if (fDimLog.state()>=20)//kSM_NightlyOpen 216 134 Dim::SendCommand("DATA_LOGGER/STOP"); 217 135 218 if (f StatusLog.second==0)136 if (fDimLog.state()==0) 219 137 Dim::SendCommand("DATA_LOGGER/WAIT_FOR_RUN_NUMBER"); 220 138 221 if (f StatusFAD.second==FAD::kConnected)139 if (fDimFAD.state()==FAD::kConnected) 222 140 { 223 141 Dim::SendCommand("FAD_CONTROL/ENABLE_TRIGGER_LINE", bool(false)); … … 225 143 } 226 144 227 if (f StatusFTM.second==FTM::kTakingData)145 if (fDimFTM.state()==FTM::kTakingData) 228 146 Dim::SendCommand("FTM_CONTROL/STOP"); 229 147 … … 237 155 int StartRun(const EventImp &evt) 238 156 { 239 if (f StatusFTM.second==-2)157 if (fDimFTM.state()==-2) 240 158 { 241 159 Error("No connection to ftmcontrol (see PRINT)."); 242 160 return GetCurrentState(); 243 161 } 244 if (f StatusFAD.second==-2)162 if (fDimFAD.state()==-2) 245 163 { 246 164 Warn("No connection to fadcontrol (see PRINT)."); 247 165 return GetCurrentState(); 248 166 } 249 if (f StatusLog.second==-2)167 if (fDimLog.state()==-2) 250 168 { 251 169 Warn("No connection to datalogger (see PRINT)."); 252 170 return GetCurrentState(); 253 171 } 254 if (f StatusRC.second==-2)172 if (fDimRC.state()==-2) 255 173 { 256 174 Warn("No connection to ratecontrol (see PRINT)."); … … 332 250 //poll_one(); 333 251 334 if ( fStatusDim.second==0)252 if (!fDim.online()) 335 253 return kStateDimNetworkNA; 336 254 337 if (f StatusFTM.second>= FTM::kConnected &&338 f StatusFAD.second>= FAD::kConnected &&339 f StatusLog.second>= kSM_Ready)255 if (fDimFTM.state() >= FTM::kConnected && 256 fDimFAD.state() >= FAD::kConnected && 257 fDimLog.state() >= kSM_Ready) 340 258 { 341 259 if (GetCurrentState()==kStateConfiguring1) 342 260 { 343 if (f StatusLog.second<30/*kSM_WaitForRun*/)261 if (fDimLog.state()<30/*kSM_WaitForRun*/) 344 262 { 345 263 Message("Starting datalogger"); … … 355 273 { 356 274 // FIMXE: Reset in case of error 357 if ((/*f StatusFTM.second!= FTM::kConfiguring2 &&*/358 f StatusFTM.second!= FTM::kConfigured) ||359 f StatusLog.second<30 || fStatusLog.second>0xff)275 if ((/*fDimFTM.state() != FTM::kConfiguring2 &&*/ 276 fDimFTM.state() != FTM::kConfigured) || 277 fDimLog.state()<30 || fDimLog.state()>0xff) 360 278 return GetCurrentState(); 361 279 … … 374 292 if (GetCurrentState()==kStateConfiguring3) 375 293 { 376 if (f StatusFTM.second!= FTM::kConfigured ||377 f StatusFAD.second!= FAD::kConfigured ||378 f StatusRC.second< 6)294 if (fDimFTM.state() != FTM::kConfigured || 295 fDimFAD.state() != FAD::kConfigured || 296 fDimRC.state() < 6) 379 297 return GetCurrentState(); 380 298 … … 387 305 if (GetCurrentState()==kStateConfigured) 388 306 { 389 if (f StatusFTM.second!= FTM::kTriggerOn)307 if (fDimFTM.state() != FTM::kTriggerOn) 390 308 return GetCurrentState(); 391 309 … … 397 315 if (GetCurrentState()==kStateTriggerOn) 398 316 { 399 if (f StatusFAD.second!= FAD::kWritingData)317 if (fDimFAD.state() != FAD::kWritingData) 400 318 return GetCurrentState(); 401 319 … … 407 325 if (GetCurrentState()==kStateTakingData) 408 326 { 409 if (f StatusFTM.second==FTM::kTriggerOn &&410 f StatusFAD.second==FAD::kWritingData)327 if (fDimFTM.state()==FTM::kTriggerOn && 328 fDimFAD.state()==FAD::kWritingData) 411 329 return kStateTakingData; 412 330 … … 418 336 419 337 /* 420 if (f StatusFTM.second>= FTM::kConnected &&421 f StatusFAD.second>= FAD::kConnected &&422 f StatusLog.second>= kSM_Ready)338 if (fDimFTM.state() >= FTM::kConnected && 339 fDimFAD.state() >= FAD::kConnected && 340 fDimLog.state() >= kSM_Ready) 423 341 return kStateIdle; 424 342 */ 425 if (f StatusFTM.second>-2 &&426 f StatusFAD.second>-2 &&427 f StatusLog.second>-2 &&428 f StatusRC.second>-2)343 if (fDimFTM.state() >-2 && 344 fDimFAD.state() >-2 && 345 fDimLog.state() >-2 && 346 fDimRC.state() >-2) 429 347 return kStateConnected; 430 348 431 if (f StatusFTM.second>-2 ||432 f StatusFAD.second>-2 ||433 f StatusLog.second>-2 ||434 f StatusRC.second>-2)349 if (fDimFTM.state() >-2 || 350 fDimFAD.state() >-2 || 351 fDimLog.state() >-2 || 352 fDimRC.state() >-2) 435 353 return kStateConnecting; 436 354 … … 440 358 public: 441 359 StateMachineMCP(ostream &out=cout) : StateMachineDim(out, "MCP"), 442 fStatusDim(make_pair(Time(), -2)), 443 fStatusFTM(make_pair(Time(), -2)), 444 fStatusFAD(make_pair(Time(), -2)), 445 fStatusLog(make_pair(Time(), -2)), 446 fDim("DIS_DNS/VERSION_NUMBER", (void*)NULL, 0, this), 447 fFTM("FTM_CONTROL/STATE", (void*)NULL, 0, this), 448 fFAD("FAD_CONTROL/STATE", (void*)NULL, 0, this), 449 fLog("DATA_LOGGER/STATE", (void*)NULL, 0, this), 450 fRC("RATE_CONTROL/STATE", (void*)NULL, 0, this), 360 fDimFTM("FTM_CONTROL"), 361 fDimFAD("FAD_CONTROL"), 362 fDimLog("DATA_LOGGER"), 363 fDimRC("RATE_CONTROL"), 451 364 fService("MCP/CONFIGURATION", "X:1;X:1;C", "Run configuration information" 452 365 "|MaxTime[s]:Maximum time before the run gets stopped" … … 461 374 // deletion and creation of threads and more. 462 375 376 fDim.Subscribe(*this); 377 fDimFTM.Subscribe(*this); 378 fDimFAD.Subscribe(*this); 379 fDimLog.Subscribe(*this); 380 fDimRC.Subscribe(*this); 381 463 382 // State names 464 383 AddStateName(kStateDimNetworkNA, "DimNetworkNotAvailable", … … 513 432 "is also propagated to FTM and FAD"); 514 433 515 // Verbosity commands516 AddEvent("SET_VERBOSE", "B:1")517 (bind(&StateMachineMCP::SetVerbosity, this, placeholders::_1))518 ("set verbosity state"519 "|verbosity[bool]:disable or enable verbosity for received data (yes/no), except dynamic data");520 521 434 AddEvent("PRINT") 522 435 (bind(&StateMachineMCP::Print, this)) … … 526 439 int EvalOptions(Configuration &) 527 440 { 528 //SetEndpoint(conf.Get<string>("addr"));529 530 //fFSC.SetVerbose(!conf.Get<bool>("quiet"));531 532 441 return -1; 533 442 } -
trunk/FACT++/src/ratecontrol.cc
r13756 r13838 27 27 28 28 #include "DimDescriptionService.h" 29 #include "DimState.h" 29 30 30 31 // ------------------------------------------------------------------------ 31 32 32 class StateMachineRateControl : public StateMachineDim , public DimInfoHandler33 class StateMachineRateControl : public StateMachineDim//, public DimInfoHandler 33 34 { 34 35 private: … … 50 51 vector<bool> fBlock; 51 52 52 DimServiceInfoList fNetwork; 53 54 pair<Time, int> fStatusDim; 55 pair<Time, int> fStatusFTM; 56 pair<Time, int> fStatusRS; 57 58 DimStampedInfo fDim; 59 DimStampedInfo fFTM; 60 DimStampedInfo fRates; 61 DimStampedInfo fStatic; 62 DimStampedInfo fRateScan; 63 64 // DimDescribedService fDimData; 65 // DimDescribedService fDimProc; 53 DimServiceInfoListImp fNetwork; 54 55 DimVersion fDim; 56 DimState fDimFTM; 57 DimState fDimRS; 66 58 67 59 float fTargetRate; … … 76 68 uint64_t fCounter; 77 69 78 pair<Time, int> GetNewState(DimStampedInfo &info) const 79 { 80 const bool disconnected = info.getSize()==0; 81 82 // Make sure getTimestamp is called _before_ getTimestampMillisecs 83 const int tsec = info.getTimestamp(); 84 const int tms = info.getTimestampMillisecs(); 85 86 return make_pair(Time(tsec, tms*1000), 87 disconnected ? -2 : info.getQuality()); 88 } 89 90 bool CheckEventSize(size_t has, const char *name, size_t size) 91 { 92 if (has==size) 70 bool CheckEventSize(const EventImp &evt, size_t size) 71 { 72 if (size_t(evt.GetSize())==size) 93 73 return true; 94 74 95 if ( has==0)75 if (evt.GetSize()==0) 96 76 return false; 97 77 98 78 ostringstream msg; 99 msg << name << " - Received event has " << has<< " bytes, but expected " << size << ".";79 msg << evt.GetName() << " - Received event has " << evt.GetSize() << " bytes, but expected " << size << "."; 100 80 Fatal(msg); 101 81 return false; … … 343 323 } 344 324 345 void infoHandler() 346 { 347 DimInfo *curr = getInfo(); // get current DimInfo address 348 if (!curr) 349 return; 350 351 if (curr==&fFTM) 352 { 353 fStatusFTM = GetNewState(fFTM); 354 return; 355 } 356 357 if (curr==&fDim) 358 { 359 fStatusDim = GetNewState(fDim); 360 fStatusDim.second = curr->getSize()==4 ? curr->getInt() : 0; 361 return; 362 } 363 if (curr==&fRateScan) 364 { 365 fStatusRS = GetNewState(fRateScan); 366 fStatusRS.second = curr->getSize()==4 ? curr->getInt() : 0; 367 return; 368 } 369 370 static vector<uint8_t> counter(160); 371 if (curr==&fStatic) 372 { 373 if (!CheckEventSize(curr->getSize(), "infoHandler[DimStaticData]", sizeof(FTM::DimStaticData))) 374 return; 375 376 const FTM::DimStaticData &sdata = *static_cast<FTM::DimStaticData*>(curr->getData()); 377 fTriggerOn = sdata.HasTrigger(); 378 379 PrintThresholds(sdata); 380 381 fThresholds.assign(sdata.fThreshold, sdata.fThreshold+160); 382 return; 383 } 384 385 if (curr==&fRates) 386 { 387 if (fThresholds.size()==0) 388 return; 389 390 if (!fTriggerOn && !fEnabled) 391 return; 392 393 if (fStatusRS.second==5) 394 return; 395 396 if (!CheckEventSize(curr->getSize(), "infoHandler[DimTriggerRates]", sizeof(FTM::DimTriggerRates))) 397 return; 398 399 const FTM::DimTriggerRates &sdata = *static_cast<FTM::DimTriggerRates*>(curr->getData()); 400 401 if (GetCurrentState()==kStateSettingGlobalThreshold) 402 ProcessCamera(sdata); 403 404 if (GetCurrentState()==kStateInProgress) 405 ProcessPatches(sdata); 406 } 325 int HandleStaticData(const EventImp &evt) 326 { 327 if (!CheckEventSize(evt, sizeof(FTM::DimStaticData))) 328 return GetCurrentState(); 329 330 const FTM::DimStaticData &sdata = *static_cast<const FTM::DimStaticData*>(evt.GetData()); 331 fTriggerOn = sdata.HasTrigger(); 332 333 PrintThresholds(sdata); 334 335 fThresholds.assign(sdata.fThreshold, sdata.fThreshold+160); 336 337 return GetCurrentState(); 338 } 339 340 int HandleTriggerRates(const EventImp &evt) 341 { 342 if (fThresholds.size()==0) 343 return GetCurrentState(); 344 345 if (!fTriggerOn && !fEnabled) 346 return GetCurrentState(); 347 348 if (fDimRS.state()==5) 349 return GetCurrentState(); 350 351 if (!CheckEventSize(evt, sizeof(FTM::DimTriggerRates))) 352 return GetCurrentState(); 353 354 const FTM::DimTriggerRates &sdata = *static_cast<const FTM::DimTriggerRates*>(evt.GetData()); 355 356 if (GetCurrentState()==kStateSettingGlobalThreshold) 357 ProcessCamera(sdata); 358 359 if (GetCurrentState()==kStateInProgress) 360 ProcessPatches(sdata); 361 362 return GetCurrentState(); 407 363 } 408 364 … … 446 402 int SetEnabled(const EventImp &evt) 447 403 { 448 if (!CheckEventSize(evt .GetSize(), "SetEnabled", 1))404 if (!CheckEventSize(evt, 1)) 449 405 return kSM_FatalError; 450 406 … … 456 412 int SetMinThreshold(const EventImp &evt) 457 413 { 458 if (!CheckEventSize(evt .GetSize(), "SetMinThreshold", 4))414 if (!CheckEventSize(evt, 4)) 459 415 return kSM_FatalError; 460 416 … … 468 424 int SetTargetRate(const EventImp &evt) 469 425 { 470 if (!CheckEventSize(evt .GetSize(), "SetTargetRate", 4))426 if (!CheckEventSize(evt, 4)) 471 427 return kSM_FatalError; 472 428 … … 475 431 return GetCurrentState(); 476 432 } 477 433 /* 478 434 void PrintState(const pair<Time,int> &state, const char *server) 479 435 { … … 500 456 return GetCurrentState(); 501 457 } 458 */ 459 460 const State GetState(const DimState &s) const 461 { 462 return fNetwork.GetState(s.name(), s.state()); 463 } 464 465 void PrintState(const DimState &state) const 466 { 467 const State rc = GetState(state); 468 469 Out() << state.time().GetAsStr("%H:%M:%S.%f").substr(0, 12) << " - "; 470 Out() << kBold << state.name() << ": "; 471 if (rc.index==-3) 472 { 473 Out() << kReset << "Offline" << endl; 474 return; 475 } 476 if (rc.index==-2) 477 Out() << state.state(); 478 else 479 Out() << rc.name << "[" << rc.index << "]"; 480 Out() << kReset << " - " << kBlue << rc.comment << endl; 481 } 482 483 int Print() const 484 { 485 Out() << fDim.time().GetAsStr("%H:%M:%S.%f").substr(0, 12) << " - "; 486 Out() << kBold << "DIM_DNS: " << fDim.version() << endl; 487 488 PrintState(fDimFTM); 489 PrintState(fDimRS); 490 491 return GetCurrentState(); 492 } 502 493 503 494 int SetVerbosity(const EventImp &evt) 504 495 { 505 if (!CheckEventSize(evt .GetSize(), "SetVerbosity", 1))496 if (!CheckEventSize(evt, 1)) 506 497 return kSM_FatalError; 507 498 … … 520 511 //poll_one(); 521 512 522 if ( fStatusDim.second==0)513 if (!fDim.online()) 523 514 return kStateDimNetworkNA; 524 515 525 516 // All subsystems are not connected 526 if (f StatusFTM.second<FTM::kConnected)517 if (fDimFTM.state()<FTM::kConnected) 527 518 return kStateDisconnected; 528 519 … … 543 534 544 535 // At least one subsystem is not connected 545 // if (f StatusFTM.second>=FTM::kConnected)546 return fTriggerOn && fEnabled && f StatusRS.second!=5 ? kStateInProgress : kStateConnected;536 // if (fDimFTM.state()>=FTM::kConnected) 537 return fTriggerOn && fEnabled && fDimRS.state()!=5 ? kStateInProgress : kStateConnected; 547 538 } 548 539 … … 550 541 StateMachineRateControl(ostream &out=cout) : StateMachineDim(out, "RATE_CONTROL"), 551 542 fTriggerOn(false), fBlock(40), 552 fStatusDim(make_pair(Time(), -2)), 553 fStatusFTM(make_pair(Time(), -2)), 554 fDim("DIS_DNS/VERSION_NUMBER", (void*)NULL, 0, this), 555 fFTM("FTM_CONTROL/STATE", (void*)NULL, 0, this), 556 fRates("FTM_CONTROL/TRIGGER_RATES", (void*)NULL, 0, this), 557 fStatic("FTM_CONTROL/STATIC_DATA", (void*)NULL, 0, this), 558 fRateScan("RATE_SCAN/STATE", (void*)NULL, 0, this)/*, 559 fDimData("RATE_SCAN/DATA", "I:1;F:1;F:1;F:1;F:40;F:160", ""), 560 fDimProc("RATE_SCAN/PROCESS_DATA", "I:1;I:1;I:1", 561 "Rate scan process data" 562 "|min[DAC]:Value at which scan was started" 563 "|max[DAC]:Value at which scan will end" 564 "|step[DAC]:Step size for scan")*/ 543 fDimFTM("FTM_CONTROL"), 544 fDimRS("RATE_SCAN") 565 545 { 566 546 // ba::io_service::work is a kind of keep_alive for the loop. … … 570 550 // previous state but this might introduce some overhead of 571 551 // deletion and creation of threads and more. 552 553 fDim.Subscribe(*this); 554 fDimFTM.Subscribe(*this); 555 fDimRS.Subscribe(*this); 556 557 Subscribe("FTM_CONTROL/TRIGGER_RATES") 558 (bind(&StateMachineRateControl::HandleTriggerRates, this, placeholders::_1)); 559 Subscribe("FTM_CONTROL/STATIC_DATA") 560 (bind(&StateMachineRateControl::HandleStaticData, this, placeholders::_1)); 572 561 573 562 // State names -
trunk/FACT++/src/ratescan.cc
r13761 r13838 18 18 #include "HeadersFTM.h" 19 19 20 namespace ba = boost::asio; 21 namespace bs = boost::system; 22 namespace dummy = ba::placeholders; 20 namespace ba = boost::asio; 21 namespace bs = boost::system; 23 22 24 23 using namespace std; … … 27 26 28 27 #include "DimDescriptionService.h" 28 #include "DimState.h" 29 29 30 30 // ------------------------------------------------------------------------ 31 31 32 class StateMachineRateScan : public StateMachineDim , public DimInfoHandler32 class StateMachineRateScan : public StateMachineDim 33 33 { 34 /*35 int Wrap(boost::function<void()> f)36 {37 f();38 return T::GetCurrentState();39 }40 41 boost::function<int(const EventImp &)> Wrapper(boost::function<void()> func)42 {43 return bind(&StateMachineMCP::Wrap, this, func);44 }*/45 46 34 private: 47 35 enum states_t … … 54 42 }; 55 43 56 // PixelMap fMap; 57 58 DimServiceInfoList fNetwork; 59 60 pair<Time, int> fStatusDim; 61 pair<Time, int> fStatusFTM; 62 63 DimStampedInfo fDim; 64 DimStampedInfo fFTM; 65 DimStampedInfo fRates; 44 DimServiceInfoListImp fNetwork; 45 46 DimVersion fDim; 47 DimState fDimFTM; 66 48 67 49 DimDescribedService fDimData; … … 105 87 } 106 88 107 pair<Time, int> GetNewState(DimStampedInfo &info) const 108 { 109 const bool disconnected = info.getSize()==0; 110 111 // Make sure getTimestamp is called _before_ getTimestampMillisecs 112 const int tsec = info.getTimestamp(); 113 const int tms = info.getTimestampMillisecs(); 114 115 return make_pair(Time(tsec, tms*1000), 116 disconnected ? -2 : info.getQuality()); 117 } 118 119 bool CheckEventSize(size_t has, const char *name, size_t size) 120 { 121 if (has==size) 89 bool CheckEventSize(const EventImp &evt, size_t size) 90 { 91 if (size_t(evt.GetSize())==size) 122 92 return true; 123 93 124 if ( has==0)94 if (evt.GetSize()==0) 125 95 return false; 126 96 127 97 ostringstream msg; 128 msg << name << " - Received event has " << has<< " bytes, but expected " << size << ".";98 msg << evt.GetName() << " - Received event has " << evt.GetSize() << " bytes, but expected " << size << "."; 129 99 Fatal(msg); 130 100 return false; 131 101 } 132 102 133 void infoHandler() 134 { 135 DimInfo *curr = getInfo(); // get current DimInfo address 136 if (!curr) 103 int HandleTriggerRates(const EventImp &evt) 104 { 105 if (!CheckEventSize(evt, sizeof(FTM::DimTriggerRates))) 106 return GetCurrentState(); 107 108 if (fThreshold<0/* || fDimFTM.state()!=FTM::kTakingData*/) 109 return GetCurrentState(); 110 111 const FTM::DimTriggerRates &sdata = *static_cast<const FTM::DimTriggerRates*>(evt.GetData()); 112 113 if (++fCounter<0) 114 return GetCurrentState(); 115 116 if (fCounter==0) 117 { 118 fRate = 0; 119 120 memset(fRateBoard, 0, 40*sizeof(double)); 121 memset(fRatePatch, 0, 160*sizeof(double)); 122 123 fOnTime = 0; 124 return GetCurrentState(); 125 } 126 /* 127 if (sdata.fTriggerRate==0) 128 { 129 Message("Rate scan stopped due zero trigger rate."); 130 fThreshold = -1; 137 131 return; 138 139 if (curr==&fFTM) 140 { 141 fStatusFTM = GetNewState(fFTM); 132 } 133 */ 134 135 fRate += sdata.fTriggerRate; 136 for (int i=0; i<40; i++) 137 fRateBoard[i] += sdata.fBoardRate[i]; 138 for (int i=0; i<160; i++) 139 fRatePatch[i] += sdata.fPatchRate[i]; 140 141 double reference = fRate; 142 if (fReference==kBoard) 143 reference = fRateBoard[fReferenceIdx]; 144 if (fReference==kPatch) 145 reference = fRatePatch[fReferenceIdx]; 146 147 fOnTime += sdata.fOnTime; 148 149 reference *= sdata.fElapsedTime; 150 151 if ((reference==0 || sqrt(reference)>fResolution*reference) && fCounter<fCounterMax) 152 { 153 ostringstream out; 154 out << "Triggers so far: " << reference; 155 if (reference>0) 156 out << " (" << sqrt(reference)/reference << ")"; 157 Info(out); 158 159 return GetCurrentState(); 160 } 161 162 const double time = sdata.fElapsedTime*fCounter; 163 const uint32_t th = fThreshold; 164 165 float data[2+3+1+40+160]; 166 memcpy(data, &fStartTime, 8); 167 memcpy(data+2, &th, 4); 168 data[3] = time; // total elapsed time 169 data[4] = fOnTime/time; // relative on time 170 data[5] = fRate/fCounter; 171 for (int i=0; i<40; i++) 172 data[i+6] = fRateBoard[i]/fCounter; 173 for (int i=0; i<160; i++) 174 data[i+46] = fRatePatch[i]/fCounter; 175 176 ostringstream sout1, sout2, sout3; 177 178 sout1 << th << " " << data[5]; 179 for (int i=0; i<200; i++) 180 sout2 << " " << data[i+6]; 181 sout3 << " " << data[3] << " " << data[4]; 182 183 Info(sout1.str()); 184 185 ofstream fout("ratescan.txt", ios::app); 186 fout << sout1.str() << sout2.str() << sout3.str() << endl; 187 188 fDimData.setQuality(fCommand=="FTM_CONTROL/SET_THRESHOLD"); 189 fDimData.setData(data, sizeof(data)); 190 fDimData.Update(); 191 192 fThreshold += fThresholdStep; 193 194 if (fCounter>=fCounterMax) 195 { 196 Message("Rate scan stopped due to timeout."); 197 fThreshold=-1; 198 return GetCurrentState(); 199 } 200 201 if (fThreshold>fThresholdMax) 202 { 203 Message("Rate scan finished."); 204 fThreshold = -1; 205 return GetCurrentState(); 206 } 207 208 // Does this need to be shifted upwards? 209 if (fCounter>1 && fThresholdStepDyn>0) 210 { 211 //const double scale = fCounter/reference/fResolution/fResolution; 212 //const double step = floor(scale*fThresholdStepDyn); 213 214 fThresholdStep = fCounter*fThresholdStepDyn; 215 } 216 217 //fCounter = -2; // FIXME: In principle one missed report is enough 218 fCounter = -1; 219 220 const int32_t cmd[2] = { -1, fThreshold }; 221 DimClient::sendCommandNB(fCommand.c_str(), (void*)cmd, 8); 222 223 return GetCurrentState(); 224 } 225 226 const State GetState(const DimState &s) const 227 { 228 return fNetwork.GetState(s.name(), s.state()); 229 } 230 231 void PrintState(const DimState &state) const 232 { 233 const State rc = GetState(state); 234 235 Out() << state.time().GetAsStr("%H:%M:%S.%f").substr(0, 12) << " - "; 236 Out() << kBold << state.name() << ": "; 237 if (rc.index==-3) 238 { 239 Out() << kReset << "Offline" << endl; 142 240 return; 143 241 } 144 145 if (curr==&fDim) 146 { 147 fStatusDim = GetNewState(fDim); 148 fStatusDim.second = curr->getSize()==4 ? curr->getInt() : 0; 149 return; 150 } 151 152 if (curr==&fRates) 153 { 154 if (!CheckEventSize(curr->getSize(), "infoHandler[DimTriggerRates]", sizeof(FTM::DimTriggerRates))) 155 return; 156 157 if (fThreshold<0/* || fStatusFTM.second!=FTM::kTakingData*/) 158 return; 159 160 const FTM::DimTriggerRates &sdata = *static_cast<FTM::DimTriggerRates*>(curr->getData()); 161 162 if (++fCounter<0) 163 return; 164 165 if (fCounter==0) 166 { 167 fRate = 0; 168 169 memset(fRateBoard, 0, 40*sizeof(double)); 170 memset(fRatePatch, 0, 160*sizeof(double)); 171 172 fOnTime = 0; 173 return; 174 } 175 /* 176 if (sdata.fTriggerRate==0) 177 { 178 Message("Rate scan stopped due zero trigger rate."); 179 fThreshold = -1; 180 return; 181 } 182 */ 183 184 fRate += sdata.fTriggerRate; 185 for (int i=0; i<40; i++) 186 fRateBoard[i] += sdata.fBoardRate[i]; 187 for (int i=0; i<160; i++) 188 fRatePatch[i] += sdata.fPatchRate[i]; 189 190 double reference = fRate; 191 if (fReference==kBoard) 192 reference = fRateBoard[fReferenceIdx]; 193 if (fReference==kPatch) 194 reference = fRatePatch[fReferenceIdx]; 195 196 fOnTime += sdata.fOnTime; 197 198 reference *= sdata.fElapsedTime; 199 200 if ((reference==0 || sqrt(reference)>fResolution*reference) && fCounter<fCounterMax) 201 { 202 ostringstream out; 203 out << "Triggers so far: " << reference; 204 if (reference>0) 205 out << " (" << sqrt(reference)/reference << ")"; 206 Info(out); 207 208 return; 209 } 210 211 const double time = sdata.fElapsedTime*fCounter; 212 const uint32_t th = fThreshold; 213 214 float data[2+3+1+40+160]; 215 memcpy(data, &fStartTime, 8); 216 memcpy(data+2, &th, 4); 217 data[3] = time; // total elapsed time 218 data[4] = fOnTime/time; // relative on time 219 data[5] = fRate/fCounter; 220 for (int i=0; i<40; i++) 221 data[i+6] = fRateBoard[i]/fCounter; 222 for (int i=0; i<160; i++) 223 data[i+46] = fRatePatch[i]/fCounter; 224 225 ostringstream sout1, sout2, sout3; 226 227 sout1 << th << " " << data[5]; 228 for (int i=0; i<200; i++) 229 sout2 << " " << data[i+6]; 230 sout3 << " " << data[3] << " " << data[4]; 231 232 Info(sout1.str()); 233 234 ofstream fout("ratescan.txt", ios::app); 235 fout << sout1.str() << sout2.str() << sout3.str() << endl; 236 237 fDimData.setQuality(fCommand=="FTM_CONTROL/SET_THRESHOLD"); 238 fDimData.setData(data, sizeof(data)); 239 fDimData.Update(); 240 241 fThreshold += fThresholdStep; 242 243 if (fCounter>=fCounterMax) 244 { 245 Message("Rate scan stopped due to timeout."); 246 fThreshold=-1; 247 return; 248 } 249 250 if (fThreshold>fThresholdMax) 251 { 252 Message("Rate scan finished."); 253 fThreshold = -1; 254 return; 255 } 256 257 // Does this need to be shifted upwards? 258 if (fCounter>1 && fThresholdStepDyn>0) 259 { 260 //const double scale = fCounter/reference/fResolution/fResolution; 261 //const double step = floor(scale*fThresholdStepDyn); 262 263 fThresholdStep = fCounter*fThresholdStepDyn; 264 } 265 266 //fCounter = -2; // FIXME: In principle one missed report is enough 267 fCounter = -1; 268 269 const int32_t cmd[2] = { -1, fThreshold }; 270 DimClient::sendCommandNB(fCommand.c_str(), (void*)cmd, 8); 271 } 272 } 273 274 void PrintState(const pair<Time,int> &state, const char *server) 275 { 276 const State rc = fNetwork.GetState(server, state.second); 277 278 Out() << state.first.GetAsStr("%H:%M:%S.%f").substr(0, 12) << " - "; 279 Out() << kBold << server << ": "; 280 Out() << rc.name << "[" << rc.index << "]"; 242 if (rc.index==-2) 243 Out() << state.state(); 244 else 245 Out() << rc.name << "[" << rc.index << "]"; 281 246 Out() << kReset << " - " << kBlue << rc.comment << endl; 282 247 } 283 248 284 int Print() 285 { 286 Out() << fStatusDim.first.GetAsStr("%H:%M:%S.%f").substr(0, 12) << " - "; 287 Out() << kBold << "DIM_DNS: "; 288 if (fStatusDim.second==0) 289 Out() << "Offline" << endl; 290 else 291 Out() << "V" << fStatusDim.second/100 << 'r' << fStatusDim.second%100 << endl; 292 293 PrintState(fStatusFTM, "FTM_CONTROL"); 249 int Print() const 250 { 251 Out() << fDim.time().GetAsStr("%H:%M:%S.%f").substr(0, 12) << " - "; 252 Out() << kBold << "DIM_DNS: " << fDim.version() << endl; 253 254 PrintState(fDimFTM); 294 255 295 256 return GetCurrentState(); … … 298 259 int StartRateScan(const EventImp &evt, const string &command) 299 260 { 300 if (!CheckEventSize(evt .GetSize(), "StartRateScan", 12))261 if (!CheckEventSize(evt, 12)) 301 262 return kSM_FatalError; 302 263 … … 355 316 Message("Rate scan manually stopped."); 356 317 357 //if (f StatusFTM.second==FTM::kTakingData)318 //if (fDimFTM.state()==FTM::kTakingData) 358 319 { 359 320 //Message("Stopping FTM"); … … 373 334 int SetReferenceBoard(const EventImp &evt) 374 335 { 375 if (!CheckEventSize(evt .GetSize(), "SetReferenceBoard", 4))336 if (!CheckEventSize(evt, 4)) 376 337 return kSM_FatalError; 377 338 … … 390 351 int SetReferencePatch(const EventImp &evt) 391 352 { 392 if (!CheckEventSize(evt .GetSize(), "SetReferencePatch", 4))353 if (!CheckEventSize(evt, 4)) 393 354 return kSM_FatalError; 394 355 … … 407 368 int ChangeStepSize(const EventImp &evt) 408 369 { 409 if (!CheckEventSize(evt .GetSize(), "ChangeStepSize", 4))370 if (!CheckEventSize(evt, 4)) 410 371 return kSM_FatalError; 411 372 … … 423 384 int ChangeMaximum(const EventImp &evt) 424 385 { 425 if (!CheckEventSize(evt .GetSize(), "ChangeMaximum", 4))386 if (!CheckEventSize(evt, 4)) 426 387 return kSM_FatalError; 427 388 … … 440 401 //poll_one(); 441 402 442 if ( fStatusDim.second==0)403 if (!fDim.online()) 443 404 return kStateDimNetworkNA; 444 405 445 406 // All subsystems are not connected 446 if (f StatusFTM.second<FTM::kConnected)407 if (fDimFTM.state()<FTM::kConnected) 447 408 return kStateDisconnected; 448 409 449 410 // At least one subsystem is not connected 450 // if (f StatusFTM.second>=FTM::kConnected)411 // if (fDimFTM.state()>=FTM::kConnected) 451 412 return fThreshold<0 ? kStateConnected : kStateInProgress; 452 413 } … … 454 415 public: 455 416 StateMachineRateScan(ostream &out=cout) : StateMachineDim(out, "RATE_SCAN"), 456 fStatusDim(make_pair(Time(), -2)), 457 fStatusFTM(make_pair(Time(), -2)), 458 fDim("DIS_DNS/VERSION_NUMBER", (void*)NULL, 0, this), 459 fFTM("FTM_CONTROL/STATE", (void*)NULL, 0, this), 460 fRates("FTM_CONTROL/TRIGGER_RATES", (void*)NULL, 0, this), 417 fDimFTM("FTM_CONTROL"), 461 418 fDimData("RATE_SCAN/DATA", "X:1;I:1;F:1;F:1;F:1;F:40;F:160", 462 419 "|Id[s]:Start time used to identify measurement (UnixTime)" … … 480 437 // previous state but this might introduce some overhead of 481 438 // deletion and creation of threads and more. 439 440 fDim.Subscribe(*this); 441 fDimFTM.Subscribe(*this); 442 443 Subscribe("FTM_CONTROL/TRIGGER_RATES") 444 (bind(&StateMachineRateScan::HandleTriggerRates, this, placeholders::_1)); 482 445 483 446 // State names -
trunk/FACT++/src/smartfact.cc
r13820 r13838 17 17 18 18 #include "tools.h" 19 #include "DimData.h"20 19 21 20 #include "LocalControl.h" … … 30 29 31 30 #include "DimDescriptionService.h" 31 #include "DimState.h" 32 32 33 33 // ------------------------------------------------------------------------ … … 305 305 // ======================================================================== 306 306 307 class DimState : public DimInfoHandler 308 { 309 protected: 310 typedef function<void(const DimData &)> callback; 311 312 public: 313 DimState(const string &n, const string s="STATE") : server(n), 314 info(make_pair(Time(), -4)), 315 dim((n+"/"+s).c_str(), (void*)NULL, 0, this) { } 316 317 string server; 318 pair<Time, int> info; 319 string msg; 320 321 DimStampedInfo dim; 322 323 callback fCallback; 324 325 void SetCallback(const callback &cb) 326 { 327 fCallback = cb; 328 } 329 330 void infoHandler() 331 { 332 DimInfo *curr = getInfo(); // get current DimInfo address 333 if (!curr || curr != &dim) 334 return; 335 336 const bool disconnected = dim.getSize()==0; 337 338 // Make sure getTimestamp is called _before_ getTimestampMillisecs 339 const int tsec = dim.getTimestamp(); 340 const int tms = dim.getTimestampMillisecs(); 341 342 info = make_pair(Time(tsec, tms*1000), 343 disconnected ? -4 : dim.getQuality()); 344 345 msg = disconnected ? "" : dim.getString(); 346 347 if (fCallback) 348 fCallback(DimData(curr)); 349 } 350 351 const Time &time() const { return info.first; } 352 const int &state() const { return info.second; } 353 354 bool online() const { return info.second>-4; } 355 356 const string &name() const { return server; } 357 }; 358 359 class DimVersion : public DimState 360 { 361 public: 362 DimVersion() : DimState("DIS_DNS", "VERSION_NUMBER") { } 363 364 void infoHandler() 365 { 366 DimInfo *curr = getInfo(); // get current DimInfo address 367 if (!curr || curr != &dim) 368 return; 369 370 DimState::infoHandler(); 371 372 info.second = dim.getSize()==4 ? dim.getInt() : 0; 373 } 374 375 string version() const 376 { 377 if (info.second==0) 378 return "Offline"; 379 380 ostringstream out; 381 out << "V" << info.second/100 << 'r' << info.second%100; 382 return out.str(); 383 } 384 }; 385 386 class DimControl : public DimState 387 { 388 map<string, callback> fCallbacks; 389 public: 390 DimControl() : DimState("DIM_CONTROL") { } 391 392 void AddCallback(const string &script, const callback &cb) 393 { 394 fCallbacks[script] = cb; 395 } 396 397 void infoHandler() 398 { 399 DimInfo *curr = getInfo(); // get current DimInfo address 400 if (!curr || curr != &dim) 401 return; 402 403 DimState::infoHandler(); 404 405 // Evaluate msg 406 const size_t p0 = msg.find_first_of(':'); 407 if (p0==string::npos) 408 return; 409 410 const size_t p1 = msg.find_last_of('['); 411 if (p1==string::npos) 412 return; 413 414 const size_t p2 = msg.find_first_of(':', p0+1); 415 416 const size_t p3 = p2==string::npos || p2>p1 ? p1-1 : p2; 417 418 const string file = msg.substr(p0+2, p3-p0-2); 419 420 const auto func = fCallbacks.find(file); 421 if (func==fCallbacks.end()) 422 return; 423 424 // Call callback 425 func->second(DimData(curr)); 426 } 427 }; 428 429 struct DimSubscriptions 430 { 431 DimServiceInfoList fNetwork; 432 433 DimVersion fDNS; 434 DimControl fControl; 435 DimState fMcp; 436 DimState fDataLogger; 437 DimState fDriveControl; 438 DimState fMagicWeather; 439 DimState fFeedback; 440 DimState fBiasControl; 441 DimState fFtmControl; 442 DimState fFadControl; 443 DimState fFscControl; 444 DimState fRateControl; 445 DimState fRateScan; 446 DimState fChatServer; 447 448 DimStampedInfo fControlMessage; 449 450 DimStampedInfo fMcpConfiguration; 451 452 DimStampedInfo fDriveControlPointing; 453 DimStampedInfo fDriveControlTracking; 454 DimStampedInfo fDriveControlSource; 455 456 DimStampedInfo fFscControlTemperature; 457 DimStampedInfo fFscControlHumidity; 458 459 DimStampedInfo fMagicWeatherData; 460 461 DimStampedInfo fFeedbackDeviation; 462 DimStampedInfo fFeedbackCalibration; 463 464 DimStampedInfo fBiasControlVoltage; 465 DimStampedInfo fBiasControlCurrent; 466 467 DimStampedInfo fFadConnections; 468 DimStampedInfo fFadEvents; 469 470 DimStampedInfo fFtmControlTriggerRates; 471 DimStampedInfo fFtmControlStaticData; 472 DimStampedInfo fFtmControlFtuList; 473 474 DimStampedInfo fRateScanData; 475 476 DimStampedInfo fFadControlEventData; 477 478 DimSubscriptions(DimInfoHandler *h) : 479 fMcp ("MCP"), 480 fDataLogger ("DATA_LOGGER"), 481 fDriveControl ("DRIVE_CONTROL"), 482 fMagicWeather ("MAGIC_WEATHER"), 483 fFeedback ("FEEDBACK"), 484 fBiasControl ("BIAS_CONTROL"), 485 fFtmControl ("FTM_CONTROL"), 486 fFadControl ("FAD_CONTROL"), 487 fFscControl ("FSC_CONTROL"), 488 fRateControl ("RATE_CONTROL"), 489 fRateScan ("RATE_SCAN"), 490 fChatServer ("CHAT_SERVER"), 491 //--- 492 fControlMessage ("DIM_CONTROL/MESSAGE", (void*)NULL, 0, h), 493 //--- 494 fMcpConfiguration ("MCP/CONFIGURATION", (void*)NULL, 0, h), 495 //--- 496 fDriveControlPointing ("DRIVE_CONTROL/POINTING_POSITION", (void*)NULL, 0, h), 497 fDriveControlTracking ("DRIVE_CONTROL/TRACKING_POSITION", (void*)NULL, 0, h), 498 fDriveControlSource ("DRIVE_CONTROL/SOURCE_POSITION", (void*)NULL, 0, h), 499 //--- 500 fFscControlTemperature ("FSC_CONTROL/TEMPERATURE", (void*)NULL, 0, h), 501 fFscControlHumidity ("FSC_CONTROL/HUMIDITY", (void*)NULL, 0, h), 502 //--- 503 fMagicWeatherData ("MAGIC_WEATHER/DATA", (void*)NULL, 0, h), 504 //--- 505 fFeedbackDeviation ("FEEDBACK/DEVIATION", (void*)NULL, 0, h), 506 fFeedbackCalibration ("FEEDBACK/CALIBRATION", (void*)NULL, 0, h), 507 //--- 508 fBiasControlVoltage ("BIAS_CONTROL/VOLTAGE", (void*)NULL, 0, h), 509 fBiasControlCurrent ("BIAS_CONTROL/CURRENT", (void*)NULL, 0, h), 510 //--- 511 fFadConnections ("FAD_CONTROL/CONNECTIONS", (void*)NULL, 0, h), 512 fFadEvents ("FAD_CONTROL/EVENTS", (void*)NULL, 0, h), 513 //--- 514 fFtmControlTriggerRates("FTM_CONTROL/TRIGGER_RATES", (void*)NULL, 0, h), 515 fFtmControlStaticData ("FTM_CONTROL/STATIC_DATA", (void*)NULL, 0, h), 516 fFtmControlFtuList ("FTM_CONTROL/FTU_LIST", (void*)NULL, 0, h), 517 //--- 518 fRateScanData ("RATE_SCAN/DATA", (void*)NULL, 0, h), 519 //--- 520 fFadControlEventData ("FAD_CONTROL/EVENT_DATA", (void*)NULL, 0, h) 521 522 { 523 } 524 525 const State GetState(const DimState &s) const 526 { 527 return fNetwork.GetState(s.name(), s.state()); 528 } 529 }; 530 531 // ======================================================================== 532 // ======================================================================== 533 // ======================================================================== 534 535 536 class StateMachineSmartFACT : public StateMachineDim, public DimInfoHandler 307 class StateMachineSmartFACT : public StateMachineDim//, public DimInfoHandler 537 308 { 538 309 private: … … 601 372 // ------------- Initialize variables before the Dim stuff ------------ 602 373 603 DimSubscriptions *fDim; 374 DimServiceInfoListImp fNetwork; 375 376 DimVersion fDimDNS; 377 DimControl fDimControl; 378 DimState fDimMcp; 379 DimState fDimDataLogger; 380 DimState fDimDriveControl; 381 DimState fDimMagicWeather; 382 DimState fDimFeedback; 383 DimState fDimBiasControl; 384 DimState fDimFtmControl; 385 DimState fDimFadControl; 386 DimState fDimFscControl; 387 DimState fDimRateControl; 388 DimState fDimRateScan; 389 DimState fDimChatServer; 604 390 605 391 // ------------------------------------------------------------------- 606 607 608 // ------------------------------------------------------------------- 609 392 /* 610 393 bool HandleService(DimInfo *curr, const DimInfo &service, void (StateMachineSmartFACT::*handle)(const DimData &)) 611 394 { … … 616 399 return true; 617 400 } 618 619 620 bool CheckDataSize(const DimData&d, const char *name, size_t size, bool min=false)621 { 622 if ((!min && d. data.size()==size) || (min && d.data.size()>size))401 */ 402 403 bool CheckDataSize(const EventImp &d, const char *name, size_t size, bool min=false) 404 { 405 if ((!min && d.GetSize()==size) || (min && d.GetSize()>size)) 623 406 return true; 624 407 625 408 ostringstream msg; 626 msg << name << " - Received service has " << d. data.size() << " bytes, but expected ";409 msg << name << " - Received service has " << d.GetSize() << " bytes, but expected "; 627 410 if (min) 628 411 msg << "more than "; … … 636 419 637 420 template<class T> 638 void WriteBinary(const DimData&d, const string &fname, const T &t, double scale, double offset=0)421 void WriteBinary(const EventImp &d, const string &fname, const T &t, double scale, double offset=0) 639 422 { 640 423 vector<uint8_t> val(t.size(), 0); … … 652 435 653 436 ostringstream out; 654 out << d. time.JavaDate() << '\n';437 out << d.GetJavaDate() << '\n'; 655 438 out << offset << '\n'; 656 439 out << offset+scale << '\n'; … … 695 478 }; 696 479 697 void HandleControlMessageImp(const DimData&d)698 { 699 if (d. size()==0)480 void HandleControlMessageImp(const EventImp &d) 481 { 482 if (d.GetSize()==0) 700 483 return; 701 484 702 485 const string str = fControlMessageHist.size()>0 ? fControlMessageHist.back() : "<pre> : : </pre> "; 703 const string time = "<pre>"+d. time.GetAsStr("%H:%M:%S")+"</pre> ";486 const string time = "<pre>"+d.GetTimeAsStr("%H:%M:%S")+"</pre> "; 704 487 705 488 ostringstream tst; 706 tst << d. qos;489 tst << d.GetQoS(); 707 490 708 491 string msg; 709 492 msg += str.substr(0, time.length())==time ? "<pre> </pre> " : time; 710 msg += d. ptr<char>();493 msg += d.Ptr<char>(); 711 494 712 495 fControlMessageHist.push_back(msg); … … 714 497 ostringstream out; 715 498 out << setprecision(3); 716 out << d. time.JavaDate() << '\n';499 out << d.GetJavaDate() << '\n'; 717 500 out << "#ffffff\t"; 718 501 … … 725 508 } 726 509 727 void HandleControlMessage(const DimData&d)728 { 729 if (d. qos==90)510 int HandleDimControlMessage(const EventImp &d) 511 { 512 if (d.GetQoS()==90) 730 513 HandleControlMessageImp(d); 731 } 732 733 void HandleControlStateChange(const DimData &d) 734 { 735 if (d.qos==-2) 514 515 return GetCurrentState(); 516 } 517 518 void HandleControlStateChange(const EventImp &d) 519 { 520 if (d.GetQoS()==-2) 736 521 fControlMessageHist.clear(); 737 522 738 if (d. qos<0)523 if (d.GetQoS()<0) 739 524 HandleControlMessageImp(d); 740 525 } 741 526 742 void HandleMcpConfiguration(const DimData&d)527 int HandleMcpConfiguration(const EventImp &d) 743 528 { 744 529 if (!CheckDataSize(d, "Mcp:Configuration", 16, true)) 745 return ;746 747 fMcpConfigurationState = d. qos;748 fMcpConfigurationMaxTime = d. get<uint64_t>();749 fMcpConfigurationMaxEvents = d. get<uint64_t>(8);750 fMcpConfigurationName = d. ptr<char>(16);751 752 if (d. qos==12)530 return GetCurrentState(); 531 532 fMcpConfigurationState = d.GetQoS(); 533 fMcpConfigurationMaxTime = d.Get<uint64_t>(); 534 fMcpConfigurationMaxEvents = d.Get<uint64_t>(8); 535 fMcpConfigurationName = d.Ptr<char>(16); 536 537 if (d.GetQoS()==12) 753 538 fMcpConfigurationRunStart = Time(); 754 } 755 756 void WriteWeather(const DimData &d, const string &name, int i, float min, float max) 539 540 return GetCurrentState(); 541 } 542 543 void WriteWeather(const EventImp &d, const string &name, int i, float min, float max) 757 544 { 758 545 const Statistics stat(fMagicWeatherHist[i]); … … 760 547 ostringstream out; 761 548 out << setprecision(3); 762 out << d. time.JavaDate() << '\n';549 out << d.GetJavaDate() << '\n'; 763 550 764 551 out << "#ffffff\t" << fMagicWeatherHist[i].back() << '\n'; … … 772 559 } 773 560 774 void HandleMagicWeatherData(const DimData&d)561 int HandleMagicWeatherData(const EventImp &d) 775 562 { 776 563 if (!CheckDataSize(d, "MagicWeather:Data", 7*4+2)) 777 return ;564 return GetCurrentState(); 778 565 779 566 // Store a history of the last 300 entries 780 567 for (int i=kWeatherBegin; i<kWeatherEnd; i++) 781 568 { 782 fMagicWeatherHist[i].push_back(d. ptr<float>(2)[i]);569 fMagicWeatherHist[i].push_back(d.Ptr<float>(2)[i]); 783 570 if (fMagicWeatherHist[i].size()>300) 784 571 fMagicWeatherHist[i].pop_front(); … … 801 588 802 589 ostringstream out; 803 out << d. time.JavaDate() << '\n';590 out << d.GetJavaDate() << '\n'; 804 591 out << astro.color << '\t' << astro.description << '\n'; 805 592 out << setprecision(2); … … 836 623 WriteWeather(d, "gusts", kGusts, 0, 100); 837 624 WriteWeather(d, "press", kPress, 700, 1000); 838 } 839 840 void HandleDriveControlPointing(const DimData &d) 625 626 return GetCurrentState(); 627 } 628 629 int HandleDrivePointing(const EventImp &d) 841 630 { 842 631 if (!CheckDataSize(d, "DriveControl:Pointing", 16)) 843 return ;844 845 fDriveControlPointingZd = d. get<double>();846 847 const double az = d. get<double>(8);632 return GetCurrentState(); 633 634 fDriveControlPointingZd = d.Get<double>(); 635 636 const double az = d.Get<double>(8); 848 637 849 638 static const char *dir[] = … … 859 648 860 649 ostringstream out; 861 out << d. time.JavaDate() << '\n';650 out << d.GetJavaDate() << '\n'; 862 651 863 652 out << setprecision(5); … … 866 655 867 656 ofstream(fPath+"/drive-pointing.txt") << out.str(); 868 } 869 870 void HandleDriveControlTracking(const DimData &d) 657 658 return GetCurrentState(); 659 } 660 661 int HandleDriveTracking(const EventImp &d) 871 662 { 872 663 if (!CheckDataSize(d, "DriveControl:Tracking", 56)) 873 return ;874 875 const double Ra = d. get<double>(0*8);876 const double Dec = d. get<double>(1*8);877 const double Zd = d. get<double>(3*8);878 const double Az = d. get<double>(4*8);664 return GetCurrentState(); 665 666 const double Ra = d.Get<double>(0*8); 667 const double Dec = d.Get<double>(1*8); 668 const double Zd = d.Get<double>(3*8); 669 const double Az = d.Get<double>(4*8); 879 670 880 671 const double zd = Zd * M_PI / 180; 881 const double dzd = d. get<double>(5*8) * M_PI / 180;882 const double daz = d. get<double>(6*8) * M_PI / 180;672 const double dzd = d.Get<double>(5*8) * M_PI / 180; 673 const double daz = d.Get<double>(6*8) * M_PI / 180; 883 674 884 675 // Correct: … … 896 687 897 688 ostringstream out; 898 out << d. time.JavaDate() << '\n';689 out << d.GetJavaDate() << '\n'; 899 690 900 691 out << kHtmlWhite << '\t' << fDriveControlSourceName << '\n'; … … 923 714 924 715 ofstream(fPath+"/tracking.txt") << out.str(); 925 } 926 927 void HandleDriveControlSource(const DimData &d) 716 717 return GetCurrentState(); 718 } 719 720 int HandleDriveSource(const EventImp &d) 928 721 { 929 722 if (!CheckDataSize(d, "DriveControl:Source", 7*4+2, true)) 930 return ;931 932 const double *ptr = d. ptr<double>();723 return GetCurrentState(); 724 725 const double *ptr = d.Ptr<double>(); 933 726 934 727 const double ra = ptr[0]; // Ra[h] … … 937 730 const double wang = ptr[5]; // Wobble angle [deg] 938 731 939 fDriveControlSourceName = d. ptr<char>(6*8);732 fDriveControlSourceName = d.Ptr<char>(6*8); 940 733 941 734 ostringstream out; 942 out << d. time.JavaDate() << '\n';735 out << d.GetJavaDate() << '\n'; 943 736 944 737 out << "#ffffff\t" << fDriveControlSourceName << '\n'; … … 951 744 952 745 ofstream(fPath+"/source.txt") << out.str(); 953 } 954 955 void HandleFeedbackCalibration(const DimData &d) 746 747 return GetCurrentState(); 748 } 749 750 int HandleFeedbackCalibration(const EventImp &d) 956 751 { 957 752 if (!CheckDataSize(d, "Feedback:Calibration", 3*4*416)) 958 753 { 959 754 fFeedbackCalibration.clear(); 960 return ;961 } 962 963 const float *ptr = d. ptr<float>();755 return GetCurrentState(); 756 } 757 758 const float *ptr = d.Ptr<float>(); 964 759 fFeedbackCalibration.assign(ptr+2*416, ptr+3*416); 965 } 966 967 void HandleFeedbackDeviation(const DimData &d) 760 761 return GetCurrentState(); 762 } 763 764 int HandleFeedbackDeviation(const EventImp &d) 968 765 { 969 766 if (!CheckDataSize(d, "Feedback:Deviation", 2*4*416+8)) 970 return ;971 972 const float *ptr = d. ptr<float>();767 return GetCurrentState(); 768 769 const float *ptr = d.Ptr<float>(); 973 770 vector<float> dev(ptr+416, ptr+416+320); 974 771 … … 985 782 986 783 ostringstream out; 987 out << d. time.JavaDate() << '\n';784 out << d.GetJavaDate() << '\n'; 988 785 out << kHtmlWhite << '\t' << fFeedbackUserOffset << '\n'; 989 786 out << setprecision(3); … … 994 791 out << kHtmlWhite << '\t' << stat.max << '\n'; 995 792 ofstream(fPath+"/feedback.txt") << out.str(); 996 } 997 998 void HandleBiasControlVoltage(const DimData &d) 793 794 return GetCurrentState(); 795 } 796 797 int HandleBiasVoltage(const EventImp &d) 999 798 { 1000 799 if (!CheckDataSize(d, "BiasControl:Voltage", 1664)) 1001 800 { 1002 801 fBiasControlVoltageVec.clear(); 1003 return ;1004 } 1005 1006 fBiasControlVoltageVec.assign(d. ptr<float>(), d.ptr<float>()+320);802 return GetCurrentState(); 803 } 804 805 fBiasControlVoltageVec.assign(d.Ptr<float>(), d.Ptr<float>()+320); 1007 806 1008 807 const Statistics stat(fBiasControlVoltageVec); … … 1017 816 } 1018 817 1019 if (fDim ->fBiasControl.state()==BIAS::kVoltageOn)818 if (fDimBiasControl.state()==BIAS::kVoltageOn) 1020 819 WriteBinary(d, "biascontrol-voltage", val, 10, 65); 1021 820 else … … 1024 823 ostringstream out; 1025 824 out << setprecision(3); 1026 out << d. time.JavaDate() << '\n';825 out << d.GetJavaDate() << '\n'; 1027 826 out << kHtmlWhite << '\t' << stat.min << '\n'; 1028 827 out << kHtmlWhite << '\t' << stat.med << '\n'; … … 1031 830 ofstream(fPath+"/voltage.txt") << out.str(); 1032 831 1033 } 1034 1035 void HandleBiasControlCurrent(const DimData &d) 832 return GetCurrentState(); 833 } 834 835 int HandleBiasCurrent(const EventImp &d) 1036 836 { 1037 837 if (!CheckDataSize(d, "BiasControl:Current", 832)) 1038 return ;838 return GetCurrentState(); 1039 839 1040 840 // Convert dac counts to uA 1041 841 vector<float> v(320); 1042 842 for (int i=0; i<320; i++) 1043 v[i] = d. ptr<uint16_t>()[i] * 5000./4096;843 v[i] = d.Ptr<uint16_t>()[i] * 5000./4096; 1044 844 1045 845 const bool cal = fFeedbackCalibration.size()>0 && fBiasControlVoltageVec.size()>0; … … 1136 936 ostringstream out; 1137 937 out << setprecision(2); 1138 out << d. time.JavaDate() << '\n';938 out << d.GetJavaDate() << '\n'; 1139 939 out << col0 << '\t' << (cal?"yes":"no") << '\n'; 1140 940 out << col1 << '\t' << stat.min << '\n'; … … 1144 944 out << kHtmlWhite << '\t' << power_tot << "W [" << power_apd << "mW]\n"; 1145 945 ofstream(fPath+"/current.txt") << out.str(); 1146 } 1147 1148 void HandleFadEvents(const DimData &d) 946 947 return GetCurrentState(); 948 } 949 950 int HandleFadEvents(const EventImp &d) 1149 951 { 1150 952 if (!CheckDataSize(d, "FadControl:Events", 4*4)) 1151 953 { 1152 954 fFadControlNumEvents = -1; 1153 return; 1154 } 1155 1156 fFadControlNumEvents = d.get<uint32_t>(); 1157 } 1158 1159 void HandleFadConnections(const DimData &d) 955 return GetCurrentState(); 956 } 957 958 fFadControlNumEvents = d.Get<uint32_t>(); 959 960 return GetCurrentState(); 961 } 962 963 int HandleFadConnections(const EventImp &d) 1160 964 { 1161 965 if (!CheckDataSize(d, "FadControl:Connections", 41)) 1162 966 { 1163 967 //fStatusEventBuilderLabel->setText("Offline"); 1164 return ;968 return GetCurrentState(); 1165 969 } 1166 970 1167 971 string rc(40, '-'); // orange/red [45] 1168 972 1169 const uint8_t *ptr = d. ptr<uint8_t>();973 const uint8_t *ptr = d.Ptr<uint8_t>(); 1170 974 1171 975 int c[4] = { '.', '.', '.', '.' }; … … 1198 1002 ostringstream out; 1199 1003 out << setprecision(3); 1200 out << d. time.JavaDate() << '\n';1004 out << d.GetJavaDate() << '\n'; 1201 1005 out << col[0] << '\t' << rc.substr( 0, 10) << '\n'; 1202 1006 out << col[1] << '\t' << rc.substr(10, 10) << '\n'; … … 1204 1008 out << col[3] << '\t' << rc.substr(30, 10) << '\n'; 1205 1009 ofstream(fPath+"/fad.txt") << out.str(); 1206 } 1207 1208 void HandleFtmControlTriggerRates(const DimData &d) 1010 1011 return GetCurrentState(); 1012 } 1013 1014 int HandleFtmTriggerRates(const EventImp &d) 1209 1015 { 1210 1016 if (!CheckDataSize(d, "FtmControl:TriggerRates", 24+160+640+8)) 1211 return ;1017 return GetCurrentState(); 1212 1018 1213 1019 // New run started 1214 if (d. get<float>(20)<0)1215 return ;1216 1217 fFtmControlTriggerRateCam = d. get<float>(20);1218 1219 const float *brates = d. ptr<float>(24); // Board rate1220 const float *prates = d. ptr<float>(24+160); // Patch rate1020 if (d.Get<float>(20)<0) 1021 return GetCurrentState(); 1022 1023 fFtmControlTriggerRateCam = d.Get<float>(20); 1024 1025 const float *brates = d.Ptr<float>(24); // Board rate 1026 const float *prates = d.Ptr<float>(24+160); // Patch rate 1221 1027 1222 1028 // Store a history of the last 60 entries … … 1236 1042 ostringstream out; 1237 1043 out << setprecision(3); 1238 out << d. time.JavaDate() << '\n';1044 out << d.GetJavaDate() << '\n'; 1239 1045 out << "#ffffff\t" << fFtmControlTriggerRateCam << '\n'; 1240 1046 … … 1245 1051 1246 1052 out.str(""); 1247 out << d. time.JavaDate() << '\n';1053 out << d.GetJavaDate() << '\n'; 1248 1054 out << kHtmlWhite << '\t' << bstat.min << '\n'; 1249 1055 out << kHtmlWhite << '\t' << bstat.med << '\n'; … … 1253 1059 1254 1060 out.str(""); 1255 out << d. time.JavaDate() << '\n';1061 out << d.GetJavaDate() << '\n'; 1256 1062 out << kHtmlWhite << '\t' << pstat.min << '\n'; 1257 1063 out << kHtmlWhite << '\t' << pstat.med << '\n'; … … 1259 1065 out << kHtmlWhite << '\t' << pstat.max << '\n'; 1260 1066 ofstream(fPath+"/patchrates.txt") << out.str(); 1261 } 1262 1263 void HandleFtmControlStaticData(const DimData &d) 1067 1068 return GetCurrentState(); 1069 } 1070 1071 int HandleFtmStaticData(const EventImp &d) 1264 1072 { 1265 1073 if (!CheckDataSize(d, "FtmControl:StaticData", 740)) 1266 return ;1267 1268 const uint16_t *ptr = d. ptr<uint16_t>(260);1074 return GetCurrentState(); 1075 1076 const uint16_t *ptr = d.Ptr<uint16_t>(260); 1269 1077 vector<uint16_t> vec(ptr, ptr+160); 1270 1078 … … 1274 1082 1275 1083 ostringstream out; 1276 out << d. time.JavaDate() << '\n';1084 out << d.GetJavaDate() << '\n'; 1277 1085 out << kHtmlWhite << '\t' << stat.min << '\n'; 1278 1086 out << kHtmlWhite << '\t' << stat.med << '\n'; … … 1280 1088 out << kHtmlWhite << '\t' << stat.max << '\n'; 1281 1089 ofstream(fPath+"/thresholds.txt") << out.str(); 1282 } 1283 1284 void HandleFtmControlFtuList(const DimData &d) 1090 1091 return GetCurrentState(); 1092 } 1093 1094 int HandleFtmFtuList(const EventImp &d) 1285 1095 { 1286 1096 if (!CheckDataSize(d, "FtmControl:FtuList", sizeof(FTM::DimFtuList))) 1287 return ;1288 1289 const FTM::DimFtuList &sdata = d. ref<FTM::DimFtuList>();1097 return GetCurrentState(); 1098 1099 const FTM::DimFtuList &sdata = d.Ref<FTM::DimFtuList>(); 1290 1100 1291 1101 ostringstream out; 1292 out << d. time.JavaDate() << '\n';1102 out << d.GetJavaDate() << '\n'; 1293 1103 1294 1104 int cnt = 0; … … 1315 1125 1316 1126 ofstream(fPath+"/ftu.txt") << out.str(); 1317 } 1318 1319 void HandleFadControlEventData(const DimData &d) 1127 1128 return GetCurrentState(); 1129 } 1130 1131 int HandleFadEventData(const EventImp &d) 1320 1132 { 1321 1133 if (!CheckDataSize(d, "FadControl:EventData", 23040)) 1322 return ;1323 1324 //const float *avg = d. ptr<float>();1325 //const float *rms = d. ptr<float>(1440*sizeof(float));1326 const float *dat = d. ptr<float>(1440*sizeof(float)*2);1327 //const float *pos = d. ptr<float>(1440*sizeof(float)*3);1134 return GetCurrentState(); 1135 1136 //const float *avg = d.Ptr<float>(); 1137 //const float *rms = d.Ptr<float>(1440*sizeof(float)); 1138 const float *dat = d.Ptr<float>(1440*sizeof(float)*2); 1139 //const float *pos = d.Ptr<float>(1440*sizeof(float)*3); 1328 1140 1329 1141 vector<float> max(320, -2); … … 1339 1151 } 1340 1152 1341 switch (d. qos)1153 switch (d.GetQoS()) 1342 1154 { 1343 1155 case 0: WriteBinary(d, "fadcontrol-eventdata", max, 2, -1); break; … … 1345 1157 default: WriteBinary(d, "fadcontrol-eventdata", max, 0.25, 0); break; 1346 1158 } 1347 } 1348 1349 void HandleFscControlTemperature(const DimData &d) 1159 1160 return GetCurrentState(); 1161 } 1162 1163 int HandleFscTemperature(const EventImp &d) 1350 1164 { 1351 1165 if (!CheckDataSize(d, "FscControl:Temperature", 240)) 1352 return ;1353 1354 const float *ptr = d. ptr<float>(4);1166 return GetCurrentState(); 1167 1168 const float *ptr = d.Ptr<float>(4); 1355 1169 1356 1170 double avg = 0; … … 1391 1205 ostringstream out; 1392 1206 out << setprecision(3); 1393 out << d. time.JavaDate() << '\n';1207 out << d.GetJavaDate() << '\n'; 1394 1208 out << "#ffffff\t" << fFscControlHumidityAvg << '\n'; 1395 1209 out << "#ffffff\t" << min << '\n'; … … 1404 1218 WriteBinary(d, "fsccontrol-temperature-hist", 1405 1219 fFscControlTemperatureHist, 10); 1406 } 1407 1408 void HandleFscControlHumidity(const DimData &d) 1220 1221 return GetCurrentState(); 1222 } 1223 1224 int HandleFscHumidity(const EventImp &d) 1409 1225 { 1410 1226 if (!CheckDataSize(d, "FscControl:Humidity", 5*4)) 1411 return ;1412 1413 const float *ptr = d. ptr<float>(4);1227 return GetCurrentState(); 1228 1229 const float *ptr = d.Ptr<float>(4); 1414 1230 1415 1231 double avg = 0; … … 1424 1240 1425 1241 fFscControlHumidityAvg = avg/num; 1426 } 1427 1428 void HandleRateScanData(const DimData &d) 1242 1243 return GetCurrentState(); 1244 } 1245 1246 int HandleRateScanData(const EventImp &d) 1429 1247 { 1430 1248 if (!CheckDataSize(d, "RateScan:Data", 824)) 1431 return ;1432 1433 const uint64_t id = d. get<uint64_t>();1434 const float *rate = d. ptr<float>(20);1249 return GetCurrentState(); 1250 1251 const uint64_t id = d.Get<uint64_t>(); 1252 const float *rate = d.Ptr<float>(20); 1435 1253 1436 1254 if (fRateScanDataId!=id) … … 1458 1276 ostringstream out; 1459 1277 out << setprecision(3); 1460 out << d. time.JavaDate() << '\n';1278 out << d.GetJavaDate() << '\n'; 1461 1279 out << "#ffffff\t" << pow(10, fRateScanDataHist[0].back()) << '\n'; 1462 1280 out << "#ffffff\t" << max << '\n'; … … 1465 1283 1466 1284 out.str(""); 1467 out << d. time.JavaDate() << '\n';1285 out << d.GetJavaDate() << '\n'; 1468 1286 out << "#ffffff\t" << int(fRateScanBoard) << '\n'; 1469 1287 out << "#ffffff\t" << pow(10, fRateScanDataHist[fRateScanBoard+1].back()) << '\n'; 1470 1288 1471 1289 ofstream(fPath+"/ratecan_board.txt") << out.str(); 1290 1291 return GetCurrentState(); 1472 1292 } 1473 1293 1474 1294 // ------------------------------------------------------------------- 1475 1295 1476 void HandleDoTest(const DimData&d)1296 void HandleDoTest(const EventImp &d) 1477 1297 { 1478 1298 ostringstream out; 1479 out << d. time.JavaDate() << '\t' << fDim->fControl.online() << '\n';1480 switch (d. qos)1299 out << d.GetJavaDate() << '\t' << fDimControl.online() << '\n'; 1300 switch (d.GetQoS()) 1481 1301 { 1482 1302 case -3: out << kHtmlWhite << "\tNot running\n"; break; 1483 1303 case -2: out << kHtmlBlue << "\tLoading\n"; break; 1484 1304 case -1: out << kHtmlBlue << "\tStarted\n"; break; 1485 default: out << kHtmlGreen << "\tRunning [" << d. qos<< "]\n"; break;1305 default: out << kHtmlGreen << "\tRunning [" << d.GetQoS() << "]\n"; break; 1486 1306 } 1487 1307 … … 1490 1310 1491 1311 // ------------------------------------------------------------------- 1492 1493 void infoHandler()1494 {1495 DimInfo *curr = getInfo(); // get current DimInfo address1496 if (!curr)1497 return;1498 1499 if (HandleService(curr, fDim->fMcpConfiguration, &StateMachineSmartFACT::HandleMcpConfiguration))1500 return;1501 if (HandleService(curr, fDim->fMagicWeatherData, &StateMachineSmartFACT::HandleMagicWeatherData))1502 return;1503 if (HandleService(curr, fDim->fDriveControlPointing, &StateMachineSmartFACT::HandleDriveControlPointing))1504 return;1505 if (HandleService(curr, fDim->fDriveControlTracking, &StateMachineSmartFACT::HandleDriveControlTracking))1506 return;1507 if (HandleService(curr, fDim->fDriveControlSource, &StateMachineSmartFACT::HandleDriveControlSource))1508 return;1509 if (HandleService(curr, fDim->fFeedbackDeviation, &StateMachineSmartFACT::HandleFeedbackDeviation))1510 return;1511 if (HandleService(curr, fDim->fFeedbackCalibration, &StateMachineSmartFACT::HandleFeedbackCalibration))1512 return;1513 if (HandleService(curr, fDim->fBiasControlVoltage, &StateMachineSmartFACT::HandleBiasControlVoltage))1514 return;1515 if (HandleService(curr, fDim->fBiasControlCurrent, &StateMachineSmartFACT::HandleBiasControlCurrent))1516 return;1517 if (HandleService(curr, fDim->fFadConnections, &StateMachineSmartFACT::HandleFadConnections))1518 return;1519 if (HandleService(curr, fDim->fFadEvents, &StateMachineSmartFACT::HandleFadEvents))1520 return;1521 if (HandleService(curr, fDim->fFtmControlTriggerRates, &StateMachineSmartFACT::HandleFtmControlTriggerRates))1522 return;1523 if (HandleService(curr, fDim->fFtmControlStaticData, &StateMachineSmartFACT::HandleFtmControlStaticData))1524 return;1525 if (HandleService(curr, fDim->fFtmControlFtuList, &StateMachineSmartFACT::HandleFtmControlFtuList))1526 return;1527 if (HandleService(curr, fDim->fFadControlEventData, &StateMachineSmartFACT::HandleFadControlEventData))1528 return;1529 if (HandleService(curr, fDim->fFscControlTemperature, &StateMachineSmartFACT::HandleFscControlTemperature))1530 return;1531 if (HandleService(curr, fDim->fFscControlHumidity, &StateMachineSmartFACT::HandleFscControlHumidity))1532 return;1533 if (HandleService(curr, fDim->fControlMessage, &StateMachineSmartFACT::HandleControlMessage))1534 return;1535 if (HandleService(curr, fDim->fRateScanData, &StateMachineSmartFACT::HandleRateScanData))1536 return;1537 }1538 1312 1539 1313 bool CheckEventSize(size_t has, const char *name, size_t size) … … 1548 1322 } 1549 1323 1324 const State GetState(const DimState &s) const 1325 { 1326 return fNetwork.GetState(s.name(), s.state()); 1327 } 1328 1550 1329 void PrintState(const DimState &state) const 1551 1330 { 1552 const State rc = fDim->GetState(state);1331 const State rc = GetState(state); 1553 1332 1554 1333 Out() << state.time().GetAsStr("%H:%M:%S.%f").substr(0, 12) << " - "; … … 1568 1347 int Print() const 1569 1348 { 1570 Out() << fDim ->fDNS.time().GetAsStr("%H:%M:%S.%f").substr(0, 12) << " - ";1571 Out() << kBold << "DIM_DNS: " << fDim ->fDNS.version() << endl;1572 1573 PrintState(fDim ->fMcp);1574 PrintState(fDim ->fControl);1575 PrintState(fDim ->fDataLogger);1576 PrintState(fDim ->fDriveControl);1577 PrintState(fDim ->fFadControl);1578 PrintState(fDim ->fFtmControl);1579 PrintState(fDim ->fBiasControl);1580 PrintState(fDim ->fFeedback);1581 PrintState(fDim ->fRateControl);1582 PrintState(fDim ->fFscControl);1583 PrintState(fDim ->fMagicWeather);1584 PrintState(fDim ->fRateScan);1585 PrintState(fDim ->fChatServer);1349 Out() << fDimDNS.time().GetAsStr("%H:%M:%S.%f").substr(0, 12) << " - "; 1350 Out() << kBold << "DIM_DNS: " << fDimDNS.version() << endl; 1351 1352 PrintState(fDimMcp); 1353 PrintState(fDimControl); 1354 PrintState(fDimDataLogger); 1355 PrintState(fDimDriveControl); 1356 PrintState(fDimFadControl); 1357 PrintState(fDimFtmControl); 1358 PrintState(fDimBiasControl); 1359 PrintState(fDimFeedback); 1360 PrintState(fDimRateControl); 1361 PrintState(fDimFscControl); 1362 PrintState(fDimMagicWeather); 1363 PrintState(fDimRateScan); 1364 PrintState(fDimChatServer); 1586 1365 1587 1366 return GetCurrentState(); … … 1593 1372 return kHtmlWhite+"\t—\n"; 1594 1373 1595 if (&state==&fDim ->fControl)1374 if (&state==&fDimControl) 1596 1375 { 1597 1376 ostringstream out; … … 1600 1379 } 1601 1380 1602 const State rc = fDim->GetState(state);1381 const State rc = GetState(state); 1603 1382 1604 1383 // Sate not found in list, server online (-3: offline; -2: not found) … … 1630 1409 //poll_one(); 1631 1410 1632 if (fDim ->fDNS.state()==0)1411 if (fDimDNS.state()==0) 1633 1412 return kStateDimNetworkNA; 1634 1413 … … 1640 1419 1641 1420 ostringstream out; 1642 out << now.JavaDate() << '\t' << fDim ->fControl.online() << '\n';1421 out << now.JavaDate() << '\t' << fDimControl.online() << '\n'; 1643 1422 out << setprecision(3); 1644 1423 1645 1424 // -------------- System status -------------- 1646 if (fDim ->fMcp.state()>=5) // Idle1425 if (fDimMcp.state()>=5) // Idle 1647 1426 { 1648 1427 string col = kHtmlBlue; … … 1651 1430 fMcpConfigurationState!=11 && // Trigger On 1652 1431 fMcpConfigurationState!=12) // Taking Data*/ 1653 if (fDim ->fMcp.state()!= 5 && // Idle1654 fDim ->fMcp.state()!=11 && // Trigger On1655 fDim ->fMcp.state()!=12) // Taking Data1432 if (fDimMcp.state()!= 5 && // Idle 1433 fDimMcp.state()!=11 && // Trigger On 1434 fDimMcp.state()!=12) // Taking Data 1656 1435 col = kHtmlYellow; 1657 1436 else 1658 if (fDim ->fFadControl.state()==FAD::kWritingData)1437 if (fDimFadControl.state()==FAD::kWritingData) 1659 1438 col = kHtmlGreen; 1660 1439 1661 1440 out << col << '\t'; 1662 1441 1663 if (fDim ->fRateControl.state()!=5 && fDim->fRateScan.state()!=5)1442 if (fDimRateControl.state()!=5 && fDimRateScan.state()!=5) 1664 1443 { 1665 switch (fDim ->fMcp.state()/*fMcpConfigurationState*/)1444 switch (fDimMcp.state()/*fMcpConfigurationState*/) 1666 1445 { 1667 1446 // kStateIdle … … 1679 1458 } 1680 1459 else 1681 if (fDim ->fRateControl.state()==5/*kStateSettingGlobalThreshold*/)1460 if (fDimRateControl.state()==5/*kStateSettingGlobalThreshold*/) 1682 1461 out << "Calibrating threshold"; 1683 1462 else 1684 1463 1685 if (fDim ->fRateScan.state()==5/*kStateSettingGlobalThreshold*/)1464 if (fDimRateScan.state()==5/*kStateSettingGlobalThreshold*/) 1686 1465 out << "Rate scan in progress"; 1687 1466 1688 if (fDim ->fMcp.state()>10 && fDim->fRateControl.state()!=5)1467 if (fDimMcp.state()>10 && fDimRateControl.state()!=5) 1689 1468 { 1690 1469 if (fMcpConfigurationMaxEvents>0 || fMcpConfigurationMaxTime>0 || fMcpConfigurationState==12) … … 1732 1511 1733 1512 // ------------------ Drive ----------------- 1734 if (fDim ->fDriveControl.state()>=5) // Armed, Moving, Tracking1513 if (fDimDriveControl.state()>=5) // Armed, Moving, Tracking 1735 1514 { 1736 1515 const double dev = fDriveControlTrackingDevHist.size()>0 ? fDriveControlTrackingDevHist.back() : 0; 1737 const State rc = fDim->GetState(fDim->fDriveControl);1516 const State rc = GetState(fDimDriveControl); 1738 1517 string col = kHtmlGreen; 1739 1518 if (rc.index==6) // Moving … … 1753 1532 out << fDriveControlPointingZd << '\t'; 1754 1533 out << fDriveControlPointingAz << '\t'; 1755 if (fDim ->fDriveControl.state()==7)1534 if (fDimDriveControl.state()==7) 1756 1535 { 1757 1536 out << fDriveControlSourceName << '\t'; … … 1767 1546 1768 1547 // ------------------- FSC ------------------ 1769 if (fDim ->fFscControl.state()>1 && fFscControlTemperatureHist.size()>0)1548 if (fDimFscControl.state()>1 && fFscControlTemperatureHist.size()>0) 1770 1549 { 1771 1550 out << kHtmlGreen << '\t' << fFscControlTemperatureHist.back() << '\n'; … … 1775 1554 1776 1555 // --------------- MagicWeather ------------- 1777 if (fDim ->fMagicWeather.state()==3 && fMagicWeatherHist[kWeatherBegin].size()>0)1556 if (fDimMagicWeather.state()==3 && fMagicWeatherHist[kWeatherBegin].size()>0) 1778 1557 { 1779 1558 /* … … 1804 1583 1805 1584 // --------------- FtmControl ------------- 1806 if (fDim ->fFtmControl.state()==FTM::kTriggerOn)1585 if (fDimFtmControl.state()==FTM::kTriggerOn) 1807 1586 { 1808 1587 string col = kHtmlGreen; … … 1818 1597 1819 1598 // --------------- BiasControl ------------- 1820 if (fDim ->fBiasControl.state()==BIAS::kRamping ||1821 fDim ->fBiasControl.state()==BIAS::kOverCurrent ||1822 fDim ->fBiasControl.state()==BIAS::kVoltageOn ||1823 fDim ->fBiasControl.state()==BIAS::kVoltageOff)1824 { 1825 const bool off = fDim ->fBiasControl.state()==BIAS::kVoltageOff;1826 const bool oc = fDim ->fBiasControl.state()==BIAS::kOverCurrent;1599 if (fDimBiasControl.state()==BIAS::kRamping || 1600 fDimBiasControl.state()==BIAS::kOverCurrent || 1601 fDimBiasControl.state()==BIAS::kVoltageOn || 1602 fDimBiasControl.state()==BIAS::kVoltageOff) 1603 { 1604 const bool off = fDimBiasControl.state()==BIAS::kVoltageOff; 1605 const bool oc = fDimBiasControl.state()==BIAS::kOverCurrent; 1827 1606 1828 1607 string col = fBiasControlVoltageMed>3?kHtmlGreen:kHtmlWhite; … … 1833 1612 1834 1613 // Bias in overcurrent => Red 1835 if (fDim ->fBiasControl.state()==BIAS::kOverCurrent)1614 if (fDimBiasControl.state()==BIAS::kOverCurrent) 1836 1615 col = kHtmlRed; 1837 1616 1838 1617 // MCP in ReadyForDatataking/Configuring/Configured/TriggerOn/TakingData 1839 1618 // and Bias not in "data-taking state' => Red 1840 if (fDim ->fMcp.state()>5 &&1841 fDim ->fBiasControl.state()!=BIAS::kVoltageOn &&1842 fDim ->fBiasControl.state()!=BIAS::kVoltageOff)1619 if (fDimMcp.state()>5 && 1620 fDimBiasControl.state()!=BIAS::kVoltageOn && 1621 fDimBiasControl.state()!=BIAS::kVoltageOff) 1843 1622 col = kHtmlRed; 1844 1623 … … 1846 1625 1847 1626 // Feedback is currently calibrating => Blue 1848 if (fDim ->fFeedback.state()==13)1627 if (fDimFeedback.state()==13) 1849 1628 { 1850 1629 out << kHtmlBlue << '\t'; … … 1882 1661 1883 1662 out.str(""); 1884 out << now.JavaDate() << '\t' << fDim ->fControl.online() << '\n';1885 1886 if (fDim ->fDNS.state()==0)1663 out << now.JavaDate() << '\t' << fDimControl.online() << '\n'; 1664 1665 if (fDimDNS.state()==0) 1887 1666 out << kHtmlWhite << "\tOffline\n\n\n\n\n\n\n\n\n\n\n\n"; 1888 1667 else 1889 1668 { 1890 out << kHtmlGreen << '\t' << fDim ->fDNS.version() << '\n';1891 1892 out << GetStateHtml(fDim ->fMcp, 4);1893 out << GetStateHtml(fDim ->fControl, 0);1894 out << GetStateHtml(fDim ->fDataLogger, 1);1895 out << GetStateHtml(fDim ->fDriveControl, 2);1896 out << GetStateHtml(fDim ->fFadControl, FAD::kConnected);1897 out << GetStateHtml(fDim ->fFtmControl, FTM::kConnected);1898 out << GetStateHtml(fDim ->fBiasControl, BIAS::kConnected);1899 out << GetStateHtml(fDim ->fFeedback, 4);1900 out << GetStateHtml(fDim ->fRateControl, 4);1901 out << GetStateHtml(fDim ->fFscControl, 2);1902 out << GetStateHtml(fDim ->fMagicWeather, 2);1903 out << GetStateHtml(fDim ->fRateScan, 4);1904 out << GetStateHtml(fDim ->fChatServer, 1);1669 out << kHtmlGreen << '\t' << fDimDNS.version() << '\n'; 1670 1671 out << GetStateHtml(fDimMcp, 4); 1672 out << GetStateHtml(fDimControl, 0); 1673 out << GetStateHtml(fDimDataLogger, 1); 1674 out << GetStateHtml(fDimDriveControl, 2); 1675 out << GetStateHtml(fDimFadControl, FAD::kConnected); 1676 out << GetStateHtml(fDimFtmControl, FTM::kConnected); 1677 out << GetStateHtml(fDimBiasControl, BIAS::kConnected); 1678 out << GetStateHtml(fDimFeedback, 4); 1679 out << GetStateHtml(fDimRateControl, 4); 1680 out << GetStateHtml(fDimFscControl, 2); 1681 out << GetStateHtml(fDimMagicWeather, 2); 1682 out << GetStateHtml(fDimRateScan, 4); 1683 out << GetStateHtml(fDimChatServer, 1); 1905 1684 } 1906 1685 … … 1909 1688 return kStateRunning; 1910 1689 } 1690 1911 1691 1912 1692 public: … … 1918 1698 fRateScanDataId(0), 1919 1699 fRateScanBoard(0), 1920 fDim(0) 1921 { 1700 // --- 1701 fDimMcp ("MCP"), 1702 fDimDataLogger ("DATA_LOGGER"), 1703 fDimDriveControl("DRIVE_CONTROL"), 1704 fDimMagicWeather("MAGIC_WEATHER"), 1705 fDimFeedback ("FEEDBACK"), 1706 fDimBiasControl ("BIAS_CONTROL"), 1707 fDimFtmControl ("FTM_CONTROL"), 1708 fDimFadControl ("FAD_CONTROL"), 1709 fDimFscControl ("FSC_CONTROL"), 1710 fDimRateControl ("RATE_CONTROL"), 1711 fDimRateScan ("RATE_SCAN"), 1712 fDimChatServer ("CHAT_SERVER") 1713 { 1714 fDimMcp.Subscribe(*this); 1715 fDimDataLogger.Subscribe(*this); 1716 fDimDriveControl.Subscribe(*this); 1717 fDimMagicWeather.Subscribe(*this); 1718 fDimFeedback.Subscribe(*this); 1719 fDimBiasControl.Subscribe(*this); 1720 fDimFtmControl.Subscribe(*this); 1721 fDimFadControl.Subscribe(*this); 1722 fDimFscControl.Subscribe(*this); 1723 fDimRateControl.Subscribe(*this); 1724 fDimRateScan.Subscribe(*this); 1725 fDimChatServer.Subscribe(*this); 1726 1727 Subscribe("DIM_CONTROL/MESSAGE") 1728 (bind(&StateMachineSmartFACT::HandleDimControlMessage, this, placeholders::_1)); 1729 1730 Subscribe("MCP/CONFIGURATION") 1731 (bind(&StateMachineSmartFACT::HandleMcpConfiguration, this, placeholders::_1)); 1732 1733 Subscribe("DRIVE_CONTROL/POINTING_POSITION") 1734 (bind(&StateMachineSmartFACT::HandleDrivePointing, this, placeholders::_1)); 1735 Subscribe("DRIVE_CONTROL/TRACKING_POSITION") 1736 (bind(&StateMachineSmartFACT::HandleDriveTracking, this, placeholders::_1)); 1737 Subscribe("DRIVE_CONTROL/SOURCE_POSITION") 1738 (bind(&StateMachineSmartFACT::HandleDriveSource, this, placeholders::_1)); 1739 1740 Subscribe("FSC_CONTROL/TEMPERATURE") 1741 (bind(&StateMachineSmartFACT::HandleFscTemperature, this, placeholders::_1)); 1742 Subscribe("FSC_CONTROL/HUMIDITY") 1743 (bind(&StateMachineSmartFACT::HandleFscHumidity, this, placeholders::_1)); 1744 1745 Subscribe("MAGIC_WEATHER/DATA") 1746 (bind(&StateMachineSmartFACT::HandleMagicWeatherData, this, placeholders::_1)); 1747 1748 Subscribe("FEEDBACK/DEVIATION") 1749 (bind(&StateMachineSmartFACT::HandleFeedbackDeviation, this, placeholders::_1)); 1750 Subscribe("FEEDBACK/CALIBRATION") 1751 (bind(&StateMachineSmartFACT::HandleFeedbackCalibration, this, placeholders::_1)); 1752 1753 Subscribe("BIAS_CONTROL/VOLTAGE") 1754 (bind(&StateMachineSmartFACT::HandleBiasVoltage, this, placeholders::_1)); 1755 Subscribe("BIAS_CONTROL/CURRENT") 1756 (bind(&StateMachineSmartFACT::HandleBiasCurrent, this, placeholders::_1)); 1757 1758 Subscribe("FAD_CONTROL/CONNECTIONS") 1759 (bind(&StateMachineSmartFACT::HandleFadConnections, this, placeholders::_1)); 1760 Subscribe("FAD_CONTROL/EVENTS") 1761 (bind(&StateMachineSmartFACT::HandleFadEvents, this, placeholders::_1)); 1762 1763 Subscribe("FTM_CONTROL/TRIGGER_RATES") 1764 (bind(&StateMachineSmartFACT::HandleFtmTriggerRates, this, placeholders::_1)); 1765 Subscribe("FTM_CONTROL/STATIC_DATA") 1766 (bind(&StateMachineSmartFACT::HandleFtmStaticData, this, placeholders::_1)); 1767 Subscribe("FTM_CONTROL/FTU_LIST") 1768 (bind(&StateMachineSmartFACT::HandleFtmFtuList, this, placeholders::_1)); 1769 1770 Subscribe("RATE_SCAN/DATA") 1771 (bind(&StateMachineSmartFACT::HandleRateScanData, this, placeholders::_1)); 1772 1773 Subscribe("FAD_CONTROL/EVENT_DATA") 1774 (bind(&StateMachineSmartFACT::HandleFadEventData, this, placeholders::_1)); 1775 1776 // ================================================================= 1777 1922 1778 // State names 1923 1779 AddStateName(kStateDimNetworkNA, "DimNetworkNotAvailable", … … 1926 1782 AddStateName(kStateRunning, "Running", ""); 1927 1783 1784 // ================================================================= 1785 1928 1786 AddEvent("PRINT") 1929 1787 (bind(&StateMachineSmartFACT::Print, this)) … … 1931 1789 1932 1790 } 1933 ~StateMachineSmartFACT()1934 {1935 delete fDim;1936 }1937 1791 int EvalOptions(Configuration &conf) 1938 1792 { … … 1945 1799 fPath = conf.Get<string>("path"); 1946 1800 1947 fDim = new DimSubscriptions(this); 1948 fDim->fControl.SetCallback(bind(&StateMachineSmartFACT::HandleControlStateChange, this, placeholders::_1)); 1949 fDim->fControl.AddCallback("dotest.dim", bind(&StateMachineSmartFACT::HandleDoTest, this, placeholders::_1)); 1801 fDimControl.SetCallback(bind(&StateMachineSmartFACT::HandleControlStateChange, this, placeholders::_1)); 1802 fDimControl.AddCallback("dotest.dim", bind(&StateMachineSmartFACT::HandleDoTest, this, placeholders::_1)); 1950 1803 1951 1804 return -1;
Note:
See TracChangeset
for help on using the changeset viewer.