CARMA C++
regtemplate.h
1 #ifndef regtemplate_h
2 #define regtemplate_h
3 
4 /* ***** PLEASE READ BEFORE MAKING MODIFICATIONS *****
5  * If you make ANY modifications to the register template
6  * which make it incompatible with older archived register
7  * map templates, you must increment the REGMAP_REVISION
8  * macro at the top of regmap.h.
9  */
10 #include <utility>
11 #include <string>
12 #include <vector>
13 
14 /*
15  * This file defines the templates required by new_RegMap() for
16  * creating register maps. The resulting register map, and
17  * accompanying objects are defined in regmap.h.
18  */
19 #include "carma/szaarrayutils/regmap.h"
20 
21 #define ARRAY_DIM(array) (sizeof(array)/sizeof((array)[0]))
22 
23 /*
24  * Each board can have up to NBASE base addresses. The choice of
25  * NBASE is arbitrary. Note, however, that if you change it, you
26  * must also change REGMAP_REVISION in regmap.h.
27  */
28 typedef enum {
29  REG_BASE0, /* To select the base address in RegBoardTemp::bases[0] */
30  REG_BASE1, /* To select the base address in RegBoardTemp::bases[1] */
31  REG_BASE2, /* To select the base address in RegBoardTemp::bases[2] */
32  REG_BASE3, /* To select the base address in RegBoardTemp::bases[3] */
33  NBASE /* The dimension of RegBoardTemp::bases[] */
34 } RegBase;
35 
36 /*
37  * The VME registers of a given board are specified via an array
38  * of the following type. This is a template for creation of a
39  * RegBlock object.
40  */
41 struct RegBlockTemp {
42  char name_[REG_NAME_LEN+1]; // The name of the block of registers
43  unsigned flags_; // A bit-set of RegFlags enumerators
44  RegAddrMode addr_mode_; // The addressing mode of the register
45  RegBase base_; // Use the base-address in board->bases[base]
46  unsigned address_; // The address of the block in the address
47  // space given by addr_mode (0 for REG_LOCAL)
48  sza::util::CoordAxes* axes_; // An axis specifier for this register
49  std::string* comment_;
50  std::string* carmaUnits_;
51  std::vector<std::pair<std::string, std::string> >* carmaErrors_;
52  unsigned carmaFlags_;
53  int carmaValidityBitIndex_; // Sequential index into the CARMA
54  // validity array of the start of this
55  // block
56 
57  //------------------------------------------------------------
58  // Methods associated with this struct
59  //------------------------------------------------------------
60 
61  // A constructor
62 
63  RegBlockTemp(std::string comment, std::string name,
64  unsigned flags, unsigned address,
65  unsigned nel0, unsigned nel1, unsigned nel2,
66  std::string carmaUnits,
67  std::vector<std::pair<std::string, std::string> >& errPairs);
68 
69  RegBlockTemp(std::string comment, std::string name,
70  unsigned flags, unsigned address=0,
71  unsigned nel0=1, unsigned nel1=0, unsigned nel2=0,
72  std::string carmaUnits="",
73  std::string carmaErrLow1="", std::string carmaErrHigh1="",
74  std::string carmaErrLow2="", std::string carmaErrHigh2="",
75  std::string carmaErrLow3="", std::string carmaErrHigh3="",
76  int carmaValidityBitIndex=-1);
77 
78  RegBlockTemp(const RegBlockTemp& reg);
79  RegBlockTemp(RegBlockTemp& reg);
80 
81  void setTo(std::string comment, std::string name,
82  unsigned flags, unsigned address,
83  unsigned nel0, unsigned nel1, unsigned nel2,
84  std::string carmaUnits,
85  std::vector<std::pair<std::string, std::string> >& errPairs,
86  int carmaValidityBitIndex=-1);
87 
88  void initialize();
89 
90  void operator=(const RegBlockTemp& reg);
91  void operator=(RegBlockTemp& reg);
92 
93  // Destructor
94 
95  ~RegBlockTemp();
96 
97  // Return the total number of register elements
98 
99  unsigned nEl();
100 
101  // Return the number of bytes per element of this register
102 
103  unsigned nBytePerEl();
104 
105  // Return the size in bytes of this register
106 
107  unsigned sizeInBytes();
108 
109  // Return true if the block type matches
110 
111  bool isBool();
112  bool isUchar();
113  bool isString();
114  bool isChar();
115  bool isUshort();
116  bool isShort();
117  bool isUint();
118  bool isInt();
119  bool isFloat();
120  bool isDouble();
121  bool isComplex();
122 };
123 
124 /*
125  * Each board of registers is described by an element of the following
126  * type.
127  */
128 typedef struct {
129  char name_[REG_NAME_LEN+1]; // An unambiguous name for the board
130  RegBlockTemp* blocks_; // The registers of the board
131  int nblock_; // The number of register blocks in blocks[]
132  unsigned bases_[NBASE]; // An array of up to NBASE base addresses
133  char comment_[100];
134 } RegBoardTemp;
135 
139 typedef struct {
140  RegBoardTemp *boards; // The array of register-board maps
141  unsigned nboard; // The number of elements in boards[]
142  char comment_[100];
143 } RegTemplate;
144 
145 RegMap *net_get_RegMap(sza::array::NetBuf *net);
146 
147 /* NB. del_RegMap() is prototyped in regmap.h */
148 
149 int net_put_RegTemplate(RegTemplate *regtmp, sza::array::NetBuf *net);
150 RegTemplate *net_get_RegTemplate(sza::array::NetBuf *net, unsigned long arraymap_revision);
151 long net_RegTemplate_size(RegTemplate *regtmp);
152 
153 /*
154  * The following destructor should only be applied the dynamically
155  * allocated templates that are returned by net_get_RegTemplate().
156  */
157 RegTemplate *del_RegTemplate(RegTemplate *regtmp);
158 
159 #endif
Class for managing coordinate axes.
Definition: CoordAxes.h:25
......................................................................
Definition: regtemplate.h:139