Changeset 10816


Ignore:
Timestamp:
May 25, 2011, 1:43:41 PM (8 years ago)
Author:
tbretz
Message:
Moved commands to HeaderFAD; fixed the range of the loop to set all ROIs
File:
1 edited

Legend:

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

    r10811 r10816  
     1#include <boost/bind.hpp>
    12#include <boost/bind.hpp>
    23#include <boost/array.hpp>
     
    107108        }
    108109
     110        // FIXME FIXME FIXME. The data block could have the same size!!!!!
     111        // !!!!!!!!!!!!!!!!!!!
    109112        if (bytes_received == sizeof(FAD::EventHeader))
    110113        {
     
    130133            fBuffer.resize(fEventHeader.fPackageLength-sizeof(FAD::EventHeader)/2);
    131134            AsyncRead(ba::buffer(fBuffer));
     135            AsyncWait(fInTimeout, 50, &Connection::HandleReadTimeout);
    132136
    133137            return;
    134138        }
     139
     140        fInTimeout.cancel();
    135141
    136142        if (ntohs(fBuffer.back())!=FAD::kDelimiterEnd)
     
    198204    }
    199205
     206    void HandleReadTimeout(const bs::error_code &error)
     207    {
     208        if (error && error!=ba::error::basic_errors::operation_aborted)
     209        {
     210            ostringstream str;
     211            str << "Read timeout of " << URL() << ": " << error.message() << " (" << error << ")";// << endl;
     212            Error(str);
     213
     214            PostClose();
     215            return;
     216
     217        }
     218
     219        if (!is_open())
     220        {
     221            // For example: Here we could schedule a new accept if we
     222            // would not want to allow two connections at the same time.
     223            return;
     224        }
     225
     226        if (error==ba::error::basic_errors::operation_aborted)
     227            return;
     228
     229        // Check whether the deadline has passed. We compare the deadline
     230        // against the current time since a new asynchronous operation
     231        // may have moved the deadline before this actor had a chance
     232        // to run.
     233        if (fInTimeout.expires_at() > ba::deadline_timer::traits_type::now())
     234            return;
     235
     236        Error("Timeout reading data from "+URL());
     237        PostClose();
     238    }
     239
    200240    // This is called when a connection was established
    201241    void ConnectionEstablished()
     
    213253//            CmdSetRoi(i, 100);
    214254
    215         Cmd(ConnectionFAD::kCmdTriggerLine, true);
    216         Cmd(ConnectionFAD::kCmdSingleTrigger);
     255        Cmd(FAD::kCmdTriggerLine, true);
     256        Cmd(FAD::kCmdSingleTrigger);
    217257    }
    218258
     
    291331
    292332public:
    293     enum Enable_t
    294     {
    295         kCmdDrsEnable       = 0x0600,  // CMD_DENABLE/CMD_DISABLE
    296         kCmdDwrite          = 0x0800,  // CMD_DWRITE_RUN/CMD_DWRITE_STOP
    297         kCmdSclk            = 0x1000,  // CMD_SCLK_ON/OFF
    298         kCmdSrclk           = 0x1500,  // CMD_SRCLK_ON/OFF
    299         kCmdTriggerLine     = 0x1800,  // CMD_TRIGGERS_ON/CMD_TRIGGERS_OFF
    300         //kCmdContTrigger  = 0x1f00,
    301         kCmdContTriggerOff  = 0x2000,
    302         kCmdRun             = 0x2200,  // CMD_Start/Stop
    303         kCmdResetTriggerId  = 0x2A00,  //
    304         kCmdSocket          = 0x3000,  // CMD_mode_command/CMD_mode_all_sockets
    305         kCmdSingleTrigger   = 0xA000,  // CMD_Trigger
    306         kCmdContTriggerOn   = 0xB000,
    307     };
    308 
    309 private:
    310     enum
    311     {
    312         kCmdWrite           = 0x0500,         // write to Config-RAM
    313         kCmdWriteRoi        = kCmdWrite|0x00, // Baseaddress ROI-Values
    314         kCmdWriteDac        = kCmdWrite|0x24, // Baseaddress DAC-Values
    315 
    316         kCmdWriteRate       = kCmdWrite|0x2c, // Continous trigger rate
    317         kCmdWriteRunNumber  = kCmdWrite|0x2d, //
    318 
    319         /*
    320          kCmdRead            = 0x0a00,         // read from Config-RAM
    321          kCmdReadRoi         = kCmdRead|0x00,  // Baseaddress ROI-Values
    322          kCmdReadDac         = kCmdRead|0x24,  // Baseaddress DAC-Values
    323          */
    324 
    325         kCmdPhaseIncrease   = 0x1200,         // CMD_PS_DIRINC
    326         kCmdPhaseDecrease   = 0x1300,         // CMD_PS_DIRDEC
    327         kCmdPhaseApply      = 0x1400,         // CMD_PS_DO
    328         kCmdPhaseReset      = 0x1700,         // CMD_PS_RESET
    329     };
    330 
    331 public:
    332333    ConnectionFAD(ba::io_service& ioservice, MessageImp &imp) :
    333334    Connection(ioservice, imp()),
     
    338339    }
    339340
    340     void Cmd(Enable_t cmd, bool on=true)
     341    void Cmd(FAD::Enable cmd, bool on=true)
    341342    {
    342343        PostCmd(cmd + (on ? 0 : 0x100));
     
    348349    void CmdPhaseShift(int16_t val)
    349350    {
    350         vector<uint16_t> cmd(abs(val)+2, kCmdPhaseApply);
    351         cmd[0] = kCmdPhaseReset;
    352         cmd[1] = val<0 ? kCmdPhaseDecrease : kCmdPhaseIncrease;
     351        vector<uint16_t> cmd(abs(val)+2, FAD::kCmdPhaseApply);
     352        cmd[0] = FAD::kCmdPhaseReset;
     353        cmd[1] = val<0 ? FAD::kCmdPhaseDecrease : FAD::kCmdPhaseIncrease;
    353354        PostCmd(cmd);
    354355    }
     
    359360            return false;
    360361
    361         PostCmd(kCmdWriteRate, val);//uint8_t(1000./val/12.5));
     362        PostCmd(FAD::kCmdWriteRate, val);//uint8_t(1000./val/12.5));
    362363        //PostCmd(kCmdContTriggerRate, uint8_t(80/val));
    363364
     
    369370        // Allowed addr:  [0, MAX_ADDR]
    370371        // Allowed value: [0, MAX_VAL]
    371         PostCmd(kCmdWrite + addr, val);
     372        PostCmd(FAD::kCmdWrite + addr, val);
    372373    }
    373374
     
    377378            return false;
    378379
    379         PostCmd(kCmdWriteDac + addr, val);
     380        PostCmd(FAD::kCmdWriteDac + addr, val);
    380381        return true;
    381382    }
     
    390391
    391392        if (addr<0)
    392             for (int i=0; i<FAD::kMaxRoiAddr; i++)
    393                 PostCmd(kCmdWriteRoi + i, val);
     393            for (int i=0; i<=FAD::kMaxRoiAddr; i++)
     394                PostCmd(FAD::kCmdWriteRoi + i, val);
    394395        else
    395             PostCmd(kCmdWriteRoi + addr, val);
     396            PostCmd(FAD::kCmdWriteRoi + addr, val);
    396397
    397398        return true;
     
    712713    }
    713714
    714     int Cmd(ConnectionFAD::Enable_t command)
     715    int Cmd(FAD::Enable command)
    715716    {
    716717        for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++)
     
    720721    }
    721722
    722     int CmdEnable(const EventImp &evt, ConnectionFAD::Enable_t command)
     723    int CmdEnable(const EventImp &evt, FAD::Enable command)
    723724    {
    724725        if (!CheckEventSize(evt.GetSize(), "CmdEnable", 1))
     
    806807        for (int nn=0; nn<n; nn++)
    807808            for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++)
    808                 i->second.second->Cmd(ConnectionFAD::kCmdSingleTrigger);
     809                i->second.second->Cmd(FAD::kCmdSingleTrigger);
    809810
    810811        return T::GetCurrentState();
     
    827828
    828829        for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++)
    829             i->second.second->Cmd(ConnectionFAD::kCmdRun, start);
     830            i->second.second->Cmd(FAD::kCmdRun, start);
    830831
    831832        return T::GetCurrentState();
     
    12181219        // FAD Commands
    12191220        T::AddEvent("ENABLE_SRCLK", "B:1")
    1220             (boost::bind(&StateMachineFAD::CmdEnable, this, _1, ConnectionFAD::kCmdSrclk))
     1221            (boost::bind(&StateMachineFAD::CmdEnable, this, _1, FAD::kCmdSrclk))
    12211222            ("Set SRCLK");
    12221223        T::AddEvent("ENABLE_SCLK", "B:1")
    1223             (boost::bind(&StateMachineFAD::CmdEnable, this, _1, ConnectionFAD::kCmdSclk))
     1224            (boost::bind(&StateMachineFAD::CmdEnable, this, _1, FAD::kCmdSclk))
    12241225            ("Set SCLK");
    12251226        T::AddEvent("ENABLE_DRS", "B:1")
    1226             (boost::bind(&StateMachineFAD::CmdEnable, this, _1, ConnectionFAD::kCmdDrsEnable))
     1227            (boost::bind(&StateMachineFAD::CmdEnable, this, _1, FAD::kCmdDrsEnable))
    12271228            ("Switch Domino wave");
    12281229        T::AddEvent("ENABLE_DWRITE", "B:1")
    1229             (boost::bind(&StateMachineFAD::CmdEnable, this, _1, ConnectionFAD::kCmdDwrite))
     1230            (boost::bind(&StateMachineFAD::CmdEnable, this, _1, FAD::kCmdDwrite))
    12301231            ("Set Dwrite (possibly high / always low)");
    12311232        T::AddEvent("SET_DEBUG_MODE", "B:1")
    1232             (boost::bind(&StateMachineFAD::CmdEnable, this, _1, ConnectionFAD::kCmdSocket))
     1233            (boost::bind(&StateMachineFAD::CmdEnable, this, _1, FAD::kCmdSocket))
    12331234            ("Set debug mode (yes: dump events through command socket, no=dump events through other sockets)");
    12341235        T::AddEvent("ENABLE_TRIGGER_LINE", "B:1")
    1235             (boost::bind(&StateMachineFAD::CmdEnable, this, _1, ConnectionFAD::kCmdTriggerLine))
     1236            (boost::bind(&StateMachineFAD::CmdEnable, this, _1, FAD::kCmdTriggerLine))
    12361237            ("Incoming triggers can be accepted/will not be accepted");
    12371238        T::AddEvent("SET_TRIGGER_RATE", "I:1")
     
    12551256
    12561257        T::AddEvent("CONTINOUS_TRIGGER_ON")
    1257             (boost::bind(&StateMachineFAD::Cmd, this, ConnectionFAD::kCmdContTriggerOn))
     1258            (boost::bind(&StateMachineFAD::Cmd, this, FAD::kCmdContTriggerOn))
    12581259            ("");
    12591260        T::AddEvent("CONTINOUS_TRIGGER_OFF")
    1260             (boost::bind(&StateMachineFAD::Cmd, this, ConnectionFAD::kCmdContTriggerOff))
     1261            (boost::bind(&StateMachineFAD::Cmd, this, FAD::kCmdContTriggerOff))
    12611262            ("");
    12621263
    12631264        T::AddEvent("RESET_TRIGGER_ID")
    1264             (boost::bind(&StateMachineFAD::Cmd, this, ConnectionFAD::kCmdResetTriggerId))
     1265            (boost::bind(&StateMachineFAD::Cmd, this, FAD::kCmdResetTriggerId))
    12651266            ("");
    12661267
Note: See TracChangeset for help on using the changeset viewer.