nidas  v1.2-1520
TwoD_USB.h
Go to the documentation of this file.
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2 // vim: set shiftwidth=4 softtabstop=4 expandtab:
3 /*
4  ********************************************************************
5  ** NIDAS: NCAR In-situ Data Acquistion Software
6  **
7  ** 2007, Copyright University Corporation for Atmospheric Research
8  **
9  ** This program is free software; you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation; either version 2 of the License, or
12  ** (at your option) any later version.
13  **
14  ** This program is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** The LICENSE.txt file accompanying this software contains
20  ** a copy of the GNU General Public License. If it is not found,
21  ** write to the Free Software Foundation, Inc.,
22  ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  **
24  ********************************************************************
25 */
26 
27 #ifndef _nidas_dynld_raf_2d_usb_h_
28 #define _nidas_dynld_raf_2d_usb_h_
29 
30 #include <nidas/core/DSMSensor.h>
32 
35 
37 
38 namespace nidas { namespace dynld { namespace raf {
39 
40 using namespace nidas::core;
41 
46 class TwoD_USB : public DSMSensor, public DerivedDataClient
47 {
48 
49 public:
50  TwoD_USB();
51  ~TwoD_USB();
52 
53  IODevice *buildIODevice() throw(nidas::util::IOException);
54 
55  SampleScanner *buildSampleScanner()
57 
61  void open(int flags)
63 
64  void close() throw(nidas::util::IOException);
65 
66  int getTASRate() const { return _tasRate; }
67 
68  void setTASRate(int val) { _tasRate = val; }
69 
76  float getResolution() const { return _resolutionMeters; }
77 
84  unsigned int getResolutionMicron() const { return _resolutionMicron; }
85 
92  virtual int NumberOfDiodes() const = 0;
93 
97  void init() throw(nidas::util::InvalidParameterException);
98 
99  virtual void
100  derivedDataNotify(const nidas::core:: DerivedDataReader * s)
101  throw();
102 
103  void printStatus(std::ostream& ostr) throw();
104 
111  // virtual int TASToTap2D(Tap2D * t2d, float tas);
112  virtual int TASToTap2D(void * t2d, float tas);
113 
124  virtual float
125  Tap2DToTAS(const Tap2D * t2d) const;
130  virtual float
131  Tap2DToTAS(const Tap2Dv1 * t2d) const;
132 
133 
134 protected:
135  class Particle
136  {
137  public:
138  Particle() : height(0), width(0), area(0), edgeTouch(0), liveTime(0), dofReject(false) { } ;
139  void zero() { height = width = area = liveTime = 0; edgeTouch = 0; dofReject = false; }
140 
142  unsigned int height;
144  unsigned int width;
149  unsigned int area;
154  unsigned char edgeTouch;
159  unsigned int liveTime;
160 
162  bool dofReject;
163  } ;
164 
165  // Probe produces Big Endian.
167 
168  // Tap2D value sent back from driver has little endian ntap value
170 
174  virtual void init_parameters()
175  throw(nidas::util::InvalidParameterException);
176 
181  virtual void sendTrueAirspeed(float tas) throw(nidas::util::IOException);
182 
190  virtual void processParticleSlice(Particle& p, const unsigned char * slice);
191 
197  virtual void countParticle(const Particle& p, float resolutionUsec);
198 
200 
205  virtual bool acceptThisParticle1D(const Particle& p) const;
206  virtual bool acceptThisParticle2D(const Particle& p) const;
208 
210 
218  virtual void createSamples(dsm_time_t nextTimeTag,std::list<const Sample *>&results) throw();
219 
223  virtual void clearData();
225 
232  int _tasRate;
233 
237  unsigned int _numImages;
238 
242  long long _lastStatusTime;
243 
245 
248  float _resolutionMeters;
249 
253  unsigned int _resolutionMicron;
255 
257 
268 
269  dsm_sample_id_t _1dcID, _2dcID;
271 
273 
276  unsigned int * _size_dist_1D;
277  unsigned int * _size_dist_2D;
278 
284  float _dead_time;
286 
288 
291  unsigned int _totalRecords;
292  unsigned int _totalParticles;
293  unsigned int _rejected1D_Cntr, _rejected2D_Cntr;
294  unsigned int _overLoadSliceCount;
295  unsigned int _overSizeCount_2D;
296  unsigned int _tasOutOfRange;
297  unsigned int _misAligned;
298  unsigned int _suspectSlices;
299  unsigned int _recordsPerSecond;
301 
303  unsigned int _totalPixelsShadowed;
304 
308  dsm_time_t _prevTime;
309 
311  long long _histoEndTime;
312 
318  float _twoDAreaRejectRatio;
319 
324  Particle _particle;
325 
329  float _trueAirSpeed;
330 
337  int _nextraValues;
338 
347  void saveBuffer(const unsigned char * cp, const unsigned char * eod);
348 
359  void setupBuffer(const unsigned char ** cp, const unsigned char ** eod);
360 
364  unsigned char * _saveBuffer;
365 
369  int _savedBytes;
370 
374  int _savedAlloc;
375 
376  static const float DefaultTrueAirspeed;
377 
378 private:
379 
381  TwoD_USB(const TwoD_USB&);
382 
384  TwoD_USB& operator=(const TwoD_USB&);
385 };
386 
387 
388 template <typename T, typename V>
389 inline
390 void
391 stream_histogram(T& out, V* sizedist, unsigned int nbins)
392 {
393  bool zeros = true;
394  for (unsigned int i = 0; i < nbins; ++i)
395  {
396  if (sizedist[i] == 0)
397  {
398  out << ".";
399  zeros = true;
400  }
401  else if (zeros)
402  {
403  out << sizedist[i];
404  zeros = false;
405  }
406  else
407  {
408  out << ",";
409  out << sizedist[i];
410  }
411  }
412 }
413 
414 }}} // namespace nidas namespace dynld namespace raf
415 
416 #endif
Definition: TwoD_USB.h:135
Struct to adjust probe slice rate for true airspeed.
Definition: usbtwod.h:69
int getTASRate() const
Definition: TwoD_USB.h:66
unsigned int getResolutionMicron() const
The probe resolution in micrometers.
Definition: TwoD_USB.h:84
unsigned int dsm_sample_id_t
Definition: Sample.h:63
unsigned int width
Max particle length, along flight path.
Definition: TwoD_USB.h:144
bool dofReject
Depth Of Field Reject? Last bit of sync word.
Definition: TwoD_USB.h:162
long long dsm_time_t
Posix time in microseconds, the number of non-leap microseconds since 1970 Jan 1 00:00 UTC...
Definition: Sample.h:61
static const nidas::util::EndianConverter * bigEndian
Definition: TwoD_USB.h:166
unsigned int area
Actual number of shadowed diodes.
Definition: TwoD_USB.h:149
This version is for rev2 of Spowarts USB board.
Definition: usbtwod.h:84
float getResolution() const
The probe resolution in meters.
Definition: TwoD_USB.h:76
void setTASRate(int val)
Definition: TwoD_USB.h:68
unsigned int liveTime
Amount of time consumed by the particle as it passed through the array.
Definition: TwoD_USB.h:159
void zero()
Definition: TwoD_USB.h:139
Virtual base class declaring methods for converting numeric values between little-endian and big-endi...
Definition: EndianConverter.h:304
unsigned int height
Max particle height, along diode array.
Definition: TwoD_USB.h:142
Particle()
Definition: TwoD_USB.h:138
unsigned char edgeTouch
Was an edge diode triggered.
Definition: TwoD_USB.h:154
An interface to an IO device.
Definition: IODevice.h:41
Interface to a data sample.
Definition: Sample.h:189
DSMSensor provides the basic support for reading, processing and distributing samples from a sensor a...
Definition: DSMSensor.h:87
Definition: IOException.h:37
A scanner of sample data.
Definition: SampleScanner.h:73
static const nidas::util::EndianConverter * littleEndian
Definition: TwoD_USB.h:169
This class will read, parse and make available the parameters in the onboard real-time broadcast of d...
Definition: DerivedDataReader.h:44
Base class for PMS 2D particle probes on a USB interface.
Definition: TwoD_USB.h:46
Interface of a DerivedDataClient of the DerivedDataReader.
Definition: DerivedDataClient.h:37
Definition: InvalidParameterException.h:35
void stream_histogram(T &out, V *sizedist, unsigned int nbins)
Definition: TwoD_USB.h:391