1 | #include <iostream>
|
---|
2 | #include <iomanip>
|
---|
3 | #include <fstream>
|
---|
4 |
|
---|
5 | #include <TSystem.h>
|
---|
6 | #include <TApplication.h>
|
---|
7 | #include <TObjectTable.h>
|
---|
8 |
|
---|
9 | #include "ethernet.h"
|
---|
10 | #include "vmodican.h"
|
---|
11 |
|
---|
12 | #include "MEnv.h"
|
---|
13 | #include "MArgs.h"
|
---|
14 | #include "MCosy.h"
|
---|
15 | #include "MTime.h"
|
---|
16 | #include "MDriveCom.h"
|
---|
17 |
|
---|
18 | #include "MLogManip.h"
|
---|
19 |
|
---|
20 | #include "MStarguider.h"
|
---|
21 |
|
---|
22 | using namespace std;
|
---|
23 |
|
---|
24 | #define EXPERT
|
---|
25 |
|
---|
26 | static void StartUpMessage()
|
---|
27 | {
|
---|
28 | gLog << all << endl;
|
---|
29 |
|
---|
30 | // 1 2 3 4 5 6
|
---|
31 | // 123456789012345678901234567890123456789012345678901234567890
|
---|
32 | gLog << "========================================================" << endl;
|
---|
33 | gLog << " COSY " << endl;
|
---|
34 | gLog << " Magic Drive Control System Software " << endl;
|
---|
35 | gLog << " Compiled with ROOT v" << ROOT_RELEASE << " on <" << __DATE__ << ">" << endl;
|
---|
36 | gLog << "========================================================" << endl;
|
---|
37 | gLog << endl;
|
---|
38 | }
|
---|
39 |
|
---|
40 | static void Usage()
|
---|
41 | {
|
---|
42 | // 1 2 3 4 5 6 7 8
|
---|
43 | // 12345678901234567890123456789012345678901234567890123456789012345678901234567890
|
---|
44 | gLog << all << endl;
|
---|
45 | gLog << "Sorry the usage is:" << endl;
|
---|
46 | gLog << " cosy [options]" << endl << endl;
|
---|
47 | gLog << " Arguments:" << endl;
|
---|
48 | gLog << " n/a" << endl;
|
---|
49 | gLog << endl;
|
---|
50 | gLog << " Root Options:" << endl;
|
---|
51 | gLog << " -b Batch mode (no graphical output to screen)" << endl<<endl;
|
---|
52 | gLog << " Options:" << endl;
|
---|
53 | gLog.Usage();
|
---|
54 | gLog << " --debug-env=0 Disable debugging setting resources <default>" << endl;
|
---|
55 | gLog << " --debug-env[=1] Display untouched resources after program execution" << endl;
|
---|
56 | gLog << " --debug-env=2 Display untouched resources after eventloop setup" << endl;
|
---|
57 | gLog << " --debug-env=3 Debug setting resources from resource file and command line" << endl;
|
---|
58 | gLog << " --debug-mem Debug memory usage" << endl << endl;
|
---|
59 | gLog << " --debug-threads Debug threads" << endl << endl;
|
---|
60 | gLog << " --rc=Name:option Set or overwrite a resource of the resource file." << endl << endl;
|
---|
61 | gLog << " --version, -V Show startup message with version number" << endl;
|
---|
62 | gLog << " -?, -h, --help This help" << endl << endl;
|
---|
63 | }
|
---|
64 |
|
---|
65 | /* ---------------------------------------------------------------------- */
|
---|
66 | int main(int argc, char **argv)
|
---|
67 | {
|
---|
68 | if (!MARS::CheckRootVer())
|
---|
69 | return 0xff;
|
---|
70 |
|
---|
71 | MLog::RedirectErrorHandler(MLog::kColor);
|
---|
72 |
|
---|
73 | //
|
---|
74 | // Evaluate arguments
|
---|
75 | //
|
---|
76 | MArgs arg(argc, argv, kTRUE);
|
---|
77 | gLog.Setup(arg);
|
---|
78 |
|
---|
79 | StartUpMessage();
|
---|
80 |
|
---|
81 | if (arg.HasOnly("-V") || arg.HasOnly("--version"))
|
---|
82 | return 0;
|
---|
83 |
|
---|
84 | if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
|
---|
85 | {
|
---|
86 | Usage();
|
---|
87 | return 2;
|
---|
88 | }
|
---|
89 |
|
---|
90 | const Int_t channel = arg.GetIntAndRemove("--channel=", 0);
|
---|
91 | const Bool_t kDebugMem = arg.HasOnlyAndRemove("--debug-mem");
|
---|
92 | const Bool_t kDebugThreads = arg.HasOnlyAndRemove("--debug-threads");
|
---|
93 | const TString sps = arg.GetStringAndRemove("--sps=", "sps");
|
---|
94 | const TString ceco = arg.GetStringAndRemove("--cc=", "161.72.130.60"); // ceco
|
---|
95 | const Int_t ceco_tx = arg.GetIntAndRemove("--cc-tx=", 7314);//7304);
|
---|
96 | const Int_t ceco_rx = arg.GetIntAndRemove("--cc-rx=", 7414);//7404);
|
---|
97 | const TString pointing = arg.GetStringAndRemove("--pointing-model=", "bending2.txt"); // ceco
|
---|
98 | const TString kConfig = arg.GetStringAndRemove("--config=", ".cosyrc"); // ceco
|
---|
99 | Int_t kDebugEnv = arg.HasOnlyAndRemove("--debug-env") ? 1 : 0;
|
---|
100 | kDebugEnv = arg.GetIntAndRemove("--debug-env=", kDebugEnv);
|
---|
101 |
|
---|
102 | //
|
---|
103 | // check for the right usage of the program (number of arguments)
|
---|
104 | //
|
---|
105 | if (arg.GetNumArguments()>0)
|
---|
106 | {
|
---|
107 | gLog << warn << "WARNING - Wrong number of arguments..." << endl;
|
---|
108 | Usage();
|
---|
109 | return 2;
|
---|
110 | }
|
---|
111 |
|
---|
112 | //
|
---|
113 | // Now we access/read the resource file. This will remove all
|
---|
114 | // --rc= from the list of arguments.
|
---|
115 | //
|
---|
116 | MEnv env(kConfig);
|
---|
117 | if (!env.IsValid())
|
---|
118 | {
|
---|
119 | gLog << err << "ERROR - Reading resource file " << kConfig << "." << endl;
|
---|
120 | return 0xfe;
|
---|
121 | }
|
---|
122 |
|
---|
123 | // And move the resource options from the command line to the MEnv
|
---|
124 | if (!env.TakeEnv(arg, kDebugEnv>2))
|
---|
125 | return 0xfd;
|
---|
126 |
|
---|
127 | //
|
---|
128 | // check for the right usage of the program (number of options)
|
---|
129 | //
|
---|
130 | if (arg.GetNumOptions()>0)
|
---|
131 | {
|
---|
132 | gLog << warn << "WARNING - Unknown commandline options..." << endl;
|
---|
133 | arg.Print("options");
|
---|
134 | gLog << endl;
|
---|
135 | return 2;
|
---|
136 | }
|
---|
137 |
|
---|
138 | if (!gLog.IsOutputDeviceEnabled(MLog::eFile))
|
---|
139 | {
|
---|
140 | const TString name = MCosy::GetFileName("log", "cosy", "log");
|
---|
141 | gLog << inf << "Open automatic logfile: " << name << endl;
|
---|
142 | gLog.SetOutputFile(name);
|
---|
143 | gLog.EnableOutputDevice(MLog::eFile);
|
---|
144 | }
|
---|
145 |
|
---|
146 | gLog << all << "Starting Cosy at " << MTime(-1) << " in thread " << TThread::SelfId() << "..." << endl;
|
---|
147 |
|
---|
148 | //
|
---|
149 | // start the main window
|
---|
150 | //
|
---|
151 | gLog << all << "- Initialising Root environment." << endl;
|
---|
152 |
|
---|
153 | //
|
---|
154 | // Initialize root
|
---|
155 | //
|
---|
156 | //MArray::Class()->IgnoreTObjectStreamer();
|
---|
157 | //MParContainer::Class()->IgnoreTObjectStreamer();
|
---|
158 |
|
---|
159 | TApplication app("cosy", &argc, argv);
|
---|
160 | if (gROOT->IsBatch())
|
---|
161 | {
|
---|
162 | gLog << err << "ERROR - Cannot run in Batch mode!" << endl;
|
---|
163 | return 0;
|
---|
164 | }
|
---|
165 | if (!gClient)
|
---|
166 | {
|
---|
167 | gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
|
---|
168 | return 1;
|
---|
169 | }
|
---|
170 |
|
---|
171 | if (kDebugMem)
|
---|
172 | TObject::SetObjectStat(kTRUE);
|
---|
173 |
|
---|
174 | //
|
---|
175 | // Create the Network. Device: /dev/dpm_00, Rate: 500kbps
|
---|
176 | //
|
---|
177 | gLog << all <<"- Constructing MCosy." << endl;
|
---|
178 | /*
|
---|
179 | //
|
---|
180 | // check for the right usage of the program
|
---|
181 | //
|
---|
182 | int mode = 0;
|
---|
183 | if (argc==2 && (argv[1][0]=='-' || argv[1][1]=='m'))
|
---|
184 | switch (argv[1][2])
|
---|
185 | {
|
---|
186 | case '0': // standard
|
---|
187 | mode = 0;
|
---|
188 | break;
|
---|
189 | case '1': // SE mode
|
---|
190 | mode = 1;
|
---|
191 | break;
|
---|
192 | case '2': // GUI demo mode
|
---|
193 | mode = 2;
|
---|
194 | break;
|
---|
195 | }
|
---|
196 | */
|
---|
197 |
|
---|
198 | MDriveCom *com = new MDriveCom(ceco, ceco_tx, ceco_rx);
|
---|
199 | com->SetTelescope(2);
|
---|
200 |
|
---|
201 | MCosy *cosy = new MCosy(env, com, pointing);
|
---|
202 |
|
---|
203 | com->SetMsgQueue(cosy);
|
---|
204 |
|
---|
205 | Interface *interface = new Ethernet(sps, 5357, 5358, cosy);
|
---|
206 | // Interface *interface = new VmodIcan(cosy, "/dev/dpm_00", 125);
|
---|
207 |
|
---|
208 | gLog << all << "- Starting MCosy." << endl;
|
---|
209 |
|
---|
210 | cosy->Start(env);
|
---|
211 |
|
---|
212 | // FIXME: Is this the right position?
|
---|
213 | if (kDebugEnv>0)
|
---|
214 | env.PrintUntouched();
|
---|
215 |
|
---|
216 |
|
---|
217 | MStarguider *client=0;
|
---|
218 | if (channel>=0)
|
---|
219 | {
|
---|
220 | gLog << all << "- Starting Camera." << endl;
|
---|
221 | client=new MStarguider(MObservatory::kMagic1, channel);
|
---|
222 | //client.SetDriveCom(&com);
|
---|
223 | cosy->SetStarguider(client);
|
---|
224 | client->SetCosy(cosy);
|
---|
225 | }
|
---|
226 |
|
---|
227 | gLog << all << "- Starting mainloop." << endl;
|
---|
228 |
|
---|
229 | app.Run(kTRUE);
|
---|
230 |
|
---|
231 | if (kDebugThreads)
|
---|
232 | TThread::Ps();
|
---|
233 |
|
---|
234 | if (channel>=0)
|
---|
235 | {
|
---|
236 | client->SetCosy(NULL);
|
---|
237 | cosy->SetStarguider(NULL);
|
---|
238 | gLog << all << "- Stopping starg." << endl;
|
---|
239 | delete client;
|
---|
240 | }
|
---|
241 |
|
---|
242 | gLog << all << "- Stopping cosy." << endl;
|
---|
243 | cosy->Stop();
|
---|
244 |
|
---|
245 | gLog << all << MTime(-1) << ": MCosy stopped." << endl;
|
---|
246 |
|
---|
247 | delete interface;
|
---|
248 |
|
---|
249 | gLog << all << "Deleting cosy at " << MTime(-1) << endl;
|
---|
250 |
|
---|
251 | //com.SetMsgQueue(NULL);
|
---|
252 |
|
---|
253 | delete cosy;
|
---|
254 |
|
---|
255 | gLog << all << "Deleting DriveCom at " << MTime(-1) << endl;
|
---|
256 | delete com;
|
---|
257 |
|
---|
258 | if (kDebugThreads)
|
---|
259 | TThread::Ps();
|
---|
260 |
|
---|
261 | //delete app;
|
---|
262 |
|
---|
263 | if (TObject::GetObjectStat())
|
---|
264 | {
|
---|
265 | TObject::SetObjectStat(kFALSE);
|
---|
266 | gObjectTable->Print();
|
---|
267 | }
|
---|
268 |
|
---|
269 | gLog << all << "The End." << endl;
|
---|
270 | }
|
---|