Changeset 10542 for trunk/FACT++


Ignore:
Timestamp:
05/03/11 18:28:38 (13 years ago)
Author:
tbretz
Message:
Added SetThreshold and CheckEventSize; some comment to remind me what work to do tomorrow.
File:
1 edited

Legend:

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

    r10517 r10542  
    132132            return;
    133133
    134         Out() << endl << kBold << "Error list received:" << endl;
     134        Out() << endl << kRed << "Error received:" << endl;
    135135        Out() << fError;
    136136        if (fIsHexOutput)
     
    557557    }
    558558
     559    bool SetThreshold(int32_t patch, int32_t value)
     560    {
     561
     562        if (patch>159)
     563            return false;
     564
     565        if (value<0 || value>0xffff)
     566            return false;
     567
     568        if (patch<0)
     569        {
     570            for (int i=0; i<160; i++)
     571                fStaticData[i/4].fDAC[i%4] = value;
     572        }
     573        else
     574            fStaticData[patch/4].fDAC[patch%4] = value;
     575
     576        CmdSendStatDat();
     577
     578        return true;
     579    }
     580
    559581    int GetState() const { return IsConnected() ? fState : (int)FTM::kDisconnected; }
    560582};
     
    673695        kStateIdle         = FTM::kIdle,
    674696        kStateTakingData   = FTM::kTakingData,
    675 /*
    676         kCmdToggleLed,
    677         kCmdPing,
    678         kCmdReqDynData,
    679         kCmdReqStatData,
    680         kCmdReqRegister,
    681         kCmdSetRegister,
    682   */
     697
    683698        kCmdTest
    684699    };
    685700
    686     int SetRegister(const Event &evt)
    687     {
    688         if (evt.GetSize()!=8)
    689         {
    690             stringstream msg;
    691             msg << "SetRegister - Received event has " << evt.GetSize() << " bytes, but expected 8.";
    692             T::Fatal(msg);
    693 
     701    bool CheckEventSize(size_t has, const char *name, size_t size)
     702    {
     703        if (has==size)
     704            return true;
     705
     706        stringstream msg;
     707        msg << name << " - Received event has " << has << " bytes, but expected " << size << ".";
     708        T::Fatal(msg);
     709        return false;
     710    }
     711
     712    int SetRegister(const EventImp &evt)
     713    {
     714        if (!CheckEventSize(evt.GetSize(), "SetRegister", 8))
    694715            return T::kSM_FatalError;
    695         }
    696716
    697717        const unsigned int *dat = reinterpret_cast<const unsigned int*>(evt.GetData());
     
    716736    }
    717737
    718     int GetRegister(const Event &evt)
    719     {
    720         if (evt.GetSize()!=4)
    721         {
    722             stringstream msg;
    723             msg << "GetRegister - Received event has " << evt.GetSize() << "bytes,  but expected 2.";
    724             T::Fatal(msg);
     738    int GetRegister(const EventImp &evt)
     739    {
     740        if (!CheckEventSize(evt.GetSize(), "GetRegister", 4))
    725741            return T::kSM_FatalError;
    726         }
    727742
    728743        const unsigned int addr = evt.GetInt();
     
    737752    }
    738753
    739     int TakeNevents(const Event &evt)
    740     {
    741         if (evt.GetSize()!=4)
    742         {
    743             stringstream msg;
    744             msg << "TakeNevents - Received event has " << evt.GetSize() << " bytes, but expected 4.";
    745             T::Fatal(msg);
    746 
     754    int TakeNevents(const EventImp &evt)
     755    {
     756        if (!CheckEventSize(evt.GetSize(), "TakeNevents", 4))
    747757            return T::kSM_FatalError;
    748         }
    749758
    750759        const unsigned int dat = evt.GetUInt();
     
    764773    }
    765774
    766     int DisableReports(const Event &evt)
    767     {
    768         if (evt.GetSize()!=1)
    769         {
    770             stringstream msg;
    771             msg << "DisableReports - Received event has " << evt.GetSize() << " bytes, but expected 1.";
    772             T::Fatal(msg);
    773 
     775    int DisableReports(const EventImp &evt)
     776    {
     777        if (!CheckEventSize(evt.GetSize(), "DisableReports", 1))
    774778            return T::kSM_FatalError;
    775         }
    776779
    777780        fFTM.CmdDisableReports(evt.GetText()[0]!=0);
     
    780783    }
    781784
    782     int SetVerbosity(const Event &evt)
    783     {
    784         if (evt.GetSize()!=1)
    785         {
    786             stringstream msg;
    787             msg << "SetVerbosity - Received event has " << evt.GetSize() << " bytes, but expected 1.";
    788             T::Fatal(msg);
    789 
     785    int SetVerbosity(const EventImp &evt)
     786    {
     787        if (!CheckEventSize(evt.GetSize(), "SetVerbosity", 1))
    790788            return T::kSM_FatalError;
    791         }
    792789
    793790        fFTM.SetVerbose(evt.GetText()[0]!=0);
     
    796793    }
    797794
    798     int LoadStaticData(const Event &evt)
     795    int LoadStaticData(const EventImp &evt)
    799796    {
    800797        if (fFTM.LoadStaticData(evt.GetString()))
     
    814811    }
    815812
    816     int SaveStaticData(const Event &evt)
     813    int SaveStaticData(const EventImp &evt)
    817814    {
    818815        if (fFTM.SaveStaticData(evt.GetString()))
     
    828825    }
    829826
     827    int SetThreshold(const EventImp &evt)
     828    {
     829        if (!CheckEventSize(evt.GetSize(), "SetThreshold", 8))
     830            return T::kSM_FatalError;
     831
     832        const int32_t *data = reinterpret_cast<const int32_t*>(evt.GetData());
     833
     834        if (!fFTM.SetThreshold(data[0], data[1]))
     835            T::Warn("SetThreshold - Maximum allowed patch number 159, valid value range 0-0xffff");
     836
     837        return T::GetCurrentState();
     838    }
    830839
    831840    int Disconnect()
     
    843852    }
    844853
    845     int Reconnect(const Event &evt)
     854    int Reconnect(const EventImp &evt)
    846855    {
    847856        // Close all connections to supress the warning in SetEndpoint
     
    957966             "|status[bool]:disable or enable that the FTM sends rate reports (yes/no)");
    958967
     968        AddConfiguration("SET_THRESHOLD", "I:2", kStateIdle)
     969            (boost::bind(&StateMachineFTM::SetThreshold, this, _1))
     970            ("Set the comparator threshold"
     971             "|Patch[idx]:Index of the patch"
     972             "|Threshold[counts]:Threshold to be set in binary counts");
     973
    959974        T::AddConfiguration("SET_VERBOSE", "B")
    960975            (boost::bind(&StateMachineFTM::SetVerbosity, this, _1))
     
    9901005
    9911006
    992         // RESET_THRESHOLD        val
    993         // --> SetThreshold(-1, val)
    994 
    9951007        // SET_THRESHOLD          idx val
    996         // ---> SetThreshold(idx, val)
    997 
    998 
    999         // ENABLE_FTU             idx bool  (-1 for all)
    1000         // ---> EnableFtu(idx, bool)
    1001 
     1008        // ---> SetThreshold(idx==-1, val)
     1009
     1010        // ENABLE_FTU             idx bool
     1011        // ---> EnableFtu(idx==-1, bool)
    10021012
    10031013        // ENABLE_TRIGGER         bool
     
    10121022        // ---> SetTriggerSequence(val, val, val)
    10131023
    1014 
    10151024        // SET_TRIGGER_INTERVAL   val
    10161025        // SET_TRIGGER_DELAY      val
     
    10191028        // ---> SetXYZ(val)
    10201029
    1021 
    10221030        // SET_PRESCALING         idx val
    1023         // ---> SetPrescaling(-1, val)
    1024 
    1025         // RESET_PRESCALING       val
    1026         // ---> SetPrescaling(idx, val)
     1031        // ---> SetPrescaling(idx==-1, val)
    10271032    }
    10281033
Note: See TracChangeset for help on using the changeset viewer.