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

Last change on this file since 4836 was 4105, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 4.3 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
10using namespace std;
11
12bool 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
31bool 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
42bool 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
68bool MDriveCom::CommandZDAZ(TString &str)
69{
70 Double_t zd, az;
71 if (!ReadPosition(str, zd, az))
72 {
73 cout << "ERROR - Reading position from ZDAZ" << endl;
74 return false;
75 }
76
77 if (!str.IsNull())
78 {
79 cout << "ERROR - Too many bytes in command ZDAZ" << endl;
80 return false;
81 }
82
83 cout << "CC-COMMAND " << MTime(-1) << " ZDAZ " << zd << "deg " << az << "deg" << endl;
84
85 ZdAz za(zd, az);
86
87 //cout << "MDriveCom - POSITION... start." << endl;
88 fQueue->PostMsg(WM_POSITION, &za, sizeof(za));
89 //cout << "MDriveCom - POSITION... done." << endl;
90 return true;
91}
92
93bool MDriveCom::InterpreteCmd(TString cmd, TString str)
94{
95 if (cmd==(TString)"WAIT" && str.IsNull())
96 {
97 //cout << "MDriveCom - WAIT... start." << endl;
98 cout << "CC-COMMAND " << MTime(-1) << " WAIT" << endl;
99 fQueue->PostMsg(WM_WAIT);
100 //cout << "MDriveCom - WAIT... done." << endl;
101 return true;
102 }
103
104 if (cmd==(TString)"STOP!" && str.IsNull())
105 {
106 //cout << "MDriveCom - STOP!... start." << endl;
107 cout << "CC-COMMAND " << MTime(-1) << " STOP!" << endl;
108 fQueue->PostMsg(WM_STOP);
109 //cout << "MDriveCom - STOP!... done." << endl;
110 return true;
111 }
112
113 if (cmd==(TString)"RADEC")
114 return CommandRADEC(str);
115
116 if (cmd==(TString)"ZDAZ")
117 return CommandZDAZ(str);
118
119 if (cmd==(TString)"PREPS")
120 {
121 cout << "Prepos: " << str << endl;
122 return true;
123 }
124
125 if (cmd.IsNull() && str.IsNull())
126 {
127 cout << "CC-COMMAND " << MTime(-1) << " Empty command (single '\\n') received." << endl;
128 return false;
129 }
130
131 cout << "CC-COMMAND " << MTime(-1) << " Syntax error: '" << cmd << "':'" << str << "'" << endl;
132 return false;
133}
134
135void MDriveCom::Print(TString &str, Double_t deg) const
136{
137 Char_t sgn;
138 UShort_t d, m, s;
139
140 MAstro::Deg2Dms(deg, sgn, d, m, s);
141
142 MString txt;
143 str += txt.Print("%c %03d %02d %03d ", sgn, d, m, s);
144}
145
146bool MDriveCom::SendReport(UInt_t stat, RaDec rd, ZdAz so, ZdAz is, ZdAz er)
147{
148 // rd [rad]
149 // so [rad]
150 // is [deg]
151 // er [rad]
152 const MTime t(-1);
153
154 rd *= kRad2Deg;
155 so *= kRad2Deg;
156 er *= kRad2Deg;
157
158 rd.Ra(rd.Ra()/15);
159
160 // Set status flag
161 if (stat&kError)
162 SetStatus(0);
163 if (stat&kStopped)
164 SetStatus(1);
165 if (stat&kStopping || stat&kMoving)
166 SetStatus(3);
167 if (stat&kTracking)
168 SetStatus(4);
169
170 MString txt;
171
172 TString str;
173 Print(str, rd.Ra()); // Ra
174 Print(str, rd.Dec()); // Dec
175 Print(str, 0); // HA
176 str += txt.Print("%12.6f ", t.GetMjd()); // mjd
177 Print(str, so.Zd());
178 Print(str, so.Az());
179 Print(str, is.Zd());
180 Print(str, is.Az());
181 str += txt.Print("%08.3f ", er.Zd());
182 str += txt.Print("%08.3f", er.Az());
183
184 return Send("DRIVE-REPORT", str);
185}
186
187bool MDriveCom::SendStatus(const char *stat)
188{
189 return Send("DRIVE-STATUS", stat);
190}
Note: See TracBrowser for help on using the repository browser.