Changeset 14036 for trunk/FACT++/src
- Timestamp:
- 06/02/12 15:14:13 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/smartfact.cc
r14034 r14036 3 3 #include <libnova/lunar.h> 4 4 #include <libnova/rise_set.h> 5 #endif 6 7 #ifdef HAVE_SQL 8 #include <mysql++/mysql++.h> 5 9 #endif 6 10 … … 282 286 } 283 287 284 double Angle(double r, double d) 288 double Angle(double r, double d) const 285 289 { 286 290 const double theta0 = M_PI/2-d*M_PI/180; … … 303 307 304 308 return acos(arg) * 180/M_PI; 309 } 310 311 static string Color(double angle) 312 { 313 if (angle<10 || angle>150) 314 return HTML::kRed; 315 if (angle<20 || angle>140) 316 return HTML::kYellow; 317 return HTML::kGreen; 305 318 } 306 319 }; … … 326 339 327 340 Time fLastUpdate; 341 Time fLastAstroCalc; 328 342 329 343 string fPath; … … 625 639 if (!CheckDataSize(d, "Mcp:Configuration", 16, true)) 626 640 { 627 fMcpConfigurationState = 0;641 fMcpConfigurationState = DimState::kOffline; 628 642 fMcpConfigurationMaxTime = 0; 629 643 fMcpConfigurationMaxEvents = 0; … … 698 712 //const uint16_t idx = uint16_t(floor(fmod(fMagicWeatherHist[kDir].back()/22.5+360+11.25, 360)/22.5))%16; 699 713 700 Sun sun (-(17.+53./60+26.525/3600), 28.+45./60+42.462/3600);701 Moon moon(-(17.+53./60+26.525/3600), 28.+45./60+42.462/3600);702 703 714 ostringstream out; 704 715 out << d.GetJavaDate() << '\n'; 705 out << sun.color << '\t' << sun.description << '\n';716 out << fSun.color << '\t' << fSun.description << '\n'; 706 717 out << setprecision(2); 707 out << ( sun.isday?HTML::kWhite:moon.color) << '\t' << moon.description << '\n';718 out << (fSun.isday?HTML::kWhite:fMoon.color) << '\t' << fMoon.description << '\n'; 708 719 out << setprecision(3); 709 720 for (int i=0; i<6; i++) … … 716 727 out << "\t\n"; 717 728 718 fSun = sun;719 fMoon = moon;720 721 729 ofstream(fPath+"/weather.data") << out.str(); 722 723 out.str("");724 out << sun.time.JavaDate() << '\n';725 out << HTML::kWhite << '\t' << sun.fSunRiseDarkTime.GetAsStr("%H:%M") << '\n';726 out << HTML::kWhite << '\t' << sun.fSunRiseAstronomical.GetAsStr("%H:%M") << '\n';727 out << HTML::kWhite << '\t' << sun.fSunRiseCivil.GetAsStr("%H:%M") << '\n';728 out << HTML::kWhite << '\t' << sun.fSunRiseDayTime.GetAsStr("%H:%M") << '\n';729 730 out << HTML::kWhite << '\t' << sun.fSunSetDayTime.GetAsStr("%H:%M") << '\n';731 out << HTML::kWhite << '\t' << sun.fSunSetCivil.GetAsStr("%H:%M") << '\n';732 out << HTML::kWhite << '\t' << sun.fSunSetAstronomical.GetAsStr("%H:%M") << '\n';733 out << HTML::kWhite << '\t' << sun.fSunSetDarkTime.GetAsStr("%H:%M") << '\n';734 735 out << HTML::kWhite << '\t' << moon.fMoonRise.GetAsStr("%H:%M") << '\n';736 out << HTML::kWhite << '\t' << moon.fMoonTransit.GetAsStr("%H:%M") << '\n';737 out << HTML::kWhite << '\t' << moon.fMoonSet.GetAsStr("%H:%M") << '\n';738 out << HTML::kWhite << '\t';739 740 ofstream(fPath+"/astro.data") << out.str();741 730 742 731 WriteWeather(d, "temp", kTemp, -5, 35); … … 852 841 { 853 842 const double angle = moon.Angle(Ra, Dec); 854 855 string col = HTML::kGreen; 856 if (angle<20 || angle>140) 857 col = HTML::kYellow; 858 if (angle<10 || angle>150) 859 col = HTML::kRed; 860 out << col << '\t' << setprecision(3) << angle << '\n'; 843 out << Moon::Color(angle) << '\t' << setprecision(3) << angle << '\n'; 861 844 862 845 fDriveControlMoonDist = angle; … … 1661 1644 } 1662 1645 1646 void UpdateAstronomy() 1647 { 1648 Time now; 1649 1650 fSun = Sun (-(17.+53./60+26.525/3600), 28.+45./60+42.462/3600); 1651 fMoon = Moon(-(17.+53./60+26.525/3600), 28.+45./60+42.462/3600); 1652 1653 ostringstream out; 1654 out << fSun.time.JavaDate() << '\n'; 1655 out << HTML::kWhite << '\t' << fSun.fSunRiseDarkTime.GetAsStr("%H:%M") << '\n'; 1656 out << HTML::kWhite << '\t' << fSun.fSunRiseAstronomical.GetAsStr("%H:%M") << '\n'; 1657 out << HTML::kWhite << '\t' << fSun.fSunRiseCivil.GetAsStr("%H:%M") << '\n'; 1658 out << HTML::kWhite << '\t' << fSun.fSunRiseDayTime.GetAsStr("%H:%M") << '\n'; 1659 1660 out << HTML::kWhite << '\t' << fSun.fSunSetDayTime.GetAsStr("%H:%M") << '\n'; 1661 out << HTML::kWhite << '\t' << fSun.fSunSetCivil.GetAsStr("%H:%M") << '\n'; 1662 out << HTML::kWhite << '\t' << fSun.fSunSetAstronomical.GetAsStr("%H:%M") << '\n'; 1663 out << HTML::kWhite << '\t' << fSun.fSunSetDarkTime.GetAsStr("%H:%M") << '\n'; 1664 1665 out << HTML::kWhite << '\t' << fMoon.fMoonRise.GetAsStr("%H:%M") << '\n'; 1666 out << HTML::kWhite << '\t' << fMoon.fMoonTransit.GetAsStr("%H:%M") << '\n'; 1667 out << HTML::kWhite << '\t' << fMoon.fMoonSet.GetAsStr("%H:%M") << '\n'; 1668 1669 out << fMoon.color << '\t' << fMoon.description << '\n'; 1670 1671 #ifdef HAVE_SQL 1672 try 1673 { 1674 const string fDatabase = "readpo:readc0nf1g@10.0.100.21/scheduling"; 1675 1676 //static const boost::regex expr("(([[:word:].-]+)(:(.+))?@)?([[:word:].-]+)(:([[:digit:]]+))?(/([[:word:].-]+))?"); 1677 static const boost::regex expr("(([[:word:].-]+)(:(.+))?@)?([[:word:].-]+)(:([[:digit:]]+))?(/([[:word:].-]+))"); 1678 // 2: user 1679 // 4: pass 1680 // 5: server 1681 // 7: port 1682 // 9: db 1683 1684 boost::smatch what; 1685 if (!boost::regex_match(fDatabase, what, expr, boost::match_extra)) 1686 throw runtime_error("Couldn't parse '"+fDatabase+"'."); 1687 1688 if (what.size()!=10) 1689 throw runtime_error("Error parsing '"+fDatabase+"'."); 1690 1691 const string user = what[2]; 1692 const string passwd = what[4]; 1693 const string server = what[5]; 1694 const string db = what[9]; 1695 const int port = atoi(string(what[7]).c_str()); 1696 /* 1697 ostringstream out; 1698 out << "Connecting to '"; 1699 if (!user.empty()) 1700 out << user << "@"; 1701 out << server; 1702 if (port) 1703 out << ":" << port; 1704 if (!db.empty()) 1705 out << "/" << db; 1706 1707 T::Message(out); 1708 */ 1709 mysqlpp::Connection conn(db.c_str(), server.c_str(), user.c_str(), passwd.c_str(), port); 1710 1711 const mysqlpp::StoreQueryResult res = 1712 conn.query("SELECT fSourceName, fRightAscension, fDeclination FROM source").store(); 1713 1714 out << HTML::kWhite << '\t'; 1715 1716 for (vector<mysqlpp::Row>::const_iterator v=res.begin(); v<res.end(); v++) 1717 { 1718 const string name = (*v)[0].c_str(); 1719 const double ra = (*v)[1]; 1720 const double dec = (*v)[2]; 1721 1722 const int32_t angle = fMoon.Angle(ra, dec); 1723 1724 out << "<tr bgcolor='" << Moon::Color(angle) << "'>"; 1725 out << "<td>" << name << "</td>"; 1726 out << "<td>" << round(angle) << "°</td>"; 1727 out << "</tr>"; 1728 } 1729 out << '\n'; 1730 out << HTML::kWhite << '\t' << Time()-now << '\n'; 1731 } 1732 catch (const exception &e) 1733 { 1734 Warn("Source database access: "+string(e.what())); 1735 } 1736 #endif 1737 1738 ofstream(fPath+"/astro.data") << out.str(); 1739 } 1740 1663 1741 int Execute() 1664 1742 { … … 1673 1751 if (now-fLastUpdate<boost::posix_time::seconds(1)) 1674 1752 return fDimDNS.online() ? kStateRunning : kStateDimNetworkNA; 1675 1676 1753 fLastUpdate=now; 1677 1754 … … 2129 2206 ofstream(fPath+"/status.data") << out.str(); 2130 2207 2208 if (now-fLastAstroCalc>boost::posix_time::seconds(15)) 2209 { 2210 UpdateAstronomy(); 2211 fLastAstroCalc = now; 2212 } 2213 2131 2214 return fDimDNS.online() ? kStateRunning : kStateDimNetworkNA; 2132 2215 } … … 2135 2218 public: 2136 2219 StateMachineSmartFACT(ostream &out=cout) : StateMachineDim(out, "SMART_FACT"), 2220 fLastAstroCalc(boost::date_time::neg_infin), 2137 2221 fPath("www/smartfact/data"), 2138 2222 fControlScriptDepth(0),
Note:
See TracChangeset
for help on using the changeset viewer.