00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef CONEXUSTTY_H
00020 #define CONEXUSTTY_H
00021
00022 #include <conexus/serial.h>
00023
00024 #include <termios.h>
00025 #include <unistd.h>
00026
00031 namespace Conexus
00032 {
00033
00042 class TTY : public Serial
00043 {
00044 public:
00045 typedef boost::shared_ptr<TTY> pointer;
00046
00058 TTY(const std::string& device=std::string());
00059
00060 static TTY::pointer create(const std::string& device=std::string());
00061
00062 virtual ~TTY();
00063
00067 typedef enum SetOption {
00069 SET_NOW=TCSANOW,
00070
00076 SET_FLUSH=TCSAFLUSH,
00077
00082 SET_DRAIN=TCSADRAIN
00083 } SetOption;
00084
00085 typedef enum Parity {
00086 PARITY_NONE,
00087 PARITY_ODD,
00088 PARITY_EVEN,
00089 };
00090
00091 typedef enum ParityError {
00092 PARITY_ERROR_DISCARD,
00093 PARITY_ERROR_MARK,
00094 PARITY_ERROR_ZERO,
00095 PARITY_ERROR_IGNORE,
00096 };
00097
00098 typedef enum FlowControl {
00099 FLOW_NONE,
00100 FLOW_HARDWARE,
00101 FLOW_SOFTWARE,
00102 FLOW_CUSTOM,
00103 };
00104
00108 void drain();
00109
00113 void flush_input();
00114
00118 void flush_output();
00119
00124 void flush();
00125
00129 void suspend_output();
00130
00134 void restart_output();
00135
00139 void suspend_input();
00140
00144 void restart_input();
00145
00183 void set_input_speed(unsigned speed, SetOption option=SET_NOW );
00184
00186 void set_output_speed(unsigned speed, SetOption option=SET_NOW );
00187
00189 void set_speed(unsigned speed, SetOption option=SET_NOW );
00190
00192 unsigned input_speed();
00193
00195 unsigned output_speed();
00196
00198 void set_parity(Parity parity, ParityError error=PARITY_ERROR_IGNORE, SetOption option=SET_NOW );
00199
00201 Parity parity();
00202
00204 ParityError parity_error();
00205
00207 unsigned byte_size();
00208
00218 void set_byte_size( unsigned size, SetOption option=SET_NOW );
00219
00221 unsigned stop_bits();
00222
00224 void set_stop_bits( unsigned size, SetOption option=SET_NOW );
00225
00227 FlowControl flow_control();
00228
00233 void set_flow_control(FlowControl flowcontrol, SetOption option=SET_NOW);
00234
00236 bool carrier_detect_enabled();
00237
00246 void set_carrier_detect(bool enable=true, SetOption option=SET_NOW);
00247
00252 bool receiver_enabled();
00253
00258 void set_receiver_enabled(bool enable=true, SetOption option=SET_NOW);
00259
00263 virtual Data read(size_t s = 0) throw (read_error);
00264
00265 virtual void open() throw (open_error);
00266
00268 virtual void open(const std::string name, int s=READ|WRITE) throw (open_error);
00269
00271 virtual void close(bool force=false) throw (close_error);
00272
00276 void set_input_modes(tcflag_t iflag, SetOption option=SET_NOW);
00277
00281 void set_output_modes(tcflag_t oflag, SetOption option=SET_NOW);
00282
00286 void set_control_modes(tcflag_t cflag, SetOption option=SET_NOW);
00287
00291 void set_local_modes(tcflag_t lflag, SetOption option=SET_NOW);
00292
00296 void set_control_characters(int index, cc_t value, SetOption option=SET_NOW);
00297
00301 struct termios attributes();
00302
00306 void inject(char data);
00307
00311 void inject(const char* buffer, size_t bufsize);
00312
00316 void inject(const std::string& buffer);
00317
00319 bool reset_on_close();
00320
00322 void set_reset_on_close(bool reset=true);
00323
00324 sigc::signal<void> signal_input_speed();
00325 sigc::signal<void> signal_output_speed();
00326 sigc::signal<void> signal_parity();
00327 sigc::signal<void> signal_byte_size();
00328 sigc::signal<void> signal_stop_bits();
00329 sigc::signal<void> signal_flow_control();
00330 sigc::signal<void> signal_carrier_detect();
00331 sigc::signal<void> signal_receiver();
00332
00333 virtual const std::string& object_type() { static std::string s("Conexus::TTY"); return s; }
00334
00335 protected:
00336 struct termios m_termios, m_origtermios;
00337 bool m_reset_on_close;
00338
00339 sigc::signal<void> m_signal_input_speed;
00340 sigc::signal<void> m_signal_output_speed;
00341 sigc::signal<void> m_signal_parity;
00342 sigc::signal<void> m_signal_byte_size;
00343 sigc::signal<void> m_signal_stop_bits;
00344 sigc::signal<void> m_signal_flow_control;
00345 sigc::signal<void> m_signal_carrier_detect;
00346 sigc::signal<void> m_signal_receiver;
00347
00348 void tcsetattr(SetOption option);
00349
00350 speed_t unsigned2speed(unsigned speed);
00351 unsigned speed2unsigned(speed_t speed);
00352
00353 };
00354
00355 }
00356
00357 #endif