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

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