CARMA C++
AntennaMaster.h
Go to the documentation of this file.
1 #ifndef ANTENNAMASTER_H
2 #define ANTENNAMASTER_H
3 
11 // C++ includes
12 
13 #include <string>
14 #include <vector>
15 
16 // C includes
17 
18 #include <signal.h>
19 
20 // The base class include
21 
22 #include "carma/szautil/AntNum.h"
23 #include "carma/szautil/Directives.h"
26 
27 // SZA includes
28 
33 
34 #define ANTENNA_HEARTBEAT_SIGNAL SIGRTMIN+1
35 #define ANTENNA_DRIVE_SIGNAL SIGRTMIN+2
36 #define ANTENNA_MONITOR_SIGNAL SIGRTMIN+3
37 #define STROBE_PMAC_SIGNAL SIGRTMIN+4
38 #define CONNECT_SIGNAL SIGRTMIN+5
39 
40 // This timer will cause parent tasks to send a heartbeat request to
41 // their children
42 
43 #define ANTENNA_HEARTBEAT_SEC 5
44 
45 // Every second, the pmac will be sent new positions.
46 
47 #define ANTENNA_DRIVE_SEC 1
48 
49 // The drive system strobe will fire a quarter second out of sync with
50 // the pmac data strobe, so that data from PMAC DPRAM are already in
51 // shared memory when the monitoring data strobe arrives.
52 
53 #define ANTENNA_DRIVE_DELAY_NSEC 500000000 // Delay after the integral
54  // second boundary. On
55  // receipt of this signal,
56  // the tracker task will
57  // deliver a new commanded
58  // position to the pmac,
59  // valid 1.5 seconds in the
60  // future.
61 
62 // We will read out the entire shared memory object every half-second.
63 
64 #define ANTENNA_MONITOR_NSEC 500000000 // 2Hz data pulse
65 
66 // Every half-second, we will read out the pmac DPRAM into shared
67 // memory, in preparation for the data strobe which will cause the
68 // shared memory to be read and sent back to the control computer. We
69 // don't want to read the DPRAM on the strobe, because the
70 // interlocking and readout operations from the pmac can be slow.
71 
72 #define STROBE_PMAC_NSEC 500000000
73 
74 // The pmac strobe will fire a quarter second out of sync with the
75 // data strobe, so that data from PMAC DPRAM are already in shared
76 // memory when the data strobe arrives.
77 
78 #define STROBE_PMAC_DELAY_NSEC 250000000 // Delay after the integral
79  // second boundary. This
80  // puts the pmac strobe out
81  // of sync with the monitor
82  // strobe by a quarter
83  // second.
84 
85 #define CONNECT_SEC 2 // Connect timer
86 
87 #define ANTENNAMASTER_TASK_FWD_FN(fn) void (fn)(AntennaMasterMsg* msg)
88 
89 namespace sza {
90  namespace antenna {
91  namespace control {
92 
97  class AntennaDrive;
98  class AntennaControl;
99  class AntennaMonitor;
100  class AntennaRx;
101  class UmacControl;
102 
110  class AntennaMaster :
111  public SzaTask,
112  public sza::util::GenericMasterTask<AntennaMasterMsg> {
113 
114  public:
115 
121  AntennaMaster(std::string host,
122  std::string nameServer,
123  const std::string& objectName,
124  std::string eventServer,
125  const std::string& eventChannelName,
126  std::string notifyServer,
127  bool simulateCanbus,
128  const sza::util::AntNum& antNum,
129  bool simPmac=false,
130  unsigned ifNodeId=1,
131  bool connect=true,
132  bool newcaltert=true,
133  unsigned nArg=0,
134  char** argv=0,
135  bool ignoreWrapLogic=true);
136 
142  ~AntennaMaster();
143 
147  sza::antenna::control::AntennaControl* AntennaControl();
148 
153 
158 
163 
168 
174  void restartServices();
175 
176  //------------------------------------------------------------
177  // Public methods for sending messages to this task.
178  //------------------------------------------------------------
179 
184  SIGNALTASK_HANDLER_FN(doNothing);
185 
192  static SIGNALTASK_HANDLER_FN(sendSendHeartBeatMsg);
193 
199  static SIGNALTASK_HANDLER_FN(sendShutDownMsg);
200 
205  static SIGNALTASK_HANDLER_FN(sendPackDataFrameMsg);
206 
212  static SIGNALTASK_HANDLER_FN(sendDriveTickMsg);
213 
219  static SIGNALTASK_HANDLER_FN(sendConnectControlMsg);
220 
226  static SIGNALTASK_HANDLER_FN(sendConnectPmacMsg);
227 
233  static SIGNALTASK_HANDLER_FN(sendConnectScannerMsg);
234 
240  static SIGNALTASK_HANDLER_FN(sendStrobePmacMsg);
241 
248  void sendAdoptBoardMsg(unsigned short, AntennaTask::Id taskId);
249 
250  //------------------------------------------------------------
251  // Communications methods
252  //------------------------------------------------------------
253 
257  static ANTENNAMASTER_TASK_FWD_FN(forwardMasterMsg);
258 
259  //------------------------------------------------------------
260  // Public accessor methods
261  //------------------------------------------------------------
262 
267  SzaShare* getShare();
268 
273 
277  inline std::string host() {return host_;}
278 
282  inline std::string nameServer() {return nameServer_;}
283 
288  inline std::string objectName() {return objectName_;}
289 
293  inline std::string eventServer() {return eventServer_;}
294 
298  inline std::string notifyServer() {return notifyServer_;}
299 
304  inline std::string eventChannelName() {return eventChannelName_;}
305 
306  inline unsigned getIFNodeId() {
307  return ifNodeId_;
308  }
309 
310  void setArgs(unsigned nArg, char** argv);
311  std::vector<std::string> getArgs();
312 
313  bool newCaltert() {
314  return newCaltert_;
315  }
316 
317  bool ignoreWrapLogic() {
318  return ignoreWrapLogic_;
319  }
320 
321  private:
322 
323  bool newCaltert_;
324 
325  // Argument string passed to the main program which
326  // instantiated this object
327 
328  unsigned int nArg_;
329  std::vector<std::string> args_;
330 
331  unsigned ifNodeId_;
332 
333  // True if connecting to the control system
334 
335  bool connect_;
336 
340  bool simPmac_;
341 
342  // True if ignoring wrap logic
343 
344  bool ignoreWrapLogic_;
345 
349  static AntennaMaster* master_;
350 
354  sza::util::AntNum* antNum_;
355 
359  std::string host_;
360 
364  std::string nameServer_;
365 
370  std::string objectName_;
371 
375  std::string eventServer_;
376 
380  std::string notifyServer_;
381 
386  std::string eventChannelName_;
387 
388  //------------------------------------------------------------
389  // Thread management methods
390  //------------------------------------------------------------
391 
392 #if DIR_HAVE_CARMA
393 
396  static THREAD_START(startAntennaCanBus);
397 #endif
398 
402  static THREAD_START(startAntennaDrive);
403 
407  static THREAD_START(startAntennaMonitor);
408 
412  static THREAD_START(startAntennaControl);
413 
417  static THREAD_START(startAntennaRx);
418 
422  static THREAD_START(startAntennaSignal);
423 
427  static THREAD_START(startUmacControl);
428 
429  //------------------------------------------------------------
430  // Thread cleanup handlers methods
431 
435  static THREAD_CLEAN(cleanAntennaDrive);
436 
440  static THREAD_CLEAN(cleanAntennaMonitor);
441 
445  static THREAD_CLEAN(cleanAntennaCanbus);
446 
450  static THREAD_CLEAN(cleanAntennaControl);
451 
455  static THREAD_CLEAN(cleanAntennaRx);
456 
460  static THREAD_CLEAN(cleanAntennaSignal);
461 
465  static THREAD_CLEAN(cleanUmacControl);
466 
467  //------------------------------------------------------------
468  // Ping routines for the (pingable) subsystem threads
469 
475  static THREAD_PING(pingAntennaControl);
476 
482  static THREAD_PING(pingAntennaDrive);
483 
489  static THREAD_PING(pingAntennaMonitor);
490 
496  static THREAD_PING(pingAntennaRx);
497 
498  //------------------------------------------------------------
499  // Pointers to the subsystem resources. These pointers are
500  // initialized by the subsystem threads on startup
501 
506  sza::antenna::control::AntennaControl* controlTask_;
507 
512 
517 
522 
526  sza::antenna::control::UmacControl* umacControlTask_;
527 
528  //------------------------------------------------------------
529  // Members pertaining to communication with this task
530 
538  void processMsg(AntennaMasterMsg* taskMsg);
539 
540  //------------------------------------------------------------
541  // Message forwarding methods. These are private, as they
542  // should not be used directly by tasks to send messages to
543  // each other, or they will run the risk of a message getting
544  // dropped if these methods are called before the recipient's
545  // queue exists.
546  //
547  // Messages to all tasks should be sent to the master, whose
548  // message queue is guaranteed to exist before any other tasks
549  // are spawned, and which will not service messages until all
550  // spawned tasks have allocated their resources. This
551  // guarantees that no messages will be lost, but simply queued
552  // until the master calls its serviceMsgQ() method.
553 
557  static ANTENNAMASTER_TASK_FWD_FN(forwardControlMsg);
558 
562  static ANTENNAMASTER_TASK_FWD_FN(forwardDriveMsg);
563 
567  static ANTENNAMASTER_TASK_FWD_FN(forwardMonitorMsg);
568 
572  static ANTENNAMASTER_TASK_FWD_FN(forwardRxMsg);
573 
577  static ANTENNAMASTER_TASK_FWD_FN(forwardUmacControlMsg);
578 
584  ANTENNAMASTER_TASK_FWD_FN(**brd_fns_);
585 
589  void initBoardFlagging();
590 
591  //------------------------------------------------------------
592  // Private send methods for messages intended for the
593  // AntennaMaster
594  //------------------------------------------------------------
595 
602 
608  void recordAdoption(AntennaMasterMsg* msg);
609 
616  void flagBoard(AntennaMasterMsg* msg);
617 
618  //------------------------------------------------------------
619  // Methods pertaining to timers managed by this task
620 
624  void sendHeartBeat();
625 
629  void installTimers();
630 
634  void installSignals();
635 
636  }; // End class AntennaMaster
637 
638  }; // End namespace control
639  }; // End namespace antenna
640 }; // End namespace sza
641 
642 #endif
A class to enumerate a single Antenna, or a set of Antennas.
Definition: AntNum.h:21
SIGNALTASK_HANDLER_FN(doNothing)
A no-op signal handler for signals we wish to explicitly disable.
sza::antenna::control::AntennaControl * AntennaControl()
Return a pointer to the Control task resources.
std::string objectName()
A copy of the CORBA object name that the nameserver will associate with us.
Tagged: Thu Nov 13 16:53:31 UTC 2003.
std::string host()
A copy of the Nameserver name to which we will attach.
sza::antenna::control::AntennaMonitor * AntennaMonitor()
Return a pointer to the Monitor task resources.
Define a class for sending snapshots of the antenna state back to the control program for archiving...
std::string nameServer()
A copy of the Nameserver name to which we will attach.
sza::antenna::control::AntennaRx * AntennaRx()
Return a pointer to the Receiver task resources.
Tagged: Thu Nov 13 16:53:54 UTC 2003.
std::string eventChannelName()
A copy of the event channel name on which we will send data back to the outside world.
void restartServices()
Public interface to startThreads()
void sendRestartMsg()
Method to send a stop message to this task via its message queue.
Definition: GenericTask.h:423
AntennaRx class will handle all receiver functions.
Definition: AntennaRx.h:55
sza::antenna::control::UmacControl * UmacControl()
Return a pointer to the Receiver task resources.
AntennaRx class will handle all receiver functions.
Definition: UmacControl.h:36
std::string notifyServer()
A copy of the Notifyserver name to which we will attach.
Tagged: Fri Nov 14 12:39:31 UTC 2003.
Tagged: Tue Jul 6 17:41:36 PDT 2004.
Tagged: Thu Nov 13 16:53:29 UTC 2003.
static void() forwardMasterMsg(AntennaMasterMsg *msg)
Public method by which other tasks can forward message to us.
sza::antenna::control::AntennaDrive * AntennaDrive()
Return a pointer to the Drive control task resources.
Tagged: Fri Nov 14 12:39:36 UTC 2003.
void sendAdoptBoardMsg(unsigned short, AntennaTask::Id taskId)
Method by which other tasks can ask us for control of boards.
std::string eventServer()
A copy of the Eventserver name to which we will attach.
sza::util::AntNum * getAnt()
Public method to get a reference to our antenna enumerator.
Id
An enumerator to identify a valid antenna task.
Definition: AntennaTask.h:25
AntennaMaster(std::string host, std::string nameServer, const std::string &objectName, std::string eventServer, const std::string &eventChannelName, std::string notifyServer, bool simulateCanbus, const sza::util::AntNum &antNum, bool simPmac=false, unsigned ifNodeId=1, bool connect=true, bool newcaltert=true, unsigned nArg=0, char **argv=0, bool ignoreWrapLogic=true)
Constructor.
The AntennaDrive collects together the functionality of the base class Drive and its descendants...
Definition: AntennaDrive.h:43
Tagged: Thu Nov 13 16:53:54 UTC 2003.
SzaShare * getShare()
Public method to get a reference to our shared resource object.
An instance of this class is created by AntennaMaster and passed to the constructors of other tasks...
Definition: Share.h:38
Define a class to encapsulate the entire Antenna control system.