BPLightContraption
 All Classes Namespaces Files Functions Variables Macros Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
MCInterface Class Reference

This class represents a microcontroller. More...

#include <microcont.h>

Inheritance diagram for MCInterface:
Inheritance graph
[legend]
Collaboration diagram for MCInterface:
Collaboration graph
[legend]

Public Member Functions

 MCInterface ()
 Initializes the interface. More...
 
void OpenPort (const QString &port)
 Opens the specified port. More...
 
void ClosePort (void)
 Closes the serial connection with the microcontroller. More...
 
void ResetPort (void)
 Resets the port (closes and then reopens the port) More...
 
bool IsOpen (void)
 Returns true if the port is opened. More...
 
QByteArray SendCommand (const quint8 *command, int len, unsigned int expectedreslen, int timeout=500)
 Sends a command to the microcontroller. More...
 
int GetMCError (void) const
 Returns the current error state of the microcontroller. More...
 
int GetMCErrorID (void) const
 Returns the id returned from the microcontroller during an error. More...
 
int GetMCErrorCMD (void) const
 Returns the command returned from the microcontroller during an error. More...
 
QSerialPort::SerialPortError GetSPError (void) const
 Returns the error code from the serial port. More...
 
QByteArray RetrieveInfo (void)
 Gets state info from the microcontroller. More...
 

Private Member Functions

 Q_DISABLE_COPY (MCInterface)
 Disables copying of this class. More...
 
void ThrowException (const QString &desc) const
 Throws an exception using the current error numbers. More...
 

Private Attributes

QSerialPort _sp
 Serial port object. More...
 
int _mcerror
 Microcontroller error flag. More...
 
int _mcerrorcmd
 Command returned by the microcontroller during an error. More...
 
int _mcerrorid
 ID of the power unit, etc, causing the error. More...
 

Detailed Description

This class represents a microcontroller.

This command is mostly used to connect and send commands.

Definition at line 20 of file microcont.h.

Constructor & Destructor Documentation

MCInterface::MCInterface ( )

Initializes the interface.

Definition at line 14 of file microcont.cpp.

Member Function Documentation

void MCInterface::ClosePort ( void  )

Closes the serial connection with the microcontroller.

Definition at line 72 of file microcont.cpp.

Here is the caller graph for this function:

int MCInterface::GetMCError ( void  ) const

Returns the current error state of the microcontroller.

See ConvertMCError()

Definition at line 24 of file microcont.cpp.

int MCInterface::GetMCErrorCMD ( void  ) const

Returns the command returned from the microcontroller during an error.

The ID should represent which command had a problem

Definition at line 34 of file microcont.cpp.

int MCInterface::GetMCErrorID ( void  ) const

Returns the id returned from the microcontroller during an error.

The ID should represent which PowerUnit had a problem

Definition at line 29 of file microcont.cpp.

QSerialPort::SerialPortError MCInterface::GetSPError ( void  ) const

Returns the error code from the serial port.

See documentation for QSterialPort

Definition at line 19 of file microcont.cpp.

Here is the caller graph for this function:

bool MCInterface::IsOpen ( void  )

Returns true if the port is opened.

Definition at line 134 of file microcont.cpp.

void MCInterface::OpenPort ( const QString &  port)

Opens the specified port.

After opening the port, it waits for the identification string. If something goes wrong, it throws a MCInterfaceException (through ThrowException())

Definition at line 39 of file microcont.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

MCInterface::Q_DISABLE_COPY ( MCInterface  )
private

Disables copying of this class.

void MCInterface::ResetPort ( void  )

Resets the port (closes and then reopens the port)

Definition at line 78 of file microcont.cpp.

Here is the call graph for this function:

QByteArray MCInterface::RetrieveInfo ( void  )

Gets state info from the microcontroller.

Information, including dimmer levels, timestamps, etc, are stored in a specific way in a QByteArray

Exceptions
MCInterfaceExceptionAn error occurred during sending the command or receiving the response

Definition at line 127 of file microcont.cpp.

Here is the call graph for this function:

QByteArray MCInterface::SendCommand ( const quint8 *  command,
int  len,
unsigned int  expectedreslen,
int  timeout = 500 
)

Sends a command to the microcontroller.

Commands are stored in an array of bytes. The reason for this is that it is a bit cleaner to write the commands, ie

uint8_t infocmd[2] = {'\\',COM_INFO};
Parameters
commandArray of bytes to send
lenThe length of the command to send
expectedreslenThe length of the result expected (not including the 3 header bytes)
timeoutThe amount of time to wait for a response from the microcontroller (in ms)
Exceptions
MCInterfaceExceptionAn error occurred during sending the command or receiving the response

Definition at line 86 of file microcont.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void MCInterface::ThrowException ( const QString &  desc) const
private

Throws an exception using the current error numbers.

This also taks a description

Definition at line 122 of file microcont.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

int MCInterface::_mcerror
private

Microcontroller error flag.

Definition at line 108 of file microcont.h.

int MCInterface::_mcerrorcmd
private

Command returned by the microcontroller during an error.

Definition at line 111 of file microcont.h.

int MCInterface::_mcerrorid
private

ID of the power unit, etc, causing the error.

Definition at line 114 of file microcont.h.

QSerialPort MCInterface::_sp
private

Serial port object.

Definition at line 105 of file microcont.h.


The documentation for this class was generated from the following files: