HokuyoAIST  3.0.2
hokuyo_errors.h
Go to the documentation of this file.
1 /* HokuyoAIST
2  *
3  * Header file for exceptions.
4  *
5  * Copyright 2008-2011 Geoffrey Biggs geoffrey.biggs@aist.go.jp
6  * RT-Synthesis Research Group
7  * Intelligent Systems Research Institute,
8  * National Institute of Advanced Industrial Science and Technology (AIST),
9  * Japan
10  * All rights reserved.
11  *
12  * This file is part of HokuyoAIST.
13  *
14  * HokuyoAIST is free software; you can redistribute it and/or modify it
15  * under the terms of the GNU Lesser General Public License as published
16  * by the Free Software Foundation; either version 2.1 of the License,
17  * or (at your option) any later version.
18  *
19  * HokuyoAIST is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with HokuyoAIST. If not, see
26  * <http://www.gnu.org/licenses/>.
27  */
28 
29 #ifndef INCLUDE_HOKUYOAIST_HOKUYO_ERRORS_H__
30 #define INCLUDE_HOKUYOAIST_HOKUYO_ERRORS_H__
31 
32 #include <sstream>
33 #include <string>
34 
35 #if defined(WIN32)
36  typedef unsigned char uint8_t;
37  typedef unsigned int uint32_t;
38  #if defined(HOKUYOAIST_STATIC)
39  #define HOKUYOAIST_EXPORT
40  #elif defined(hokuyoaist_EXPORTS)
41  #define HOKUYOAIST_EXPORT __declspec(dllexport)
42  #else
43  #define HOKUYOAIST_EXPORT __declspec(dllimport)
44  #endif
45 #else
46  #include <stdint.h>
47  #define HOKUYOAIST_EXPORT
48 #endif
49 
54 namespace hokuyoaist {
55 
57 std::string scip2_error_to_string(char const* const error,
58  char const* const cmd);
59 
61 std::string desc_code_to_string(unsigned int code);
62 
63 
65 class HOKUYOAIST_EXPORT BaseError : public std::exception
66 {
67  public:
73  BaseError(unsigned int desc_code, char const* error_type);
74  BaseError(BaseError const& rhs);
75  virtual ~BaseError() throw() {}
76 
77  virtual unsigned int desc_code() const throw()
78  { return desc_code_; }
79 
80  virtual char const* error_type() const throw()
81  { return error_type_; }
82 
83  virtual const char* what() const throw();
84 
85  protected:
87  unsigned int desc_code_;
88 
90  std::string error_str_;
91 
93  char error_type_[32];
94 };
95 
96 
99 {
100  public:
104  explicit LogicError(unsigned int desc_code)
105  : BaseError(desc_code, "LogicError")
106  {}
107  explicit LogicError(unsigned int desc_code, char const* error_type)
108  : BaseError(desc_code, error_type)
109  {}
110  virtual ~LogicError() throw() {}
111 };
112 
113 
116 {
117  public:
121  explicit RuntimeError(unsigned int desc_code)
122  : BaseError(desc_code, "RuntimeError")
123  {}
124  explicit RuntimeError(unsigned int desc_code, char const* error_type)
125  : BaseError(desc_code, error_type)
126  {}
127  virtual ~RuntimeError() throw() {}
128 };
129 
130 
133 {
134  public:
138  explicit ReadError(unsigned int desc_code)
139  : RuntimeError(desc_code, "ReadError")
140  {}
141 }; // class ReadError
142 
143 
146 {
147  public:
151  explicit WriteError(unsigned int desc_code)
152  : RuntimeError(desc_code, "WriteError")
153  {}
154 }; // class WriteError
155 
156 
159 {
160  public:
164  explicit BaudrateError(unsigned int baud);
165  BaudrateError(BaudrateError const& rhs);
166 
167  unsigned int baud() const throw()
168  {
169  return baud_;
170  }
171 
172  protected:
174  unsigned int baud_;
175 }; // class BaudrateError
176 
177 
180 {
181  public:
183  : RuntimeError(3, "CloseError")
184  {}
185 }; // class CloseError
186 
187 
190 {
191  public:
193  : RuntimeError(11, "NoDestinationError")
194  {}
195 }; // class NoDestinationError
196 
197 
200 {
201  public:
203  : RuntimeError(23, "FirmwareError")
204  {}
205 }; // class FirmwareError
206 
207 
210 {
211  public:
213  : RuntimeError(22, "ScipVersionError")
214  {}
215 }; // class ScipVersionError
216 
217 
220 {
221  public:
223  : RuntimeError(4, "UnknownScipVersionError")
224  {}
225 }; // class UnknownScipVersionError
226 
227 
230 {
231  public:
235  explicit UnsupportedError(unsigned int desc_code)
236  : RuntimeError(desc_code, "UnsupportedError")
237  {}
238 }; // class UnsupportedError
239 
240 
243 {
244  public:
248  explicit ArgError(unsigned int desc_code)
249  : RuntimeError(desc_code, "ArgError")
250  {}
251  ArgError(unsigned int desc_code, char const* error_type)
252  : RuntimeError(desc_code, error_type)
253  {}
254  virtual ~ArgError() throw() {}
255 }; // class ArgError
256 
257 
260 {
261  public:
263  : RuntimeError(13, "NoDataError")
264  {}
265 }; // class NoDataError
266 
267 
270 {
271  public:
273  : RuntimeError(5, "NotSerialError")
274  {}
275 }; // class NotSerialError
276 
277 
280 {
281  public:
283  : RuntimeError(2, "IndexError")
284  {}
285 }; // class IndexError
286 
287 
290 {
291  public:
293  : RuntimeError(37, "SetIPError")
294  {}
295 }; // class SetIPError
296 
297 
300 {
301  public:
303  : ArgError(9, "MotorSpeedError")
304  {}
305 }; // class MotorSpeedError
306 
307 
310 {
311  public:
313  : ArgError(14, "StartStepError")
314  {}
315 }; // class StartStepError
316 
317 
320 {
321  public:
323  : ArgError(15, "EndStepError")
324  {}
325 }; // class EndStepError
326 
327 
330 {
331  public:
335  explicit ProtocolError(unsigned int desc_code)
336  : RuntimeError(desc_code, "ProtocolError")
337  {}
338  ProtocolError(unsigned int desc_code, char const* error_type)
339  : RuntimeError(desc_code, error_type)
340  {}
341  virtual ~ProtocolError() throw() {}
342 }; // class ProtocolError
343 
344 
347 {
348  public:
353  ChecksumError(int expected, int calculated);
354  ChecksumError(ChecksumError const& rhs);
355 
356  virtual int expected() const throw()
357  { return expected_; }
358 
359  virtual int calculated() const throw()
360  { return calculated_; }
361 
362  protected:
367 }; // class ProtocolError
368 
369 
372 {
373  public:
375  : ProtocolError(25, "DataCountError")
376  {}
377 }; // class DataCountError
378 
379 
382 {
383  public:
385  : ProtocolError(26, "MisplacedLineFeedError")
386  {}
387 }; // class MisplacedLineFeedError
388 
389 
392 {
393  public:
397  explicit UnknownLineError(char const* const line);
399 
400  virtual char const* const line() const throw()
401  { return line_; }
402 
403  protected:
405  char line_[128];
406 }; // class UnknownLineError
407 
408 
411 {
412  public:
417  ParseError(char const* const line, char const* const type);
418  ParseError(ParseError const& rhs);
419 
420  virtual char const* const line() const throw()
421  { return line_; }
422 
423  virtual char const* const type() const throw()
424  { return type_; }
425 
426  protected:
428  char line_[128];
430  char type_[16];
431 }; // class ParseError
432 
433 
436 {
437  public:
439  : ProtocolError(29, "MissingFirmSpecError")
440  {}
441 }; // class MissingFirmSpecError
442 
443 
446 {
447  public:
452  ResponseError(char const* const error, char const* const cmd);
453  ResponseError(ResponseError const& rhs);
454 
456  virtual char const* const error_code() const throw()
457  { return error_; }
458 
460  virtual char const* const cmd_code() const throw()
461  { return cmd_; }
462 
463  protected:
465  char error_[2];
467  char cmd_[2];
468 }; // class ResponseError
469 
470 
473 {
474  public:
479  Scip1ResponseError(char error, char cmd);
482  virtual char error_code() const throw()
483  { return error_; }
484 
486  virtual char cmd_code() const throw()
487  { return cmd_; }
488 
489  protected:
491  char error_;
493  char cmd_;
494 }; // class Scip1ResponseError
495 
496 
499 {
500  public:
505  CommandEchoError(char const* const cmd, char const* const echo);
507 
509  virtual char const* const cmd_code() const throw()
510  { return cmd_; }
511 
513  virtual char const* const cmd_echo() const throw()
514  { return echo_; }
515 
516  protected:
518  char cmd_[2];
520  char echo_[2];
521 }; // class CommandEchoError
522 
523 
526 {
527  public:
531  explicit ParamEchoError(char const* const cmd);
532  ParamEchoError(ParamEchoError const& rhs);
533 
535  virtual char const* const cmd_code() const throw()
536  { return cmd_; }
537 
538  protected:
540  char cmd_[2];
541 }; // class ParamEchoError
542 
543 
546 {
547  public:
552  InsufficientBytesError(int num, int line_length);
554 
555  virtual int num() const throw()
556  { return num_; }
557 
558  virtual int line_length() const throw()
559  { return line_length_; }
560 
561  protected:
563  int num_;
566 }; // class InsufficientBytesError
567 
568 
571 {
572  public:
577  LineLengthError(int length, int expected);
578  LineLengthError(LineLengthError const& rhs);
579 
580  virtual int length() const throw()
581  { return length_; }
582 
583  virtual int expected() const throw()
584  { return expected_; }
585 
586  protected:
588  int length_;
591 }; // class LineLengthError
592 
593 } // namespace hokuyoaist
594 
597 #endif // INCLUDE_HOKUYOAIST_HOKUYO_ERRORS_H__
ProtocolError(unsigned int desc_code)
Protocol error constructor.
Command echo error.
RuntimeError(unsigned int desc_code, char const *error_type)
Bad checksum error.
Write error class.
Logic error class.
Definition: hokuyo_errors.h:98
virtual char const *const error_code() const
Get the two-byte error code as a non-null-terminated array.
Incorrect line length error.
unsigned int baud() const
unsigned int baud_
Baud rate that caused the error.
ArgError(unsigned int desc_code)
Argument error constructor.
int line_length_
Length of the line.
Set IP error class.
virtual int length() const
unsigned int desc_code_
Description code for use with the error string table.
Definition: hokuyo_errors.h:87
Read error class.
int length_
The received line length.
virtual char cmd_code() const
Get the one-byte command code.
Insufficient bytes to calculate checksum error.
Bad index error class.
ProtocolError(unsigned int desc_code, char const *error_type)
Unknown SCIP version error class.
Baudrate error class.
Bad firmware error class.
LogicError(unsigned int desc_code, char const *error_type)
char cmd_
Command that triggered the error, from SCIP2 (two bytes).
Bad response error (SCIP1 version)
Runtime error class.
virtual char const *const cmd_code() const
Get the two-byte command code as a non-null-terminated array.
Close error class.
LogicError(unsigned int desc_code)
Logic error constructor.
std::string desc_code_to_string(unsigned int code)
Translates an error description code into a string.
#define HOKUYOAIST_EXPORT
Definition: hokuyo_errors.h:47
ReadError(unsigned int desc_code)
Read error constructor.
No data error class.
No destination error class.
virtual int calculated() const
Base protocol error.
UnsupportedError(unsigned int desc_code)
Unsupported error constructor.
SCIP version error class.
virtual char const * error_type() const
Definition: hokuyo_errors.h:80
virtual char error_code() const
Get the one-byte error code.
Parameter echo error.
int calculated_
Calculated checksum value.
virtual char const *const line() const
int expected_
Expected checksum value.
virtual int expected() const
virtual char const *const type() const
Bad argument error class.
std::string error_str_
Formatted description of the error.
Definition: hokuyo_errors.h:90
Invalid motor speed error class.
virtual char const *const cmd_code() const
Get the two-byte command code as a non-null-terminated array.
RuntimeError(unsigned int desc_code)
Runtime error constructor.
WriteError(unsigned int desc_code)
Write error constructor.
virtual int expected() const
Unsupported feature error class.
Bad response error - may be sent in response to any command.
virtual unsigned int desc_code() const
Definition: hokuyo_errors.h:77
int expected_
The expected line length.
Bad start step error class.
std::string scip2_error_to_string(char const *const error, char const *const cmd)
Translates a SCIP2 error code into a string.
Not a serial connection error class.
virtual char const *const cmd_code() const
Get the two-byte command code as a non-null-terminated array.
Incorrect number of data sets read error.
Misplaced line feed error.
virtual char const *const cmd_echo() const
Get the two-byte command echo as a non-null-terminated array.
char error_
Error code as defined in SCIP2 (two bytes).
Bad end step error class.
General error class.
Definition: hokuyo_errors.h:65
Missing firmware specification error.
virtual char const *const line() const
virtual int line_length() const
int num_
Number of bytes available.
ArgError(unsigned int desc_code, char const *error_type)