My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
AntennaMaster.h
Go to the documentation of this file.
1 #ifndef ANTENNAMASTER_H
2 #define ANTENNAMASTER_H
3 
12 // C++ includes
13 
14 #include <string>
15 
16 // C includes
17 
18 #include <signal.h>
19 
20 // Util includes
21 
22 #include "gcp/util/common/AntNum.h"
23 #include "gcp/util/common/GenericMasterTask.h"
24 #include "gcp/util/common/SignalTask.h"
25 
26 #include "gcp/util/specific/Directives.h"
27 
28 // Antenna includes
29 
30 #include "gcp/antenna/control/specific/AntennaTask.h"
31 #include "gcp/antenna/control/specific/AntennaMasterMsg.h"
32 #include "gcp/antenna/control/specific/SpecificShare.h"
33 #include "gcp/antenna/control/specific/SpecificTask.h"
34 
35 #define ANTENNA_HEARTBEAT_SIGNAL SIGRTMIN
36 #define ANTENNA_MONITOR_SIGNAL SIGRTMIN+1
37 #define ANTENNA_SERVO_CMD_SIGNAL SIGRTMIN+2
38 #define ANTENNA_SERVO_READ_SIGNAL SIGRTMIN+3
39 #define CONNECT_SIGNAL SIGRTMIN+4
40 #define ANTENNA_GPIB_SIGNAL SIGRTMIN+5
41 #define ANTENNA_RX_SIGNAL SIGRTMIN+6
42 #define ANTENNA_RX_READ_SIGNAL SIGRTMIN+7
43 #define ANTENNA_LNA_READ_SIGNAL SIGRTMIN+8
44 #define ANTENNA_ROACH_SIGNAL SIGRTMIN+9
45 #define ANTENNA_ROACH_READ_SIGNAL SIGRTMIN+10
46 #define ANTENNA_ADC_READ_SIGNAL SIGRTMIN+11
47 
48 //------------------------------------------------------------
49 // This timer will cause parent tasks to send a heartbeat request to
50 // their children
51 //------------------------------------------------------------
52 
53 #define ANTENNA_HEARTBEAT_SEC 5
54 
55 //-------------------------------------------------------------
56 // We will read out the entire shared memory object every second, on
57 // the absolute second boundary
58 //------------------------------------------------------------
59 
60 #define ANTENNA_MONITOR_SEC 1 // 1Hz data pulse
61 #define ANTENNA_MONITOR_NSEC 0
62 
63 //------------------------------------------------------------
64 // We will command the servo once a second, on the three-quarter-second
65 //------------------------------------------------------------
66 
67 #define ANTENNA_SERVO_CMD_SEC 1
68 #define ANTENNA_SERVO_CMD_NSEC 750000000 // 0.75 seconds after the
69  // 0.absolute second
70  // 0.boundary
71 
72 //------------------------------------------------------------
73 // We will read back positions from the servo box once a second, on
74 // the quarter second, so that the previous positions are in shared
75 // memory by the time the 0.5-second command 1pps arrives
76 //------------------------------------------------------------
77 
78 #define ANTENNA_SERVO_READ_SEC 1
79 #define ANTENNA_SERVO_READ_NSEC 250000000 // 0.25 seconds after the
80  // 0.absolute second
81  // 0.boundary
82 
83 //------------------------------------------------------------
84 // If we are disconnected from the mediator, we will attempt to
85 // reconnect every 2 seconds
86 //------------------------------------------------------------
87 
88 #define CONNECT_SEC 2 // Connect timer
89 #define CONNECT_NSEC 750000000 // 0.25 seconds after the
90  // 0.absolute second boundary
91 
92 //------------------------------------------------------------
93 // We will read out the GPIB network every 200 ms, offset from the
94 // second boundary
95 //------------------------------------------------------------
96 
97 #define ANTENNA_GPIB_SEC 1
98 #define ANTENNA_GPIB_NSEC 200000000
99 #define ANTENNA_GPIB_DELAY_NSEC 50000000 // start timer 50 ms after
100  // the absolute
101  // second boundary
102 
103 //------------------------------------------------------------
104 // We will
105 // probe the roach boards 10x/s,
106 //------------------------------------------------------------
107 
108 #define ANTENNA_ROACH_SEC 0
109 #define ANTENNA_ROACH_NSEC 100000000
110 #define ANTENNA_ROACH_DELAY_NSEC 10000000 // start timer 10 ms after the
111  // absolute second boundary
112 //------------------------------------------------------------
113 // We will
114 // write the receiver data once a second at the 0.3ms mark
115 //------------------------------------------------------------
116 
117 #define ANTENNA_ROACH_READ_SEC 0
118 #define ANTENNA_ROACH_READ_NSEC 1000000000
119 #define ANTENNA_ROACH_READ_DELAY_NSEC 300000000 // start timer 0.3 s after the
120  // absolute second boundary
121 
122 //------------------------------------------------------------
123 // We will
124 // probe 1 roach board 10x/s, but have them offset from each other by 50ms.
125 //------------------------------------------------------------
126 
127 #define ANTENNA_RX_SEC 0
128 #define ANTENNA_RX_NSEC 100000000
129 #define ANTENNA_RX_DELAY_NSEC 10000000 // start timer 10 ms after the
130  // absolute second boundary
131 //------------------------------------------------------------
132 // We will
133 // write the receiver data once a second at the 0.3ms mark
134 //------------------------------------------------------------
135 
136 #define ANTENNA_RX_READ_SEC 0
137 #define ANTENNA_RX_READ_NSEC 1000000000
138 #define ANTENNA_RX_READ_DELAY_NSEC 300000000 // start timer 0.3 s after the
139 
140 
141 //------------------------------------------------------------
142 // We will
143 // write the LNA data every second at the 150ms mark
144 //------------------------------------------------------------
145 
146 #define ANTENNA_LNA_READ_SEC 1
147 #define ANTENNA_LNA_READ_NSEC 1000000000
148 #define ANTENNA_LNA_READ_DELAY_NSEC 150000000 // start timer 150 ms after the
149  // absolute second boundary
150 
151 #define ANTENNA_ADC_READ_SEC 10
152 #define ANTENNA_ADC_READ_NSEC 5000000000
153 #define ANTENNA_ADC_READ_DELAY_NSEC 550000000 // start timer 150 ms after the
154  // absolute second boundary
155 
156 #define ANTENNAMASTER_TASK_FWD_FN(fn) void (fn)(AntennaMasterMsg* msg)
157 
158 namespace gcp {
159  namespace antenna {
160  namespace control {
161 
166  class AntennaDrive;
167  class AntennaControl;
168  class AntennaMonitor;
169  class AntennaRx;
170  class AntennaRoach;
171 
179  class AntennaMaster :
180  public SpecificTask,
181  public gcp::util::GenericMasterTask<AntennaMasterMsg> {
182 
183  public:
184 
190  AntennaMaster(std::string host,
191  bool simPmac=false,
192  bool simGpib=false,
193  bool simDlp=false,
194  bool priv=true,
195  bool simLna=false,
196  bool simAdc=false,
197  bool simRoach1=false,
198  bool simRoach2=false);
199 
205  ~AntennaMaster();
206 
211 
216 
221 
226 
231 
237  void restartServices();
238 
239  //------------------------------------------------------------
240  // Public methods for sending messages to this task.
241  //------------------------------------------------------------
242 
247  SIGNALTASK_HANDLER_FN(doNothing);
248 
255  static SIGNALTASK_HANDLER_FN(sendSendHeartBeatMsg);
256 
262  static SIGNALTASK_HANDLER_FN(sendShutDownMsg);
263 
268  static SIGNALTASK_HANDLER_FN(sendPackDataFrameMsg);
269 
274 
279  static SIGNALTASK_HANDLER_FN(sendDriveTickMsg);
280 
285  static SIGNALTASK_HANDLER_FN(sendDriveReadMsg);
286 
290  static SIGNALTASK_HANDLER_FN(sendDlpTempRequestMsg);
291 
295  static SIGNALTASK_HANDLER_FN(sendConnectControlMsg);
296 
300  static SIGNALTASK_HANDLER_FN(sendConnectDriveMsg);
301 
305  static SIGNALTASK_HANDLER_FN(sendConnectScannerMsg);
306 
307  /*
308  * Send a message to the gpib task to read data back from the
309  * GPIB network
310  */
311  static SIGNALTASK_HANDLER_FN(sendReadoutGpibMsg);
312 
316  static SIGNALTASK_HANDLER_FN(sendConnectRxMsg);
317 
321  static SIGNALTASK_HANDLER_FN(sendConnectRoachMsg);
322 
326  static SIGNALTASK_HANDLER_FN(sendDisconnectRxMsg);
327 
331  static SIGNALTASK_HANDLER_FN(sendDisconnectRoachMsg);
332 
333  /*
334  * Send a message to the rx task to read data back from the
335  * receiver backend
336  */
337  static SIGNALTASK_HANDLER_FN(sendReadoutRoachMsg);
338 
339  /*
340  * Send a message to the rx task to write the data it has stored into
341  * the share object
342  */
343  static SIGNALTASK_HANDLER_FN(sendWriteRoachMsg);
344 
345  /*
346  * Send a message to the rx task to read data back from the
347  * receiver backend
348  */
349  static SIGNALTASK_HANDLER_FN(sendReadoutRxMsg);
350 
351  /*
352  * Send a message to the rx task to write the data it has stored into
353  * the share object
354  */
355  static SIGNALTASK_HANDLER_FN(sendWriteRxMsg);
356 
357  /*
358  * Send a message to the lna task to read/write the data it has stored into
359  * the share object
360  */
361  static SIGNALTASK_HANDLER_FN(sendReadLnaMsg);
362 
363  /*
364  * Send a message to the adc task to read/write the data it has stored into
365  * the share object
366  */
367  static SIGNALTASK_HANDLER_FN(sendReadAdcMsg);
368 
373  void sendAdoptBoardMsg(unsigned short, AntennaTask::Id taskId);
374 
375  //------------------------------------------------------------
376  // Communications methods
377  //------------------------------------------------------------
378 
382  static ANTENNAMASTER_TASK_FWD_FN(forwardMasterMsg);
383 
384  //------------------------------------------------------------
385  // Public accessor methods
386  //------------------------------------------------------------
387 
393 
398 
402  inline std::string host() {return host_;}
403 
408  bool usePrio();
409 
410  // Methods to determine if we are simulating devices
411 
412  bool simPmac();
413  bool simGpib();
414  bool simLna();
415  bool simAdc();
416  bool simDlp();
417  bool simRoach1();
418  bool simRoach2();
419 
420 
421  private:
422 
426  bool simPmac_;
427 
428  // True if simulating a GPIB network
429 
430  bool simGpib_;
431 
432  // True if simulating a LNA task
433 
434  bool simLna_;
435 
436  // True if simulating a ADC task
437 
438  bool simAdc_;
439 
440  // True if simulating a temperature sensor bus
441 
442  bool simDlp_;
443 
444  // True if simulating a roach
445 
446  bool simRoach1_;
447  bool simRoach2_;
448 
452  bool usePrio_;
453 
457  static AntennaMaster* master_;
458 
462  gcp::util::AntNum* antNum_;
463 
467  std::string host_;
468 
469  //------------------------------------------------------------
470  // Thread management methods
471  //------------------------------------------------------------
472 
476  static THREAD_START(startAntennaDrive);
477 
481  static THREAD_START(startAntennaMonitor);
482 
486  static THREAD_START(startAntennaControl);
487 
491  static THREAD_START(startAntennaRx);
492 
496  static THREAD_START(startAntennaRoach);
497 
501  static THREAD_START(startAntennaSignal);
502 
503 
504  //------------------------------------------------------------
505  // Thread cleanup handlers methods
506 
510  static THREAD_CLEAN(cleanAntennaDrive);
511 
515  static THREAD_CLEAN(cleanAntennaMonitor);
516 
520  static THREAD_CLEAN(cleanAntennaControl);
521 
525  static THREAD_CLEAN(cleanAntennaRx);
526 
530  static THREAD_CLEAN(cleanAntennaRoach);
531 
535  static THREAD_CLEAN(cleanAntennaSignal);
536 
537  //------------------------------------------------------------
538  // Ping routines for the (pingable) subsystem threads
539 
545  static THREAD_PING(pingAntennaControl);
546 
552  static THREAD_PING(pingAntennaDrive);
553 
559  static THREAD_PING(pingAntennaMonitor);
560 
566  static THREAD_PING(pingAntennaRx);
567 
573  static THREAD_PING(pingAntennaRoach);
574 
575  //------------------------------------------------------------
576  // Pointers to the subsystem resources. These pointers are
577  // initialized by the subsystem threads on startup
578 
579  // Pointer to the Control resources
580 
582 
583  // Pointer to the Drive system resources
584 
586 
587  // Pointer to the Receiver Task resources
588 
590 
591  // Pointer to the Receiver Task resources
592 
594 
595  // Pointer to the Monitor Task resources
596 
598 
599  //------------------------------------------------------------
600  // Members pertaining to communication with this task
601 
607  void processMsg(AntennaMasterMsg* taskMsg);
608 
609  //------------------------------------------------------------
610  // Message forwarding methods. These are private, as they
611  // should not be used directly by tasks to send messages to
612  // each other, or they will run the risk of a message getting
613  // dropped if these methods are called before the recipient's
614  // queue exists.
615  //
616  // Messages to all tasks should be sent to the master, whose
617  // message queue is guaranteed to exist before any other tasks
618  // are spawned, and which will not service messages until all
619  // spawned tasks have allocated their resources. This
620  // guarantees that no messages will be lost, but simply queued
621  // until the master calls its serviceMsgQ() method.
622 
626  static ANTENNAMASTER_TASK_FWD_FN(forwardControlMsg);
627 
631  static ANTENNAMASTER_TASK_FWD_FN(forwardDriveMsg);
632 
636  static ANTENNAMASTER_TASK_FWD_FN(forwardMonitorMsg);
637 
641  static ANTENNAMASTER_TASK_FWD_FN(forwardRxMsg);
642 
646  static ANTENNAMASTER_TASK_FWD_FN(forwardRoachMsg);
647 
648  //------------------------------------------------------------
649  // Private send methods for messages intended for the
650  // AntennaMaster
651  //------------------------------------------------------------
652 
657 
658  //------------------------------------------------------------
659  // Methods pertaining to timers managed by this task
660  //------------------------------------------------------------
661 
665  void sendHeartBeat();
666 
670  void installTimers();
671 
675  void installSignals();
676 
677  }; // End class AntennaMaster
678 
679  }; // End namespace control
680  }; // End namespace antenna
681 }; // End namespace gcp
682 
683 #endif
Definition: AntennaControl.h:43
gcp::antenna::control::AntennaRx * AntennaRx()
Definition: AntennaMaster.cc:502
Definition: AntennaRx.h:32
static ANTENNAMASTER_TASK_FWD_FN(forwardMasterMsg)
Id
Definition: AntennaTask.h:25
gcp::antenna::control::AntennaRoach * AntennaRoach()
Definition: AntennaMaster.cc:581
void sendDriveShutDownMessage()
Definition: AntennaMaster.cc:1385
Definition: AntennaRoach.h:32
Definition: AntennaMasterMsg.h:31
gcp::antenna::control::AntennaControl * AntennaControl()
Definition: AntennaMaster.cc:419
Definition: GenericMasterTask.h:22
Definition: AntennaMonitor.h:37
SpecificShare * getShare()
Definition: AntennaMaster.cc:1163
void sendAdoptBoardMsg(unsigned short, AntennaTask::Id taskId)
bool usePrio()
Definition: AntennaMaster.cc:1420
Definition: SpecificTask.h:19
~AntennaMaster()
Definition: AntennaMaster.cc:161
gcp::util::AntNum * getAnt()
Definition: AntennaMaster.cc:1171
void restartServices()
Definition: AntennaMaster.cc:657
AntennaMaster(std::string host, bool simPmac=false, bool simGpib=false, bool simDlp=false, bool priv=true, bool simLna=false, bool simAdc=false, bool simRoach1=false, bool simRoach2=false)
Definition: AntennaMaster.cc:45
Definition: AntennaMaster.h:179
Definition: AntennaDrive.h:43
gcp::antenna::control::AntennaMonitor * AntennaMonitor()
Definition: AntennaMaster.cc:269
Definition: AntNum.h:23
std::string host()
Definition: AntennaMaster.h:402
gcp::antenna::control::AntennaDrive * AntennaDrive()
Definition: AntennaMaster.cc:188