1 | #include "MDriveCom.h"
|
---|
2 |
|
---|
3 | #include <iostream>
|
---|
4 |
|
---|
5 | #include "MAstro.h"
|
---|
6 | #include "MCosy.h"
|
---|
7 | #include "MString.h"
|
---|
8 | #include "Ring.h"
|
---|
9 |
|
---|
10 | using namespace std;
|
---|
11 |
|
---|
12 | bool MDriveCom::ReadAngle(TString &str, Double_t &ret)
|
---|
13 | {
|
---|
14 | Char_t sgn;
|
---|
15 | Int_t d, len;
|
---|
16 | UInt_t m;
|
---|
17 | Float_t s;
|
---|
18 |
|
---|
19 | // Skip whitespaces before %c and after %f
|
---|
20 | int n=sscanf(str.Data(), " %c %d %d %f %n", &sgn, &d, &m, &s, &len);
|
---|
21 |
|
---|
22 | if (n!=4 || (sgn!='+' && sgn!='-'))
|
---|
23 | return false;
|
---|
24 |
|
---|
25 | str.Remove(0, len);
|
---|
26 |
|
---|
27 | ret = MAstro::Dms2Deg(d, m, s, sgn);
|
---|
28 | return true;
|
---|
29 | }
|
---|
30 |
|
---|
31 | bool MDriveCom::ReadPosition(TString &str, Double_t &d1, Double_t &d2)
|
---|
32 | {
|
---|
33 | if (!ReadAngle(str, d1))
|
---|
34 | return false;
|
---|
35 |
|
---|
36 | if (!ReadAngle(str, d2))
|
---|
37 | return false;
|
---|
38 |
|
---|
39 | return true;
|
---|
40 | }
|
---|
41 |
|
---|
42 | bool MDriveCom::CommandRADEC(TString &str)
|
---|
43 | {
|
---|
44 | Double_t ra, dec;
|
---|
45 | if (!ReadPosition(str, ra, dec))
|
---|
46 | {
|
---|
47 | cout << "ERROR - Reading position from RADEC" << endl;
|
---|
48 | return false;
|
---|
49 | }
|
---|
50 | if (!str.IsNull())
|
---|
51 | {
|
---|
52 | cout << "ERROR - Too many bytes in command RADEC" << endl;
|
---|
53 | return false;
|
---|
54 | }
|
---|
55 |
|
---|
56 | cout << "CC-COMMAND " << MTime(-1) << " RADEC " << ra << "h " << dec << "d '" << str << "'" << endl;
|
---|
57 |
|
---|
58 | ra *= 15; // h -> deg
|
---|
59 |
|
---|
60 | RaDec rd[2] = { RaDec(ra, dec), RaDec(ra, dec) };
|
---|
61 |
|
---|
62 | //cout << "MDriveCom - TRACK... start." << endl;
|
---|
63 | fQueue->PostMsg(WM_TRACK, &rd, sizeof(rd));
|
---|
64 | //cout << "MDriveCom - TRACK... done." << endl;
|
---|
65 | return true;
|
---|
66 | }
|
---|
67 |
|
---|
68 | bool MDriveCom::CommandGRB(TString &str)
|
---|
69 | {
|
---|
70 | Double_t ra, dec;
|
---|
71 | if (!ReadPosition(str, ra, dec))
|
---|
72 | {
|
---|
73 | cout << "ERROR - Reading position from GRB" << endl;
|
---|
74 | return false;
|
---|
75 | }
|
---|
76 | if (!str.IsNull())
|
---|
77 | {
|
---|
78 | cout << "ERROR - Too many bytes in command GRB" << endl;
|
---|
79 | return false;
|
---|
80 | }
|
---|
81 |
|
---|
82 | cout << "CC-COMMAND " << MTime(-1) << " GRB " << ra << "h " << dec << "d '" << str << "'" << endl;
|
---|
83 |
|
---|
84 | ra *= 15; // h -> deg
|
---|
85 |
|
---|
86 | RaDec rd[2] = { RaDec(ra, dec), RaDec(ra, dec) };
|
---|
87 |
|
---|
88 | //cout << "MDriveCom - TRACK... start." << endl;
|
---|
89 | fQueue->PostMsg(WM_GRB, &rd, sizeof(rd));
|
---|
90 | //cout << "MDriveCom - TRACK... done." << endl;
|
---|
91 | return true;
|
---|
92 | }
|
---|
93 |
|
---|
94 | bool MDriveCom::CommandZDAZ(TString &str)
|
---|
95 | {
|
---|
96 | Double_t zd, az;
|
---|
97 | if (!ReadPosition(str, zd, az))
|
---|
98 | {
|
---|
99 | cout << "ERROR - Reading position from ZDAZ" << endl;
|
---|
100 | return false;
|
---|
101 | }
|
---|
102 |
|
---|
103 | if (!str.IsNull())
|
---|
104 | {
|
---|
105 | cout << "ERROR - Too many bytes in command ZDAZ" << endl;
|
---|
106 | return false;
|
---|
107 | }
|
---|
108 |
|
---|
109 | cout << "CC-COMMAND " << MTime(-1) << " ZDAZ " << zd << "deg " << az << "deg" << endl;
|
---|
110 |
|
---|
111 | ZdAz za(zd, az);
|
---|
112 |
|
---|
113 | //cout << "MDriveCom - POSITION... start." << endl;
|
---|
114 | fQueue->PostMsg(WM_POSITION, &za, sizeof(za));
|
---|
115 | //cout << "MDriveCom - POSITION... done." << endl;
|
---|
116 | return true;
|
---|
117 | }
|
---|
118 |
|
---|
119 | bool MDriveCom::CommandPREPS(TString &str)
|
---|
120 | {
|
---|
121 | str = str.Strip(TString::kBoth);
|
---|
122 | if (str.IsNull())
|
---|
123 | {
|
---|
124 | cout << "ERROR - No identifier for preposition (PREPS) given." << endl;
|
---|
125 | return false;
|
---|
126 | }
|
---|
127 | if (str.First(' ')>=0)
|
---|
128 | {
|
---|
129 | cout << "ERROR - PREPS command syntax error (contains whitespaces)." << endl;
|
---|
130 | return false;
|
---|
131 | }
|
---|
132 |
|
---|
133 | str.ToLower();
|
---|
134 |
|
---|
135 | cout << "CC-COMMAND " << MTime(-1) << " PREPS '" << str << "'" << endl;
|
---|
136 |
|
---|
137 | //cout << "MDriveCom - TRACK... start." << endl;
|
---|
138 | fQueue->PostMsg(WM_PREPS, (void*)str.Data(), str.Length()+1);
|
---|
139 | //cout << "MDriveCom - TRACK... done." << endl;
|
---|
140 | return true;
|
---|
141 | }
|
---|
142 |
|
---|
143 | bool MDriveCom::CommandARM(TString &str)
|
---|
144 | {
|
---|
145 | str = str.Strip(TString::kBoth);
|
---|
146 | if (str.IsNull())
|
---|
147 | {
|
---|
148 | cout << "ERROR - No identifier for ARM command." << endl;
|
---|
149 | return false;
|
---|
150 | }
|
---|
151 | if (str.First(' ')>=0)
|
---|
152 | {
|
---|
153 | cout << "ERROR - ARM command syntax error (contains whitespaces)." << endl;
|
---|
154 | return false;
|
---|
155 | }
|
---|
156 |
|
---|
157 | str.ToLower();
|
---|
158 | if (str!="lock" && str!="unlock")
|
---|
159 | {
|
---|
160 | cout << "ERROR - ARM command syntax error (neither LOCK nor UNLOCK)." << endl;
|
---|
161 | return false;
|
---|
162 | }
|
---|
163 |
|
---|
164 | cout << "CC-COMMAND " << MTime(-1) << " ARM '" << str << "'" << endl;
|
---|
165 |
|
---|
166 | bool lock = str=="lock";
|
---|
167 |
|
---|
168 | fQueue->PostMsg(WM_ARM, &lock, sizeof(lock));
|
---|
169 | return true;
|
---|
170 | }
|
---|
171 |
|
---|
172 | bool MDriveCom::InterpreteCmd(TString cmd, TString str)
|
---|
173 | {
|
---|
174 | if (cmd==(TString)"WAIT" && str.IsNull())
|
---|
175 | {
|
---|
176 | //cout << "MDriveCom - WAIT... start." << endl;
|
---|
177 | cout << "CC-COMMAND " << MTime(-1) << " WAIT" << endl;
|
---|
178 | fQueue->PostMsg(WM_WAIT);
|
---|
179 | //cout << "MDriveCom - WAIT... done." << endl;
|
---|
180 | return true;
|
---|
181 | }
|
---|
182 |
|
---|
183 | if (cmd==(TString)"STOP!" && str.IsNull())
|
---|
184 | {
|
---|
185 | //cout << "MDriveCom - STOP!... start." << endl;
|
---|
186 | cout << "CC-COMMAND " << MTime(-1) << " STOP!" << endl;
|
---|
187 | fQueue->PostMsg(WM_STOP);
|
---|
188 | //cout << "MDriveCom - STOP!... done." << endl;
|
---|
189 | return true;
|
---|
190 | }
|
---|
191 |
|
---|
192 | if (cmd==(TString)"RADEC")
|
---|
193 | return CommandRADEC(str);
|
---|
194 |
|
---|
195 | if (cmd==(TString)"GRB")
|
---|
196 | return CommandGRB(str);
|
---|
197 |
|
---|
198 | if (cmd==(TString)"ZDAZ")
|
---|
199 | return CommandZDAZ(str);
|
---|
200 |
|
---|
201 | if (cmd==(TString)"PREPS")
|
---|
202 | return CommandPREPS(str);
|
---|
203 |
|
---|
204 | if (cmd.IsNull() && str.IsNull())
|
---|
205 | {
|
---|
206 | cout << "CC-COMMAND " << MTime(-1) << " Empty command (single '\\n') received." << endl;
|
---|
207 | return false;
|
---|
208 | }
|
---|
209 |
|
---|
210 | cout << "CC-COMMAND " << MTime(-1) << " Syntax error: '" << cmd << "':'" << str << "'" << endl;
|
---|
211 | return false;
|
---|
212 | }
|
---|
213 |
|
---|
214 | void MDriveCom::Print(TString &str, Double_t deg) const
|
---|
215 | {
|
---|
216 | Char_t sgn;
|
---|
217 | UShort_t d, m, s;
|
---|
218 |
|
---|
219 | MAstro::Deg2Dms(deg, sgn, d, m, s);
|
---|
220 |
|
---|
221 | MString txt;
|
---|
222 | str += txt.Print("%c %03d %02d %03d ", sgn, d, m, s);
|
---|
223 | }
|
---|
224 |
|
---|
225 | bool MDriveCom::SendReport(UInt_t stat, RaDec rd, ZdAz so, ZdAz is, ZdAz er)
|
---|
226 | {
|
---|
227 | // rd [rad]
|
---|
228 | // so [rad]
|
---|
229 | // is [deg]
|
---|
230 | // er [rad]
|
---|
231 | const MTime t(-1);
|
---|
232 |
|
---|
233 | rd *= kRad2Deg;
|
---|
234 | so *= kRad2Deg;
|
---|
235 | er *= kRad2Deg;
|
---|
236 |
|
---|
237 | rd.Ra(rd.Ra()/15);
|
---|
238 |
|
---|
239 | // Set status flag
|
---|
240 | if (stat&kError)
|
---|
241 | SetStatus(0);
|
---|
242 | if (stat&kStopped)
|
---|
243 | SetStatus(1);
|
---|
244 | if (stat&kStopping || stat&kMoving)
|
---|
245 | SetStatus(3);
|
---|
246 | if (stat&kTracking)
|
---|
247 | SetStatus(4);
|
---|
248 |
|
---|
249 | MString txt;
|
---|
250 |
|
---|
251 | TString str;
|
---|
252 | Print(str, rd.Ra()); // Ra
|
---|
253 | Print(str, rd.Dec()); // Dec
|
---|
254 | Print(str, 0); // HA
|
---|
255 | str += txt.Print("%12.6f ", t.GetMjd()); // mjd
|
---|
256 | Print(str, so.Zd());
|
---|
257 | Print(str, so.Az());
|
---|
258 | Print(str, is.Zd());
|
---|
259 | Print(str, is.Az());
|
---|
260 | str += txt.Print("%08.3f ", er.Zd());
|
---|
261 | str += txt.Print("%08.3f", er.Az());
|
---|
262 |
|
---|
263 | return SendRep("DRIVE-REPORT", str, kFALSE);
|
---|
264 | }
|
---|
265 |
|
---|
266 | bool MDriveCom::SendStatus(const char *stat)
|
---|
267 | {
|
---|
268 | return SendRep("DRIVE-STATUS", stat, kFALSE);
|
---|
269 | }
|
---|
270 |
|
---|
271 | bool MDriveCom::SendStargReport(UInt_t stat, ZdAz miss, ZdAz nompos, Ring center, Int_t num, Int_t n, Double_t bright, Double_t mjd, Double_t x, Double_t y)
|
---|
272 | {
|
---|
273 | // miss [deg]
|
---|
274 | // nompos [deg]
|
---|
275 | const MTime t(-1);
|
---|
276 |
|
---|
277 | miss *= 60; // [arcmin]
|
---|
278 |
|
---|
279 | // Set status flag
|
---|
280 | if (stat&kError)
|
---|
281 | SetStatus(0);
|
---|
282 | if (stat&kStandby)
|
---|
283 | SetStatus(2);
|
---|
284 | if (stat&kMonitoring)
|
---|
285 | SetStatus(4);
|
---|
286 |
|
---|
287 | MString txt;
|
---|
288 |
|
---|
289 | TString str;
|
---|
290 | str += txt.Print("%05.3f ", miss.Zd()); //[arcmin]
|
---|
291 | str += txt.Print("%05.3f ", miss.Az()); //[arcmin]
|
---|
292 | Print(str, nompos.Zd()); //[deg]
|
---|
293 | Print(str, nompos.Az()); //[deg]
|
---|
294 | str += txt.Print("%05.1f ", center.GetX()); //number
|
---|
295 | str += txt.Print("%05.1f ", center.GetY()); //number
|
---|
296 | str += txt.Print("%04d ", n); //number of correleated stars
|
---|
297 | str += txt.Print("%03.1f ", bright);
|
---|
298 | str += txt.Print("%12.6f ", t.GetMjd()); // mjd
|
---|
299 | str += txt.Print("%.1f ", x);
|
---|
300 | str += txt.Print("%.1f ", y);
|
---|
301 | str += txt.Print("%04d ", num); //number of detected stars
|
---|
302 |
|
---|
303 | return SendRep("STARG-REPORT", str, kTRUE);
|
---|
304 | }
|
---|