Changeset 13765
- Timestamp:
- 05/17/12 20:20:16 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/smartfact.cc
r13759 r13765 75 75 deque<float> fFscControlTemperatureHist; 76 76 77 float fFscControlTemperatureAvg;78 77 float fFscControlHumidityAvg; 79 78 80 79 float fDriveControlPointingZd; 81 80 string fDriveControlPointingAz; 82 float fDriveControlTrackingDev;83 81 string fDriveControlSourceName; 82 83 deque<float> fDriveControlTrackingDevHist; 84 84 85 85 int64_t fFadControlNumEvents; … … 163 163 }; 164 164 165 class DimControl : public DimState 166 { 167 typedef function<void(const DimData &)> callback; 168 map<string, callback> fCallbacks; 169 public: 170 DimControl() : DimState("DIM_CONTROL") { } 171 172 void AddCallback(const string &script, const callback &cb) 173 { 174 fCallbacks[script] = cb; 175 } 176 177 void infoHandler() 178 { 179 DimInfo *curr = getInfo(); // get current DimInfo address 180 if (!curr || curr != &dim) 181 return; 182 183 DimState::infoHandler(); 184 185 // Evaluate msg 186 const size_t p0 = msg.find_first_of(':'); 187 if (p0==string::npos) 188 return; 189 190 const size_t p1 = msg.find_last_of('['); 191 if (p1==string::npos) 192 return; 193 194 const size_t p2 = msg.find_first_of(':', p0+1); 195 196 const size_t p3 = p2==string::npos || p2>p1 ? p1-1 : p2; 197 198 const string file = msg.substr(p0+2, p3-p0-2); 199 200 const auto func = fCallbacks.find(file); 201 if (func==fCallbacks.end()) 202 return; 203 204 // Call callback 205 func->second(DimData(curr)); 206 } 207 }; 208 209 165 210 166 211 DimVersion fDim; 212 DimControl fDimControl; 167 213 DimState fDimMcp; 168 DimState fDimControl;169 214 DimState fDimDataLogger; 170 215 DimState fDimDriveControl; … … 258 303 const char *ptr = reinterpret_cast<char*>(val.data()); 259 304 260 ofstream fout(fPath+"/"+fname+".bin"); 261 fout << d.time.JavaDate() << '\n'; 262 fout << offset << '\n'; 263 fout << offset+scale << '\n'; 264 fout.write(ptr, val.size()*sizeof(uint8_t)); 305 ostringstream out; 306 out << d.time.JavaDate() << '\n'; 307 out << offset << '\n'; 308 out << offset+scale << '\n'; 309 out.write(ptr, val.size()*sizeof(uint8_t)); 310 311 ofstream(fPath+"/"+fname+".bin") << out.str(); 265 312 } 266 313 … … 407 454 return; 408 455 409 const double zd = d.get<double>(3*8) * M_PI / 180; 456 const double Ra = d.get<double>(0*8); 457 const double Dec = d.get<double>(1*8); 458 const double Zd = d.get<double>(3*8); 459 const double Az = d.get<double>(4*8); 460 461 const double zd = Zd * M_PI / 180; 410 462 const double dzd = d.get<double>(5*8) * M_PI / 180; 411 463 const double daz = d.get<double>(6*8) * M_PI / 180; … … 415 467 416 468 // Simplified: 417 const double dev = cos(dzd) - sin(zd+dzd)*sin(zd)*(1.-cos(daz)); 418 fDriveControlTrackingDev = acos(dev) * 180 / M_PI * 3600; 419 420 if (fDriveControlTrackingDev<0.01) 421 fDriveControlTrackingDev=0; 469 double dev = cos(dzd) - sin(zd+dzd)*sin(zd)*(1.-cos(daz)); 470 dev = acos(dev) * 180 / M_PI * 3600; 471 472 fDriveControlTrackingDevHist.push_back(dev); 473 if (fDriveControlTrackingDevHist.size()>300) 474 fDriveControlTrackingDevHist.pop_front(); 475 476 WriteBinary(d, "control-deviation-hist", fDriveControlTrackingDevHist, 120); 477 478 ostringstream out; 479 out << d.time.JavaDate() << '\n'; 480 481 out << "#ffffff\t" << fDriveControlSourceName << '\n'; 482 out << setprecision(5); 483 out << "#ffffff\t" << Ra << '\n'; 484 out << "#ffffff\t" << Dec << '\n'; 485 out << setprecision(3); 486 out << "#ffffff\t" << Zd << '\n'; 487 out << "#ffffff\t" << Az << '\n'; 488 out << "#ffffff\t" << dev << '\n'; 489 490 ofstream(fPath+"/tracking.txt") << out.str(); 422 491 } 423 492 … … 447 516 out << "#ffffff\t" << wang << '\n'; 448 517 449 ofstream(fPath+"/ drive.txt") << out.str();518 ofstream(fPath+"/source.txt") << out.str(); 450 519 } 451 520 … … 842 911 rms = sqrt(rms/num-avg*avg); 843 912 844 fFscControlTemperatureAvg = avg;845 846 913 fFscControlTemperatureHist.push_back(avg); 847 914 if (fFscControlTemperatureHist.size()>300) … … 853 920 out << setprecision(3); 854 921 out << d.time.JavaDate() << '\n'; 922 out << "#ffffff\t" << fFscControlHumidityAvg << '\n'; 855 923 out << "#ffffff\t" << min << '\n'; 856 924 out << "#ffffff\t" << avg << '\n'; … … 902 970 903 971 WriteBinary(d, "ratescan-hist", fRateScanDataHist, 10, -2); 972 } 973 974 // ------------------------------------------------------------------- 975 976 void HandleDoTest(const DimData &d) 977 { 978 ostringstream out; 979 out << d.time.JavaDate() << '\t' << fDimControl.online() << '\n'; 980 switch (d.qos) 981 { 982 case -3: out << kHtmlWhite << "\tNot running\n"; break; 983 case -2: out << kHtmlBlue << "\tLoading\n"; break; 984 case -1: out << kHtmlBlue << "\tStarted\n"; break; 985 default: out << kHtmlGreen << "\tRunning [" << d.qos << "]\n"; break; 986 } 987 988 ofstream(fPath+"/dotest.txt") << out.str(); 904 989 } 905 990 … … 1067 1152 1068 1153 out << col << '\t'; 1069 1070 if (fMcpConfigurationState!=5 && 1071 fMcpConfigurationState!=11 && 1072 fMcpConfigurationState!=12) 1073 out << "Configuring "; 1074 out << fMcpConfigurationName; 1075 1076 if (fDimRateControl.state()==5/*kStateSettingGlobalThreshold*/) 1077 out << "Calibrating threshold"; 1078 1079 if (fDimRateScan.state()==5/*kStateSettingGlobalThreshold*/) 1080 out << "Rate scan in progress"; 1154 /* 1155 out << fDimRateControl.state() << "/"; 1156 out << fDimRateScan.state() << "/"; 1157 out << fMcpConfigurationState << "/"; 1158 */ 1159 1160 if (fDimRateControl.state()!=5 && 1161 fDimRateScan.state()!=5) 1162 { 1163 if (fMcpConfigurationState!=5 && 1164 fMcpConfigurationState!=11 && 1165 fMcpConfigurationState!=12) 1166 out << "Configuring "; 1167 out << fMcpConfigurationName; 1168 } 1169 else 1170 if (fDimRateControl.state()==5/*kStateSettingGlobalThreshold*/) 1171 out << "Calibrating threshold"; 1172 else 1173 1174 if (fDimRateScan.state()==5/*kStateSettingGlobalThreshold*/) 1175 out << "Rate scan in progress"; 1081 1176 1082 1177 if (fDimMcp.state()>5 && fDimRateControl.state()!=5) … … 1128 1223 if (fDimDriveControl.state()>=5) // Armed, Moving, Tracking 1129 1224 { 1225 const double dev = fDriveControlTrackingDevHist.size()>0 ? fDriveControlTrackingDevHist.back() : 0; 1130 1226 const State rc = GetState(fDimDriveControl); 1131 1227 string col = kHtmlGreen; … … 1136 1232 if (rc.index==7) // Tracking 1137 1233 { 1138 if ( fDriveControlTrackingDev>60) // ~1.5mm1234 if (dev>60) // ~1.5mm 1139 1235 col = kHtmlYellow; 1140 if ( fDriveControlTrackingDev>100) // ~1/4 of a pixel ~ 2.5mm1236 if (dev>100) // ~1/4 of a pixel ~ 2.5mm 1141 1237 col = kHtmlRed; 1142 1238 } … … 1150 1246 out << fDriveControlSourceName << '\t'; 1151 1247 out << setprecision(2); 1152 out << fDriveControlTrackingDev << '\n';1248 out << dev << '\n'; 1153 1249 out << setprecision(3); 1154 1250 } … … 1160 1256 1161 1257 // ------------------- FSC ------------------ 1162 if (fDimFscControl.state()>1) 1163 { 1164 out << kHtmlGreen << '\t' << fFscControlTemperatureAvg << '\n'; 1258 if (fDimFscControl.state()>1 && fFscControlTemperatureHist.size()>0) 1259 { 1260 if (fDimMagicWeather.state()==3 && fMagicWeatherHist[kTemp].size()>0) 1261 out << kHtmlGreen << '\t' << fFscControlTemperatureHist.back()-fMagicWeatherHist[kTemp].back() << '\n'; 1262 else 1263 out << kHtmlGreen << '\t' << fFscControlTemperatureHist.back() << " [abs]"; 1264 1165 1265 } 1166 1266 else … … 1311 1411 //--- 1312 1412 fDimMcp ("MCP"), 1313 fDimControl ("DIM_CONTROL"),1314 1413 fDimDataLogger ("DATA_LOGGER"), 1315 1414 fDimDriveControl ("DRIVE_CONTROL"), … … 1357 1456 AddStateName(kStateRunning, "Running", ""); 1358 1457 1359 // Verbosity commands1360 // AddEvent("SET_VERBOSE", "B:1")1361 // (bind(&StateMachineMCP::SetVerbosity, this, placeholders::_1))1362 // ("set verbosity state"1363 // "|verbosity[bool]:disable or enable verbosity for received data (yes/no), except dynamic data");1364 1365 1458 AddEvent("PRINT") 1366 1459 (bind(&StateMachineSmartFACT::Print, this)) 1367 1460 (""); 1461 1462 fDimControl.AddCallback("dotest.dim", bind(&StateMachineSmartFACT::HandleDoTest, this, placeholders::_1)); 1368 1463 } 1369 1464 ~StateMachineSmartFACT()
Note:
See TracChangeset
for help on using the changeset viewer.