Changeset 13956


Ignore:
Timestamp:
05/29/12 12:42:40 (13 years ago)
Author:
tbretz
Message:
(Hopefully) improved the state handling.
File:
1 edited

Legend:

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

    r13915 r13956  
    1616
    1717#include "HeadersFTM.h"
     18#include "HeadersRateScan.h"
    1819#include "HeadersRateControl.h"
    1920
     
    4142    DimDescribedState fDimFTM;
    4243    DimDescribedState fDimRS;
     44
     45    DimDescribedService fDimThreshold;
    4346
    4447    float  fTargetRate;
     
    218221    }
    219222
    220     void ProcessCamera(const FTM::DimTriggerRates &sdata)
     223    int ProcessCamera(const FTM::DimTriggerRates &sdata)
    221224    {
    222225        if (fCounter++==0)
    223             return;
     226            return GetCurrentState();
    224227
    225228        // Caluclate Median and deviation
     
    241244        {
    242245            Warn("The median or the deviation of all board rates is zero... cannot calibrate.");
    243             return;
     246            return GetCurrentState();
    244247        }
    245248
     
    283286        {
    284287            fThresholds.assign(160, fThresholdMin);
    285             return;
     288            fDimThreshold.Update(fThresholdMin);
     289            return RateControl::State::kGlobalThresholdSet;
    286290        }
    287291
     
    292296        const uint16_t diff = fThresholdMin+int16_t(truncf(step));
    293297        if (diff<=fThresholdMin)
    294             return;
     298        {
     299            fDimThreshold.Update(fThresholdMin);
     300            return RateControl::State::kGlobalThresholdSet;
     301        }
    295302
    296303        if (fVerbose)
     
    306313
    307314        fThresholdMin = diff;
     315
     316        return GetCurrentState();
    308317    }
    309318
     
    328337            return GetCurrentState();
    329338
    330         if (!fTriggerOn && !fEnabled)
    331             return GetCurrentState();
    332 
    333         if (fDimRS.state()>=5)
     339        if (GetCurrentState()<=RateControl::State::kConnected ||
     340            GetCurrentState()==RateControl::State::kGlobalThresholdSet)
    334341            return GetCurrentState();
    335342
     
    340347
    341348        if (GetCurrentState()==RateControl::State::kSettingGlobalThreshold)
    342             ProcessCamera(sdata);
     349            return ProcessCamera(sdata);
    343350
    344351        if (GetCurrentState()==RateControl::State::kInProgress)
     
    363370        fThresholdMin = fThresholdReference;
    364371        fTriggerRate  = -1;
    365         fEnabled      = true;
    366372        fCounter      = 0;
    367373
     
    385391    }
    386392
    387     int SetEnabled(const EventImp &evt)
    388     {
    389         if (!CheckEventSize(evt, 1))
    390             return kSM_FatalError;
    391 
    392         fEnabled = evt.GetBool();
    393 
    394         return GetCurrentState();
    395     }
    396 
    397393    int SetMinThreshold(const EventImp &evt)
    398394    {
     
    438434    int Execute()
    439435    {
    440         // Dispatch (execute) at most one handler from the queue. In contrary
    441         // to run_one(), it doesn't wait until a handler is available
    442         // which can be dispatched, so poll_one() might return with 0
    443         // handlers dispatched. The handlers are always dispatched/executed
    444         // synchronously, i.e. within the call to poll_one()
    445         //poll_one();
    446 
    447436        if (!fDim.online())
    448437            return RateControl::State::kDimNetworkNA;
     
    453442
    454443        if (GetCurrentState()==RateControl::State::kSettingGlobalThreshold)
    455         {
    456             if (fTriggerRate<0 || fTriggerRate>fTargetRate)
    457                 return RateControl::State::kSettingGlobalThreshold;
    458 
     444            return RateControl::State::kSettingGlobalThreshold;
     445
     446        if (GetCurrentState()==RateControl::State::kGlobalThresholdSet)
    459447            return RateControl::State::kGlobalThresholdSet;
    460         }
    461 
    462         if (GetCurrentState()==RateControl::State::kGlobalThresholdSet)
    463         {
    464             if (!fTriggerOn)
    465                 return RateControl::State::kGlobalThresholdSet;
    466             //return RateControl::State::kInProgress;
    467         }
    468 
    469         // At least one subsystem is not connected
    470         //        if (fDimFTM.state()>=FTM::kConnected)
    471         return fTriggerOn && fEnabled && fDimRS.state()<5 ? RateControl::State::kInProgress : RateControl::State::kConnected;
     448
     449        if (fEnabled && fTriggerOn && fDimRS.state()<RateScan::State::kConfiguring)
     450            return RateControl::State::kInProgress;
     451
     452        return RateControl::State::kConnected;
    472453    }
    473454
     
    476457        fTriggerOn(false), fBlock(40),
    477458        fDimFTM("FTM_CONTROL"),
    478         fDimRS("RATE_SCAN")
     459        fDimRS("RATE_SCAN"),
     460        fDimThreshold("THRESHOLD", "S:1", "Resulting threshold after calibration|threshold[dac]:Resulting threshold from calibration")
    479461    {
    480462        // ba::io_service::work is a kind of keep_alive for the loop.
     
    514496            ("");
    515497
    516         AddEvent("START", "")
     498        AddEvent("START", "", RateControl::State::kConnected, RateControl::State::kGlobalThresholdSet)
    517499            (bind(&StateMachineRateControl::StartRC, this))
    518500            ("");
    519501
    520         AddEvent("STOP", "")
     502        AddEvent("STOP", "", RateControl::State::kSettingGlobalThreshold, RateControl::State::kInProgress)
    521503            (bind(&StateMachineRateControl::StopRC, this))
    522504            ("");
Note: See TracChangeset for help on using the changeset viewer.