00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __ARDUINOCLIENT_H_
00021 #define __ARDUINOCLIENT_H_
00022
00023
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
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",
00053 "!UN",
00054 "!SS",
00055 "!ST",
00056 "!GR",
00057 "!GB",
00058 "!GS",
00059 };
00060
00062 static const char ArduinoRetStr[2][4] =
00063 {
00064 "?OK",
00065 "?ER",
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
00099 #endif