00001
00002 You must wrap around the Standard C function:
00003
00004 open()
00005 close()
00006 read()
00007 write()
00008 select()
00009
00010 raw/unraw
00011
00012 You should check for errors and the class should
00013 know it's file descriptor, name, etc.
00014
00015
00016
00017 #ifndef DEVICE_HPP
00018 #define DEVICE_HPP
00019
00020 #include <stdio.h>
00021 #include <stdlib.h>
00022 #include <string.h>
00023 #include <errno.h>
00024
00025 #include <time.h>
00026 #include <fcntl.h>
00027 #include <unistd.h>
00028
00029
00030 #include <pthread.h>
00031 #include <sys/neutrino.h>
00032
00033 #include <sys/stat.h>
00034 #include <sys/select.h>
00035 #include <sys/ioctl.h>
00036 #include <sys/types.h>
00037 #include <sys/uio.h>
00038
00039 #include <sys/termio.h>
00040
00041
00042 #define CONSOLE "/dev/con1"
00043 #define SERIAL "/dev/ser1"
00044
00045 class Device {
00046 public:
00047
00048
00049 Device( const char* name = CONSOLE,
00050 int flags = O_RDWR,
00051 bool openit = true );
00052
00053
00054 virtual ~Device();
00055
00056 void Open();
00057 void Close();
00058
00059
00060 void Read( void* buf, size_t sz );
00061 void Write( const void* buf, size_t sz );
00062
00063
00064 inline char ReadChar();
00065 inline void WriteChar( char c );
00066
00067
00068 int Select();
00069
00070
00071 void Raw();
00072 void Cooked();
00073
00074
00075
00076 inline const char* getName() const;
00077
00078 inline bool isOpen() const;
00079 inline bool getMode() const;
00080 inline int getFlags() const;
00081
00082 private:
00083
00084 Device( const Device& );
00085 const Device& operator=( const Device& );
00086
00087 protected:
00088
00089 int fd;
00090
00091 bool opened;
00092 bool mode;
00093
00094 int oflag;
00095
00096 fd_set rfd;
00097 struct timeval tv;
00098
00099 char name[ 20 ];
00100 char buffer[ 80 ];
00101
00102 };
00103
00104 #endif
00105
00106 > Can you please explain to me what Device class should be like?
00107 > Can you show me a clear sample
00108 > Device class like what should each function does in the class?
00109
00110
00111 class Keyboard : public Driver {
00112
00113 };
00114
00115 class SerialPort : public Driver {
00116
00117 };
00118
00119 You need another class Chat or
00120 two other class SerialThread,
00121 ConsoleThread for Read blocking states...
00122
00123 Sincerly,
00124 Fred.
00125