| 1 | #include "MDriveCom.h"
|
|---|
| 2 |
|
|---|
| 3 | #include <iostream>
|
|---|
| 4 |
|
|---|
| 5 | #include "coord.h"
|
|---|
| 6 | #include "MAstro.h"
|
|---|
| 7 | #include "MCosy.h"
|
|---|
| 8 |
|
|---|
| 9 | using namespace std;
|
|---|
| 10 |
|
|---|
| 11 | bool MDriveCom::ReadAngle(TString &str, Double_t &ret)
|
|---|
| 12 | {
|
|---|
| 13 | Char_t sgn;
|
|---|
| 14 | Int_t d, len;
|
|---|
| 15 | UInt_t m;
|
|---|
| 16 | Float_t s;
|
|---|
| 17 |
|
|---|
| 18 | // Skip whitespaces before %c and after %f
|
|---|
| 19 | int n=sscanf(str.Data(), " %c %d %d %f %n", &sgn, &d, &m, &s, &len);
|
|---|
| 20 |
|
|---|
| 21 | if (n!=4 || (sgn!='+' && sgn!='-'))
|
|---|
| 22 | return false;
|
|---|
| 23 |
|
|---|
| 24 | str.Remove(0, len);
|
|---|
| 25 |
|
|---|
| 26 | ret = MAstro::Dms2Deg(d, m, s, sgn);
|
|---|
| 27 | return true;
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | bool MDriveCom::ReadPosition(TString &str, Double_t &d1, Double_t &d2)
|
|---|
| 31 | {
|
|---|
| 32 | if (!ReadAngle(str, d1))
|
|---|
| 33 | return false;
|
|---|
| 34 |
|
|---|
| 35 | if (!ReadAngle(str, d2))
|
|---|
| 36 | return false;
|
|---|
| 37 |
|
|---|
| 38 | return true;
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | bool MDriveCom::CommandRADEC(TString &str)
|
|---|
| 42 | {
|
|---|
| 43 | Double_t ra, dec;
|
|---|
| 44 | if (!ReadPosition(str, ra, dec))
|
|---|
| 45 | {
|
|---|
| 46 | cout << "ERROR - Reading position from RADEC" << endl;
|
|---|
| 47 | return false;
|
|---|
| 48 | }
|
|---|
| 49 | if (!str.IsNull())
|
|---|
| 50 | {
|
|---|
| 51 | cout << "ERROR - Too many bytes in command RADEC" << endl;
|
|---|
| 52 | return false;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | lout << "CC-COMMAND: Track " << ra << "h " << dec << "deg '" << str
|
|---|
| 56 | << "'" << 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::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 | lout << "CC-COMMAND: Move " << 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 |
|
|---|
| 93 | bool MDriveCom::InterpreteCmd(TString cmd, TString str)
|
|---|
| 94 | {
|
|---|
| 95 | if (cmd==(TString)"WAIT" && str.IsNull())
|
|---|
| 96 | {
|
|---|
| 97 | cout << "MDriveCom - WAIT... start." << endl;
|
|---|
| 98 | fQueue->PostMsg(WM_WAIT);
|
|---|
| 99 | cout << "MDriveCom - WAIT... done." << endl;
|
|---|
| 100 | return true;
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | if (cmd==(TString)"STOP!" && str.IsNull())
|
|---|
| 104 | {
|
|---|
| 105 | cout << "MDriveCom - STOP!... start." << endl;
|
|---|
| 106 | lout << "CC-COMMAND: STOP!" << endl;
|
|---|
| 107 | fQueue->PostMsg(WM_STOP);
|
|---|
| 108 | cout << "MDriveCom - STOP!... done." << endl;
|
|---|
| 109 | return true;
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | if (cmd==(TString)"RADEC")
|
|---|
| 113 | return CommandRADEC(str);
|
|---|
| 114 |
|
|---|
| 115 | if (cmd==(TString)"ZDAZ")
|
|---|
| 116 | return CommandZDAZ(str);
|
|---|
| 117 |
|
|---|
| 118 | if (cmd==(TString)"PREPS")
|
|---|
| 119 | {
|
|---|
| 120 | cout << "Prepos: " << str << endl;
|
|---|
| 121 | return true;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | if (cmd.IsNull() && str.IsNull())
|
|---|
| 125 | {
|
|---|
| 126 | cout << "Empty command (single '\\n') received." << endl;
|
|---|
| 127 | return false;
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | cout << "Unknown Command: '" << cmd << "':'" << str << "'" << endl;
|
|---|
| 131 | return false;
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | void MDriveCom::Print(TString &str, Double_t deg) const
|
|---|
| 135 | {
|
|---|
| 136 | Char_t sgn;
|
|---|
| 137 | UShort_t d, m, s;
|
|---|
| 138 |
|
|---|
| 139 | MAstro::Deg2Dms(deg, sgn, d, m, s);
|
|---|
| 140 |
|
|---|
| 141 | str += Form("%c %03d %02d %03d ", sgn, d, m, s);
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | bool MDriveCom::SendReport(UInt_t stat, RaDec rd, ZdAz so, ZdAz is, ZdAz er)
|
|---|
| 145 | {
|
|---|
| 146 | // rd [rad]
|
|---|
| 147 | // so [rad]
|
|---|
| 148 | // is [deg]
|
|---|
| 149 | // er [rad]
|
|---|
| 150 |
|
|---|
| 151 | rd *= kRad2Deg;
|
|---|
| 152 | so *= kRad2Deg;
|
|---|
| 153 | er *= kRad2Deg;
|
|---|
| 154 |
|
|---|
| 155 | rd.Ra(rd.Ra()*24/360);
|
|---|
| 156 |
|
|---|
| 157 | // Set status flag
|
|---|
| 158 | if (stat&kError)
|
|---|
| 159 | SetStatus(0);
|
|---|
| 160 | if (stat&kStopped)
|
|---|
| 161 | SetStatus(1);
|
|---|
| 162 | if (stat&kStopping || stat&kMoving)
|
|---|
| 163 | SetStatus(3);
|
|---|
| 164 | if (stat&kTracking)
|
|---|
| 165 | SetStatus(4);
|
|---|
| 166 |
|
|---|
| 167 | MTime t;
|
|---|
| 168 | t.Now();
|
|---|
| 169 |
|
|---|
| 170 | TString str;
|
|---|
| 171 | Print(str, rd.Ra()); // Ra
|
|---|
| 172 | Print(str, rd.Dec()); // Dec
|
|---|
| 173 | Print(str, 0); // HA
|
|---|
| 174 | str += Form("%12.6f ", t.GetMjd()); // mjd
|
|---|
| 175 | Print(str, so.Zd());
|
|---|
| 176 | Print(str, so.Az());
|
|---|
| 177 | Print(str, is.Zd());
|
|---|
| 178 | Print(str, is.Az());
|
|---|
| 179 | str += Form("%08.3f ", er.Zd());
|
|---|
| 180 | str += Form("%08.3f", er.Az());
|
|---|
| 181 |
|
|---|
| 182 | return Send(str);
|
|---|
| 183 | }
|
|---|