Commit d1d6f8f9 authored by pixhawk's avatar pixhawk

Cleaned up serial port libs, activated mav visualization on map (still...

Cleaned up serial port libs, activated mav visualization on map (still debugging), fixed standalone MAVLink generator
parent 0846707b
......@@ -37,12 +37,12 @@ HEADERS += src/standalone/mavlinkgen/MAVLinkGen.h \
src/comm/MAVLinkXMLParser.h \
src/ui/mavlink/DomItem.h \
src/ui/mavlink/DomModel.h \
src/comm/MAVLinkSyntaxHighlighter.h
src/ui/mavlink/QGCMAVLinkTextEdit.h
SOURCES += src/standalone/mavlinkgen/main.cc \
src/standalone/mavlinkgen/MAVLinkGen.cc \
src/ui/XMLCommProtocolWidget.cc \
src/ui/mavlink/DomItem.cc \
src/ui/mavlink/DomModel.cc \
src/comm/MAVLinkXMLParser.cc \
src/comm/MAVLinkSyntaxHighlighter.cc
src/ui/mavlink/QGCMAVLinkTextEdit.cc
RESOURCES = mavground.qrc
......@@ -29,7 +29,7 @@
# $$BASEDIR/lib/openjaus/libopenJaus/include
message(Qt version $$[QT_VERSION])
message(Using Qt from $QTDIR)
message(Using Qt from $$[QTDIR])
release {
# DEFINES += QT_NO_DEBUG_OUTPUT
......
# -------------------------------------------------
# QGroundControl - Micro Air Vehicle Groundstation
# Please see our website at <http://qgroundcontrol.org>
# Author:
# Lorenz Meier <mavteam@student.ethz.ch>
# (c) 2009-2010 PIXHAWK Team
# This file is part of the mav groundstation project
# Maintainer:
# Lorenz Meier <lm@inf.ethz.ch>
# (c) 2009-2011 QGroundControl Developers
# This file is part of the open groundstation project
# QGroundControl is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
......@@ -23,11 +23,17 @@
# Version from GIT repository is preferred
# include ( "../qmapcontrol/QMapControl/QMapControl.pri" ) #{
# Include bundled version if necessary
#include(lib/QMapControl/QMapControl.pri)
# include(lib/QMapControl/QMapControl.pri)
include(lib/nmea/nmea.pri)
include(lib/opmapcontrol/opmapcontrol.pri)
# This is a HACK - linking to openpilot repo for now
# OPMapControl is a OpenPilot-independent map library
# provided by the OpenPilot team - thanks, great piece
# of open-source software!
# (We're not reusing any part of the OP GCS, just the map library)
include(../openpilot/ground/openpilotgcs/src/libs/opmapcontrol/opmapcontrol_external.pri)
# include(lib/opmapcontrol/opmapcontrol.pri)
# message("Including bundled QMapControl version as FALLBACK. This is fine on Linux and MacOS, but not the best choice in Windows")
QT += network \
opengl \
......@@ -57,7 +63,6 @@ exists(user_config.pri) {
message("Adding support for additional MAVLink messages for: " $$MAVLINK_CONF)
message("------------------------------------------------------------------------")
}
INCLUDEPATH += $$BASEDIR/../mavlink/include/common
INCLUDEPATH += $$BASEDIR/../mavlink/include
INCLUDEPATH += $$BASEDIR/thirdParty/mavlink/include/common
......@@ -112,27 +117,19 @@ include(qgroundcontrol.pri)
# Include QWT plotting library
include(src/lib/qwt/qwt.pri)
DEPENDPATH += . \
# lib/QMapControl \
# lib/QMapControl/src \
lib/opmapcontrol \
lib/opmapcontrol/src \
plugins \
thirdParty/qserialport/include \
thirdParty/qserialport/include/QtSerialPort \
thirdParty/qserialport
\ # lib/QMapControl \
# lib/QMapControl/src \
lib/opmapcontrollib/opmapcontrol/srcpluginsthirdParty/qserialport/includethirdParty/qserialport/include/QtSerialPortthirdParty/qserialport
INCLUDEPATH += . \
# lib/QMapControl \
lib/opmapcontrol \
thirdParty/qserialport/include \
thirdParty/qserialport/include/QtSerialPort \
thirdParty/qserialport/src
\ # lib/QMapControl \
lib/opmapcontrolthirdParty/qserialport/includethirdParty/qserialport/include/QtSerialPortthirdParty/qserialport/src
# Include serial port library
#include(src/lib/qextserialport/qextserialport.pri)
# include(src/lib/qextserialport/qextserialport.pri)
# include qserial library
include(thirdParty/qserialport/qgroundcontrol-qserialport.pri)
# ../mavlink/include \
# MAVLink/include \
# mavlink/include
......@@ -151,7 +148,7 @@ FORMS += src/ui/MainWindow.ui \
src/ui/ObjectDetectionView.ui \
src/ui/JoystickWidget.ui \
src/ui/DebugConsole.ui \
# src/ui/MapWidget.ui \
\ \ # src/ui/MapWidget.ui \
src/ui/XMLCommProtocolWidget.ui \
src/ui/HDDisplay.ui \
src/ui/MAVLinkSettingsWidget.ui \
......@@ -183,7 +180,6 @@ FORMS += src/ui/MainWindow.ui \
src/ui/UASControlParameters.ui \
src/ui/mission/QGCMissionDoWidget.ui \
src/ui/mission/QGCMissionConditionWidget.ui
INCLUDEPATH += src \
src/ui \
src/ui/linechart \
......@@ -199,7 +195,6 @@ INCLUDEPATH += src \
src/ui/watchdog \
src/ui/map3D \
src/ui/designer
HEADERS += src/MG.h \
src/QGCCore.h \
src/uas/UASInterface.h \
......@@ -237,7 +232,6 @@ HEADERS += src/MG.h \
src/input/JoystickInput.h \
src/ui/JoystickWidget.h \
src/ui/DebugConsole.h \
# src/ui/MapWidget.h \
src/ui/XMLCommProtocolWidget.h \
src/ui/mavlink/DomItem.h \
src/ui/mavlink/DomModel.h \
......@@ -264,8 +258,6 @@ HEADERS += src/MG.h \
src/ui/QGCPxImuFirmwareUpdate.h \
src/ui/QGCDataPlot2D.h \
src/ui/linechart/IncrementalPlot.h \
# src/ui/map/Waypoint2DIcon.h \
# src/ui/map/MAV2DIcon.h \
src/ui/QGCRemoteControlView.h \
src/ui/RadioCalibration/RadioCalibrationData.h \
src/ui/RadioCalibration/RadioCalibrationWindow.h \
......@@ -298,13 +290,11 @@ HEADERS += src/MG.h \
src/ui/mission/QGCMissionDoWidget.h \
src/ui/mission/QGCMissionConditionWidget.h \
src/uas/QGCUASParamManager.h \
src/ui/QGCMapWidget.h
src/ui/QGCMapWidget.h \
src/ui/mavlink/QGCMAVLinkTextEdit.h
# Google Earth is only supported on Mac OS and Windows with Visual Studio Compiler
macx|win32-msvc2008: {
HEADERS += src/ui/map3D/QGCGoogleEarthView.h
}
macx|win32-msvc2008::HEADERS += src/ui/map3D/QGCGoogleEarthView.h
contains(DEPENDENCIES_PRESENT, osg) {
message("Including headers for OpenSceneGraph")
......@@ -336,7 +326,6 @@ contains(DEPENDENCIES_PRESENT, libfreenect) {
# Enable only if libfreenect is available
HEADERS += src/input/Freenect.h
}
SOURCES += src/main.cc \
src/QGCCore.cc \
src/uas/UASManager.cc \
......@@ -369,7 +358,7 @@ SOURCES += src/main.cc \
src/input/JoystickInput.cc \
src/ui/JoystickWidget.cc \
src/ui/DebugConsole.cc \
# src/ui/MapWidget.cc \
\ \ # src/ui/MapWidget.cc \
src/ui/XMLCommProtocolWidget.cc \
src/ui/mavlink/DomItem.cc \
src/ui/mavlink/DomModel.cc \
......@@ -396,8 +385,8 @@ SOURCES += src/main.cc \
src/ui/QGCPxImuFirmwareUpdate.cc \
src/ui/QGCDataPlot2D.cc \
src/ui/linechart/IncrementalPlot.cc \
# src/ui/map/Waypoint2DIcon.cc \
# src/ui/map/MAV2DIcon.cc \
\ \ # src/ui/map/Waypoint2DIcon.cc \
# src/ui/map/MAV2DIcon.cc \
src/ui/QGCRemoteControlView.cc \
src/ui/RadioCalibration/RadioCalibrationWindow.cc \
src/ui/RadioCalibration/AirfoilServoCalibrator.cc \
......@@ -429,12 +418,9 @@ SOURCES += src/main.cc \
src/ui/mission/QGCMissionDoWidget.cc \
src/ui/mission/QGCMissionConditionWidget.cc \
src/uas/QGCUASParamManager.cc \
src/ui/QGCMapWidget.cc
macx|win32-msvc2008: {
SOURCES += src/ui/map3D/QGCGoogleEarthView.cc
}
src/ui/QGCMapWidget.cc \
src/ui/mavlink/QGCMAVLinkTextEdit.cc
macx|win32-msvc2008::SOURCES += src/ui/map3D/QGCGoogleEarthView.cc
contains(DEPENDENCIES_PRESENT, osg) {
message("Including sources for OpenSceneGraph")
......@@ -452,9 +438,7 @@ contains(DEPENDENCIES_PRESENT, osg) {
src/ui/map3D/Texture.cc \
src/ui/map3D/Imagery.cc \
src/ui/map3D/HUDScaleGeode.cc \
src/ui/map3D/WaypointGroupNode.cc \
src/ui/map3D/WaypointGroupNode.cc
contains(DEPENDENCIES_PRESENT, osgearth) {
message("Including sources for osgEarth")
......@@ -471,7 +455,7 @@ contains(DEPENDENCIES_PRESENT, libfreenect) {
RESOURCES += mavground.qrc
# Include RT-LAB Library
win32:exists(src/lib/opalrt/OpalApi.h):exists(C:/OPAL-RT/RT-LAB7.2.4/Common/bin) {
win32:exists(src/lib/opalrt/OpalApi.h):exists(C:/OPAL-RT/RT-LAB7.2.4/Common/bin) {
message("Building support for Opal-RT")
LIBS += -LC:/OPAL-RT/RT-LAB7.2.4/Common/bin \
-lOpalApi
......@@ -491,6 +475,5 @@ win32:exists(src/lib/opalrt/OpalApi.h):exists(C:/OPAL-RT/RT-LAB7.2.4/Common/bin)
FORMS += src/ui/OpalLinkSettings.ui
DEFINES += OPAL_RT
}
TRANSLATIONS += es-MX.ts \
TRANSLATIONS += es-MX.ts \
en-US.ts
......@@ -149,7 +149,8 @@ bool MAVLinkXMLParser::generate()
connect(&includeParser, SIGNAL(parseState(QString)), this, SIGNAL(parseState(QString)));
// Generate and write
recursion_level++;
includeParser.generate();
// Abort if inclusion fails
if (!includeParser.generate()) return false;
recursion_level--;
mainHeader += "\n#include \"../" + pureIncludeFileName + "/" + pureIncludeFileName + ".h\"\n";
......
#ifndef QGC_CONFIGURATION_H
#define QGC_CONFIGURATION_H
#include "mavlink.h"
#include <QString>
/** @brief Polling interval in ms */
#ifdef MAVLINK_ENABLED_SLUGS
#define SERIAL_POLL_INTERVAL 7
#else
#define SERIAL_POLL_INTERVAL 7
#endif
/** @brief Heartbeat emission rate, in Hertz (times per second) */
#define MAVLINK_HEARTBEAT_DEFAULT_RATE 1
......
This diff is collapsed.
#ifndef _POSIX_QEXTSERIALPORT_H_
#define _POSIX_QEXTSERIALPORT_H_
#include <stdio.h>
#include <termios.h>
#include <errno.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include "qextserialbase.h"
class Posix_QextSerialPort:public QextSerialBase
{
private:
/*!
* This method is a part of constructor.
*/
void init();
protected:
int fd;
struct termios Posix_CommConfig;
struct termios old_termios;
struct timeval Posix_Timeout;
struct timeval Posix_Copy_Timeout;
virtual qint64 readData(char * data, qint64 maxSize);
virtual qint64 writeData(const char * data, qint64 maxSize);
public:
Posix_QextSerialPort(QextSerialBase::QueryMode mode);
Posix_QextSerialPort(const Posix_QextSerialPort& s);
Posix_QextSerialPort(const QString & name, QextSerialBase::QueryMode mode);
Posix_QextSerialPort(const PortSettings& settings, QextSerialBase::QueryMode mode);
Posix_QextSerialPort(const QString & name, const PortSettings& settings, QextSerialBase::QueryMode mode);
Posix_QextSerialPort& operator=(const Posix_QextSerialPort& s);
virtual ~Posix_QextSerialPort();
virtual void setBaudRate(BaudRateType);
virtual void setDataBits(DataBitsType);
virtual void setParity(ParityType);
virtual void setStopBits(StopBitsType);
virtual void setFlowControl(FlowType);
virtual void setTimeout(long);
virtual bool open(OpenMode mode);
virtual void close();
virtual void flush();
virtual qint64 size() const;
virtual qint64 bytesAvailable() const;
virtual void ungetChar(char c);
virtual void translateError(ulong error);
virtual void setDtr(bool set=true);
virtual void setRts(bool set=true);
virtual ulong lineStatus();
};
#endif
#include "qextserialbase.h"
/*!
\fn QextSerialBase::QextSerialBase()
Default constructor.
*/
QextSerialBase::QextSerialBase()
: QIODevice()
{
#ifdef _TTY_WIN_
setPortName("COM1");
#elif defined(_TTY_IRIX_)
setPortName("/dev/ttyf1");
#elif defined(_TTY_HPUX_)
setPortName("/dev/tty1p0");
#elif defined(_TTY_SUN_)
setPortName("/dev/ttya");
#elif defined(_TTY_DIGITAL_)
setPortName("/dev/tty01");
#elif defined(_TTY_FREEBSD_)
setPortName("/dev/ttyd1");
#elif defined(_TTY_OPENBSD_)
setPortName("/dev/tty00");
#else
setPortName("/dev/ttyS0");
#endif
construct();
}
/*!
\fn QextSerialBase::QextSerialBase(const QString & name)
Construct a port and assign it to the device specified by the name parameter.
*/
QextSerialBase::QextSerialBase(const QString & name)
: QIODevice()
{
setPortName(name);
construct();
}
/*!
\fn QextSerialBase::~QextSerialBase()
Standard destructor.
*/
QextSerialBase::~QextSerialBase()
{
delete mutex;
}
/*!
\fn void QextSerialBase::construct()
Common constructor function for setting up default port settings.
(115200 Baud, 8N1, Hardware flow control where supported, otherwise no flow control, and 0 ms timeout).
*/
void QextSerialBase::construct()
{
lastErr = E_NO_ERROR;
Settings.BaudRate=BAUD115200;
Settings.DataBits=DATA_8;
Settings.Parity=PAR_NONE;
Settings.StopBits=STOP_1;
Settings.FlowControl=FLOW_HARDWARE;
Settings.Timeout_Millisec=500;
mutex = new QMutex( QMutex::Recursive );
setOpenMode(QIODevice::NotOpen);
}
void QextSerialBase::setQueryMode(QueryMode mechanism)
{
_queryMode = mechanism;
}
/*!
\fn void QextSerialBase::setPortName(const QString & name)
Sets the name of the device associated with the object, e.g. "COM1", or "/dev/ttyS0".
*/
void QextSerialBase::setPortName(const QString & name)
{
port = name;
}
/*!
\fn QString QextSerialBase::portName() const
Returns the name set by setPortName().
*/
QString QextSerialBase::portName() const
{
return port;
}
/*!
\fn BaudRateType QextSerialBase::baudRate(void) const
Returns the baud rate of the serial port. For a list of possible return values see
the definition of the enum BaudRateType.
*/
BaudRateType QextSerialBase::baudRate(void) const
{
return Settings.BaudRate;
}
/*!
\fn DataBitsType QextSerialBase::dataBits() const
Returns the number of data bits used by the port. For a list of possible values returned by
this function, see the definition of the enum DataBitsType.
*/
DataBitsType QextSerialBase::dataBits() const
{
return Settings.DataBits;
}
/*!
\fn ParityType QextSerialBase::parity() const
Returns the type of parity used by the port. For a list of possible values returned by
this function, see the definition of the enum ParityType.
*/
ParityType QextSerialBase::parity() const
{
return Settings.Parity;
}
/*!
\fn StopBitsType QextSerialBase::stopBits() const
Returns the number of stop bits used by the port. For a list of possible return values, see
the definition of the enum StopBitsType.
*/
StopBitsType QextSerialBase::stopBits() const
{
return Settings.StopBits;
}
/*!
\fn FlowType QextSerialBase::flowControl() const
Returns the type of flow control used by the port. For a list of possible values returned
by this function, see the definition of the enum FlowType.
*/
FlowType QextSerialBase::flowControl() const
{
return Settings.FlowControl;
}
/*!
\fn bool QextSerialBase::isSequential() const
Returns true if device is sequential, otherwise returns false. Serial port is sequential device
so this function always returns true. Check QIODevice::isSequential() documentation for more
information.
*/
bool QextSerialBase::isSequential() const
{
return true;
}
/*!
\fn bool QextSerialBase::atEnd() const
This function will return true if the input buffer is empty (or on error), and false otherwise.
Call QextSerialBase::lastError() for error information.
*/
bool QextSerialBase::atEnd() const
{
if (size()) {
return true;
}
return false;
}
/*!
\fn qint64 QextSerialBase::readLine(char * data, qint64 maxSize)
This function will read a line of buffered input from the port, stopping when either maxSize bytes
have been read, the port has no more data available, or a newline is encountered.
The value returned is the length of the string that was read.
*/
qint64 QextSerialBase::readLine(char * data, qint64 maxSize)
{
qint64 numBytes = bytesAvailable();
char* pData = data;
if (maxSize < 2) //maxSize must be larger than 1
return -1;
/*read a byte at a time for MIN(bytesAvail, maxSize - 1) iterations, or until a newline*/
while (pData<(data+numBytes) && --maxSize) {
readData(pData, 1);
if (*pData++ == '\n') {
break;
}
}
*pData='\0';
/*return size of data read*/
return (pData-data);
}
/*!
\fn ulong QextSerialBase::lastError() const
Returns the code for the last error encountered by the port, or E_NO_ERROR if the last port
operation was successful. Possible error codes are:
\verbatim
Error Explanation
--------------------------- -------------------------------------------------------------
E_NO_ERROR No Error has occured
E_INVALID_FD Invalid file descriptor (port was not opened correctly)
E_NO_MEMORY Unable to allocate memory tables (POSIX)
E_CAUGHT_NON_BLOCKED_SIGNAL Caught a non-blocked signal (POSIX)
E_PORT_TIMEOUT Operation timed out (POSIX)
E_INVALID_DEVICE The file opened by the port is not a character device (POSIX)
E_BREAK_CONDITION The port detected a break condition
E_FRAMING_ERROR The port detected a framing error
(usually caused by incorrect baud rate settings)
E_IO_ERROR There was an I/O error while communicating with the port
E_BUFFER_OVERRUN Character buffer overrun
E_RECEIVE_OVERFLOW Receive buffer overflow
E_RECEIVE_PARITY_ERROR The port detected a parity error in the received data
E_TRANSMIT_OVERFLOW Transmit buffer overflow
E_READ_FAILED General read operation failure
E_WRITE_FAILED General write operation failure
\endverbatim
*/
ulong QextSerialBase::lastError() const
{
return lastErr;
}
#ifndef _QEXTSERIALBASE_H_
#define _QEXTSERIALBASE_H_
#include <QIODevice>
#include <QFile>
#include <QThread>
#include <QMutex>
/*if all warning messages are turned off, flag portability warnings to be turned off as well*/
#ifdef _TTY_NOWARN_
#define _TTY_NOWARN_PORT_
#endif
/*macros for thread support*/
#define LOCK_MUTEX() mutex->lock()
#define UNLOCK_MUTEX() mutex->unlock()
/*macros for warning and debug messages*/
#ifdef _TTY_NOWARN_PORT_
#define TTY_PORTABILITY_WARNING(s)
#else
#define TTY_PORTABILITY_WARNING(s) qWarning(s)
#endif /*_TTY_NOWARN_PORT_*/
#ifdef _TTY_NOWARN_
#define TTY_WARNING(s)
#else
#define TTY_WARNING(s) qWarning(s)
#endif /*_TTY_NOWARN_*/
/*line status constants*/
#define LS_CTS 0x01
#define LS_DSR 0x02
#define LS_DCD 0x04
#define LS_RI 0x08
#define LS_RTS 0x10
#define LS_DTR 0x20
#define LS_ST 0x40
#define LS_SR 0x80
/*error constants*/
#define E_NO_ERROR 0
#define E_INVALID_FD 1
#define E_NO_MEMORY 2
#define E_CAUGHT_NON_BLOCKED_SIGNAL 3
#define E_PORT_TIMEOUT 4
#define E_INVALID_DEVICE 5
#define E_BREAK_CONDITION 6
#define E_FRAMING_ERROR 7
#define E_IO_ERROR 8
#define E_BUFFER_OVERRUN 9
#define E_RECEIVE_OVERFLOW 10
#define E_RECEIVE_PARITY_ERROR 11
#define E_TRANSMIT_OVERFLOW 12
#define E_READ_FAILED 13
#define E_WRITE_FAILED 14
/*!
* Enums for port settings.
*/
enum NamingConvention {
WIN_NAMES,
IRIX_NAMES,
HPUX_NAMES,
SUN_NAMES,
DIGITAL_NAMES,
FREEBSD_NAMES,
OPENBSD_NAMES,
LINUX_NAMES
};
enum BaudRateType {
BAUD50, //POSIX ONLY
BAUD75, //POSIX ONLY
BAUD110,
BAUD134, //POSIX ONLY
BAUD150, //POSIX ONLY
BAUD200, //POSIX ONLY
BAUD300,
BAUD600,
BAUD1200,
BAUD1800, //POSIX ONLY
BAUD2400,
BAUD4800,
BAUD9600,
BAUD14400, //WINDOWS ONLY
BAUD19200,
BAUD38400,
BAUD56000, //WINDOWS ONLY
BAUD57600,
BAUD76800, //POSIX ONLY
BAUD115200,
BAUD128000, // WINDOWS ONLY
BAUD230400, // WINDOWS ONLY
BAUD256000, // WINDOWS ONLY
BAUD460800, // WINDOWS ONLY
BAUD921600 // WINDOWS ONLY
};
enum DataBitsType {
DATA_5,
DATA_6,
DATA_7,
DATA_8
};
enum ParityType {
PAR_NONE,
PAR_ODD,
PAR_EVEN,
PAR_MARK, //WINDOWS ONLY
PAR_SPACE
};
enum StopBitsType {
STOP_1,
STOP_1_5, //WINDOWS ONLY
STOP_2
};
enum FlowType {
FLOW_OFF,
FLOW_HARDWARE,
FLOW_XONXOFF
};
/**
* structure to contain port settings
*/
struct PortSettings {
BaudRateType BaudRate;
DataBitsType DataBits;
ParityType Parity;
StopBitsType StopBits;
FlowType FlowControl;
long Timeout_Millisec;
};
/*!
* \author Stefan Sander
* \author Michal Policht
*
* A common base class for Win_QextSerialBase, Posix_QextSerialBase and QextSerialPort.
*/
class QextSerialBase : public QIODevice
{
Q_OBJECT
public:
enum QueryMode {
Polling,
EventDriven
};
protected:
QMutex* mutex;
QString port;
PortSettings Settings;
ulong lastErr;
QextSerialBase::QueryMode _queryMode;
virtual qint64 readData(char * data, qint64 maxSize)=0;
virtual qint64 writeData(const char * data, qint64 maxSize)=0;
public:
QextSerialBase();
QextSerialBase(const QString & name);
virtual ~QextSerialBase();
virtual void construct();
virtual void setPortName(const QString & name);
virtual QString portName() const;
/**!
* Get query mode.
* \return query mode.
*/
inline QextSerialBase::QueryMode queryMode() const {
return _queryMode;
};
/*!
* Set desired serial communication handling style. You may choose from polling
* or event driven approach. This function does nothing when port is open; to
* apply changes port must be reopened.
*
* In event driven approach read() and write() functions are acting
* asynchronously. They return immediately and the operation is performed in
* the background, so they doesn't freeze the calling thread.
* To determine when operation is finished, QextSerialPort runs separate thread
* and monitors serial port events. Whenever the event occurs, adequate signal
* is emitted.
*
* When polling is set, read() and write() are acting synchronously. Signals are
* not working in this mode and some functions may not be available. The advantage
* of polling is that it generates less overhead due to lack of signals emissions
* and it doesn't start separate thread to monitor events.
*
* Generally event driven approach is more capable and friendly, although some
* applications may need as low overhead as possible and then polling comes.
*
* \param mode query mode.
*/
virtual void setQueryMode(QueryMode mode);
virtual void setBaudRate(BaudRateType)=0;
virtual BaudRateType baudRate() const;
virtual void setDataBits(DataBitsType)=0;
virtual DataBitsType dataBits() const;
virtual void setParity(ParityType)=0;
virtual ParityType parity() const;
virtual void setStopBits(StopBitsType)=0;
virtual StopBitsType stopBits() const;
virtual void setFlowControl(FlowType)=0;
virtual FlowType flowControl() const;
virtual void setTimeout(long)=0;
virtual bool open(OpenMode mode)=0;
virtual bool isSequential() const;
virtual void close()=0;
virtual void flush()=0;
virtual qint64 size() const = 0;
virtual qint64 bytesAvailable() const = 0;
virtual bool atEnd() const;
virtual void ungetChar(char c)=0;
virtual qint64 readLine(char * data, qint64 maxSize);
virtual ulong lastError() const;
virtual void translateError(ulong error)=0;
virtual void setDtr(bool set=true)=0;
virtual void setRts(bool set=true)=0;
virtual ulong lineStatus()=0;
signals:
/**
* This signal is emitted whenever port settings are updated.
* \param valid \p true if settings are valid, \p false otherwise.
*
* @todo implement.
*/
// void validSettings(bool valid);
/*!
* This signal is emitted whenever dsr line has changed its state. You may
* use this signal to check if device is connected.
* \param status \p true when DSR signal is on, \p false otherwise.
*
* \see lineStatus().
*/
void dsrChanged(bool status);
};
#endif
/**
* @file qextserialenumerator.cpp
* @author Michał Policht
* @see QextSerialEnumerator
*/
#include "qextserialenumerator.h"
#ifdef _TTY_WIN_
#include <objbase.h>
#include <initguid.h>
//this is serial port GUID
#ifndef GUID_CLASS_COMPORT
DEFINE_GUID(GUID_CLASS_COMPORT, 0x86e0d1e0L, 0x8089, 0x11d0, 0x9c, 0xe4, 0x08, 0x00, 0x3e, 0x30, 0x1f, 0x73);
#endif
/* Gordon Schumacher's macros for TCHAR -> QString conversions and vice versa */
#ifdef UNICODE
#define QStringToTCHAR(x) (wchar_t*) x.utf16()
#define PQStringToTCHAR(x) (wchar_t*) x->utf16()
#define TCHARToQString(x) QString::fromUtf16((ushort*)(x))
#define TCHARToQStringN(x,y) QString::fromUtf16((ushort*)(x),(y))
#else
#define QStringToTCHAR(x) x.local8Bit().constData()
#define PQStringToTCHAR(x) x->local8Bit().constData()
#define TCHARToQString(x) QString::fromLocal8Bit((x))
#define TCHARToQStringN(x,y) QString::fromLocal8Bit((x),(y))
#endif /*UNICODE*/
//static
QString QextSerialEnumerator::getRegKeyValue(HKEY key, LPCTSTR property)
{
DWORD size = 0;
RegQueryValueEx(key, property, NULL, NULL, NULL, & size);
BYTE * buff = new BYTE[size];
if (RegQueryValueEx(key, property, NULL, NULL, buff, & size) == ERROR_SUCCESS) {
return TCHARToQStringN(buff, size);
delete [] buff;
} else {
qWarning("QextSerialEnumerator::getRegKeyValue: can not obtain value from registry");
delete [] buff;
return QString();
}
}
//static
QString QextSerialEnumerator::getDeviceProperty(HDEVINFO devInfo, PSP_DEVINFO_DATA devData, DWORD property)
{
DWORD buffSize = 0;
SetupDiGetDeviceRegistryProperty(devInfo, devData, property, NULL, NULL, 0, & buffSize);
BYTE * buff = new BYTE[buffSize];
if (!SetupDiGetDeviceRegistryProperty(devInfo, devData, property, NULL, buff, buffSize, NULL))
qCritical("Can not obtain property: %ld from registry", property);
QString result = TCHARToQString(buff);
delete [] buff;
return result;
}
//static
void QextSerialEnumerator::setupAPIScan(QList<QextPortInfo> & infoList)
{
HDEVINFO devInfo = INVALID_HANDLE_VALUE;
GUID * guidDev = (GUID *) & GUID_CLASS_COMPORT;
devInfo = SetupDiGetClassDevs(guidDev, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if(devInfo == INVALID_HANDLE_VALUE) {
qCritical("SetupDiGetClassDevs failed. Error code: %ld", GetLastError());
return;
}
//enumerate the devices
bool ok = true;
SP_DEVICE_INTERFACE_DATA ifcData;
ifcData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
SP_DEVICE_INTERFACE_DETAIL_DATA * detData = NULL;
DWORD detDataSize = 0;
DWORD oldDetDataSize = 0;
for (DWORD i = 0; ok; i++) {
ok = SetupDiEnumDeviceInterfaces(devInfo, NULL, guidDev, i, &ifcData);
if (ok) {
SP_DEVINFO_DATA devData = {sizeof(SP_DEVINFO_DATA)};
//check for required detData size
SetupDiGetDeviceInterfaceDetail(devInfo, & ifcData, NULL, 0, & detDataSize, & devData);
//if larger than old detData size then reallocate the buffer
if (detDataSize > oldDetDataSize) {
delete [] detData;
detData = (SP_DEVICE_INTERFACE_DETAIL_DATA *) new char[detDataSize];
detData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
oldDetDataSize = detDataSize;
}
//check the details
if (SetupDiGetDeviceInterfaceDetail(devInfo, & ifcData, detData, detDataSize,
NULL, & devData)) {
// Got a device. Get the details.
QextPortInfo info;
info.friendName = getDeviceProperty(devInfo, & devData, SPDRP_FRIENDLYNAME);
info.physName = getDeviceProperty(devInfo, & devData, SPDRP_PHYSICAL_DEVICE_OBJECT_NAME);
info.enumName = getDeviceProperty(devInfo, & devData, SPDRP_ENUMERATOR_NAME);
//anyway, to get the port name we must still open registry directly :( ???
//Eh...
HKEY devKey = SetupDiOpenDevRegKey(devInfo, & devData, DICS_FLAG_GLOBAL, 0,
DIREG_DEV, KEY_READ);
info.portName = getRegKeyValue(devKey, TEXT("PortName"));
RegCloseKey(devKey);
infoList.append(info);
} else {
qCritical("SetupDiGetDeviceInterfaceDetail failed. Error code: %ld", GetLastError());
delete [] detData;
return;
}
} else {
if (GetLastError() != ERROR_NO_MORE_ITEMS) {
delete [] detData;
qCritical("SetupDiEnumDeviceInterfaces failed. Error code: %ld", GetLastError());
return;
}
}
}
delete [] detData;
}
#endif /*_TTY_WIN_*/
//static
QList<QextPortInfo> QextSerialEnumerator::getPorts()
{
QList<QextPortInfo> ports;
#ifdef _TTY_WIN_
OSVERSIONINFO vi;
vi.dwOSVersionInfoSize = sizeof(vi);
if (!::GetVersionEx(&vi)) {
qCritical("Could not get OS version.");
return ports;
}
// Handle windows 9x and NT4 specially
if (vi.dwMajorVersion < 5) {
qCritical("Enumeration for this version of Windows is not implemented yet");
/* if (vi.dwPlatformId == VER_PLATFORM_WIN32_NT)
EnumPortsWNt4(ports);
else
EnumPortsW9x(ports);*/
} else //w2k or later
setupAPIScan(ports);
#endif /*_TTY_WIN_*/
#ifdef _TTY_POSIX_
qCritical("Enumeration for POSIX systems is not implemented yet.");
#endif /*_TTY_POSIX_*/
return ports;
}
/*!
* \file qextserialenumerator.h
* \author Michal Policht
* \see QextSerialEnumerator
*/
#ifndef _QEXTSERIALENUMERATOR_H_
#define _QEXTSERIALENUMERATOR_H_
#include <QString>
#include <QList>
#ifdef _TTY_WIN_
#include <windows.h>
#include <setupapi.h>
#endif /*_TTY_WIN_*/
/*!
* Structure containing port information.
*/
struct QextPortInfo {
QString portName; ///< Port name.
QString physName; ///< Physical name.
QString friendName; ///< Friendly name.
QString enumName; ///< Enumerator name.
};
/*!
* Serial port enumerator. This class provides list of ports available in the system.
*
* Windows implementation is based on Zach Gorman's work from
* <a href="http://www.codeproject.com">The Code Project</a> (http://www.codeproject.com/system/setupdi.asp).
*/
class QextSerialEnumerator
{
private:
#ifdef _TTY_WIN_
/*!
* Get value of specified property from the registry.
* \param key handle to an open key.
* \param property property name.
* \return property value.
*/
static QString getRegKeyValue(HKEY key, LPCTSTR property);
/*!
* Get specific property from registry.
* \param devInfo pointer to the device information set that contains the interface
* and its underlying device. Returned by SetupDiGetClassDevs() function.
* \param devData pointer to an SP_DEVINFO_DATA structure that defines the device instance.
* this is returned by SetupDiGetDeviceInterfaceDetail() function.
* \param property registry property. One of defined SPDRP_* constants.
* \return property string.
*/
static QString getDeviceProperty(HDEVINFO devInfo, PSP_DEVINFO_DATA devData, DWORD property);
/*!
* Search for serial ports using setupapi.
* \param infoList list with result.
*/
static void setupAPIScan(QList<QextPortInfo> & infoList);
#endif /*_TTY_WIN_*/
public:
/*!
* Get list of ports.
* \return list of ports currently available in the system.
*/
static QList<QextPortInfo> getPorts();
};
#endif /*_QEXTSERIALENUMERATOR_H_*/
/*!
\class QextSerialPort
\author Stefan Sander
\author Michal Policht
A cross-platform serial port class.
This class encapsulates a serial port on both POSIX and Windows systems. The user will be
notified of errors and possible portability conflicts at run-time by default - this behavior can
be turned off by defining _TTY_NOWARN_ (to turn off all warnings) or _TTY_NOWARN_PORT_ (to turn
off portability warnings) in the project.
You may choose from polling or event driven API. For details check setQueryMode() documentation.
\note
On Windows NT/2000/XP this class uses Win32 serial port functions by default. The user may
select POSIX behavior under NT, 2000, or XP ONLY by defining _TTY_POSIX_ in the project. I can
make no guarantees as to the quality of POSIX support under NT/2000 however.
*/
#include <stdio.h>
#include "qextserialport.h"
/*!
Default constructor. Note that the naming convention used by a QextSerialPort constructed with
this constructor will be determined by #defined constants, or lack thereof - the default behavior
is the same as _TTY_LINUX_. Possible naming conventions and their associated constants are:
\verbatim
Constant Used By Naming Convention
---------- ------------- ------------------------
_TTY_WIN_ Windows COM1, COM2
_TTY_IRIX_ SGI/IRIX /dev/ttyf1, /dev/ttyf2
_TTY_HPUX_ HP-UX /dev/tty1p0, /dev/tty2p0
_TTY_SUN_ SunOS/Solaris /dev/ttya, /dev/ttyb
_TTY_DIGITAL_ Digital UNIX /dev/tty01, /dev/tty02
_TTY_FREEBSD_ FreeBSD /dev/ttyd0, /dev/ttyd1
_TTY_LINUX_ Linux /dev/ttyS0, /dev/ttyS1
<none> Linux /dev/ttyS0, /dev/ttyS1
\endverbatim
The object will be associated with the first port in the system, e.g. COM1 on Windows systems.
See the other constructors if you need to use a port other than the first.
*/
QextSerialPort::QextSerialPort(QueryMode mode)
: QextBaseType(mode)
{}
/*!
Constructs a serial port attached to the port specified by name.
name is the name of the device, which is windowsystem-specific,
e.g."COM1" or "/dev/ttyS0".
\see setQueryMode().
*/
QextSerialPort::QextSerialPort(const QString & name, QueryMode mode)
: QextBaseType(name, mode)
{
}
/*!
Constructs a port with default name and settings specified by the settings parameter.
\see setQueryMode().
*/
QextSerialPort::QextSerialPort(PortSettings const& settings, QueryMode mode)
: QextBaseType(settings, mode)
{}
/*!
Constructs a port with the name and settings specified.
\see setQueryMode().
*/
QextSerialPort::QextSerialPort(const QString & name, PortSettings const& settings, QueryMode mode)
: QextBaseType(name, settings, mode)
{}
/*!
Copy constructor.
\deprecated
*/
QextSerialPort::QextSerialPort(const QextSerialPort& s)
: QextBaseType(s)
{}
/*!
\fn QextSerialPort& QextSerialPort::operator=(const QextSerialPort& s)
Overrides the = operator.
\deprecated
*/
QextSerialPort& QextSerialPort::operator=(const QextSerialPort& s)
{
return (QextSerialPort&)QextBaseType::operator=(s);
}
/*!
\fn QextSerialPort::~QextSerialPort()
Standard destructor.
*/
QextSerialPort::~QextSerialPort()
{}
#ifndef _QEXTSERIALPORT_H_
#define _QEXTSERIALPORT_H_
/*POSIX CODE*/
#ifdef _TTY_POSIX_
#include "posix_qextserialport.h"
#define QextBaseType Posix_QextSerialPort
/*MS WINDOWS CODE*/
#else
#include "win_qextserialport.h"
#define QextBaseType Win_QextSerialPort
#endif
class QextSerialPort: public QextBaseType
{
Q_OBJECT
public:
typedef QextSerialBase::QueryMode QueryMode;
QextSerialPort(QueryMode mode = QextSerialPort::EventDriven);
QextSerialPort(const QString & name, QueryMode mode = QextSerialPort::EventDriven);
QextSerialPort(PortSettings const& s, QueryMode mode = QextSerialPort::EventDriven);
QextSerialPort(const QString & name, PortSettings const& s, QueryMode mode = QextSerialPort::EventDriven);
QextSerialPort(const QextSerialPort& s);
QextSerialPort& operator=(const QextSerialPort&);
virtual ~QextSerialPort();
};
#endif
QPORTDIR = src/lib/qextserialport
INCLUDEPATH += $$QPORTDIR
HEADERS += $$QPORTDIR/qextserialbase.h \
$$QPORTDIR/qextserialport.h \
$$QPORTDIR/qextserialenumerator.h
SOURCES += $$QPORTDIR/qextserialbase.cpp \
$$QPORTDIR/qextserialport.cpp \
$$QPORTDIR/qextserialenumerator.cpp
unix:HEADERS += $$QPORTDIR/posix_qextserialport.h
unix:SOURCES += $$QPORTDIR/posix_qextserialport.cpp
unix:DEFINES += _TTY_POSIX_
win32:HEADERS += $$QPORTDIR/win_qextserialport.h
win32:SOURCES += $$QPORTDIR/win_qextserialport.cpp
win32:DEFINES += _TTY_WIN_
win32:LIBS += -lsetupapi
unix:VERSION = 1.2.0
This diff is collapsed.
#ifndef _WIN_QEXTSERIALPORT_H_
#define _WIN_QEXTSERIALPORT_H_
#include "qextserialbase.h"
#include <windows.h>
#include <QThread>
/* These baudrates work on windows, but are not part of the windows headers */
#ifndef CBR_230400
#define CBR_230400 230400
#endif
#ifndef CBR_460800
#define CBR_460800 460800
#endif
#ifndef CBR_921600
#define CBR_921600 921600
#endif
/*if all warning messages are turned off, flag portability warnings to be turned off as well*/
#ifdef _TTY_NOWARN_
#define _TTY_NOWARN_PORT_
#endif
class QReadWriteLock;
class Win_QextSerialThread;
/*!
\author Stefan Sander
\author Michal Policht
A cross-platform serial port class.
This class encapsulates the Windows portion of QextSerialPort. The user will be notified of
errors and possible portability conflicts at run-time by default - this behavior can be turned
off by defining _TTY_NOWARN_ (to turn off all warnings) or _TTY_NOWARN_PORT_ (to turn off
portability warnings) in the project. Note that defining _TTY_NOWARN_ also defines
_TTY_NOWARN_PORT_.
\note
On Windows NT/2000/XP this class uses Win32 serial port functions by default. The user may
select POSIX behavior under NT, 2000, or XP ONLY by defining _TTY_POSIX_ in the project. I can
make no guarantees as to the quality of POSIX support under NT/2000 however.
\todo remove copy constructor and assign operator.
*/
class Win_QextSerialPort: public QextSerialBase
{
Q_OBJECT
friend class Win_QextSerialThread;
private:
/*!
* This method is a part of constructor.
*/
void init();
protected:
HANDLE Win_Handle;
HANDLE threadStartEvent;
HANDLE threadTerminateEvent;
OVERLAPPED overlap;
OVERLAPPED overlapWrite;
COMMCONFIG Win_CommConfig;
COMMTIMEOUTS Win_CommTimeouts;
QReadWriteLock * bytesToWriteLock; ///< @todo maybe move to QextSerialBase.
qint64 _bytesToWrite; ///< @todo maybe move to QextSerialBase (and implement in POSIX).
Win_QextSerialThread * overlapThread; ///< @todo maybe move to QextSerialBase (and implement in POSIX).
void monitorCommEvent();
void terminateCommWait();
virtual qint64 readData(char *data, qint64 maxSize);
virtual qint64 writeData(const char *data, qint64 maxSize);
public:
Win_QextSerialPort(QextSerialBase::QueryMode mode);
Win_QextSerialPort(Win_QextSerialPort const& s);
Win_QextSerialPort(const QString & name, QextSerialBase::QueryMode mode);
Win_QextSerialPort(const PortSettings& settings, QextSerialBase::QueryMode mode);
Win_QextSerialPort(const QString & name, const PortSettings& settings, QextSerialBase::QueryMode mode);
Win_QextSerialPort& operator=(const Win_QextSerialPort& s);
virtual ~Win_QextSerialPort();
virtual bool open(OpenMode mode);
virtual void close();
virtual void flush();
virtual qint64 size() const;
virtual void ungetChar(char c);
virtual void setFlowControl(FlowType);
virtual void setParity(ParityType);
virtual void setDataBits(DataBitsType);
virtual void setStopBits(StopBitsType);
virtual void setBaudRate(BaudRateType);
virtual void setDtr(bool set=true);
virtual void setRts(bool set=true);
virtual ulong lineStatus(void);
virtual qint64 bytesAvailable() const;
virtual void translateError(ulong);
virtual void setTimeout(long);
/*!
* Return number of bytes waiting in the buffer. Currently this shows number
* of bytes queued within write() and before the TX_EMPTY event occured. TX_EMPTY
* event is created whenever last character in the system buffer was sent.
*
* \return number of bytes queued within write(), before the first TX_EMPTY
* event occur.
*
* \warning this function may not give you expected results since TX_EMPTY may occur
* while writing data to the buffer. Eventually some TX_EMPTY events may not be
* catched.
*
* \note this function always returns 0 in polling mode.
*
* \see flush().
*/
virtual qint64 bytesToWrite() const;
virtual bool waitForReadyRead(int msecs); ///< @todo implement.
};
/*!
* This thread monitors communication events.
*/
class Win_QextSerialThread: public QThread
{
Win_QextSerialPort * qesp;
bool terminate;
public:
/*!
* Constructor.
*
* \param qesp valid serial port object.
*/
Win_QextSerialThread(Win_QextSerialPort * qesp);
/*!
* Stop the thread.
*/
void stop();
protected:
//overriden
virtual void run();
};
#endif
......@@ -60,8 +60,8 @@ This file is part of the PIXHAWK project
MAVLinkGen::MAVLinkGen(int &argc, char* argv[]) : QApplication(argc, argv)
{
this->setApplicationName("MAVLink Generator");
this->setApplicationVersion("v. 0.1.0 (Beta)");
this->setOrganizationName(QLatin1String("OpenMAV Association"));
this->setApplicationVersion("v. 1.0.0 (Beta)");
this->setOrganizationName(QLatin1String("QGroundControl"));
this->setOrganizationDomain("http://qgroundcontrol.org");
QSettings::setDefaultFormat(QSettings::IniFormat);
......
......@@ -29,6 +29,7 @@
#include "QGCToolWidget.h"
#include "QGCMAVLinkLogPlayer.h"
#include "QGCSettingsWidget.h"
#include "QGCMapWidget.h"
#ifdef QGC_OSG_ENABLED
#include "Q3DWidgetFactory.h"
......@@ -352,7 +353,7 @@ void MainWindow::buildCommonWidgets()
// Center widgets
if (!mapWidget)
{
mapWidget = new mapcontrol::OPMapWidget(this);//new MapWidget(this);
mapWidget = new QGCMapWidget(this);
addToCentralWidgetsMenu (mapWidget, "Maps", SLOT(showCentralWidget()),CENTRAL_MAP);
}
......
......@@ -11,9 +11,6 @@ QGCMapWidget::QGCMapWidget(QWidget *parent) :
{
addUAS(uas);
}
UAV->setVisible(true);
UAV->setPos(0, 0);
UAV->show();
......@@ -68,6 +65,9 @@ QGCMapWidget::QGCMapWidget(QWidget *parent) :
Home->SetCoord(pos_lat_lon); // set the HOME position
UAV->SetUAVPos(pos_lat_lon, 0.0); // set the UAV position
GPS->SetUAVPos(pos_lat_lon, 0.0); // set the UAV position
//UAV->setVisible(false);
//UAV->setPos(0, 0);
//UAV->show();
//SetUAVPos(pos_lat_lon, 0.0); // set the UAV position
......@@ -89,6 +89,7 @@ QGCMapWidget::~QGCMapWidget()
*/
void QGCMapWidget::addUAS(UASInterface* uas)
{
qDebug() << "ADDING UAS";
connect(uas, SIGNAL(globalPositionChanged(UASInterface*,double,double,double,quint64)), this, SLOT(updateGlobalPosition(UASInterface*,double,double,double,quint64)));
//connect(uas, SIGNAL(attitudeChanged(UASInterface*,double,double,double,quint64)), this, SLOT(updateAttitude(UASInterface*,double,double,double,quint64)));
//connect(uas, SIGNAL(systemSpecsChanged(int)), this, SLOT(updateSystemSpecs(int)));
......@@ -108,9 +109,13 @@ void QGCMapWidget::updateGlobalPosition(UASInterface* uas, double lat, double lo
Q_UNUSED(usec);
Q_UNUSED(alt); // FIXME Use altitude
UAV->setPos(lat, lon);
UAV->show();
qDebug() << "Updating 2D map position";
static int uasid = 220;
if (uas->getUASID() == uasid)
{
UAV->setPos(lon, lat);
if (!UAV->isVisible()) UAV->show();
qDebug() << "Updating 2D map position" << uas->getUASID() << "LAT:" << lat << "LON:" << lon;
}
// QPointF coordinate;
// coordinate.setX(lon);
......
......@@ -19,14 +19,12 @@ XMLCommProtocolWidget::XMLCommProtocolWidget(QWidget *parent) :
m_ui->setupUi(this);
// Now set syntax highlighter
highlighter = new MAVLinkSyntaxHighlighter(m_ui->xmlTextView->document());
//highlighter = new MAVLinkSyntaxHighlighter(m_ui->xmlTextView->document());
connect(m_ui->selectFileButton, SIGNAL(clicked()), this, SLOT(selectXMLFile()));
connect(m_ui->selectOutputButton, SIGNAL(clicked()), this, SLOT(selectOutputDirectory()));
connect(m_ui->generateButton, SIGNAL(clicked()), this, SLOT(generate()));
connect(m_ui->saveButton, SIGNAL(clicked()), this, SLOT(save()));
this->setVisible(false);
}
void XMLCommProtocolWidget::selectXMLFile()
......@@ -81,6 +79,7 @@ void XMLCommProtocolWidget::setXML(const QString& xml)
}
model = new DomModel(doc, this);
m_ui->xmlTreeView->setModel(model);
m_ui->xmlTreeView->expandAll();
m_ui->xmlTreeView->repaint();
}
......@@ -126,6 +125,9 @@ void XMLCommProtocolWidget::generate()
// Clean log
m_ui->compileLog->clear();
// Check XML validity
if (!m_ui->xmlTextView->syntaxcheck()) return;
MAVLinkXMLParser* parser = new MAVLinkXMLParser(m_ui->fileNameLabel->text().trimmed(), m_ui->outputDirNameLabel->text().trimmed());
connect(parser, SIGNAL(parseState(QString)), m_ui->compileLog, SLOT(appendHtml(QString)));
bool result = parser->generate();
......
......@@ -57,7 +57,7 @@
</widget>
</item>
<item row="0" column="3" rowspan="6">
<widget class="QTextEdit" name="xmlTextView">
<widget class="QGCMAVLinkTextEdit" name="xmlTextView">
<property name="readOnly">
<bool>false</bool>
</property>
......@@ -130,6 +130,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QGCMAVLinkTextEdit</class>
<extends>QTextEdit</extends>
<header location="global">QGCMAVLinkTextEdit.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../../mavground.qrc"/>
</resources>
......
This diff is collapsed.
// Based on: Syntax highlighting from:
// http://code.google.com/p/fop-miniscribus/
// (GPL v2) thanks!
#ifndef QGCMAVLINKTEXTEDIT_H
#define QGCMAVLINKTEXTEDIT_H
#include <QSyntaxHighlighter>
#include <QTextCharFormat>
#include <QColor>
#include <QDomDocument>
#include <QTextEdit>
//class QGCMAVLinkTextEdit : public QTextEdit
//{
//public:
// QGCMAVLinkTextEdit();
//};
class XmlHighlighter : public QSyntaxHighlighter
{
public:
XmlHighlighter(QObject* parent);
XmlHighlighter(QTextDocument* parent);
XmlHighlighter(QTextEdit* parent);
~XmlHighlighter();
enum HighlightType
{
SyntaxChar,
ElementName,
Comment,
AttributeName,
AttributeValue,
Error,
Other
};
void setHighlightColor(HighlightType type, QColor color, bool foreground = true);
void setHighlightFormat(HighlightType type, QTextCharFormat format);
protected:
void highlightBlock(const QString& rstrText);
int processDefaultText(int i, const QString& rstrText);
private:
void init();
QTextCharFormat fmtSyntaxChar;
QTextCharFormat fmtElementName;
QTextCharFormat fmtComment;
QTextCharFormat fmtAttributeName;
QTextCharFormat fmtAttributeValue;
QTextCharFormat fmtError;
QTextCharFormat fmtOther;
enum ParsingState
{
NoState = 0,
ExpectElementNameOrSlash,
ExpectElementName,
ExpectAttributeOrEndOfElement,
ExpectEqual,
ExpectAttributeValue
};
enum BlockState
{
NoBlock = -1,
InComment,
InElement
};
ParsingState state;
};
class QGCMAVLinkTextEdit : public QTextEdit
{
Q_OBJECT
//
public:
QGCMAVLinkTextEdit( QWidget * parent = 0 );
bool Conform();
QDomDocument xml_document();
inline QString text() const
{
return QTextEdit::toPlainText();
}
QMenu *createOwnStandardContextMenu();
protected:
void contextMenuEvent ( QContextMenuEvent * e );
bool event( QEvent *event );
private:
XmlHighlighter *highlight;
signals:
public slots:
bool syntaxcheck();
void setPlainText( const QString txt );
};
#endif // QGCMAVLINKTEXTEDIT_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment