INTRODUCTION Overview Download and Install Documentation Publications REPOSITORY Libraries DEVELOPER Dev Guide Dashboard PEOPLE Contributors Users Project Download Mailing lists
|
hokuyo_errors.h00001 /* 00002 * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics 00003 * http://gearbox.sf.net/ 00004 * Copyright (c) 2008-2010 Geoffrey Biggs 00005 * 00006 * hokuyo_aist Hokuyo laser scanner driver. 00007 * 00008 * This distribution is licensed to you under the terms described in the 00009 * LICENSE file included in this distribution. 00010 * 00011 * This work is a product of the National Institute of Advanced Industrial 00012 * Science and Technology, Japan. Registration number: H22PRO-1086. 00013 * 00014 * This file is part of hokuyo_aist. 00015 * 00016 * This software is licensed under the Eclipse Public License -v 1.0 (EPL). See 00017 * http://www.opensource.org/licenses/eclipse-1.0.txt 00018 */ 00019 00020 #ifndef HOKUYO_ERRORS_H__ 00021 #define HOKUYO_ERRORS_H__ 00022 00023 #include <sstream> 00024 00025 #if defined(WIN32) 00026 typedef unsigned char uint8_t; 00027 typedef unsigned int uint32_t; 00028 #if defined(HOKUYO_AIST_STATIC) 00029 #define HOKUYO_AIST_EXPORT 00030 #elif defined(HOKUYO_AIST_EXPORTS) 00031 #define HOKUYO_AIST_EXPORT __declspec(dllexport) 00032 #else 00033 #define HOKUYO_AIST_EXPORT __declspec(dllimport) 00034 #endif 00035 #else 00036 #include <stdint.h> 00037 #define HOKUYO_AIST_EXPORT 00038 #endif 00039 00044 namespace hokuyo_aist 00045 { 00046 00048 std::string scip2_error_to_string(char const* const error, 00049 char const* const cmd); 00050 00052 std::string desc_code_to_string(unsigned int code); 00053 00054 00056 class HOKUYO_AIST_EXPORT BaseError : public std::exception 00057 { 00058 public: 00062 BaseError(unsigned int desc_code, char const* error_type); 00063 BaseError(BaseError const& rhs); 00064 virtual ~BaseError() throw() {}; 00065 00066 virtual unsigned int desc_code() const throw() 00067 { return desc_code_; } 00068 00069 virtual char const* error_type() const throw() 00070 { return error_type_; } 00071 00072 virtual const char* what() throw(); 00073 00074 protected: 00076 unsigned int desc_code_; 00077 00079 std::stringstream ss; 00081 char error_type_[32]; 00082 }; //class BaseError 00083 00084 00086 class HOKUYO_AIST_EXPORT LogicError : public BaseError 00087 { 00088 public: 00092 LogicError(unsigned int desc_code) 00093 : BaseError(desc_code, "LogicError") 00094 {} 00095 LogicError(unsigned int desc_code, char const* error_type) 00096 : BaseError(desc_code, error_type) 00097 {} 00098 virtual ~LogicError() throw() {}; 00099 }; // class LogicError 00100 00101 00103 class HOKUYO_AIST_EXPORT RuntimeError : public BaseError 00104 { 00105 public: 00109 RuntimeError(unsigned int desc_code) 00110 : BaseError(desc_code, "RuntimeError") 00111 {} 00112 RuntimeError(unsigned int desc_code, char const* error_type) 00113 : BaseError(desc_code, error_type) 00114 {} 00115 virtual ~RuntimeError() throw() {}; 00116 }; // class RuntimeError 00117 00118 00120 class HOKUYO_AIST_EXPORT ReadError: public RuntimeError 00121 { 00122 public: 00126 ReadError(unsigned int desc_code) 00127 : RuntimeError(desc_code, "ReadError") 00128 {} 00129 }; // class ReadError 00130 00131 00133 class HOKUYO_AIST_EXPORT WriteError: public RuntimeError 00134 { 00135 public: 00139 WriteError(unsigned int desc_code) 00140 : RuntimeError(desc_code, "WriteError") 00141 {} 00142 }; // class WriteError 00143 00144 00146 class HOKUYO_AIST_EXPORT BaudrateError: public RuntimeError 00147 { 00148 public: 00152 BaudrateError(unsigned int baud) 00153 : RuntimeError(6, "BaudrateError"), baud_(baud) 00154 {} 00155 BaudrateError(BaudrateError const& rhs) 00156 : RuntimeError(rhs), baud_(rhs.baud()) 00157 {} 00158 00159 unsigned int baud() const throw() 00160 { return baud_; } 00161 00162 const char* what() throw(); 00163 00164 protected: 00166 unsigned int baud_; 00167 }; // class BaudrateError 00168 00169 00171 class HOKUYO_AIST_EXPORT CloseError: public RuntimeError 00172 { 00173 public: 00174 CloseError() 00175 : RuntimeError(3, "CloseError") 00176 {} 00177 }; // class CloseError 00178 00179 00181 class HOKUYO_AIST_EXPORT NoDestinationError: public RuntimeError 00182 { 00183 public: 00184 NoDestinationError() 00185 : RuntimeError(11, "NoDestinationError") 00186 {} 00187 }; // class NoDestinationError 00188 00189 00191 class HOKUYO_AIST_EXPORT FirmwareError: public RuntimeError 00192 { 00193 public: 00194 FirmwareError() 00195 : RuntimeError(23, "FirmwareError") 00196 {} 00197 }; // class FirmwareError 00198 00199 00201 class HOKUYO_AIST_EXPORT ScipVersionError: public RuntimeError 00202 { 00203 public: 00204 ScipVersionError() 00205 : RuntimeError(22, "ScipVersionError") 00206 {} 00207 }; // class ScipVersionError 00208 00209 00211 class HOKUYO_AIST_EXPORT UnknownScipVersionError: public RuntimeError 00212 { 00213 public: 00214 UnknownScipVersionError() 00215 : RuntimeError(4, "UnknownScipVersionError") 00216 {} 00217 }; // class UnknownScipVersionError 00218 00219 00221 class HOKUYO_AIST_EXPORT UnsupportedError: public RuntimeError 00222 { 00223 public: 00227 UnsupportedError(unsigned int desc_code) 00228 : RuntimeError(desc_code, "UnsupportedError") 00229 {} 00230 }; // class UnsupportedError 00231 00232 00234 class HOKUYO_AIST_EXPORT ArgError: public RuntimeError 00235 { 00236 public: 00240 ArgError(unsigned int desc_code) 00241 : RuntimeError(desc_code, "ArgError") 00242 {} 00243 ArgError(unsigned int desc_code, char const* error_type) 00244 : RuntimeError(desc_code, error_type) 00245 {} 00246 virtual ~ArgError() throw() {}; 00247 }; // class ArgError 00248 00249 00251 class HOKUYO_AIST_EXPORT NoDataError: public RuntimeError 00252 { 00253 public: 00254 NoDataError() 00255 : RuntimeError(13, "NoDataError") 00256 {} 00257 }; // class NoDataError 00258 00259 00261 class HOKUYO_AIST_EXPORT NotSerialError: public RuntimeError 00262 { 00263 public: 00264 NotSerialError() 00265 : RuntimeError(5, "NotSerialError") 00266 {} 00267 }; // class NotSerialError 00268 00269 00271 class HOKUYO_AIST_EXPORT IndexError: public RuntimeError 00272 { 00273 public: 00274 IndexError() 00275 : RuntimeError(2, "IndexError") 00276 {} 00277 }; // class IndexError 00278 00279 00281 class HOKUYO_AIST_EXPORT SetIPError: public RuntimeError 00282 { 00283 public: 00284 SetIPError() 00285 : RuntimeError(37, "SetIPError") 00286 {} 00287 }; // class SetIPError 00288 00289 00291 class HOKUYO_AIST_EXPORT MotorSpeedError: public ArgError 00292 { 00293 public: 00294 MotorSpeedError() 00295 : ArgError(9, "MotorSpeedError") 00296 {} 00297 }; // class MotorSpeedError 00298 00299 00301 class HOKUYO_AIST_EXPORT StartStepError: public ArgError 00302 { 00303 public: 00304 StartStepError() 00305 : ArgError(14, "StartStepError") 00306 {} 00307 }; // class StartStepError 00308 00309 00311 class HOKUYO_AIST_EXPORT EndStepError: public ArgError 00312 { 00313 public: 00314 EndStepError() 00315 : ArgError(15, "EndStepError") 00316 {} 00317 }; // class EndStepError 00318 00319 00321 class HOKUYO_AIST_EXPORT ProtocolError: public RuntimeError 00322 { 00323 public: 00327 ProtocolError(unsigned int desc_code) 00328 : RuntimeError(desc_code, "ProtocolError") 00329 {} 00330 ProtocolError(unsigned int desc_code, char const* error_type) 00331 : RuntimeError(desc_code, error_type) 00332 {} 00333 virtual ~ProtocolError() throw() {} 00334 }; // class ProtocolError 00335 00336 00338 class HOKUYO_AIST_EXPORT ChecksumError: public ProtocolError 00339 { 00340 public: 00345 ChecksumError(int expected, int calculated) 00346 : ProtocolError(24, "ChecksumError"), expected_(expected), 00347 calculated_(calculated) 00348 {} 00349 ChecksumError(ChecksumError const& rhs) 00350 : ProtocolError(rhs), expected_(rhs.expected()), 00351 calculated_(rhs.calculated()) 00352 {} 00353 00354 virtual int expected() const throw() 00355 { return expected_; } 00356 00357 virtual int calculated() const throw() 00358 { return calculated_; } 00359 00360 const char* what() throw(); 00361 00362 protected: 00364 int expected_; 00366 int calculated_; 00367 }; // class ProtocolError 00368 00369 00371 class HOKUYO_AIST_EXPORT DataCountError: public ProtocolError 00372 { 00373 public: 00374 DataCountError() 00375 : ProtocolError(25, "DataCountError") 00376 {} 00377 }; // class DataCountError 00378 00379 00381 class HOKUYO_AIST_EXPORT MisplacedLineFeedError: public ProtocolError 00382 { 00383 public: 00384 MisplacedLineFeedError() 00385 : ProtocolError(26, "MisplacedLineFeedError") 00386 {} 00387 }; // class MisplacedLineFeedError 00388 00389 00391 class HOKUYO_AIST_EXPORT UnknownLineError: public ProtocolError 00392 { 00393 public: 00397 UnknownLineError(char const* const line); 00398 UnknownLineError(UnknownLineError const& rhs); 00399 00400 virtual char const* const line() const throw() 00401 { return line_; } 00402 00403 const char* what() throw(); 00404 00405 protected: 00407 char line_[128]; 00408 }; // class UnknownLineError 00409 00410 00412 class HOKUYO_AIST_EXPORT ParseError: public ProtocolError 00413 { 00414 public: 00419 ParseError(char const* const line, char const* const type); 00420 ParseError(ParseError const& rhs); 00421 00422 virtual char const* const line() const throw() 00423 { return line_; } 00424 00425 virtual char const* const type() const throw() 00426 { return type_; } 00427 00428 const char* what() throw(); 00429 00430 protected: 00432 char line_[128]; 00434 char type_[16]; 00435 }; // class ParseError 00436 00437 00439 class HOKUYO_AIST_EXPORT MissingFirmSpecError: public ProtocolError 00440 { 00441 public: 00442 MissingFirmSpecError() 00443 : ProtocolError(29, "MissingFirmSpecError") 00444 {} 00445 }; // class MissingFirmSpecError 00446 00447 00449 class HOKUYO_AIST_EXPORT ResponseError: public ProtocolError 00450 { 00451 public: 00456 ResponseError(char const* const error, char const* const cmd) 00457 : ProtocolError(30, "ResponseError") 00458 { 00459 error_[0] = error[0]; error_[1] = error[1]; 00460 cmd_[0] = cmd[0]; cmd_[1] = cmd[1]; 00461 } 00462 ResponseError(ResponseError const& rhs) 00463 : ProtocolError(rhs) 00464 { 00465 error_[0] = rhs.error_code()[0]; 00466 error_[1] = rhs.error_code()[1]; 00467 cmd_[0] = rhs.cmd_code()[0]; 00468 cmd_[1] = rhs.cmd_code()[1]; 00469 } 00470 00472 virtual char const* const error_code() const throw() 00473 { return error_; } 00474 00476 virtual char const* const cmd_code() const throw() 00477 { return cmd_; } 00478 00479 const char* what() throw(); 00480 00481 protected: 00483 char error_[2]; 00485 char cmd_[2]; 00486 }; // class ResponseError 00487 00488 00490 class HOKUYO_AIST_EXPORT Scip1ResponseError: public ProtocolError 00491 { 00492 public: 00497 Scip1ResponseError(char error, char cmd) 00498 : ProtocolError(30, "Scip1ResponseError"), 00499 error_(error), cmd_(cmd) 00500 {} 00501 Scip1ResponseError(Scip1ResponseError const& rhs) 00502 : ProtocolError(rhs), error_(rhs.error_code()), 00503 cmd_(rhs.cmd_code()) 00504 {} 00505 00507 virtual char error_code() const throw() 00508 { return error_; } 00509 00511 virtual char cmd_code() const throw() 00512 { return cmd_; } 00513 00514 const char* what() throw(); 00515 00516 protected: 00518 char error_; 00520 char cmd_; 00521 }; // class Scip1ResponseError 00522 00523 00525 class HOKUYO_AIST_EXPORT CommandEchoError: public ProtocolError 00526 { 00527 public: 00532 CommandEchoError(char const* const cmd, char const* const echo) 00533 : ProtocolError(31, "CommandEchoError") 00534 { 00535 cmd_[0] = cmd[0]; cmd_[1] = cmd[1]; 00536 echo_[0] = echo[0]; echo_[1] = echo[1]; 00537 } 00538 CommandEchoError(CommandEchoError const& rhs) 00539 : ProtocolError(rhs) 00540 { 00541 cmd_[0] = rhs.cmd_code()[0]; 00542 cmd_[1] = rhs.cmd_code()[1]; 00543 echo_[0] = rhs.cmd_echo()[0]; 00544 echo_[1] = rhs.cmd_echo()[1]; 00545 } 00546 00548 virtual char const* const cmd_code() const throw() 00549 { return cmd_; } 00550 00552 virtual char const* const cmd_echo() const throw() 00553 { return echo_; } 00554 00555 const char* what() throw(); 00556 00557 protected: 00559 char cmd_[2]; 00561 char echo_[2]; 00562 }; // class CommandEchoError 00563 00564 00566 class HOKUYO_AIST_EXPORT ParamEchoError: public ProtocolError 00567 { 00568 public: 00572 ParamEchoError(char const* const cmd) 00573 : ProtocolError(32, "ParamEchoError") 00574 { 00575 cmd_[0] = cmd[0]; cmd_[1] = cmd[1]; 00576 } 00577 ParamEchoError(ParamEchoError const& rhs) 00578 : ProtocolError(rhs) 00579 { 00580 cmd_[0] = rhs.cmd_code()[0]; 00581 cmd_[1] = rhs.cmd_code()[1]; 00582 } 00583 00585 virtual char const* const cmd_code() const throw() 00586 { return cmd_; } 00587 00588 const char* what() throw(); 00589 00590 protected: 00592 char cmd_[2]; 00593 }; // class ParamEchoError 00594 00595 00597 class HOKUYO_AIST_EXPORT InsufficientBytesError: public ProtocolError 00598 { 00599 public: 00604 InsufficientBytesError(int num, int line_length) 00605 : ProtocolError(33, "InsufficientBytesError"), 00606 num_(num), line_length_(line_length) 00607 {} 00608 InsufficientBytesError(InsufficientBytesError const& rhs) 00609 : ProtocolError(rhs), num_(rhs.num()), 00610 line_length_(rhs.line_length()) 00611 {} 00612 00613 virtual int num() const throw() 00614 { return num_; } 00615 00616 virtual int line_length() const throw() 00617 { return line_length_; } 00618 00619 const char* what() throw(); 00620 00621 protected: 00623 int num_; 00625 int line_length_; 00626 }; // class InsufficientBytesError 00627 00628 00630 class HOKUYO_AIST_EXPORT LineLengthError: public ProtocolError 00631 { 00632 public: 00637 LineLengthError(int length, int expected) 00638 : ProtocolError(34, "LineLengthError"), 00639 length_(length), expected_(expected) 00640 {} 00641 LineLengthError(LineLengthError const& rhs) 00642 : ProtocolError(rhs), length_(rhs.length()), 00643 expected_(rhs.expected()) 00644 {} 00645 00646 virtual int length() const throw() 00647 { return length_; } 00648 00649 virtual int expected() const throw() 00650 { return expected_; } 00651 00652 const char* what() throw(); 00653 00654 protected: 00656 int length_; 00658 int expected_; 00659 }; // class LineLengthError 00660 00661 }; // namespace hokuyo_aist 00662 00665 #endif // HOKUYO_ERRORS_H__ 00666 |