- Timestamp:
- 05/30/12 15:42:26 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/drivectrl.cc
r13975 r13982 645 645 // ------------------------------------------------------------------------ 646 646 647 struct Source 648 { 649 Source() : ra(0), dec(0), offset(0) 650 { 651 angle[0] = angle[1] = 0; 652 } 653 654 double ra; 655 double dec; 656 double offset; 657 array<double, 2> angle; 658 }; 659 660 647 661 template <class T, class S> 648 662 class StateMachineDrive : public T, public ba::io_service, public ba::io_service::work … … 653 667 string fDatabase; 654 668 655 typedef map<string, pair<double,double>> sources;669 typedef map<string, Source> sources; 656 670 sources fSources; 657 671 … … 797 811 } 798 812 813 const sources::const_iterator GetSourceFromDB(const char *ptr, const char *last) 814 { 815 if (find(ptr, last, '\0')==last) 816 { 817 T::Fatal("TrackWobble - The name transmitted by dim is not null-terminated."); 818 throw uint32_t(T::kSM_FatalError); 819 } 820 821 const string name(Tools::TrimQuotes(ptr)); 822 823 const sources::const_iterator it = fSources.find(name); 824 if (it==fSources.end()) 825 { 826 T::Error("Source '"+name+"' not found in list."); 827 throw uint32_t(T::GetCurrentState()); 828 } 829 830 return it; 831 } 832 833 int TrackWobble(const EventImp &evt) 834 { 835 if (evt.GetSize()<=2) 836 { 837 ostringstream msg; 838 msg << "Track - Received event has " << evt.GetSize() << " bytes, but expected at least 3."; 839 T::Fatal(msg); 840 return T::kSM_FatalError; 841 } 842 843 const uint16_t wobble = evt.GetUShort(); 844 if (wobble!=1 && wobble!=2) 845 { 846 ostringstream msg; 847 msg << "TrackWobble - Wobble id " << wobble << " undefined, only 1 and 2 allowed."; 848 T::Error(msg); 849 return T::GetCurrentState(); 850 } 851 852 const char *ptr = evt.Ptr<char>(2); 853 const char *last = ptr+evt.GetSize()-2; 854 855 try 856 { 857 const sources::const_iterator it = GetSourceFromDB(ptr, last); 858 859 const string &name = it->first; 860 const Source &src = it->second; 861 862 return StartWobble(src.ra, src.dec, src.offset, src.angle[wobble-1], name); 863 } 864 catch (const uint32_t &e) 865 { 866 return e; 867 } 868 } 869 799 870 int Track(const EventImp &evt) 800 871 { … … 804 875 msg << "Track - Received event has " << evt.GetSize() << " bytes, but expected at least 17."; 805 876 T::Fatal(msg); 806 return false;877 return T::kSM_FatalError; 807 878 } 808 879 … … 811 882 const char *last = ptr+evt.GetSize()-16; 812 883 813 if (find(ptr, last, '\0')==last) 814 { 815 T::Fatal("Track - The name transmitted by dim is not null-terminated."); 816 return false; 817 } 818 819 const string name(Tools::TrimQuotes(ptr)); 820 821 const sources::const_iterator it = fSources.find(name); 822 if (it==fSources.end()) 823 { 824 T::Error("Source '"+name+"' not found in list."); 825 return false; 826 } 827 828 const double &ra = it->second.first; 829 const double &dec = it->second.second; 830 831 return StartWobble(ra, dec, dat[0], dat[1], name); 884 try 885 { 886 const sources::const_iterator it = GetSourceFromDB(ptr, last); 887 888 const string &name = it->first; 889 const Source &src = it->second; 890 891 return StartWobble(src.ra, src.dec, dat[0], dat[1], name); 892 } 893 catch (const uint32_t &e) 894 { 895 return e; 896 } 832 897 } 833 898 … … 857 922 int Print() 858 923 { 859 for (sources::const_iterator it=fSources.begin(); 860 it!=fSources.end(); it++) 924 for (auto it=fSources.begin(); it!=fSources.end(); it++) 861 925 { 862 926 const string &name = it->first; 863 const double &ra = it->second.first; 864 const double &dec = it->second.second; 865 866 T::Out() << name << "," << ra << "," << dec << endl; 927 const Source &src = it->second; 928 929 T::Out() << name << ","; 930 T::Out() << src.ra << "," << src.dec << "," << src.offset << ","; 931 T::Out() << src.angle[0] << "," << src.angle[1] << endl; 867 932 } 868 933 return T::GetCurrentState(); … … 1004 1069 "|Offset[deg]:Wobble offset" 1005 1070 "|Angle[deg]:Wobble angle" 1071 "|Name[string]:Source name"); 1072 1073 T::AddEvent("TRACK_WOBBLE", "S:1;C", State::kArmed, State::kTracking) // ->RADEC/GRB 1074 (bind(&StateMachineDrive::TrackWobble, this, placeholders::_1)) 1075 ("Move the telescope to the given wobble position around the given source and start tracking" 1076 "|id:Wobble angle id (1 or 2)" 1006 1077 "|Name[string]:Source name"); 1007 1078 … … 1133 1204 for (vector<mysqlpp::Row>::const_iterator v=res.begin(); v<res.end(); v++) 1134 1205 { 1206 Source src; 1207 src.ra = (*v)[1]; 1208 src.dec = (*v)[2]; 1135 1209 const string name = (*v)[0].c_str(); 1136 const double ra = (*v)[1];1137 const double dec = (*v)[2];1138 1210 1139 1211 // FIXME: Check double names 1140 fSources[name] = make_pair(ra, dec);1212 fSources[name] = src; 1141 1213 1142 1214 if (print) 1143 1215 { 1144 1216 ostringstream msg; 1145 msg << " " << name << setprecision(8) << ": Ra=" << ra << "h Dec=" <<dec << "deg";1217 msg << " " << name << setprecision(8) << ": Ra=" << src.ra << "h Dec=" << src.dec << "deg"; 1146 1218 T::Message(msg); 1147 1219 } … … 1183 1255 if (i==3) 1184 1256 { 1257 Source src; 1258 src.ra = ra; 1259 src.dec = dec; 1260 1185 1261 // FIXME: Check double names 1186 fSources[name] = make_pair(ra, dec);1262 fSources[name] = src; 1187 1263 } 1188 1264 }
Note:
See TracChangeset
for help on using the changeset viewer.