Changeset 13893


Ignore:
Timestamp:
05/25/12 21:04:52 (13 years ago)
Author:
tbretz
Message:
Updated to configure the ftm properly before a ratescan is started; added new configuration states and a callback to record the ftm state change properly.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/ratescan.cc

    r13847 r13893  
    3838        kStateConnecting,
    3939        kStateConnected,
     40        kStateConfiguring,
    4041        kStateInProgress,
    4142    };
     
    103104            return GetCurrentState();
    104105
    105         if (fThreshold<0/* || fDimFTM.state()!=FTM::kTakingData*/)
     106        if (GetCurrentState()!=kStateInProgress)
    106107            return GetCurrentState();
    107108
     
    192193        {
    193194            Message("Rate scan stopped due to timeout.");
    194             fThreshold=-1;
    195             return GetCurrentState();
     195            return kStateConnected;
    196196        }
    197197
     
    199199        {
    200200            Message("Rate scan finished.");
    201             fThreshold = -1;
    202             return GetCurrentState();
     201            return kStateConnected;
    203202        }
    204203
     
    245244
    246245        UpdateProc();
     246
     247        const string data = "\0\0\0\0\0\0\0\0ratescan";
     248
     249        Dim::SendCommand("FAD_CONTROL/SET_FILE_FORMAT", uint16_t(0));
     250        Dim::SendCommand("FTM_CONTROL/CONFIGURE", data);
     251
     252        Message("Configuration for ratescan started.");
     253
     254        return kStateConfiguring;
     255    }
     256
     257    int HandleFtmStateChange(/*const EventImp &evt*/)
     258    {
     259        if (GetCurrentState()!=kStateConfiguring)
     260            return GetCurrentState();
     261
     262        if (fDimFTM.state()!=FTM::kConfigured)
     263            return GetCurrentState();
     264
     265        const int32_t data[2] = { -1, fThresholdMin };
     266
     267        Dim::SendCommand(fCommand, data);
     268
     269        fThreshold = fThresholdMin;
     270        fCounter = -2;
    247271
    248272        const Time now;
     
    262286        fout << "# -----" << endl;
    263287
    264         Dim::SendCommand("FAD_CONTROL/SET_FILE_FORMAT", uint16_t(0));
    265 
    266         const int32_t data[2] = { -1, fThresholdMin };
    267 
    268         //Message("Starting Trigger (FTM)");
    269         //Dim::SendCommand("FTM_CONTROL/SET_PRESCALING", int32_t(20));
    270         Dim::SendCommand(fCommand, data);
    271         //Dim::SendCommand("FTM_CONTROL/STOP_TRIGGER");
    272 
    273         fThreshold = fThresholdMin;
    274         fCounter = -2;
    275 
    276288        ostringstream msg;
    277289        msg << "Rate scan " << now << "(" << fStartTime << ") from " << fThresholdMin << " to ";
     
    280292        Message(msg);
    281293
    282         return GetCurrentState();
     294        return kStateInProgress;
    283295    }
    284296
    285297    int StopRateScan()
    286298    {
    287         fThreshold = -1;
     299        if (GetCurrentState()!=kStateConfiguring && GetCurrentState()!=kStateInProgress)
     300            return GetCurrentState();
     301
    288302        Message("Rate scan manually stopped.");
    289303
    290         //if (fDimFTM.state()==FTM::kTakingData)
    291         {
    292             //Message("Stopping FTM");
    293             //Dim::SendCommand("FTM_CONTROL/STOP_TRIGGER");
    294         }
    295 
    296         return GetCurrentState();
     304        return kStateConnected;
    297305    }
    298306
     
    366374    int Execute()
    367375    {
    368         // Dispatch (execute) at most one handler from the queue. In contrary
    369         // to run_one(), it doesn't wait until a handler is available
    370         // which can be dispatched, so poll_one() might return with 0
    371         // handlers dispatched. The handlers are always dispatched/executed
    372         // synchronously, i.e. within the call to poll_one()
    373         //poll_one();
    374 
    375376        if (!fDim.online())
    376377            return kStateDimNetworkNA;
     
    380381            return kStateDisconnected;
    381382
    382         // At least one subsystem is not connected
    383         //        if (fDimFTM.state()>=FTM::kConnected)
    384         return fThreshold<0 ? kStateConnected : kStateInProgress;
     383        return GetCurrentState();
    385384    }
    386385
     
    412411        fDim.Subscribe(*this);
    413412        fDimFTM.Subscribe(*this);
     413        fDimFTM.SetCallback(bind(&StateMachineRateScan::HandleFtmStateChange, this));
    414414
    415415        Subscribe("FTM_CONTROL/TRIGGER_RATES")
     
    453453             "|max[int]:Limiting value in DAC counts");
    454454
    455         AddEvent("STOP", kStateInProgress)
     455        AddEvent("STOP", kStateConfiguring, kStateInProgress)
    456456            (bind(&StateMachineRateScan::StopRateScan, this))
    457457            ("Stop a ratescan in progress");
Note: See TracChangeset for help on using the changeset viewer.