nidas v1.2.3
CharacterSensor.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 ** 2006, 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_CORE_CHARACTERSENSOR_H
28#define NIDAS_CORE_CHARACTERSENSOR_H
29
30#include "DSMSensor.h"
31#include "Prompt.h"
32#include <nidas/util/util.h>
33
34namespace nidas { namespace core {
35
36class AsciiSscanf;
37class Sample;
38class TimetagAdjuster;
39
47
48public:
49
54
55 virtual ~CharacterSensor();
56
69
80
89 void open(int flags);
90
97 void validate();
98
107 void init();
108
116 virtual void setMessageParameters(unsigned int length, const std::string& val,
117 bool eom);
118
123 const std::string& getMessageSeparator() const
124 {
125 return _messageSeparator;
126 }
127
135
137 {
138 return _separatorAtEOM;
139 }
140
142 {
143 return _messageLength;
144 }
145
152 virtual void addPrompt(const std::string& promptString, double promptRate,
153 double promptOffset)
154 {
156 prompt.setString(promptString);
157 prompt.setRate(promptRate);
158 prompt.setOffset(promptOffset);
159
160 _prompts.push_back(prompt);
161 _prompted = true;
162//cerr<< "pushed back prompt. String = "<<promptString<<" rate= "<<promptRate;
163 }
164
165 const std::list<Prompt>& getPrompts() const { return _prompts;}
166
172 virtual bool isPrompted() const { return _prompted; }
173
178 virtual bool isPrompting() const { return false; }
179
183 virtual void startPrompting()
184 {
186 "startPrompting","not supported");
187 }
188
192 virtual void stopPrompting()
193 {
195 "stopPrompting","not supported");
196 }
197
201 virtual void togglePrompting()
202 {
203 if (isPrompting()) stopPrompting();
204 else startPrompting();
205 }
206
212 void setInitString(const std::string& val) { _initString = val; }
213
214 const std::string& getInitString() const { return _initString; }
215
219 virtual void sendInitString();
220
221 bool getNullTerminated() const
222 {
223 if (!getSampleScanner()) return false;
225 }
226
233 return _scanfFailures;
234 }
235
242 return _scanfPartials;
243 }
244
249 const std::list<AsciiSscanf*>& getScanfers() const
250 {
251 return _sscanfers;
252 }
253
259 int getMaxScanfFields() const { return _maxScanfFields; }
260
269 virtual void validateSscanfs();
270
278 virtual bool process(const Sample*,std::list<const Sample*>& result);
279
283 void fromDOMElement(const xercesc::DOMElement*);
284
289 bool doesAsciiSscanfs();
290
291protected:
292
298 void setPromptRate(const double val) {_promptRate = val;}
299
300 double getPromptRate() const { return (_promptRate);}
301
302 void setPromptOffset(const double val) {_promptOffset = val;}
303
304 double getPromptOffset()const { return (_promptOffset);}
305
311 void setPromptString(const std::string& val) { _promptString = val; }
312
313 const std::string& getPromptString() const { return (_promptString);}
314
315 virtual int scanSample(AsciiSscanf* sscanf, const char* inputstr,
316 float* data_ptr);
317
333 SampleT<float>*
334 searchSampleScanners(const Sample* samp, SampleTag** stag_out=0) throw();
335
340 void
341 adjustTimeTag(SampleTag* stag, SampleT<float>* outs);
342
344
345private:
346
347 std::string _messageSeparator;
348
350
352
353 std::list<Prompt> _prompts;
354
355 std::string _promptString;
356
358
360
362
363 std::list<AsciiSscanf*>::const_iterator _nextSscanfer;
364
366
368
370
372
376 std::string _initString;
377
378 std::string _emptyString;
379
382
385
386};
387
388}} // namespace nidas namespace core
389
390#endif
Class providing sscanf functionality for parsing ASCII data.
Definition AsciiSscanf.h:62
Implementation of support for a sensor which generates character output.
Definition CharacterSensor.h:46
virtual bool process(const Sample *, std::list< const Sample * > &result)
Process a raw sample, which in this case means do a sscanf on the character string contents,...
Definition CharacterSensor.cc:447
std::list< AsciiSscanf * >::const_iterator _nextSscanfer
Definition CharacterSensor.h:363
virtual void togglePrompting()
Definition CharacterSensor.h:201
void adjustTimeTag(SampleTag *stag, SampleT< float > *outs)
Apply TimetagAdjuster and lag adjustments to the timetag of the given sample.
Definition CharacterSensor.cc:471
virtual void sendInitString()
Definition CharacterSensor.cc:108
virtual ~CharacterSensor()
Definition CharacterSensor.cc:70
virtual void startPrompting()
Definition CharacterSensor.h:183
std::string _messageSeparator
Definition CharacterSensor.h:347
const std::list< AsciiSscanf * > & getScanfers() const
Return the list of AsciiSscanfs requested for this CharacterSensor.
Definition CharacterSensor.h:249
void setPromptOffset(const double val)
Definition CharacterSensor.h:302
int getMaxScanfFields() const
The maximum number of fields in any of the AsciiSscanfs for this CharacterSensor.
Definition CharacterSensor.h:259
SampleT< float > * searchSampleScanners(const Sample *samp, SampleTag **stag_out=0)
Search through the AsciiSscanf instances attached to this sensor, looking for the next scanner which ...
Definition CharacterSensor.cc:361
void init()
Initialize the CharacterSensor instance for post-processing.
Definition CharacterSensor.cc:162
CharacterSensor()
No arg constructor.
Definition CharacterSensor.cc:51
SampleScanner * buildSampleScanner()
Creates a SampleScanner for this DSMSensor depending on the device name prefix: name prefix type of S...
Definition CharacterSensor.cc:133
std::string _emptyString
Definition CharacterSensor.h:378
const std::string & getPromptString() const
Definition CharacterSensor.h:313
std::string _initString
String that is sent once after sensor is opened.
Definition CharacterSensor.h:376
bool _prompted
Definition CharacterSensor.h:371
void setPromptRate(const double val)
Set the rate at which <sensor> prompts are sent to this sensor.
Definition CharacterSensor.h:298
const std::string & getMessageSeparator() const
Get message separator with backslash sequences replaced by their intended character.
Definition CharacterSensor.h:123
virtual int scanSample(AsciiSscanf *sscanf, const char *inputstr, float *data_ptr)
Definition CharacterSensor.cc:352
double getPromptOffset() const
Definition CharacterSensor.h:304
int _maxScanfFields
Definition CharacterSensor.h:365
virtual bool isPrompted() const
Is this a prompted sensor.
Definition CharacterSensor.h:172
IODevice * buildIODevice()
Creates an IODevice depending on the device name prefix: name prefix type of IODevice inet: TCPSocket...
Definition CharacterSensor.cc:118
virtual void setMessageParameters(unsigned int length, const std::string &val, bool eom)
The messageSeparator is the string of bytes that sensor generates to separate messages.
Definition CharacterSensor.cc:88
int _messageLength
Definition CharacterSensor.h:351
std::map< const SampleTag *, TimetagAdjuster * > _ttadjusters
Definition CharacterSensor.h:343
virtual void addPrompt(const std::string &promptString, double promptRate, double promptOffset)
Prompting Sensors can have multiple prompts and rates.
Definition CharacterSensor.h:152
void validate()
Implementation of DSMSensor::validate for a Character Sensor.
Definition CharacterSensor.cc:323
void setPromptString(const std::string &val)
Set the <sensor> prompt string for this sensor.
Definition CharacterSensor.h:311
virtual void stopPrompting()
Definition CharacterSensor.h:192
std::list< AsciiSscanf * > _sscanfers
Definition CharacterSensor.h:361
bool doesAsciiSscanfs()
Definition CharacterSensor.cc:152
bool getNullTerminated() const
Definition CharacterSensor.h:221
double _promptRate
Definition CharacterSensor.h:357
int _scanfFailures
Definition CharacterSensor.h:367
int _scanfPartials
Definition CharacterSensor.h:369
virtual bool isPrompting() const
Is prompting active, i.e.
Definition CharacterSensor.h:178
void fromDOMElement(const xercesc::DOMElement *)
Definition CharacterSensor.cc:224
bool _separatorAtEOM
Definition CharacterSensor.h:349
std::list< Prompt > _prompts
Definition CharacterSensor.h:353
const std::list< Prompt > & getPrompts() const
Definition CharacterSensor.h:165
double getPromptRate() const
Definition CharacterSensor.h:300
int getMessageLength() const
Definition CharacterSensor.h:141
int getNumScanfPartials() const
How many samples have been partially scanned, because a character in the middle of a message conflict...
Definition CharacterSensor.h:241
void open(int flags)
Open the sensor device port for real-time sampling.
Definition CharacterSensor.cc:99
int getNumScanfFailures() const
How many samples have resulted in complete scanf failures - nothing parsed, because the sensor messag...
Definition CharacterSensor.h:232
std::string _promptString
Definition CharacterSensor.h:355
const std::string & getInitString() const
Definition CharacterSensor.h:214
virtual void validateSscanfs()
Virtual method to check that the Sscanfs for this CharacterSensor are OK.
Definition CharacterSensor.cc:202
const std::string getBackslashedMessageSeparator() const
Get message separator with backslash sequences added back.
Definition CharacterSensor.h:131
bool getMessageSeparatorAtEOM() const
Definition CharacterSensor.h:136
double _promptOffset
Definition CharacterSensor.h:359
void setInitString(const std::string &val)
Set the initialization string(s) for this sensor.
Definition CharacterSensor.h:212
DSMSensor provides the basic support for reading, processing and distributing samples from a sensor a...
Definition DSMSensor.h:88
SampleScanner * getSampleScanner() const
Definition DSMSensor.h:981
virtual std::string getName() const
Return a name that should fully identify this sensor.
Definition DSMSensor.h:183
An interface to an IO device.
Definition IODevice.h:42
Class to contain prompt information - string and rate.
Definition Prompt.h:38
A scanner of sample data.
Definition SampleScanner.h:74
virtual bool getNullTerminate() const
Should the SampleScanner append a null character, '\0', to the messages.
Definition SampleScanner.h:129
A typed Sample, with data of type DataT.
Definition Sample.h:394
Class describing a group of variables that are sampled and handled together.
Definition SampleTag.h:88
Interface to a data sample.
Definition Sample.h:190
Adjust time tags of fixed delta-T time series to correct for irregular latency in the assignments of ...
Definition TimetagAdjuster.h:45
Definition IOException.h:37
Sample * getSample(sampleType type, unsigned int len)
A convienence method for getting a sample of an enumerated type from a pool.
Definition Sample.cc:70
std::string addBackslashSequences(const std::string &str)
Utility function for substituting backslash sequences back into a string.
Definition util.cc:106
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31