CARMA C++
SzaShare.h
Go to the documentation of this file.
1 #ifndef SZASHARE_H
2 #define SZASHARE_H
3 
11 #include <string>
12 
13 #include <pthread.h>
14 
15 #include "carma/szautil/TimeVal.h"
16 
18 #include "carma/szautil/QuadPath.h"
19 
21 #include "carma/antenna/sza/antenna/control/Site.h"
22 
23 // C header files from the array control code
24 
25 #include "carma/szaarrayutils/szaregs.h"
26 #include "carma/szaarrayutils/astrom.h"
27 
28 namespace sza {
29  namespace antenna {
30  namespace control {
31 
37  class SzaShare : public sza::util::AntennaDataFrameManager {
38 
39  public:
40 
44  enum TimeOut {
45  NO_WAIT,
46  WAIT_FOREVER
47  };
48 
49  //------------------------------------------------------------
50  // SzaRegDb Object
51  //------------------------------------------------------------
52 
57  class SzaRegDb {
58 
59  public:
60 
61 
67  SzaRegDb();
68 
72  ~SzaRegDb();
73 
79  void grabRegs(TimeOut timeout);
80 
86  void ungrabRegs();
87 
91  RegMapBoard* findRegMapBoard(std::string boardName);
92 
105  void flagBoard(int board);
106 
115  void unflagBoard(int board);
116 
130  bool verifyBoard(int board);
131 
132  private:
133 
137  friend class SzaShare;
138 
142  SzaRegMap *regmap_;
143 
147  pthread_mutex_t guard_;
148 
152  unsigned *shadow_;
156  int nshadow_;
157 
168  unsigned* boardStatusReg(int board);
169 
170  };
171 
172  //------------------------------------------------------------
173  // SzaClock Object
174  //------------------------------------------------------------
175 
179  class SzaClock {
180 
181  public:
182 
186  SzaClock();
187 
193  ~SzaClock();
194 
200  void setClock(unsigned long mjd, unsigned long sec,
201  unsigned long nanoSeconds);
202 
208  void setClock(sza::util::TimeVal& time);
209 
216  void setClock();
217 
223  double getUtc();
224 
225  private:
226 
230  pthread_mutex_t guard_;
231 
232  sza::util::TimeVal time_;
233  };
234 
235  //----------------------------------------------------------------------
236  // SzaAstrom Object
237  //------------------------------------------------------------
238 
243  class SzaAstrom {
244 
245  public:
246 
252  SzaAstrom();
253 
257  virtual ~SzaAstrom();
258 
264  virtual void setSite(double longitude, double latitude, double altitude);
265 
272 
279  void extendUt1Utc(double utc, double ut1utc);
280 
288  void extendEqnEqx(double tt, double eqneqx);
289 
295  double getUt1Utc(double utc);
296 
303  double getEqnEqx(double tt);
304 
305  private:
306 
310  pthread_mutex_t guard_;
311 
316 
321  sza::util::QuadPath* ut1utc_;
322 
328  sza::util::QuadPath* eqneqx_;
329 
330  }; // Class SzaAstrom
331 
332  //------------------------------------------------------------
333  // SzaPmacLock Object
334  //------------------------------------------------------------
335 
341  class SzaPmacLock {
342 
343  public:
344 
351 
357  ~SzaPmacLock();
358 
359  private:
360 
364  pthread_mutex_t guard_;
365 
369  int count_;
370 
374  RegMapBoard *pmac_;
375 
379  RegMapBlock *host_read_;
380 
381  }; // End class SzaPmacLock
382 
383  //------------------------------------------------------------
384  // SzaShare Methods
385  //------------------------------------------------------------
386 
391  struct HostAddress {
392  char* name;
393  char* address;
394  };
395 
396  // Static members and functions
397 
401  static SzaShare* share;
402 
406  static HostAddress host_address[];
407 
417  static std::string hostIpAddress(std::string host);
418 
419  virtual void setTuningPending(bool pending) {};
420 
421 
429  static void pciBusErrorHandler(int sig);
430 
438  static void pciSegvErrorHandler(int sig);
439 
445  SzaShare(std::string host);
446 
450  ~SzaShare();
451 
463  void grabRegs(TimeOut timeout);
464 
470  void ungrabRegs();
471 
472  /*
473  * Flag a board as unreachable. Note that this is called
474  * automatically by read_regdb() and write_regdb() if their
475  * 'check' argument is true and an exception occurs. If
476  * 'check' is false then the caller is expected to perform
477  * exception handling and to call the following function if an
478  * exception occurs.
479  *
480  * @throws Exception
481  */
482  void flagBoard(int board);
483 
484  /*
485  * This function will be called by the scanner task after
486  * successfully reading all registers of a previously flagged
487  * board without incuring an exception. It marks the board as
488  * usable by other tasks.
489  *
490  * @throws Exception
491  */
492  void unflagBoard(int board);
493 
499  bool verifyBoard(int board);
500 
506  virtual double getLst(double utc);
507 
511  double getTt(double lst);
512 
518  double getUtc();
519 
525  void setClock(unsigned long mjd, unsigned long sec,
526  unsigned long nanoSeconds);
527 
533  void setClock(sza::util::TimeVal& time);
534 
540  void setClock();
541 
547  virtual void setSite(double longitude, double latitude, double altitude);
548 
554  double getUt1Utc(double utc);
555 
562  double getEqnEqx(double tt);
563 
570  void extendUt1Utc(double utc, double ut1utc);
571 
579  void extendEqnEqx(double tt, double eqneqx);
580 
584  RegMapBoard* findRegMapBoard(std::string boardName);
585 
591  void freezePmacReadout();
592 
598  void unfreezePmacReadout();
599 
603  unsigned int getNboard();
604 
608  unsigned int getNarchived();
609 
613  unsigned int getNreg();
614 
618  unsigned int getNbyte();
619 
626 
627  RegMap* getRegMap();
628 
629  private:
630 
634  unsigned* tmpbuf_;
635 
639  std::string controlHost_;
640 
644  SzaRegDb *regdb_;
645 
649  SzaClock *clock_;
650 
654  SzaAstrom *astrom_;
655 
659  SzaPmacLock *pmac_lock_;
660 
661  }; // class SzaShare
662 
663  }; // End namespace control
664  }; // End namespace antenna
665 }; // End namespace sza
666 
667 #endif
void setClock()
Fill the internal time representation with the current time.
bool verifyBoard(int board)
Return the value of the status register of a given register board.
void packFrame(sza::util::DataFrameManager *frame)
Public method to pack a frame.
void getSite(sza::antenna::control::Site *site)
Get a copy of the SZA site-specification object.
DataFrame * frame()
Return a handle to the raw data frame managed by this object.
A class to handle quadrature interpolation of ephemerides received from the control program...
Definition: QuadPath.h:27
double getLst(double utc)
Get the Local Sidereal Time that corresponds to a given MJD UTC.
A class for managing timeval/timespec structs.
Definition: TimeVal.h:53
static void pciBusErrorHandler(int sig)
This is a signal handler for trapping bus and address errors while readReg() and writeReg() access PC...
void grabRegs(TimeOut timeout)
Acquire exclusive access to the database.
static std::string hostIpAddress(std::string host)
Validate a specified IP address or host-name alias, and return a malloc&#39;d copy of the resulting IP ad...
double getTt(double lst)
Get the terrestrial time as MJD.
RegMapBoard * findRegMapBoard(std::string boardName)
Return a pointer to the requested register.
void extendUt1Utc(double utc, double ut1utc)
Extend the quadratic interpolation table of ut1 - utc versus MJD UTC.
This is a base class for managing a generic dataframe of registers.
double getUt1Utc(double utc)
Get the value of UT1-UTC for a given UTC.
Tagged: Fri Nov 14 12:39:38 UTC 2003.
TimeOut
Enumerate supported timeouts.
Definition: Share.h:45
Tagged: Thu Nov 13 16:53:49 UTC 2003.
Class for managing antenna site-specific parameters.
Definition: Site.h:33
void freezePmacReadout()
Freeze the pmac readout.
void setSite(double longitude, double latitude, double altitude)
Record new site-location details in share-&gt;site.
RegMapBoard * findRegMapBoard(std::string boardName)
Look up a board in the register map.
double getUtc()
Return the Utc as MJD.
void unfreezePmacReadout()
Un-freeze the pmac readout.
void unflagBoard(int board)
Mark a given register board as reachable.
unsigned int getNboard()
Return the number of boards in the register map.
static SzaShare * share
Static pointer for use in signal handlers.
Definition: SzaShare.h:401
void extendEqnEqx(double tt, double eqneqx)
Extend the quadratic interpolation table of the equation of the equinoxes versus Terrestrial Time (as...
Tagged: Sat Mar 20 05:20:30 UTC 2004.
unsigned int getNarchived()
Return the number of archived registers in the register map.
unsigned int getNreg()
Return the total number of registers in the register map.
double getUt1Utc(double utc)
Get the value of UT1-UTC for a given UTC.
void grabRegs(TimeOut timeout)
Acquire exlusive use of the register database.
void flagBoard(int board)
Flag a given register board as unreachable.
Struct used to store names and IP addresses of trusted hosts.
Definition: Share.h:397
void setClock()
Set the current time.
SzaPmacLock(SzaShare *share)
Constructor.
The following structure encapsulates the reader lock used to prevent clashes when freezing and unfree...
Definition: SzaShare.h:341
double getEqnEqx(double tt)
Get the value of the equation of the equinoxes for a given terrestrial time.
double getEqnEqx(double tt)
Get the value of the equation of the equinoxes for a given terrestrial time.
bool verifyBoard(int board)
Return false if a board is flagged as unreachable.
static void pciSegvErrorHandler(int sig)
This is a signal handler for trapping bus and address errors while readReg() and writeReg() access PC...
void extendEqnEqx(double tt, double eqneqx)
Extend the quadratic interpolation table of the equation of the equinoxes versus Terrestrial Time (as...
Tagged: Thu Nov 13 16:53:48 UTC 2003.
void setSite(double longitude, double latitude, double altitude)
Public function to set the site parameters.
void extendUt1Utc(double utc, double ut1utc)
Extend the quadratic interpolation table of ut1 - utc versus MJD UTC.
double getUtc()
Get the current UTC as a Modified Julian Date.
static HostAddress host_address[]
An array of trusted hosts.
Definition: Share.h:412
An instance of this class is created by AntennaMaster and passed to the constructors of other tasks...
Definition: Share.h:38
void ungrabRegs()
Release the database.
SzaShare(std::string host)
Constructor.
unsigned int getNbyte()
Return the number of bytes.
void ungrabRegs()
Relinquish exclusive use to the register database.