- Timestamp:
- 03/23/12 22:09:19 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/magicweather.cc
r13201 r13210 49 49 class ConnectionWeather : public Connection 50 50 { 51 int fState;52 51 uint16_t fInterval; 53 52 54 53 bool fIsVerbose; 55 54 55 string fSite; 56 56 57 virtual void UpdateWeather(const Time &, const DimWeather &) 57 58 { … … 63 64 64 65 Time fLastReport; 66 Time fLastReception; 65 67 66 68 void HandleRead(const boost::system::error_code& err, size_t bytes_received) … … 86 88 } 87 89 90 fLastReception = Time(); 91 88 92 const string str(fArray.data(), bytes_received); 89 93 memset(fArray.data(), 0, fArray.size()); … … 180 184 181 185 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 << "°"; 186 194 Message(msg); 187 195 … … 208 216 void PostRequest() 209 217 { 210 const string dir = "/site/weather/weather_data.txt";211 218 const string cmd = 212 "GET "+ dir+" HTTP/1.1\r\n"219 "GET "+fSite+" HTTP/1.1\r\n" 213 220 "Accept: */*\r\n" 214 221 "Content-Type: application/octet-stream\r\n" … … 228 235 PostRequest(); 229 236 230 fKeepAlive.expires_from_now(boost::posix_time::seconds(fInterval ));237 fKeepAlive.expires_from_now(boost::posix_time::seconds(fInterval/2)); 231 238 fKeepAlive.async_wait(boost::bind(&ConnectionWeather::HandleRequest, 232 239 this, dummy::error)); … … 279 286 public: 280 287 ConnectionWeather(ba::io_service& ioservice, MessageImp &imp) : Connection(ioservice, imp()), 281 f State(-1), fIsVerbose(true), fKeepAlive(ioservice)288 fIsVerbose(true), fKeepAlive(ioservice) 282 289 { 283 290 SetLogStream(&imp); … … 287 294 { 288 295 fIsVerbose = b; 296 Connection::SetVerbose(b); 289 297 } 290 298 … … 294 302 } 295 303 304 void SetSite(const string &site) 305 { 306 fSite = site; 307 } 308 296 309 int GetState() const 297 310 { 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()) 301 314 return 2; 302 return fState+3; 315 return 1; 316 303 317 } 304 318 }; … … 361 375 kStateDisconnected = 1, 362 376 kStateConnected, 363 kState Ok,377 kStateReceiving, 364 378 }; 365 379 … … 384 398 return T::GetCurrentState(); 385 399 } 386 400 /* 387 401 int Disconnect() 388 402 { 389 403 // Close all connections 390 404 fWeather.PostClose(false); 391 392 /*393 // Now wait until all connection have been closed and394 // all pending handlers have been processed395 poll();396 */397 405 398 406 return T::GetCurrentState(); … … 416 424 return T::GetCurrentState(); 417 425 } 418 426 */ 419 427 int Execute() 420 428 { … … 444 452 // State names 445 453 AddStateName(kStateDisconnected, "Disconnected", 446 "No connection to cosy");454 "No connection with web-server recently"); 447 455 448 456 AddStateName(kStateConnected, "Connected", 449 "Co sy connected, drive stopped");450 451 AddStateName(kState Ok, "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"); 453 461 454 462 // Verbosity commands … … 457 465 ("set verbosity state" 458 466 "|verbosity[bool]:disable or enable verbosity for received data (yes/no), except dynamic data"); 459 467 /* 460 468 // Conenction commands 461 AddEvent("DISCONNECT" , kStateConnected)469 AddEvent("DISCONNECT") 462 470 (bind(&StateMachineDrive::Disconnect, this)) 463 471 ("disconnect from ethernet"); 464 472 465 AddEvent("RECONNECT", "O" , kStateDisconnected, kStateConnected)473 AddEvent("RECONNECT", "O") 466 474 (bind(&StateMachineDrive::Reconnect, this, placeholders::_1)) 467 475 ("(Re)connect ethernet connection to FTM, a new address can be given" 468 476 "|[host][string]:new ethernet address in the form <host:port>"); 469 477 */ 470 478 fWeather.StartConnect(); 471 479 } … … 478 486 int EvalOptions(Configuration &conf) 479 487 { 480 SetEndpoint(conf.Get<string>("addr"));481 482 488 fWeather.SetVerbose(!conf.Get<bool>("quiet")); 483 489 fWeather.SetInterval(conf.Get<uint16_t>("interval")); 484 490 fWeather.SetDebugTx(conf.Get<bool>("debug-tx")); 491 fWeather.SetSite(conf.Get<string>("url")); 492 493 SetEndpoint(conf.Get<string>("addr")); 494 485 495 486 496 return -1; … … 505 515 ("no-dim,d", po_switch(), "Disable dim services") 506 516 ("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") 507 518 ("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 requestsin seconds")519 ("interval,i", var<uint16_t>(30), "Interval between two updates on the server in seconds") 509 520 ("debug-tx", po_bool(), "Enable debugging of ethernet transmission.") 510 521 ;
Note:
See TracChangeset
for help on using the changeset viewer.