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