source: trunk/FACT++/src/smartfact.cc@ 13524

Last change on this file since 13524 was 13498, checked in by tbretz, 14 years ago
Added rates from ftm control.
File size: 24.1 KB
Line 
1#include "Dim.h"
2#include "Event.h"
3#include "Shell.h"
4#include "StateMachineDim.h"
5#include "Connection.h"
6#include "Configuration.h"
7#include "Console.h"
8#include "Converter.h"
9#include "DimServiceInfoList.h"
10#include "PixelMap.h"
11
12#include "tools.h"
13#include "DimData.h"
14
15#include "LocalControl.h"
16
17#include "HeadersFAD.h"
18#include "HeadersBIAS.h"
19#include "HeadersFTM.h"
20
21namespace ba = boost::asio;
22namespace bs = boost::system;
23namespace dummy = ba::placeholders;
24
25using namespace std;
26
27// ------------------------------------------------------------------------
28
29#include "DimDescriptionService.h"
30
31// ------------------------------------------------------------------------
32
33class StateMachineSmartFACT : public StateMachineDim, public DimInfoHandler
34{
35private:
36 enum states_t
37 {
38 kStateDimNetworkNA = 1,
39 kStateRunning,
40 };
41
42 // ------------------------- Internal variables -----------------------
43
44 PixelMap fPixelMap;
45
46 Time fLastUpdate;
47
48 // ----------------------------- Data storage -------------------------
49
50 enum weather_t { kTemp = 0, kDew, kHum, kPress, kWind, kGusts, kDir };
51 float fMagicWeatherData[7];
52
53 vector<float> fFeedbackCalibration;
54 vector<float> fBiasControlVoltageVec;
55
56 float fBiasControlVoltageMed;
57 float fBiasControlCurrentMed;
58 float fBiasControlCurrentMax;
59
60 deque<float> fBiasControlCurrentHist;
61
62 float fDriveControlPointingZd;
63 string fDriveControlPointingAz;
64 float fDriveControlTrackingDev;
65 string fDriveControlSourceName;
66
67 float fFtmControlTriggerRateCam;
68 deque<float> fFtmControlTriggerRateHist;
69
70 uint8_t fFadControlEventCounter;
71
72 // ------------- Initialize variables before the Dim stuff ------------
73
74 DimServiceInfoList fNetwork;
75
76 pair<Time, int> fStatusDim;
77 pair<Time, int> fStatusDriveControl;
78 pair<Time, int> fStatusMagicWeather;
79 pair<Time, int> fStatusFeedback;
80 pair<Time, int> fStatusBiasControl;
81 pair<Time, int> fStatusFtmControl;
82 pair<Time, int> fStatusFadControl;
83
84 DimStampedInfo fDim;
85
86 DimStampedInfo fDimDriveControl;
87 DimStampedInfo fDimDriveControlPointing;
88 DimStampedInfo fDimDriveControlTracking;
89 DimStampedInfo fDimDriveControlSource;
90
91 DimStampedInfo fDimMagicWeather;
92 DimStampedInfo fDimMagicWeatherData;
93
94 DimStampedInfo fDimFeedback;
95 DimStampedInfo fDimFeedbackCalibration;
96
97 DimStampedInfo fDimBiasControl;
98 DimStampedInfo fDimBiasControlVoltage;
99 DimStampedInfo fDimBiasControlCurrent;
100
101 DimStampedInfo fDimFtmControl;
102 DimStampedInfo fDimFtmControlTriggerRates;
103
104 DimStampedInfo fDimFadControl;
105 DimStampedInfo *fDimFadControlEventData;
106
107 // -------------------------------------------------------------------
108
109 pair<Time, int> GetNewState(DimStampedInfo &info) const
110 {
111 const bool disconnected = info.getSize()==0;
112
113 // Make sure getTimestamp is called _before_ getTimestampMillisecs
114 const int tsec = info.getTimestamp();
115 const int tms = info.getTimestampMillisecs();
116
117 return make_pair(Time(tsec, tms*1000),
118 disconnected ? -2 : info.getQuality());
119 }
120
121 bool UpdateState(DimInfo *curr, DimStampedInfo &service, pair<Time,int> &rc)
122 {
123 if (curr!=&service)
124 return false;
125
126 rc = GetNewState(service);
127 return true;
128 }
129
130 bool HandleService(DimInfo *curr, const DimInfo &service, void (StateMachineSmartFACT::*handle)(const DimData &))
131 {
132 if (curr!=&service)
133 return false;
134
135 (this->*handle)(DimData(curr));
136 return true;
137 }
138
139
140 bool CheckDataSize(const DimData &d, const char *name, size_t size)
141 {
142 if (d.data.size()==size)
143 return true;
144
145 ostringstream msg;
146 msg << name << " - Received service has " << d.data.size() << " bytes, but expected " << size << ".";
147 Warn(msg);
148 return false;
149 }
150
151
152 // -------------------------------------------------------------------
153
154 template<class T>
155 void WriteBinary(const string &fname, const T &t, double scale, double offset=0)
156 {
157 vector<uint8_t> val(t.size(), 0);
158 for (uint64_t i=0; i<t.size(); i++)
159 {
160 float range = nearbyint(128*(t[i]+offset)/scale); // [-2V; 2V]
161 if (range>127)
162 range=127;
163 if (range<0)
164 range=0;
165 val[i] = (uint8_t)range;
166 }
167
168 const char *ptr = reinterpret_cast<char*>(val.data());
169
170 ofstream fout("www/"+fname+".bin");
171 fout.write(ptr, val.size()*sizeof(uint8_t));
172 }
173
174 // -------------------------------------------------------------------
175
176 void HandleMagicWeatherData(const DimData &d)
177 {
178 if (!CheckDataSize(d, "MagicWeather:Data", 7*4+2))
179 return;
180
181 // FIXME: Check size (7*4+2)
182
183 //const uint16_t status = d.get<uint16_t>();
184 memcpy(fMagicWeatherData, d.ptr<float>(2), 7*sizeof(float));
185
186 ostringstream out;
187 out << uint64_t(d.time.UnixTime()*1000) << '\n';
188
189 for (int i=0; i<7; i++)
190 out << "#ffffff\t" << fMagicWeatherData[i] << '\n';
191
192 ofstream fout("www/magicweather.txt");
193 fout << out.str();
194 }
195
196 void HandleDrivePointing(const DimData &d)
197 {
198 if (!CheckDataSize(d, "DriveControl:Pointing", 7*4+2))
199 return;
200
201 fDriveControlPointingZd = d.get<double>();
202
203 const double az = d.get<double>(8);
204
205 static const char *dir[] =
206 {
207 "N", "NNE", "NE", "ENE",
208 "E", "ESE", "SE", "SSE",
209 "S", "SSW", "SW", "WSW",
210 "W", "WNW", "NW", "NNW"
211 };
212
213 const uint16_t i = uint16_t(floor(fmod(az+11.25, 360)/22));
214 fDriveControlPointingAz = dir[i];
215
216 ostringstream out;
217 out << uint64_t(d.time.UnixTime()*1000) << '\n';
218
219 out << setprecision(5);
220 out << fDriveControlPointingZd << '\n';
221 out << az << '\n';
222
223 ofstream fout("www/drive-pointing.txt");
224 fout << out.str();
225 }
226
227 void HandleDriveTracking(const DimData &d)
228 {
229 if (!CheckDataSize(d, "DriveControl:Tracking", 7*4+2))
230 return;
231
232 const double zd = d.get<double>(4*8) * M_PI / 180;
233 const double dzd = d.get<double>(6*8) * M_PI / 180;
234 const double daz = d.get<double>(7*8) * M_PI / 180;
235
236 // Correct:
237 // const double d = cos(del) - sin(zd+dzd)*sin(zd)*(1.-cos(daz));
238
239 // Simplified:
240 const double dev = cos(dzd) - sin(zd)*sin(zd)*(1.-cos(daz));
241 fDriveControlTrackingDev = acos(dev) * 180 / M_PI;
242 }
243
244 void HandleDriveSource(const DimData &d)
245 {
246 if (!CheckDataSize(d, "DriveControl:Source", 7*4+2))
247 return;
248
249 const double *ptr = d.ptr<double>();
250
251 const double ra = ptr[0]; // Ra[h]
252 const double dec = ptr[1]; // Dec[deg]
253 const double woff = ptr[4]; // Wobble offset [deg]
254 const double wang = ptr[5]; // Wobble angle [deg]
255
256 fDriveControlSourceName = d.ptr<char>(6*8);
257
258 ostringstream out;
259 out << uint64_t(d.time.UnixTime()*1000) << '\n';
260
261 out << fDriveControlSourceName << '\n';
262 out << setprecision(5);
263 out << "#ffffff\t" << ra << '\n';
264 out << "#ffffff\t" << dec << '\n';
265 out << setprecision(3);
266 out << "#ffffff\t" << woff << '\n';
267 out << "#ffffff\t" << wang << '\n';
268
269 ofstream fout("www/drive.txt");
270 fout << out.str();
271 }
272
273 void HandleFeedbackCalibration(const DimData &d)
274 {
275 if (!CheckDataSize(d, "Feedback:Calibration", 3*4*416))
276 {
277 fFeedbackCalibration.clear();
278 return;
279 }
280
281 const float *ptr = d.ptr<float>();
282 fFeedbackCalibration.assign(ptr+2*416, ptr+3*416);
283 }
284
285 void HandleBiasControlVoltage(const DimData &d)
286 {
287 if (!CheckDataSize(d, "BiasControl:Voltage", 1664))
288 {
289 fBiasControlVoltageVec.clear();
290 return;
291 }
292
293 fBiasControlVoltageVec.assign(d.ptr<float>(), d.ptr<float>()+320);
294
295 vector<float> v(fBiasControlVoltageVec);
296 sort(v.begin(), v.end());
297
298 fBiasControlVoltageMed = (v[159]+v[160])/2;
299
300 const char *ptr = d.ptr<char>();
301
302 ofstream fout("www/biascontrol-voltage.bin");
303 fout.write(ptr, 320*sizeof(float));
304 }
305
306 void HandleBiasControlCurrent(const DimData &d)
307 {
308 if (!CheckDataSize(d, "BiasControl:Current", 832))
309 return;
310
311 // Convert dac counts to uA
312 vector<float> v(320);
313 for (int i=0; i<320; i++)
314 v[i] = d.ptr<uint16_t>()[i] * 5000./4096;
315
316 // Calibrate the data (subtract offset)
317 if (fFeedbackCalibration.size()>0 && fBiasControlVoltageVec.size()>0)
318 for (int i=0; i<320; i++)
319 v[i] -= fBiasControlVoltageVec[i]/fFeedbackCalibration[i]*1e6;
320
321 // Get the maximum of each patch
322 vector<float> val(160, 0);
323 for (int i=0; i<160; i++)
324 val[i] = max(v[i*2], v[i*2+1]);
325
326 // Write the 160 patch values to a file
327 WriteBinary("biascontrol-current", val, 1000);
328
329 // Now sort them to determine the median
330 sort(v.begin(), v.end());
331
332 // Exclude the three crazy channels
333 fBiasControlCurrentMed = (v[159]+v[160])/2;
334 fBiasControlCurrentMax = v[316];
335
336 // Store a history of the last 60 entries
337 fBiasControlCurrentHist.push_back(fBiasControlCurrentMed);
338 if (fBiasControlCurrentHist.size()>60)
339 fBiasControlCurrentHist.pop_front();
340
341 // write the history to a file
342 WriteBinary("biascontrol-current-hist", fBiasControlCurrentHist, 1000);
343 }
344
345 void HandleFtmControlTriggerRates(const DimData &d)
346 {
347 if (!CheckDataSize(d, "FtmControl:TriggerRates", 24+160+640+8))
348 return;
349
350 fFtmControlTriggerRateCam = d.get<float>(20);
351
352 const float *brates = d.ptr<float>(24); // Board rate
353 const float *prates = d.ptr<float>(24+160); // Patch rate
354
355 // Store a history of the last 60 entries
356 fFtmControlTriggerRateHist.push_back(fFtmControlTriggerRateCam);
357 if (fFtmControlTriggerRateHist.size()>60)
358 fFtmControlTriggerRateHist.pop_front();
359
360 WriteBinary("ftmcontrol-triggerrate-hist",
361 fFtmControlTriggerRateHist, 100);
362 WriteBinary("ftmcontrol-boardrates",
363 vector<float>(brates, brates+40), 50);
364 WriteBinary("ftmcontrol-patchrates",
365 vector<float>(prates, prates+160), 10);
366 }
367
368 void HandleFadControlEventData(const DimData &d)
369 {
370 if (!CheckDataSize(d, "FadControl:EventData", 23040))
371 return;
372
373 if (fFadControlEventCounter++%30)
374 return;
375
376 //const float *avg = d.ptr<float>();
377 //const float *rms = d.ptr<float>(1440*sizeof(float));
378 const float *max = d.ptr<float>(1440*sizeof(float)*2);
379 //const float *pos = d.ptr<float>(1440*sizeof(float)*3);
380
381 vector<float> dat(160, 0);
382 for (int i=0; i<1440; i++)
383 {
384 const int idx = fPixelMap.index(i).hw()/9;
385 if (max[i]>dat[idx])
386 dat[idx]=max[i];
387 //dat[idx] += max[i];
388 }
389
390 WriteBinary("fadcontrol-eventdata", dat, 4000, 2000);
391 }
392
393 // -------------------------------------------------------------------
394
395 void infoHandler()
396 {
397 DimInfo *curr = getInfo(); // get current DimInfo address
398 if (!curr)
399 return;
400
401 if (HandleService(curr, fDimMagicWeatherData, &StateMachineSmartFACT::HandleMagicWeatherData))
402 return;
403 if (HandleService(curr, fDimFeedbackCalibration, &StateMachineSmartFACT::HandleFeedbackCalibration))
404 return;
405 if (HandleService(curr, fDimBiasControlVoltage, &StateMachineSmartFACT::HandleBiasControlVoltage))
406 return;
407 if (HandleService(curr, fDimBiasControlCurrent, &StateMachineSmartFACT::HandleBiasControlCurrent))
408 return;
409 if (HandleService(curr, fDimFtmControlTriggerRates, &StateMachineSmartFACT::HandleFtmControlTriggerRates))
410 return;
411 if (HandleService(curr, *fDimFadControlEventData, &StateMachineSmartFACT::HandleFadControlEventData))
412 return;
413
414 if (UpdateState(curr, fDimMagicWeather, fStatusMagicWeather))
415 return;
416 if (UpdateState(curr, fDimFeedback, fStatusFeedback))
417 return;
418 if (UpdateState(curr, fDimBiasControl, fStatusBiasControl))
419 return;
420 if (UpdateState(curr, fDimFtmControl, fStatusFtmControl))
421 return;
422 if (UpdateState(curr, fDimFadControl, fStatusFadControl))
423 return;
424
425 if (curr==&fDim)
426 {
427 fStatusDim = GetNewState(fDim);
428 fStatusDim.second = curr->getSize()==4 ? curr->getInt() : 0;
429 return;
430 }
431 }
432
433 bool CheckEventSize(size_t has, const char *name, size_t size)
434 {
435 if (has==size)
436 return true;
437
438 ostringstream msg;
439 msg << name << " - Received event has " << has << " bytes, but expected " << size << ".";
440 Fatal(msg);
441 return false;
442 }
443
444 void PrintState(const pair<Time,int> &state, const char *server)
445 {
446 const State rc = fNetwork.GetState(server, state.second);
447
448 Out() << state.first.GetAsStr("%H:%M:%S.%f").substr(0, 12) << " - ";
449 Out() << kBold << server << ": ";
450 if (rc.index==-2)
451 {
452 Out() << kReset << "Offline" << endl;
453 return;
454 }
455 Out() << rc.name << "[" << rc.index << "]";
456 Out() << kReset << " - " << kBlue << rc.comment << endl;
457 }
458
459 int Print()
460 {
461 Out() << fStatusDim.first.GetAsStr("%H:%M:%S.%f").substr(0, 12) << " - ";
462 Out() << kBold << "DIM_DNS: ";
463 if (fStatusDim.second==0)
464 Out() << "Offline" << endl;
465 else
466 Out() << "V" << fStatusDim.second/100 << 'r' << fStatusDim.second%100 << endl;
467
468 PrintState(fStatusMagicWeather, "MAGIC_WEATHER");
469 PrintState(fStatusDriveControl, "DRIVE_CONTROL");
470 PrintState(fStatusFeedback, "FEEDBACK");
471 PrintState(fStatusBiasControl, "BIAS_CONTROL");
472 PrintState(fStatusFadControl, "FAD_CONTROL");
473
474 return GetCurrentState();
475 }
476
477 int Execute()
478 {
479 // Dispatch (execute) at most one handler from the queue. In contrary
480 // to run_one(), it doesn't wait until a handler is available
481 // which can be dispatched, so poll_one() might return with 0
482 // handlers dispatched. The handlers are always dispatched/executed
483 // synchronously, i.e. within the call to poll_one()
484 //poll_one();
485
486 if (fStatusDim.second==0)
487 return kStateDimNetworkNA;
488
489 Time now;
490 if (now-fLastUpdate<boost::posix_time::seconds(1))
491 return kStateRunning;
492
493 fLastUpdate=now;
494
495 ostringstream out;
496 out << uint64_t(nearbyint(now.UnixTime()*1000)) << '\n';
497 out << setprecision(3);
498
499 // -------------- System status --------------
500 out << "n/a\n";
501
502 const static string kWhite = "#ffffff";
503 const static string kYellow = "#fffff0";
504 const static string kRed = "#fff8f0";
505 const static string kGreen = "#f0fff0";
506 const static string kBlue = "#f0f0ff";
507
508 // ------------------ Drive -----------------
509 if (fStatusDriveControl.second>=5) // Armed, Moving, Tracking
510 {
511 const State rc = fNetwork.GetState("DRIVE_CONTROL", fStatusDriveControl.second);
512 out << kWhite << "\t";
513 out << rc.name << '\t';
514 out << fDriveControlPointingZd << '\t';
515 out << fDriveControlPointingAz << '\t';
516 out << fDriveControlTrackingDev << '\t';
517 out << fDriveControlSourceName << '\n';
518 }
519 else
520 out << kWhite << "\n";
521
522 // --------------- MagicWeather -------------
523 if (fStatusMagicWeather.second==3)
524 {
525 const float diff = fMagicWeatherData[kTemp]-fMagicWeatherData[kDew];
526 string col1 = kRed;
527 if (diff>0.3)
528 col1 = kYellow;
529 if (diff>0.7)
530 col1 = kGreen;
531
532 const float wind = fMagicWeatherData[kGusts];
533 string col2 = kGreen;
534 if (wind>35)
535 col2 = kYellow;
536 if (wind>50)
537 col2 = kRed;
538
539 out << col1 << "\t";
540 out << fMagicWeatherData[kTemp] << '\t';
541 out << fMagicWeatherData[kDew] << '\n';
542 out << col2 << "\t";
543 out << fMagicWeatherData[kGusts] << '\n';
544 }
545 else
546 out << kWhite << "\n\n";
547
548 // --------------- FtmControl -------------
549 if (fStatusFtmControl.second>=FTM::kIdle)
550 {
551 string col = kGreen;
552 if (fFtmControlTriggerRateCam<15)
553 col = kYellow;
554 if (fFtmControlTriggerRateCam>100)
555 col = kRed;
556
557 out << col << '\t' << fFtmControlTriggerRateCam << '\n';
558 }
559 else
560 out << kWhite << '\n';
561
562 // --------------- BiasControl -------------
563 if (fStatusBiasControl.second==5 || // Ramping
564 fStatusBiasControl.second==7 || // On
565 fStatusBiasControl.second==9) // Off
566 {
567 string col = fBiasControlVoltageMed>3?kGreen:kWhite;
568 if (fBiasControlCurrentMax>280)
569 col = kYellow;
570 if (fBiasControlCurrentMax>350)
571 col = kRed;
572
573 if (fFeedbackCalibration.size()==0)
574 col = kBlue;
575
576 out << col << "\t";
577 out << fBiasControlCurrentMed << '\t';
578 out << fBiasControlCurrentMax << '\t';
579 out << fBiasControlVoltageMed << '\n';
580 }
581 else
582 out << kWhite << "\n";
583
584
585 // ------------------------------------------
586 ofstream fout("www/fact.txt");
587 fout << out.str();
588
589 return kStateRunning;
590 }
591
592public:
593 StateMachineSmartFACT(ostream &out=cout) : StateMachineDim(out, "SMART_FACT"),
594 fFadControlEventCounter(0),
595 //---
596 fStatusDim (make_pair(Time(), -2)),
597 fStatusDriveControl(make_pair(Time(), -2)),
598 fStatusMagicWeather(make_pair(Time(), -2)),
599 fStatusFeedback (make_pair(Time(), -2)),
600 fStatusBiasControl (make_pair(Time(), -2)),
601 fStatusFtmControl (make_pair(Time(), -2)),
602 fStatusFadControl (make_pair(Time(), -2)),
603 //---
604 fDim ("DIS_DNS/VERSION_NUMBER", (void*)NULL, 0, this),
605 //---
606 fDimDriveControl ("DRIVE_CONTROL/STATE", (void*)NULL, 0, this),
607 fDimDriveControlPointing ("DRIVE_CONTROL/POINTING_POSITION", (void*)NULL, 0, this),
608 fDimDriveControlTracking ("DRIVE_CONTROL/TRACKING_POSITION", (void*)NULL, 0, this),
609 fDimDriveControlSource ("DRIVE_CONTROL/SOURCE_POSITION", (void*)NULL, 0, this),
610 //---
611 fDimMagicWeather ("MAGIC_WEATHER/STATE", (void*)NULL, 0, this),
612 fDimMagicWeatherData ("MAGIC_WEATHER/DATA", (void*)NULL, 0, this),
613 //---
614 fDimFeedback ("FEEDBACK/STATE", (void*)NULL, 0, this),
615 fDimFeedbackCalibration ("FEEDBACK/CALIBRATION", (void*)NULL, 0, this),
616 //---
617 fDimBiasControl ("BIAS_CONTROL/STATE", (void*)NULL, 0, this),
618 fDimBiasControlVoltage ("BIAS_CONTROL/VOLTAGE", (void*)NULL, 0, this),
619 fDimBiasControlCurrent ("BIAS_CONTROL/CURRENT", (void*)NULL, 0, this),
620 //---
621 fDimFtmControl ("FTM_CONTROL/STATE", (void*)NULL, 0, this),
622 fDimFtmControlTriggerRates("FTM_CONTROL/TRIGGER_RATES", (void*)NULL, 0, this),
623 //-
624 fDimFadControl ("FAD_CONTROL/STATE", (void*)NULL, 0, this),
625 fDimFadControlEventData(0)
626 {
627 // State names
628 AddStateName(kStateDimNetworkNA, "DimNetworkNotAvailable",
629 "The Dim DNS is not reachable.");
630
631 AddStateName(kStateRunning, "Running", "");
632
633 // Verbosity commands
634// AddEvent("SET_VERBOSE", "B:1")
635// (bind(&StateMachineMCP::SetVerbosity, this, placeholders::_1))
636// ("set verbosity state"
637// "|verbosity[bool]:disable or enable verbosity for received data (yes/no), except dynamic data");
638
639 AddEvent("PRINT")
640 (bind(&StateMachineSmartFACT::Print, this))
641 ("");
642 }
643 ~StateMachineSmartFACT()
644 {
645 delete fDimFadControlEventData;
646 }
647 int EvalOptions(Configuration &conf)
648 {
649 if (!fPixelMap.Read(conf.Get<string>("pixel-map-file")))
650 {
651 Error("Reading mapping table from "+conf.Get<string>("pixel-map-file")+" failed.");
652 return 1;
653 }
654
655 // Pixel map is needed to deal with this service
656 fDimFadControlEventData=new DimStampedInfo("FAD_CONTROL/EVENT_DATA", (void*)NULL, 0, this);
657
658 return -1;
659 }
660};
661
662// ------------------------------------------------------------------------
663
664#include "Main.h"
665
666template<class T>
667int RunShell(Configuration &conf)
668{
669 return Main::execute<T, StateMachineSmartFACT>(conf);
670}
671
672void SetupConfiguration(Configuration &conf)
673{
674 po::options_description control("Smart FACT");
675 control.add_options()
676 ("pixel-map-file", var<string>("FACTmapV5a.txt"), "Pixel mapping file. Used here to get the default reference voltage.")
677 ;
678
679 conf.AddOptions(control);
680}
681
682/*
683 Extract usage clause(s) [if any] for SYNOPSIS.
684 Translators: "Usage" and "or" here are patterns (regular expressions) which
685 are used to match the usage synopsis in program output. An example from cp
686 (GNU coreutils) which contains both strings:
687 Usage: cp [OPTION]... [-T] SOURCE DEST
688 or: cp [OPTION]... SOURCE... DIRECTORY
689 or: cp [OPTION]... -t DIRECTORY SOURCE...
690 */
691void PrintUsage()
692{
693 cout <<
694 "SmartFACT is a tool writing the files needed for the SmartFACT web interface.\n"
695 "\n"
696 "The default is that the program is started without user intercation. "
697 "All actions are supposed to arrive as DimCommands. Using the -c "
698 "option, a local shell can be initialized. With h or help a short "
699 "help message about the usuage can be brought to the screen.\n"
700 "\n"
701 "Usage: smartfact [-c type] [OPTIONS]\n"
702 " or: smartfact [OPTIONS]\n";
703 cout << endl;
704}
705
706void PrintHelp()
707{
708 Main::PrintHelp<StateMachineSmartFACT>();
709
710 /* Additional help text which is printed after the configuration
711 options goes here */
712
713 /*
714 cout << "bla bla bla" << endl << endl;
715 cout << endl;
716 cout << "Environment:" << endl;
717 cout << "environment" << endl;
718 cout << endl;
719 cout << "Examples:" << endl;
720 cout << "test exam" << endl;
721 cout << endl;
722 cout << "Files:" << endl;
723 cout << "files" << endl;
724 cout << endl;
725 */
726}
727
728int main(int argc, const char* argv[])
729{
730 Configuration conf(argv[0]);
731 conf.SetPrintUsage(PrintUsage);
732 Main::SetupConfiguration(conf);
733 SetupConfiguration(conf);
734
735 if (!conf.DoParse(argc, argv, PrintHelp))
736 return -1;
737
738 //try
739 {
740 // No console access at all
741 if (!conf.Has("console"))
742 {
743// if (conf.Get<bool>("no-dim"))
744// return RunShell<LocalStream, StateMachine, ConnectionFSC>(conf);
745// else
746 return RunShell<LocalStream>(conf);
747 }
748 // Cosole access w/ and w/o Dim
749/* if (conf.Get<bool>("no-dim"))
750 {
751 if (conf.Get<int>("console")==0)
752 return RunShell<LocalShell, StateMachine, ConnectionFSC>(conf);
753 else
754 return RunShell<LocalConsole, StateMachine, ConnectionFSC>(conf);
755 }
756 else
757*/ {
758 if (conf.Get<int>("console")==0)
759 return RunShell<LocalShell>(conf);
760 else
761 return RunShell<LocalConsole>(conf);
762 }
763 }
764 /*catch (std::exception& e)
765 {
766 cerr << "Exception: " << e.what() << endl;
767 return -1;
768 }*/
769
770 return 0;
771}
Note: See TracBrowser for help on using the repository browser.