Changeset 13210 for trunk


Ignore:
Timestamp:
03/23/12 22:09:19 (13 years ago)
Author:
tbretz
Message:
Removed all the unnecessary log-messages.
File:
1 edited

Legend:

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

    r13201 r13210  
    4949class ConnectionWeather : public Connection
    5050{
    51     int      fState;
    5251    uint16_t fInterval;
    5352
    5453    bool fIsVerbose;
    5554
     55    string fSite;
     56
    5657    virtual void UpdateWeather(const Time &, const DimWeather &)
    5758    {
     
    6364
    6465    Time fLastReport;
     66    Time fLastReception;
    6567
    6668    void HandleRead(const boost::system::error_code& err, size_t bytes_received)
     
    8688        }
    8789
     90        fLastReception = Time();
     91
    8892        const string str(fArray.data(), bytes_received);
    8993        memset(fArray.data(), 0, fArray.size());
     
    180184
    181185            ostringstream msg;
    182             msg << tm << "[" << data.fStatus << "]: T="
    183                 << data.fTemp << "°C H=" << data.fHum << "% P="
    184                 << data.fPress << "hPa Td=" << data.fDew << "°C V="
    185                 << data.fWind << "km/h dir=" << data.fDir << "deg";
     186            msg << tm.GetAsStr("%H:%M:%S") << "[" << data.fStatus << "]:"
     187                << " T="    << data.fTemp  << "°C"
     188                << " H="    << data.fHum   << "%"
     189                << " P="    << data.fPress << "hPa"
     190                << " Td="   << data.fDew   << "°C"
     191                << " V="    << data.fWind  << "km/h"
     192                << " Vmax=" << data.fGusts << "km/h"
     193                << " dir="  << data.fDir   << "°";
    186194            Message(msg);
    187195
     
    208216    void PostRequest()
    209217    {
    210         const string dir = "/site/weather/weather_data.txt";
    211218        const string cmd =
    212             "GET "+dir+" HTTP/1.1\r\n"
     219            "GET "+fSite+" HTTP/1.1\r\n"
    213220            "Accept: */*\r\n"
    214221            "Content-Type: application/octet-stream\r\n"
     
    228235        PostRequest();
    229236
    230         fKeepAlive.expires_from_now(boost::posix_time::seconds(fInterval));
     237        fKeepAlive.expires_from_now(boost::posix_time::seconds(fInterval/2));
    231238        fKeepAlive.async_wait(boost::bind(&ConnectionWeather::HandleRequest,
    232239                                          this, dummy::error));
     
    279286public:
    280287    ConnectionWeather(ba::io_service& ioservice, MessageImp &imp) : Connection(ioservice, imp()),
    281         fState(-1), fIsVerbose(true), fKeepAlive(ioservice)
     288        fIsVerbose(true), fKeepAlive(ioservice)
    282289    {
    283290        SetLogStream(&imp);
     
    287294    {
    288295        fIsVerbose = b;
     296        Connection::SetVerbose(b);
    289297    }
    290298
     
    294302    }
    295303
     304    void SetSite(const string &site)
     305    {
     306        fSite = site;
     307    }
     308
    296309    int GetState() const
    297310    {
    298         if (!IsConnected())
    299             return 1;
    300         if (IsConnected() && fState<0)
     311        if (fLastReport+boost::posix_time::seconds(fInterval*2)>Time())
     312            return 3;
     313        if (fLastReception+boost::posix_time::seconds(fInterval*2)>Time())
    301314            return 2;
    302         return fState+3;
     315        return 1;
     316
    303317    }
    304318};
     
    361375        kStateDisconnected = 1,
    362376        kStateConnected,
    363         kStateOk,
     377        kStateReceiving,
    364378    };
    365379
     
    384398        return T::GetCurrentState();
    385399    }
    386 
     400/*
    387401    int Disconnect()
    388402    {
    389403        // Close all connections
    390404        fWeather.PostClose(false);
    391 
    392         /*
    393          // Now wait until all connection have been closed and
    394          // all pending handlers have been processed
    395          poll();
    396          */
    397405
    398406        return T::GetCurrentState();
     
    416424        return T::GetCurrentState();
    417425    }
    418 
     426*/
    419427    int Execute()
    420428    {
     
    444452        // State names
    445453        AddStateName(kStateDisconnected, "Disconnected",
    446                      "No connection to cosy");
     454                     "No connection with web-server recently");
    447455
    448456        AddStateName(kStateConnected, "Connected",
    449                      "Cosy connected, drive stopped");
    450 
    451         AddStateName(kStateOk, "Ok",
    452                      "Drive system not ready for movement");
     457                     "Connection to webserver can be established, but received data is not recent");
     458
     459        AddStateName(kStateReceiving, "Valid",
     460                     "Connection to webserver can be established, receint data received");
    453461
    454462        // Verbosity commands
     
    457465            ("set verbosity state"
    458466             "|verbosity[bool]:disable or enable verbosity for received data (yes/no), except dynamic data");
    459 
     467/*
    460468        // Conenction commands
    461         AddEvent("DISCONNECT", kStateConnected)
     469        AddEvent("DISCONNECT")
    462470            (bind(&StateMachineDrive::Disconnect, this))
    463471            ("disconnect from ethernet");
    464472
    465         AddEvent("RECONNECT", "O", kStateDisconnected, kStateConnected)
     473        AddEvent("RECONNECT", "O")
    466474            (bind(&StateMachineDrive::Reconnect, this, placeholders::_1))
    467475            ("(Re)connect ethernet connection to FTM, a new address can be given"
    468476             "|[host][string]:new ethernet address in the form <host:port>");
    469 
     477*/
    470478        fWeather.StartConnect();
    471479    }
     
    478486    int EvalOptions(Configuration &conf)
    479487    {
    480         SetEndpoint(conf.Get<string>("addr"));
    481 
    482488        fWeather.SetVerbose(!conf.Get<bool>("quiet"));
    483489        fWeather.SetInterval(conf.Get<uint16_t>("interval"));
    484490        fWeather.SetDebugTx(conf.Get<bool>("debug-tx"));
     491        fWeather.SetSite(conf.Get<string>("url"));
     492
     493        SetEndpoint(conf.Get<string>("addr"));
     494
    485495
    486496        return -1;
     
    505515        ("no-dim,d",  po_switch(),    "Disable dim services")
    506516        ("addr,a",  var<string>("www.magic.iac.es:80"),  "Network address of Cosy")
     517        ("url,u",  var<string>("/site/weather/weather_data.txt"),  "File name and path to load")
    507518        ("quiet,q", po_bool(true),  "Disable printing contents of all received messages (except dynamic data) in clear text.")
    508         ("interval,i", var<uint16_t>(25), "Interval between two server requests in seconds")
     519        ("interval,i", var<uint16_t>(30), "Interval between two updates on the server in seconds")
    509520        ("debug-tx", po_bool(), "Enable debugging of ethernet transmission.")
    510521        ;
Note: See TracChangeset for help on using the changeset viewer.