HokuyoAIST  3.0.1
hokuyo_errors.h
Go to the documentation of this file.
00001 /* HokuyoAIST
00002  *
00003  * Header file for exceptions.
00004  *
00005  * Copyright 2008-2011 Geoffrey Biggs geoffrey.biggs@aist.go.jp
00006  *     RT-Synthesis Research Group
00007  *     Intelligent Systems Research Institute,
00008  *     National Institute of Advanced Industrial Science and Technology (AIST),
00009  *     Japan
00010  *     All rights reserved.
00011  *
00012  * This file is part of HokuyoAIST.
00013  *
00014  * HokuyoAIST is free software; you can redistribute it and/or modify it
00015  * under the terms of the GNU Lesser General Public License as published
00016  * by the Free Software Foundation; either version 2.1 of the License,
00017  * or (at your option) any later version.
00018  *
00019  * HokuyoAIST is distributed in the hope that it will be useful, but
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022  * Lesser General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU Lesser General Public
00025  * License along with HokuyoAIST. If not, see
00026  * <http://www.gnu.org/licenses/>.
00027  */
00028 
00029 #ifndef HOKUYO_ERRORS_H__
00030 #define HOKUYO_ERRORS_H__
00031 
00032 #include <sstream>
00033 
00034 #if defined(WIN32)
00035     typedef unsigned char           uint8_t;
00036     typedef unsigned int            uint32_t;
00037     #if defined(HOKUYOAIST_STATIC)
00038         #define HOKUYOAIST_EXPORT
00039     #elif defined(hokuyoaist_EXPORTS)
00040         #define HOKUYOAIST_EXPORT       __declspec(dllexport)
00041     #else
00042         #define HOKUYOAIST_EXPORT       __declspec(dllimport)
00043     #endif
00044 #else
00045     #include <stdint.h>
00046     #define HOKUYOAIST_EXPORT
00047 #endif
00048 
00053 namespace hokuyoaist
00054 {
00055 
00057 std::string scip2_error_to_string(char const* const error,
00058         char const* const cmd);
00059 
00061 std::string desc_code_to_string(unsigned int code);
00062 
00063 
00065 class HOKUYOAIST_EXPORT BaseError : public std::exception
00066 {
00067     public:
00073         BaseError(unsigned int desc_code, char const* error_type);
00074         BaseError(BaseError const& rhs);
00075         virtual ~BaseError() throw() {};
00076 
00077         virtual unsigned int desc_code() const throw()
00078             { return desc_code_; }
00079 
00080         virtual char const* error_type() const throw()
00081             { return error_type_; }
00082 
00083 #if __cplusplus >= 201103L
00084         virtual const char* what() const throw();
00085 #else
00086         virtual const char* what() throw();
00087 #endif
00088 
00089     protected:
00091         unsigned int desc_code_;
00092 
00094         std::stringstream ss;
00096         char error_type_[32];
00097 }; //class BaseError
00098 
00099 
00101 class HOKUYOAIST_EXPORT LogicError : public BaseError
00102 {
00103     public:
00107         LogicError(unsigned int desc_code)
00108             : BaseError(desc_code, "LogicError")
00109         {}
00110         LogicError(unsigned int desc_code, char const* error_type)
00111             : BaseError(desc_code, error_type)
00112         {}
00113         virtual ~LogicError() throw() {};
00114 }; // class LogicError
00115 
00116 
00118 class HOKUYOAIST_EXPORT RuntimeError : public BaseError
00119 {
00120     public:
00124         RuntimeError(unsigned int desc_code)
00125             : BaseError(desc_code, "RuntimeError")
00126         {}
00127         RuntimeError(unsigned int desc_code, char const* error_type)
00128             : BaseError(desc_code, error_type)
00129         {}
00130         virtual ~RuntimeError() throw() {};
00131 }; // class RuntimeError
00132 
00133 
00135 class HOKUYOAIST_EXPORT ReadError: public RuntimeError
00136 {
00137     public:
00141         ReadError(unsigned int desc_code)
00142             : RuntimeError(desc_code, "ReadError")
00143         {}
00144 }; // class ReadError
00145 
00146 
00148 class HOKUYOAIST_EXPORT WriteError: public RuntimeError
00149 {
00150     public:
00154         WriteError(unsigned int desc_code)
00155             : RuntimeError(desc_code, "WriteError")
00156         {}
00157 }; // class WriteError
00158 
00159 
00161 class HOKUYOAIST_EXPORT BaudrateError: public RuntimeError
00162 {
00163     public:
00167         BaudrateError(unsigned int baud)
00168             : RuntimeError(6, "BaudrateError"), baud_(baud)
00169         {}
00170         BaudrateError(BaudrateError const& rhs)
00171             : RuntimeError(rhs), baud_(rhs.baud())
00172         {}
00173 
00174         unsigned int baud() const throw()
00175             { return baud_; }
00176 
00177 #if __cplusplus >= 201103L
00178         virtual const char* what() const throw();
00179 #else
00180         virtual const char* what() throw();
00181 #endif
00182 
00183     protected:
00185         unsigned int baud_;
00186 }; // class BaudrateError
00187 
00188 
00190 class HOKUYOAIST_EXPORT CloseError: public RuntimeError
00191 {
00192     public:
00193         CloseError()
00194             : RuntimeError(3, "CloseError")
00195         {}
00196 }; // class CloseError
00197 
00198 
00200 class HOKUYOAIST_EXPORT NoDestinationError: public RuntimeError
00201 {
00202     public:
00203         NoDestinationError()
00204             : RuntimeError(11, "NoDestinationError")
00205         {}
00206 }; // class NoDestinationError
00207 
00208 
00210 class HOKUYOAIST_EXPORT FirmwareError: public RuntimeError
00211 {
00212     public:
00213         FirmwareError()
00214             : RuntimeError(23, "FirmwareError")
00215         {}
00216 }; // class FirmwareError
00217 
00218 
00220 class HOKUYOAIST_EXPORT ScipVersionError: public RuntimeError
00221 {
00222     public:
00223         ScipVersionError()
00224             : RuntimeError(22, "ScipVersionError")
00225         {}
00226 }; // class ScipVersionError
00227 
00228 
00230 class HOKUYOAIST_EXPORT UnknownScipVersionError: public RuntimeError
00231 {
00232     public:
00233         UnknownScipVersionError()
00234             : RuntimeError(4, "UnknownScipVersionError")
00235         {}
00236 }; // class UnknownScipVersionError
00237 
00238 
00240 class HOKUYOAIST_EXPORT UnsupportedError: public RuntimeError
00241 {
00242     public:
00246         UnsupportedError(unsigned int desc_code)
00247             : RuntimeError(desc_code, "UnsupportedError")
00248         {}
00249 }; // class UnsupportedError
00250 
00251 
00253 class HOKUYOAIST_EXPORT ArgError: public RuntimeError
00254 {
00255     public:
00259         ArgError(unsigned int desc_code)
00260             : RuntimeError(desc_code, "ArgError")
00261         {}
00262         ArgError(unsigned int desc_code, char const* error_type)
00263             : RuntimeError(desc_code, error_type)
00264         {}
00265         virtual ~ArgError() throw() {};
00266 }; // class ArgError
00267 
00268 
00270 class HOKUYOAIST_EXPORT NoDataError: public RuntimeError
00271 {
00272     public:
00273         NoDataError()
00274             : RuntimeError(13, "NoDataError")
00275         {}
00276 }; // class NoDataError
00277 
00278 
00280 class HOKUYOAIST_EXPORT NotSerialError: public RuntimeError
00281 {
00282     public:
00283         NotSerialError()
00284             : RuntimeError(5, "NotSerialError")
00285         {}
00286 }; // class NotSerialError
00287 
00288 
00290 class HOKUYOAIST_EXPORT IndexError: public RuntimeError
00291 {
00292     public:
00293         IndexError()
00294             : RuntimeError(2, "IndexError")
00295         {}
00296 }; // class IndexError
00297 
00298 
00300 class HOKUYOAIST_EXPORT SetIPError: public RuntimeError
00301 {
00302     public:
00303         SetIPError()
00304             : RuntimeError(37, "SetIPError")
00305         {}
00306 }; // class SetIPError
00307 
00308 
00310 class HOKUYOAIST_EXPORT MotorSpeedError: public ArgError
00311 {
00312     public:
00313         MotorSpeedError()
00314             : ArgError(9, "MotorSpeedError")
00315         {}
00316 }; // class MotorSpeedError
00317 
00318 
00320 class HOKUYOAIST_EXPORT StartStepError: public ArgError
00321 {
00322     public:
00323         StartStepError()
00324             : ArgError(14, "StartStepError")
00325         {}
00326 }; // class StartStepError
00327 
00328 
00330 class HOKUYOAIST_EXPORT EndStepError: public ArgError
00331 {
00332     public:
00333         EndStepError()
00334             : ArgError(15, "EndStepError")
00335         {}
00336 }; // class EndStepError
00337 
00338 
00340 class HOKUYOAIST_EXPORT ProtocolError: public RuntimeError
00341 {
00342     public:
00346         ProtocolError(unsigned int desc_code)
00347             : RuntimeError(desc_code, "ProtocolError")
00348         {}
00349         ProtocolError(unsigned int desc_code, char const* error_type)
00350             : RuntimeError(desc_code, error_type)
00351         {}
00352         virtual ~ProtocolError() throw() {}
00353 }; // class ProtocolError
00354 
00355 
00357 class HOKUYOAIST_EXPORT ChecksumError: public ProtocolError
00358 {
00359     public:
00364         ChecksumError(int expected, int calculated)
00365             : ProtocolError(24, "ChecksumError"), expected_(expected),
00366             calculated_(calculated)
00367         {}
00368         ChecksumError(ChecksumError const& rhs)
00369             : ProtocolError(rhs), expected_(rhs.expected()),
00370             calculated_(rhs.calculated())
00371         {}
00372 
00373         virtual int expected() const throw()
00374             { return expected_; }
00375 
00376         virtual int calculated() const throw()
00377             { return calculated_; }
00378 
00379 #if __cplusplus >= 201103L
00380         virtual const char* what() const throw();
00381 #else
00382         virtual const char* what() throw();
00383 #endif
00384 
00385     protected:
00387         int expected_;
00389         int calculated_;
00390 }; // class ProtocolError
00391 
00392 
00394 class HOKUYOAIST_EXPORT DataCountError: public ProtocolError
00395 {
00396     public:
00397         DataCountError()
00398             : ProtocolError(25, "DataCountError")
00399         {}
00400 }; // class DataCountError
00401 
00402 
00404 class HOKUYOAIST_EXPORT MisplacedLineFeedError: public ProtocolError
00405 {
00406     public:
00407         MisplacedLineFeedError()
00408             : ProtocolError(26, "MisplacedLineFeedError")
00409         {}
00410 }; // class MisplacedLineFeedError
00411 
00412 
00414 class HOKUYOAIST_EXPORT UnknownLineError: public ProtocolError
00415 {
00416     public:
00420         UnknownLineError(char const* const line);
00421         UnknownLineError(UnknownLineError const& rhs);
00422 
00423         virtual char const* const line() const throw()
00424             { return line_; }
00425 
00426 #if __cplusplus >= 201103L
00427         virtual const char* what() const throw();
00428 #else
00429         virtual const char* what() throw();
00430 #endif
00431 
00432     protected:
00434         char line_[128];
00435 }; // class UnknownLineError
00436 
00437 
00439 class HOKUYOAIST_EXPORT ParseError: public ProtocolError
00440 {
00441     public:
00446         ParseError(char const* const line, char const* const type);
00447         ParseError(ParseError const& rhs);
00448 
00449         virtual char const* const line() const throw()
00450             { return line_; }
00451 
00452         virtual char const* const type() const throw()
00453             { return type_; }
00454 
00455 #if __cplusplus >= 201103L
00456         virtual const char* what() const throw();
00457 #else
00458         virtual const char* what() throw();
00459 #endif
00460 
00461     protected:
00463         char line_[128];
00465         char type_[16];
00466 }; // class ParseError
00467 
00468 
00470 class HOKUYOAIST_EXPORT MissingFirmSpecError: public ProtocolError
00471 {
00472     public:
00473         MissingFirmSpecError()
00474             : ProtocolError(29, "MissingFirmSpecError")
00475         {}
00476 }; // class MissingFirmSpecError
00477 
00478 
00480 class HOKUYOAIST_EXPORT ResponseError: public ProtocolError
00481 {
00482     public:
00487         ResponseError(char const* const error, char const* const cmd)
00488             : ProtocolError(30, "ResponseError")
00489         {
00490             error_[0] = error[0]; error_[1] = error[1];
00491             cmd_[0] = cmd[0]; cmd_[1] = cmd[1];
00492         }
00493         ResponseError(ResponseError const& rhs)
00494             : ProtocolError(rhs)
00495         {
00496             error_[0] = rhs.error_code()[0];
00497             error_[1] = rhs.error_code()[1];
00498             cmd_[0] = rhs.cmd_code()[0];
00499             cmd_[1] = rhs.cmd_code()[1];
00500         }
00501 
00503         virtual char const* const error_code() const throw()
00504             { return error_; }
00505 
00507         virtual char const* const cmd_code() const throw()
00508             { return cmd_; }
00509 
00510 #if __cplusplus >= 201103L
00511         virtual const char* what() const throw();
00512 #else
00513         virtual const char* what() throw();
00514 #endif
00515 
00516     protected:
00518         char error_[2];
00520         char cmd_[2];
00521 }; // class ResponseError
00522 
00523 
00525 class HOKUYOAIST_EXPORT Scip1ResponseError: public ProtocolError
00526 {
00527     public:
00532         Scip1ResponseError(char error, char cmd)
00533             : ProtocolError(30, "Scip1ResponseError"),
00534             error_(error), cmd_(cmd)
00535         {}
00536         Scip1ResponseError(Scip1ResponseError const& rhs)
00537             : ProtocolError(rhs), error_(rhs.error_code()),
00538             cmd_(rhs.cmd_code())
00539         {}
00540 
00542         virtual char error_code() const throw()
00543             { return error_; }
00544 
00546         virtual char cmd_code() const throw()
00547             { return cmd_; }
00548 
00549 #if __cplusplus >= 201103L
00550         virtual const char* what() const throw();
00551 #else
00552         virtual const char* what() throw();
00553 #endif
00554 
00555     protected:
00557         char error_;
00559         char cmd_;
00560 }; // class Scip1ResponseError
00561 
00562 
00564 class HOKUYOAIST_EXPORT CommandEchoError: public ProtocolError
00565 {
00566     public:
00571         CommandEchoError(char const* const cmd, char const* const echo)
00572             : ProtocolError(31, "CommandEchoError")
00573         {
00574             cmd_[0] = cmd[0]; cmd_[1] = cmd[1];
00575             echo_[0] = echo[0]; echo_[1] = echo[1];
00576         }
00577         CommandEchoError(CommandEchoError const& rhs)
00578             : ProtocolError(rhs)
00579         {
00580             cmd_[0] = rhs.cmd_code()[0];
00581             cmd_[1] = rhs.cmd_code()[1];
00582             echo_[0] = rhs.cmd_echo()[0];
00583             echo_[1] = rhs.cmd_echo()[1];
00584         }
00585 
00587         virtual char const* const cmd_code() const throw()
00588             { return cmd_; }
00589 
00591         virtual char const* const cmd_echo() const throw()
00592             { return echo_; }
00593 
00594 #if __cplusplus >= 201103L
00595         virtual const char* what() const throw();
00596 #else
00597         virtual const char* what() throw();
00598 #endif
00599 
00600     protected:
00602         char cmd_[2];
00604         char echo_[2];
00605 }; // class CommandEchoError
00606 
00607 
00609 class HOKUYOAIST_EXPORT ParamEchoError: public ProtocolError
00610 {
00611     public:
00615         ParamEchoError(char const* const cmd)
00616             : ProtocolError(32, "ParamEchoError")
00617         {
00618             cmd_[0] = cmd[0]; cmd_[1] = cmd[1];
00619         }
00620         ParamEchoError(ParamEchoError const& rhs)
00621             : ProtocolError(rhs)
00622         {
00623             cmd_[0] = rhs.cmd_code()[0];
00624             cmd_[1] = rhs.cmd_code()[1];
00625         }
00626 
00628         virtual char const* const cmd_code() const throw()
00629             { return cmd_; }
00630 
00631 #if __cplusplus >= 201103L
00632         virtual const char* what() const throw();
00633 #else
00634         virtual const char* what() throw();
00635 #endif
00636 
00637     protected:
00639         char cmd_[2];
00640 }; // class ParamEchoError
00641 
00642 
00644 class HOKUYOAIST_EXPORT InsufficientBytesError: public ProtocolError
00645 {
00646     public:
00651         InsufficientBytesError(int num, int line_length)
00652             : ProtocolError(33, "InsufficientBytesError"),
00653             num_(num), line_length_(line_length)
00654         {}
00655         InsufficientBytesError(InsufficientBytesError const& rhs)
00656             : ProtocolError(rhs), num_(rhs.num()),
00657             line_length_(rhs.line_length())
00658         {}
00659 
00660         virtual int num() const throw()
00661             { return num_; }
00662 
00663         virtual int line_length() const throw()
00664             { return line_length_; }
00665 
00666 #if __cplusplus >= 201103L
00667         virtual const char* what() const throw();
00668 #else
00669         virtual const char* what() throw();
00670 #endif
00671 
00672     protected:
00674         int num_;
00676         int line_length_;
00677 }; // class InsufficientBytesError
00678 
00679 
00681 class HOKUYOAIST_EXPORT LineLengthError: public ProtocolError
00682 {
00683     public:
00688         LineLengthError(int length, int expected)
00689             : ProtocolError(34, "LineLengthError"),
00690             length_(length), expected_(expected)
00691         {}
00692         LineLengthError(LineLengthError const& rhs)
00693             : ProtocolError(rhs), length_(rhs.length()),
00694             expected_(rhs.expected())
00695         {}
00696 
00697         virtual int length() const throw()
00698             { return length_; }
00699 
00700         virtual int expected() const throw()
00701             { return expected_; }
00702 
00703 #if __cplusplus >= 201103L
00704         virtual const char* what() const throw();
00705 #else
00706         virtual const char* what() throw();
00707 #endif
00708 
00709     protected:
00711         int length_;
00713         int expected_;
00714 }; // class LineLengthError
00715 
00716 }; // namespace hokuyoaist
00717 
00720 #endif // HOKUYO_ERRORS_H__
00721