HokuyoAIST  3.0.1
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 HOKUYO_ERRORS_H__
30 #define HOKUYO_ERRORS_H__
31 
32 #include <sstream>
33 
34 #if defined(WIN32)
35  typedef unsigned char uint8_t;
36  typedef unsigned int uint32_t;
37  #if defined(HOKUYOAIST_STATIC)
38  #define HOKUYOAIST_EXPORT
39  #elif defined(hokuyoaist_EXPORTS)
40  #define HOKUYOAIST_EXPORT __declspec(dllexport)
41  #else
42  #define HOKUYOAIST_EXPORT __declspec(dllimport)
43  #endif
44 #else
45  #include <stdint.h>
46  #define HOKUYOAIST_EXPORT
47 #endif
48 
53 namespace hokuyoaist
54 {
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 #if __cplusplus >= 201103L
84  virtual const char* what() const throw();
85 #else
86  virtual const char* what() throw();
87 #endif
88 
89  protected:
91  unsigned int desc_code_;
92 
94  std::stringstream ss;
96  char error_type_[32];
97 }; //class BaseError
98 
99 
102 {
103  public:
107  LogicError(unsigned int desc_code)
108  : BaseError(desc_code, "LogicError")
109  {}
110  LogicError(unsigned int desc_code, char const* error_type)
111  : BaseError(desc_code, error_type)
112  {}
113  virtual ~LogicError() throw() {};
114 }; // class LogicError
115 
116 
119 {
120  public:
124  RuntimeError(unsigned int desc_code)
125  : BaseError(desc_code, "RuntimeError")
126  {}
127  RuntimeError(unsigned int desc_code, char const* error_type)
128  : BaseError(desc_code, error_type)
129  {}
130  virtual ~RuntimeError() throw() {};
131 }; // class RuntimeError
132 
133 
136 {
137  public:
141  ReadError(unsigned int desc_code)
142  : RuntimeError(desc_code, "ReadError")
143  {}
144 }; // class ReadError
145 
146 
149 {
150  public:
154  WriteError(unsigned int desc_code)
155  : RuntimeError(desc_code, "WriteError")
156  {}
157 }; // class WriteError
158 
159 
162 {
163  public:
167  BaudrateError(unsigned int baud)
168  : RuntimeError(6, "BaudrateError"), baud_(baud)
169  {}
171  : RuntimeError(rhs), baud_(rhs.baud())
172  {}
173 
174  unsigned int baud() const throw()
175  { return baud_; }
176 
177 #if __cplusplus >= 201103L
178  virtual const char* what() const throw();
179 #else
180  virtual const char* what() throw();
181 #endif
182 
183  protected:
185  unsigned int baud_;
186 }; // class BaudrateError
187 
188 
191 {
192  public:
194  : RuntimeError(3, "CloseError")
195  {}
196 }; // class CloseError
197 
198 
201 {
202  public:
204  : RuntimeError(11, "NoDestinationError")
205  {}
206 }; // class NoDestinationError
207 
208 
211 {
212  public:
214  : RuntimeError(23, "FirmwareError")
215  {}
216 }; // class FirmwareError
217 
218 
221 {
222  public:
224  : RuntimeError(22, "ScipVersionError")
225  {}
226 }; // class ScipVersionError
227 
228 
231 {
232  public:
234  : RuntimeError(4, "UnknownScipVersionError")
235  {}
236 }; // class UnknownScipVersionError
237 
238 
241 {
242  public:
246  UnsupportedError(unsigned int desc_code)
247  : RuntimeError(desc_code, "UnsupportedError")
248  {}
249 }; // class UnsupportedError
250 
251 
254 {
255  public:
259  ArgError(unsigned int desc_code)
260  : RuntimeError(desc_code, "ArgError")
261  {}
262  ArgError(unsigned int desc_code, char const* error_type)
263  : RuntimeError(desc_code, error_type)
264  {}
265  virtual ~ArgError() throw() {};
266 }; // class ArgError
267 
268 
271 {
272  public:
274  : RuntimeError(13, "NoDataError")
275  {}
276 }; // class NoDataError
277 
278 
281 {
282  public:
284  : RuntimeError(5, "NotSerialError")
285  {}
286 }; // class NotSerialError
287 
288 
291 {
292  public:
294  : RuntimeError(2, "IndexError")
295  {}
296 }; // class IndexError
297 
298 
301 {
302  public:
304  : RuntimeError(37, "SetIPError")
305  {}
306 }; // class SetIPError
307 
308 
311 {
312  public:
314  : ArgError(9, "MotorSpeedError")
315  {}
316 }; // class MotorSpeedError
317 
318 
321 {
322  public:
324  : ArgError(14, "StartStepError")
325  {}
326 }; // class StartStepError
327 
328 
331 {
332  public:
334  : ArgError(15, "EndStepError")
335  {}
336 }; // class EndStepError
337 
338 
341 {
342  public:
346  ProtocolError(unsigned int desc_code)
347  : RuntimeError(desc_code, "ProtocolError")
348  {}
349  ProtocolError(unsigned int desc_code, char const* error_type)
350  : RuntimeError(desc_code, error_type)
351  {}
352  virtual ~ProtocolError() throw() {}
353 }; // class ProtocolError
354 
355 
358 {
359  public:
364  ChecksumError(int expected, int calculated)
365  : ProtocolError(24, "ChecksumError"), expected_(expected),
366  calculated_(calculated)
367  {}
369  : ProtocolError(rhs), expected_(rhs.expected()),
370  calculated_(rhs.calculated())
371  {}
372 
373  virtual int expected() const throw()
374  { return expected_; }
375 
376  virtual int calculated() const throw()
377  { return calculated_; }
378 
379 #if __cplusplus >= 201103L
380  virtual const char* what() const throw();
381 #else
382  virtual const char* what() throw();
383 #endif
384 
385  protected:
390 }; // class ProtocolError
391 
392 
395 {
396  public:
398  : ProtocolError(25, "DataCountError")
399  {}
400 }; // class DataCountError
401 
402 
405 {
406  public:
408  : ProtocolError(26, "MisplacedLineFeedError")
409  {}
410 }; // class MisplacedLineFeedError
411 
412 
415 {
416  public:
420  UnknownLineError(char const* const line);
422 
423  virtual char const* const line() const throw()
424  { return line_; }
425 
426 #if __cplusplus >= 201103L
427  virtual const char* what() const throw();
428 #else
429  virtual const char* what() throw();
430 #endif
431 
432  protected:
434  char line_[128];
435 }; // class UnknownLineError
436 
437 
440 {
441  public:
446  ParseError(char const* const line, char const* const type);
447  ParseError(ParseError const& rhs);
448 
449  virtual char const* const line() const throw()
450  { return line_; }
451 
452  virtual char const* const type() const throw()
453  { return type_; }
454 
455 #if __cplusplus >= 201103L
456  virtual const char* what() const throw();
457 #else
458  virtual const char* what() throw();
459 #endif
460 
461  protected:
463  char line_[128];
465  char type_[16];
466 }; // class ParseError
467 
468 
471 {
472  public:
474  : ProtocolError(29, "MissingFirmSpecError")
475  {}
476 }; // class MissingFirmSpecError
477 
478 
481 {
482  public:
487  ResponseError(char const* const error, char const* const cmd)
488  : ProtocolError(30, "ResponseError")
489  {
490  error_[0] = error[0]; error_[1] = error[1];
491  cmd_[0] = cmd[0]; cmd_[1] = cmd[1];
492  }
494  : ProtocolError(rhs)
495  {
496  error_[0] = rhs.error_code()[0];
497  error_[1] = rhs.error_code()[1];
498  cmd_[0] = rhs.cmd_code()[0];
499  cmd_[1] = rhs.cmd_code()[1];
500  }
501 
503  virtual char const* const error_code() const throw()
504  { return error_; }
505 
507  virtual char const* const cmd_code() const throw()
508  { return cmd_; }
509 
510 #if __cplusplus >= 201103L
511  virtual const char* what() const throw();
512 #else
513  virtual const char* what() throw();
514 #endif
515 
516  protected:
518  char error_[2];
520  char cmd_[2];
521 }; // class ResponseError
522 
523 
526 {
527  public:
532  Scip1ResponseError(char error, char cmd)
533  : ProtocolError(30, "Scip1ResponseError"),
534  error_(error), cmd_(cmd)
535  {}
537  : ProtocolError(rhs), error_(rhs.error_code()),
538  cmd_(rhs.cmd_code())
539  {}
540 
542  virtual char error_code() const throw()
543  { return error_; }
544 
546  virtual char cmd_code() const throw()
547  { return cmd_; }
548 
549 #if __cplusplus >= 201103L
550  virtual const char* what() const throw();
551 #else
552  virtual const char* what() throw();
553 #endif
554 
555  protected:
557  char error_;
559  char cmd_;
560 }; // class Scip1ResponseError
561 
562 
565 {
566  public:
571  CommandEchoError(char const* const cmd, char const* const echo)
572  : ProtocolError(31, "CommandEchoError")
573  {
574  cmd_[0] = cmd[0]; cmd_[1] = cmd[1];
575  echo_[0] = echo[0]; echo_[1] = echo[1];
576  }
578  : ProtocolError(rhs)
579  {
580  cmd_[0] = rhs.cmd_code()[0];
581  cmd_[1] = rhs.cmd_code()[1];
582  echo_[0] = rhs.cmd_echo()[0];
583  echo_[1] = rhs.cmd_echo()[1];
584  }
585 
587  virtual char const* const cmd_code() const throw()
588  { return cmd_; }
589 
591  virtual char const* const cmd_echo() const throw()
592  { return echo_; }
593 
594 #if __cplusplus >= 201103L
595  virtual const char* what() const throw();
596 #else
597  virtual const char* what() throw();
598 #endif
599 
600  protected:
602  char cmd_[2];
604  char echo_[2];
605 }; // class CommandEchoError
606 
607 
610 {
611  public:
615  ParamEchoError(char const* const cmd)
616  : ProtocolError(32, "ParamEchoError")
617  {
618  cmd_[0] = cmd[0]; cmd_[1] = cmd[1];
619  }
621  : ProtocolError(rhs)
622  {
623  cmd_[0] = rhs.cmd_code()[0];
624  cmd_[1] = rhs.cmd_code()[1];
625  }
626 
628  virtual char const* const cmd_code() const throw()
629  { return cmd_; }
630 
631 #if __cplusplus >= 201103L
632  virtual const char* what() const throw();
633 #else
634  virtual const char* what() throw();
635 #endif
636 
637  protected:
639  char cmd_[2];
640 }; // class ParamEchoError
641 
642 
645 {
646  public:
651  InsufficientBytesError(int num, int line_length)
652  : ProtocolError(33, "InsufficientBytesError"),
653  num_(num), line_length_(line_length)
654  {}
656  : ProtocolError(rhs), num_(rhs.num()),
657  line_length_(rhs.line_length())
658  {}
659 
660  virtual int num() const throw()
661  { return num_; }
662 
663  virtual int line_length() const throw()
664  { return line_length_; }
665 
666 #if __cplusplus >= 201103L
667  virtual const char* what() const throw();
668 #else
669  virtual const char* what() throw();
670 #endif
671 
672  protected:
674  int num_;
677 }; // class InsufficientBytesError
678 
679 
682 {
683  public:
688  LineLengthError(int length, int expected)
689  : ProtocolError(34, "LineLengthError"),
690  length_(length), expected_(expected)
691  {}
693  : ProtocolError(rhs), length_(rhs.length()),
694  expected_(rhs.expected())
695  {}
696 
697  virtual int length() const throw()
698  { return length_; }
699 
700  virtual int expected() const throw()
701  { return expected_; }
702 
703 #if __cplusplus >= 201103L
704  virtual const char* what() const throw();
705 #else
706  virtual const char* what() throw();
707 #endif
708 
709  protected:
711  int length_;
714 }; // class LineLengthError
715 
716 }; // namespace hokuyoaist
717 
720 #endif // HOKUYO_ERRORS_H__
721 
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.
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
BaudrateError(unsigned int baud)
Baud rate error constructor.
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
std::stringstream ss
Formatted description of the error.
Definition: hokuyo_errors.h:94
unsigned int desc_code_
Description code for use with the error string table.
Definition: hokuyo_errors.h:91
ParamEchoError(char const *const cmd)
Parameter echo error constructor.
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.
CommandEchoError(char const *const cmd, char const *const echo)
Command echo error constructor.
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)
LineLengthError(LineLengthError const &rhs)
Scip1ResponseError(char error, char cmd)
Response error constructor.
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:46
ReadError(unsigned int desc_code)
Read error constructor.
ResponseError(ResponseError const &rhs)
InsufficientBytesError(int num, int line_length)
Insufficient bytes error constructor.
No data error class.
No destination error class.
ChecksumError(int expected, int calculated)
Checksum error constructor.
virtual int calculated() const
Base protocol error.
UnsupportedError(unsigned int desc_code)
Unsupported error constructor.
SCIP version error class.
ChecksumError(ChecksumError const &rhs)
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.
CommandEchoError(CommandEchoError const &rhs)
virtual char const *const line() const
int expected_
Expected checksum value.
virtual int expected() const
virtual char const *const type() const
InsufficientBytesError(InsufficientBytesError const &rhs)
Bad argument error class.
ResponseError(char const *const error, char const *const cmd)
Response error constructor.
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.
BaudrateError(BaudrateError const &rhs)
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.
LineLengthError(int length, int expected)
Line length error constructor.
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.
Scip1ResponseError(Scip1ResponseError const &rhs)
ParamEchoError(ParamEchoError const &rhs)
ArgError(unsigned int desc_code, char const *error_type)