BPLightContraption
 All Classes Namespaces Files Functions Variables Macros Pages
microcontexception.h
Go to the documentation of this file.
1 /*! \file
2  * \brief Exception thrown by the MCInterface class
3  * \author Benjamin Pritchard (ben@bennyp.org)
4  * \copyright 2013 Benjamin Pritchard. Released under the MIT License
5  */
6 
7 #ifndef MICROCONTEXCEPTION_H
8 #define MICROCONTEXCEPTION_H
9 
10 #include <QtSerialPort/QSerialPort>
11 #include <QtSerialPort/QSerialPortInfo>
12 
13 #include <exception>
14 #include <stdexcept>
15 
16 using namespace std;
17 
18 
19 //! An exception thrown from the MCInterfaceException class
20 class MCInterfaceException : public runtime_error
21 {
22 private:
23  int _mcerror; //!< An error code
24  int _mcerrorcmd; //!< Command that the microcontroller had a problem with (returned by the MC)
25  int _mcerrorid; //!< Powerunit ID that had a problem (returned by the MC)
26  QSerialPort::SerialPortError _sperror; //!< The current status of the serial port
27 
28  public:
29  //! Basic constructor
30  MCInterfaceException(const QString & desc,
31  int mcerror,
32  int mcerrorcmd,
33  int mcerrorid,
34  QSerialPort::SerialPortError sperror);
35 
36  //! Constructor with just the microcontroller error component
37  MCInterfaceException(const QString & desc,
38  int mcerror,
39  QSerialPort::SerialPortError sperror);
40 
41  //! Returns the current error code
42  int GetMCError(void) const;
43 
44  //! Returns the IDd the microcontroller had a problem with
45  /*!
46  * This code is returned by the microcontroller itself, indicating a
47  * problem with this power unit ID
48  */
49  int GetMCErrorID(void) const;
50 
51  //! Returns the command the microcontroller had a problem with
52  /*!
53  * This code is returned by the microcontroller itself, indicating a
54  * problem with this command
55  */
56  int GetMCErrorCMD(void) const;
57 
58  //! Returns the current serial port error. See the QSerialPort documentation
59  QSerialPort::SerialPortError GetSPError(void) const;
60 
61  //! Returns a string describing the current serial port error
62  const char * GetSPErrorText(void) const;
63 };
64 
65 #endif // POWERUNITEXCEPTION_H
66