Changeset 11931 for trunk


Ignore:
Timestamp:
09/01/11 15:24:26 (13 years ago)
Author:
tbretz
Message:
Fixed a couple of minor bugs only visible during the first real test; made things work; do not request current during ramping (the ramping procedure does this anyway.
File:
1 edited

Legend:

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

    r11927 r11931  
    145145    bool CheckMessageLength(int received, int expected, const string &msg)
    146146    {
    147         if (received!=expected)
    148             return false;
     147        if (received==expected)
     148            return true;
    149149
    150150        ostringstream str;
     
    166166        const uint16_t board  =  answer[2]&0xf;
    167167
     168        /*
     169        Out() << dec << setw(2) << board << '|' << wrap << " ";
     170        if (id%8==7)
     171            Out() << endl;
     172            */
     173
    168174        if (fWrapCounter>=0)
    169175        {
     
    171177            {
    172178                ostringstream msg;
    173                 msg << "Corrupted answer: received wrap counter " << wrap << " is not last received counter (" << fWrapCounter << "+1)%8.";
     179                msg << "Corrupted answer (id=" << id << "): received wrap counter " << wrap << " doesn't match last received counter " << fWrapCounter << ".";
    174180                Error(msg);
    175181                return false;
     
    184190            msg << hex << setfill('0');
    185191            msg << "Initial answer received:";
    186             msg << " 0x" << setw(2) << answer[0];
    187             msg << " 0x" << setw(2) << answer[1];
    188             msg << " 0x" << setw(2) << answer[2];
     192            msg << " 0x" << setw(2) << (int)answer[0];
     193            msg << " 0x" << setw(2) << (int)answer[1];
     194            msg << " 0x" << setw(2) << (int)answer[2];
    189195            Message(msg);
    190196
    191             if (status!=0 || ddd!=0 || error!=0 || board==0)
     197            if (status!=0 || ddd!=0 || error!=0 || board!=0)
     198            {
    192199                Warn("Initial answer doesn't seem to be a reset as naively expected.");
     200
     201                // FIXME:
     202                //ostringstream msg;
     203                //msg << hex << setfill('0');
     204                //msg << "S=" << status << " D=" << ddd << " E=" << error << " B=" << board;
     205                //Message(msg);
     206            }
    193207
    194208            fSendCounter = wrap;
     
    299313
    300314        // Now print the received message if requested by the user
    301         if (fIsVerbose)
    302         {
     315        if (fIsVerbose/* && command!=kUpdate*/)
     316        {
     317            Out() << endl << kBold << dec << "Data received (size=" << bytes_received << "):" << endl;
     318            Out() << " Command=" << command << " fWrapCounter=" << fWrapCounter << " fSendCounter=" << fSendCounter << " fIsInitializing=" << fIsInitializing << " fIsRamping=" << fIsRamping << endl;
     319            Out() << hex << setfill('0');
     320
    303321            vector<uint32_t> vout((bytes_received/3)*4);
    304322
     
    306324            {
    307325                vout[i] =
    308                     (uint32_t(fBuffer[i*3+0])<<16) |
     326                    (uint32_t(fBuffer[i*3+2])<<16) |
    309327                    (uint32_t(fBuffer[i*3+1])<< 8) |
    310                     (uint32_t(fBuffer[i*3+2])<< 0);
     328                    (uint32_t(fBuffer[i*3+0])<< 0);
     329
     330                Out() << setw(6) << vout[i] << " ";
     331                if (i%8==7)
     332                    Out() << endl;
    311333            }
    312334
    313             Out() << endl << kBold << "Data received (size=" << bytes_received << "):" << endl;
    314             Out() << " fWrapCounter=" << fWrapCounter << " fSendCounter=" << fSendCounter << " fIsInitializing=" << fIsInitializing << " fIsRamping=" << fIsRamping << endl;
    315             Out() << Converter::GetHex<uint32_t>(vout, 16) << endl;
     335            //Out() << Converter::GetHex<uint32_t>(vout, 16) << endl;
    316336        }
    317337
     
    336356        }
    337357
     358        // Now we are ready to send a new message
     359//        fWaitingForAnswer = false;
     360
     361        if (command==kSynchronize)
     362        {
     363            Message("Stream successfully synchronized.");
     364            fIsInitializing = false;
     365
     366            // Cancel sending of the next 0
     367            fSyncTimer.cancel();
     368
     369            // Start continous reading of all channels
     370            ScheduleUpdate(100);
     371            return;
     372        }
     373
    338374        if (send_counter%8 != fWrapCounter)
    339375        {
    340376            ostringstream msg;
    341             msg << "Corrupted answer: received wrap counter " << fWrapCounter  << " is not send counter " << fSendCounter << "%8.";
     377            msg << "Corrupted answer: received wrap counter " << fWrapCounter  << " is not send counter " << send_counter << "%8.";
    342378            Error(msg);
    343379            PostClose(false);
    344380        }
    345381
    346         // Now we are ready to send a new message
    347 //        fWaitingForAnswer = false;
    348 
    349         if (command==kSynchronize)
    350         {
    351             Message("Stream successfully synchronized.");
    352             fIsInitializing = false;
    353 
    354             // Cancel sending of the next 0
    355             fSyncTimer.cancel();
    356 
    357             // Start continous reading of all channels
    358             ScheduleUpdate(100);
    359         }
    360382
    361383        // Take action depending on what is going on
     
    367389            UpdateV();
    368390            UpdateA();
    369             return;
    370391        }
    371392
     
    395416        if (error==ba::error::basic_errors::operation_aborted)
    396417        {
    397             Warn("Synchronization aborted...");
    398             fIsRamping = false;
     418            if (fIsInitializing)
     419                Warn("Synchronization aborted...");
     420            else
     421                Info("Synchronization successfull.");
    399422            return;
    400423        }
     
    417440
    418441        ostringstream msg;
    419         msg << "Synchronization time expired (" << counter << ")" << endl;
     442        msg << "Synchronization time expired (" << counter << ")";
    420443        Info(msg);
    421444
     
    440463    void ScheduleSync(int counter=0)
    441464    {
    442         fSyncTimer.expires_from_now(boost::posix_time::milliseconds(333));
     465        fSyncTimer.expires_from_now(boost::posix_time::milliseconds(1000));
    443466        fSyncTimer.async_wait(boost::bind(&ConnectionBias::HandleSyncTimer, this, counter, dummy::error));
    444467    }
     
    453476        fIsInitializing = true;
    454477
    455         fVolt.assign(   0, kNumChannels);
    456         fVoltRef.assign(0, kNumChannels);
    457         fVoltCmd.assign(0, kNumChannels);
     478        fVolt.assign(   kNumChannels, 0);
     479        fVoltRef.assign(kNumChannels, 0);
     480        fVoltCmd.assign(kNumChannels, 0);
    458481
    459482        // Send a single 0 (and possible two consecutive 0's
    460483        // to make sure we are in sync with the device)
    461484        PostMessage("\0", 1);
    462         AsyncRead(ba::buffer(fBuffer, 3), kSynchronize, ++fSendCounter);
     485        AsyncRead(ba::buffer(fBuffer, 3), kSynchronize, 0);//++fSendCounter);
    463486//        fWaitingForAnswer = true;
    464487
     
    489512
    490513        if (is_open())
    491             ReadAllChannels(true);
     514        {
     515            if (fIsRamping)
     516            {
     517                Info("Schedule of update timer skipped.");
     518                ScheduleUpdate(fUpdateTime);
     519            }
     520            else
     521                ReadAllChannels(true);
     522        }
    492523    }
    493524
     
    540571        {
    541572            dac[ch] = RampOneStep(ch);
    542             if (dac[ch]!=fVolt[ch])
     573            if (dac[ch]!=fVolt[ch] && fPresent[ch/kNumChannelsPerBoard])
    543574                identical = false;
    544575        }
     
    583614        }
    584615
     616        // Check whether the deadline has passed. We compare the deadline
     617        // against the current time since a new asynchronous operation
     618        // may have moved the deadline before this actor had a chance
     619        // to run.
     620        if (fRampTimer.expires_at() > ba::deadline_timer::traits_type::now())
     621            return;
     622
    585623        fIsRamping = RampOneStep();
    586624    }
     
    588626    void ScheduleRampStep()
    589627    {
     628        Message("Schedule ramping");
    590629        fRampTimer.expires_from_now(boost::posix_time::milliseconds(fRampTime));
    591630        fRampTimer.async_wait(boost::bind(&ConnectionBias::HandleRampTimer, this, dummy::error));
     
    598637        fUpdateTimer(ioservice),
    599638        fBuffer(3*kNumChannels),
    600         fIsVerbose(true),
     639        fIsVerbose(false),
    601640        fVoltCmd(kNumChannels),
    602641        fVoltGapd(kNumChannels),
     
    752791
    753792        fIsRamping = RampOneStep();
     793
     794        ostringstream msg;
     795        msg << "Ramp=" << fIsRamping;
     796        Message(msg);
    754797    }
    755798
     
    828871    bool ExpertGlobalSetVolt(float volt)
    829872    {
    830         return GlobalSetDac(volt*4096/90);
     873        return ExpertGlobalSetDac(volt*4096/90);
    831874    }
    832875
     
    12141257        T::AddEvent("REQUEST_STATUS", ConnectionBias::kConnected, ConnectionBias::kRamping)
    12151258            (Wrapper(bind(&ConnectionBias::ReadAllChannels, &fBias, false)))
    1216             ("");
     1259            ("Asynchronously request the status (current) of all channels.");
    12171260
    12181261        T::AddEvent("RESET_OVER_CURRENT_STATUS", ConnectionBias::kConnected)
    12191262            (Wrapper(bind(&ConnectionBias::OverCurrentReset, &fBias)))
    1220             ("");
     1263            ("NOT YET TESTED");
    12211264
    12221265
     
    12241267        T::AddEvent("SET_GLOBAL_VOLTAGE", "F:1", ConnectionBias::kConnected, ConnectionBias::kRamping)
    12251268            (bind(&StateMachineBias::SetGlobalVolt, this, placeholders::_1))
    1226             ("");
     1269            ("Set all channels to a new reference voltage. Starts ramping if necessary. (This command is not realized with the GLOBAL SET command.)");
    12271270
    12281271        T::AddEvent("SET_GLOBAL_DAC", "S:1", ConnectionBias::kConnected, ConnectionBias::kRamping)
    12291272            (bind(&StateMachineBias::SetGlobalDac, this, placeholders::_1))
    1230             ("");
     1273            ("Set all channels to a new DAC reference. Starts ramping if necessary. (This command is not realized with the GLOBAL SET command.)");
    12311274
    12321275        T::AddEvent("SET_CHANNEL_VOLTAGE", "S:1;F:1", ConnectionBias::kConnected, ConnectionBias::kRamping)
    12331276            (bind(&StateMachineBias::SetChannelVolt, this, placeholders::_1))
    1234             ("");
     1277            ("Set a single channel a new reference voltage. Starts ramping if necessary.");
    12351278
    12361279        T::AddEvent("SET_CHANNEL_DAC", "S:1;S:1", ConnectionBias::kConnected, ConnectionBias::kRamping)
    12371280            (bind(&StateMachineBias::SetChannelDac, this, placeholders::_1))
    1238             ("");
     1281            ("Set a single channel a new DAC reference value. Starts ramping if necessary.");
    12391282
    12401283        T::AddEvent("SET_GAPD_REFERENCE_VOLTAGE", ConnectionBias::kConnected, ConnectionBias::kRamping)
    12411284            (Wrapper(bind(&ConnectionBias::SetGapdVoltage, &fBias)))
    1242             ("");
     1285            ("Set all channels to their G-APD reference voltage. Starts ramping if necessary.");
    12431286
    12441287        T::AddEvent("SET_ZERO_VOLTAGE", ConnectionBias::kConnected, ConnectionBias::kRamping)
    12451288            (Wrapper(bind(&ConnectionBias::SetZero, &fBias)))
    1246             ("");
     1289            ("Set all channels to a zero reference voltage. Starts ramping if necessary.");
    12471290
    12481291
     
    12581301
    12591302
    1260         T::AddEvent("PRINT", ConnectionBias::kConnected, ConnectionBias::kRamping)
     1303        T::AddEvent("PRINT", ConnectionBias::kConnected, ConnectionBias::kExpertMode, ConnectionBias::kRamping)
    12611304            (Wrapper(bind(&ConnectionBias::Print, &fBias)))
    12621305            ("");
     
    12651308        T::AddEvent("EXPERT_MODE", "B:1")
    12661309            (bind(&StateMachineBias::SetExpertMode, this, placeholders::_1))
    1267             ("");
     1310            ("Enable usage of expert commands (note that for safty reasons the are exclusive with the standard commands)");
    12681311
    12691312        T::AddEvent("EXPERT_RESET", ConnectionBias::kExpertMode)
    12701313            (Wrapper(bind(&ConnectionBias::ExpertReset, &fBias)))
    1271             ("");
     1314            ("Send the RESET command (note that this is possibly harmfull command)");
    12721315
    12731316        T::AddEvent("EXPERT_SET_GLOBAL_VOLTAGE", "F:1", ConnectionBias::kExpertMode)
    12741317            (bind(&StateMachineBias::ExpertSetGlobalVolt, this, placeholders::_1))
    1275             ("");
     1318            ("Send the global set command. The given voltage is converted to DAC counts.");
    12761319
    12771320        T::AddEvent("EXPERT_SET_GLOBAL_DAC", "S:1", ConnectionBias::kExpertMode)
    12781321            (bind(&StateMachineBias::ExpertSetGlobalDac, this, placeholders::_1))
    1279             ("");
     1322            ("Send the global set command.");
    12801323
    12811324        T::AddEvent("EXPERT_SET_CHANNEL_VOLTAGE", "S:1;F:1", ConnectionBias::kExpertMode)
    12821325            (bind(&StateMachineBias::ExpertSetChannelVolt, this, placeholders::_1))
    1283             ("");
     1326            ("Send a single channel set command. The given voltage is converted to DAC commands.");
    12841327
    12851328        T::AddEvent("EXPERT_SET_CHANNEL_DAC", "S:1;S:1", ConnectionBias::kExpertMode)
    12861329            (bind(&StateMachineBias::ExpertSetChannelDac, this, placeholders::_1))
    1287             ("");
    1288     }
     1330            ("Send a single channel set command.");
     1331    }
     1332
     1333    ~StateMachineBias() { T::Warn("Implement rampming at shutdown!"); }
    12891334
    12901335    int EvalOptions(Configuration &conf)
     
    13901435        ("ramp-time",     var<uint16_t>(),  "")
    13911436        ("ramp-step",     var<uint16_t>(),  "")
    1392         ("ramp-volt",     var<float>(),     "")
    13931437        ;
    13941438
Note: See TracChangeset for help on using the changeset viewer.