ARPDAS_QNX6 1.0
|
00001 #ifndef SERSELECTOR_H_INCLUDED 00002 #define SERSELECTOR_H_INCLUDED 00003 /* SerSelector.h */ 00004 00005 #include <string> 00006 #include "Selector.h" 00007 #include "collect.h" 00008 #include "tm.h" 00009 00010 /** 00011 * A Selectee wrapper for Col_send() and friends to support sending data to 00012 * collection. The data structure should be defined in a header file shared 00013 * with collection and declared in tmc as 'TM "Receive" <name> 1'. The 1 00014 * indicates that data will be reported synchronously to telemetry. 00015 * The intention is that the same data structure will be shared with 00016 * another Selectee (possibly one derived from Ser_Sel) to record data 00017 * as it is received. 00018 * 00019 * Whenever the data is written to telemetry, Selector::set_gflag(0) 00020 * is called. Another Selectee can request to be notified of this by 00021 * setting bit Selector::gflag(0) in their flags word. 00022 * 00023 * For tighter control over acquisition and reporting, you can overload 00024 * ProcessData() in a subclass. 00025 */ 00026 class TM_Selectee : public Selectee { 00027 public: 00028 TM_Selectee(const char *name, void *data, unsigned short size); 00029 TM_Selectee(); 00030 ~TM_Selectee(); 00031 void init(const char *name, void *data, unsigned short size); 00032 int ProcessData(int flag); 00033 protected: 00034 send_id TMid; 00035 }; 00036 00037 /** 00038 * A Selectee for monitoring a serial line. 00039 */ 00040 class Ser_Sel : public Selectee { 00041 public: 00042 Ser_Sel(const char *path, int open_flags, int bufsz); 00043 Ser_Sel(); 00044 ~Ser_Sel(); 00045 void init(const char *path, int open_flags, int bufsz); 00046 void setup( int baud, int bits, char par, int stopbits, 00047 int min, int time ); 00048 protected: 00049 int fillbuf(); 00050 void consume(int nchars); 00051 void flush_input(); 00052 void report_err( const char *msg, ... ); 00053 void report_ok(); 00054 int not_found(unsigned char c); 00055 int not_hex(unsigned short &hexval); 00056 int not_int(int &val ); 00057 int not_str(const char *str, unsigned int len); 00058 int not_str(const std::string &s); 00059 int not_str(const char *str); 00060 int not_float( float &val ); 00061 unsigned int nc, cp; 00062 unsigned char *buf; 00063 int bufsize; 00064 int n_fills, n_empties; 00065 int n_eagain, n_eintr; 00066 private: 00067 void sersel_init(); 00068 /** Number of qualified errors. Decremented by report_ok() */ 00069 int n_errors; 00070 /** Number of messages currently suppressed. */ 00071 int n_suppressed; 00072 /** Total number of errors found. */ 00073 int total_errors; 00074 int total_suppressed; 00075 }; 00076 00077 /** 00078 * A Selectee to monitor a command channel. The default channel is 00079 * "cmd/Quit" and the default action is to terminate the event loop, 00080 * but this can be overridden in a subclass. 00081 */ 00082 class Cmd_Selectee : public Ser_Sel { 00083 public: 00084 Cmd_Selectee(const char *name = "cmd/Quit"); 00085 Cmd_Selectee(const char *name, int bufsz); 00086 int ProcessData(int flag); 00087 }; 00088 00089 00090 extern const char *ascii_escape(const char *str, int len); 00091 extern const char *ascii_escape(const std::string &s); 00092 extern const char *ascii_esc(const char *str); 00093 00094 #endif