My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
SpecificShare.h
Go to the documentation of this file.
1 #ifndef SPECIFICSHARE_H
2 #define SPECIFICSHARE_H
3 
11 #include <string>
12 
13 #include <pthread.h>
14 
15 #include "gcp/util/common/DoubleBufferVec.h"
16 #include "gcp/util/common/TimeVal.h"
17 
18 #include "gcp/util/common/AntennaDataFrameManager.h"
19 #include "gcp/util/common/QuadPath.h"
20 
21 #include "gcp/antenna/control/specific/PolarEncoderPos.h"
22 #include "gcp/antenna/control/specific/Site.h"
23 
24 // C header files from the array control code
25 
26 #include "gcp/control/code/unix/libunix_src/specific/specificregs.h"
27 #include "gcp/control/code/unix/libunix_src/common/astrom.h"
28 
29 #include "gcp/util/common/Directives.h"
30 
31 namespace gcp {
32  namespace antenna {
33  namespace control {
34 
35  class AcuPort;
36 
42  class SpecificShare : public gcp::util::AntennaDataFrameManager {
43 
44  public:
45 
49  enum TimeOut {
50  NO_WAIT,
51  WAIT_FOREVER
52  };
53 
54  // Define the fundamental hardware tick rate used to
55  // synchronize all antenna tracking A pulse with this period
56  // is distributed to all tracking and receiver hardware to
57  // synchronize antenna positions and data acquisition samples
58 
59  static const unsigned int NANOSECONDS_PER_POSITION = 10000000;
60 
61  //------------------------------------------------------------
62  // An object to manage buffered registers
63  //------------------------------------------------------------
64 
65  struct Block {
66 
67  // Public members
68 
69  SpecificShare* parent_;
70  RegMapBlock* blk_;
71  unsigned nElPerSample_;
72  unsigned nFastElPerFrame_;
73  unsigned nBytePerSample_;
74  unsigned nBytePerEl_;
75  unsigned nBytePerFrame_;
77  unsigned char* bufPtr_;
78  unsigned char* framePtr_;
79 
80  // Methods
81 
82  Block(char* boardName, char* blockName,
83  SpecificShare* parent);
84 
85  virtual ~Block();
86 
87  void buffer(unsigned iSamp, void* data, bool print=false);
88  void buffer(void* data, bool print=false);
89 
90  void switchBuffers();
91  void copyDataToFrame();
92  };
93 
94 
95  //------------------------------------------------------------
96  // SpecificRegDb Object
97  //------------------------------------------------------------
98 
104 
105  public:
106 
112  SpecificRegDb();
113 
117  ~SpecificRegDb();
118 
124  void grabRegs(TimeOut timeout);
125 
131  void ungrabRegs();
132 
136  RegMapBoard* findRegMapBoard(std::string boardName);
137 
150  void flagBoard(int board);
151 
160  void unflagBoard(int board);
161 
175  bool verifyBoard(int board);
176 
177  private:
178 
182  friend class SpecificShare;
183 
187  RegMap *regmap_;
188 
192  pthread_mutex_t guard_;
193 
197  unsigned *shadow_;
201  int nshadow_;
202 
213  unsigned* boardStatusReg(int board);
214 
215  };
216 
217  //------------------------------------------------------------
218  // SpecificClock Object
219  //------------------------------------------------------------
220 
225 
226  public:
227 
231  SpecificClock();
232 
238  ~SpecificClock();
239 
245  void setClock(unsigned long mjd, unsigned long sec,
246  unsigned long nanoSeconds);
247 
253  void setClock(gcp::util::TimeVal& time);
254 
261  void setClock();
262 
268  double getUtc();
269 
270 
271  private:
272 
276  pthread_mutex_t guard_;
277 
278  gcp::util::TimeVal time_;
279  };
280 
281  //----------------------------------------------------------------------
282  // SpecificAstrom Object
283  //------------------------------------------------------------
284 
290 
291  public:
292 
298  SpecificAstrom();
299 
303  ~SpecificAstrom();
304 
310  void setSite(double longitude, double latitude, double altitude);
311 
318 
325  void extendUt1Utc(double utc, double ut1utc);
326 
334  void extendEqnEqx(double tt, double eqneqx);
335 
341  double getUt1Utc(double utc);
342 
349  double getEqnEqx(double tt);
350 
351  private:
352 
356  pthread_mutex_t guard_;
357 
362 
367  gcp::util::QuadPath* ut1utc_;
368 
374  gcp::util::QuadPath* eqneqx_;
375 
376  }; // Class SpecificAstrom
377 
378  //------------------------------------------------------------
379  // SpecificPmacLock Object
380  //------------------------------------------------------------
381 
388 
389  public:
390 
397 
404 
405  private:
406 
410  pthread_mutex_t guard_;
411 
415  int count_;
416 
420  RegMapBoard *pmac_;
421 
425  RegMapBlock *host_read_;
426 
427  }; // End class SpecificPmacLock
428 
429  //------------------------------------------------------------
430  // SpecificShare Methods
431  //------------------------------------------------------------
432 
437  struct HostAddress {
438  char* name;
439  char* address;
440  };
441 
442  // Static members and functions
443 
448 
452  static HostAddress host_address[];
453 
463  static std::string hostIpAddress(std::string host);
464 
472  static void pciBusErrorHandler(int sig);
473 
481  static void pciSegvErrorHandler(int sig);
482 
488  SpecificShare(std::string host);
489 
493  ~SpecificShare();
494 
506  void grabRegs(TimeOut timeout);
507 
513  void ungrabRegs();
514 
515  /*
516  * Flag a board as unreachable. Note that this is called
517  * automatically by read_regdb() and write_regdb() if their
518  * 'check' argument is true and an exception occurs. If
519  * 'check' is false then the caller is expected to perform
520  * exception handling and to call the following function if an
521  * exception occurs.
522  *
523  * @throws Exception
524  */
525  void flagBoard(int board);
526 
527  /*
528  * This function will be called by the scanner task after
529  * successfully reading all registers of a previously flagged
530  * board without incuring an exception. It marks the board as
531  * usable by other tasks.
532  *
533  * @throws Exception
534  */
535  void unflagBoard(int board);
536 
542  bool verifyBoard(int board);
543 
549  double getLst(double utc);
550 
554  double getTt(double lst);
555 
561  double getUtc();
562 
568  void setClock(unsigned long mjd, unsigned long sec,
569  unsigned long nanoSeconds);
570 
576  void setClock(gcp::util::TimeVal& time);
577 
583  void setClock();
584 
585  public:
586 
592  void setSite(double longitude, double latitude, double altitude);
593 
599  double getUt1Utc(double utc);
600 
607  double getEqnEqx(double tt);
608 
615  void extendUt1Utc(double utc, double ut1utc);
616 
624  void extendEqnEqx(double tt, double eqneqx);
625 
629  RegMapBoard* findRegMapBoard(std::string boardName);
630 
636  void freezePmacReadout();
637 
643  void unfreezePmacReadout();
644 
648  unsigned int getNboard();
649 
653  unsigned int getNarchived();
654 
658  unsigned int getNreg();
659 
663  unsigned int getNbyte();
664 
671 
672  void debugTrigger();
673 
674  void setNewFramePending() {newFramePending_ = true;};
675 
676  void clearNewFramePending() {newFramePending_ = false;};
677 
678  bool isNewFramePending() {return newFramePending_;};
679 
680  // Method to add an element to the list of registers being
681  // buffered
682 
683  Block* addBufferedBlock(char* boardName, char* blockName);
684 
685  // Method to copy data to the frame
686 
688 
689  // Method to switch buffers
690 
691  void switchBuffers();
692 
693  private:
694 
695  // A vector of blocks that are currently being buffered
696 
697  std::vector<Block*> bufferedBlocks_;
698 
702  unsigned* tmpbuf_;
703 
707  std::string controlHost_;
708 
712  SpecificRegDb *regdb_;
713 
720  volatile bool newFramePending_;
721 
725  SpecificClock *clock_;
726 
730  SpecificAstrom *astrom_;
731 
735  SpecificPmacLock *pmac_lock_;
736 
737  gcp::util::TimeVal startTime_;
738  gcp::util::TimeVal endTime_;
739 
740  }; // class SpecificShare
741 
742  }; // End namespace control
743  }; // End namespace antenna
744 } // End namespace gcp
745 
746 #endif
double getTt(double lst)
Definition: SpecificShare.cc:1124
void setSite(double longitude, double latitude, double altitude)
Definition: SpecificShare.cc:1191
void flagBoard(int board)
Definition: SpecificShare.cc:180
Definition: Site.h:33
void switchBuffers()
Definition: SpecificShare.cc:1464
void grabRegs(TimeOut timeout)
Definition: SpecificShare.cc:697
Block * addBufferedBlock(char *boardName, char *blockName)
Definition: SpecificShare.cc:1343
void extendEqnEqx(double tt, double eqneqx)
Definition: SpecificShare.cc:929
void extendUt1Utc(double utc, double ut1utc)
Definition: SpecificShare.cc:1200
SpecificClock()
Definition: SpecificShare.cc:365
bool verifyBoard(int board)
Definition: SpecificShare.cc:302
double getUtc()
Definition: SpecificShare.cc:1140
void ungrabRegs()
Definition: SpecificShare.cc:705
void getSite(gcp::antenna::control::Site *site)
Definition: SpecificShare.cc:847
~SpecificShare()
Definition: SpecificShare.cc:655
unsigned int getNarchived()
Definition: SpecificShare.cc:1225
void setClock()
Definition: SpecificShare.cc:461
SpecificRegDb()
Definition: SpecificShare.cc:52
~SpecificAstrom()
Definition: SpecificShare.cc:769
Definition: SpecificShare.h:65
bool verifyBoard(int board)
Definition: SpecificShare.cc:729
void buffer(unsigned iSamp, void *data, bool print=false)
Definition: SpecificShare.cc:1420
void unflagBoard(int board)
Definition: SpecificShare.cc:243
unsigned int getNboard()
Definition: SpecificShare.cc:1217
void grabRegs(TimeOut timeout)
Definition: SpecificShare.cc:131
void switchBuffers()
Definition: SpecificShare.cc:1364
void setClock()
Definition: SpecificShare.cc:1183
void ungrabRegs()
Definition: SpecificShare.cc:153
void copyDataToFrame()
Definition: SpecificShare.cc:1474
static void pciSegvErrorHandler(int sig)
void extendUt1Utc(double utc, double ut1utc)
Definition: SpecificShare.cc:882
~SpecificClock()
Definition: SpecificShare.cc:375
static HostAddress host_address[]
Definition: Share.h:412
static SpecificShare * share
Definition: SpecificShare.h:447
RegMapBoard * findRegMapBoard(std::string boardName)
void extendEqnEqx(double tt, double eqneqx)
Definition: SpecificShare.cc:1209
double getEqnEqx(double tt)
Definition: SpecificShare.cc:1033
double getUt1Utc(double utc)
Definition: SpecificShare.cc:1158
double getUt1Utc(double utc)
Definition: SpecificShare.cc:979
double getUtc()
Definition: SpecificShare.cc:495
DataFrame * frame()
Definition: DataFrameManager.cc:384
Definition: TimeVal.h:55
RegMapBoard * findRegMapBoard(std::string boardName)
Definition: SpecificShare.cc:162
unsigned int getNbyte()
Definition: SpecificShare.cc:1241
double getEqnEqx(double tt)
Definition: SpecificShare.cc:1149
Definition: QuadPath.h:27
static void pciBusErrorHandler(int sig)
Definition: DataFrameManager.h:23
static std::string hostIpAddress(std::string host)
void packFrame(gcp::util::DataFrameManager *frame)
Definition: SpecificShare.cc:1324
void flagBoard(int board)
Definition: SpecificShare.cc:713
void setSite(double longitude, double latitude, double altitude)
Definition: SpecificShare.cc:796
unsigned int getNreg()
Definition: SpecificShare.cc:1233
void copyBufferedBlocksToFrame()
Definition: SpecificShare.cc:1355
Definition: AntennaDataFrameManager.h:22
Block(char *boardName, char *blockName, SpecificShare *parent)
Definition: SpecificShare.cc:1377
void unflagBoard(int board)
Definition: SpecificShare.cc:721
SpecificAstrom()
Definition: SpecificShare.cc:742
~SpecificRegDb()
Definition: SpecificShare.cc:99
double getLst(double utc)
Definition: SpecificShare.cc:1086