Changeset 14324 for trunk/FACT++/src


Ignore:
Timestamp:
08/07/12 22:22:33 (12 years ago)
Author:
neise
Message:
added AntiFloddingTimer
File:
1 edited

Legend:

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

    r14317 r14324  
    6060   
    6161    boost::asio::deadline_timer fCheckStatusTimer;
     62    boost::asio::deadline_timer fAntiFloddingTimer;
    6263
    6364    void PostStatusRequest()
     
    111112
    112113    int  fLineCounter;
     114
     115    void Start_async_read_until()
     116    {
     117        // Bind Received Data Handler to the event: "received <enter> character"
     118        //   this Handler will try to parse the incoming data
     119        ba::async_read_until(*this, fBuffer, "\n",
     120                             boost::bind(&ConnectionAgilent::ReceivedStatusHandler, this,
     121                                         bapla::error, bapla::bytes_transferred, 0));
     122
     123        // FIXME: Add timeout here
     124    }
    113125
    114126    void ReceivedStatusHandler(const bs::error_code& err, size_t bytes_received, int /*type*/)
     
    136148
    137149        if (fIsVerbose)
     150        {
    138151           Out() << kBold << "Received (" << bytes_received << " bytes):" << endl;
     152        }
     153        // FIXME: the piece of code below causes a Seg Fault in case
     154        // The Agilent is not listening during program start, then after a while is
     155        // listening and after connection established.
     156        // It sends: 1.) a string and 2.) and empty line (just an <Enter> pressed)
     157        //
     158        // then the agilent_ctrl segfaults ... was able to reproduce it.
     159        // gdp just gave me the hint, that Time().GetAdStr() caused the Seg Fault in a way...
     160        // Is Time threadsafe?
    139161        /*
    140162        if (fDump)
     
    144166            Dump(msg.str());
    145167        }
    146 */
     168        */
     169
     170
    147171        istream is(&fBuffer);
    148         // data should contain two floats:
    149         //  * measured output voltage in volts
    150         //  * measured ouput current in amperes
    151         vector<float> data;
    152 
    153172        fLineCounter++;
    154173
     
    157176            // this is the Agilent identity string, do nothing
    158177            string s;
    159             is >> s;
     178            getline(s,buffer, '\n');
    160179            Out() << "ID string: " << s << endl;
    161180        }
     
    164183            // this should be a float containing the measured voltage
    165184            is >> fMeasuredVoltage;
    166             data.push_back(fMeasuredVoltage);
    167185            Out() << "voltage: " << fMeasuredVoltage << endl;
    168186        }
     
    171189            // this should be a float containing the measured voltage
    172190            is >> fMeasuredCurrent;
    173             data.push_back(fMeasuredCurrent);
    174191            Out() << "current: " << fMeasuredCurrent << endl;
    175192            fLineCounter = 0;
     193
     194            // data should contain two floats:
     195            //  * measured output voltage in volts
     196            //  * measured ouput current in amperes
     197            vector<float> data(2);
     198            data[0] = fMeasuredVoltage;
     199            data[1] = fMeasuredCurrent;
     200            UpdateDim(data);
    176201        }
    177202       
     
    195220            fState = State::kVoltage_Off;
    196221        }
    197 
    198         UpdateDim(data);
    199        
    200222        Start_async_read_until();
    201223    }
    202224
    203     void Start_async_read_until()
    204     {
    205         // Bind Received Data Handler to the event: "received <enter> character"
    206         //   this Handler will try to parse the incoming data
    207         ba::async_read_until(*this, fBuffer, "\n",
    208                              boost::bind(&ConnectionAgilent::ReceivedStatusHandler, this,
    209                                          bapla::error, bapla::bytes_transferred, 0));
    210 
    211         // FIXME: Add timeout here
    212     }
    213225
    214226    // This is called when a connection was established
    215227    void ConnectionEstablished()
    216228    {
     229        // DN 07.08.2012: The next line is imho not needed.
     230        // But I'm in a train and cannot test it.
    217231        fState = State::kConnected;
    218232        Start_async_read_until();
     
    228242        fIsVerbose(true),
    229243        fDump(true),
    230         fCheckStatusTimer(ioservice)
     244        fCheckStatusTimer(ioservice),
     245        fAntiFloddingTimer(ioservice)
    231246    {
    232247        SetLogStream(&imp);
     
    250265        if (b)
    251266        {
    252             PostMessage(string("outp on\n"));
     267            // check if the previous 'outp off' is some time ago
     268            if (fAntiFloddingTimer.expires_at() > ba::deadline_timer::traits_type::now())
     269            {
     270                PostMessage(string("outp on\n"));
     271            }
    253272        }
    254273        else
    255274        {
    256275            PostMessage(string("outp off\n"));
    257         }
    258         RequestStatus();
     276            // start a Timer, which runs out in 60sec making sure, that the
     277            // camera can't be switched off&on on short time scales.
     278            // sending repetetive outp off is possible
     279            // sending repetivitve outp on is also posible
     280            // switching off immediately after switching on is also possible.
     281            fAntiFloddingTimer.expires_from_now(boost::posix_time::seconds(60));
     282        }
     283        RequestStatus();
    259284    }
    260285   
    261286    int GetState() const
    262287    {
     288        // fState is set in ReceivedStatusHandler
    263289        return fState;
    264290    }
     
    500526{
    501527    cout <<
    502         "The ftmctrl controls the FSC (FACT Slow Control) board.\n"
     528        "The agilentctrl controls the FACT camera power supply.\n"
     529        "The powersupply is made by Agilent, so we call it 'The Agilent'. \n"
     530        "Since FACT uses three Agilent Power Supplies with different output voltages\n"
     531        "one might still not now which one ist controlled by this Program, so:\n"
    503532        "\n"
    504         "The default is that the program is started without user intercation. "
     533        "This program controls the 48V Agilent."
     534        "\n"
     535        "The default is that the program is started with user intercation. "
    505536        "All actions are supposed to arrive as DimCommands. Using the -c "
    506537        "option, a local shell can be initialized. With h or help a short "
    507538        "help message about the usuage can be brought to the screen.\n"
    508539        "\n"
    509         "Usage: fscctrl [-c type] [OPTIONS]\n"
    510         "  or:  fscctrl [OPTIONS]\n";
     540        "Usage: agilentctrl [-c type] [OPTIONS]\n"
     541        "  or:  agilentctrl [OPTIONS]\n";
    511542    cout << endl;
    512543}
     
    515546{
    516547    Main::PrintHelp<StateMachineAgilent<StateMachine, ConnectionAgilent>>();
    517 
    518     /* Additional help text which is printed after the configuration
    519      options goes here */
    520 
    521     /*
    522      cout << "bla bla bla" << endl << endl;
    523      cout << endl;
    524      cout << "Environment:" << endl;
    525      cout << "environment" << endl;
    526      cout << endl;
    527      cout << "Examples:" << endl;
    528      cout << "test exam" << endl;
    529      cout << endl;
    530      cout << "Files:" << endl;
    531      cout << "files" << endl;
    532      cout << endl;
    533      */
    534548}
    535549
Note: See TracChangeset for help on using the changeset viewer.