pxar
 All Classes Namespaces Functions Variables Typedefs Friends
helper.h
1 /* This file contains helper classes which are used by API and DUT
2  implementations to search API objects for certain properties */
3 
4 #ifndef PXAR_HELPER_H
5 #define PXAR_HELPER_H
6 
8 #if ((defined WIN32) && (defined __CINT__))
9 typedef int int32_t;
10 typedef short int int16_t;
11 typedef unsigned int uint32_t;
12 typedef unsigned short int uint16_t;
13 typedef unsigned char uint8_t;
14 #else
15 #include <stdint.h>
16 #endif
17 
18 #ifdef WIN32
19 #ifdef __CINT__
20 #include <Windows4Root.h>
21 #else
22 #include <Windows.h>
23 #endif // __CINT__
24 #else
25 #include <unistd.h>
26 #endif // WIN32
27 
28 #include "api.h"
29 
30 #include <algorithm>
31 #include <string>
32 #include <vector>
33 #include <sstream>
34 #include <iomanip>
35 
36 namespace pxar {
40  void inline mDelay(uint32_t ms) {
41  // Wait for the given time in milliseconds:
42 #ifdef WIN32
43  Sleep(ms);
44 #else
45  usleep(ms*1000);
46 #endif
47  }
48 
52  {
53  const bool _isEnable;
54 
55  public:
56  configEnableSet(const bool pEnable) : _isEnable(pEnable) {}
57 
58  template<class ConfigType>
59  bool operator()(const ConfigType &config) const
60  {
61  return config.enable() == _isEnable;
62  }
63  };
64 
68  {
69  const bool _isMasked;
70 
71  public:
72  configMaskSet(const bool pMask) : _isMasked(pMask) {}
73 
74  template<class ConfigType>
75  bool operator()(const ConfigType &config) const
76  {
77  return config.mask() == _isMasked;
78  }
79  };
80 
84  {
85  const uint8_t _column;
86  const uint8_t _row;
87  const uint8_t _roc;
88  const bool _check_roc;
89 
90  public:
91  findPixelXY(const uint8_t pColumn, const uint8_t pRow)
92  : _column(pColumn), _row(pRow), _roc(0), _check_roc(false) {}
93  findPixelXY(const uint8_t pColumn, const uint8_t pRow, const uint8_t pRoc)
94  : _column(pColumn), _row(pRow), _roc(pRoc), _check_roc(true) {}
95 
96  template<class ConfigType>
97  bool operator()(const ConfigType &config) const
98  {
99  if(_check_roc) return (config.row() == _row) && (config.column() == _column) && (config.roc() == _roc);
100  return (config.row() == _row) && (config.column() == _column);
101  }
102  };
103 
104 
109  {
110  const uint8_t _column;
111  const uint8_t _row;
112 
113  public:
114  findPixelBeyondXY(const uint8_t pColumn, const uint8_t pRow) : _column(pColumn), _row(pRow) {}
115 
116  template<class ConfigType>
117  bool operator()(const ConfigType &config) const
118  {
119  return (config.row() > _row) || (config.column() > _column);
120  }
121  };
122 
125  class findRoc
126  {
127  const uint8_t _i2c_address;
128 
129  public:
130  findRoc(const uint8_t pI2cAddress) : _i2c_address(pI2cAddress) {}
131 
132  template<class ConfigType>
133  bool operator()(const ConfigType &config) const
134  {
135  return (config.i2c_address == _i2c_address);
136  }
137  };
138 
141  bool inline comparePixelConfiguration(const std::vector<pixelConfig> pxA, const std::vector<pixelConfig> pxB) {
142 
143  // Check the number of enabled pixels:
144  if(pxA.size() != pxB.size()) return false;
145 
146  // Check the single pixels:
147  for(std::vector<pixelConfig>::const_iterator pixit = pxA.begin(); pixit != pxA.end(); pixit++){
148  if(std::count_if(pxB.begin(), pxB.end(), findPixelXY(pixit->column(),pixit->row())) != 1) { return false; }
149  }
150  return true;
151  }
152 
156  template <typename T>
157  std::string listVector(std::vector<T> vec, bool hex = false) {
158  std::stringstream os;
159  if(hex) { os << std::hex; }
160  for(typename std::vector<T>::iterator it = vec.begin(); it != vec.end(); ++it) {
161  if(hex) os << std::setw(4) << std::setfill('0');
162  os << static_cast<int>(*it) << " ";
163  }
164  if(hex) { os << std::dec; }
165  return os.str();
166  }
167 
170  std::string inline listFlags(uint32_t flags) {
171  std::stringstream os;
172 
173  // No flags given:
174  if(flags == 0) return "(0) ";
175 
176  if((flags&FLAG_FORCE_SERIAL) != 0) { os << "FLAG_FORCE_SERIAL, "; flags -= FLAG_FORCE_SERIAL; }
177  if((flags&FLAG_CALS) != 0) { os << "FLAG_CALS, "; flags -= FLAG_CALS; }
178  if((flags&FLAG_XTALK) != 0) { os << "FLAG_XTALK, "; flags -= FLAG_XTALK; }
179  if((flags&FLAG_RISING_EDGE) != 0) { os << "FLAG_RISING_EDGE, "; flags -= FLAG_RISING_EDGE; }
180  if((flags&FLAG_FORCE_MASKED) != 0) { os << "FLAG_FORCE_MASKED (obsolete), "; flags -= FLAG_FORCE_MASKED; }
181  if((flags&FLAG_DISABLE_DACCAL) != 0) { os << "FLAG_DISABLE_DACCAL, "; flags -= FLAG_DISABLE_DACCAL; }
182  if((flags&FLAG_NOSORT) != 0) { os << "FLAG_NOSORT, "; flags -= FLAG_NOSORT; }
183  if((flags&FLAG_CHECK_ORDER) != 0) { os << "FLAG_CHECK_ORDER, "; flags -= FLAG_CHECK_ORDER; }
184  if((flags&FLAG_FORCE_UNMASKED) != 0) { os << "FLAG_FORCE_UNMASKED, "; flags -= FLAG_FORCE_UNMASKED; }
185 
186  if(flags != 0) os << "Unknown flag: " << flags;
187  return os.str();
188  }
189 
190 }
191 #endif
std::string listFlags(uint32_t flags)
Definition: helper.h:170
bool comparePixelConfiguration(const std::vector< pixelConfig > pxA, const std::vector< pixelConfig > pxB)
Definition: helper.h:141
std::string listVector(std::vector< T > vec, bool hex=false)
Definition: helper.h:157
void mDelay(uint32_t ms)
Definition: helper.h:40