CARMA C++
Port.h
Go to the documentation of this file.
1 #ifndef SZA_UTIL_PORT_H
2 #define SZA_UTIL_PORT_H
3 
11 #include <string>
12 #include "carma/szautil/String.h"
13 #include "carma/szautil/Vector.h"
14 
15 namespace sza {
16  namespace util {
17 
18  class Port {
19  public:
20 
21  static const unsigned int MAX_RCV_BUFFER = 300;
22 
23  // The default telnet port number
24 
25  static const unsigned TELNET_PORT_NO = 23;
26 
30  Port(int fd = -1);
31 
35  virtual ~Port();
36 
40  inline int getFd() {
41  return fd_;
42  }
43 
44  void setFd(int fd) {
45  fd_ = fd;
46  }
47 
51  virtual int connect()
52  {
53  return 0;
54  };
55 
59  void writeString(std::string& message, int fd=-1);
60  void writeBytes(Vector<unsigned char>& buffer);
61  static void writeBytes(Vector<unsigned char>& buffer, int fd);
62 
66  unsigned int readBytes(unsigned char *message, int fd=-1);
67  unsigned int readBytes(Vector<unsigned char>& buffer);
68 
69  // Read tne next byte from the serial port
70 
71  unsigned char getNextByte();
72 
76  std::string readString(int fd=-1);
77 
78  bool concatenateString(std::ostringstream& os, int fd=-1, bool cont=true);
79  void concatenateChar(std::ostringstream& os, int fd=-1);
80  int getNbyte(int fd=-1);
81 
86  void terminateAt(std::string strip);
87 
92  void strip(std::string strip);
93 
98  void dontStrip(std::string strip);
99 
103  void stripUnprintable(bool strip);
104 
108  void append(std::string append);
109 
110  void appendNewline();
111  void appendLinefeed();
112  void appendNull();
113  void appendNothing();
114 
118  void setNoBuf();
119 
123  void setLineBuf();
124 
125  void print(unsigned char);
126 
127  protected:
128 
129  int fd_;
130 
131  private:
132 
133  std::vector<unsigned char> appendVec_;
134 
135  String termStr_;
136  String stripStr_;
137  String dontStripStr_;
138  String appendStr_;
139  bool stripUnprintable_;
140  };
141  } // End namespace util
142 } // End namespace sza
143 
144 
145 
146 #endif // End #ifndef SZA_UTIL_PORT_H
Tagged: Wed May 12 09:30:13 PDT 2004.