source: trunk/MagicSoft/Cosy/cosy.cc@ 2602

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