khepera_serial.h
00001 /*
00002  *  Player - One Hell of a Robot Server
00003  *  Copyright (C) 2006
00004  *     Toby Collett
00005  *
00006  *
00007  *  This library is free software; you can redistribute it and/or
00008  *  modify it under the terms of the GNU Lesser General Public
00009  *  License as published by the Free Software Foundation; either
00010  *  version 2.1 of the License, or (at your option) any later version.
00011  *
00012  *  This library is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  *  Lesser General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU Lesser General Public
00018  *  License along with this library; if not, write to the Free Software
00019  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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         // serial port descriptor
00047         int fd;
00048         struct termios oldtio;
00049         
00050         // read/write buffer
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

Last updated 25 May 2011 21:17:00