diff --git a/mavlinkgen.pro b/mavlinkgen.pro index fb019cde630c33a8f27682da4fac259c7907ae78..f12b2c871c901a5bb4517601e97eeac916f1448c 100644 --- a/mavlinkgen.pro +++ b/mavlinkgen.pro @@ -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 diff --git a/qgroundcontrol.pri b/qgroundcontrol.pri index 36c57a1bb6634cf7e7522ca536bce6d3690f42ca..e16bb0d80b83fe09bae7f3cd4eef93b13e2e1eb6 100644 --- a/qgroundcontrol.pri +++ b/qgroundcontrol.pri @@ -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 diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 42a5d5808af7f999a09fbe2bd4f767a494ea4fb3..20de2a06e3ef758ba66528dde8b9942dd50e0d80 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -1,10 +1,10 @@ # ------------------------------------------------- # QGroundControl - Micro Air Vehicle Groundstation # Please see our website at -# Author: -# Lorenz Meier -# (c) 2009-2010 PIXHAWK Team -# This file is part of the mav groundstation project +# Maintainer: +# Lorenz Meier +# (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 diff --git a/src/comm/MAVLinkXMLParser.cc b/src/comm/MAVLinkXMLParser.cc index 2ef5ab873b14beba809038a7ae17b66d8202b5a1..0640dc7e98cd45f27b883bc94d981e1e47f9d3cc 100644 --- a/src/comm/MAVLinkXMLParser.cc +++ b/src/comm/MAVLinkXMLParser.cc @@ -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"; diff --git a/src/configuration.h b/src/configuration.h index 32eaf92bd51f00e763eff3b1f435482865a5cef5..aae0cc93955bc6f1f033acba6a533850969387ba 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -1,15 +1,10 @@ #ifndef QGC_CONFIGURATION_H #define QGC_CONFIGURATION_H -#include "mavlink.h" #include /** @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 diff --git a/src/lib/qextserialport/posix_qextserialport.cpp b/src/lib/qextserialport/posix_qextserialport.cpp deleted file mode 100644 index 0aa13887b7985153c719f245ca3d7ccba2ecd004..0000000000000000000000000000000000000000 --- a/src/lib/qextserialport/posix_qextserialport.cpp +++ /dev/null @@ -1,1128 +0,0 @@ - -/*! -\class Posix_QextSerialPort -\version 1.0.0 -\author Stefan Sander -\author Michal Policht - -A cross-platform serial port class. -This class encapsulates the POSIX 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 _TTY_NOWARN_ will also turn off portability warnings. -*/ - -#include -#include -#include "posix_qextserialport.h" - -/*! -\fn Posix_QextSerialPort::Posix_QextSerialPort() -Default constructor. Note that the name of the device 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_OPENBSD_ OpenBSD /dev/tty00, /dev/tty01 -_TTY_LINUX_ Linux /dev/ttyS0, /dev/ttyS1 - Linux /dev/ttyS0, /dev/ttyS1 -\endverbatim - -This constructor assigns the device name to the name of the first port on the specified system. -See the other constructors if you need to open a different port. -*/ -Posix_QextSerialPort::Posix_QextSerialPort(QextSerialBase::QueryMode mode) - : QextSerialBase() -{ - setQueryMode(mode); - init(); -} - -/*! -\fn Posix_QextSerialPort::Posix_QextSerialPort(const Posix_QextSerialPort&) -Copy constructor. -*/ -Posix_QextSerialPort::Posix_QextSerialPort(const Posix_QextSerialPort& s) - : QextSerialBase(s.port) -{ - setOpenMode(s.openMode()); - port = s.port; - Settings.BaudRate=s.Settings.BaudRate; - Settings.DataBits=s.Settings.DataBits; - Settings.Parity=s.Settings.Parity; - Settings.StopBits=s.Settings.StopBits; - Settings.FlowControl=s.Settings.FlowControl; - lastErr=s.lastErr; - - fd = s.fd; - memcpy(&Posix_Timeout, &s.Posix_Timeout, sizeof(struct timeval)); - memcpy(&Posix_Copy_Timeout, &s.Posix_Copy_Timeout, sizeof(struct timeval)); - memcpy(&Posix_CommConfig, &s.Posix_CommConfig, sizeof(struct termios)); -} - -/*! -\fn Posix_QextSerialPort::Posix_QextSerialPort(const QString & name) -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". -*/ -Posix_QextSerialPort::Posix_QextSerialPort(const QString & name, QextSerialBase::QueryMode mode) - : QextSerialBase(name) -{ - setQueryMode(mode); - init(); -} - -/*! -\fn Posix_QextSerialPort::Posix_QextSerialPort(const PortSettings& settings) -Constructs a port with default name and specified settings. -*/ -Posix_QextSerialPort::Posix_QextSerialPort(const PortSettings& settings, QextSerialBase::QueryMode mode) - : QextSerialBase() -{ - setBaudRate(settings.BaudRate); - setDataBits(settings.DataBits); - setParity(settings.Parity); - setStopBits(settings.StopBits); - setFlowControl(settings.FlowControl); - - setTimeout(settings.Timeout_Millisec); - setQueryMode(mode); - init(); -} - -/*! -\fn Posix_QextSerialPort::Posix_QextSerialPort(const QString & name, const PortSettings& settings) -Constructs a port with specified name and settings. -*/ -Posix_QextSerialPort::Posix_QextSerialPort(const QString & name, const PortSettings& settings, QextSerialBase::QueryMode mode) - : QextSerialBase(name) -{ - setBaudRate(settings.BaudRate); - setDataBits(settings.DataBits); - setParity(settings.Parity); - setStopBits(settings.StopBits); - setFlowControl(settings.FlowControl); - - setTimeout(settings.Timeout_Millisec); - setQueryMode(mode); - init(); -} - -/*! -\fn Posix_QextSerialPort& Posix_QextSerialPort::operator=(const Posix_QextSerialPort& s) -Override the = operator. -*/ -Posix_QextSerialPort& Posix_QextSerialPort::operator=(const Posix_QextSerialPort& s) -{ - setOpenMode(s.openMode()); - port = s.port; - Settings.BaudRate=s.Settings.BaudRate; - Settings.DataBits=s.Settings.DataBits; - Settings.Parity=s.Settings.Parity; - Settings.StopBits=s.Settings.StopBits; - Settings.FlowControl=s.Settings.FlowControl; - lastErr=s.lastErr; - - fd = s.fd; - memcpy(& Posix_Timeout, &(s.Posix_Timeout), sizeof(struct timeval)); - memcpy(& Posix_Copy_Timeout, &(s.Posix_Copy_Timeout), sizeof(struct timeval)); - memcpy(& Posix_CommConfig, &(s.Posix_CommConfig), sizeof(struct termios)); - return *this; -} - -void Posix_QextSerialPort::init() -{ - fd = 0; - if (queryMode() == QextSerialBase::EventDriven) - qWarning("POSIX doesn't have event driven mechanism implemented yet"); -} - -/*! -\fn Posix_QextSerialPort::~Posix_QextSerialPort() -Standard destructor. -*/ -Posix_QextSerialPort::~Posix_QextSerialPort() -{ - if (isOpen()) { - close(); - } -} - -/*! -\fn void Posix_QextSerialPort::setBaudRate(BaudRateType baudRate) -Sets the baud rate of the serial port. Note that not all rates are applicable on -all platforms. The following table shows translations of the various baud rate -constants on Windows(including NT/2000) and POSIX platforms. Speeds marked with an * -are speeds that are usable on both Windows and POSIX. - -\note -BAUD76800 may not be supported on all POSIX systems. SGI/IRIX systems do not support -BAUD1800. - -\verbatim - - RATE Windows Speed POSIX Speed - ----------- ------------- ----------- - BAUD50 110 50 - BAUD75 110 75 - *BAUD110 110 110 - BAUD134 110 134.5 - BAUD150 110 150 - BAUD200 110 200 - *BAUD300 300 300 - *BAUD600 600 600 - *BAUD1200 1200 1200 - BAUD1800 1200 1800 - *BAUD2400 2400 2400 - *BAUD4800 4800 4800 - *BAUD9600 9600 9600 - BAUD14400 14400 9600 - *BAUD19200 19200 19200 - *BAUD38400 38400 38400 - BAUD56000 56000 38400 - *BAUD57600 57600 57600 - BAUD76800 57600 76800 - *BAUD115200 115200 115200 - BAUD128000 128000 115200 - BAUD230400 230400 115200 - BAUD256000 256000 115200 - BAUD460800 460800 115200 - BAUD921600 921600 115200 -\endverbatim -*/ -void Posix_QextSerialPort::setBaudRate(BaudRateType baudRate) -{ - LOCK_MUTEX(); - if (Settings.BaudRate!=baudRate) { - switch (baudRate) { - case BAUD14400: - Settings.BaudRate=BAUD9600; - break; - - case BAUD56000: - Settings.BaudRate=BAUD38400; - break; - - case BAUD76800: - -#ifndef B76800 - Settings.BaudRate=BAUD57600; -#else - Settings.BaudRate=baudRate; -#endif - break; - - case BAUD128000: - case BAUD230400: - case BAUD460800: - case BAUD921600: - case BAUD256000: - Settings.BaudRate=BAUD115200; - break; - - default: - Settings.BaudRate=baudRate; - break; - } - } - if (isOpen()) { - switch (baudRate) { - - /*50 baud*/ - case BAUD50: - TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 50 baud operation."); -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B50; -#else - cfsetispeed(&Posix_CommConfig, B50); - cfsetospeed(&Posix_CommConfig, B50); -#endif - break; - - /*75 baud*/ - case BAUD75: - TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 75 baud operation."); -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B75; -#else - cfsetispeed(&Posix_CommConfig, B75); - cfsetospeed(&Posix_CommConfig, B75); -#endif - break; - - /*110 baud*/ - case BAUD110: -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B110; -#else - cfsetispeed(&Posix_CommConfig, B110); - cfsetospeed(&Posix_CommConfig, B110); -#endif - break; - - /*134.5 baud*/ - case BAUD134: - TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 134.5 baud operation."); -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B134; -#else - cfsetispeed(&Posix_CommConfig, B134); - cfsetospeed(&Posix_CommConfig, B134); -#endif - break; - - /*150 baud*/ - case BAUD150: - TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 150 baud operation."); -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B150; -#else - cfsetispeed(&Posix_CommConfig, B150); - cfsetospeed(&Posix_CommConfig, B150); -#endif - break; - - /*200 baud*/ - case BAUD200: - TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 200 baud operation."); -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B200; -#else - cfsetispeed(&Posix_CommConfig, B200); - cfsetospeed(&Posix_CommConfig, B200); -#endif - break; - - /*300 baud*/ - case BAUD300: -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B300; -#else - cfsetispeed(&Posix_CommConfig, B300); - cfsetospeed(&Posix_CommConfig, B300); -#endif - break; - - /*600 baud*/ - case BAUD600: -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B600; -#else - cfsetispeed(&Posix_CommConfig, B600); - cfsetospeed(&Posix_CommConfig, B600); -#endif - break; - - /*1200 baud*/ - case BAUD1200: -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B1200; -#else - cfsetispeed(&Posix_CommConfig, B1200); - cfsetospeed(&Posix_CommConfig, B1200); -#endif - break; - - /*1800 baud*/ - case BAUD1800: - TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows and IRIX do not support 1800 baud operation."); -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B1800; -#else - cfsetispeed(&Posix_CommConfig, B1800); - cfsetospeed(&Posix_CommConfig, B1800); -#endif - break; - - /*2400 baud*/ - case BAUD2400: -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B2400; -#else - cfsetispeed(&Posix_CommConfig, B2400); - cfsetospeed(&Posix_CommConfig, B2400); -#endif - break; - - /*4800 baud*/ - case BAUD4800: -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B4800; -#else - cfsetispeed(&Posix_CommConfig, B4800); - cfsetospeed(&Posix_CommConfig, B4800); -#endif - break; - - /*9600 baud*/ - case BAUD9600: -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B9600; -#else - cfsetispeed(&Posix_CommConfig, B9600); - cfsetospeed(&Posix_CommConfig, B9600); -#endif - break; - - /*14400 baud*/ - case BAUD14400: - TTY_WARNING("Posix_QextSerialPort: POSIX does not support 14400 baud operation. Switching to 9600 baud."); -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B9600; -#else - cfsetispeed(&Posix_CommConfig, B9600); - cfsetospeed(&Posix_CommConfig, B9600); -#endif - break; - - /*19200 baud*/ - case BAUD19200: -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B19200; -#else - cfsetispeed(&Posix_CommConfig, B19200); - cfsetospeed(&Posix_CommConfig, B19200); -#endif - break; - - /*38400 baud*/ - case BAUD38400: -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B38400; -#else - cfsetispeed(&Posix_CommConfig, B38400); - cfsetospeed(&Posix_CommConfig, B38400); -#endif - break; - - /*56000 baud*/ - case BAUD56000: - TTY_WARNING("Posix_QextSerialPort: POSIX does not support 56000 baud operation. Switching to 38400 baud."); -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B38400; -#else - cfsetispeed(&Posix_CommConfig, B38400); - cfsetospeed(&Posix_CommConfig, B38400); -#endif - break; - - /*57600 baud*/ - case BAUD57600: -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B57600; -#else - cfsetispeed(&Posix_CommConfig, B57600); - cfsetospeed(&Posix_CommConfig, B57600); -#endif - break; - - /*76800 baud*/ - case BAUD76800: - TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows and some POSIX systems do not support 76800 baud operation."); -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - -#ifdef B76800 - Posix_CommConfig.c_cflag|=B76800; -#else - TTY_WARNING("Posix_QextSerialPort: Posix_QextSerialPort was compiled without 76800 baud support. Switching to 57600 baud."); - Posix_CommConfig.c_cflag|=B57600; -#endif //B76800 -#else //CBAUD -#ifdef B76800 - cfsetispeed(&Posix_CommConfig, B76800); - cfsetospeed(&Posix_CommConfig, B76800); -#else - TTY_WARNING("Posix_QextSerialPort: Posix_QextSerialPort was compiled without 76800 baud support. Switching to 57600 baud."); - cfsetispeed(&Posix_CommConfig, B57600); - cfsetospeed(&Posix_CommConfig, B57600); -#endif //B76800 -#endif //CBAUD - break; - - /*115200 baud*/ - case BAUD115200: -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B115200; -#else - cfsetispeed(&Posix_CommConfig, B115200); - cfsetospeed(&Posix_CommConfig, B115200); -#endif - break; - - /*128000 baud*/ - case BAUD128000: - TTY_WARNING("Posix_QextSerialPort: POSIX does not support 128000 baud operation. Switching to 115200 baud."); -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B115200; -#else - cfsetispeed(&Posix_CommConfig, B115200); - cfsetospeed(&Posix_CommConfig, B115200); -#endif - break; - - /*256000 baud*/ - case BAUD230400: - case BAUD460800: - case BAUD921600: - case BAUD256000: - TTY_WARNING("Posix_QextSerialPort: POSIX does not support baud rates above 115200 baud. Switching to 115200 baud."); -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B115200; -#else - cfsetispeed(&Posix_CommConfig, B115200); - cfsetospeed(&Posix_CommConfig, B115200); -#endif - break; - } - tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig); - } - UNLOCK_MUTEX(); -} - -/*! -\fn void Posix_QextSerialPort::setDataBits(DataBitsType dataBits) -Sets the number of data bits used by the serial port. Possible values of dataBits are: -\verbatim - DATA_5 5 data bits - DATA_6 6 data bits - DATA_7 7 data bits - DATA_8 8 data bits -\endverbatim - -\note -This function is subject to the following restrictions: -\par - 5 data bits cannot be used with 2 stop bits. -\par - 8 data bits cannot be used with space parity on POSIX systems. - -*/ -void Posix_QextSerialPort::setDataBits(DataBitsType dataBits) -{ - LOCK_MUTEX(); - if (Settings.DataBits!=dataBits) { - if ((Settings.StopBits==STOP_2 && dataBits==DATA_5) || - (Settings.StopBits==STOP_1_5 && dataBits!=DATA_5) || - (Settings.Parity==PAR_SPACE && dataBits==DATA_8)) { - } else { - Settings.DataBits=dataBits; - } - } - if (isOpen()) { - switch(dataBits) { - - /*5 data bits*/ - case DATA_5: - if (Settings.StopBits==STOP_2) { - TTY_WARNING("Posix_QextSerialPort: 5 Data bits cannot be used with 2 stop bits."); - } else { - Settings.DataBits=dataBits; - Posix_CommConfig.c_cflag&=(~CSIZE); - Posix_CommConfig.c_cflag|=CS5; - tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig); - } - break; - - /*6 data bits*/ - case DATA_6: - if (Settings.StopBits==STOP_1_5) { - TTY_WARNING("Posix_QextSerialPort: 6 Data bits cannot be used with 1.5 stop bits."); - } else { - Settings.DataBits=dataBits; - Posix_CommConfig.c_cflag&=(~CSIZE); - Posix_CommConfig.c_cflag|=CS6; - tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig); - } - break; - - /*7 data bits*/ - case DATA_7: - if (Settings.StopBits==STOP_1_5) { - TTY_WARNING("Posix_QextSerialPort: 7 Data bits cannot be used with 1.5 stop bits."); - } else { - Settings.DataBits=dataBits; - Posix_CommConfig.c_cflag&=(~CSIZE); - Posix_CommConfig.c_cflag|=CS7; - tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig); - } - break; - - /*8 data bits*/ - case DATA_8: - if (Settings.StopBits==STOP_1_5) { - TTY_WARNING("Posix_QextSerialPort: 8 Data bits cannot be used with 1.5 stop bits."); - } else { - Settings.DataBits=dataBits; - Posix_CommConfig.c_cflag&=(~CSIZE); - Posix_CommConfig.c_cflag|=CS8; - tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig); - } - break; - } - } - UNLOCK_MUTEX(); -} - -/*! -\fn void Posix_QextSerialPort::setParity(ParityType parity) -Sets the parity associated with the serial port. The possible values of parity are: -\verbatim - PAR_SPACE Space Parity - PAR_MARK Mark Parity - PAR_NONE No Parity - PAR_EVEN Even Parity - PAR_ODD Odd Parity -\endverbatim - -\note -This function is subject to the following limitations: -\par -POSIX systems do not support mark parity. -\par -POSIX systems support space parity only if tricked into doing so, and only with - fewer than 8 data bits. Use space parity very carefully with POSIX systems. - -*/ -void Posix_QextSerialPort::setParity(ParityType parity) -{ - LOCK_MUTEX(); - if (Settings.Parity!=parity) { - if (parity==PAR_MARK || (parity==PAR_SPACE && Settings.DataBits==DATA_8)) { - } else { - Settings.Parity=parity; - } - } - if (isOpen()) { - switch (parity) { - - /*space parity*/ - case PAR_SPACE: - if (Settings.DataBits==DATA_8) { - TTY_PORTABILITY_WARNING("Posix_QextSerialPort: Space parity is only supported in POSIX with 7 or fewer data bits"); - } else { - - /*space parity not directly supported - add an extra data bit to simulate it*/ - Posix_CommConfig.c_cflag&=~(PARENB|CSIZE); - switch(Settings.DataBits) { - case DATA_5: - Settings.DataBits=DATA_6; - Posix_CommConfig.c_cflag|=CS6; - break; - - case DATA_6: - Settings.DataBits=DATA_7; - Posix_CommConfig.c_cflag|=CS7; - break; - - case DATA_7: - Settings.DataBits=DATA_8; - Posix_CommConfig.c_cflag|=CS8; - break; - - case DATA_8: - break; - } - tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig); - } - break; - - /*mark parity - WINDOWS ONLY*/ - case PAR_MARK: - TTY_WARNING("Posix_QextSerialPort: Mark parity is not supported by POSIX."); - break; - - /*no parity*/ - case PAR_NONE: - Posix_CommConfig.c_cflag&=(~PARENB); - tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig); - break; - - /*even parity*/ - case PAR_EVEN: - Posix_CommConfig.c_cflag&=(~PARODD); - Posix_CommConfig.c_cflag|=PARENB; - tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig); - break; - - /*odd parity*/ - case PAR_ODD: - Posix_CommConfig.c_cflag|=(PARENB|PARODD); - tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig); - break; - } - } - UNLOCK_MUTEX(); -} - -/*! -\fn void Posix_QextSerialPort::setStopBits(StopBitsType stopBits) -Sets the number of stop bits used by the serial port. Possible values of stopBits are: -\verbatim - STOP_1 1 stop bit - STOP_1_5 1.5 stop bits - STOP_2 2 stop bits -\endverbatim -\note -This function is subject to the following restrictions: -\par - 2 stop bits cannot be used with 5 data bits. -\par - POSIX does not support 1.5 stop bits. - -*/ -void Posix_QextSerialPort::setStopBits(StopBitsType stopBits) -{ - LOCK_MUTEX(); - if (Settings.StopBits!=stopBits) { - if ((Settings.DataBits==DATA_5 && stopBits==STOP_2) || stopBits==STOP_1_5) {} - else { - Settings.StopBits=stopBits; - } - } - if (isOpen()) { - switch (stopBits) { - - /*one stop bit*/ - case STOP_1: - Settings.StopBits=stopBits; - Posix_CommConfig.c_cflag&=(~CSTOPB); - tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig); - break; - - /*1.5 stop bits*/ - case STOP_1_5: - TTY_WARNING("Posix_QextSerialPort: 1.5 stop bit operation is not supported by POSIX."); - break; - - /*two stop bits*/ - case STOP_2: - if (Settings.DataBits==DATA_5) { - TTY_WARNING("Posix_QextSerialPort: 2 stop bits cannot be used with 5 data bits"); - } else { - Settings.StopBits=stopBits; - Posix_CommConfig.c_cflag|=CSTOPB; - tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig); - } - break; - } - } - UNLOCK_MUTEX(); -} - -/*! -\fn void Posix_QextSerialPort::setFlowControl(FlowType flow) -Sets the flow control used by the port. Possible values of flow are: -\verbatim - FLOW_OFF No flow control - FLOW_HARDWARE Hardware (RTS/CTS) flow control - FLOW_XONXOFF Software (XON/XOFF) flow control -\endverbatim -\note -FLOW_HARDWARE may not be supported on all versions of UNIX. In cases where it is -unsupported, FLOW_HARDWARE is the same as FLOW_OFF. - -*/ -void Posix_QextSerialPort::setFlowControl(FlowType flow) -{ - LOCK_MUTEX(); - if (Settings.FlowControl!=flow) { - Settings.FlowControl=flow; - } - if (isOpen()) { - switch(flow) { - - /*no flow control*/ - case FLOW_OFF: - Posix_CommConfig.c_cflag&=(~CRTSCTS); - Posix_CommConfig.c_iflag&=(~(IXON|IXOFF|IXANY)); - tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig); - break; - - /*software (XON/XOFF) flow control*/ - case FLOW_XONXOFF: - Posix_CommConfig.c_cflag&=(~CRTSCTS); - Posix_CommConfig.c_iflag|=(IXON|IXOFF|IXANY); - tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig); - break; - - case FLOW_HARDWARE: - Posix_CommConfig.c_cflag|=CRTSCTS; - Posix_CommConfig.c_iflag&=(~(IXON|IXOFF|IXANY)); - tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig); - break; - } - } - UNLOCK_MUTEX(); -} - -/*! -\fn void Posix_QextSerialPort::setTimeout(ulong sec); -Sets the read and write timeouts for the port to millisec milliseconds. -Note that this is a per-character timeout, i.e. the port will wait this long for each -individual character, not for the whole read operation. This timeout also applies to the -bytesWaiting() function. - -\note -POSIX does not support millisecond-level control for I/O timeout values. Any -timeout set using this function will be set to the next lowest tenth of a second for -the purposes of detecting read or write timeouts. For example a timeout of 550 milliseconds -will be seen by the class as a timeout of 500 milliseconds for the purposes of reading and -writing the port. However millisecond-level control is allowed by the select() system call, -so for example a 550-millisecond timeout will be seen as 550 milliseconds on POSIX systems for -the purpose of detecting available bytes in the read buffer. - -*/ -void Posix_QextSerialPort::setTimeout(long millisec) -{ - LOCK_MUTEX(); - Settings.Timeout_Millisec = millisec; - Posix_Copy_Timeout.tv_sec = millisec / 1000; - Posix_Copy_Timeout.tv_usec = millisec % 1000; - if (isOpen()) { - if (millisec == -1) - fcntl(fd, F_SETFL, O_NDELAY); - else - //O_SYNC should enable blocking ::write() - //however this seems not working on Linux 2.6.21 (works on OpenBSD 4.2) - fcntl(fd, F_SETFL, O_SYNC); - tcgetattr(fd, & Posix_CommConfig); - Posix_CommConfig.c_cc[VTIME] = millisec/100; - tcsetattr(fd, TCSAFLUSH, & Posix_CommConfig); - } - UNLOCK_MUTEX(); -} - -/*! -\fn bool Posix_QextSerialPort::open(OpenMode mode) -Opens the serial port associated to this class. -This function has no effect if the port associated with the class is already open. -The port is also configured to the current settings, as stored in the Settings structure. -*/ -bool Posix_QextSerialPort::open(OpenMode mode) -{ - LOCK_MUTEX(); - if (mode == QIODevice::NotOpen) - return isOpen(); - if (!isOpen()) { - /*open the port*/ - qDebug("trying to open file"); - //note: linux 2.6.21 seems to ignore O_NDELAY flag - if ((fd = ::open(port.toAscii() ,O_RDWR | O_NOCTTY | O_NDELAY)) != -1) { - qDebug("file opened succesfully"); - - setOpenMode(mode); // Flag the port as opened - tcgetattr(fd, &old_termios); // Save the old termios - Posix_CommConfig = old_termios; // Make a working copy - cfmakeraw(&Posix_CommConfig); // Enable raw access - - /*set up other port settings*/ - Posix_CommConfig.c_cflag|=CREAD|CLOCAL; - Posix_CommConfig.c_lflag&=(~(ICANON|ECHO|ECHOE|ECHOK|ECHONL|ISIG)); - Posix_CommConfig.c_iflag&=(~(INPCK|IGNPAR|PARMRK|ISTRIP|ICRNL|IXANY)); - Posix_CommConfig.c_oflag&=(~OPOST); - Posix_CommConfig.c_cc[VMIN]= 0; -#ifdef _POSIX_VDISABLE // Is a disable character available on this system? - // Some systems allow for per-device disable-characters, so get the - // proper value for the configured device - const long vdisable = fpathconf(fd, _PC_VDISABLE); - Posix_CommConfig.c_cc[VINTR] = vdisable; - Posix_CommConfig.c_cc[VQUIT] = vdisable; - Posix_CommConfig.c_cc[VSTART] = vdisable; - Posix_CommConfig.c_cc[VSTOP] = vdisable; - Posix_CommConfig.c_cc[VSUSP] = vdisable; -#endif //_POSIX_VDISABLE - setBaudRate(Settings.BaudRate); - setDataBits(Settings.DataBits); - setParity(Settings.Parity); - setStopBits(Settings.StopBits); - setFlowControl(Settings.FlowControl); - setTimeout(Settings.Timeout_Millisec); - tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig); - } else { - qDebug("could not open file: %s", strerror(errno)); - } - } - UNLOCK_MUTEX(); - return isOpen(); -} - -/*! -\fn void Posix_QextSerialPort::close() -Closes a serial port. This function has no effect if the serial port associated with the class -is not currently open. -*/ -void Posix_QextSerialPort::close() -{ - LOCK_MUTEX(); - if( isOpen() ) { - // Force a flush and then restore the original termios - flush(); - // Using both TCSAFLUSH and TCSANOW here discards any pending input - tcsetattr(fd, TCSAFLUSH | TCSANOW, &old_termios); // Restore termios - // Be a good QIODevice and call QIODevice::close() before POSIX close() - // so the aboutToClose() signal is emitted at the proper time - QIODevice::close(); // Flag the device as closed - // QIODevice::close() doesn't actually close the port, so do that here - ::close(fd); - } - UNLOCK_MUTEX(); -} - -/*! -\fn void Posix_QextSerialPort::flush() -Flushes all pending I/O to the serial port. This function has no effect if the serial port -associated with the class is not currently open. -*/ -void Posix_QextSerialPort::flush() -{ - LOCK_MUTEX(); - if (isOpen()) - tcflush(fd, TCIOFLUSH); - UNLOCK_MUTEX(); -} - -/*! -\fn qint64 Posix_QextSerialPort::size() const -This function will return the number of bytes waiting in the receive queue of the serial port. -It is included primarily to provide a complete QIODevice interface, and will not record errors -in the lastErr member (because it is const). This function is also not thread-safe - in -multithreading situations, use Posix_QextSerialPort::bytesWaiting() instead. -*/ -qint64 Posix_QextSerialPort::size() const -{ - int numBytes; - if (ioctl(fd, FIONREAD, &numBytes)<0) { - numBytes = 0; - } - return (qint64)numBytes; -} - -/*! -\fn qint64 Posix_QextSerialPort::bytesAvailable() -Returns the number of bytes waiting in the port's receive queue. This function will return 0 if -the port is not currently open, or -1 on error. -*/ -qint64 Posix_QextSerialPort::bytesAvailable() const -{ - LOCK_MUTEX(); - if (isOpen()) { - int bytesQueued; - if (ioctl(fd, FIONREAD, &bytesQueued) == -1) { - UNLOCK_MUTEX(); - return (qint64)-1; - } - UNLOCK_MUTEX(); - return bytesQueued + QIODevice::bytesAvailable(); - } - UNLOCK_MUTEX(); - return 0; -} - -/*! -\fn void Posix_QextSerialPort::ungetChar(char) -This function is included to implement the full QIODevice interface, and currently has no -purpose within this class. This function is meaningless on an unbuffered device and currently -only prints a warning message to that effect. -*/ -void Posix_QextSerialPort::ungetChar(char) -{ - /*meaningless on unbuffered sequential device - return error and print a warning*/ - TTY_WARNING("Posix_QextSerialPort: ungetChar() called on an unbuffered sequential device - operation is meaningless"); -} - -/*! -\fn void Posix_QextSerialPort::translateError(ulong error) -Translates a system-specific error code to a QextSerialPort error code. Used internally. -*/ -void Posix_QextSerialPort::translateError(ulong error) -{ - switch (error) { - case EBADF: - case ENOTTY: - lastErr=E_INVALID_FD; - break; - - case EINTR: - lastErr=E_CAUGHT_NON_BLOCKED_SIGNAL; - break; - - case ENOMEM: - lastErr=E_NO_MEMORY; - break; - } -} - -/*! -\fn void Posix_QextSerialPort::setDtr(bool set) -Sets DTR line to the requested state (high by default). This function will have no effect if -the port associated with the class is not currently open. -*/ -void Posix_QextSerialPort::setDtr(bool set) -{ - LOCK_MUTEX(); - if (isOpen()) { - int status; - ioctl(fd, TIOCMGET, &status); - if (set) { - status|=TIOCM_DTR; - } else { - status&=~TIOCM_DTR; - } - ioctl(fd, TIOCMSET, &status); - } - UNLOCK_MUTEX(); -} - -/*! -\fn void Posix_QextSerialPort::setRts(bool set) -Sets RTS line to the requested state (high by default). This function will have no effect if -the port associated with the class is not currently open. -*/ -void Posix_QextSerialPort::setRts(bool set) -{ - LOCK_MUTEX(); - if (isOpen()) { - int status; - ioctl(fd, TIOCMGET, &status); - if (set) { - status|=TIOCM_RTS; - } else { - status&=~TIOCM_RTS; - } - ioctl(fd, TIOCMSET, &status); - } - UNLOCK_MUTEX(); -} - -/*! -\fn unsigned long Posix_QextSerialPort::lineStatus() -returns the line status as stored by the port function. This function will retrieve the states -of the following lines: DCD, CTS, DSR, and RI. On POSIX systems, the following additional lines -can be monitored: DTR, RTS, Secondary TXD, and Secondary RXD. The value returned is an unsigned -long with specific bits indicating which lines are high. The following constants should be used -to examine the states of individual lines: - -\verbatim -Mask Line ------- ---- -LS_CTS CTS -LS_DSR DSR -LS_DCD DCD -LS_RI RI -LS_RTS RTS (POSIX only) -LS_DTR DTR (POSIX only) -LS_ST Secondary TXD (POSIX only) -LS_SR Secondary RXD (POSIX only) -\endverbatim - -This function will return 0 if the port associated with the class is not currently open. -*/ -unsigned long Posix_QextSerialPort::lineStatus() -{ - unsigned long Status=0, Temp=0; - LOCK_MUTEX(); - if (isOpen()) { - ioctl(fd, TIOCMGET, &Temp); - if (Temp&TIOCM_CTS) { - Status|=LS_CTS; - } - if (Temp&TIOCM_DSR) { - Status|=LS_DSR; - } - if (Temp&TIOCM_RI) { - Status|=LS_RI; - } - if (Temp&TIOCM_CD) { - Status|=LS_DCD; - } - if (Temp&TIOCM_DTR) { - Status|=LS_DTR; - } - if (Temp&TIOCM_RTS) { - Status|=LS_RTS; - } - if (Temp&TIOCM_ST) { - Status|=LS_ST; - } - if (Temp&TIOCM_SR) { - Status|=LS_SR; - } - } - UNLOCK_MUTEX(); - return Status; -} - -/*! -\fn qint64 Posix_QextSerialPort::readData(char * data, qint64 maxSize) -Reads a block of data from the serial port. This function will read at most maxSize bytes from -the serial port and place them in the buffer pointed to by data. Return value is the number of -bytes actually read, or -1 on error. - -\warning before calling this function ensure that serial port associated with this class -is currently open (use isOpen() function to check if port is open). -*/ -qint64 Posix_QextSerialPort::readData(char * data, qint64 maxSize) -{ - LOCK_MUTEX(); - int retVal = 0; - retVal = ::read(fd, data, maxSize); - if (retVal == -1) - lastErr = E_READ_FAILED; - UNLOCK_MUTEX(); - - return retVal; -} - -/*! -\fn qint64 Posix_QextSerialPort::writeData(const char * data, qint64 maxSize) -Writes a block of data to the serial port. This function will write maxSize bytes -from the buffer pointed to by data to the serial port. Return value is the number -of bytes actually written, or -1 on error. - -\warning before calling this function ensure that serial port associated with this class -is currently open (use isOpen() function to check if port is open). -*/ -qint64 Posix_QextSerialPort::writeData(const char * data, qint64 maxSize) -{ - LOCK_MUTEX(); - int retVal = 0; - retVal = ::write(fd, data, maxSize); - if (retVal == -1) { - lastErr = E_WRITE_FAILED; - } - UNLOCK_MUTEX(); - - return (qint64)retVal; -} diff --git a/src/lib/qextserialport/posix_qextserialport.h b/src/lib/qextserialport/posix_qextserialport.h deleted file mode 100644 index 68cb34deebec6cc525fe434d284dcc78eb456a81..0000000000000000000000000000000000000000 --- a/src/lib/qextserialport/posix_qextserialport.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef _POSIX_QEXTSERIALPORT_H_ -#define _POSIX_QEXTSERIALPORT_H_ - -#include -#include -#include -#include -#include -#include -#include -#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 diff --git a/src/lib/qextserialport/qextserialbase.cpp b/src/lib/qextserialport/qextserialbase.cpp deleted file mode 100644 index 42f3af62b08927d406568e4f207158b45400f17b..0000000000000000000000000000000000000000 --- a/src/lib/qextserialport/qextserialbase.cpp +++ /dev/null @@ -1,230 +0,0 @@ -#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; -} diff --git a/src/lib/qextserialport/qextserialbase.h b/src/lib/qextserialport/qextserialbase.h deleted file mode 100644 index 66568f7744a73239a15106675da058ee4132111d..0000000000000000000000000000000000000000 --- a/src/lib/qextserialport/qextserialbase.h +++ /dev/null @@ -1,255 +0,0 @@ -#ifndef _QEXTSERIALBASE_H_ -#define _QEXTSERIALBASE_H_ - -#include -#include -#include -#include - -/*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 diff --git a/src/lib/qextserialport/qextserialenumerator.cpp b/src/lib/qextserialport/qextserialenumerator.cpp deleted file mode 100644 index f322075e74948ce7c459c0b1676f45b6d627a12a..0000000000000000000000000000000000000000 --- a/src/lib/qextserialport/qextserialenumerator.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/** - * @file qextserialenumerator.cpp - * @author MichaƂ Policht - * @see QextSerialEnumerator - */ - -#include "qextserialenumerator.h" - -#ifdef _TTY_WIN_ - -#include -#include - - -//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 & 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 QextSerialEnumerator::getPorts() -{ - QList 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; -} diff --git a/src/lib/qextserialport/qextserialenumerator.h b/src/lib/qextserialport/qextserialenumerator.h deleted file mode 100644 index 5a99b10b006891ee528688818cdbfe17f841298d..0000000000000000000000000000000000000000 --- a/src/lib/qextserialport/qextserialenumerator.h +++ /dev/null @@ -1,75 +0,0 @@ -/*! - * \file qextserialenumerator.h - * \author Michal Policht - * \see QextSerialEnumerator - */ - -#ifndef _QEXTSERIALENUMERATOR_H_ -#define _QEXTSERIALENUMERATOR_H_ - - -#include -#include - -#ifdef _TTY_WIN_ -#include -#include -#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 - * The Code Project (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 & infoList); -#endif /*_TTY_WIN_*/ - -public: - /*! - * Get list of ports. - * \return list of ports currently available in the system. - */ - static QList getPorts(); -}; - -#endif /*_QEXTSERIALENUMERATOR_H_*/ diff --git a/src/lib/qextserialport/qextserialport.cpp b/src/lib/qextserialport/qextserialport.cpp deleted file mode 100644 index 577fa35cc39979d4a7187cfcc5ec0928a3ab8c43..0000000000000000000000000000000000000000 --- a/src/lib/qextserialport/qextserialport.cpp +++ /dev/null @@ -1,106 +0,0 @@ - -/*! -\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 -#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 - 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() -{} diff --git a/src/lib/qextserialport/qextserialport.h b/src/lib/qextserialport/qextserialport.h deleted file mode 100644 index 4881ec8e642f9926d4bee37c4236bd14a8afbcb4..0000000000000000000000000000000000000000 --- a/src/lib/qextserialport/qextserialport.h +++ /dev/null @@ -1,33 +0,0 @@ - -#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 diff --git a/src/lib/qextserialport/qextserialport.pri b/src/lib/qextserialport/qextserialport.pri deleted file mode 100644 index 0265e399c002af5480bf49332ccc3ad833723b8a..0000000000000000000000000000000000000000 --- a/src/lib/qextserialport/qextserialport.pri +++ /dev/null @@ -1,22 +0,0 @@ -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 diff --git a/src/lib/qextserialport/win_qextserialport.cpp b/src/lib/qextserialport/win_qextserialport.cpp deleted file mode 100644 index f2115c8458e5434f91565091d348668ef3a8b11d..0000000000000000000000000000000000000000 --- a/src/lib/qextserialport/win_qextserialport.cpp +++ /dev/null @@ -1,1071 +0,0 @@ -//#include -//#include -//#include -//#include -#include -#include "win_qextserialport.h" - - -/*! -\fn Win_QextSerialPort::Win_QextSerialPort() -Default constructor. Note that the name of the device used by a Win_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 - Linux /dev/ttyS0, /dev/ttyS1 -\endverbatim - -This constructor associates the object with the first port on the system, e.g. COM1 for Windows -platforms. See the other constructor if you need a port other than the first. -*/ -Win_QextSerialPort::Win_QextSerialPort(QextSerialBase::QueryMode mode): - QextSerialBase() -{ - Win_Handle=INVALID_HANDLE_VALUE; - setQueryMode(mode); - init(); -} - -/*!Win_QextSerialPort::Win_QextSerialPort(const Win_QextSerialPort&) -Copy constructor. -*/ -Win_QextSerialPort::Win_QextSerialPort(const Win_QextSerialPort& s): - QextSerialBase(s.port) -{ - Win_Handle=INVALID_HANDLE_VALUE; - _queryMode = s._queryMode; - _bytesToWrite = s._bytesToWrite; - bytesToWriteLock = new QReadWriteLock; - overlapThread = new Win_QextSerialThread(this); - memcpy(& overlap, & s.overlap, sizeof(OVERLAPPED)); - memcpy(& overlapWrite, & s.overlapWrite, sizeof(OVERLAPPED)); - setOpenMode(s.openMode()); - lastErr=s.lastErr; - port = s.port; - Settings.FlowControl=s.Settings.FlowControl; - Settings.Parity=s.Settings.Parity; - Settings.DataBits=s.Settings.DataBits; - Settings.StopBits=s.Settings.StopBits; - Settings.BaudRate=s.Settings.BaudRate; - Win_Handle=s.Win_Handle; - memcpy(&Win_CommConfig, &s.Win_CommConfig, sizeof(COMMCONFIG)); - memcpy(&Win_CommTimeouts, &s.Win_CommTimeouts, sizeof(COMMTIMEOUTS)); - if (s.overlapThread->isRunning()) - overlapThread->start(); -} - -/*! -\fn Win_QextSerialPort::Win_QextSerialPort(const QString & name) -Constructs a serial port attached to the port specified by devName. -devName is the name of the device, which is windowsystem-specific, -e.g."COM2" or "/dev/ttyS0". -*/ -Win_QextSerialPort::Win_QextSerialPort(const QString & name, QextSerialBase::QueryMode mode): - QextSerialBase(name) -{ - Win_Handle=INVALID_HANDLE_VALUE; - setQueryMode(mode); - init(); -} - -/*! -\fn Win_QextSerialPort::Win_QextSerialPort(const PortSettings& settings) -Constructs a port with default name and specified settings. -*/ -Win_QextSerialPort::Win_QextSerialPort(const PortSettings& settings, QextSerialBase::QueryMode mode): - QextSerialBase() -{ - Win_Handle=INVALID_HANDLE_VALUE; - setBaudRate(settings.BaudRate); - setDataBits(settings.DataBits); - setStopBits(settings.StopBits); - setParity(settings.Parity); - setFlowControl(settings.FlowControl); - setTimeout(settings.Timeout_Millisec); - setQueryMode(mode); - init(); -} - -/*! -\fn Win_QextSerialPort::Win_QextSerialPort(const QString & name, const PortSettings& settings) -Constructs a port with specified name and settings. -*/ -Win_QextSerialPort::Win_QextSerialPort(const QString & name, const PortSettings& settings, QextSerialBase::QueryMode mode): - QextSerialBase(name) -{ - Win_Handle=INVALID_HANDLE_VALUE; - setPortName(name); - setBaudRate(settings.BaudRate); - setDataBits(settings.DataBits); - setStopBits(settings.StopBits); - setParity(settings.Parity); - setFlowControl(settings.FlowControl); - setTimeout(settings.Timeout_Millisec); - setQueryMode(mode); - init(); -} - -void Win_QextSerialPort::init() -{ - _bytesToWrite = 0; - overlap.Internal = 0; - overlap.InternalHigh = 0; - overlap.Offset = 0; - overlap.OffsetHigh = 0; - overlap.hEvent = CreateEvent(NULL, true, false, NULL); - overlapThread = new Win_QextSerialThread(this); - bytesToWriteLock = new QReadWriteLock; -} - -/*! -\fn Win_QextSerialPort::~Win_QextSerialPort() -Standard destructor. -*/ -Win_QextSerialPort::~Win_QextSerialPort() -{ - if (isOpen()) { - close(); - } - CloseHandle(overlap.hEvent); - delete overlapThread; - delete bytesToWriteLock; -} - -/*! -\fn Win_QextSerialPort& Win_QextSerialPort::operator=(const Win_QextSerialPort& s) -overrides the = operator -*/ -Win_QextSerialPort& Win_QextSerialPort::operator=(const Win_QextSerialPort& s) -{ - setOpenMode(s.openMode()); - _queryMode = s._queryMode; - _bytesToWrite = s._bytesToWrite; - bytesToWriteLock = new QReadWriteLock; - overlapThread = new Win_QextSerialThread(this); - memcpy(& overlap, & s.overlap, sizeof(OVERLAPPED)); - memcpy(& overlapWrite, & s.overlapWrite, sizeof(OVERLAPPED)); - lastErr=s.lastErr; - port = s.port; - Settings.FlowControl=s.Settings.FlowControl; - Settings.Parity=s.Settings.Parity; - Settings.DataBits=s.Settings.DataBits; - Settings.StopBits=s.Settings.StopBits; - Settings.BaudRate=s.Settings.BaudRate; - Win_Handle=s.Win_Handle; - memcpy(&Win_CommConfig, &s.Win_CommConfig, sizeof(COMMCONFIG)); - memcpy(&Win_CommTimeouts, &s.Win_CommTimeouts, sizeof(COMMTIMEOUTS)); - if (s.overlapThread->isRunning()) - overlapThread->start(); - return *this; -} - - -/*! -\fn bool Win_QextSerialPort::open(OpenMode mode) -Opens a serial port. Note that this function does not specify which device to open. If you need -to open a device by name, see Win_QextSerialPort::open(const char*). This function has no effect -if the port associated with the class is already open. The port is also configured to the current -settings, as stored in the Settings structure. -*/ -bool Win_QextSerialPort::open(OpenMode mode) -{ - unsigned long confSize = sizeof(COMMCONFIG); - Win_CommConfig.dwSize = confSize; - DWORD dwFlagsAndAttributes = 0; - if (queryMode() == QextSerialBase::EventDriven) - dwFlagsAndAttributes += FILE_FLAG_OVERLAPPED; - - LOCK_MUTEX(); - if (mode == QIODevice::NotOpen) - return isOpen(); - if (!isOpen()) { - /*open the port*/ - Win_Handle=CreateFileA(port.toAscii(), GENERIC_READ|GENERIC_WRITE, - FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, dwFlagsAndAttributes, NULL); - if (Win_Handle!=INVALID_HANDLE_VALUE) { - /*configure port settings*/ - GetCommConfig(Win_Handle, &Win_CommConfig, &confSize); - GetCommState(Win_Handle, &(Win_CommConfig.dcb)); - - /*set up parameters*/ - Win_CommConfig.dcb.fBinary=TRUE; - Win_CommConfig.dcb.fInX=FALSE; - Win_CommConfig.dcb.fOutX=FALSE; - Win_CommConfig.dcb.fAbortOnError=FALSE; - Win_CommConfig.dcb.fNull=FALSE; - setBaudRate(Settings.BaudRate); - setDataBits(Settings.DataBits); - setStopBits(Settings.StopBits); - setParity(Settings.Parity); - setFlowControl(Settings.FlowControl); - setTimeout(Settings.Timeout_Millisec); - SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG)); - - //init event driven approach - if (queryMode() == QextSerialBase::EventDriven) { - Win_CommTimeouts.ReadIntervalTimeout = MAXDWORD; - Win_CommTimeouts.ReadTotalTimeoutMultiplier = 0; - Win_CommTimeouts.ReadTotalTimeoutConstant = 0; - Win_CommTimeouts.WriteTotalTimeoutMultiplier = 0; - Win_CommTimeouts.WriteTotalTimeoutConstant = 0; - SetCommTimeouts(Win_Handle, &Win_CommTimeouts); - if (!SetCommMask( Win_Handle, EV_TXEMPTY | EV_RXCHAR | EV_DSR)) { - qWarning("failed to set Comm Mask. Error code: %ld", GetLastError()); - UNLOCK_MUTEX(); - return false; - } - overlapThread->start(); - } - QIODevice::open(mode); - } - } else { - UNLOCK_MUTEX(); - return false; - } - UNLOCK_MUTEX(); - return isOpen(); -} - -/*! -\fn void Win_QextSerialPort::close() -Closes a serial port. This function has no effect if the serial port associated with the class -is not currently open. -*/ -void Win_QextSerialPort::close() -{ - LOCK_MUTEX(); - - if (isOpen()) { - flush(); - if (overlapThread->isRunning()) { - overlapThread->stop(); - if (QThread::currentThread() != overlapThread) - overlapThread->wait(); - } - if (CloseHandle(Win_Handle)) - Win_Handle = INVALID_HANDLE_VALUE; - _bytesToWrite = 0; - QIODevice::close(); - } - - UNLOCK_MUTEX(); -} - -/*! -\fn void Win_QextSerialPort::flush() -Flushes all pending I/O to the serial port. This function has no effect if the serial port -associated with the class is not currently open. -*/ -void Win_QextSerialPort::flush() -{ - LOCK_MUTEX(); - if (isOpen()) { - FlushFileBuffers(Win_Handle); - } - UNLOCK_MUTEX(); -} - -/*! -\fn qint64 Win_QextSerialPort::size() const -This function will return the number of bytes waiting in the receive queue of the serial port. -It is included primarily to provide a complete QIODevice interface, and will not record errors -in the lastErr member (because it is const). This function is also not thread-safe - in -multithreading situations, use Win_QextSerialPort::bytesAvailable() instead. -*/ -qint64 Win_QextSerialPort::size() const -{ - int availBytes; - COMSTAT Win_ComStat; - DWORD Win_ErrorMask=0; - ClearCommError(Win_Handle, &Win_ErrorMask, &Win_ComStat); - availBytes = Win_ComStat.cbInQue; - return (qint64)availBytes; -} - -/*! -\fn qint64 Win_QextSerialPort::bytesAvailable() -Returns the number of bytes waiting in the port's receive queue. This function will return 0 if -the port is not currently open, or -1 on error. -*/ -qint64 Win_QextSerialPort::bytesAvailable() const -{ - LOCK_MUTEX(); - if (isOpen()) { - DWORD Errors; - COMSTAT Status; - if (ClearCommError(Win_Handle, &Errors, &Status)) { - UNLOCK_MUTEX(); - return Status.cbInQue + QIODevice::bytesAvailable(); - } - UNLOCK_MUTEX(); - return (qint64)-1; - } - UNLOCK_MUTEX(); - return 0; -} - -/*! -\fn void Win_QextSerialPort::translateError(ulong error) -Translates a system-specific error code to a QextSerialPort error code. Used internally. -*/ -void Win_QextSerialPort::translateError(ulong error) -{ - if (error&CE_BREAK) { - lastErr=E_BREAK_CONDITION; - } else if (error&CE_FRAME) { - lastErr=E_FRAMING_ERROR; - } else if (error&CE_IOE) { - lastErr=E_IO_ERROR; - } else if (error&CE_MODE) { - lastErr=E_INVALID_FD; - } else if (error&CE_OVERRUN) { - lastErr=E_BUFFER_OVERRUN; - } else if (error&CE_RXPARITY) { - lastErr=E_RECEIVE_PARITY_ERROR; - } else if (error&CE_RXOVER) { - lastErr=E_RECEIVE_OVERFLOW; - } else if (error&CE_TXFULL) { - lastErr=E_TRANSMIT_OVERFLOW; - } -} - -/*! -\fn qint64 Win_QextSerialPort::readData(char *data, qint64 maxSize) -Reads a block of data from the serial port. This function will read at most maxlen bytes from -the serial port and place them in the buffer pointed to by data. Return value is the number of -bytes actually read, or -1 on error. - -\warning before calling this function ensure that serial port associated with this class -is currently open (use isOpen() function to check if port is open). -*/ -qint64 Win_QextSerialPort::readData(char *data, qint64 maxSize) -{ - DWORD retVal; - - LOCK_MUTEX(); - - retVal = 0; - if (queryMode() == QextSerialBase::EventDriven) { - OVERLAPPED overlapRead; - overlapRead.Internal = 0; - overlapRead.InternalHigh = 0; - overlapRead.Offset = 0; - overlapRead.OffsetHigh = 0; - overlapRead.hEvent = CreateEvent(NULL, true, false, NULL); - if (!ReadFile(Win_Handle, (void*)data, (DWORD)maxSize, & retVal, & overlapRead)) { - if (GetLastError() == ERROR_IO_PENDING) - GetOverlappedResult(Win_Handle, & overlapRead, & retVal, true); - else { - lastErr = E_READ_FAILED; - retVal = (DWORD)-1; - } - } - CloseHandle(overlapRead.hEvent); - } else if (!ReadFile(Win_Handle, (void*)data, (DWORD)maxSize, & retVal, NULL)) { - lastErr = E_READ_FAILED; - retVal = (DWORD)-1; - } - - UNLOCK_MUTEX(); - - return (qint64)retVal; -} - -/*! -\fn qint64 Win_QextSerialPort::writeData(const char *data, qint64 maxSize) -Writes a block of data to the serial port. This function will write len bytes -from the buffer pointed to by data to the serial port. Return value is the number -of bytes actually written, or -1 on error. - -\warning before calling this function ensure that serial port associated with this class -is currently open (use isOpen() function to check if port is open). -*/ -qint64 Win_QextSerialPort::writeData(const char *data, qint64 maxSize) -{ - DWORD retVal; - - LOCK_MUTEX(); - - retVal = 0; - if (queryMode() == QextSerialBase::EventDriven) { - bytesToWriteLock->lockForWrite(); - _bytesToWrite += maxSize; - bytesToWriteLock->unlock(); - overlapWrite.Internal = 0; - overlapWrite.InternalHigh = 0; - overlapWrite.Offset = 0; - overlapWrite.OffsetHigh = 0; - overlapWrite.hEvent = CreateEvent(NULL, true, false, NULL); - if (!WriteFile(Win_Handle, (void*)data, (DWORD)maxSize, & retVal, & overlapWrite)) { - lastErr = E_WRITE_FAILED; - retVal = (DWORD)-1; - } else - retVal = maxSize; - } else if (!WriteFile(Win_Handle, (void*)data, (DWORD)maxSize, & retVal, NULL)) { - lastErr = E_WRITE_FAILED; - retVal = (DWORD)-1; - } - - UNLOCK_MUTEX(); - - return (qint64)retVal; -} - -/*! -\fn void Win_QextSerialPort::ungetChar(char c) -This function is included to implement the full QIODevice interface, and currently has no -purpose within this class. This function is meaningless on an unbuffered device and currently -only prints a warning message to that effect. -*/ -void Win_QextSerialPort::ungetChar(char c) -{ - - /*meaningless on unbuffered sequential device - return error and print a warning*/ - TTY_WARNING("Win_QextSerialPort: ungetChar() called on an unbuffered sequential device - operation is meaningless"); -} - -/*! -\fn void Win_QextSerialPort::setFlowControl(FlowType flow) -Sets the flow control used by the port. Possible values of flow are: -\verbatim - FLOW_OFF No flow control - FLOW_HARDWARE Hardware (RTS/CTS) flow control - FLOW_XONXOFF Software (XON/XOFF) flow control -\endverbatim -*/ -void Win_QextSerialPort::setFlowControl(FlowType flow) -{ - LOCK_MUTEX(); - if (Settings.FlowControl!=flow) { - Settings.FlowControl=flow; - } - if (isOpen()) { - switch(flow) { - - /*no flow control*/ - case FLOW_OFF: - Win_CommConfig.dcb.fOutxCtsFlow=FALSE; - Win_CommConfig.dcb.fRtsControl=RTS_CONTROL_DISABLE; - Win_CommConfig.dcb.fInX=FALSE; - Win_CommConfig.dcb.fOutX=FALSE; - SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG)); - break; - - /*software (XON/XOFF) flow control*/ - case FLOW_XONXOFF: - Win_CommConfig.dcb.fOutxCtsFlow=FALSE; - Win_CommConfig.dcb.fRtsControl=RTS_CONTROL_DISABLE; - Win_CommConfig.dcb.fInX=TRUE; - Win_CommConfig.dcb.fOutX=TRUE; - SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG)); - break; - - case FLOW_HARDWARE: - Win_CommConfig.dcb.fOutxCtsFlow=TRUE; - Win_CommConfig.dcb.fRtsControl=RTS_CONTROL_HANDSHAKE; - Win_CommConfig.dcb.fInX=FALSE; - Win_CommConfig.dcb.fOutX=FALSE; - SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG)); - break; - } - } - UNLOCK_MUTEX(); -} - -/*! -\fn void Win_QextSerialPort::setParity(ParityType parity) -Sets the parity associated with the serial port. The possible values of parity are: -\verbatim - PAR_SPACE Space Parity - PAR_MARK Mark Parity - PAR_NONE No Parity - PAR_EVEN Even Parity - PAR_ODD Odd Parity -\endverbatim -*/ -void Win_QextSerialPort::setParity(ParityType parity) -{ - LOCK_MUTEX(); - if (Settings.Parity!=parity) { - Settings.Parity=parity; - } - if (isOpen()) { - Win_CommConfig.dcb.Parity=(unsigned char)parity; - switch (parity) { - - /*space parity*/ - case PAR_SPACE: - if (Settings.DataBits==DATA_8) { - TTY_PORTABILITY_WARNING("Win_QextSerialPort Portability Warning: Space parity with 8 data bits is not supported by POSIX systems."); - } - Win_CommConfig.dcb.fParity=TRUE; - break; - - /*mark parity - WINDOWS ONLY*/ - case PAR_MARK: - TTY_PORTABILITY_WARNING("Win_QextSerialPort Portability Warning: Mark parity is not supported by POSIX systems"); - Win_CommConfig.dcb.fParity=TRUE; - break; - - /*no parity*/ - case PAR_NONE: - Win_CommConfig.dcb.fParity=FALSE; - break; - - /*even parity*/ - case PAR_EVEN: - Win_CommConfig.dcb.fParity=TRUE; - break; - - /*odd parity*/ - case PAR_ODD: - Win_CommConfig.dcb.fParity=TRUE; - break; - } - SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG)); - } - UNLOCK_MUTEX(); -} - -/*! -\fn void Win_QextSerialPort::setDataBits(DataBitsType dataBits) -Sets the number of data bits used by the serial port. Possible values of dataBits are: -\verbatim - DATA_5 5 data bits - DATA_6 6 data bits - DATA_7 7 data bits - DATA_8 8 data bits -\endverbatim - -\note -This function is subject to the following restrictions: -\par - 5 data bits cannot be used with 2 stop bits. -\par - 1.5 stop bits can only be used with 5 data bits. -\par - 8 data bits cannot be used with space parity on POSIX systems. - -*/ -void Win_QextSerialPort::setDataBits(DataBitsType dataBits) -{ - LOCK_MUTEX(); - if (Settings.DataBits!=dataBits) { - if ((Settings.StopBits==STOP_2 && dataBits==DATA_5) || - (Settings.StopBits==STOP_1_5 && dataBits!=DATA_5)) { - } else { - Settings.DataBits=dataBits; - } - } - if (isOpen()) { - switch(dataBits) { - - /*5 data bits*/ - case DATA_5: - if (Settings.StopBits==STOP_2) { - TTY_WARNING("Win_QextSerialPort: 5 Data bits cannot be used with 2 stop bits."); - } else { - Win_CommConfig.dcb.ByteSize=5; - SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG)); - } - break; - - /*6 data bits*/ - case DATA_6: - if (Settings.StopBits==STOP_1_5) { - TTY_WARNING("Win_QextSerialPort: 6 Data bits cannot be used with 1.5 stop bits."); - } else { - Win_CommConfig.dcb.ByteSize=6; - SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG)); - } - break; - - /*7 data bits*/ - case DATA_7: - if (Settings.StopBits==STOP_1_5) { - TTY_WARNING("Win_QextSerialPort: 7 Data bits cannot be used with 1.5 stop bits."); - } else { - Win_CommConfig.dcb.ByteSize=7; - SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG)); - } - break; - - /*8 data bits*/ - case DATA_8: - if (Settings.StopBits==STOP_1_5) { - TTY_WARNING("Win_QextSerialPort: 8 Data bits cannot be used with 1.5 stop bits."); - } else { - Win_CommConfig.dcb.ByteSize=8; - SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG)); - } - break; - } - } - UNLOCK_MUTEX(); -} - -/*! -\fn void Win_QextSerialPort::setStopBits(StopBitsType stopBits) -Sets the number of stop bits used by the serial port. Possible values of stopBits are: -\verbatim - STOP_1 1 stop bit - STOP_1_5 1.5 stop bits - STOP_2 2 stop bits -\endverbatim - -\note -This function is subject to the following restrictions: -\par - 2 stop bits cannot be used with 5 data bits. -\par - 1.5 stop bits cannot be used with 6 or more data bits. -\par - POSIX does not support 1.5 stop bits. -*/ -void Win_QextSerialPort::setStopBits(StopBitsType stopBits) -{ - LOCK_MUTEX(); - if (Settings.StopBits!=stopBits) { - if ((Settings.DataBits==DATA_5 && stopBits==STOP_2) || - (stopBits==STOP_1_5 && Settings.DataBits!=DATA_5)) { - } else { - Settings.StopBits=stopBits; - } - } - if (isOpen()) { - switch (stopBits) { - - /*one stop bit*/ - case STOP_1: - Win_CommConfig.dcb.StopBits=ONESTOPBIT; - SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG)); - break; - - /*1.5 stop bits*/ - case STOP_1_5: - TTY_PORTABILITY_WARNING("Win_QextSerialPort Portability Warning: 1.5 stop bit operation is not supported by POSIX."); - if (Settings.DataBits!=DATA_5) { - TTY_WARNING("Win_QextSerialPort: 1.5 stop bits can only be used with 5 data bits"); - } else { - Win_CommConfig.dcb.StopBits=ONE5STOPBITS; - SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG)); - } - break; - - /*two stop bits*/ - case STOP_2: - if (Settings.DataBits==DATA_5) { - TTY_WARNING("Win_QextSerialPort: 2 stop bits cannot be used with 5 data bits"); - } else { - Win_CommConfig.dcb.StopBits=TWOSTOPBITS; - SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG)); - } - break; - } - } - UNLOCK_MUTEX(); -} - -/*! -\fn void Win_QextSerialPort::setBaudRate(BaudRateType baudRate) -Sets the baud rate of the serial port. Note that not all rates are applicable on -all platforms. The following table shows translations of the various baud rate -constants on Windows(including NT/2000) and POSIX platforms. Speeds marked with an * -are speeds that are usable on both Windows and POSIX. -\verbatim - - RATE Windows Speed POSIX Speed - ----------- ------------- ----------- - BAUD50 110 50 - BAUD75 110 75 - *BAUD110 110 110 - BAUD134 110 134.5 - BAUD150 110 150 - BAUD200 110 200 - *BAUD300 300 300 - *BAUD600 600 600 - *BAUD1200 1200 1200 - BAUD1800 1200 1800 - *BAUD2400 2400 2400 - *BAUD4800 4800 4800 - *BAUD9600 9600 9600 - BAUD14400 14400 9600 - *BAUD19200 19200 19200 - *BAUD38400 38400 38400 - BAUD56000 56000 38400 - *BAUD57600 57600 57600 - BAUD76800 57600 76800 - *BAUD115200 115200 115200 - BAUD128000 128000 115200 - BAUD256000 256000 115200 - BAUD230400 230400 115200 - BAUD256000 256000 115200 - BAUD460800 460800 115200 - BAUD921600 921600 115200 -\endverbatim -*/ -void Win_QextSerialPort::setBaudRate(BaudRateType baudRate) -{ - LOCK_MUTEX(); - if (Settings.BaudRate!=baudRate) { - switch (baudRate) { - case BAUD50: - case BAUD75: - case BAUD134: - case BAUD150: - case BAUD200: - Settings.BaudRate=BAUD110; - break; - - case BAUD1800: - Settings.BaudRate=BAUD1200; - break; - - case BAUD76800: - Settings.BaudRate=BAUD57600; - break; - - default: - Settings.BaudRate=baudRate; - break; - } - } - if (isOpen()) { - switch (baudRate) { - - /*50 baud*/ - case BAUD50: - TTY_WARNING("Win_QextSerialPort: Windows does not support 50 baud operation. Switching to 110 baud."); - Win_CommConfig.dcb.BaudRate=CBR_110; - break; - - /*75 baud*/ - case BAUD75: - TTY_WARNING("Win_QextSerialPort: Windows does not support 75 baud operation. Switching to 110 baud."); - Win_CommConfig.dcb.BaudRate=CBR_110; - break; - - /*110 baud*/ - case BAUD110: - Win_CommConfig.dcb.BaudRate=CBR_110; - break; - - /*134.5 baud*/ - case BAUD134: - TTY_WARNING("Win_QextSerialPort: Windows does not support 134.5 baud operation. Switching to 110 baud."); - Win_CommConfig.dcb.BaudRate=CBR_110; - break; - - /*150 baud*/ - case BAUD150: - TTY_WARNING("Win_QextSerialPort: Windows does not support 150 baud operation. Switching to 110 baud."); - Win_CommConfig.dcb.BaudRate=CBR_110; - break; - - /*200 baud*/ - case BAUD200: - TTY_WARNING("Win_QextSerialPort: Windows does not support 200 baud operation. Switching to 110 baud."); - Win_CommConfig.dcb.BaudRate=CBR_110; - break; - - /*300 baud*/ - case BAUD300: - Win_CommConfig.dcb.BaudRate=CBR_300; - break; - - /*600 baud*/ - case BAUD600: - Win_CommConfig.dcb.BaudRate=CBR_600; - break; - - /*1200 baud*/ - case BAUD1200: - Win_CommConfig.dcb.BaudRate=CBR_1200; - break; - - /*1800 baud*/ - case BAUD1800: - TTY_WARNING("Win_QextSerialPort: Windows does not support 1800 baud operation. Switching to 1200 baud."); - Win_CommConfig.dcb.BaudRate=CBR_1200; - break; - - /*2400 baud*/ - case BAUD2400: - Win_CommConfig.dcb.BaudRate=CBR_2400; - break; - - /*4800 baud*/ - case BAUD4800: - Win_CommConfig.dcb.BaudRate=CBR_4800; - break; - - /*9600 baud*/ - case BAUD9600: - Win_CommConfig.dcb.BaudRate=CBR_9600; - break; - - /*14400 baud*/ - case BAUD14400: - TTY_PORTABILITY_WARNING("Win_QextSerialPort Portability Warning: POSIX does not support 14400 baud operation."); - Win_CommConfig.dcb.BaudRate=CBR_14400; - break; - - /*19200 baud*/ - case BAUD19200: - Win_CommConfig.dcb.BaudRate=CBR_19200; - break; - - /*38400 baud*/ - case BAUD38400: - Win_CommConfig.dcb.BaudRate=CBR_38400; - break; - - /*56000 baud*/ - case BAUD56000: - TTY_PORTABILITY_WARNING("Win_QextSerialPort Portability Warning: POSIX does not support 56000 baud operation."); - Win_CommConfig.dcb.BaudRate=CBR_56000; - break; - - /*57600 baud*/ - case BAUD57600: - Win_CommConfig.dcb.BaudRate=CBR_57600; - break; - - /*76800 baud*/ - case BAUD76800: - TTY_WARNING("Win_QextSerialPort: Windows does not support 76800 baud operation. Switching to 57600 baud."); - Win_CommConfig.dcb.BaudRate=CBR_57600; - break; - - /*115200 baud*/ - case BAUD115200: - Win_CommConfig.dcb.BaudRate=CBR_115200; - break; - - /*128000 baud*/ - case BAUD128000: - TTY_PORTABILITY_WARNING("Win_QextSerialPort Portability Warning: POSIX does not support 128000 baud operation."); - Win_CommConfig.dcb.BaudRate=CBR_128000; - break; - - /*256000 baud*/ - case BAUD256000: - TTY_PORTABILITY_WARNING("Win_QextSerialPort Portability Warning: POSIX does not support 256000 baud operation."); - Win_CommConfig.dcb.BaudRate=CBR_256000; - break; - /*230400 baud*/ - case BAUD230400: - TTY_PORTABILITY_WARNING("Win_QextSerialPort Portability Warning: POSIX does not support 230400 baud operation."); - Win_CommConfig.dcb.BaudRate=CBR_230400; - break; - /*460800 baud*/ - case BAUD460800: - TTY_PORTABILITY_WARNING("Win_QextSerialPort Portability Warning: POSIX does not support 460800 baud operation."); - Win_CommConfig.dcb.BaudRate=CBR_460800; - break; - /*921600 baud*/ - case BAUD921600: - TTY_PORTABILITY_WARNING("Win_QextSerialPort Portability Warning: POSIX does not support 921600 baud operation."); - Win_CommConfig.dcb.BaudRate=CBR_921600; - break; - } - SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG)); - } - UNLOCK_MUTEX(); -} - -/*! -\fn void Win_QextSerialPort::setDtr(bool set) -Sets DTR line to the requested state (high by default). This function will have no effect if -the port associated with the class is not currently open. -*/ -void Win_QextSerialPort::setDtr(bool set) -{ - LOCK_MUTEX(); - if (isOpen()) { - if (set) { - EscapeCommFunction(Win_Handle, SETDTR); - } else { - EscapeCommFunction(Win_Handle, CLRDTR); - } - } - UNLOCK_MUTEX(); -} - -/*! -\fn void Win_QextSerialPort::setRts(bool set) -Sets RTS line to the requested state (high by default). This function will have no effect if -the port associated with the class is not currently open. -*/ -void Win_QextSerialPort::setRts(bool set) -{ - LOCK_MUTEX(); - if (isOpen()) { - if (set) { - EscapeCommFunction(Win_Handle, SETRTS); - } else { - EscapeCommFunction(Win_Handle, CLRRTS); - } - } - UNLOCK_MUTEX(); -} - -/*! -\fn ulong Win_QextSerialPort::lineStatus(void) -returns the line status as stored by the port function. This function will retrieve the states -of the following lines: DCD, CTS, DSR, and RI. On POSIX systems, the following additional lines -can be monitored: DTR, RTS, Secondary TXD, and Secondary RXD. The value returned is an unsigned -long with specific bits indicating which lines are high. The following constants should be used -to examine the states of individual lines: - -\verbatim -Mask Line ------- ---- -LS_CTS CTS -LS_DSR DSR -LS_DCD DCD -LS_RI RI -\endverbatim - -This function will return 0 if the port associated with the class is not currently open. -*/ -ulong Win_QextSerialPort::lineStatus(void) -{ - unsigned long Status=0, Temp=0; - LOCK_MUTEX(); - if (isOpen()) { - GetCommModemStatus(Win_Handle, &Temp); - if (Temp&MS_CTS_ON) { - Status|=LS_CTS; - } - if (Temp&MS_DSR_ON) { - Status|=LS_DSR; - } - if (Temp&MS_RING_ON) { - Status|=LS_RI; - } - if (Temp&MS_RLSD_ON) { - Status|=LS_DCD; - } - } - UNLOCK_MUTEX(); - return Status; -} - -bool Win_QextSerialPort::waitForReadyRead(int msecs) -{ - //@todo implement - return false; -} - -qint64 Win_QextSerialPort::bytesToWrite() const -{ - return _bytesToWrite; -} - -void Win_QextSerialPort::monitorCommEvent() -{ - DWORD eventMask = 0; - - ResetEvent(overlap.hEvent); - if (!WaitCommEvent(Win_Handle, & eventMask, & overlap)) - if (GetLastError() != ERROR_IO_PENDING) - qCritical("WaitCommEvent error %ld\n", GetLastError()); - - if (WaitForSingleObject(overlap.hEvent, INFINITE) == WAIT_OBJECT_0) { - //overlap event occured - DWORD undefined; - if (!GetOverlappedResult(Win_Handle, & overlap, & undefined, false)) { - qWarning("CommEvent overlapped error %ld", GetLastError()); - return; - } - if (eventMask & EV_RXCHAR) { - if (sender() != this) - emit readyRead(); - } - if (eventMask & EV_TXEMPTY) { - DWORD numBytes; - GetOverlappedResult(Win_Handle, & overlapWrite, & numBytes, true); - bytesToWriteLock->lockForWrite(); - if (sender() != this) - emit bytesWritten(bytesToWrite()); - _bytesToWrite = 0; - bytesToWriteLock->unlock(); - } - if (eventMask & EV_DSR) { - if (lineStatus() & LS_DSR) - emit dsrChanged(true); - } else { - emit dsrChanged(false); - } - } -} - -void Win_QextSerialPort::terminateCommWait() -{ - SetCommMask(Win_Handle, 0); -} - - -/*! -\fn void Win_QextSerialPort::setTimeout(ulong millisec); -Sets the read and write timeouts for the port to millisec milliseconds. -Setting 0 indicates that timeouts are not used for read nor write operations; -however read() and write() functions will still block. Set -1 to provide -non-blocking behaviour (read() and write() will return immediately). - -\note this function does nothing in event driven mode. -*/ -void Win_QextSerialPort::setTimeout(long millisec) -{ - LOCK_MUTEX(); - Settings.Timeout_Millisec = millisec; - - if (millisec == -1) { - Win_CommTimeouts.ReadIntervalTimeout = MAXDWORD; - Win_CommTimeouts.ReadTotalTimeoutConstant = 0; - } else { - Win_CommTimeouts.ReadIntervalTimeout = millisec; - Win_CommTimeouts.ReadTotalTimeoutConstant = millisec; - } - Win_CommTimeouts.ReadTotalTimeoutMultiplier = 0; - Win_CommTimeouts.WriteTotalTimeoutMultiplier = millisec; - Win_CommTimeouts.WriteTotalTimeoutConstant = 0; - if (queryMode() != QextSerialBase::EventDriven) - SetCommTimeouts(Win_Handle, &Win_CommTimeouts); - - UNLOCK_MUTEX(); -} - - -Win_QextSerialThread::Win_QextSerialThread(Win_QextSerialPort * qesp): - QThread() -{ - this->qesp = qesp; - terminate = false; -} - -void Win_QextSerialThread::stop() -{ - terminate = true; - qesp->terminateCommWait(); -} - -void Win_QextSerialThread::run() -{ - while (!terminate) - qesp->monitorCommEvent(); - terminate = false; -} diff --git a/src/lib/qextserialport/win_qextserialport.h b/src/lib/qextserialport/win_qextserialport.h deleted file mode 100644 index 845e69338066a8ffbd2e6d0c8a3e4dcd7835ad49..0000000000000000000000000000000000000000 --- a/src/lib/qextserialport/win_qextserialport.h +++ /dev/null @@ -1,147 +0,0 @@ -#ifndef _WIN_QEXTSERIALPORT_H_ -#define _WIN_QEXTSERIALPORT_H_ - -#include "qextserialbase.h" -#include -#include - -/* 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 diff --git a/src/standalone/mavlinkgen/MAVLinkGen.cc b/src/standalone/mavlinkgen/MAVLinkGen.cc index 1f100f6242f766551d32a78da965842728fccce9..bbec09b3be39fe82349dc71afd201c4469ce2788 100644 --- a/src/standalone/mavlinkgen/MAVLinkGen.cc +++ b/src/standalone/mavlinkgen/MAVLinkGen.cc @@ -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); diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index 8fb83d2199f2729c35c77fa00995d1967919ad46..4fd2fec47fe4ccd8f4bbb55aca79e990f953b084 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -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); } diff --git a/src/ui/QGCMapWidget.cc b/src/ui/QGCMapWidget.cc index 22a0ae21d3b25a30c54eed1d543e139051b7024b..52118dbba0988825b07abcd2ea4b33b5b8e7310c 100644 --- a/src/ui/QGCMapWidget.cc +++ b/src/ui/QGCMapWidget.cc @@ -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); diff --git a/src/ui/XMLCommProtocolWidget.cc b/src/ui/XMLCommProtocolWidget.cc index b42d16484a55fe26f1621410b939272513c2a16f..4cc97096bda23604c73ce14f57433cbb724fb50b 100644 --- a/src/ui/XMLCommProtocolWidget.cc +++ b/src/ui/XMLCommProtocolWidget.cc @@ -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(); diff --git a/src/ui/XMLCommProtocolWidget.ui b/src/ui/XMLCommProtocolWidget.ui index 4604ef5770d165cbee5733b1b5049656cf3723d1..8b1fb3d58f8952320350b901f89e5c87c34c7ac2 100644 --- a/src/ui/XMLCommProtocolWidget.ui +++ b/src/ui/XMLCommProtocolWidget.ui @@ -57,7 +57,7 @@ - + false @@ -130,6 +130,13 @@ + + + QGCMAVLinkTextEdit + QTextEdit +
QGCMAVLinkTextEdit.h
+
+
diff --git a/src/ui/mavlink/QGCMAVLinkTextEdit.cc b/src/ui/mavlink/QGCMAVLinkTextEdit.cc new file mode 100644 index 0000000000000000000000000000000000000000..89721e0b296e59c95540c08abcbb8dfbdb3bb63c --- /dev/null +++ b/src/ui/mavlink/QGCMAVLinkTextEdit.cc @@ -0,0 +1,478 @@ +#include "QGCMAVLinkTextEdit.h" +#include +#include +#include +#include +#include +#include + +QGCMAVLinkTextEdit::QGCMAVLinkTextEdit(QWidget *parent) + : QTextEdit(parent) +{ + setViewportMargins(50, 0, 0, 0); + highlight = new XmlHighlighter(document()); + setLineWrapMode ( QTextEdit::NoWrap ); + setAcceptRichText ( false ); + connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(update())); + connect(this, SIGNAL(textChanged()), this, SLOT(update())); +} + + +bool QGCMAVLinkTextEdit::Conform() +{ + QString errorStr; + int errorLine, errorColumn; + QDomDocument doc; + return doc.setContent(text(),false, &errorStr, &errorLine, &errorColumn); +} + +QDomDocument QGCMAVLinkTextEdit::xml_document() +{ + QString errorStr; + int errorLine, errorColumn; + QDomDocument doc; + doc.setContent(text(),false, &errorStr, &errorLine, &errorColumn); + return doc; +} + + +void QGCMAVLinkTextEdit::setPlainText( const QString txt ) +{ + QString errorStr; + int errorLine, errorColumn; + QDomDocument doc; + if (!doc.setContent(txt,false, &errorStr, &errorLine, &errorColumn)) { + QTextEdit::setPlainText(txt); + } else { + QTextEdit::setPlainText(doc.toString(5)); + } +} + +bool QGCMAVLinkTextEdit::syntaxcheck() +{ + bool error = false; + if (text().size() > 0 ) { + QString errorStr; + int errorLine, errorColumn; + QDomDocument doc; + if (!doc.setContent(text(),false, &errorStr, &errorLine, &errorColumn)) { + //////return doc.toString(5); + QMessageBox::information(0, tr("Found xml error"),tr("Check line %1 column %2 on string \"%3\"!") + .arg(errorLine - 1) + .arg(errorColumn - 1) + .arg(errorStr)); + error = true; + + // FIXME Mark line + if (errorLine >= 0 ) { + + } + } else { + QMessageBox::information(0, tr("XML valid."),tr("All tag are valid size %1.").arg(text().size())); + setPlainText(doc.toString(5)); + } + } else { + QMessageBox::information(0, tr("XML not found!"),tr("Null size xml document!")); + error = true; + } +} + +void QGCMAVLinkTextEdit::contextMenuEvent ( QContextMenuEvent * e ) +{ + QMenu *RContext = createOwnStandardContextMenu(); + RContext->exec(QCursor::pos()); + delete RContext; +} + +QMenu *QGCMAVLinkTextEdit::createOwnStandardContextMenu() +{ + QMenu *TContext = createStandardContextMenu(); + TContext->addAction(QIcon(QString::fromUtf8(":/img/zoomin.png")),tr( "Zoom In" ), this , SLOT( zoomIn() ) ); + TContext->addAction(QIcon(QString::fromUtf8(":/img/zoomout.png")),tr( "Zoom Out" ), this , SLOT( zoomOut() ) ); + TContext->addAction(tr("Check xml syntax" ), this , SLOT( syntaxcheck() ) ); + return TContext; +} + +bool QGCMAVLinkTextEdit::event( QEvent *event ) +{ + if (event->type()==QEvent::Paint) { + QPainter p(this); + p.fillRect(0, 0, 50, height(), QColor("#636363")); + QFont workfont(font()); + QPen pen(QColor("#ffffff"),1); + p.setPen(pen); + p.setFont (workfont); + int contentsY = verticalScrollBar()->value(); + qreal pageBottom = contentsY+viewport()->height(); + int m_lineNumber(1); + const QFontMetrics fm=fontMetrics(); + const int ascent = fontMetrics().ascent() +1; + + for (QTextBlock block=document()->begin(); block.isValid(); block=block.next(), m_lineNumber++) { + QTextLayout *layout = block.layout(); + const QRectF boundingRect = layout->boundingRect(); + QPointF position = layout->position(); + if ( position.y() +boundingRect.height() < contentsY ) { + continue; + } + if ( position.y() > pageBottom ) { + break; + } + const QString txt = QString::number(m_lineNumber); + p.drawText(50-fm.width(txt)-2, qRound(position.y())-contentsY+ascent, txt); + + } + p.setPen(QPen(Qt::NoPen)); + } else if ( event->type() == QEvent::KeyPress ) { + QKeyEvent *ke = static_cast(event); + if ((ke->modifiers() & Qt::ControlModifier) && ke->key() == Qt::Key_Minus) { + QTextEdit::zoomOut(); + return true; + } + if ((ke->modifiers() & Qt::ControlModifier) && ke->key() == Qt::Key_Plus) { + QTextEdit::zoomIn(); + return true; + } + } + return QTextEdit::event(event); +} + + + + + + + + + + + + + + + +static const QColor DEFAULT_SYNTAX_CHAR = Qt::blue; +static const QColor DEFAULT_ELEMENT_NAME = Qt::darkRed; +static const QColor DEFAULT_COMMENT = Qt::darkGreen; +static const QColor DEFAULT_ATTRIBUTE_NAME = Qt::red; +static const QColor DEFAULT_ATTRIBUTE_VALUE = Qt::darkGreen; +static const QColor DEFAULT_ERROR = Qt::darkMagenta; +static const QColor DEFAULT_OTHER = Qt::black; + +// Regular expressions for parsing XML borrowed from: +// http://www.cs.sfu.ca/~cameron/REX.html +static const QString EXPR_COMMENT = "