source: trunk/MagicSoft/Cosy/tcpip/MDriveCom.cc@ 8809

Last change on this file since 8809 was 8378, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 7.5 KB
Line 
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
11using namespace std;
12
13bool 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
32bool 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
43bool 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
69bool 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
95bool 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
120bool MDriveCom::CommandPREPS(TString &str)
121{
122 str = str.Strip(TString::kBoth);
123 if (str.IsNull())
124 {
125 cout << "ERROR - No identifier for preposition (PREPS) given." << endl;
126 return false;
127 }
128 if (str.First(' ')>=0)
129 {
130 cout << "ERROR - PREPS command syntax error (contains whitespaces)." << endl;
131 return false;
132 }
133
134 str.ToLower();
135
136 cout << "CC-COMMAND " << MTime(-1) << " PREPS '" << str << "'" << endl;
137
138 //cout << "MDriveCom - TRACK... start." << endl;
139 fQueue->PostMsg(WM_PREPS, (void*)str.Data(), str.Length()+1);
140 //cout << "MDriveCom - TRACK... done." << endl;
141 return true;
142}
143
144bool MDriveCom::CommandARM(TString &str)
145{
146 str = str.Strip(TString::kBoth);
147 if (str.IsNull())
148 {
149 cout << "ERROR - No identifier for ARM command." << endl;
150 return false;
151 }
152 if (str.First(' ')>=0)
153 {
154 cout << "ERROR - ARM command syntax error (contains whitespaces)." << endl;
155 return false;
156 }
157
158 str.ToLower();
159 if (str!="lock" && str!="unlock")
160 {
161 cout << "ERROR - ARM command syntax error (neither LOCK nor UNLOCK)." << endl;
162 return false;
163 }
164
165 cout << "CC-COMMAND " << MTime(-1) << " ARM '" << str << "'" << endl;
166
167 bool lock = str=="lock";
168
169 fQueue->PostMsg(WM_ARM, &lock, sizeof(lock));
170 return true;
171}
172
173bool MDriveCom::InterpreteCmd(TString cmd, TString str)
174{
175 if (cmd==(TString)"WAIT" && str.IsNull())
176 {
177 //cout << "MDriveCom - WAIT... start." << endl;
178 cout << "CC-COMMAND " << MTime(-1) << " WAIT" << endl;
179 fQueue->PostMsg(WM_WAIT);
180 //cout << "MDriveCom - WAIT... done." << endl;
181 return true;
182 }
183
184 if (cmd==(TString)"STOP!" && str.IsNull())
185 {
186 //cout << "MDriveCom - STOP!... start." << endl;
187 cout << "CC-COMMAND " << MTime(-1) << " STOP!" << endl;
188 fQueue->PostMsg(WM_STOP);
189 //cout << "MDriveCom - STOP!... done." << endl;
190 return true;
191 }
192
193 if (cmd==(TString)"RADEC")
194 return CommandRADEC(str);
195
196 if (cmd==(TString)"GRB")
197 return CommandGRB(str);
198
199 if (cmd==(TString)"ZDAZ")
200 return CommandZDAZ(str);
201
202 if (cmd==(TString)"PREPS")
203 return CommandPREPS(str);
204
205 if (cmd.IsNull() && str.IsNull())
206 {
207 cout << "CC-COMMAND " << MTime(-1) << " Empty command (single '\\n') received." << endl;
208 return false;
209 }
210
211 cout << "CC-COMMAND " << MTime(-1) << " Syntax error: '" << cmd << "':'" << str << "'" << endl;
212 return false;
213}
214
215void MDriveCom::Print(TString &str, Double_t deg) const
216{
217 Char_t sgn;
218 UShort_t d, m, s;
219
220 MAstro::Deg2Dms(deg, sgn, d, m, s);
221
222 MString txt;
223 str += txt.Print("%c %03d %02d %03d ", sgn, d, m, s);
224}
225
226bool MDriveCom::SendReport(UInt_t stat, RaDec rd, ZdAz so, ZdAz is, ZdAz er)
227{
228 // rd [rad]
229 // so [rad]
230 // is [deg]
231 // er [rad]
232 const MTime t(-1);
233
234 rd *= kRad2Deg;
235 so *= kRad2Deg;
236 er *= kRad2Deg;
237
238 rd.Ra(rd.Ra()/15);
239
240 // Set status flag
241 if (stat&kError)
242 SetStatus(0);
243 if (stat&kStopped)
244 SetStatus(1);
245 if (stat&kStopping || stat&kMoving)
246 SetStatus(3);
247 if (stat&kTracking)
248 SetStatus(4);
249
250 MString txt;
251
252 TString str;
253 Print(str, rd.Ra()); // Ra
254 Print(str, rd.Dec()); // Dec
255 Print(str, 0); // HA
256 str += txt.Print("%12.6f ", t.GetMjd()); // mjd
257 Print(str, so.Zd());
258 Print(str, so.Az());
259 Print(str, is.Zd());
260 Print(str, is.Az());
261 str += txt.Print("%08.3f ", er.Zd());
262 str += txt.Print("%08.3f", er.Az());
263
264 return SendRep("DRIVE-REPORT", str, kFALSE);
265}
266
267bool MDriveCom::SendStatus(const char *stat)
268{
269 return SendRep("DRIVE-STATUS", stat, kFALSE);
270}
271
272bool 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)
273{
274 // miss [deg]
275 // nompos [deg]
276 const MTime t(-1);
277
278 miss *= 60; // [arcmin]
279
280 // Set status flag
281 if (stat&kError)
282 SetStatus(0);
283 if (stat&kStandby)
284 SetStatus(2);
285 if (stat&kMonitoring)
286 SetStatus(4);
287
288 MString txt;
289
290 TString str;
291 str += txt.Print("%05.3f ", miss.Zd()); //[arcmin]
292 str += txt.Print("%05.3f ", miss.Az()); //[arcmin]
293 Print(str, nompos.Zd()); //[deg]
294 Print(str, nompos.Az()); //[deg]
295 str += txt.Print("%05.1f ", center.GetX()); //number
296 str += txt.Print("%05.1f ", center.GetY()); //number
297 str += txt.Print("%04d ", n); //number of correleated stars
298 str += txt.Print("%03.1f ", bright);
299 str += txt.Print("%12.6f ", t.GetMjd()); // mjd
300 str += txt.Print("%.1f ", x);
301 str += txt.Print("%.1f ", y);
302 str += txt.Print("%04d ", num); //number of detected stars
303
304 return SendRep("STARG-REPORT", str, kTRUE);
305}
Note: See TracBrowser for help on using the repository browser.