My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
BoardDataFrameManager.h
Go to the documentation of this file.
1 // $Id: BoardDataFrameManager.h,v 1.1.1.1 2009/07/06 23:57:25 eml Exp $
2 
3 #ifndef GCP_UTIL_BOARDDATAFRAMEMANAGER_H
4 #define GCP_UTIL_BOARDDATAFRAMEMANAGER_H
5 
15 #include "gcp/util/common/Complex.h"
16 #include "gcp/util/common/RegMapDataFrameManager.h"
17 
18 #include "gcp/control/code/unix/libunix_src/common/scanner.h"
19 
20 #include <iostream>
21 
22 namespace gcp {
23  namespace util {
24 
25  //-----------------------------------------------------------------------
26  // Class definition for BoardDataFrameManager. Manages a data
27  // frame which represents the data for a single board of a
28  // register map
29  //-----------------------------------------------------------------------
30 
32  public:
33 
37  BoardDataFrameManager(std::string regmap, std::string board,
38  bool archivedOnly=false);
39 
43  virtual ~BoardDataFrameManager();
44 
48  RegMapBlock* getReg(std::string block);
49 
50  // Pack data of an arbitrary type into the underlying frame
51 
52  template<class type>
53  void writeBoardReg(RegMapBlock* blk, type* data, CoordRange* range=0,
54  bool lock=true);
55 
56  template<class type>
57  void writeBoardReg(std::string block, type* data, CoordRange* range=0,
58  bool lock=true);
59 
60  template<class type>
61  void readBoardReg(RegMapBlock* blk, type* data, CoordRange* range=0,
62  bool lock=true);
63 
64  template<class type>
65  void readBoardReg(std::string block, type* data, CoordRange* range=0,
66  bool lock=true);
67 
68 
69  // Return the offset in bytes of the data for the requested and
70  // register, from the beginning of the frame buffer.
71 
72  int byteOffsetInFrameOf(RegMapBlock* blk, Coord* coord);
73  int byteOffsetInFrameOf(RegMapBlock* blk, CoordRange* range=0);
74 
75  RegMapBoard* board() {return brd_;}
76  ArrRegMap* regmap() {return arrRegMap_;}
77 
78  void incrementRecord();
79 
80  void setReceived(bool recv);
81 
82  void setMjd(RegDate& date);
83 
84  protected:
85 
86  ArrRegMap* arrRegMap_;
87  RegMapBoard* brd_;
88 
89  private:
90 
91  unsigned record_;
92 
93  }; // End class BoardDataFrameManager
94 
95 
96  //-----------------------------------------------------------------------
97  // Implementation
98  //-----------------------------------------------------------------------
99 
103  template <class type>
105  writeBoardReg(std::string block, type* data, CoordRange* range,
106  bool lockFrame)
107  {
108  RegMapBlock* blk = 0;
109  blk = brd_->findRegMapBlock(block);
110 
111  if(blk==0) {
112  ThrowError("Block: " << block << " not found in board: " <<
113  brd_->name);
114  }
115 
116  writeBoardReg(blk, data, range, lockFrame);
117  }
118 
122  template <class type>
124  writeBoardReg(RegMapBlock* blk, type* data, CoordRange* range,
125  bool lockFrame)
126  {
127  DataType::Type dataType = DataType::typeOf(data);
128 
129  // Calculate the byte offset of the start element of this
130  // register
131  // from the head of the frame.
132 
133  int byteOffset = byteOffsetInFrameOf(blk);
134 
135  // Do nothing if this register isn't archived
136 
137  if(byteOffset < 0)
138  return;
139 
140  // If the number of bytes was passed as 0, use the default
141  // from the block descriptor
142 
143  AxisRange axisRange(blk->axes_, range);
144  frame_->pack((void*)data, axisRange, dataType, byteOffset, lockFrame);
145  }
146 
150  template <class type>
152  readBoardReg(std::string block, type* data, CoordRange* range,
153  bool lockFrame)
154  {
155  RegMapBlock* blk = 0;
156  blk = brd_->findRegMapBlock(block);
157 
158  if(blk==0) {
159  ThrowError("Block: " << block << " not found in board: " <<
160  brd_->name);
161  }
162 
163  readBoardReg(blk, data, range, lockFrame);
164  }
165 
169  template <class type>
171  readBoardReg(RegMapBlock* blk, type* data, CoordRange* range,
172  bool lockFrame)
173  {
174  DataType::Type dataType = DataType::typeOf(data);
175 
176  // Calculate the byte offset of the start element of this
177  // register
178  // from the head of the frame.
179 
180  int byteOffset = byteOffsetInFrameOf(blk);
181 
182  // Do nothing if this register isn't archived
183 
184  if(byteOffset < 0)
185  return;
186 
187  // If the number of bytes was passed as 0, use the default
188  // from the block descriptor
189 
190  AxisRange axisRange(blk->axes_, range);
191  frame_->unpack((void*)data, axisRange, dataType, byteOffset, lockFrame);
192  }
193 
194  } // End namespace util
195 } // End namespace gcp
196 
197 
198 
199 #endif // End #ifndef GCP_UTIL_BOARDDATAFRAMEMANAGER_H
static Type typeOf(RegMapBlock *blk)
Definition: DataType.cc:223
Definition: BoardDataFrameManager.h:31
void pack(void *data, AxisRange &range, DataType::Type type, unsigned iStart, bool lockFrame=true)
Definition: DataFrame.cc:118
Definition: AxisRange.h:19
BoardDataFrameManager(std::string regmap, std::string board, bool archivedOnly=false)
Definition: BoardDataFrameManager.cc:14
void writeBoardReg(RegMapBlock *blk, type *data, CoordRange *range=0, bool lock=true)
Definition: BoardDataFrameManager.h:124
void unpack(void *data, AxisRange &range, DataType::Type type, unsigned iStart, bool lockFrame=true)
Definition: DataFrame.cc:854
void readBoardReg(RegMapBlock *blk, type *data, CoordRange *range=0, bool lock=true)
Definition: BoardDataFrameManager.h:171
Definition: arraymap.h:63
void setMjd()
Definition: RegMapDataFrameManager.cc:2433
Definition: Coord.h:21
Definition: CoordRange.h:20
RegMapBlock * getReg(std::string block)
Definition: BoardDataFrameManager.cc:64
void lock()
Definition: DataFrameManager.cc:406
virtual ~BoardDataFrameManager()
Definition: BoardDataFrameManager.cc:54
Definition: RegDate.h:19
int byteOffsetInFrameOf(RegMapBlock *blk, Coord *coord)
Definition: BoardDataFrameManager.cc:91
Definition: RegMapDataFrameManager.h:26