- Timestamp:
- 03/23/12 11:06:06 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/magicweather.cc
r13191 r13192 1 1 #include <boost/bind.hpp> 2 3 #include <string> // std::string 4 #include <algorithm> // std::transform 5 #include <cctype> // std::tolower 2 6 3 7 #include "FACT.h" … … 82 86 } 83 87 84 PostClose(false);85 86 88 const string str(fArray.data(), bytes_received); 87 89 memset(fArray.data(), 0, fArray.size()); … … 95 97 96 98 int hh=0, mm=0, ss=0, y=0, m=0, d=0; 99 100 bool keepalive = false; 97 101 98 102 stringstream is(str); … … 108 112 if (isheader) 109 113 { 110 /* 111 if (line.substr(0, 16)=="Content-Length: ") 112 { 113 fSize = atoi(line.substr(16).data()); 114 cout << "Size==" << fSize << endl; 115 } 116 117 if (line.substr(0, 15)=="Last-Modified: ") 118 cout << "Last==" << line.substr(15).data() << endl; 119 */ 114 const size_t p = line.find_first_of(": "); 115 if (p==string::npos) 116 continue; 117 118 std::transform(line.begin(), line.end(), line.begin(), (int(&)(int))std::tolower); 119 120 const string key = line.substr(0, p); 121 const string val = line.substr(p+2); 122 123 if (key=="connection" && val=="keep-alive") 124 keepalive = true; 120 125 } 121 126 else 122 127 { 123 128 if (line.substr(0, 2)=="ST") 124 data.fStatus = atoi(line.substr(2).data());129 data.fStatus = stoi(line.substr(2)); 125 130 126 131 if (line.substr(0, 2)=="TE") 127 data.fTemp = atof(line.substr(2).data());132 data.fTemp = stof(line.substr(2)); 128 133 129 134 if (line.substr(0, 2)=="DP") 130 data.fDew = atof(line.substr(2).data());135 data.fDew = stof(line.substr(2)); 131 136 132 137 if (line.substr(0, 3)=="HUM") 133 data.fHum = atof(line.substr(3).data());138 data.fHum = stof(line.substr(3)); 134 139 135 140 if (line.substr(0, 2)=="WS") 136 data.fWind = atof(line.substr(2).data());141 data.fWind = stof(line.substr(2)); 137 142 138 143 if (line.substr(0, 3)=="MWD") 139 data.fDir = atof(line.substr(3).data());144 data.fDir = stof(line.substr(3)); 140 145 141 146 if (line.substr(0, 2)=="WP") 142 data.fGusts = atof(line.substr(2).data());147 data.fGusts = stof(line.substr(2)); 143 148 144 149 if (line.substr(0, 5)=="PRESS") 145 data.fPress = atof(line.substr(5).data());150 data.fPress = stof(line.substr(5)); 146 151 147 152 if (line.substr(0, 4)=="HOUR") 148 hh = atoi(line.substr(4).data());153 hh = stoi(line.substr(4)); 149 154 150 155 if (line.substr(0, 6)=="MINUTS") 151 mm = atoi(line.substr(6).data());156 mm = stoi(line.substr(6)); 152 157 153 158 if (line.substr(0, 7)=="SECONDS") 154 ss = atoi(line.substr(7).data());159 ss = stoi(line.substr(7)); 155 160 156 161 if (line.substr(0, 4)=="YEAR") 157 y = atoi(line.substr(4).data());162 y = stoi(line.substr(4)); 158 163 159 164 if (line.substr(0, 5)=="MONTH") 160 m = atoi(line.substr(5).data());165 m = stoi(line.substr(5)); 161 166 162 167 if (line.substr(0, 3)=="DAY") 163 d = atoi(line.substr(3).data());168 d = stoi(line.substr(3)); 164 169 } 165 170 } 171 172 if (!keepalive) 173 PostClose(false); 166 174 167 175 try … … 175 183 << data.fTemp << "°C H=" << data.fHum << "% P=" 176 184 << data.fPress << "hPa Td=" << data.fDew << "°C V=" 177 << data.fWind << "km/h dir=" << data.fDir << "deg" << endl;185 << data.fWind << "km/h dir=" << data.fDir << "deg"; 178 186 Message(msg); 179 187 … … 201 209 { 202 210 const string dir = "/site/weather/weather_data.txt"; 203 204 const string cmd = "GET "+dir+" HTTP/1.1\r\nHost: www.fact-project.org\r\n\r\n"; 211 const string cmd = 212 "GET "+dir+" HTTP/1.1\r\n" 213 "Accept: */*\r\n" 214 "Content-Type: application/octet-stream\r\n" 215 "User-Agent: FACT\r\n" 216 "Host: www.fact-project.org\r\n" 217 "Pragma: no-cache\r\n" 218 "Cache-Control: no-cache\r\n" 219 "Expires: 0\r\n" 220 "Connection: Keep-Alive\r\n" 221 "Cache-Control: max-age=0\r\n" 222 "\r\n"; 205 223 PostMessage(cmd); 206 224 }
Note:
See TracChangeset
for help on using the changeset viewer.