1 | #include <iomanip.h>
|
---|
2 | #include <fstream.h>
|
---|
3 | #include <iostream.h>
|
---|
4 |
|
---|
5 | #include <TROOT.h>
|
---|
6 | #include <TSystem.h>
|
---|
7 | #include <TApplication.h>
|
---|
8 |
|
---|
9 | #include "MCosy.h"
|
---|
10 | #include "MLogManip.h"
|
---|
11 | #include "base/timer.h"
|
---|
12 |
|
---|
13 | #include "Camera.h"
|
---|
14 | #include "PngReader.h"
|
---|
15 | #include "MStarguider.h"
|
---|
16 |
|
---|
17 | //#define EXPERT
|
---|
18 | #define HAVE_CAMERA
|
---|
19 |
|
---|
20 | #define clog(txt) \
|
---|
21 | { \
|
---|
22 | const Bool_t is = lout.IsOutputDeviceEnabled(MLog::eStdout); \
|
---|
23 | lout << edev(MLog::eStdout) << txt << endl; \
|
---|
24 | if (is) \
|
---|
25 | lout.EnableOutputDevice(MLog::eStdout); \
|
---|
26 | }
|
---|
27 |
|
---|
28 | TROOT root("Cosy", "Magic Control System");
|
---|
29 |
|
---|
30 | /* ---------------------------------------------------------------------- */
|
---|
31 | //extern void InitGui();
|
---|
32 | //VoidFuncPtr_t initfuncs[] = { InitGui, 0 };
|
---|
33 |
|
---|
34 | int main(int argc, char **argv)
|
---|
35 | {
|
---|
36 | gLog << "==================================================" << endl;
|
---|
37 | gLog << " Cosy V0.1 " << endl;
|
---|
38 | gLog << " Magic Drive Control System Software " << endl;
|
---|
39 | gLog << " Compiled on <" << __DATE__ << ">" << endl;
|
---|
40 | gLog << " Using ROOT v" << ROOTVER << endl;
|
---|
41 | gLog << "==================================================" << endl;
|
---|
42 | gLog << endl;
|
---|
43 |
|
---|
44 | Timer time;
|
---|
45 | time.Now();
|
---|
46 |
|
---|
47 | //
|
---|
48 | // this must move to MGCosy !!!! (or MApplication)
|
---|
49 | //
|
---|
50 | int i=0;
|
---|
51 | char name[100];
|
---|
52 | while (1)
|
---|
53 | {
|
---|
54 | sprintf(name, "log/cosy%03d.log", i++);
|
---|
55 | if (gSystem->AccessPathName(name, kFileExists))
|
---|
56 | break;
|
---|
57 | }
|
---|
58 |
|
---|
59 | MLog *l = new MLog(name, kTRUE);
|
---|
60 | MLog &lout = *l;
|
---|
61 |
|
---|
62 | clog("Starting Cosy at " << time.GetTimeStr() << " ...");
|
---|
63 |
|
---|
64 | //
|
---|
65 | // start the main window
|
---|
66 | //
|
---|
67 | clog("- Initialising Root environment.");
|
---|
68 |
|
---|
69 | TApplication* app = new TApplication("App", &argc, argv);
|
---|
70 |
|
---|
71 | //
|
---|
72 | // Create the Network. Device: /dev/dpm_00, Rate: 500kbps
|
---|
73 | //
|
---|
74 | clog("- Constructing MCosy.");
|
---|
75 |
|
---|
76 | //
|
---|
77 | // check for the right usage of the program
|
---|
78 | //
|
---|
79 | int mode = 0;
|
---|
80 | if (argc==2 && (argv[1][0]=='-' || argv[1][1]=='m'))
|
---|
81 | switch (argv[1][2])
|
---|
82 | {
|
---|
83 | case '0': // standard
|
---|
84 | mode = 0;
|
---|
85 | break;
|
---|
86 | case '1': // SE mode
|
---|
87 | mode = 1;
|
---|
88 | break;
|
---|
89 | case '2': // GUI demo mode
|
---|
90 | mode = 2;
|
---|
91 | break;
|
---|
92 | }
|
---|
93 |
|
---|
94 | MCosy *cosy = new MCosy(mode, "/dev/dpm_00", 125, lout);
|
---|
95 |
|
---|
96 | clog("- Starting MCosy.");
|
---|
97 | #ifndef EXPERT
|
---|
98 | lout.DisableOutputDevice(MLog::eStdout);
|
---|
99 | #endif
|
---|
100 | cosy->Start();
|
---|
101 |
|
---|
102 | clog("- Starting Camera.");
|
---|
103 | #ifdef HAVE_CAMERA
|
---|
104 | MStarguider *client=new MStarguider(MObservatory::kMagic1);
|
---|
105 | Camera *cam = new Camera(*client);
|
---|
106 | cam->Loop(0);
|
---|
107 |
|
---|
108 | cosy->SetStarguider(client);
|
---|
109 | client->SetCosy(cosy);
|
---|
110 | #endif
|
---|
111 | clog("- Starting mainloop.");
|
---|
112 | #ifndef EXPERT
|
---|
113 | lout.DisableOutputDevice(MLog::eStdout);
|
---|
114 | #endif
|
---|
115 | app->Run(kTRUE);
|
---|
116 | #ifdef HAVE_CAMERA
|
---|
117 | client->SetCosy(NULL);
|
---|
118 | cosy->SetStarguider(NULL);
|
---|
119 |
|
---|
120 | clog("- Stopping starg.");
|
---|
121 | cam->ExitLoop();
|
---|
122 | delete cam;
|
---|
123 | delete client;
|
---|
124 | #endif
|
---|
125 | clog("- Stopping cosy.");
|
---|
126 | cosy->Stop();
|
---|
127 | clog("- cosy stopped.");
|
---|
128 |
|
---|
129 | delete cosy;
|
---|
130 |
|
---|
131 | clog("- Terminating Program.");
|
---|
132 |
|
---|
133 | delete l;
|
---|
134 |
|
---|
135 | cout << "The End." << endl;
|
---|
136 |
|
---|
137 | }
|
---|