Changeset 11858 for trunk/FACT++/src


Ignore:
Timestamp:
08/09/11 14:20:13 (14 years ago)
Author:
tbretz
Message:
More updates... added new function... restructured functions, etc.
File:
1 edited

Legend:

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

    r11852 r11858  
    6262
    6363    virtual void UpdateA()
     64    {
     65    }
     66
     67    virtual void UpdateV()
    6468    {
    6569    }
     
    195199
    196200        SystemReset();
    197         ReadAllChannelsStatus();
     201        ReadAllChannels();
    198202    }
    199203
     
    258262
    259263        return data;
    260     }
    261 
    262     void GlobalSetDac(uint16_t dac)
    263     {
    264         PostMessage(GetCmd(0, kCmdGlobalSet, dac));
    265         AsyncRead(ba::buffer(fBuffer), kCmdGlobalSet);
    266264    }
    267265
     
    315313    }
    316314
    317     bool GlobalSet(double voltage)
    318     {
    319         const uint16_t dac = voltage*4096/90;
     315    void SystemReset()
     316    {
     317        Message("Sending system reset.");
     318        PostMessage(GetCmd(0, kCmdReset));
     319        AsyncRead(ba::buffer(fBuffer), kCmdReset);
     320    }
     321
     322    void ReadChannel(int ch)
     323    {
     324        PostMessage(GetCmd(ch, kCmdRead));
     325        AsyncRead(ba::buffer(fBuffer), kCmdRead|(ch<<4));
     326    }
     327
     328
     329    void ReadAllChannels()
     330    {
     331        Message("Requesting full system status.");
     332
     333        // Prepare command to read all channels
     334        for (int i=0; i<kNumChannels; i++)
     335            ReadChannel(i);
     336
     337        //vector<char> buf;
     338        //AsyncRead(ba::buffer(buf), kCmdPrint);
     339    }
     340
     341    bool GlobalSetDac(uint16_t dac)
     342    {
    320343        if (dac>0xfff)
    321344            return false;
    322345
    323         GlobalSetDac(dac);
     346        PostMessage(GetCmd(0, kCmdGlobalSet, dac));
     347        AsyncRead(ba::buffer(fBuffer), kCmdGlobalSet);
     348
     349        ReadAllChannels();
     350
     351        fVolt.assign(kNumChannels, dac);
     352        UpdateV();
    324353
    325354        return true;
    326355    }
    327356
    328     bool ChannelSet(uint16_t ch, double voltage)
    329     {
    330         const uint16_t dac = voltage*4096/90;
     357    bool GlobalSet(double voltage)
     358    {
     359        return GlobalSetDac(voltage*4096/90);
     360    }
     361
     362    bool ChannelSetDac(uint16_t ch, uint16_t dac)
     363    {
    331364        if (dac>0xfff)
    332365            return false;
     
    335368            return false;
    336369
     370        if (fVolt[ch]==dac)
     371            return true;
     372
    337373        PostMessage(GetCmd(ch, kCmdChannelSet, dac));
    338374        AsyncRead(ba::buffer(fBuffer), kCmdChannelSet|(ch<<4));
    339375
     376        ReadChannel(ch);
     377
     378        fVolt[ch] = dac;
     379        UpdateV();
     380
    340381        return true;
    341382    }
    342383
    343     void ReadAllChannelsStatus()
    344     {
    345         Message("Requesting full system status.");
    346 
    347         // Prepare command to read all channels
    348         for (int i=0; i<kNumChannels; i++)
    349         {
    350             const vector<char> cmd = GetCmd(i, kCmdRead);
    351             PostMessage(cmd);
    352             AsyncRead(ba::buffer(fBuffer), kCmdRead|(i<<4));
    353         }
    354 
    355         //vector<char> buf;
    356         //AsyncRead(ba::buffer(buf), kCmdPrint);
     384    bool ChannelSet(uint16_t ch, double voltage)
     385    {
     386        return ChannelSetDac(ch, voltage*4096/90);
     387    }
     388
     389    void SetVoltage(int ch, int32_t dac)
     390    {
     391        if (dac<0)
     392            dac = 0;
     393
     394        if (dac>0xfff)
     395            dac = 0xfff;
     396
     397        ChannelSetDac(ch, dac);
    357398    }
    358399
     
    368409            // const double diffcur = (fRefCurrent[i]-fCurrent[i])*5000/4096
    369410            //const int32_t diffcur = int32_t(fRefCurrent[i]-fCurrent[i])*5000;
    370             const int32_t diffvolt = (fRefCurrent[i]-fCurrent[i])*5;
    371411
    372412            // Calculate voltage difference
     
    376416            // Calculate new vlaue by onverting voltage difference to DAC units
    377417            //const int32_t dac = fRefVolt[i] + diffvolt*4096/90.0;
    378             int32_t dac = fRefVolt[i] + diffvolt/90;
    379 
    380             if (dac<0)
    381                 dac = 0;
    382             if (dac>0xfff)
    383                 dac = 0xfff;
    384 
    385             if (fVolt[i] == dac)
    386                 continue;
    387 
    388             PostMessage(GetCmd(i, kCmdChannelSet, dac));
    389             AsyncRead(ba::buffer(fBuffer), kCmdChannelSet|(i<<4));
    390         }
    391     }
    392 
    393     void SystemReset()
    394     {
    395         Message("Sending system reset.");
    396         PostMessage(GetCmd(0, kCmdReset));
    397         AsyncRead(ba::buffer(fBuffer), kCmdReset);
     418            SetVoltage(i, fRefVolt[i] + (fRefCurrent[i]-fCurrent[i])/18);
     419        }
    398420    }
    399421
     
    457479    {
    458480        fDimCurrent.Update(fCurrent);
    459         ConnectionBias::UpdateA();
    460     }
    461 
    462     /*
     481    }
     482
    463483    void UpdateV()
    464484    {
    465         fDimCurrent.Update(fRefVolt);
    466     }*/
     485        fDimVoltage.Update(fVolt);
     486    }
    467487
    468488public:
    469489    ConnectionDimBias(ba::io_service& ioservice, MessageImp &imp) :
    470490        ConnectionBias(ioservice, imp),
    471         fDimCurrent("BIAS_CONTROL/CURRENT", "F:416", ""),
    472         fDimVoltage("BIAS_CONTROL/VOLTAGE", "F:416", "")
     491        fDimCurrent("BIAS_CONTROL/CURRENT", "S:416", ""),
     492        fDimVoltage("BIAS_CONTROL/VOLTAGE", "S:416", "")
    473493    {
    474494    }
     
    524544    }
    525545
     546    int SetGlobalDac(const EventImp &evt)
     547    {
     548        if (!CheckEventSize(evt.GetSize(), "SetGlobalDac", 2))
     549            return false;
     550
     551        if (!fBias.GlobalSetDac(evt.GetUShort()))
     552            T::Error("Supplied voltage out of range (0-90)");
     553
     554        return T::GetCurrentState();
     555    }
     556
    526557    int SetChannel(const EventImp &evt)
    527558    {
     
    530561
    531562        if (!fBias.ChannelSet(evt.GetUShort(), evt.Get<float>(2)))
     563            T::Error("Value out of range");
     564
     565        return T::GetCurrentState();
     566    }
     567
     568    int SetChannelDac(const EventImp &evt)
     569    {
     570        if (!CheckEventSize(evt.GetSize(), "SetChannelDac", 4))
     571            return false;
     572
     573        if (!fBias.ChannelSetDac(evt.Get<uint16_t>(), evt.Get<uint16_t>(2)))
    532574            T::Error("Value out of range");
    533575
     
    627669
    628670        AddEvent("REQUEST_STATUS", kStateConnected)
    629             (Wrapper(bind(&ConnectionBias::ReadAllChannelsStatus, &fBias)))
     671            (Wrapper(bind(&ConnectionBias::ReadAllChannels, &fBias)))
    630672            ("");
    631673
     
    634676            ("");
    635677
     678        AddEvent("SET_GLOBAL_DAC", "S:1", kStateConnected)
     679            (bind(&StateMachineBias::SetGlobalDac, this, _1))
     680            ("");
     681
    636682        AddEvent("SET_CHANNEL_VOLTAGE", "S:1;F:1", kStateConnected)
    637683            (bind(&StateMachineBias::SetChannel, this, _1))
     684            ("");
     685
     686        AddEvent("SET_CHANNEL_DAC", "S:1;S:1", kStateConnected)
     687            (bind(&StateMachineBias::SetChannelDac, this, _1))
    638688            ("");
    639689
Note: See TracChangeset for help on using the changeset viewer.