00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef KHEPERA_SERIAL_H
00023 #define KHEPERA_SERIAL_H
00024
00025 #include <pthread.h>
00026 #include <termios.h>
00027
00028 #define KHEPERA_DEFAULT_BAUD B38400
00029 #define KHEPERA_BUFFER_LEN 255
00030 #define KHEPERA_SERIAL_TIMEOUT_USECS 100000
00031
00032
00033 class KheperaSerial
00034 {
00035 public:
00036
00037 KheperaSerial(char * port, int rate = KHEPERA_DEFAULT_BAUD);
00038 ~KheperaSerial();
00039
00040 bool Open() {return fd >0;};
00041 int KheperaCommand(char command, int InCount, int * InValues, int OutCount, int * OutValues);
00042
00043 void Lock();
00044 void Unlock();
00045 protected:
00046
00047 int fd;
00048 struct termios oldtio;
00049
00050
00051 char buffer[KHEPERA_BUFFER_LEN+1];
00052
00053 int WriteInts(char command, int Count = 0, int * Values = NULL);
00054 int ReadInts(char Header, int Count = 0, int * Values = NULL);
00055
00056 pthread_mutex_t lock;
00057 };
00058
00059 #endif