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  virtual const char* what() throw();
84 
85  protected:
87  unsigned int desc_code_;
88 
90  std::stringstream ss;
92  char error_type_[32];
93 }; //class BaseError
94 
95 
98 {
99  public:
103  LogicError(unsigned int desc_code)
104  : BaseError(desc_code, "LogicError")
105  {}
106  LogicError(unsigned int desc_code, char const* error_type)
107  : BaseError(desc_code, error_type)
108  {}
109  virtual ~LogicError() throw() {};
110 }; // class LogicError
111 
112 
115 {
116  public:
120  RuntimeError(unsigned int desc_code)
121  : BaseError(desc_code, "RuntimeError")
122  {}
123  RuntimeError(unsigned int desc_code, char const* error_type)
124  : BaseError(desc_code, error_type)
125  {}
126  virtual ~RuntimeError() throw() {};
127 }; // class RuntimeError
128 
129 
132 {
133  public:
137  ReadError(unsigned int desc_code)
138  : RuntimeError(desc_code, "ReadError")
139  {}
140 }; // class ReadError
141 
142 
145 {
146  public:
150  WriteError(unsigned int desc_code)
151  : RuntimeError(desc_code, "WriteError")
152  {}
153 }; // class WriteError
154 
155 
158 {
159  public:
163  BaudrateError(unsigned int baud)
164  : RuntimeError(6, "BaudrateError"), baud_(baud)
165  {}
167  : RuntimeError(rhs), baud_(rhs.baud())
168  {}
169 
170  unsigned int baud() const throw()
171  { return baud_; }
172 
173  const char* what() throw();
174 
175  protected:
177  unsigned int baud_;
178 }; // class BaudrateError
179 
180 
183 {
184  public:
186  : RuntimeError(3, "CloseError")
187  {}
188 }; // class CloseError
189 
190 
193 {
194  public:
196  : RuntimeError(11, "NoDestinationError")
197  {}
198 }; // class NoDestinationError
199 
200 
203 {
204  public:
206  : RuntimeError(23, "FirmwareError")
207  {}
208 }; // class FirmwareError
209 
210 
213 {
214  public:
216  : RuntimeError(22, "ScipVersionError")
217  {}
218 }; // class ScipVersionError
219 
220 
223 {
224  public:
226  : RuntimeError(4, "UnknownScipVersionError")
227  {}
228 }; // class UnknownScipVersionError
229 
230 
233 {
234  public:
238  UnsupportedError(unsigned int desc_code)
239  : RuntimeError(desc_code, "UnsupportedError")
240  {}
241 }; // class UnsupportedError
242 
243 
246 {
247  public:
251  ArgError(unsigned int desc_code)
252  : RuntimeError(desc_code, "ArgError")
253  {}
254  ArgError(unsigned int desc_code, char const* error_type)
255  : RuntimeError(desc_code, error_type)
256  {}
257  virtual ~ArgError() throw() {};
258 }; // class ArgError
259 
260 
263 {
264  public:
266  : RuntimeError(13, "NoDataError")
267  {}
268 }; // class NoDataError
269 
270 
273 {
274  public:
276  : RuntimeError(5, "NotSerialError")
277  {}
278 }; // class NotSerialError
279 
280 
283 {
284  public:
286  : RuntimeError(2, "IndexError")
287  {}
288 }; // class IndexError
289 
290 
293 {
294  public:
296  : RuntimeError(37, "SetIPError")
297  {}
298 }; // class SetIPError
299 
300 
303 {
304  public:
306  : ArgError(9, "MotorSpeedError")
307  {}
308 }; // class MotorSpeedError
309 
310 
313 {
314  public:
316  : ArgError(14, "StartStepError")
317  {}
318 }; // class StartStepError
319 
320 
323 {
324  public:
326  : ArgError(15, "EndStepError")
327  {}
328 }; // class EndStepError
329 
330 
333 {
334  public:
338  ProtocolError(unsigned int desc_code)
339  : RuntimeError(desc_code, "ProtocolError")
340  {}
341  ProtocolError(unsigned int desc_code, char const* error_type)
342  : RuntimeError(desc_code, error_type)
343  {}
344  virtual ~ProtocolError() throw() {}
345 }; // class ProtocolError
346 
347 
350 {
351  public:
356  ChecksumError(int expected, int calculated)
357  : ProtocolError(24, "ChecksumError"), expected_(expected),
358  calculated_(calculated)
359  {}
361  : ProtocolError(rhs), expected_(rhs.expected()),
362  calculated_(rhs.calculated())
363  {}
364 
365  virtual int expected() const throw()
366  { return expected_; }
367 
368  virtual int calculated() const throw()
369  { return calculated_; }
370 
371  const char* what() throw();
372 
373  protected:
375  int expected_;
377  int calculated_;
378 }; // class ProtocolError
379 
380 
383 {
384  public:
386  : ProtocolError(25, "DataCountError")
387  {}
388 }; // class DataCountError
389 
390 
393 {
394  public:
396  : ProtocolError(26, "MisplacedLineFeedError")
397  {}
398 }; // class MisplacedLineFeedError
399 
400 
403 {
404  public:
408  UnknownLineError(char const* const line);
410 
411  virtual char const* const line() const throw()
412  { return line_; }
413 
414  const char* what() throw();
415 
416  protected:
418  char line_[128];
419 }; // class UnknownLineError
420 
421 
424 {
425  public:
430  ParseError(char const* const line, char const* const type);
431  ParseError(ParseError const& rhs);
432 
433  virtual char const* const line() const throw()
434  { return line_; }
435 
436  virtual char const* const type() const throw()
437  { return type_; }
438 
439  const char* what() throw();
440 
441  protected:
443  char line_[128];
445  char type_[16];
446 }; // class ParseError
447 
448 
450 class HOKUYOAIST_EXPORT MissingFirmSpecError: public ProtocolError
451 {
452  public:
454  : ProtocolError(29, "MissingFirmSpecError")
455  {}
456 }; // class MissingFirmSpecError
457 
458 
460 class HOKUYOAIST_EXPORT ResponseError: public ProtocolError
461 {
462  public:
467  ResponseError(char const* const error, char const* const cmd)
468  : ProtocolError(30, "ResponseError")
469  {
470  error_[0] = error[0]; error_[1] = error[1];
471  cmd_[0] = cmd[0]; cmd_[1] = cmd[1];
472  }
474  : ProtocolError(rhs)
475  {
476  error_[0] = rhs.error_code()[0];
477  error_[1] = rhs.error_code()[1];
478  cmd_[0] = rhs.cmd_code()[0];
479  cmd_[1] = rhs.cmd_code()[1];
480  }
481 
483  virtual char const* const error_code() const throw()
484  { return error_; }
485 
487  virtual char const* const cmd_code() const throw()
488  { return cmd_; }
489 
490  const char* what() throw();
491 
492  protected:
494  char error_[2];
496  char cmd_[2];
497 }; // class ResponseError
498 
499 
501 class HOKUYOAIST_EXPORT Scip1ResponseError: public ProtocolError
502 {
503  public:
508  Scip1ResponseError(char error, char cmd)
509  : ProtocolError(30, "Scip1ResponseError"),
510  error_(error), cmd_(cmd)
511  {}
513  : ProtocolError(rhs), error_(rhs.error_code()),
514  cmd_(rhs.cmd_code())
515  {}
516 
518  virtual char error_code() const throw()
519  { return error_; }
520 
522  virtual char cmd_code() const throw()
523  { return cmd_; }
524 
525  const char* what() throw();
526 
527  protected:
529  char error_;
531  char cmd_;
532 }; // class Scip1ResponseError
533 
534 
536 class HOKUYOAIST_EXPORT CommandEchoError: public ProtocolError
537 {
538  public:
543  CommandEchoError(char const* const cmd, char const* const echo)
544  : ProtocolError(31, "CommandEchoError")
545  {
546  cmd_[0] = cmd[0]; cmd_[1] = cmd[1];
547  echo_[0] = echo[0]; echo_[1] = echo[1];
548  }
550  : ProtocolError(rhs)
551  {
552  cmd_[0] = rhs.cmd_code()[0];
553  cmd_[1] = rhs.cmd_code()[1];
554  echo_[0] = rhs.cmd_echo()[0];
555  echo_[1] = rhs.cmd_echo()[1];
556  }
557 
559  virtual char const* const cmd_code() const throw()
560  { return cmd_; }
561 
563  virtual char const* const cmd_echo() const throw()
564  { return echo_; }
565 
566  const char* what() throw();
567 
568  protected:
570  char cmd_[2];
572  char echo_[2];
573 }; // class CommandEchoError
574 
575 
577 class HOKUYOAIST_EXPORT ParamEchoError: public ProtocolError
578 {
579  public:
583  ParamEchoError(char const* const cmd)
584  : ProtocolError(32, "ParamEchoError")
585  {
586  cmd_[0] = cmd[0]; cmd_[1] = cmd[1];
587  }
589  : ProtocolError(rhs)
590  {
591  cmd_[0] = rhs.cmd_code()[0];
592  cmd_[1] = rhs.cmd_code()[1];
593  }
594 
596  virtual char const* const cmd_code() const throw()
597  { return cmd_; }
598 
599  const char* what() throw();
600 
601  protected:
603  char cmd_[2];
604 }; // class ParamEchoError
605 
606 
608 class HOKUYOAIST_EXPORT InsufficientBytesError: public ProtocolError
609 {
610  public:
615  InsufficientBytesError(int num, int line_length)
616  : ProtocolError(33, "InsufficientBytesError"),
617  num_(num), line_length_(line_length)
618  {}
620  : ProtocolError(rhs), num_(rhs.num()),
621  line_length_(rhs.line_length())
622  {}
623 
624  virtual int num() const throw()
625  { return num_; }
626 
627  virtual int line_length() const throw()
628  { return line_length_; }
629 
630  const char* what() throw();
631 
632  protected:
634  int num_;
636  int line_length_;
637 }; // class InsufficientBytesError
638 
639 
641 class HOKUYOAIST_EXPORT LineLengthError: public ProtocolError
642 {
643  public:
648  LineLengthError(int length, int expected)
649  : ProtocolError(34, "LineLengthError"),
650  length_(length), expected_(expected)
651  {}
653  : ProtocolError(rhs), length_(rhs.length()),
654  expected_(rhs.expected())
655  {}
656 
657  virtual int length() const throw()
658  { return length_; }
659 
660  virtual int expected() const throw()
661  { return expected_; }
662 
663  const char* what() throw();
664 
665  protected:
667  int length_;
669  int expected_;
670 }; // class LineLengthError
671 
672 }; // namespace hokuyoaist
673 
676 #endif // HOKUYO_ERRORS_H__
677