nidas  v1.2-1520
DSMSensor.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  ** 2004, 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 #ifndef NIDAS_CORE_DSMSENSOR_H
27 #define NIDAS_CORE_DSMSENSOR_H
28 
29 #include "SampleClient.h"
30 #include "SampleSourceSupport.h"
31 #include "SampleScanner.h"
32 #include "SampleTag.h"
33 #include "IODevice.h"
34 #include "DOMable.h"
35 #include "Dictionary.h"
36 #include "VariableIndex.h"
37 
38 #include <nidas/util/IOException.h>
40 
41 #include <xmlrpcpp/XmlRpc.h>
42 
43 #include <string>
44 #include <list>
45 
46 #include <fcntl.h>
47 
48 namespace nidas { namespace core {
49 
50 class DSMConfig;
51 class Parameter;
52 class CalFile;
53 class Looper;
54 
87 class DSMSensor : public SampleSource, public SampleClient, public DOMable
88 {
89 
90 public:
91 
96  DSMSensor();
97 
98  virtual ~DSMSensor();
99 
103  void setDSMConfig(const DSMConfig* val);
104 
108  const DSMConfig* getDSMConfig() const
109  {
110  return _dsm;
111  }
112 
116  const Site* getSite() const;
117 
123  virtual void setDeviceName(const std::string& val)
124  {
125  _devname = val;
126  }
127 
132  virtual const std::string& getDeviceName() const
133  {
134  return _devname;
135  }
136 
143  virtual void setClassName(const std::string& val)
144  {
145  _className = val;
146  }
147 
151  virtual const std::string& getClassName() const
152  {
153  return _className;
154  }
155 
159  virtual void setCatalogName(const std::string& val)
160  {
161  _catalogName = val;
162  }
163 
167  virtual const std::string& getCatalogName() const
168  {
169  return _catalogName;
170  }
171 
175  const std::string& getDSMName() const;
176 
183  virtual std::string getName() const
184  {
185  return getDSMName() + ':' + getDeviceName();
186  }
187 
193  const std::string& getLocation() const;
194 
195  void setLocation(const std::string& val) { _location = val; }
196 
209  const std::string& getSuffix() const { return _suffix; }
210 
211  void setSuffix(const std::string& val);
212 
213  int getStation() const
214  {
215  return _station;
216  }
217 
218  void setStation(int val);
219 
229  void setHeight(const std::string& val);
230 
238  void setHeight(float val);
239 
244  const std::string& getHeightString() const { return _heightString; }
245 
250  float getHeight() const { return _height; }
251 
261  void setDepth(const std::string& val);
262 
271  void setDepth(float val);
272 
277  const std::string& getDepthString() const { return _depthString; }
278 
283  float getDepth() const { return -_height; }
284 
292  const std::string& getFullSuffix() const { return _fullSuffix; }
293 
301  std::string expandString(const std::string& input) const
302  {
303  return _dictionary.expandString(input);
304  }
305 
310  bool getTokenValue(const std::string& token,std::string& value) const
311  {
312  return _dictionary.getTokenValue(token,value);
313  }
314 
315  const Dictionary& getDictionary() const
316  {
317  return _dictionary;
318  }
319 
327  {
328  return &_rawSource;
329  }
330 
336  {
337  return this;
338  }
339 
345  const SampleTag* getRawSampleTag() const
346  {
347  return &_rawSampleTag;
348  }
349 
362  virtual void addSampleTag(SampleTag* val)
364 
368  virtual void removeSampleTag(SampleTag* val) throw();
369 
373  std::list<const SampleTag*> getSampleTags() const
374  {
375  return _source.getSampleTags();
376  }
377 
381  std::list<SampleTag*>& getSampleTags()
382  {
383  return _sampleTags;
384  }
385 
387  {
388  return SampleTagIterator(this);
389  }
390 
396  void addSampleClient(SampleClient* c) throw()
397  {
398  return _source.addSampleClient(c);
399  }
400 
407  {
408  return _source.removeSampleClient(c);
409  }
410 
416  void addSampleClientForTag(SampleClient* client,const SampleTag* tag) throw()
417  {
418  return _source.addSampleClientForTag(client,tag);
419  }
420 
426  void removeSampleClientForTag(SampleClient* client,const SampleTag* tag) throw()
427  {
428  return _source.removeSampleClientForTag(client,tag);
429  }
430 
434  int getClientCount() const throw()
435  {
436  return _source.getClientCount();
437  }
438 
443  void flush() throw() {}
444 
449  void distributeRaw(const Sample* s) throw()
450  {
452  }
453 
455  {
456  return _source.getSampleStats();
457  }
458 
459  virtual int getReadFd() const
460  {
461  if (_iodev) return _iodev->getReadFd();
462  return -1;
463  }
464 
465  virtual int getWriteFd() const
466  {
467  if (_iodev) return _iodev->getWriteFd();
468  return -1;
469  }
470 
476  virtual bool reopenOnIOException() const { return true; }
477 
484  void setId(dsm_sample_id_t val) { _id = SET_FULL_ID(_id,val); }
485  void setSensorId(unsigned int val) { _id = SET_SPS_ID(_id,val); }
486  void setDSMId(unsigned int val) { _id = SET_DSM_ID(_id,val); }
487 
494  dsm_sample_id_t getId() const { return GET_FULL_ID(_id); }
495  unsigned int getDSMId() const { return GET_DSM_ID(_id); }
496  unsigned int getSensorId() const { return GET_SPS_ID(_id); }
497 
507  virtual void setLatency(float val)
509  {
510  _latency = val;
511  }
512 
513  virtual float getLatency() const { return _latency; }
514 
524  virtual void setTimeoutMsecs(int val)
525  {
526  _timeoutMsecs = val;
527  }
528 
529  virtual int getTimeoutMsecs() const
530  {
531  return _timeoutMsecs;
532  }
533 
534  int getTimeoutCount() const
535  {
536  return _nTimeouts;
537  }
538 
540  {
541  _nTimeouts++;
542  }
543 
550  void addParameter(Parameter* val);
551 
555  const std::list<const Parameter*>& getParameters() const
556  {
557  return _constParameters;
558  }
559 
564  const Parameter* getParameter(const std::string& name) const;
565 
570  virtual IODevice* buildIODevice() throw(nidas::util::IOException) = 0;
571 
577  {
578  _iodev = val;
579  }
580 
586  throw(nidas::util::InvalidParameterException) = 0;
587 
593  {
594  _scanner = val;
595  }
596 
601  virtual void validate() throw(nidas::util::InvalidParameterException);
602 
606  virtual void open(int flags)
607  throw(nidas::util::IOException,nidas::util::InvalidParameterException);
608 
618  virtual void init() throw(nidas::util::InvalidParameterException);
619 
624  virtual int getDefaultMode() const
625  {
626  return _defaultMode;
627  }
628 
629  virtual void setDefaultMode(int val)
630  {
631  _defaultMode = val;
632  }
633 
638  virtual size_t getBytesAvailable() const
639  throw(nidas::util::IOException)
640  {
641  return _iodev->getBytesAvailable();
642  }
643 
648  virtual size_t read(void *buf, size_t len)
650  {
651  return _iodev->read(buf,len);
652  }
653 
657  virtual size_t read(void *buf, size_t len,int msecTimeout)
659  {
660  return _iodev->read(buf,len,msecTimeout);
661  }
662 
667  virtual size_t write(const void *buf, size_t len)
669  {
670  return _iodev->write(buf,len);
671  }
672 
678  virtual void ioctl(int request, void* buf, size_t len)
680  {
681  _iodev->ioctl(request,buf,len);
682  }
683 
687  virtual void close() throw(nidas::util::IOException);
688 
700  virtual bool readSamples()
701  throw(nidas::util::IOException);
702 
707  virtual Sample* nextSample()
708  {
709  return _scanner->nextSample(this);
710  }
711 
715  virtual Sample* readSample()
716  throw(nidas::util::IOException);
717 
728  bool receive(const Sample *s) throw();
729 
736  virtual bool process(const Sample*,std::list<const Sample*>& result)
737  throw() = 0;
738 
739  void printStatusHeader(std::ostream& ostr) throw();
740  virtual void printStatus(std::ostream&) throw();
741  void printStatusTrailer(std::ostream& ostr) throw();
742 
748  void calcStatistics(unsigned int periodUsec)
749  {
750  if (_scanner) _scanner->calcStatistics(periodUsec);
751  }
752 
753  unsigned int getMaxSampleLength() const
754  {
755  if (_scanner) return _scanner->getMaxSampleLength();
756  return 0;
757  }
758 
759  unsigned int getMinSampleLength() const
760  {
761  if (_scanner) return _scanner->getMinSampleLength();
762  return 0;
763  }
764 
766  {
768  return 0.0;
769  }
770 
771  float getObservedDataRate() const
772  {
773  if (_scanner) return _scanner->getObservedDataRate();
774  return 0.0;
775  }
776 
777  size_t getBadTimeTagCount() const
778  {
779  if (_scanner) return _scanner->getBadTimeTagCount();
780  return 0;
781  }
782 
784 
790  static const std::string getClassName(const xercesc::DOMElement* node,
791  const Project* project)
793 
794  void fromDOMElement(const xercesc::DOMElement*)
795  throw(nidas::util::InvalidParameterException);
796 
797  xercesc::DOMElement*
798  toDOMParent(xercesc::DOMElement* parent,bool complete) const
799  throw(xercesc::DOMException);
800 
801  xercesc::DOMElement*
802  toDOMElement(xercesc::DOMElement* node,bool complete) const
803  throw(xercesc::DOMException);
804 
811  virtual void setTypeName(const std::string& val)
812  {
813  _typeName = val;
814  }
815 
819  virtual const std::string& getTypeName(void) const
820  {
821  return _typeName;
822  }
823 
833  bool getDuplicateIdOK() const
834  {
835  return _duplicateIdOK;
836  }
837 
841  void setDuplicateIdOK(bool val)
842  {
843  _duplicateIdOK = val;
844  }
845 
846  virtual bool getApplyVariableConversions() const
847  {
849  }
850 
851  virtual void setApplyVariableConversions(bool val)
852  {
854  }
855 
856  virtual int getDriverTimeTagUsecs() const
857  {
858  return _driverTimeTagUsecs;
859  }
860 
861  virtual void setDriverTimeTagUsecs(int val)
862  {
863  _driverTimeTagUsecs = val;
864  }
865 
871  void addCalFile(CalFile* val);
872 
876  const std::map<std::string,CalFile*>& getCalFiles()
877  {
878  return _calFiles;
879  }
880 
884  CalFile* getCalFile(const std::string& name);
885 
889  void removeCalFiles();
890 
897  virtual void executeXmlRpc(XmlRpc::XmlRpcValue&, XmlRpc::XmlRpcValue&)
898  throw() {}
899 
900  static void deleteLooper();
901 
907  virtual const std::list<SampleTag*>& getNonConstSampleTags()
908  {
909  return _sampleTags;
910  }
911 
912 
913  bool allowOpen()
914  {
915  return _openable;
916  }
917 
921  bool readBuffer() throw(nidas::util::IOException)
922  {
923  bool exhausted;
924  _scanner->readBuffer(this,exhausted);
925  return exhausted;
926  }
927 
931  bool readBuffer(int msecTimeout)
933  {
934  bool exhausted;
935  _scanner->readBuffer(this,exhausted, msecTimeout);
936  return exhausted;
937  }
938 
939 
940 protected:
941 
945  void clearBuffer()
946  {
948  }
949 
950 
951  IODevice* getIODevice() const { return _iodev; }
952 
954 
955  void setFullSuffix(const std::string& val) { _fullSuffix = val; }
956 
962  static Looper* getLooper();
963 
981  virtual int getLagUsecs() const
982  {
983  return _lag;
984  }
989  virtual double getLagSecs() const
990  {
991  return (double)_lag / USECS_PER_SEC;
992  }
993 
1019  virtual void setLagSecs(double val)
1020  {
1021  _lag = (int) rint(val * USECS_PER_SEC);
1022  }
1023 
1047  void
1048  applyConversions(SampleTag* stag, SampleT<float>* outs, float* results=0);
1049 
1058  void
1059  trimUnparsed(SampleTag* stag, SampleT<float>* outs, int nparsed);
1060 
1067  findVariableIndex(const std::string& vprefix);
1068 
1079 
1080 
1081 private:
1082 
1087  void addSampleTag(const SampleTag* val)
1089 
1094  void removeSampleTag(const SampleTag* val) throw();
1095 
1096  std::string _devname;
1097 
1098  class MyDictionary : public Dictionary {
1099  public:
1100  MyDictionary(DSMSensor* sensor): _sensor(sensor) {}
1103  {
1104  if (&rhs != this) {
1105  *(Dictionary*)this = rhs;
1106  _sensor = rhs._sensor;
1107  }
1108  return *this;
1109  }
1110  bool getTokenValue(const std::string& token, std::string& value) const;
1111  private:
1113  } _dictionary;
1114 
1115 
1117 
1119 
1124  std::string _className;
1125 
1126  std::string _catalogName;
1127 
1131  std::string _suffix;
1132 
1133  std::string _heightString;
1134 
1135  std::string _depthString;
1136 
1137  float _height;
1138 
1142  std::string _fullSuffix;
1143 
1144  std::string _location;
1145 
1147 
1148  const DSMConfig* _dsm;
1149 
1155 
1157 
1158  std::list<SampleTag*> _sampleTags;
1159 
1161 
1163 
1164  // toggle flag for zebra striping printStatus
1165  static bool zebra;
1166 
1167  float _latency;
1168 
1172  std::map<std::string,Parameter*> _parameters;
1173 
1178  std::list<const Parameter*> _constParameters;
1179 
1180  std::map<std::string,CalFile*> _calFiles;
1181 
1182  std::string _typeName;
1183 
1185 
1187 
1189 
1191 
1193 
1194  static Looper* _looper;
1195 
1197 
1198  int _lag;
1199 
1201 
1202 private:
1203 
1204  // no copying
1205  DSMSensor(const DSMSensor& x);
1206 
1207  // no assignment
1208  DSMSensor& operator=(const DSMSensor& x);
1209 
1210 };
1211 
1212 }} // namespace nidas namespace core
1213 
1214 #endif
float getObservedDataRate() const
Definition: DSMSensor.h:771
void setLocation(const std::string &val)
Definition: DSMSensor.h:195
virtual void calcStatistics(unsigned int periodUsec)
Update the sensor sampling statistics: samples/sec, bytes/sec, min/max sample size, that can be accessed via getObservedSamplingRate(), getObservedDataRate() etc.
Definition: SampleScanner.cc:193
SampleScanner * _scanner
Definition: DSMSensor.h:1146
std::string _location
Definition: DSMSensor.h:1144
std::string _className
Class name attribute of this sensor.
Definition: DSMSensor.h:1124
void setDepth(const std::string &val)
Set sensor depth below ground via a string which is added to variable names.
Definition: DSMSensor.cc:232
std::list< SampleTag * > _sampleTags
Definition: DSMSensor.h:1158
A class for reading ASCII files containing a time series of calibration data.
Definition: CalFile.h:164
Interface for a Dictionary class, which can return a string value for a string token name...
Definition: Dictionary.h:38
void flush()
Implementation of SampleClient::flush().
Definition: DSMSensor.h:443
SampleScanner * getSampleScanner() const
Definition: DSMSensor.h:953
std::string _depthString
Definition: DSMSensor.h:1135
#define GET_DSM_ID(tid)
Definition: Sample.h:81
int _nTimeouts
Definition: DSMSensor.h:1192
virtual void ioctl(int request, void *buf, size_t len)
Perform an ioctl on the device.
Definition: DSMSensor.h:678
static void deleteLooper()
Definition: DSMSensor.cc:927
virtual bool reopenOnIOException() const
Whether to reopen this sensor on an IOException.
Definition: DSMSensor.h:476
virtual double getLagSecs() const
Return the sampling lag for this sensor in seconds.
Definition: DSMSensor.h:989
#define SET_DSM_ID(tid, val)
Definition: Sample.h:82
unsigned int dsm_sample_id_t
Definition: Sample.h:63
const SampleStats & getSampleStats() const
Definition: DSMSensor.h:454
MyDictionary & operator=(const MyDictionary &rhs)
Definition: DSMSensor.h:1102
virtual int getDriverTimeTagUsecs() const
Definition: DSMSensor.h:856
virtual void setDriverTimeTagUsecs(int val)
Definition: DSMSensor.h:861
void setId(dsm_sample_id_t val)
Set the various levels of the sensor identification.
Definition: DSMSensor.h:484
virtual std::string getName() const
Return a name that should fully identify this sensor.
Definition: DSMSensor.h:183
virtual int getWriteFd() const =0
The file descriptor used when writing to this sensor.
int _defaultMode
Definition: DSMSensor.h:1118
void printStatusTrailer(std::ostream &ostr)
Definition: DSMSensor.cc:518
virtual size_t write(const void *buf, size_t len)=0
Write to the sensor.
virtual const std::string & getCatalogName() const
Fetch the name of the catalog entry for this sensor.
Definition: DSMSensor.h:167
const DSMConfig * getDSMConfig() const
What DSMConfig am I associated with?
Definition: DSMSensor.h:108
A measurement site.
Definition: Site.h:49
#define GET_FULL_ID(tid)
Definition: Sample.h:78
virtual void setDefaultMode(int val)
Definition: DSMSensor.h:629
int getTimeoutCount() const
Definition: DSMSensor.h:534
bool _applyVariableConversions
Definition: DSMSensor.h:1188
float _height
Definition: DSMSensor.h:1137
Looper is a Thread that periodically loops, calling the LooperClient::looperNotify() method of Looper...
Definition: Looper.h:51
const std::list< const Parameter * > & getParameters() const
Get list of parameters.
Definition: DSMSensor.h:555
bool _openable
Whether this sensor is allowed to be opened.
Definition: DSMSensor.h:1078
virtual void setTypeName(const std::string &val)
Set the type name of this sensor, e.g.
Definition: DSMSensor.h:811
virtual void printStatus(std::ostream &)
Definition: DSMSensor.cc:522
float getObservedSamplingRate() const
Definition: SampleScanner.cc:208
bool _duplicateIdOK
Definition: DSMSensor.h:1186
std::string expandString(const std::string &input) const
Utility function to expand ${TOKEN} or $TOKEN fields in a string with their value from getTokenValue(...
Definition: DSMSensor.h:301
#define SET_FULL_ID(tid, val)
Definition: Sample.h:79
SampleSourceSupport _rawSource
Definition: DSMSensor.h:1160
SampleSource * getRawSampleSource()
Implementation of SampleSource::getRawSampleSource().
Definition: DSMSensor.h:326
Definition: DSMSensor.h:1098
Class that should include all that is configurable about a DSM.
Definition: DSMConfig.h:55
Pure virtual interface for a source of Samples.
Definition: SampleSource.h:48
Class for iterating over the Variables of a Project, Site, DSMConfig, DSMSensor, or SampleTag...
Definition: NidsIterators.h:286
void addSampleClientForTag(SampleClient *client, const SampleTag *tag)
Add a SampleClient to this SampleSource.
Definition: DSMSensor.h:416
void setSuffix(const std::string &val)
Definition: DSMSensor.cc:182
virtual Sample * readSample()
Return the next sample.
Definition: DSMSensor.cc:386
virtual void setDeviceName(const std::string &val)
Set the name of the system device that the sensor is connected to.
Definition: DSMSensor.h:123
bool getTokenValue(const std::string &token, std::string &value) const
Definition: DSMSensor.cc:458
size_t getBadTimeTagCount() const
Definition: DSMSensor.h:777
void setFullSuffix(const std::string &val)
Definition: DSMSensor.h:955
virtual const std::string & getDeviceName() const
Fetch the name of the system device that the sensor is connected to.
Definition: DSMSensor.h:132
unsigned int getMaxSampleLength() const
Definition: DSMSensor.h:753
void addParameter(Parameter *val)
Add a parameter to this DSMSensor.
Definition: DSMSensor.cc:299
DSMSensor * _sensor
Definition: DSMSensor.h:1112
dsm_sample_id_t _id
Id of this sensor.
Definition: DSMSensor.h:1154
virtual size_t read(void *buf, size_t len, int msecTimeout)
Read from the device with a timeout.
Definition: DSMSensor.h:657
Interface of an object that can be instantiated from a DOM element, via the fromDOMElement method...
Definition: DOMable.h:51
float getObservedDataRate() const
Definition: SampleScanner.cc:216
IODevice * _iodev
Definition: DSMSensor.h:1116
A source of samples.
Definition: SampleSourceSupport.h:47
xercesc::DOMElement * toDOMElement(xercesc::DOMElement *node, bool complete) const
Add my content into a DOMElement.
Definition: DSMSensor.cc:895
std::string expandString(const std::string &input) const
Utility function that scans a string for tokens like ${XXXX}, or $XXX followed by any characters from...
Definition: Dictionary.cc:33
void removeSampleClient(SampleClient *c)
Remove a SampleClient from this SampleSource This will also remove a SampleClient if it has been adde...
Definition: SampleSourceSupport.cc:88
float getObservedSamplingRate() const
Definition: DSMSensor.h:765
virtual IODevice * buildIODevice()=0
Factory method for an IODevice for this DSMSensor.
unsigned int getDSMId() const
Definition: DSMSensor.h:495
void setStation(int val)
Definition: DSMSensor.cc:172
void removeSampleClientForTag(SampleClient *c, const SampleTag *)
Add a SampleClient to this SampleSource.
Definition: SampleSourceSupport.cc:121
virtual size_t getBytesAvailable() const
How many bytes are available to read on this sensor.
Definition: DSMSensor.h:638
void addSampleClient(SampleClient *c)
Add a SampleClient to this SampleSource.
Definition: SampleSourceSupport.cc:80
Pure virtual interface of a client of Samples.
Definition: SampleClient.h:38
const DSMConfig * _dsm
Definition: DSMSensor.h:1148
void fromDOMElement(const xercesc::DOMElement *)
Initialize myself from a xercesc::DOMElement.
Definition: DSMSensor.cc:571
void setSensorId(unsigned int val)
Definition: DSMSensor.h:485
std::map< std::string, Parameter * > _parameters
Map of parameters by name.
Definition: DSMSensor.h:1172
dsm_sample_id_t getId() const
Get the various levels of the samples identification.
Definition: DSMSensor.h:494
void printStatusHeader(std::ostream &ostr)
Definition: DSMSensor.cc:492
bool readBuffer()
Read into my SampleScanner&#39;s buffer.
Definition: DSMSensor.h:921
float _latency
Definition: DSMSensor.h:1167
const std::string & getDepthString() const
Get sensor depth below ground in a string.
Definition: DSMSensor.h:277
virtual void setLagSecs(double val)
Set the sampling lag for this sensor in seconds.
Definition: DSMSensor.h:1019
const SampleTag * getRawSampleTag() const
Convenience function to get my one-and-only raw SampleTag().
Definition: DSMSensor.h:345
const SampleStats & getSampleStats() const
Definition: SampleSourceSupport.h:149
bool receive(const Sample *s)
A DSMSensor can be used as a SampleClient, meaning it receives its own raw samples.
Definition: DSMSensor.cc:397
virtual int getReadFd() const
Definition: DSMSensor.h:459
void removeSampleClient(SampleClient *c)
Remove a SampleClient from this SampleSource This will also remove a SampleClient if it has been adde...
Definition: DSMSensor.h:406
SampleSource * getProcessedSampleSource()
Implementation of SampleSource::getProcessedSampleSource().
Definition: DSMSensor.h:335
std::string _devname
Definition: DSMSensor.h:1096
MyDictionary(const MyDictionary &x)
Definition: DSMSensor.h:1101
static Looper * getLooper()
Fetch a pointer to a static instance of a Looper thread.
Definition: DSMSensor.cc:908
virtual float getLatency() const
Definition: DSMSensor.h:513
virtual ~DSMSensor()
Definition: DSMSensor.cc:81
virtual void setTimeoutMsecs(int val)
Set the sensor timeout value in milliseconds.
Definition: DSMSensor.h:524
const std::map< std::string, CalFile * > & getCalFiles()
Return the collection of CalFiles, mapped by name.
Definition: DSMSensor.h:876
std::list< const SampleTag * > getSampleTags() const
Implementation of SampleSource::getSampleTags().
Definition: DSMSensor.h:373
VariableIterator getVariableIterator() const
Definition: DSMSensor.cc:141
virtual void validate()
validate() is called once on a DSMSensor after it has been configured, but before open() or init() ar...
Definition: DSMSensor.cc:833
float getHeight() const
Get sensor height above ground.
Definition: DSMSensor.h:250
virtual void open(int flags)
Open the device.
Definition: DSMSensor.cc:334
virtual SampleScanner * buildSampleScanner()=0
Factory method for a SampleScanner for this DSMSensor.
std::string _catalogName
Definition: DSMSensor.h:1126
virtual void executeXmlRpc(XmlRpc::XmlRpcValue &, XmlRpc::XmlRpcValue &)
Method invoked when the DSMEngineIntf XmlRpcServer receives a &quot;SensorAction&quot; request, with a &quot;device&quot; string matching the string that this DSMSensor registers via DSMEngine::registerSensorWithXmlRpc(string,DSMServer*).
Definition: DSMSensor.h:897
virtual void setClassName(const std::string &val)
Set the class name.
Definition: DSMSensor.h:143
static nidas::util::Mutex _looperMutex
Definition: DSMSensor.h:1196
const Parameter * getParameter(const std::string &name) const
Fetch a parameter by name.
Definition: DSMSensor.cc:324
void setSampleScanner(SampleScanner *val)
Set the SampleScanner for this sensor.
Definition: DSMSensor.h:592
virtual void addSampleTag(SampleTag *val)
Add a SampleTag to this sensor.
Definition: DSMSensor.cc:103
bool readBuffer(int msecTimeout)
Read into my SampleScanner&#39;s buffer.
Definition: DSMSensor.h:931
void calcStatistics(unsigned int periodUsec)
Update the sensor sampling statistics.
Definition: DSMSensor.h:748
unsigned int getSensorId() const
Definition: DSMSensor.h:496
virtual bool getApplyVariableConversions() const
Definition: DSMSensor.h:846
int _station
Definition: DSMSensor.h:1200
std::string _suffix
Sensor suffix, which is added to variable names.
Definition: DSMSensor.h:1131
VariableIndex findVariableIndex(const std::string &vprefix)
Search all the sample tags for a variable whose name starts with the given prefix, and return it&#39;s index in the list of variables in the sample tag.
Definition: DSMSensor.cc:848
virtual void setLatency(float val)
Set desired latency, providing some control over the response time vs buffer efficiency tradeoff...
Definition: DSMSensor.h:507
bool allowOpen()
Definition: DSMSensor.h:913
unsigned int getMaxSampleLength() const
Definition: SampleScanner.h:179
An interface to an IO device.
Definition: IODevice.h:41
const Dictionary & getDictionary() const
Definition: DSMSensor.h:315
void distributeRaw(const Sample *s)
Distribute a raw sample which has been read from my file descriptor in real time. ...
Definition: DSMSensor.h:449
SampleSourceSupport _source
Definition: DSMSensor.h:1162
virtual size_t read(void *buf, size_t len)=0
Read from the sensor.
virtual int getReadFd() const =0
The file descriptor used when reading from this sensor.
int len
Definition: sing.cc:934
static bool zebra
Definition: DSMSensor.h:1165
CalFile * getCalFile(const std::string &name)
Return a CalFile by its getName().
Definition: DSMSensor.cc:278
virtual int getWriteFd() const
Definition: DSMSensor.h:465
Interface to a data sample.
Definition: Sample.h:189
virtual void init()
Initialize the DSMSensor.
Definition: DSMSensor.cc:354
virtual void clearBuffer()
Definition: SampleScanner.cc:174
DSMSensor provides the basic support for reading, processing and distributing samples from a sensor a...
Definition: DSMSensor.h:87
unsigned int getMinSampleLength() const
Definition: DSMSensor.h:759
void addSampleClient(SampleClient *c)
Add a SampleClient to this SampleSource.
Definition: DSMSensor.h:396
const Site * getSite() const
What Site am I associated with?
Definition: DSMSensor.cc:149
Definition: Parameter.h:46
virtual void removeSampleTag(SampleTag *val)
Remove val from the list of SampleTags, and delete it.
Definition: DSMSensor.cc:120
virtual size_t read(void *buf, size_t len)
Read from the device (duh).
Definition: DSMSensor.h:648
const std::string & getSuffix() const
Sensor suffix, which is added to variable names.
Definition: DSMSensor.h:209
void removeCalFiles()
Remove all CalFiles.
Definition: DSMSensor.cc:287
std::map< std::string, CalFile * > _calFiles
Definition: DSMSensor.h:1180
bool getTokenValue(const std::string &token, std::string &value) const
Implement a lookup for tokens that I know about, like $HEIGHT.
Definition: DSMSensor.h:310
MyDictionary(DSMSensor *sensor)
Definition: DSMSensor.h:1100
float getDepth() const
Get sensor depth below ground.
Definition: DSMSensor.h:283
Definition: IOException.h:37
int _lag
Definition: DSMSensor.h:1198
Class for iterating over the SampleTags of a Project, Site, DSMConfig, or a SampleSource.
Definition: NidsIterators.h:217
void setHeight(const std::string &val)
Set sensor height above ground via a string which is added to variable names.
Definition: DSMSensor.cc:193
const std::string & getLocation() const
Location string.
Definition: DSMSensor.cc:167
std::string _typeName
Definition: DSMSensor.h:1182
int getClientCount() const
How many SampleClients are currently in my list.
Definition: DSMSensor.h:434
IODevice * getIODevice() const
Definition: DSMSensor.h:951
virtual int getTimeoutMsecs() const
Definition: DSMSensor.h:529
void setIODevice(IODevice *val)
Set the IODevice for this sensor.
Definition: DSMSensor.h:576
Class describing a group of variables that are sampled and handled together.
Definition: SampleTag.h:87
void incrementTimeoutCount()
Definition: DSMSensor.h:539
unsigned int getMinSampleLength() const
Definition: SampleScanner.h:182
A scanner of sample data.
Definition: SampleScanner.h:73
void distribute(const Sample *s)
Distribute a sample to my clients, calling the receive() method of each client, passing the const poi...
Definition: SampleSourceSupport.cc:141
void addSampleClientForTag(SampleClient *c, const SampleTag *)
Add a SampleClient to this SampleSource.
Definition: SampleSourceSupport.cc:101
unsigned int getBadTimeTagCount() const
Definition: SampleScanner.h:189
A VariableIndex associates a Variable pointer with it&#39;s index into it&#39;s SampleTag.
Definition: VariableIndex.h:51
void trimUnparsed(SampleTag *stag, SampleT< float > *outs, int nparsed)
Fill with floatNAN all the values past nparsed values in output sample outs, and trim the length of t...
Definition: DSMSensor.cc:408
std::string _heightString
Definition: DSMSensor.h:1133
virtual Sample * nextSample()
Extract the next sample from the buffer.
Definition: DSMSensor.h:707
A source of samples.
Definition: SampleStats.h:41
virtual Sample * nextSample(DSMSensor *sensor)=0
Extract the next sample from the buffer.
xercesc::DOMElement * toDOMParent(xercesc::DOMElement *parent, bool complete) const
Create a DOMElement and append it to the parent.
Definition: DSMSensor.cc:875
nidas::core::DSMSensor::MyDictionary _dictionary
#define USECS_PER_SEC
Definition: ublox.cc:59
int _timeoutMsecs
Definition: DSMSensor.h:1184
virtual bool readSamples()
Read samples from my associated file descriptor, and distribute() them to my RawSampleClient&#39;s.
Definition: DSMSensor.cc:358
virtual size_t getBytesAvailable() const
Return how many bytes are available to read on this IODevice.
Definition: IODevice.h:114
const std::string & getFullSuffix() const
Full sensor suffix, the concatenation of the sensor suffix, if any, and the height or depth string...
Definition: DSMSensor.h:292
Definition: Project.h:60
virtual const std::list< SampleTag * > & getNonConstSampleTags()
We&#39;ll allow derived classes and calibration applications to change the SampleTags, so this method returns a list of non-constant SampleTags.
Definition: DSMSensor.h:907
SampleTagIterator getSampleTagIterator() const
Definition: DSMSensor.h:386
void setDSMConfig(const DSMConfig *val)
Set the DSMConfig for this sensor.
Definition: DSMSensor.cc:97
std::list< const Parameter * > _constParameters
List of const pointers to Parameters for providing via getParameters().
Definition: DSMSensor.h:1178
void clearBuffer()
Clear the internal buffer.
Definition: DSMSensor.h:945
void setDSMId(unsigned int val)
Definition: DSMSensor.h:486
std::string _fullSuffix
Concatenation of sensor suffix, and the height or depth string.
Definition: DSMSensor.h:1142
virtual int getLagUsecs() const
Return the sampling lag for this sensor in microseconds.
Definition: DSMSensor.h:981
DSMSensor & operator=(const DSMSensor &x)
void removeSampleClientForTag(SampleClient *client, const SampleTag *tag)
Remove a SampleClient for a given SampleTag from this SampleSource.
Definition: DSMSensor.h:426
int getClientCount() const
How many SampleClients are currently in my list.
Definition: SampleSourceSupport.cc:136
#define GET_SPS_ID(tid)
Definition: Sample.h:84
static Looper * _looper
Definition: DSMSensor.h:1194
virtual void ioctl(int request, void *buf, size_t len)=0
DSMSensor()
Constructor.
Definition: DSMSensor.cc:56
virtual const std::string & getClassName() const
Fetch the class name.
Definition: DSMSensor.h:151
virtual void setCatalogName(const std::string &val)
Set the name of the catalog entry for this sensor.
Definition: DSMSensor.h:159
std::list< const SampleTag * > getSampleTags() const
What SampleTags am I a SampleSource for?
Definition: SampleSourceSupport.cc:54
bool getDuplicateIdOK() const
getDuplicateIdOK will be true if it is OK for samples from this sensor to have identical IDs to sampl...
Definition: DSMSensor.h:833
virtual const std::string & getTypeName(void) const
Get the type name of this sensor.
Definition: DSMSensor.h:819
A C++ wrapper for a POSIX mutex.
Definition: ThreadSupport.h:154
#define SET_SPS_ID(tid, val)
Definition: Sample.h:87
virtual int getDefaultMode() const
How do I want to be opened.
Definition: DSMSensor.h:624
std::list< SampleTag * > & getSampleTags()
Non-const method to get a list of non-const pointers to SampleTags.
Definition: DSMSensor.h:381
SampleTag _rawSampleTag
Definition: DSMSensor.h:1156
const std::string & getHeightString() const
Get sensor height above ground in a string.
Definition: DSMSensor.h:244
virtual size_t readBuffer(DSMSensor *sensor, bool &exhausted)
Read from the sensor into the internal buffer of this SampleScanner.
Definition: SampleScanner.cc:82
virtual bool process(const Sample *, std::list< const Sample * > &result)=0
Apply further necessary processing to a raw sample from this DSMSensor.
void addCalFile(CalFile *val)
Add a calibration file for this DSMSensor.
Definition: DSMSensor.cc:271
virtual void setApplyVariableConversions(bool val)
Definition: DSMSensor.h:851
virtual void close()
close my associated device.
Definition: DSMSensor.cc:347
void setDuplicateIdOK(bool val)
Set the duplicate ID attribute of this DSMSensor.
Definition: DSMSensor.h:841
void applyConversions(SampleTag *stag, SampleT< float > *outs, float *results=0)
Perform variable conversions for the variables in stag whose values and sample time have been set in ...
Definition: DSMSensor.cc:427
int _driverTimeTagUsecs
Definition: DSMSensor.h:1190
virtual size_t write(const void *buf, size_t len)
Write to the device (duh).
Definition: DSMSensor.h:667
int getStation() const
Definition: DSMSensor.h:213
const std::string & getDSMName() const
Fetch the DSM name.
Definition: DSMSensor.cc:158
Definition: InvalidParameterException.h:35