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         virtual const char* what() throw();
00084 
00085     protected:
00087         unsigned int desc_code_;
00088 
00090         std::stringstream ss;
00092         char error_type_[32];
00093 }; //class BaseError
00094 
00095 
00097 class HOKUYOAIST_EXPORT LogicError : public BaseError
00098 {
00099     public:
00103         LogicError(unsigned int desc_code)
00104             : BaseError(desc_code, "LogicError")
00105         {}
00106         LogicError(unsigned int desc_code, char const* error_type)
00107             : BaseError(desc_code, error_type)
00108         {}
00109         virtual ~LogicError() throw() {};
00110 }; // class LogicError
00111 
00112 
00114 class HOKUYOAIST_EXPORT RuntimeError : public BaseError
00115 {
00116     public:
00120         RuntimeError(unsigned int desc_code)
00121             : BaseError(desc_code, "RuntimeError")
00122         {}
00123         RuntimeError(unsigned int desc_code, char const* error_type)
00124             : BaseError(desc_code, error_type)
00125         {}
00126         virtual ~RuntimeError() throw() {};
00127 }; // class RuntimeError
00128 
00129 
00131 class HOKUYOAIST_EXPORT ReadError: public RuntimeError
00132 {
00133     public:
00137         ReadError(unsigned int desc_code)
00138             : RuntimeError(desc_code, "ReadError")
00139         {}
00140 }; // class ReadError
00141 
00142 
00144 class HOKUYOAIST_EXPORT WriteError: public RuntimeError
00145 {
00146     public:
00150         WriteError(unsigned int desc_code)
00151             : RuntimeError(desc_code, "WriteError")
00152         {}
00153 }; // class WriteError
00154 
00155 
00157 class HOKUYOAIST_EXPORT BaudrateError: public RuntimeError
00158 {
00159     public:
00163         BaudrateError(unsigned int baud)
00164             : RuntimeError(6, "BaudrateError"), baud_(baud)
00165         {}
00166         BaudrateError(BaudrateError const& rhs)
00167             : RuntimeError(rhs), baud_(rhs.baud())
00168         {}
00169 
00170         unsigned int baud() const throw()
00171             { return baud_; }
00172 
00173         const char* what() throw();
00174 
00175     protected:
00177         unsigned int baud_;
00178 }; // class BaudrateError
00179 
00180 
00182 class HOKUYOAIST_EXPORT CloseError: public RuntimeError
00183 {
00184     public:
00185         CloseError()
00186             : RuntimeError(3, "CloseError")
00187         {}
00188 }; // class CloseError
00189 
00190 
00192 class HOKUYOAIST_EXPORT NoDestinationError: public RuntimeError
00193 {
00194     public:
00195         NoDestinationError()
00196             : RuntimeError(11, "NoDestinationError")
00197         {}
00198 }; // class NoDestinationError
00199 
00200 
00202 class HOKUYOAIST_EXPORT FirmwareError: public RuntimeError
00203 {
00204     public:
00205         FirmwareError()
00206             : RuntimeError(23, "FirmwareError")
00207         {}
00208 }; // class FirmwareError
00209 
00210 
00212 class HOKUYOAIST_EXPORT ScipVersionError: public RuntimeError
00213 {
00214     public:
00215         ScipVersionError()
00216             : RuntimeError(22, "ScipVersionError")
00217         {}
00218 }; // class ScipVersionError
00219 
00220 
00222 class HOKUYOAIST_EXPORT UnknownScipVersionError: public RuntimeError
00223 {
00224     public:
00225         UnknownScipVersionError()
00226             : RuntimeError(4, "UnknownScipVersionError")
00227         {}
00228 }; // class UnknownScipVersionError
00229 
00230 
00232 class HOKUYOAIST_EXPORT UnsupportedError: public RuntimeError
00233 {
00234     public:
00238         UnsupportedError(unsigned int desc_code)
00239             : RuntimeError(desc_code, "UnsupportedError")
00240         {}
00241 }; // class UnsupportedError
00242 
00243 
00245 class HOKUYOAIST_EXPORT ArgError: public RuntimeError
00246 {
00247     public:
00251         ArgError(unsigned int desc_code)
00252             : RuntimeError(desc_code, "ArgError")
00253         {}
00254         ArgError(unsigned int desc_code, char const* error_type)
00255             : RuntimeError(desc_code, error_type)
00256         {}
00257         virtual ~ArgError() throw() {};
00258 }; // class ArgError
00259 
00260 
00262 class HOKUYOAIST_EXPORT NoDataError: public RuntimeError
00263 {
00264     public:
00265         NoDataError()
00266             : RuntimeError(13, "NoDataError")
00267         {}
00268 }; // class NoDataError
00269 
00270 
00272 class HOKUYOAIST_EXPORT NotSerialError: public RuntimeError
00273 {
00274     public:
00275         NotSerialError()
00276             : RuntimeError(5, "NotSerialError")
00277         {}
00278 }; // class NotSerialError
00279 
00280 
00282 class HOKUYOAIST_EXPORT IndexError: public RuntimeError
00283 {
00284     public:
00285         IndexError()
00286             : RuntimeError(2, "IndexError")
00287         {}
00288 }; // class IndexError
00289 
00290 
00292 class HOKUYOAIST_EXPORT SetIPError: public RuntimeError
00293 {
00294     public:
00295         SetIPError()
00296             : RuntimeError(37, "SetIPError")
00297         {}
00298 }; // class SetIPError
00299 
00300 
00302 class HOKUYOAIST_EXPORT MotorSpeedError: public ArgError
00303 {
00304     public:
00305         MotorSpeedError()
00306             : ArgError(9, "MotorSpeedError")
00307         {}
00308 }; // class MotorSpeedError
00309 
00310 
00312 class HOKUYOAIST_EXPORT StartStepError: public ArgError
00313 {
00314     public:
00315         StartStepError()
00316             : ArgError(14, "StartStepError")
00317         {}
00318 }; // class StartStepError
00319 
00320 
00322 class HOKUYOAIST_EXPORT EndStepError: public ArgError
00323 {
00324     public:
00325         EndStepError()
00326             : ArgError(15, "EndStepError")
00327         {}
00328 }; // class EndStepError
00329 
00330 
00332 class HOKUYOAIST_EXPORT ProtocolError: public RuntimeError
00333 {
00334     public:
00338         ProtocolError(unsigned int desc_code)
00339             : RuntimeError(desc_code, "ProtocolError")
00340         {}
00341         ProtocolError(unsigned int desc_code, char const* error_type)
00342             : RuntimeError(desc_code, error_type)
00343         {}
00344         virtual ~ProtocolError() throw() {}
00345 }; // class ProtocolError
00346 
00347 
00349 class HOKUYOAIST_EXPORT ChecksumError: public ProtocolError
00350 {
00351     public:
00356         ChecksumError(int expected, int calculated)
00357             : ProtocolError(24, "ChecksumError"), expected_(expected),
00358             calculated_(calculated)
00359         {}
00360         ChecksumError(ChecksumError const& rhs)
00361             : ProtocolError(rhs), expected_(rhs.expected()),
00362             calculated_(rhs.calculated())
00363         {}
00364 
00365         virtual int expected() const throw()
00366             { return expected_; }
00367 
00368         virtual int calculated() const throw()
00369             { return calculated_; }
00370 
00371         const char* what() throw();
00372 
00373     protected:
00375         int expected_;
00377         int calculated_;
00378 }; // class ProtocolError
00379 
00380 
00382 class HOKUYOAIST_EXPORT DataCountError: public ProtocolError
00383 {
00384     public:
00385         DataCountError()
00386             : ProtocolError(25, "DataCountError")
00387         {}
00388 }; // class DataCountError
00389 
00390 
00392 class HOKUYOAIST_EXPORT MisplacedLineFeedError: public ProtocolError
00393 {
00394     public:
00395         MisplacedLineFeedError()
00396             : ProtocolError(26, "MisplacedLineFeedError")
00397         {}
00398 }; // class MisplacedLineFeedError
00399 
00400 
00402 class HOKUYOAIST_EXPORT UnknownLineError: public ProtocolError
00403 {
00404     public:
00408         UnknownLineError(char const* const line);
00409         UnknownLineError(UnknownLineError const& rhs);
00410 
00411         virtual char const* const line() const throw()
00412             { return line_; }
00413 
00414         const char* what() throw();
00415 
00416     protected:
00418         char line_[128];
00419 }; // class UnknownLineError
00420 
00421 
00423 class HOKUYOAIST_EXPORT ParseError: public ProtocolError
00424 {
00425     public:
00430         ParseError(char const* const line, char const* const type);
00431         ParseError(ParseError const& rhs);
00432 
00433         virtual char const* const line() const throw()
00434             { return line_; }
00435 
00436         virtual char const* const type() const throw()
00437             { return type_; }
00438 
00439         const char* what() throw();
00440 
00441     protected:
00443         char line_[128];
00445         char type_[16];
00446 }; // class ParseError
00447 
00448 
00450 class HOKUYOAIST_EXPORT MissingFirmSpecError: public ProtocolError
00451 {
00452     public:
00453         MissingFirmSpecError()
00454             : ProtocolError(29, "MissingFirmSpecError")
00455         {}
00456 }; // class MissingFirmSpecError
00457 
00458 
00460 class HOKUYOAIST_EXPORT ResponseError: public ProtocolError
00461 {
00462     public:
00467         ResponseError(char const* const error, char const* const cmd)
00468             : ProtocolError(30, "ResponseError")
00469         {
00470             error_[0] = error[0]; error_[1] = error[1];
00471             cmd_[0] = cmd[0]; cmd_[1] = cmd[1];
00472         }
00473         ResponseError(ResponseError const& rhs)
00474             : ProtocolError(rhs)
00475         {
00476             error_[0] = rhs.error_code()[0];
00477             error_[1] = rhs.error_code()[1];
00478             cmd_[0] = rhs.cmd_code()[0];
00479             cmd_[1] = rhs.cmd_code()[1];
00480         }
00481 
00483         virtual char const* const error_code() const throw()
00484             { return error_; }
00485 
00487         virtual char const* const cmd_code() const throw()
00488             { return cmd_; }
00489 
00490         const char* what() throw();
00491 
00492     protected:
00494         char error_[2];
00496         char cmd_[2];
00497 }; // class ResponseError
00498 
00499 
00501 class HOKUYOAIST_EXPORT Scip1ResponseError: public ProtocolError
00502 {
00503     public:
00508         Scip1ResponseError(char error, char cmd)
00509             : ProtocolError(30, "Scip1ResponseError"),
00510             error_(error), cmd_(cmd)
00511         {}
00512         Scip1ResponseError(Scip1ResponseError const& rhs)
00513             : ProtocolError(rhs), error_(rhs.error_code()),
00514             cmd_(rhs.cmd_code())
00515         {}
00516 
00518         virtual char error_code() const throw()
00519             { return error_; }
00520 
00522         virtual char cmd_code() const throw()
00523             { return cmd_; }
00524 
00525         const char* what() throw();
00526 
00527     protected:
00529         char error_;
00531         char cmd_;
00532 }; // class Scip1ResponseError
00533 
00534 
00536 class HOKUYOAIST_EXPORT CommandEchoError: public ProtocolError
00537 {
00538     public:
00543         CommandEchoError(char const* const cmd, char const* const echo)
00544             : ProtocolError(31, "CommandEchoError")
00545         {
00546             cmd_[0] = cmd[0]; cmd_[1] = cmd[1];
00547             echo_[0] = echo[0]; echo_[1] = echo[1];
00548         }
00549         CommandEchoError(CommandEchoError const& rhs)
00550             : ProtocolError(rhs)
00551         {
00552             cmd_[0] = rhs.cmd_code()[0];
00553             cmd_[1] = rhs.cmd_code()[1];
00554             echo_[0] = rhs.cmd_echo()[0];
00555             echo_[1] = rhs.cmd_echo()[1];
00556         }
00557 
00559         virtual char const* const cmd_code() const throw()
00560             { return cmd_; }
00561 
00563         virtual char const* const cmd_echo() const throw()
00564             { return echo_; }
00565 
00566         const char* what() throw();
00567 
00568     protected:
00570         char cmd_[2];
00572         char echo_[2];
00573 }; // class CommandEchoError
00574 
00575 
00577 class HOKUYOAIST_EXPORT ParamEchoError: public ProtocolError
00578 {
00579     public:
00583         ParamEchoError(char const* const cmd)
00584             : ProtocolError(32, "ParamEchoError")
00585         {
00586             cmd_[0] = cmd[0]; cmd_[1] = cmd[1];
00587         }
00588         ParamEchoError(ParamEchoError const& rhs)
00589             : ProtocolError(rhs)
00590         {
00591             cmd_[0] = rhs.cmd_code()[0];
00592             cmd_[1] = rhs.cmd_code()[1];
00593         }
00594 
00596         virtual char const* const cmd_code() const throw()
00597             { return cmd_; }
00598 
00599         const char* what() throw();
00600 
00601     protected:
00603         char cmd_[2];
00604 }; // class ParamEchoError
00605 
00606 
00608 class HOKUYOAIST_EXPORT InsufficientBytesError: public ProtocolError
00609 {
00610     public:
00615         InsufficientBytesError(int num, int line_length)
00616             : ProtocolError(33, "InsufficientBytesError"),
00617             num_(num), line_length_(line_length)
00618         {}
00619         InsufficientBytesError(InsufficientBytesError const& rhs)
00620             : ProtocolError(rhs), num_(rhs.num()),
00621             line_length_(rhs.line_length())
00622         {}
00623 
00624         virtual int num() const throw()
00625             { return num_; }
00626 
00627         virtual int line_length() const throw()
00628             { return line_length_; }
00629 
00630         const char* what() throw();
00631 
00632     protected:
00634         int num_;
00636         int line_length_;
00637 }; // class InsufficientBytesError
00638 
00639 
00641 class HOKUYOAIST_EXPORT LineLengthError: public ProtocolError
00642 {
00643     public:
00648         LineLengthError(int length, int expected)
00649             : ProtocolError(34, "LineLengthError"),
00650             length_(length), expected_(expected)
00651         {}
00652         LineLengthError(LineLengthError const& rhs)
00653             : ProtocolError(rhs), length_(rhs.length()),
00654             expected_(rhs.expected())
00655         {}
00656 
00657         virtual int length() const throw()
00658             { return length_; }
00659 
00660         virtual int expected() const throw()
00661             { return expected_; }
00662 
00663         const char* what() throw();
00664 
00665     protected:
00667         int length_;
00669         int expected_;
00670 }; // class LineLengthError
00671 
00672 }; // namespace hokuyoaist
00673 
00676 #endif // HOKUYO_ERRORS_H__
00677 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 16 Oct 2012 for HokuyoAIST by  doxygen 1.6.1