68 if (bytes_received==0 || err)
70 if (err==ba::error::eof)
71 Warn(
"Connection closed by remote host.");
75 if (err && err!=ba::error::eof &&
76 err!=ba::error::basic_errors::not_connected &&
77 err!=ba::error::basic_errors::operation_aborted)
80 str <<
"Reading from " << URL() <<
": " << err.message() <<
" (" << err <<
")";
83 PostClose(err!=ba::error::basic_errors::operation_aborted);
92 if (end==string::npos)
94 Out() <<
"Received data corrupted [1]." << endl;
100 data.erase(0, end+4);
105 const size_t chunk =
data.find(
"\r\n", pos);
106 if (chunk==0 || chunk==string::npos)
113 stringstream val(
data.substr(pos, chunk-pos));
116 data.erase(pos, chunk-pos+2);
130 Out() <<
"------------------------------------------------------" << endl;
131 Out() <<
data << endl;
132 Out() <<
"------------------------------------------------------" << endl;
136 if (!doc.setContent(QString(
data.data()),
false))
138 Warn(
"Parsing of xml failed [0].");
144 Out() <<
"Parsed:\n-------\n" << doc.toString().toStdString() << endl;
146 const QDomElement root = doc.documentElement();
147 const QDomElement channel = root.firstChildElement(
"channel");
148 const QDomElement
item = channel.firstChildElement(
"item");
150 const QDomElement see = item.firstChildElement(
"tngw:dimmSeeing");
151 const QDomElement mjd = item.firstChildElement(
"tngw:dimmSeeing.date");
152 const QDomElement med = item.firstChildElement(
"tngw:dimmSeeing.median");
153 const QDomElement sdev = item.firstChildElement(
"tngw:dimmSeeing.stdev");
154 const QDomElement dust = item.firstChildElement(
"tngw:dustTotal");
155 const QDomElement trend = item.firstChildElement(
"tngw:trend");
156 const QDomElement pres = item.firstChildElement(
"tngw:airPressure");
157 const QDomElement dew = item.firstChildElement(
"tngw:dewPoint");
158 const QDomElement wdir = item.firstChildElement(
"tngw:windDirection");
159 const QDomElement speed = item.firstChildElement(
"tngw:windSpeed");
160 const QDomElement
hum = item.firstChildElement(
"tngw:hum");
161 const QDomElement tmp = item.firstChildElement(
"tngw:temperature");
162 const QDomElement solar = item.firstChildElement(
"tngw:solarimeter");
163 const QDomElement date = item.firstChildElement(
"tngw:date");
165 if (see.isNull() || mjd.isNull() || med.isNull() || sdev.isNull() ||
166 dust.isNull() || trend.isNull() || pres.isNull() || dew.isNull() ||
167 wdir.isNull() || speed.isNull() || hum.isNull() || tmp.isNull() ||
168 solar.isNull()|| date.isNull())
170 Warn(
"Parsing of xml failed [1].");
187 s.
fSeeing = see .text().toFloat();
191 const string dateObj = date.text().toStdString();
192 const string dateSee = mjd .text().toStdString();
194 Time timeObj(dateObj);
195 Time timeSee(dateSee);
196 if (!timeObj.IsValid())
200 vector<char> buf(255);
201 if (strptime(dateObj.c_str(),
"%c", &tm))
202 timeObj =
Time(tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
203 tm.tm_hour, tm.tm_min, tm.tm_sec);
206 if (!timeSee.IsValid())
210 vector<char> buf(255);
211 if (strptime(dateSee.c_str(),
"%c", &tm))
212 timeSee =
Time(tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
213 tm.tm_hour, tm.tm_min, tm.tm_sec);
215 Warn(
"Seeing time invalid ["+dateObj+
"]");
218 if (!timeObj.IsValid())
219 throw runtime_error(
"object time invalid");
224 Out() <<
"Date: " << timeObj << endl;
225 Out() <<
"DustTotal: " << w.
fDustTotal <<
" ugr/m^2" << endl;
226 Out() <<
"AirPressure: " << w.
fAirPressure <<
" mbar" << endl;
227 Out() <<
"DewPoint: " << w.
fDewPoint <<
" deg C" << endl;
229 Out() <<
"WindSpeed: " << w.
fWindSpeed <<
" m/s" << endl;
230 Out() <<
"Humidity: " << w.
fHumidity <<
"%" << endl;
231 Out() <<
"Temperature: " << w.
fTemperature <<
" deg C" << endl;
232 Out() <<
"TempTrend 24h: " << w.
fTempTrend <<
" deg C" << endl;
233 Out() <<
"Solarimeter: " << w.
fSolarimeter <<
" W/m^2" << endl;
235 Out() <<
"Seeing: " << s.
fSeeing <<
" arcsec [" << timeSee <<
"]" << endl;
257 out << setprecision(3) <<
"Dust: " <<
fDust <<
"ug/m^3 [" << timeObj <<
"]";
Adds some functionality to boost::posix_time::ptime for our needs.
virtual void UpdateSeeing(const Time &, const DimSeeing &)
virtual void UpdateWeather(const Time &, const DimWeather &)
virtual void UpdateDust(const Time &, const float &)
boost::array< char, 4096 > fArray