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