00001 #ifndef SICK_LMS200_H
00002 #define SICK_LMS200_H
00003
00004
00005
00006
00007
00008
00009 #include <termios.h>
00010
00011 #define MAXNDATA 802
00012
00013 namespace SickDriver {
00014 typedef unsigned char uchar;
00015 class Exception {
00016 const char* descr;
00017 public:
00018 Exception(const char* _descr);
00019 const char* getDescription();
00020 };
00021
00022 class BaudRateChangeException : public Exception {
00023 public:
00024 BaudRateChangeException();
00025 };
00026
00027 class InvalidResolutionException:public Exception {
00028 public:
00029 InvalidResolutionException();
00030 };
00031
00032 class ResolutionFailureException:public Exception {
00033 public:
00034 ResolutionFailureException();
00035 };
00036
00037
00038 class ModeFailureException:public Exception {
00039 public:
00040 ModeFailureException();
00041 };
00042
00043 class StartFailureException:public Exception {
00044 public:
00045 StartFailureException();
00046 };
00047
00048 class StopFailureException:public Exception {
00049 public:
00050 StopFailureException();
00051 };
00052
00053
00054 class RegisterException:public Exception {
00055 public:
00056 RegisterException();
00057 };
00058
00059 class IOException:public Exception {
00060 public:
00061 IOException(const char* _descr);
00062 };
00063
00064 class FatalMeasurementException:public Exception {
00065 public:
00066 FatalMeasurementException();
00067 };
00068
00069
00070 class SickLMS200 {
00071 const char* port;
00072 int range_mode;
00073 int res_mode;
00074 int unit_mode;
00075 termios oldtio;
00076 int fd;
00077 uchar meas_state;
00078 public:
00079 typedef enum {
00080 RANGE_100=32,
00081 RANGE_180=16,
00082 RES_1_DEG=8,
00083 RES_0_5_DEG=4,
00084 RES_0_25_DEG=2,
00085 MMMODE=1,
00086 CMMODE=0 } Constants;
00087
00088 SickLMS200(
00089 const char* _port,
00090 uchar _range_mode=RANGE_100,
00091 uchar _res_mode = RES_1_DEG,
00092 uchar _unit_mode = MMMODE );
00093 bool start();
00094 int readMeasurement(uchar* buf,int& datalen);
00095 bool reset();
00096 bool stop();
00097 ~SickLMS200();
00098 bool checkErrorMeasurement();
00099 bool checkPlausible();
00100 private:
00101
00102 bool msgcmp(int len1, const uchar *s1, int len2, const uchar *s2);
00103
00104
00105 void wtLMSmsg(int fd, int len, const uchar *msg);
00106
00107 int rdLMSmsg(int fd, int len, const uchar *buf);
00108
00109 uchar rdLMSbyte(int fd);
00110
00111
00112 bool chkAck(int fd, int ackmsglen, const uchar *ackmsg);
00113
00114
00115 bool initLMS(const char *serialdev, struct termios *oldtio, int& fd);
00116
00117
00118
00119 bool setmode(int fd, int mode);
00120
00121
00122 bool startLMS(int fd);
00123
00124
00125 bool stopLMS(int fd);
00126
00127
00128 void chkstatus(uchar c);
00129
00130
00131 bool resetLMS(int fd, struct termios *oldtio);
00132
00133
00134
00135 static void sig_trap(int sig);
00136 };
00137
00138
00139 bool registerSickLMS200SignalHandler();
00140 };
00141 #endif
00142