nidas  v1.2-1520
SerialSensor.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  ** 2011, 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_DYNLD_SERIALSENSOR_H
27 #define NIDAS_DYNLD_SERIALSENSOR_H
28 
29 #include "CharacterSensor.h"
30 #include "LooperClient.h"
31 #include "SerialPortIODevice.h"
32 
33 namespace nidas { namespace core {
34 
35 using namespace nidas::core;
36 
65 {
66 
67 public:
68 
73  SerialSensor();
74 
75  ~SerialSensor();
76 
81  nidas::util::Termios& termios() { return _termios; }
82 
86  const nidas::util::Termios& getTermios() const { return _termios; }
87 
93  SampleScanner* buildSampleScanner()
94  throw(nidas::util::InvalidParameterException);
95 
108  IODevice* buildIODevice() throw(nidas::util::IOException);
109 
115  void open(int flags) throw(nidas::util::IOException,
116  nidas::util::InvalidParameterException);
117 
118  /*
119  * Close the device connected to the sensor.
120  */
121  void close() throw(nidas::util::IOException);
122 
127  void applyTermios() throw(nidas::util::IOException);
128 
133  void setMessageParameters(unsigned int len,const std::string& sep, bool eom)
134  throw(nidas::util::InvalidParameterException,nidas::util::IOException);
135 
136  void printStatus(std::ostream& ostr) throw();
137 
142  bool isPrompting() const { return _prompting; }
143 
148  void startPrompting() throw(nidas::util::IOException);
149 
150  void stopPrompting() throw(nidas::util::IOException);
151 
152  void fromDOMElement(const xercesc::DOMElement* node)
153  throw(nidas::util::InvalidParameterException);
154 
161  int getUsecsPerByte() const;
162 
163 protected:
164 
169  void initPrompting() throw(nidas::util::IOException);
170 
174  void shutdownPrompting() throw(nidas::util::IOException);
175 
176  void unixDevInit(int flags)
177  throw(nidas::util::IOException);
178 
179 private:
180 
184  nidas::util::Termios _termios;
185 
189  SerialPortIODevice* _serialDevice;
190 
191  class Prompter: public nidas::core::LooperClient
192  {
193  public:
194  Prompter(SerialSensor* sensor): _sensor(sensor),
195  _prompt(0),_promptLen(0), _promptPeriodMsec(0),
196  _promptOffsetMsec(0) {}
197 
198  ~Prompter();
199 
200  void setPrompt(const std::string& val);
201  const std::string getPrompt() const { return _prompt; }
202 
203  void setPromptPeriodMsec(const int);
204  int getPromptPeriodMsec() const { return _promptPeriodMsec; }
205 
206  void setPromptOffsetMsec(const int);
207  int getPromptOffsetMsec() const { return _promptOffsetMsec; }
208 
212  void looperNotify() throw();
213  private:
214  SerialSensor* _sensor;
215  char* _prompt;
216  int _promptLen;
217  int _promptPeriodMsec;
218  int _promptOffsetMsec;
219 
221  Prompter(const Prompter&);
222 
224  Prompter& operator=(const Prompter&);
225  };
226 
227  std::list<Prompter*> _prompters;
228 
229  bool _prompting;
230 
235  int _rts485;
236 
238  SerialSensor(const SerialSensor&);
239 
241  SerialSensor& operator=(const SerialSensor&);
242 
243 };
244 
245 }} // namespace nidas namespace core
246 
247 #endif
A serial port.
Definition: SerialPortIODevice.h:47
Interface of a client of Looper.
Definition: LooperClient.h:38
Definition: SerialSensor.h:191
Implementation of support for a sensor which generates character output.
Definition: CharacterSensor.h:46
Support for a sensor that is sending packets on a TCP socket, a UDP socket, a Bluetooth RF Comm socke...
Definition: SerialSensor.h:64
nidas::util::Termios & termios()
Expose the Termios.
Definition: SerialSensor.h:81
const nidas::util::Termios & getTermios() const
Get a read-only copy of the Termios.
Definition: SerialSensor.h:86
An interface to an IO device.
Definition: IODevice.h:41
int len
Definition: sing.cc:934
int getPromptPeriodMsec() const
Definition: SerialSensor.h:204
A scanner of sample data.
Definition: SampleScanner.h:73
Prompter(SerialSensor *sensor)
Definition: SerialSensor.h:194
const std::string getPrompt() const
Definition: SerialSensor.h:201
int getPromptOffsetMsec() const
Definition: SerialSensor.h:207
A class providing get/set methods into a termios structure.
Definition: Termios.h:48