ArduinoClient.h

Go to the documentation of this file.
00001 /***************************************************************
00002 
00003  Mini Grand Challenge 2010
00004  Pennsylvania State University - Robotics Club
00005  Learn more at www.psurobotics.org
00006  Protected by the GNU General Public License
00007 
00008  This source file is developed and maintained by:
00009  + Jeremy Bridon jbridon@psu.edu
00010 
00011  File: ArduinoClient.h
00012  Desc: Wraps the communication protocol with the ArduinoServer.
00013  If there are a certain number of errors (see: MAX_ERRORS) then
00014  the communication system is reset to resolve the communication
00015  failures.
00016 
00017 ***************************************************************/
00018 
00019 // Inclusion guard
00020 #ifndef __ARDUINOCLIENT_H_
00021 #define __ARDUINOCLIENT_H_
00022 
00023 // Includes
00024 #include <fcntl.h>
00025 #include <string.h>
00026 #include <stdint.h>
00027 #include <stdlib.h>
00028 #include <unistd.h>
00029 #include <cctype>
00030 #include <termios.h>
00031 #include <sys/ioctl.h>
00032 #include <stdlib.h>
00033 
00034 // Project includes
00035 #include "../Shared/Utilities.h"
00036 
00038 #define DEVICE_ID 1
00039 
00041 #define MAX_ERRORS 5
00042 
00044 enum ArduinoInstr { CMD_INIT = 0, CMD_UNIT, CMD_SETSPEED, CMD_SETTURN, CMD_GETRANGE, CMD_GETBEARING, CMD_GETSPEED };
00045 
00047 enum ArduinoRet { RET_OK = 0, RET_ERROR, RET_VAL };
00048 
00050 static const char ArduinoInstrStr[7][4] =
00051 {
00052         "!IN", // CMD_INIT
00053         "!UN", // CMD_UNIT
00054         "!SS", // CMD_SETSPEED
00055         "!ST", // CMD_SETTURN
00056         "!GR", // CMD_GETRANGE
00057         "!GB", // CMD_GETBEARING
00058         "!GS", // CMD_GETSPEED
00059 };
00060 
00062 static const char ArduinoRetStr[2][4] =
00063 {
00064         "?OK", // RET_OK
00065         "?ER", // RET_ERROR
00066 };
00067 
00069 class ArduinoClient
00070 {
00071 public:
00072 
00075         ArduinoClient(const char *DeviceName, int Baudrate = 9600);
00076 
00078         ~ArduinoClient();
00079 
00081         ArduinoRet SendCommand(ArduinoInstr Instruction, int Argument = -1, int *ToReturn = NULL);
00082 
00084         void Reset();
00085 
00086 private:
00087 
00089         void SendMsg(ArduinoInstr Instruction, int Argument = -1);
00090 
00092         ArduinoRet GetMsg(int *Return = NULL);
00093 
00094         int SerialID;   
00095         int ErrorCount; 
00096 };
00097 
00098 // Inclusion guard
00099 #endif

Generated on Sun Feb 21 00:00:08 2010 for Penn State Robotics Club: Mini Grand Challenge 2010 by  doxygen 1.5.5