Changeset 10606 for trunk


Ignore:
Timestamp:
05/06/11 09:52:22 (13 years ago)
Author:
tbretz
Message:
Added support for boost 1.42 even with gcc 4.5; added many new commands; added FTM_COUNTROL/COUNTER
File:
1 edited

Legend:

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

    r10587 r10606  
    11#include <boost/bind.hpp>
    22#include <boost/array.hpp>
     3#if BOOST_VERSION<1440
     4#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 4))
     5#undef BOOST_HAS_RVALUE_REFS
     6#error test
     7#endif
     8#endif
    39#include <boost/thread.hpp>
    410#include <boost/asio/error.hpp>
     
    1824#include "LocalControl.h"
    1925#include "HeadersFTM.h"
     26
    2027
    2128namespace ba = boost::asio;
     
    6168    // ...
    6269
     70protected:
    6371    map<uint16_t, int> fCounter;
    6472
    65 protected:
    6673    FTM::Header      fHeader;
    6774    FTM::FtuList     fFtuList;
     
    138145    }
    139146
     147    virtual void UpdateCounter()
     148    {
     149        if (!fIsVerbose)
     150            return;
     151
     152        if (!fIsDynamicOut)
     153            return;
     154
     155        Out() << "Received: ";
     156        Out() << "H=" << fCounter[kHeader] << "  ";
     157        Out() << "S=" << fCounter[kStaticData] << "  ";
     158        Out() << "D=" << fCounter[kDynamicData] << "  ";
     159        Out() << "F=" << fCounter[kFtuList] << "  ";
     160        Out() << "E=" << fCounter[kError] << "  ";
     161        Out() << "R=" << fCounter[kRegister] << endl;
     162    }
     163
    140164private:
    141165    void HandleReceivedData(const bs::error_code& err, size_t bytes_received, int /*type*/)
    142166    {
     167        cout << "Data received " << err << " " << bytes_received << endl;
     168
    143169        // Do not schedule a new read if the connection failed.
    144170        if (bytes_received==0 || err)
     
    205231                UpdateFirstHeader();
    206232
     233            UpdateCounter();
    207234            UpdateHeader();
    208235
     
    254281
    255282            fCounter[fHeader.fType]++;
     283            UpdateCounter();
     284
     285            cout << "TYPE=" << fHeader.fType << endl;
    256286
    257287            switch (fHeader.fType)
     
    263293
    264294            case kStaticData:
     295                cout << fBuffer.size() << " " << sizeof(fStaticData) << endl;
    265296                fStaticData = fBuffer;
    266297                UpdateStaticData();
    267             break;
     298                break;
    268299
    269300            case kDynamicData:
     
    416447public:
    417448    ConnectionFTM(ba::io_service& ioservice, MessageImp &imp) : Connection(ioservice, imp()),
    418         fIsVerbose(true), fIsDynamicOut(false), fIsHexOutput(false)
     449        fIsVerbose(true), fIsDynamicOut(true), fIsHexOutput(true)
    419450    {
    420451        SetLogStream(&imp);
     
    512543    }
    513544
     545    void SetHexOutput(bool b)
     546    {
     547        fIsHexOutput = b;
     548    }
     549
     550    void SetDynamicOut(bool b)
     551    {
     552        fIsDynamicOut = b;
     553    }
     554
    514555    bool LoadStaticData(string name)
    515556    {
     
    536577        fStaticData = data;
    537578
    538         CmdSendStatDat();
     579        for (int i=0; i<100; i++)
     580            CmdSendStatDat();
    539581
    540582        return true;
     
    557599    bool SetThreshold(int32_t patch, int32_t value)
    558600    {
    559 
    560601        if (patch>159)
    561602            return false;
     
    566607        if (patch<0)
    567608        {
     609            bool ident = true;
     610            for (int i=0; i<160; i++)
     611                if (fStaticData[i/4].fDAC[patch%4] != value)
     612                {
     613                    ident = false;
     614                    break;
     615                }
     616
     617            if (ident)
     618                return;
     619
    568620            for (int i=0; i<160; i++)
    569621                fStaticData[i/4].fDAC[i%4] = value;
    570622        }
    571623        else
     624        {
     625            if (fStaticData[patch/4].fDAC[patch%4] == value)
     626                return true;
     627
    572628            fStaticData[patch/4].fDAC[patch%4] = value;
     629        }
     630
     631        // Maybe move to a "COMMIT" command?
     632        CmdSendStatDat();
     633
     634        return true;
     635    }
     636
     637    bool SetPrescaling(uint16_t value)
     638    {
     639        if (value>0xffff)
     640            return false;
     641
     642
     643        bool ident = true;
     644        for (int i=0; i<40; i++)
     645            if (fStaticData[i].fPrescaling != value)
     646            {
     647                ident = false;
     648                break;
     649            }
     650
     651        if (ident)
     652            return true;
     653
     654        for (int i=0; i<40; i++)
     655            fStaticData[i].fPrescaling = value;
    573656
    574657        // Maybe move to a "COMMIT" command?
     
    672755    DimDescribedService fDimStaticData;
    673756    DimDescribedService fDimDynamicData;
     757    DimDescribedService fDimCounter;
    674758
    675759    template<class T>
     
    681765    }
    682766
    683     virtual void UpdateFirstHeader()
     767    void UpdateFirstHeader()
    684768    {
    685769        ConnectionFTM::UpdateFirstHeader();
     
    689773    }
    690774
    691     virtual void UpdateHeader()
     775    void UpdateHeader()
    692776    {
    693777        ConnectionFTM::UpdateHeader();
     
    697781    }
    698782
    699     virtual void UpdateFtuList()
     783    void UpdateFtuList()
    700784    {
    701785        ConnectionFTM::UpdateFtuList();
     
    705789    }
    706790
    707     virtual void UpdateStaticData()
     791    void UpdateStaticData()
    708792    {
    709793        ConnectionFTM::UpdateStaticData();
     
    713797    }
    714798
    715     virtual void UpdateDynamicData()
     799    void UpdateDynamicData()
    716800    {
    717801        ConnectionFTM::UpdateDynamicData();
     
    721805    }
    722806
    723     virtual void UpdateError()
     807    void UpdateError()
    724808    {
    725809        ConnectionFTM::UpdateError();
     
    727811        const DimError data(fHeader, fError);
    728812        Update(fDimError, data);
     813    }
     814
     815    void UpdateCounter()
     816    {
     817        ConnectionFTM::UpdateCounter();
     818
     819        const uint32_t counter[6] =
     820        {
     821            fCounter[kHeader],
     822            fCounter[kStaticData],
     823            fCounter[kDynamicData],
     824            fCounter[kFtuList],
     825            fCounter[kError],
     826            fCounter[kRegister],
     827        };
     828
     829        Update(fDimCounter, counter);
    729830    }
    730831
     
    737838        fDimFtuList       ("FTM_CONTROL/FTU_LIST",        "X:1;X:1;S:1;C:4;X:40;C:40;C:40", NULL, 0, ""),
    738839        fDimStaticData    ("FTM_CONTROL/STATIC_DATA",     "X:1;S:1;S:1;X:1;S:1;S:3;S:1;S:1;S:1;S:1;S:1;S:1;I:1;S:8;S:80;S:160;S:40;S:40", NULL, 0, ""),
    739         fDimDynamicData   ("FTM_CONTROL/DYNAMIC_DATA",    "X:1;X:1;F:4;I:160;I:40;S:40;S:40", NULL, 0, "")
     840        fDimDynamicData   ("FTM_CONTROL/DYNAMIC_DATA",    "X:1;X:1;F:4;I:160;I:40;S:40;S:40", NULL, 0, ""),
     841        fDimCounter       ("FTM_CONTROL/COUNTER",         "I:6",          NULL, 0, "")
    740842    {
    741843    }
     
    867969    }
    868970
     971    int SetHexOutput(const EventImp &evt)
     972    {
     973        if (!CheckEventSize(evt.GetSize(), "SetHexOutput", 1))
     974            return T::kSM_FatalError;
     975
     976        fFTM.SetHexOutput(evt.GetText()[0]!=0);
     977
     978        return T::GetCurrentState();
     979    }
     980
     981    int SetDynamicOut(const EventImp &evt)
     982    {
     983        if (!CheckEventSize(evt.GetSize(), "SetDynamicOut", 1))
     984            return T::kSM_FatalError;
     985
     986        fFTM.SetDynamicOut(evt.GetText()[0]!=0);
     987
     988        return T::GetCurrentState();
     989    }
     990
    869991    int LoadStaticData(const EventImp &evt)
    870992    {
     
    9661088        if (!fFTM.SetTimeMarkerDelay(evt.GetInt()))
    9671089            T::Warn("SetTimeMarkerDelay -  Value out of range.");
     1090
     1091        return T::GetCurrentState();
     1092    }
     1093
     1094    int SetPrescaling(const EventImp &evt)
     1095    {
     1096        if (!CheckEventSize(evt.GetSize(), "SetPrescaling", 4))
     1097            return T::kSM_FatalError;
     1098
     1099        if (!fFTM.SetPrescaling(evt.GetInt()))
     1100            T::Warn("SetPrescaling -  Value out of range.");
    9681101
    9691102        return T::GetCurrentState();
     
    11131246             "|Threshold[counts]:Threshold to be set in binary counts");
    11141247
     1248        AddConfiguration("SET_PRESCALING", "I:1", kStateIdle)
     1249            (boost::bind(&StateMachineFTM::SetPrescaling, this, _1))
     1250            (""
     1251             "|[]:");
     1252
    11151253        AddConfiguration("ENABLE_FTU", "I:1;B:1", kStateIdle)
    11161254            (boost::bind(&StateMachineFTM::EnableFTU, this, _1))
     
    11441282             "|[]:");
    11451283
     1284
     1285
     1286        // Load/save static data block
     1287        T::AddConfiguration("SAVE", "C", kStateIdle)
     1288            (boost::bind(&StateMachineFTM::SaveStaticData, this, _1))
     1289            ("Saves the static data (FTM configuration) from memory to a file"
     1290             "|filename[string]:Filename (can include a path), .bin is automatically added");
     1291
     1292        T::AddConfiguration("LOAD", "C", kStateIdle)
     1293            (boost::bind(&StateMachineFTM::LoadStaticData, this, _1))
     1294            ("Loads the static data (FTM configuration) from a file into memory and sends it to the FTM"
     1295             "|filename[string]:Filename (can include a path), .bin is automatically added");
     1296
     1297
     1298
     1299        // Verbosity commands
    11461300        T::AddConfiguration("SET_VERBOSE", "B")
    11471301            (boost::bind(&StateMachineFTM::SetVerbosity, this, _1))
     
    11491303             "|verbosity[bool]:disable or enable verbosity for received data (yes/no)");
    11501304
    1151         T::AddConfiguration("SAVE", "C", kStateIdle)
    1152             (boost::bind(&StateMachineFTM::SaveStaticData, this, _1))
    1153             ("Saves the static data (FTM configuration) from memory to a file"
    1154              "|filename[string]:Filename (can include a path), .bin is automatically added");
    1155 
    1156         T::AddConfiguration("LOAD", "C", kStateIdle)
    1157             (boost::bind(&StateMachineFTM::LoadStaticData, this, _1))
    1158             ("Loads the static data (FTM configuration) from a file into memory and sends it to the FTM"
    1159              "|filename[string]:Filename (can include a path), .bin is automatically added");
     1305        T::AddConfiguration("SET_HEX_OUTPUT", "B")
     1306            (boost::bind(&StateMachineFTM::SetHexOutput, this, _1))
     1307            ("enable or disable hex output for received data"
     1308             "|hexout[bool]:disable or enable hex output for verbose and received data (yes/no)");
     1309
     1310        T::AddConfiguration("SET_DYNAMIC_OUTPUT", "B")
     1311            (boost::bind(&StateMachineFTM::SetDynamicOut, this, _1))
     1312            ("enable or disable output for received dynamic data (data is still broadcasted via Dim)"
     1313             "|dynout[bool]:disable or enable output for dynamic data (yes/no)");
     1314
    11601315
    11611316        // Conenction commands
     
    13891544        << endl;
    13901545}
     1546/*
     1547string GetLocalIp()
     1548{
     1549    const char *kDnsIp = getenv("DIM_DNS_NODE");
     1550
     1551    struct addrinfo hints, *servinfo, *p;
     1552
     1553    memset(&hints, 0, sizeof hints);
     1554    hints.ai_family   = AF_INET; //AF_UNSPEC; // use AF_INET6 to force IPv6
     1555    hints.ai_socktype = SOCK_STREAM;
     1556
     1557    int rv;
     1558    if ((rv = getaddrinfo(kDnsIp, NULL, &hints, &servinfo)) != 0)
     1559    {
     1560        cout << "WARNING - getaddrinfo: " << gai_strerror(rv) << endl;
     1561        return kDnsIp;
     1562    }
     1563
     1564    // loop through all the results and connect to the first we can
     1565    for (p=servinfo; p; p=p->ai_next)
     1566    {
     1567        const int sock = socket(AF_INET, SOCK_DGRAM, 0);
     1568        if (sock==-1)
     1569            continue;
     1570
     1571        if (connect(sock, p->ai_addr, p->ai_addrlen)==-1)
     1572        {
     1573            cout << "WARNING - connect: " << strerror(errno) << endl;
     1574            close(sock);
     1575            continue;
     1576        }
     1577
     1578        sockaddr_in name;
     1579        socklen_t namelen = sizeof(name);
     1580        if (getsockname(sock, (sockaddr*)&name, &namelen)==-1)
     1581        {
     1582            cout << "WARNING - getsockname: " << strerror(errno) << endl;
     1583            close(sock);
     1584            continue;
     1585        }
     1586
     1587        char buffer[16];
     1588        if (!inet_ntop(AF_INET, &name.sin_addr, buffer, 16))
     1589        {
     1590            cout << "WARNING - inet_ntop: " << strerror(errno) << endl;
     1591            close(sock);
     1592            continue;
     1593        }
     1594
     1595        close(sock);
     1596
     1597        freeaddrinfo(servinfo); // all done with this structure
     1598
     1599        cout << "DIM_HOST_NODE=" << buffer << endl;
     1600        return buffer;
     1601    }
     1602
     1603    freeaddrinfo(servinfo); // all done with this structure
     1604    return kDnsIp;
     1605}
     1606*/
    13911607
    13921608int main(int argc, const char* argv[])
     
    14341650    // To allow overwriting of DIM_DNS_NODE set 0 to 1
    14351651    setenv("DIM_DNS_NODE", conf.Get<string>("dns").c_str(), 1);
     1652    //setenv("DIM_HOST_NODE", GetLocalIp().c_str(), 1);
    14361653
    14371654    //try
Note: See TracChangeset for help on using the changeset viewer.