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 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
53namespace hokuyoaist
54{
55
57std::string scip2_error_to_string(char const* const error,
58 char const* const cmd);
59
61std::string desc_code_to_string(unsigned int code);
62
63
65class 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}; //class BaseError
95
96
99{
100 public:
104 LogicError(unsigned int desc_code)
105 : BaseError(desc_code, "LogicError")
106 {}
107 LogicError(unsigned int desc_code, char const* error_type)
108 : BaseError(desc_code, error_type)
109 {}
110 virtual ~LogicError() throw() {};
111}; // class LogicError
112
113
116{
117 public:
121 RuntimeError(unsigned int desc_code)
122 : BaseError(desc_code, "RuntimeError")
123 {}
124 RuntimeError(unsigned int desc_code, char const* error_type)
125 : BaseError(desc_code, error_type)
126 {}
127 virtual ~RuntimeError() throw() {}
128}; // class RuntimeError
129
130
133{
134 public:
138 ReadError(unsigned int desc_code)
139 : RuntimeError(desc_code, "ReadError")
140 {}
141}; // class ReadError
142
143
146{
147 public:
151 WriteError(unsigned int desc_code)
152 : RuntimeError(desc_code, "WriteError")
153 {}
154}; // class WriteError
155
156
159{
160 public:
164 BaudrateError(unsigned int baud);
166
167 unsigned int baud() const throw()
168 { return baud_; }
169
170 protected:
172 unsigned int baud_;
173}; // class BaudrateError
174
175
178{
179 public:
181 : RuntimeError(3, "CloseError")
182 {}
183}; // class CloseError
184
185
188{
189 public:
191 : RuntimeError(11, "NoDestinationError")
192 {}
193}; // class NoDestinationError
194
195
198{
199 public:
201 : RuntimeError(23, "FirmwareError")
202 {}
203}; // class FirmwareError
204
205
208{
209 public:
211 : RuntimeError(22, "ScipVersionError")
212 {}
213}; // class ScipVersionError
214
215
218{
219 public:
221 : RuntimeError(4, "UnknownScipVersionError")
222 {}
223}; // class UnknownScipVersionError
224
225
228{
229 public:
233 UnsupportedError(unsigned int desc_code)
234 : RuntimeError(desc_code, "UnsupportedError")
235 {}
236}; // class UnsupportedError
237
238
241{
242 public:
246 ArgError(unsigned int desc_code)
247 : RuntimeError(desc_code, "ArgError")
248 {}
249 ArgError(unsigned int desc_code, char const* error_type)
250 : RuntimeError(desc_code, error_type)
251 {}
252 virtual ~ArgError() throw() {};
253}; // class ArgError
254
255
258{
259 public:
261 : RuntimeError(13, "NoDataError")
262 {}
263}; // class NoDataError
264
265
268{
269 public:
271 : RuntimeError(5, "NotSerialError")
272 {}
273}; // class NotSerialError
274
275
278{
279 public:
281 : RuntimeError(2, "IndexError")
282 {}
283}; // class IndexError
284
285
288{
289 public:
291 : RuntimeError(37, "SetIPError")
292 {}
293}; // class SetIPError
294
295
298{
299 public:
301 : ArgError(9, "MotorSpeedError")
302 {}
303}; // class MotorSpeedError
304
305
308{
309 public:
311 : ArgError(14, "StartStepError")
312 {}
313}; // class StartStepError
314
315
318{
319 public:
321 : ArgError(15, "EndStepError")
322 {}
323}; // class EndStepError
324
325
328{
329 public:
333 ProtocolError(unsigned int desc_code)
334 : RuntimeError(desc_code, "ProtocolError")
335 {}
336 ProtocolError(unsigned int desc_code, char const* error_type)
337 : RuntimeError(desc_code, error_type)
338 {}
339 virtual ~ProtocolError() throw() {}
340}; // class ProtocolError
341
342
345{
346 public:
351 ChecksumError(int expected, int calculated);
353
354 virtual int expected() const throw()
355 { return expected_; }
356
357 virtual int calculated() const throw()
358 { return calculated_; }
359
360 protected:
365}; // class ProtocolError
366
367
370{
371 public:
373 : ProtocolError(25, "DataCountError")
374 {}
375}; // class DataCountError
376
377
380{
381 public:
383 : ProtocolError(26, "MisplacedLineFeedError")
384 {}
385}; // class MisplacedLineFeedError
386
387
390{
391 public:
395 UnknownLineError(char const* const line);
397
398 virtual char const* const line() const throw()
399 { return line_; }
400
401 protected:
403 char line_[128];
404}; // class UnknownLineError
405
406
409{
410 public:
415 ParseError(char const* const line, char const* const type);
417
418 virtual char const* const line() const throw()
419 { return line_; }
420
421 virtual char const* const type() const throw()
422 { return type_; }
423
424 protected:
426 char line_[128];
428 char type_[16];
429}; // class ParseError
430
431
434{
435 public:
437 : ProtocolError(29, "MissingFirmSpecError")
438 {}
439}; // class MissingFirmSpecError
440
441
444{
445 public:
450 ResponseError(char const* const error, char const* const cmd);
452
454 virtual char const* const error_code() const throw()
455 { return error_; }
456
458 virtual char const* const cmd_code() const throw()
459 { return cmd_; }
460
461 protected:
463 char error_[2];
465 char cmd_[2];
466}; // class ResponseError
467
468
471{
472 public:
477 Scip1ResponseError(char error, char cmd);
480 virtual char error_code() const throw()
481 { return error_; }
482
484 virtual char cmd_code() const throw()
485 { return cmd_; }
486
487 protected:
489 char error_;
491 char cmd_;
492}; // class Scip1ResponseError
493
494
497{
498 public:
503 CommandEchoError(char const* const cmd, char const* const echo);
505
507 virtual char const* const cmd_code() const throw()
508 { return cmd_; }
509
511 virtual char const* const cmd_echo() const throw()
512 { return echo_; }
513
514 protected:
516 char cmd_[2];
518 char echo_[2];
519}; // class CommandEchoError
520
521
524{
525 public:
529 ParamEchoError(char const* const cmd);
531
533 virtual char const* const cmd_code() const throw()
534 { return cmd_; }
535
536 protected:
538 char cmd_[2];
539}; // class ParamEchoError
540
541
544{
545 public:
550 InsufficientBytesError(int num, int line_length);
552
553 virtual int num() const throw()
554 { return num_; }
555
556 virtual int line_length() const throw()
557 { return line_length_; }
558
559 protected:
561 int num_;
564}; // class InsufficientBytesError
565
566
569{
570 public:
575 LineLengthError(int length, int expected);
577
578 virtual int length() const throw()
579 { return length_; }
580
581 virtual int expected() const throw()
582 { return expected_; }
583
584 protected:
589}; // class LineLengthError
590
591} // namespace hokuyoaist
592
595#endif // HOKUYO_ERRORS_H__
596
Bad argument error class.
ArgError(unsigned int desc_code, char const *error_type)
ArgError(unsigned int desc_code)
Argument error constructor.
General error class.
BaseError(unsigned int desc_code, char const *error_type)
Hokuyo error constructor.
BaseError(BaseError const &rhs)
virtual unsigned int desc_code() const
virtual char const * error_type() const
virtual const char * what() const
Baudrate error class.
BaudrateError(unsigned int baud)
Baud rate error constructor.
unsigned int baud_
Baud rate that caused the error.
unsigned int baud() const
BaudrateError(BaudrateError const &rhs)
Bad checksum error.
int calculated_
Calculated checksum value.
virtual int expected() const
ChecksumError(ChecksumError const &rhs)
ChecksumError(int expected, int calculated)
Checksum error constructor.
int expected_
Expected checksum value.
virtual int calculated() const
Close error class.
virtual char const *const cmd_code() const
Get the two-byte command code as a non-null-terminated array.
CommandEchoError(char const *const cmd, char const *const echo)
Command echo error constructor.
CommandEchoError(CommandEchoError const &rhs)
virtual char const *const cmd_echo() const
Get the two-byte command echo as a non-null-terminated array.
Incorrect number of data sets read error.
Bad end step error class.
Bad firmware error class.
Bad index error class.
Insufficient bytes to calculate checksum error.
InsufficientBytesError(InsufficientBytesError const &rhs)
int line_length_
Length of the line.
InsufficientBytesError(int num, int line_length)
Insufficient bytes error constructor.
int num_
Number of bytes available.
Incorrect line length error.
virtual int expected() const
int expected_
The expected line length.
int length_
The received line length.
virtual int length() const
LineLengthError(int length, int expected)
Line length error constructor.
LineLengthError(LineLengthError const &rhs)
Logic error class.
LogicError(unsigned int desc_code, char const *error_type)
LogicError(unsigned int desc_code)
Logic error constructor.
Misplaced line feed error.
Missing firmware specification error.
Invalid motor speed error class.
No data error class.
No destination error class.
Not a serial connection error class.
Parameter echo error.
virtual char const *const cmd_code() const
Get the two-byte command code as a non-null-terminated array.
ParamEchoError(char const *const cmd)
Parameter echo error constructor.
ParamEchoError(ParamEchoError const &rhs)
ParseError(ParseError const &rhs)
virtual char const *const type() const
virtual char const *const line() const
ParseError(char const *const line, char const *const type)
Parse error constructor.
Base protocol error.
ProtocolError(unsigned int desc_code, char const *error_type)
ProtocolError(unsigned int desc_code)
Protocol error constructor.
Read error class.
ReadError(unsigned int desc_code)
Read error constructor.
Bad response error - may be sent in response to any command.
virtual char const *const error_code() const
Get the two-byte error code as a non-null-terminated array.
ResponseError(ResponseError const &rhs)
ResponseError(char const *const error, char const *const cmd)
Response error constructor.
virtual char const *const cmd_code() const
Get the two-byte command code as a non-null-terminated array.
Runtime error class.
RuntimeError(unsigned int desc_code, char const *error_type)
RuntimeError(unsigned int desc_code)
Runtime error constructor.
Bad response error (SCIP1 version)
virtual char error_code() const
Get the one-byte error code.
char error_
Error code as defined in SCIP2 (two bytes).
char cmd_
Command that triggered the error, from SCIP2 (two bytes).
virtual char cmd_code() const
Get the one-byte command code.
Scip1ResponseError(char error, char cmd)
Response error constructor.
Scip1ResponseError(Scip1ResponseError const &rhs)
SCIP version error class.
Set IP error class.
Bad start step error class.
virtual char const *const line() const
UnknownLineError(UnknownLineError const &rhs)
UnknownLineError(char const *const line)
Unknown line error constructor.
Unknown SCIP version error class.
Unsupported feature error class.
UnsupportedError(unsigned int desc_code)
Unsupported error constructor.
Write error class.
WriteError(unsigned int desc_code)
Write error constructor.
#define HOKUYOAIST_EXPORT
std::string desc_code_to_string(unsigned int code)
Translates an error description code into a string.
std::string scip2_error_to_string(char const *const error, char const *const cmd)
Translates a SCIP2 error code into a string.