CARMA C++
Share.h
1 #ifndef SZA_ANTENNA_SZASHARE_H
2 #define SZA_ANTENNA_SZASHARE_H
3 
11 #include <string>
12 
13 #include <pthread.h>
14 
15 #include "carma/szautil/TimeVal.h"
16 
18 #include "carma/szautil/Mutex.h"
19 #include "carma/szautil/QuadPath.h"
20 
22 #include "carma/antenna/sza/antenna/control/Site.h"
23 
24 // C header files from the array control code
25 
26 #include "carma/szaarrayutils/szaregs.h"
27 #include "carma/szaarrayutils/astrom.h"
28 
29 namespace sza {
30  namespace antenna {
31  namespace control {
32 
38  class SzaShare {
39 
40  public:
41 
45  enum TimeOut {
46  NO_WAIT,
47  WAIT_FOREVER
48  };
49 
53  enum Type {
54  CHAR,
55  UCHAR,
56  SHORT,
57  USHORT,
58  INT,
59  UINT,
60  LONG,
61  ULONG,
62  FLOAT,
63  DOUBLE
64  };
65 
70  struct DataPtr {
71  Type type;
72  void* ptr_;
73  };
74 
75  //------------------------------------------------------------
76  // SzaRegDb Object
77  //------------------------------------------------------------
78 
83  class SzaRegDb {
84 
85  public:
86 
92  SzaRegDb();
93 
97  ~SzaRegDb();
98 
111  void readShadowReg(RegMapBlock *blk, unsigned first,
112  unsigned nreg, DataPtr& value);
113 
127  void writeShadowReg(RegMapBlock *blk, unsigned first,
128  unsigned nreg, Dataptr& value);
129 
135  void grabRegs(TimeOut timeout);
136 
142  void ungrabRegs();
143 
147  RegMapBoard* findRegMapBoard(std::string boardName);
148 
161  void SzaShare::SzaRegDb::flagBoard(int board);
162 
171  void SzaShare::SzaRegDb::unflagBoard(int board);
172 
186  bool SzaShare::SzaRegDb::verifyBoard(int board);
187 
188  private:
189 
193  friend class SzaShare;
194 
198  SzaRegMap* regmap_;
199 
203  sza::util::Mutex guard_;
204 
208  unsigned char* shadow_;
209 
213  int nShadow_;
214 
225  unsigned* SzaShare::SzaRegDb::boardStatusReg(int board);
226 
227  };
228 
229  //------------------------------------------------------------
230  // SzaClock Object
231  //------------------------------------------------------------
232 
236  class SzaClock {
237 
238  public:
239 
243  SzaClock();
244 
250  ~SzaClock();
251 
257  void setClock(unsigned long mjd, unsigned long sec,
258  unsigned long nanoSeconds);
259 
265  void setClock(sza::util::TimeVal& time);
266 
273  void setClock();
274 
280  double getUtc();
281 
282  private:
283 
287  sza::util::Mutex guard_;
288 
289  sza::util::TimeVal time_;
290  };
291 
292  //----------------------------------------------------------------------
293  // SzaAstrom Object
294  //------------------------------------------------------------
295 
300  class SzaAstrom {
301 
302  public:
303 
309  SzaAstrom();
310 
314  ~SzaAstrom();
315 
321  void setSite(double longitude, double latitude, double altitude);
322 
329 
336  void extendUt1Utc(double utc, double ut1utc);
337 
345  void extendEqnEqx(double tt, double eqneqx);
346 
352  double getUt1Utc(double utc);
353 
360  double getEqnEqx(double tt);
361 
362  private:
363 
367  sza::util::Mutex guard_;
368 
373 
378  sza::util::QuadPath* ut1utc_;
379 
385  sza::util::QuadPath* eqneqx_;
386 
387  }; // Class SzaAstrom
388 
389  //------------------------------------------------------------
390  // SzaShare Methods
391  //------------------------------------------------------------
392 
397  struct HostAddress {
398  char* name;
399  char* address;
400  };
401 
402  // Static members and functions
403 
407  static SzaShare* share_;
408 
413 
423  static std::string hostIpAddress(std::string host);
424 
430  SzaShare(std::string host);
431 
435  ~SzaShare();
436 
459  void readReg(RegMapBlock *blk, unsigned first, unsigned nreg,
460  unsigned *value);
461 
477  void readRawReg(RegMapBlock *blk, unsigned first, unsigned nreg,
478  unsigned *value);
479 
494  void writeReg(RegMapBlock* blk, unsigned first, unsigned nreg,
495  signed char* value);
496 
497  void writeReg(RegMapBlock* blk, unsigned first, unsigned nreg,
498  unsigned char* value);
499 
500  void writeReg(RegMapBlock* blk, unsigned first, unsigned nreg,
501  signed short* value);
502 
503  void writeReg(RegMapBlock* blk, unsigned first, unsigned nreg,
504  unsigned short* value);
505 
506  void writeReg(RegMapBlock* blk, unsigned first, unsigned nreg,
507  int* value);
508 
509  void writeReg(RegMapBlock* blk, unsigned first, unsigned nreg,
510  unsigned int* value);
511 
512  void writeReg(RegMapBlock* blk, unsigned first, unsigned nreg,
513  long* value);
514 
515  void writeReg(RegMapBlock* blk, unsigned first, unsigned nreg,
516  unsigned long* value);
517 
518  void writeReg(RegMapBlock *blk, unsigned first, unsigned nreg,
519  float* value);
520 
521  void writeReg(RegMapBlock *blk, unsigned first, unsigned nreg,
522  double* value);
523 
538  void writeRawReg(RegMapBlock* blk, unsigned first, unsigned nreg,
539  unsigned char* value);
540 
541  void writeRawReg(RegMapBlock* blk, unsigned first, unsigned nreg,
542  unsigned short* value);
543 
544  void writeRawReg(RegMapBlock* blk, unsigned first, unsigned nreg,
545  unsigned* value);
546 
547  void writeRawReg(RegMapBlock* blk, unsigned first, unsigned nreg,
548  float* value);
549 
550  void writeRawReg(RegMapBlock* blk, unsigned first, unsigned nreg,
551  double* value);
552 
564  void grabRegs(TimeOut timeout);
565 
571  void ungrabRegs();
572 
573  /*
574  * Flag a board as unreachable. Note that this is called
575  * automatically by read_regdb() and write_regdb() if their
576  * 'check' argument is true and an exception occurs. If
577  * 'check' is false then the caller is expected to perform
578  * exception handling and to call the following function if an
579  * exception occurs.
580  *
581  * @throws Exception
582  */
583  void flagBoard(int board);
584 
585  /*
586  * This function will be called by the scanner task after
587  * successfully reading all registers of a previously flagged
588  * board without incuring an exception. It marks the board as
589  * usable by other tasks.
590  *
591  * @throws Exception
592  */
593  void unflagBoard(int board);
594 
600  bool verifyBoard(int board);
601 
607  double getLst(double utc);
608 
612  double getTt(double lst);
613 
619  double getUtc();
620 
626  void setClock(unsigned long mjd, unsigned long sec,
627  unsigned long nanoSeconds);
628 
634  void setClock(sza::util::TimeVal& time);
635 
641  void setClock();
642 
648  void setSite(double longitude, double latitude, double altitude);
649 
655  double getUt1Utc(double utc);
656 
663  double getEqnEqx(double tt);
664 
671  void extendUt1Utc(double utc, double ut1utc);
672 
680  void extendEqnEqx(double tt, double eqneqx);
681 
685  RegMapBoard* findRegMapBoard(std::string boardName);
686 
690  unsigned int getNboard();
691 
695  unsigned int getNarchived();
696 
703 
704  private:
705 
715  void packRegBoard(RegMapBoard* brd,
717 
721  unsigned char* tmpbuf_;
722 
726  std::string controlHost_;
727 
731  SzaRegDb *regdb_;
732 
736  SzaClock *clock_;
737 
741  SzaAstrom *astrom_;
742 
743  }; // class SzaShare
744 
745  }; // End namespace control
746  }; // End namespace antenna
747 }; // End namespace sza
748 
749 #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
An object of the following type will be used to specify an arbitrary pointer.
Definition: Share.h:70
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
void writeRawReg(RegMapBlock *blk, unsigned first, unsigned nreg, unsigned char *value)
The same as writeReg() but mutual exclusion and exception handling are left up to the caller...
Tagged: Thu Nov 13 16:53:49 UTC 2003.
Class for managing antenna site-specific parameters.
Definition: Site.h:33
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 unflagBoard(int board)
Mark a given register board as reachable.
unsigned int getNboard()
Return the number of boards in the register map.
void readReg(RegMapBlock *blk, unsigned first, unsigned nreg, unsigned *value)
Read one or more elements of a given register from the register database.
void extendEqnEqx(double tt, double eqneqx)
Extend the quadratic interpolation table of the equation of the equinoxes versus Terrestrial Time (as...
unsigned int getNarchived()
Return the number of archived 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.
void writeReg(RegMapBlock *blk, unsigned first, unsigned nreg, signed char *value)
Write one or more elements of a given SZA PCI register, with mutual exlusion and exception handling...
Struct used to store names and IP addresses of trusted hosts.
Definition: Share.h:397
Encapsulate the astrometry details of the array in this class.
Definition: Share.h:300
Tagged: Sat Mar 27 16:28:13 PST 2004.
void setClock()
Set the current time.
double getEqnEqx(double tt)
Get the value of the equation of the equinoxes for a given terrestrial time.
Access to the register database and its shadow registers is provided through an object of the followi...
Definition: Share.h:83
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.
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.
Type
Enumerate valid data types.
Definition: Share.h:53
void writeShadowReg(RegMapBlock *blk, unsigned first, unsigned nreg, Dataptr &value)
A private function of writeReg() and writeRawReg() to write one or more elements of a shadow register...
void readShadowReg(RegMapBlock *blk, unsigned first, unsigned nreg, DataPtr &value)
A private function of readReg() and readRawReg() to read one or more elements of a shadow register...
void extendUt1Utc(double utc, double ut1utc)
Extend the quadratic interpolation table of ut1 - utc versus MJD UTC.
void readRawReg(RegMapBlock *blk, unsigned first, unsigned nreg, unsigned *value)
The same as readReg() but mutual exclusion and exception handling are left up to the caller...
double getUtc()
Get the current UTC as a Modified Julian Date.
static SzaShare * share_
Static pointer for use in signal handlers.
Definition: Share.h:407
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.
Tagged: Fri Nov 14 12:37:53 UTC 2003.
The following structure is used by the SZA UTC clock.
Definition: Share.h:236
void ungrabRegs()
Relinquish exclusive use to the register database.