Browse Source

Update qextserialport and build as library

Neal Wilson 9 years ago
parent
commit
9d34e74664
46 changed files with 1315 additions and 2280 deletions
  1. 47
    41
      src/3rdparty/qextserialport/.gitignore
  2. 0
    4
      src/3rdparty/qextserialport/.hgtags
  3. 17
    1
      src/3rdparty/qextserialport/ChangeLog
  4. 6
    0
      src/3rdparty/qextserialport/LICENSE
  5. 18
    85
      src/3rdparty/qextserialport/README
  6. 0
    17
      src/3rdparty/qextserialport/buildlib/buildlib.pro
  7. 0
    17
      src/3rdparty/qextserialport/common.pri
  8. 0
    11
      src/3rdparty/qextserialport/config_example.pri
  9. 103
    31
      src/3rdparty/qextserialport/doc/index.qdoc
  10. 1
    1
      src/3rdparty/qextserialport/examples/event/PortListener.cpp
  11. 1
    1
      src/3rdparty/qextserialport/examples/event/PortListener.h
  12. 24
    24
      src/3rdparty/qextserialport/examples/qespta/MainWindow.cpp
  13. 4
    4
      src/3rdparty/qextserialport/examples/qespta/MainWindow.h
  14. 66
    59
      src/3rdparty/qextserialport/examples/qespta/MessageWindow.cpp
  15. 47
    45
      src/3rdparty/qextserialport/examples/qespta/MessageWindow.h
  16. 79
    80
      src/3rdparty/qextserialport/examples/qespta/QespTest.cpp
  17. 13
    13
      src/3rdparty/qextserialport/examples/qespta/QespTest.h
  18. 7
    3
      src/3rdparty/qextserialport/examples/qespta/main.cpp
  19. 4
    4
      src/3rdparty/qextserialport/examples/qespta/qespta.pro
  20. 25
    5
      src/3rdparty/qextserialport/examples/uartassistant/dialog.cpp
  21. 4
    0
      src/3rdparty/qextserialport/examples/uartassistant/dialog.h
  22. 1
    1
      src/3rdparty/qextserialport/examples/uartassistant/hled.cpp
  23. 1
    1
      src/3rdparty/qextserialport/examples/uartassistant/hled.h
  24. 24
    0
      src/3rdparty/qextserialport/extserialport.prf.in
  25. 94
    5
      src/3rdparty/qextserialport/qextserialport.pro
  26. 0
    427
      src/3rdparty/qextserialport/src/extserialport/qextserialport_win.cpp
  27. 0
    414
      src/3rdparty/qextserialport/src/extserialport/qextserialport_win.cpp.orig
  28. 10
    14
      src/3rdparty/qextserialport/src/qextserialenumerator.cpp
  29. 6
    3
      src/3rdparty/qextserialport/src/qextserialenumerator.h
  30. 210
    0
      src/3rdparty/qextserialport/src/qextserialenumerator_linux.cpp
  31. 41
    47
      src/3rdparty/qextserialport/src/qextserialenumerator_osx.cpp
  32. 41
    21
      src/3rdparty/qextserialport/src/qextserialenumerator_p.h
  33. 4
    48
      src/3rdparty/qextserialport/src/qextserialenumerator_unix.cpp
  34. 78
    77
      src/3rdparty/qextserialport/src/qextserialenumerator_win.cpp
  35. 61
    62
      src/3rdparty/qextserialport/src/qextserialport.cpp
  36. 7
    7
      src/3rdparty/qextserialport/src/qextserialport.h
  37. 26
    37
      src/3rdparty/qextserialport/src/qextserialport.pri
  38. 2
    2
      src/3rdparty/qextserialport/src/qextserialport_global.h
  39. 27
    34
      src/3rdparty/qextserialport/src/qextserialport_p.h
  40. 102
    92
      src/3rdparty/qextserialport/src/qextserialport_unix.cpp
  41. 113
    135
      src/3rdparty/qextserialport/src/qextserialport_win.cpp
  42. 0
    247
      src/3rdparty/qextserialport/src/qextwineventnotifier_p.cpp
  43. 0
    80
      src/3rdparty/qextserialport/src/qextwineventnotifier_p.h
  44. 0
    77
      src/3rdparty/qextserialport/tests/qextwineventnotifier/tst_qextwineventnotifier.cpp
  45. 0
    2
      src/3rdparty/qextserialport/tests/tests.pro
  46. 1
    1
      src/Typica.pro

src/3rdparty/qextserialport/.hgignore → src/3rdparty/qextserialport/.gitignore View File

@@ -1,41 +1,47 @@
1
-syntax: glob
2
-*.pro.user*
3
-*.app
4
-*.moc
5
-Makefile*
6
-doc/html/
7
-debug/
8
-release/
9
-qtc-gdbmacros/
10
-*.rej
11
-*.orig
12
-*.obj
13
-*.swp
14
-*.dll
15
-*.exp
16
-*.ilk
17
-*.pdb
18
-*.lib
19
-moc_*.cpp
20
-qrc_*.cpp
21
-*.o
22
-*.so.*
23
-*.so
24
-*.pdb
25
-ui_*.h
26
-*~
27
-.qmake.cache
28
-lib/*
29
-*.orig
30
-*.exe
31
-*.vcproj
32
-*.vcproj.*.user
33
-*.sln
34
-*.idb
35
-*.ncb
36
-*.suo
37
-examples/enumerator/enumerator
38
-examples/event/event
39
-examples/qespta/qespta
40
-examples/uartassistant/uartassistant
41
-object_script.*
1
+syntax: glob
2
+*.pro.user*
3
+*.app
4
+*.moc
5
+*.prl
6
+Makefile*
7
+doc/html/
8
+*.framework/
9
+*.xcodeproj/
10
+debug/
11
+release/
12
+qtc-gdbmacros/
13
+*.rej
14
+*.orig
15
+*.obj
16
+*.swp
17
+*.dll
18
+*.exp
19
+*.ilk
20
+*.pdb
21
+*.lib
22
+Thumbs.db
23
+moc_*.cpp
24
+qrc_*.cpp
25
+*.o
26
+*.so.*
27
+*.so
28
+*.pdb
29
+ui_*.h
30
+*~
31
+.qmake.cache
32
+extserialport.prf
33
+lib/*
34
+*.orig
35
+*.exe
36
+*.vcproj
37
+*.vcproj.*.user
38
+*_resource.rc
39
+*.sln
40
+*.idb
41
+*.ncb
42
+*.suo
43
+examples/enumerator/enumerator
44
+examples/event/event
45
+examples/qespta/qespta
46
+examples/uartassistant/uartassistant
47
+object_script.*

+ 0
- 4
src/3rdparty/qextserialport/.hgtags View File

@@ -1,4 +0,0 @@
1
-96e3a424c22cda7bd430736ffe8ec94c02e9d462 REL_0_9
2
-ecdbd5f836603c25941f6ea7659b271767088cb8 REL_1_1
3
-f5c8064caf35b35778bd191a2d8aed9e7b1260f4 REL_0_8
4
-4a0173d282232b56c55962e17aa254917c52c4c0 1.2-beta1

+ 17
- 1
src/3rdparty/qextserialport/ChangeLog View File

@@ -2,12 +2,28 @@ Change history for QextSerialPort (formerly QwSerialPort):
2 2
 (Lines beginning with + represent new functionality, * represent changed or
3 3
 fixed functionality, - represent removed or deprecated functionality)
4 4
 
5
+Version 1.2 rc (2012 Debao Zhang)
6
+  * Build-system refactor
7
+  * Issue 145 : Custom baud support for MacOS
8
+  * Issue 36  : Fix Devices Notification for Vista
9
+  * Issue 54 and Issue 108 : Try detect more ports for windows
10
+  * Issue 139 : Adjust the name of generated library
11
+  - QextWinEventNotifier has been removed
12
+
13
+Version 1.2 beta2 (2012 Debao Zhang)
14
+  * Issue 124 : implement canReadLine
15
+  * Issue 122 : make Dtr default to TRUE under Windows.
16
+  * Issue 127 : fix QObject::MoveToThread brokes SerialPort on Windows
17
+  * Issue 129 : Add custom baud support for Windows.
18
+  * Issue 131 : Make sure portName returned by QextSerialEnumerator can be used by QextSerialPort
19
+  * Issue 134 : Make "make install" really works
20
+  * Issue 2: device discovery / removal notification on linux (read config_example.pri to figure out how to enable it.)
21
+
5 22
 Version 1.2 beta1 (2012 Debao Zhang)
6 23
   * D-pointer and Q_PRIVATE_SLOT are used to moving private members from QextSerialPort to QextSerialPortPrivate
7 24
   * qdoc3 instead of doxygen is used for generating documents
8 25
   * MIT license header add to all sources files
9 26
   + add a helper class QextWinEventNotifier for windows user, when user's SDK doesnot contain Qt's private files, this class will be auto selected.
10
-  + Support platform custom baudrate. Macros such as B230400 / B460800 can be used directly if you OS support it. 
11 27
 
12 28
 Version 1.2win-alpha (2007 Michal Policht)
13 29
   + Added QextSerialEnumerator pre-alpha. Works under W2k and later versions of Windows.

+ 6
- 0
src/3rdparty/qextserialport/LICENSE View File

@@ -86,3 +86,9 @@ And from [http://groups.google.com/group/qextserialport/browse_thread/thread/fbc
86 86
  * Liam Staskawicz,
87 87
 
88 88
     That works for me - let's call it MIT and go for it :) 
89
+
90
+And from [[https://groups.google.com/forum/?fromgroups#!topic/qextserialport/P_5TrNHBICE this other thread]] on the same mailing list:
91
+
92
+ * Michal Policht,
93
+
94
+    I agree to license.

+ 18
- 85
src/3rdparty/qextserialport/README View File

@@ -28,104 +28,37 @@ QextSerialPort provides an interface to old fashioned serial ports for Qt-based
28 28
             ....
29 29
             
30 30
 == How to use (2) ==
31
-
32 31
 It's very easy to compile QextSerialPort directly into your application
33
-(see above section), however, we would prefer to use it as a static or
34
- shared library.
35
-
36
- * Download the source code, and put it in any location you like.
37
-
38
-           |-- yourpath\
39
-           |     |-- qextserialport\
40
-           |     |
41
-
42
- * Create a config.pri file, and put into qextserialport's directory.
43
-
44
-           |-- yourpath\
45
-           |     |-- qextserialport\
46
-           |     |     |-- config.pri
47
-           
48
-   * Contents of config_example.pri
49
-  
50
-           # uncomment the following line if you want to use qesp as library
51
-           # QEXTSERIALPORT_LIBRARY = yes
52
-
53
-           # uncomment the following line too if you want to use it as static library
54
-           # QEXTSERIALPORT_STATIC = yes
55
-
56
- * Goto qextserialport/buildlib, and run following command to generate library.
57
-
58
-           qmake
59
-           make (or nmake)
60
-
61
- * Add following line to your qmake project file. Enjoy it!
62
-
63
-           include(pathToQextserialport/src/qextserialport.pri)
64
-
65
-== How to use (3) ==
66
-
67
-Someone complains that, I want to used !QextSerialPort as a shared libaray, but
68
-I don't want to add the {{{include(***.pri)}}} to my project file. Otherwise,
69
-all the source files of !QextSerialPort will be shown in Qt Creator, which is
70
-very annoying.
71
-
72
-Ok, let's go!
32
+(see above section), however, we would prefer to use it as a shared library.
73 33
 
74 34
  * Download the source code, and put it in any location you like.
75 35
 
76
- * Goto qextserialport/buildlib, and run following command to generate library. (Yes, config.pri is not needed.)
36
+ * Run following command to generate library. 
77 37
 
78 38
           qmake
79 39
           make (or nmake)
40
+          sudo make install (or nmake install)
80 41
 
81
- * Add following lines to your .pro file. And you need to specify the path to the lib and headers. Then Enjoy it!
82
-
83
-          # Specify lib and headers path if they are not in standard locations.
84
-          # Otherwise, your can ignore this.
85
-          unix{
86
-             QEXTSERIALPORT_LIBDIR = #path_to_qextserialport_lib
87
-             QEXTSERIALPORT_INCDIR = #path_to_qextserialport_headers
88
-          }else{
89
-             QEXTSERIALPORT_LIBDIR = #path_to_qextserialport_lib
90
-             QEXTSERIALPORT_INCDIR = #path_to_qextserialport_headers
91
-          }
92
-
93
-          SAVE_TEMPLATE = $$TEMPLATE
94
-          TEMPLATE = fakelib
95
-          QEXTSERIALPORT_LIBNAME = $$qtLibraryTarget(qextserialport-1.2)
96
-          TEMPLATE = $$SAVE_TEMPLATE
97
-
98
-          INCLUDEPATH += $$QEXTSERIALPORT_INCDIR
99
-          LIBS += -L$$QEXTSERIALPORT_LIBDIR -l$$QEXTSERIALPORT_LIBNAME
100
-          DEFINES += QEXTSERIALPORT_USING_SHARED
101
-
102
-          unix:QMAKE_RPATHDIR += $$QEXTSERIALPORT_LIBDIR
103
-
104
- * Oh, this file looks a bit complicated, as we need cross-platform. If you don't care cross-platform. It will be very simple :-) , for example
105
-      
106
-          INCLUDEPATH += /home/xxxx/download/qextserialport/src
107
-          LIBS += /home/xxxx/download/qextserialport/lib/libqextsrialport-1.2.so
108
-          DEFINES += QEXTSERIALPORT_USING_SHARED
109
-
110
- * Note:
111
-  * If you do not want to add such lines to each of your projects. This is another solution too.
112
-  * Create a new file called *extserialport.prf* , then add above lines to this new file.
113
-  * Put this .prf file to one of feature paths, such as
114
-          
115
-          $QTDIR\mkspecs\features\
116
-          
117
-  * Add the following line to your .pro file. Enjoy it!
42
+ * Add following line to your project's file
118 43
 
119 44
           CONFIG += extserialport
120 45
 
121
-== Build (optional) ==
46
+ * Using QextSerialPort in your code. Enjoy it!
122 47
 
123
- * Run qmake from the toplevel directory.(If your has create a config.pri file properly, this will generate the library, and then all examples will use the library. Otherwise, qextserialport will be directly compiled into the examples)
48
+            #include "qextserialport.h"
49
+            ....
50
+            QextSerialPort * port = new QextSerialPort();
51
+            ....
124 52
 
125
-           qmake (or qmake -r)
126
-           make (or nmake)
53
+== Build Documents ==
54
+ * Run
55
+           qmake
56
+           make docs
127 57
 
128
- * Run qdoc3 from the doc directory.
58
+ * Note: More information can be found in doc/readme.txt
129 59
 
130
-           qdoc3 qextserialport.qdocconf
60
+== Build examples ==
61
+ * Goto examples directory, then run
62
+           qmake (or qmake -r)
63
+           make (or nmake)
131 64
 

+ 0
- 17
src/3rdparty/qextserialport/buildlib/buildlib.pro View File

@@ -1,17 +0,0 @@
1
-TEMPLATE=lib
2
-CONFIG += qt qextserialport-buildlib
3
-# Include .pri file before using "qextserialport-static"
4
-# and after CONFIG += "qextserialport-buildlib"
5
-include(../src/qextserialport.pri)
6
-qextserialport-static:CONFIG += static
7
-else:CONFIG += dll
8
-mac:CONFIG += absolute_library_soname
9
-win32|mac:!wince*:!win32-msvc:!macx-xcode:CONFIG += debug_and_release build_all
10
-TARGET = $$QEXTSERIALPORT_LIBNAME
11
-DESTDIR = $$QEXTSERIALPORT_LIBDIR
12
-win32:!qextserialport-static{
13
-    DLLDESTDIR = $$[QT_INSTALL_BINS]
14
-    QMAKE_DISTCLEAN += $$[QT_INSTALL_BINS]\\$${QEXTSERIALPORT_LIBNAME}.dll
15
-}
16
-target.path = $$DESTDIR
17
-INSTALLS += target

+ 0
- 17
src/3rdparty/qextserialport/common.pri View File

@@ -1,17 +0,0 @@
1
-infile(config.pri, QEXTSERIALPORT_LIBRARY, yes): CONFIG += qextserialport-library
2
-qextserialport-library{
3
-    infile(config.pri, QEXTSERIALPORT_STATIC, yes): CONFIG += qextserialport-static
4
-}
5
-# Though maybe you have been fimiliar with "TEMPLATE += fakelib" and "TEMPLATE -= fakelib",
6
-# but it don't work when you using "qmake -tp XXX". So I use another variable Here.
7
-SAVE_TEMPLATE = $$TEMPLATE
8
-TEMPLATE = fakelib
9
-contains(QT_VERSION, ^5\\..*\\..*) {
10
-    #different name for Qt4 and Qt5
11
-    QEXTSERIALPORT_LIBNAME = $$qtLibraryTarget(QtExtSerialPort-1.2)
12
-} else {
13
-    QEXTSERIALPORT_LIBNAME = $$qtLibraryTarget(qextserialport-1.2)
14
-}
15
-TEMPLATE = $$SAVE_TEMPLATE
16
-QEXTSERIALPORT_LIBDIR = $$PWD/lib
17
-unix:qextserialport-library:!qextserialport-buildlib:QMAKE_RPATHDIR += $$QEXTSERIALPORT_LIBDIR

+ 0
- 11
src/3rdparty/qextserialport/config_example.pri View File

@@ -1,11 +0,0 @@
1
-# This is an example config.pri for building and using qextserialport.
2
-# 
3
-# When using the qextserialport, all you need is to add following line
4
-# in your .pro file:
5
-#    include(pathToQextserialport/src/qextserialport.pri)
6
-#
7
-# uncomment the following line if you want to use qextserialport as library
8
-# QEXTSERIALPORT_LIBRARY = yes
9
-
10
-# uncomment the following line too if you want to use it as static library
11
-# QEXTSERIALPORT_STATIC = yes

+ 103
- 31
src/3rdparty/qextserialport/doc/index.qdoc View File

@@ -22,10 +22,24 @@
22 22
       \endlist
23 23
     
24 24
     \section1 Getting Started
25
-      The package contains a qextserialport.pri file that allows you to integrate the 
26
-      component into programs that use qmake for the build step.
27 25
 
28
-      All you need is adding following line to your qmake's project file:
26
+
27
+    \section2 Usage(1): Source Code Only
28
+
29
+ The package contains a qextserialport.pri file that allows you to integrate the component into programs that use qmake for the build step.
30
+
31
+      Download the source code.
32
+      Put the source code in any directory you like. For example, 3rdparty:
33
+
34
+      \code
35
+       |-- project.pro
36
+       |-- ....
37
+       |-- 3rdparty\
38
+       |     |-- qextserialport\
39
+       |     |
40
+      \endcode
41
+
42
+      Add following line to your qmake project file:
29 43
       \code
30 44
       include(pathToPri/qextserialport.pri)
31 45
       \endcode
@@ -48,35 +62,102 @@
48 62
       }
49 63
       \endcode
50 64
 
51
-    \section2 Using QexSerialPort as library
65
+    \section2 Usage(2): shared library
52 66
       Although QextSerialPort can be directly compiled into your application, You may prefer
53 67
       to use QextSerailPort as an library, which is very easy too.
54 68
 
55
-      1. Write a config.pri file.(read config_example.pri for reference):
69
+     1. Download the source code, and put it in any location you like.
70
+    
71
+     2. Goto the top level directory ,run following command to generate library.
72
+    
73
+          \code
74
+          qmake
75
+          sudo make install (or nmake install)
76
+          \endcode
77
+    
78
+     3. Add following line to your project's file
79
+    
80
+          \code
81
+          CONFIG += extserialport
82
+          \endcode
83
+    
84
+     4. Using QextSerialPort in your code. Enjoy it!
85
+    
86
+          \code
87
+          #include "qextserialport.h"
88
+          ....
89
+          QextSerialPort * port = new QextSerialPort();
90
+          ....
91
+          \endcode
92
+
93
+    \section2 Usage(3): Static library
56 94
 
57
-      \list
58
-        \o shared library
59
-        \o static library
60
-      \endlist
95
+        Someone prefer to use QextSerailPort as static library.
61 96
 
62
-      2. Changed to subdirectory 'buildlib', run
63
-      \code
64
-      qmake
65
-      make
66
-      \endcode
67
-      shared or static library will be generated.
97
+        Open the project file: qextserialport.pro, add uncomment follow line
98
+
99
+          \code
100
+           # CONFIG += qesp_static
101
+          \endcode
102
+
103
+        Then follow the same steps as shared library
104
+
105
+          \code
106
+           qmake
107
+           sudo make install
108
+          \endcode
109
+
110
+        The static library, the header files, and the feature file will be installed to your system.
111
+
112
+        Add following line to your qmake's project file:
113
+
114
+          \code
115
+          CONFIG += extserialport
116
+          \endcode
117
+    
118
+      \section1 Platform Special
119
+
120
+      \section2 For MacX: Build as framework
121
+
122
+      Open the project file: *qextserialport.pro*, and uncomment follow line
123
+
124
+          \code
125
+           # CONFIG += qesp_mac_framework
126
+          \endcode
127
+
128
+      Then follow the same steps as shared library, Goto the top level directory , and run
129
+
130
+          \code
131
+           qmake
132
+           sudo make install
133
+          \endcode
134
+ 
135
+      The framework which includes libraries and the header files, and the feature file will be installed to your system.
136
+
137
+      Add following line to your qmake's project file:
138
+
139
+          \code
140
+           CONFIG += extserialport
141
+          \endcode
142
+
143
+      \section2 For Linux: Enable udev
144
+
145
+       Open the project file: *qextserialport.pro*, uncomment follow line
146
+
147
+          \code
148
+           #linux*:CONFIG += qesp_linux_udev
149
+          \endcode
150
+
151
+       Note, If you are using the usage(1), Add following line before include the qextserialport.pri file. 
152
+          \code
153
+           CONFIG += qesp_linux_udev
154
+          \endcode
68 155
 
69
-      3.  Add following line to your qmake project file:
70
-      \code
71
-      include(pathToPri/qextserialport.pri)
72
-      \endcode
73 156
 
74 157
      \section2 Build documents
75
-      Run qdoc3 from the doc directory.
76 158
       \code
77
-        qdoc3 qextserialport.qdocconf
159
+        make docs
78 160
       \endcode
79
-      Note: qdoc3 has been renamed to qdoc under Qt5.
80 161
 
81 162
     \section1 Examples
82 163
       \list
@@ -85,15 +166,6 @@
85 166
       \o \l examples/uartassistant
86 167
       \endlist
87 168
 
88
-     \section2 Build examples
89
-      Run following commands at toplevel directory
90
-      \code
91
-      qmake
92
-      make
93
-      \endcode
94
-
95
-      or simply open the qextserialport.pro using Qt Creator.
96
-
97 169
     \section1 Resources
98 170
         \section2  Nokia(Trolltech)
99 171
         \list

+ 1
- 1
src/3rdparty/qextserialport/examples/event/PortListener.cpp View File

@@ -2,7 +2,7 @@
2 2
 #include "PortListener.h"
3 3
 #include <QtDebug>
4 4
 
5
-PortListener::PortListener(const QString & portName)
5
+PortListener::PortListener(const QString &portName)
6 6
 {
7 7
     qDebug() << "hi there";
8 8
     this->port = new QextSerialPort(portName, QextSerialPort::EventDriven);

+ 1
- 1
src/3rdparty/qextserialport/examples/event/PortListener.h View File

@@ -11,7 +11,7 @@ class PortListener : public QObject
11 11
 {
12 12
 Q_OBJECT
13 13
 public:
14
-    PortListener(const QString & portName);
14
+    PortListener(const QString &portName);
15 15
 
16 16
 private:
17 17
     QextSerialPort *port;

+ 24
- 24
src/3rdparty/qextserialport/examples/qespta/MainWindow.cpp View File

@@ -15,14 +15,14 @@
15 15
 MainWindow::MainWindow()
16 16
 {
17 17
     //central widget
18
-	QespTest* qespTest = new QespTest();
18
+    QespTest *qespTest = new QespTest();
19 19
     setCentralWidget(qespTest);
20
-	//bottom dock widget
21
-	MessageWindow* msgWindow = new MessageWindow();
22
-	addDockWidget(Qt::BottomDockWidgetArea, msgWindow);
20
+    //bottom dock widget
21
+    MessageWindow *msgWindow = new MessageWindow();
22
+    addDockWidget(Qt::BottomDockWidgetArea, msgWindow);
23 23
 
24
-	createActions();
25
-	createMenus();
24
+    createActions();
25
+    createMenus();
26 26
 
27 27
     setWindowTitle(tr("QextSerialPort Test Application"));
28 28
 }
@@ -30,32 +30,32 @@ MainWindow::MainWindow()
30 30
 void MainWindow::about()
31 31
 {
32 32
     QMessageBox::about(this, tr("About "),
33
-            tr("<B>""</B><BR>"
34
-				"author: Michal Policht<br>"
35
-                "<a href='mailto:xpolik@users.sourceforge.net'>xpolik@users.sourceforge.net</a>"));
33
+                       tr("<B>""</B><BR>"
34
+                          "author: Michal Policht<br>"
35
+                          "<a href='mailto:xpolik@users.sourceforge.net'>xpolik@users.sourceforge.net</a>"));
36 36
 }
37 37
 
38 38
 void MainWindow::createActions()
39 39
 {
40
-	//File actions
41
-	exitAct = new QAction(tr("E&xit"), this);
42
-	exitAct->setShortcut(tr("CTRL+D"));
43
-	exitAct->setStatusTip(tr("Exit the application"));
44
-	connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
45
-	
46
-	//Help actions
47
-	aboutAct = new QAction(tr("&About"), this);
48
-	aboutAct->setShortcut(tr("CTRL+A"));
49
-	aboutAct->setStatusTip(tr("About application"));
50
-	connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
40
+    //File actions
41
+    exitAct = new QAction(tr("E&xit"), this);
42
+    exitAct->setShortcut(tr("CTRL+D"));
43
+    exitAct->setStatusTip(tr("Exit the application"));
44
+    connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
45
+
46
+    //Help actions
47
+    aboutAct = new QAction(tr("&About"), this);
48
+    aboutAct->setShortcut(tr("CTRL+A"));
49
+    aboutAct->setStatusTip(tr("About application"));
50
+    connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
51 51
 }
52 52
 
53 53
 void MainWindow::createMenus()
54 54
 {
55
-	fileMenu = menuBar()->addMenu(tr("&File"));
56
-	fileMenu->addAction(exitAct);
55
+    fileMenu = menuBar()->addMenu(tr("&File"));
56
+    fileMenu->addAction(exitAct);
57 57
 
58
-	helpMenu = menuBar()->addMenu(tr("&Help"));
59
-	helpMenu->addAction(aboutAct);
58
+    helpMenu = menuBar()->addMenu(tr("&Help"));
59
+    helpMenu->addAction(aboutAct);
60 60
 }
61 61
 

+ 4
- 4
src/3rdparty/qextserialport/examples/qespta/MainWindow.h View File

@@ -15,13 +15,13 @@ class QAction;
15 15
 
16 16
 class MainWindow : public QMainWindow
17 17
 {
18
-	Q_OBJECT
18
+    Q_OBJECT
19 19
 
20
-	QMenu *fileMenu;
20
+    QMenu *fileMenu;
21 21
     QAction *exitAct;
22
-	QMenu *helpMenu;
22
+    QMenu *helpMenu;
23 23
     QAction *aboutAct;
24
-	
24
+
25 25
 private:
26 26
     void createMenus();
27 27
     void createActions();

+ 66
- 59
src/3rdparty/qextserialport/examples/qespta/MessageWindow.cpp View File

@@ -11,85 +11,92 @@
11 11
 #include <QCoreApplication>
12 12
 #include <QMutexLocker>
13 13
 
14
-const char* MessageWindow::WINDOW_TITLE = "Message Window";
15
-MessageWindow* MessageWindow::MsgHandler = NULL;
14
+const char *MessageWindow::WINDOW_TITLE = "Message Window";
15
+MessageWindow *MessageWindow::MsgHandler = NULL;
16 16
 
17
-MessageWindow::MessageWindow(QWidget* parent, Qt::WFlags flags) 
18
-	: QDockWidget(parent, flags),
19
-		msgTextEdit(this)
17
+MessageWindow::MessageWindow(QWidget *parent, Qt::WindowFlags flags)
18
+    : QDockWidget(parent, flags),
19
+      msgTextEdit(this)
20 20
 {
21
-	setWindowTitle(tr(WINDOW_TITLE));
22
-	msgTextEdit.setReadOnly(true);
23
-	setWidget(&msgTextEdit);
21
+    setWindowTitle(tr(WINDOW_TITLE));
22
+    msgTextEdit.setReadOnly(true);
23
+    setWidget(&msgTextEdit);
24 24
 
25
-	MessageWindow::MsgHandler = this;
25
+    MessageWindow::MsgHandler = this;
26 26
 }
27 27
 
28 28
 //static
29 29
 QString MessageWindow::QtMsgToQString(QtMsgType type, const char *msg)
30 30
 {
31
-	switch (type) {
32
-		case QtDebugMsg:
33
-			return QLatin1String("Debug: ")+QLatin1String(msg);
34
-		case QtWarningMsg:
35
-			return QLatin1String("Warning: ")+QLatin1String(msg);
36
-		case QtCriticalMsg:
37
-			return QLatin1String("Critical: ")+QLatin1String(msg);
38
-		case QtFatalMsg:
39
-			return QLatin1String("Fatal: ")+QLatin1String(msg);
40
-		default:
41
-			return QLatin1String("Unrecognized message type: ")+QLatin1String(msg);
42
-	}
31
+    switch (type) {
32
+    case QtDebugMsg:
33
+        return QLatin1String("Debug: ")+QLatin1String(msg);
34
+    case QtWarningMsg:
35
+        return QLatin1String("Warning: ")+QLatin1String(msg);
36
+    case QtCriticalMsg:
37
+        return QLatin1String("Critical: ")+QLatin1String(msg);
38
+    case QtFatalMsg:
39
+        return QLatin1String("Fatal: ")+QLatin1String(msg);
40
+    default:
41
+        return QLatin1String("Unrecognized message type: ")+QLatin1String(msg);
42
+    }
43 43
 }
44 44
 
45 45
 //static
46
-void MessageWindow::AppendMsgWrapper(QtMsgType type, const char* msg)
46
+void MessageWindow::AppendMsgWrapper(QtMsgType type, const char *msg)
47 47
 {
48
-	static QMutex mutex;
49
-	QMutexLocker locker(&mutex);
50
-	
51
-	if (MessageWindow::MsgHandler != NULL)
52
-		return MessageWindow::MsgHandler->postMsgEvent(type, msg);
53
-	else
48
+    static QMutex mutex;
49
+    QMutexLocker locker(&mutex);
50
+
51
+    if (MessageWindow::MsgHandler != NULL)
52
+        return MessageWindow::MsgHandler->postMsgEvent(type, msg);
53
+    else
54 54
         fprintf(stderr, "%s", MessageWindow::QtMsgToQString(type, msg).toLatin1().data());
55 55
 }
56 56
 
57
-void MessageWindow::customEvent(QEvent* event)
57
+#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
58
+void MessageWindow::AppendMsgWrapper(QtMsgType type, const QMessageLogContext & /*context*/, const QString &msg)
59
+{
60
+    AppendMsgWrapper(type, msg.toLatin1().data());
61
+}
62
+#endif
63
+
64
+void MessageWindow::customEvent(QEvent *event)
58 65
 {
59
-	if (static_cast<MessageWindow::EventType>(event->type()) == MessageWindow::MessageEventType)
60
-		msgTextEdit.append(dynamic_cast<MessageEvent* >(event)->msg);
66
+    if (static_cast<MessageWindow::EventType>(event->type()) == MessageWindow::MessageEventType)
67
+        msgTextEdit.append(dynamic_cast<MessageEvent *>(event)->msg);
61 68
 }
62 69
 
63
-void MessageWindow::postMsgEvent(QtMsgType type, const char* msg)
70
+void MessageWindow::postMsgEvent(QtMsgType type, const char *msg)
64 71
 {
65
-	QString qmsg = MessageWindow::QtMsgToQString(type, msg);
66
-	switch (type) {
67
-		case QtDebugMsg:
68
-			break;
69
-		case QtWarningMsg:
70
-			qmsg.prepend(QLatin1String("<FONT color=\"#FF0000\">"));
71
-			qmsg.append(QLatin1String("</FONT>"));
72
-			break;
73
-		case QtCriticalMsg:
74
-			if (QMessageBox::critical(this, QLatin1String("Critical Error"), qmsg,
75
-					QMessageBox::Ignore,
76
-					QMessageBox::Abort,
77
-					QMessageBox::NoButton) == QMessageBox::Abort)
78
-				abort(); // core dump
79
-			qmsg.prepend(QLatin1String("<B><FONT color=\"#FF0000\">"));
80
-			qmsg.append(QLatin1String("</FONT></B>"));
81
-			break;
82
-		case QtFatalMsg:
83
-			QMessageBox::critical(this, QLatin1String("Fatal Error"), qmsg, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton);
84
-			abort(); // deliberately core dump
85
-	}
86
-	//it's impossible to change GUI directly from thread other than the main thread 
87
-	//so post message encapsulated by MessageEvent to the main thread's event queue
88
-	QCoreApplication::postEvent(this, new MessageEvent(qmsg));
72
+    QString qmsg = MessageWindow::QtMsgToQString(type, msg);
73
+    switch (type) {
74
+    case QtDebugMsg:
75
+        break;
76
+    case QtWarningMsg:
77
+        qmsg.prepend(QLatin1String("<FONT color=\"#FF0000\">"));
78
+        qmsg.append(QLatin1String("</FONT>"));
79
+        break;
80
+    case QtCriticalMsg:
81
+        if (QMessageBox::critical(this, QLatin1String("Critical Error"), qmsg,
82
+                                  QMessageBox::Ignore,
83
+                                  QMessageBox::Abort,
84
+                                  QMessageBox::NoButton) == QMessageBox::Abort)
85
+            abort(); // core dump
86
+        qmsg.prepend(QLatin1String("<B><FONT color=\"#FF0000\">"));
87
+        qmsg.append(QLatin1String("</FONT></B>"));
88
+        break;
89
+    case QtFatalMsg:
90
+        QMessageBox::critical(this, QLatin1String("Fatal Error"), qmsg, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton);
91
+        abort(); // deliberately core dump
92
+    }
93
+    //it's impossible to change GUI directly from thread other than the main thread
94
+    //so post message encapsulated by MessageEvent to the main thread's event queue
95
+    QCoreApplication::postEvent(this, new MessageEvent(qmsg));
89 96
 }
90 97
 
91
-MessageEvent::MessageEvent(QString & msg):
92
-	QEvent(static_cast<QEvent::Type>(MessageWindow::MessageEventType))
98
+MessageEvent::MessageEvent(QString &msg):
99
+    QEvent(static_cast<QEvent::Type>(MessageWindow::MessageEventType))
93 100
 {
94
-	this->msg = msg;
101
+    this->msg = msg;
95 102
 }

+ 47
- 45
src/3rdparty/qextserialport/examples/qespta/MessageWindow.h View File

@@ -17,49 +17,51 @@
17 17
  */
18 18
 class MessageWindow: public QDockWidget
19 19
 {
20
-	Q_OBJECT
20
+    Q_OBJECT
21 21
 
22
-	QTextEdit msgTextEdit;				///< Main widget.
23
-	static MessageWindow* MsgHandler;	///< Set in constructor.
24
-	static const char* WINDOW_TITLE; 	///< Window title.
22
+    QTextEdit msgTextEdit;              ///< Main widget.
23
+    static MessageWindow *MsgHandler;   ///< Set in constructor.
24
+    static const char *WINDOW_TITLE;    ///< Window title.
25 25
 
26
-	private:
27
-		static QString QtMsgToQString(QtMsgType type, const char *msg);
28
-	
29
-	protected:
30
-		/**
31
-		 * Handle custom events. MessageWindow hadles custom events listed in
32
-		 * EventType enum.
33
-		 */
34
-		virtual void customEvent(QEvent* event);
35
-		
36
-	public:
37
-        enum EventType {MessageEventType = QEvent::User};	///< Custom event types.
38
-		
39
-		/**
40
-		 * Default constructor.
41
-		 * 	@param parent parent widget.
42
-		 * 	@param flags widget flags.
43
-		 */
44
-		MessageWindow(QWidget* parent = 0, Qt::WFlags flags = 0);
26
+private:
27
+    static QString QtMsgToQString(QtMsgType type, const char *msg);
28
+
29
+protected:
30
+    /**
31
+         * Handle custom events. MessageWindow hadles custom events listed in
32
+         * EventType enum.
33
+         */
34
+    virtual void customEvent(QEvent* event);
35
+
36
+public:
37
+    enum EventType {MessageEventType = QEvent::User};    ///< Custom event types.
38
+
39
+    /**
40
+         * Default constructor.
41
+         *     @param parent parent widget.
42
+         *     @param flags widget flags.
43
+         */
44
+    MessageWindow(QWidget* parent = 0, Qt::WindowFlags flags = 0);
45
+
46
+    /**
47
+         * Append message wrapper. Since ISO forbids casting member functions
48
+         * to C functions, wrapper is needed to use this class as QtMsgHandler.
49
+         * This method is thread-safe but not reentrant.
50
+         *     @param type message type.
51
+         *     @param msg message string.
52
+         */
53
+    static void AppendMsgWrapper(QtMsgType type, const char *msg);
54
+#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
55
+    static void AppendMsgWrapper(QtMsgType type, const QMessageLogContext &context, const QString &msg);
56
+#endif
57
+    /**
58
+         * Post message event to the main event loop. This function encapsulates
59
+         * message into MessageEvent object and passes it to the main event loop.
60
+         *     @param type message type.
61
+         *     @param msg message string.
62
+         */
63
+    void postMsgEvent(QtMsgType type, const char *msg);
45 64
 
46
-		/**
47
-		 * Append message wrapper. Since ISO forbids casting member functions
48
-		 * to C functions, wrapper is needed to use this class as QtMsgHandler.
49
-		 * This method is thread-safe but not reentrant.
50
-		 * 	@param type message type.
51
-		 * 	@param msg message string.
52
-		 */
53
-		static void AppendMsgWrapper(QtMsgType type, const char *msg);
54
-		
55
-		/**
56
-		 * Post message event to the main event loop. This function encapsulates
57
-		 * message into MessageEvent object and passes it to the main event loop.
58
-		 * 	@param type message type.
59
-		 * 	@param msg message string.
60
-		 */
61
-		void postMsgEvent(QtMsgType type, const char *msg);
62
-	
63 65
 };
64 66
 
65 67
 
@@ -69,14 +71,14 @@ class MessageWindow: public QDockWidget
69 71
  */
70 72
 class MessageEvent: public QEvent
71 73
 {
72
-    public:
73
-        QString msg;	///< Message string.
74
+public:
75
+    QString msg;    ///< Message string.
74 76
 
75
-        /**
77
+    /**
76 78
          * Contructor.
77
-         * 	@param msg message to post.
79
+         *     @param msg message to post.
78 80
          */
79
-        MessageEvent(QString & msg);
81
+    MessageEvent(QString &msg);
80 82
 };
81 83
 
82 84
 #endif /*MESSAGEWINDOW_H_*/

+ 79
- 80
src/3rdparty/qextserialport/examples/qespta/QespTest.cpp View File

@@ -9,64 +9,64 @@
9 9
 #include <QSpinBox>
10 10
 
11 11
 
12
-QespTest::QespTest(QWidget* parent) 
13
-	: QWidget(parent)
12
+QespTest::QespTest(QWidget *parent)
13
+    : QWidget(parent)
14 14
 
15 15
 {
16
-	//modify the port settings on your own
17
-    #ifdef Q_OS_UNIX
18
-		port = new QextSerialPort(QLatin1String("/dev/ttyS0"), QextSerialPort::Polling);
19
-	#else
20
-		port = new QextSerialPort(QLatin1String("COM1"), QextSerialPort::Polling);
21
-    #endif /*Q_OS_UNIX*/
22
-	port->setBaudRate(BAUD19200);
23
-	port->setFlowControl(FLOW_OFF);
24
-	port->setParity(PAR_NONE);
25
-	port->setDataBits(DATA_8);
26
-	port->setStopBits(STOP_2);
27
-	//set timeouts to 500 ms
28
-	port->setTimeout(500);
29
-	
30
-	message = new QLineEdit(this);
31
-
32
-	// transmit receive
33
-	QPushButton *transmitButton = new QPushButton(tr("Transmit"));
34
-	connect(transmitButton, SIGNAL(clicked()), SLOT(transmitMsg()));
35
-	QPushButton *receiveButton = new QPushButton(tr("Receive"));
36
-	connect(receiveButton, SIGNAL(clicked()), SLOT(receiveMsg()));
37
-	QHBoxLayout* trLayout = new QHBoxLayout;
38
-	trLayout->addWidget(transmitButton);
39
-	trLayout->addWidget(receiveButton);
40
-	  
41
-	//CR LF
42
-	QPushButton *CRButton = new QPushButton(tr("CR"));
43
-	connect(CRButton, SIGNAL(clicked()), SLOT(appendCR()));
44
-	QPushButton *LFButton = new QPushButton(tr("LF"));
45
-	connect(LFButton, SIGNAL(clicked()), SLOT(appendLF()));
46
-	QHBoxLayout *crlfLayout = new QHBoxLayout;
47
-	crlfLayout->addWidget(CRButton);
48
-	crlfLayout->addWidget(LFButton);
49
-	
50
-	//open close
51
-	QPushButton *openButton = new QPushButton(tr("Open"));
52
-	connect(openButton, SIGNAL(clicked()), SLOT(openPort()));
53
-	QPushButton *closeButton = new QPushButton(tr("Close"));
54
-	connect(closeButton, SIGNAL(clicked()), SLOT(closePort()));
55
-	QHBoxLayout *ocLayout = new QHBoxLayout;
56
-	ocLayout->addWidget(openButton);
57
-	ocLayout->addWidget(closeButton);
58
-	
59
-	received_msg = new QTextEdit();
60
-	  
61
-	QVBoxLayout *myVBox = new QVBoxLayout;
62
-	myVBox->addWidget(message);
63
-	myVBox->addLayout(crlfLayout);
64
-	myVBox->addLayout(trLayout);
65
-	myVBox->addLayout(ocLayout);
66
-	myVBox->addWidget(received_msg);
67
-	setLayout(myVBox);
68
-	
69
-	qDebug("isOpen : %d", port->isOpen());
16
+    //modify the port settings on your own
17
+#ifdef Q_OS_UNIX
18
+    port = new QextSerialPort(QLatin1String("/dev/ttyS0"), QextSerialPort::Polling);
19
+#else
20
+    port = new QextSerialPort(QLatin1String("COM1"), QextSerialPort::Polling);
21
+#endif /*Q_OS_UNIX*/
22
+    port->setBaudRate(BAUD19200);
23
+    port->setFlowControl(FLOW_OFF);
24
+    port->setParity(PAR_NONE);
25
+    port->setDataBits(DATA_8);
26
+    port->setStopBits(STOP_2);
27
+    //set timeouts to 500 ms
28
+    port->setTimeout(500);
29
+
30
+    message = new QLineEdit(this);
31
+
32
+    // transmit receive
33
+    QPushButton *transmitButton = new QPushButton(tr("Transmit"));
34
+    connect(transmitButton, SIGNAL(clicked()), SLOT(transmitMsg()));
35
+    QPushButton *receiveButton = new QPushButton(tr("Receive"));
36
+    connect(receiveButton, SIGNAL(clicked()), SLOT(receiveMsg()));
37
+    QHBoxLayout *trLayout = new QHBoxLayout;
38
+    trLayout->addWidget(transmitButton);
39
+    trLayout->addWidget(receiveButton);
40
+
41
+    //CR LF
42
+    QPushButton *CRButton = new QPushButton(tr("CR"));
43
+    connect(CRButton, SIGNAL(clicked()), SLOT(appendCR()));
44
+    QPushButton *LFButton = new QPushButton(tr("LF"));
45
+    connect(LFButton, SIGNAL(clicked()), SLOT(appendLF()));
46
+    QHBoxLayout *crlfLayout = new QHBoxLayout;
47
+    crlfLayout->addWidget(CRButton);
48
+    crlfLayout->addWidget(LFButton);
49
+
50
+    //open close
51
+    QPushButton *openButton = new QPushButton(tr("Open"));
52
+    connect(openButton, SIGNAL(clicked()), SLOT(openPort()));
53
+    QPushButton *closeButton = new QPushButton(tr("Close"));
54
+    connect(closeButton, SIGNAL(clicked()), SLOT(closePort()));
55
+    QHBoxLayout *ocLayout = new QHBoxLayout;
56
+    ocLayout->addWidget(openButton);
57
+    ocLayout->addWidget(closeButton);
58
+
59
+    received_msg = new QTextEdit();
60
+
61
+    QVBoxLayout *myVBox = new QVBoxLayout;
62
+    myVBox->addWidget(message);
63
+    myVBox->addLayout(crlfLayout);
64
+    myVBox->addLayout(trLayout);
65
+    myVBox->addLayout(ocLayout);
66
+    myVBox->addWidget(received_msg);
67
+    setLayout(myVBox);
68
+
69
+    qDebug("isOpen : %d", port->isOpen());
70 70
 }
71 71
 
72 72
 QespTest::~QespTest()
@@ -77,53 +77,52 @@ QespTest::~QespTest()
77 77
 
78 78
 void QespTest::transmitMsg()
79 79
 {
80
-  int i = port->write((message->text()).toAscii(),
81
-                       (message->text()).length());
82
-  qDebug("trasmitted : %d", i);
80
+    int i = port->write(message->text().toLatin1());
81
+    qDebug("trasmitted : %d", i);
83 82
 }
84 83
 
85 84
 void QespTest::receiveMsg()
86 85
 {
87
-	char buff[1024];
88
-  	int numBytes;
89
-  
90
-	numBytes = port->bytesAvailable();
91
-    if(numBytes > 1024) 
92
-    	numBytes = 1024;
86
+    char buff[1024];
87
+    int numBytes;
88
+
89
+    numBytes = port->bytesAvailable();
90
+    if(numBytes > 1024)
91
+        numBytes = 1024;
93 92
 
94 93
     int i = port->read(buff, numBytes);
95 94
     if (i != -1)
96
-		buff[i] = '\0';
97
-	else
98
-		buff[0] = '\0';
99
-	QString msg = QLatin1String(buff);
100
-	
101
-   	received_msg->append(msg);
102
-   	received_msg->ensureCursorVisible();
103
-	qDebug("bytes available: %d", numBytes);
104
-	qDebug("received: %d", i);
95
+        buff[i] = '\0';
96
+    else
97
+        buff[0] = '\0';
98
+    QString msg = QLatin1String(buff);
99
+
100
+    received_msg->append(msg);
101
+    received_msg->ensureCursorVisible();
102
+    qDebug("bytes available: %d", numBytes);
103
+    qDebug("received: %d", i);
105 104
 }
106 105
 
107 106
 
108 107
 void QespTest::appendCR()
109 108
 {
110
-	message->insert(QLatin1String("\x0D"));
109
+    message->insert(QLatin1String("\x0D"));
111 110
 }
112 111
 
113 112
 void QespTest::appendLF()
114 113
 {
115
-	message->insert(QLatin1String("\x0A"));
114
+    message->insert(QLatin1String("\x0A"));
116 115
 }
117 116
 
118 117
 void QespTest::closePort()
119 118
 {
120
-	port->close();
121
-	qDebug("is open: %d", port->isOpen());
119
+    port->close();
120
+    qDebug("is open: %d", port->isOpen());
122 121
 }
123 122
 
124 123
 void QespTest::openPort()
125 124
 {
126
-	port->open(QIODevice::ReadWrite | QIODevice::Unbuffered);
127
-	qDebug("is open: %d", port->isOpen());
125
+    port->open(QIODevice::ReadWrite | QIODevice::Unbuffered);
126
+    qDebug("is open: %d", port->isOpen());
128 127
 }
129 128
 

+ 13
- 13
src/3rdparty/qextserialport/examples/qespta/QespTest.h View File

@@ -12,25 +12,25 @@ class QSpinBox;
12 12
 
13 13
 class QespTest :  public QWidget
14 14
 {
15
-  Q_OBJECT
15
+    Q_OBJECT
16 16
 public:
17
-  QespTest(QWidget *parent=0);
17
+    QespTest(QWidget *parent=0);
18 18
 
19
-  virtual ~QespTest();
19
+    virtual ~QespTest();
20 20
 
21 21
 private:
22
-  QLineEdit *message;
23
-  QSpinBox* delaySpinBox;
24
-  QTextEdit *received_msg;
25
-  QextSerialPort *port;
22
+    QLineEdit *message;
23
+    QSpinBox *delaySpinBox;
24
+    QTextEdit *received_msg;
25
+    QextSerialPort *port;
26 26
 
27 27
 private slots:
28
-  void transmitMsg();
29
-  void receiveMsg();
30
-  void appendCR();
31
-  void appendLF();
32
-  void closePort();
33
-  void openPort();
28
+    void transmitMsg();
29
+    void receiveMsg();
30
+    void appendCR();
31
+    void appendLF();
32
+    void closePort();
33
+    void openPort();
34 34
 };
35 35
 
36 36
 #endif

+ 7
- 3
src/3rdparty/qextserialport/examples/qespta/main.cpp View File

@@ -11,14 +11,18 @@
11 11
 
12 12
 int main(int argc, char *argv[])
13 13
 {
14
-	QApplication app(argc, argv);
14
+    QApplication app(argc, argv);
15 15
     //! [0]
16
+#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
16 17
     //redirect debug messages to the MessageWindow dialog
17
-	qInstallMsgHandler(MessageWindow::AppendMsgWrapper);
18
+    qInstallMsgHandler(MessageWindow::AppendMsgWrapper);
19
+#else
20
+    qInstallMessageHandler(MessageWindow::AppendMsgWrapper);
21
+#endif
18 22
     //! [0]
19 23
 
20 24
     MainWindow mainWindow;
21
-	mainWindow.show();
25
+    mainWindow.show();
22 26
 
23 27
     return app.exec();
24 28
 }

+ 4
- 4
src/3rdparty/qextserialport/examples/qespta/qespta.pro View File

@@ -3,12 +3,12 @@ DEPENDPATH += .
3 3
 QT += core gui
4 4
 contains(QT_VERSION, ^5\\..*\\..*): QT += widgets
5 5
 HEADERS += MainWindow.h \
6
-		MessageWindow.h \
6
+        MessageWindow.h \
7 7
         QespTest.h
8 8
 
9 9
 SOURCES += main.cpp \
10
-		MainWindow.cpp \
11
-		MessageWindow.cpp \
12
-		QespTest.cpp
10
+           MainWindow.cpp \
11
+           MessageWindow.cpp \
12
+           QespTest.cpp
13 13
 
14 14
 include(../../src/qextserialport.pri)

+ 25
- 5
src/3rdparty/qextserialport/examples/uartassistant/dialog.cpp View File

@@ -1,4 +1,5 @@
1 1
 #include "qextserialport.h"
2
+#include "qextserialenumerator.h"
2 3
 #include "dialog.h"
3 4
 #include "ui_dialog.h"
4 5
 #include <QtCore>
@@ -10,11 +11,8 @@ Dialog::Dialog(QWidget *parent) :
10 11
     ui->setupUi(this);
11 12
 
12 13
     //! [0]
13
-#ifdef Q_OS_WIN
14
-    ui->portBox->addItems(QStringList()<<"COM1"<<"COM2"<<"COM3"<<"COM4");
15
-#else
16
-    ui->portBox->addItems(QStringList()<<"/dev/ttyS0"<<"/dev/ttyS1"<<"/dev/ttyUSB0"<<"/dev/ttyUSB1");
17
-#endif
14
+    foreach (QextPortInfo info, QextSerialEnumerator::getPorts())
15
+        ui->portBox->addItem(info.portName);
18 16
     //make sure user can input their own port name!
19 17
     ui->portBox->setEditable(true);
20 18
 
@@ -50,6 +48,10 @@ Dialog::Dialog(QWidget *parent) :
50 48
     PortSettings settings = {BAUD9600, DATA_8, PAR_NONE, STOP_1, FLOW_OFF, 10};
51 49
     port = new QextSerialPort(ui->portBox->currentText(), settings, QextSerialPort::Polling);
52 50
     //! [1]
51
+
52
+    enumerator = new QextSerialEnumerator(this);
53
+    enumerator->setUpNotifications();
54
+
53 55
     connect(ui->baudRateBox, SIGNAL(currentIndexChanged(int)), SLOT(onBaudRateChanged(int)));
54 56
     connect(ui->parityBox, SIGNAL(currentIndexChanged(int)), SLOT(onParityChanged(int)));
55 57
     connect(ui->dataBitsBox, SIGNAL(currentIndexChanged(int)), SLOT(onDataBitsChanged(int)));
@@ -62,6 +64,9 @@ Dialog::Dialog(QWidget *parent) :
62 64
     connect(timer, SIGNAL(timeout()), SLOT(onReadyRead()));
63 65
     connect(port, SIGNAL(readyRead()), SLOT(onReadyRead()));
64 66
 
67
+    connect(enumerator, SIGNAL(deviceDiscovered(QextPortInfo)), SLOT(onPortAddedOrRemoved()));
68
+    connect(enumerator, SIGNAL(deviceRemoved(QextPortInfo)), SLOT(onPortAddedOrRemoved()));
69
+
65 70
     setWindowTitle(tr("QextSerialPort Demo"));
66 71
 }
67 72
 
@@ -156,4 +161,19 @@ void Dialog::onReadyRead()
156 161
         ui->recvEdit->insertPlainText(QString::fromLatin1(port->readAll()));
157 162
     }
158 163
 }
164
+
165
+void Dialog::onPortAddedOrRemoved()
166
+{
167
+    QString current = ui->portBox->currentText();
168
+
169
+    ui->portBox->blockSignals(true);
170
+    ui->portBox->clear();
171
+    foreach (QextPortInfo info, QextSerialEnumerator::getPorts())
172
+        ui->portBox->addItem(info.portName);
173
+
174
+    ui->portBox->setCurrentIndex(ui->portBox->findText(current));
175
+
176
+    ui->portBox->blockSignals(false);
177
+}
178
+
159 179
 //! [4]

+ 4
- 0
src/3rdparty/qextserialport/examples/uartassistant/dialog.h View File

@@ -8,6 +8,7 @@ namespace Ui {
8 8
 }
9 9
 class QTimer;
10 10
 class QextSerialPort;
11
+class QextSerialEnumerator;
11 12
 
12 13
 class Dialog : public QDialog
13 14
 {
@@ -32,10 +33,13 @@ private Q_SLOTS:
32 33
     void onSendButtonClicked();
33 34
     void onReadyRead();
34 35
 
36
+    void onPortAddedOrRemoved();
37
+
35 38
 private:
36 39
     Ui::Dialog *ui;
37 40
     QTimer *timer;
38 41
     QextSerialPort *port;
42
+    QextSerialEnumerator *enumerator;
39 43
 };
40 44
 
41 45
 #endif // DIALOG_H

+ 1
- 1
src/3rdparty/qextserialport/examples/uartassistant/hled.cpp View File

@@ -62,7 +62,7 @@ void HLed::turnOff(bool off)
62 62
     turnOn(!off);
63 63
 }
64 64
 
65
-void HLed::paintEvent(QPaintEvent* /* event*/)
65
+void HLed::paintEvent(QPaintEvent * /*event*/)
66 66
 {
67 67
     int width = ledWidth();
68 68
 

+ 1
- 1
src/3rdparty/qextserialport/examples/uartassistant/hled.h View File

@@ -23,7 +23,7 @@ public slots:
23 23
     void turnOff(bool off=true);
24 24
 
25 25
 protected:
26
-    void paintEvent(QPaintEvent*);
26
+    void paintEvent(QPaintEvent *);
27 27
     int ledWidth() const;
28 28
 
29 29
 private:

+ 24
- 0
src/3rdparty/qextserialport/extserialport.prf.in View File

@@ -0,0 +1,24 @@
1
+defineReplace(qextLibraryName) {
2
+   unset(LIBRARY_NAME)
3
+   LIBRARY_NAME = \$\$1
4
+   greaterThan(QT_MAJOR_VERSION, 4):LIBRARY_NAME ~= s,^Qt,Qt\$\$QT_MAJOR_VERSION,
5
+   CONFIG(debug, debug|release) {
6
+      !debug_and_release|build_pass {
7
+          mac:LIBRARY_NAME = \$\${LIBRARY_NAME}_debug
8
+          else:win32:LIBRARY_NAME = \$\${LIBRARY_NAME}d
9
+      }
10
+   }
11
+   return(\$\$LIBRARY_NAME)
12
+}
13
+
14
+!!IF qesp_mac_framework
15
+LIBS += -framework $$QESP_LIB_BASENAME
16
+INCLUDEPATH += $$[QT_INSTALL_LIBS]/$${QESP_LIB_BASENAME}.framework/Headers
17
+!!ELSE
18
+LIBS += -l\$\$qextLibraryName($$QESP_LIB_BASENAME)
19
+INCLUDEPATH += $$[QT_INSTALL_HEADERS]/QtExtSerialPort
20
+!!ENDIF
21
+
22
+!!IF !qesp_static
23
+DEFINES += QEXTSERIALPORT_USING_SHARED
24
+!!ENDIF

+ 94
- 5
src/3rdparty/qextserialport/qextserialport.pro View File

@@ -1,7 +1,96 @@
1
-TEMPLATE=subdirs
2
-CONFIG += ordered
3
-include(common.pri)
4
-qextserialport-library:SUBDIRS=buildlib
5
-SUBDIRS+=examples
1
+############################### *User Config* ###############################
6 2
 
3
+# Uncomment following line if you want to build a static library
4
+# CONFIG += qesp_static
5
+
6
+# Uncomment following line if you want to build framework for mac
7
+# macx:CONFIG += qesp_mac_framework
8
+
9
+# Uncomment following line if you want to enable udev for linux
10
+# linux*:CONFIG += qesp_linux_udev
11
+
12
+# Note: you can create a ".qmake.cache" file, then copy these lines to it.
13
+# If so, you can avoid to change this project file.
14
+############################### *User Config* ###############################
15
+
16
+defineReplace(qextLibraryName) {
17
+   unset(LIBRARY_NAME)
18
+   LIBRARY_NAME = $$1
19
+   macx:qesp_mac_framework {
20
+      QMAKE_FRAMEWORK_BUNDLE_NAME = $$LIBRARY_NAME
21
+      export(QMAKE_FRAMEWORK_BUNDLE_NAME)
22
+   } else {
23
+       greaterThan(QT_MAJOR_VERSION, 4):LIBRARY_NAME ~= s,^Qt,Qt$$QT_MAJOR_VERSION,
24
+   }
25
+   CONFIG(debug, debug|release) {
26
+      !debug_and_release|build_pass {
27
+          mac:LIBRARY_NAME = $${LIBRARY_NAME}_debug
28
+          else:win32:LIBRARY_NAME = $${LIBRARY_NAME}d
29
+      }
30
+   }
31
+   return($$LIBRARY_NAME)
32
+}
33
+
34
+TEMPLATE=lib
35
+include(src/qextserialport.pri)
36
+
37
+#create_prl is needed, otherwise, MinGW can't found libqextserialport1.a
38
+CONFIG += create_prl
39
+
40
+#mac framework is designed for shared library
41
+macx:qesp_mac_framework:qesp_static: CONFIG -= qesp_static
42
+!macx:qesp_mac_framework:CONFIG -= qesp_mac_framework
43
+
44
+qesp_static {
45
+    CONFIG += static
46
+} else {
47
+    CONFIG += shared
48
+    macx:!qesp_mac_framework:CONFIG += absolute_library_soname
49
+    DEFINES += QEXTSERIALPORT_BUILD_SHARED
50
+}
51
+
52
+#Creare lib bundle for mac
53
+macx:qesp_mac_framework {
54
+    CONFIG += lib_bundle
55
+    FRAMEWORK_HEADERS.files = $$PUBLIC_HEADERS
56
+    FRAMEWORK_HEADERS.path = Headers
57
+    QMAKE_BUNDLE_DATA += FRAMEWORK_HEADERS
58
+}
59
+
60
+win32|mac:!wince*:!win32-msvc:!macx-xcode:CONFIG += debug_and_release build_all
61
+
62
+#For non-windows system, only depends on QtCore module
63
+unix:QT = core
64
+else:QT = core gui
65
+
66
+#generate proper library name
67
+greaterThan(QT_MAJOR_VERSION, 4) {
68
+    QESP_LIB_BASENAME = QtExtSerialPort
69
+} else {
70
+    QESP_LIB_BASENAME = qextserialport
71
+}
72
+TARGET = $$qextLibraryName($$QESP_LIB_BASENAME)
73
+VERSION = 1.2.0
74
+
75
+# generate feature file by qmake based on this *.in file.
76
+QMAKE_SUBSTITUTES += extserialport.prf.in
77
+OTHER_FILES += extserialport.prf.in
78
+
79
+# for make docs
7 80
 include(doc/doc.pri)
81
+
82
+# for make install
83
+win32:!qesp_static {
84
+    dlltarget.path = $$[QT_INSTALL_BINS]
85
+    INSTALLS += dlltarget
86
+}
87
+!macx|!qesp_mac_framework {
88
+    headers.files = $$PUBLIC_HEADERS
89
+    headers.path = $$[QT_INSTALL_HEADERS]/QtExtSerialPort
90
+    INSTALLS += headers
91
+}
92
+target.path = $$[QT_INSTALL_LIBS]
93
+
94
+features.files = extserialport.prf
95
+features.path = $$[QMAKE_MKSPECS]/features
96
+INSTALLS += target features

+ 0
- 427
src/3rdparty/qextserialport/src/extserialport/qextserialport_win.cpp View File

@@ -1,427 +0,0 @@
1
-/****************************************************************************
2
-** Copyright (c) 2000-2003 Wayne Roth
3
-** Copyright (c) 2004-2007 Stefan Sander
4
-** Copyright (c) 2007 Michal Policht
5
-** Copyright (c) 2008 Brandon Fosdick
6
-** Copyright (c) 2009-2010 Liam Staskawicz
7
-** Copyright (c) 2011 Debao Zhang
8
-** All right reserved.
9
-** Web: http://code.google.com/p/qextserialport/
10
-**
11
-** Permission is hereby granted, free of charge, to any person obtaining
12
-** a copy of this software and associated documentation files (the
13
-** "Software"), to deal in the Software without restriction, including
14
-** without limitation the rights to use, copy, modify, merge, publish,
15
-** distribute, sublicense, and/or sell copies of the Software, and to
16
-** permit persons to whom the Software is furnished to do so, subject to
17
-** the following conditions:
18
-**
19
-** The above copyright notice and this permission notice shall be
20
-** included in all copies or substantial portions of the Software.
21
-**
22
-** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23
-** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
-** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25
-** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26
-** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27
-** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28
-** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
-**
30
-****************************************************************************/
31
-
32
-#include "qextserialport.h"
33
-#include "qextserialport_p.h"
34
-#include <QtCore/QThread>
35
-#include <QtCore/QReadWriteLock>
36
-#include <QtCore/QMutexLocker>
37
-#include <QtCore/QDebug>
38
-#include <QtCore/QRegExp>
39
-#include <QtCore/QMetaType>
40
-#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
41
-#  include <QtCore/QWinEventNotifier>
42
-#  define WinEventNotifier QWinEventNotifier
43
-#elif !defined(QESP_NO_QT4_PRIVATE)
44
-#  include <QtCore/private/qwineventnotifier_p.h>
45
-#  define WinEventNotifier QWinEventNotifier
46
-#else
47
-#  include "qextwineventnotifier_p.h"
48
-#  define WinEventNotifier QextWinEventNotifier
49
-#endif
50
-void QextSerialPortPrivate::platformSpecificInit()
51
-{
52
-    Win_Handle=INVALID_HANDLE_VALUE;
53
-    ZeroMemory(&overlap, sizeof(OVERLAPPED));
54
-    overlap.hEvent = CreateEvent(NULL, true, false, NULL);
55
-    winEventNotifier = 0;
56
-    bytesToWriteLock = new QReadWriteLock;
57
-    _bytesToWrite = 0;
58
-}
59
-
60
-void QextSerialPortPrivate::platformSpecificDestruct() {
61
-    CloseHandle(overlap.hEvent);
62
-    delete bytesToWriteLock;
63
-}
64
-
65
-
66
-/*!
67
-    \internal
68
-    COM ports greater than 9 need \\.\ prepended
69
-
70
-    This is only need when open the port.
71
-*/
72
-static QString fullPortNameWin(const QString & name)
73
-{
74
-    QRegExp rx(QLatin1String("^COM(\\d+)"));
75
-    QString fullName(name);
76
-    if(fullName.contains(rx))
77
-        fullName.prepend(QLatin1String("\\\\.\\"));
78
-    return fullName;
79
-}
80
-
81
-bool QextSerialPortPrivate::open_sys(QIODevice::OpenMode mode)
82
-{
83
-    Q_Q(QextSerialPort);
84
-    DWORD confSize = sizeof(COMMCONFIG);
85
-    Win_CommConfig.dwSize = confSize;
86
-    DWORD dwFlagsAndAttributes = 0;
87
-    if (_queryMode == QextSerialPort::EventDriven)
88
-        dwFlagsAndAttributes += FILE_FLAG_OVERLAPPED;
89
-
90
-    /*open the port*/
91
-    Win_Handle=CreateFileW((wchar_t*)fullPortNameWin(port).utf16(), GENERIC_READ|GENERIC_WRITE,
92
-                           0, NULL, OPEN_EXISTING, dwFlagsAndAttributes, NULL);
93
-    if (Win_Handle!=INVALID_HANDLE_VALUE) {
94
-        q->setOpenMode(mode);
95
-        /*configure port settings*/
96
-        GetCommConfig(Win_Handle, &Win_CommConfig, &confSize);
97
-        GetCommState(Win_Handle, &(Win_CommConfig.dcb));
98
-
99
-        /*set up parameters*/
100
-        Win_CommConfig.dcb.fBinary=TRUE;
101
-        Win_CommConfig.dcb.fInX=FALSE;
102
-        Win_CommConfig.dcb.fOutX=FALSE;
103
-        Win_CommConfig.dcb.fAbortOnError=FALSE;
104
-        Win_CommConfig.dcb.fNull=FALSE;
105
-        /* Dtr default to true. See Issue 122*/
106
-        Win_CommConfig.dcb.fDtrControl=TRUE;
107
-        /*flush all settings*/
108
-        settingsDirtyFlags = DFE_ALL;
109
-        updatePortSettings();
110
-
111
-        //init event driven approach
112
-        if (_queryMode == QextSerialPort::EventDriven) {
113
-            if (!SetCommMask( Win_Handle, EV_TXEMPTY | EV_RXCHAR | EV_DSR)) {
114
-                QESP_WARNING()<<"failed to set Comm Mask. Error code:"<<GetLastError();
115
-                return false;
116
-            }
117
-            winEventNotifier = new WinEventNotifier(overlap.hEvent, q);
118
-            qRegisterMetaType<HANDLE>("HANDLE");
119
-            q->connect(winEventNotifier, SIGNAL(activated(HANDLE)), q, SLOT(_q_onWinEvent(HANDLE)), Qt::DirectConnection);
120
-            WaitCommEvent(Win_Handle, &eventMask, &overlap);
121
-        }
122
-        return true;
123
-    }
124
-    return false;
125
-}
126
-
127
-bool QextSerialPortPrivate::close_sys()
128
-{
129
-    flush_sys();
130
-    CancelIo(Win_Handle);
131
-    if (CloseHandle(Win_Handle))
132
-        Win_Handle = INVALID_HANDLE_VALUE;
133
-    if (winEventNotifier){
134
-        winEventNotifier->setEnabled(false);
135
-        winEventNotifier->deleteLater();
136
-        winEventNotifier = 0;
137
-    }
138
-    _bytesToWrite = 0;
139
-
140
-    foreach(OVERLAPPED* o, pendingWrites) {
141
-        CloseHandle(o->hEvent);
142
-        delete o;
143
-    }
144
-    pendingWrites.clear();
145
-    return true;
146
-}
147
-
148
-bool QextSerialPortPrivate::flush_sys()
149
-{
150
-    FlushFileBuffers(Win_Handle);
151
-    return true;
152
-}
153
-
154
-qint64 QextSerialPortPrivate::bytesAvailable_sys() const
155
-{
156
-    DWORD Errors;
157
-    COMSTAT Status;
158
-    if (ClearCommError(Win_Handle, &Errors, &Status)) {
159
-        return Status.cbInQue;
160
-    }
161
-    return (qint64)-1;
162
-}
163
-
164
-/*
165
-    Translates a system-specific error code to a QextSerialPort error code.  Used internally.
166
-*/
167
-void QextSerialPortPrivate::translateError(ulong error)
168
-{
169
-    if (error&CE_BREAK) {
170
-        lastErr=E_BREAK_CONDITION;
171
-    }
172
-    else if (error&CE_FRAME) {
173
-        lastErr=E_FRAMING_ERROR;
174
-    }
175
-    else if (error&CE_IOE) {
176
-        lastErr=E_IO_ERROR;
177
-    }
178
-    else if (error&CE_MODE) {
179
-        lastErr=E_INVALID_FD;
180
-    }
181
-    else if (error&CE_OVERRUN) {
182
-        lastErr=E_BUFFER_OVERRUN;
183
-    }
184
-    else if (error&CE_RXPARITY) {
185
-        lastErr=E_RECEIVE_PARITY_ERROR;
186
-    }
187
-    else if (error&CE_RXOVER) {
188
-        lastErr=E_RECEIVE_OVERFLOW;
189
-    }
190
-    else if (error&CE_TXFULL) {
191
-        lastErr=E_TRANSMIT_OVERFLOW;
192
-    }
193
-}
194
-
195
-/*
196
-    Reads a block of data from the serial port.  This function will read at most maxlen bytes from
197
-    the serial port and place them in the buffer pointed to by data.  Return value is the number of
198
-    bytes actually read, or -1 on error.
199
-    
200
-    \warning before calling this function ensure that serial port associated with this class
201
-    is currently open (use isOpen() function to check if port is open).
202
-*/
203
-qint64 QextSerialPortPrivate::readData_sys(char *data, qint64 maxSize)
204
-{
205
-    DWORD bytesRead = 0;
206
-    bool failed = false;
207
-    if (_queryMode == QextSerialPort::EventDriven) {
208
-        OVERLAPPED overlapRead;
209
-        ZeroMemory(&overlapRead, sizeof(OVERLAPPED));
210
-        if (!ReadFile(Win_Handle, (void*)data, (DWORD)maxSize, & bytesRead, & overlapRead)) {
211
-            if (GetLastError() == ERROR_IO_PENDING)
212
-                GetOverlappedResult(Win_Handle, & overlapRead, & bytesRead, true);
213
-            else
214
-                failed = true;
215
-        }
216
-    } else if (!ReadFile(Win_Handle, (void*)data, (DWORD)maxSize, & bytesRead, NULL)) {
217
-        failed = true;
218
-    }
219
-    if (!failed)
220
-        return (qint64)bytesRead;
221
-
222
-    lastErr = E_READ_FAILED;
223
-    return -1;
224
-}
225
-
226
-/*
227
-    Writes a block of data to the serial port.  This function will write len bytes
228
-    from the buffer pointed to by data to the serial port.  Return value is the number
229
-    of bytes actually written, or -1 on error.
230
-    
231
-    \warning before calling this function ensure that serial port associated with this class
232
-    is currently open (use isOpen() function to check if port is open).
233
-*/
234
-qint64 QextSerialPortPrivate::writeData_sys(const char *data, qint64 maxSize)
235
-{
236
-    DWORD bytesWritten = 0;
237
-    bool failed = false;
238
-    if (_queryMode == QextSerialPort::EventDriven) {
239
-        OVERLAPPED* newOverlapWrite = new OVERLAPPED;
240
-        ZeroMemory(newOverlapWrite, sizeof(OVERLAPPED));
241
-        newOverlapWrite->hEvent = CreateEvent(NULL, true, false, NULL);
242
-        if (WriteFile(Win_Handle, (void*)data, (DWORD)maxSize, & bytesWritten, newOverlapWrite)) {
243
-            CloseHandle(newOverlapWrite->hEvent);
244
-            delete newOverlapWrite;
245
-        }
246
-        else if (GetLastError() == ERROR_IO_PENDING) {
247
-            // writing asynchronously...not an error
248
-            QWriteLocker writelocker(bytesToWriteLock);
249
-            _bytesToWrite += maxSize;
250
-            pendingWrites.append(newOverlapWrite);
251
-        }
252
-        else {
253
-            QESP_WARNING()<<"QextSerialPort write error:"<<GetLastError();
254
-            failed = true;
255
-            if(!CancelIo(newOverlapWrite->hEvent))
256
-                QESP_WARNING("QextSerialPort: couldn't cancel IO");
257
-            if(!CloseHandle(newOverlapWrite->hEvent))
258
-                QESP_WARNING("QextSerialPort: couldn't close OVERLAPPED handle");
259
-            delete newOverlapWrite;
260
-        }
261
-    } else if (!WriteFile(Win_Handle, (void*)data, (DWORD)maxSize, & bytesWritten, NULL)) {
262
-        failed = true;
263
-    }
264
-
265
-    if (!failed)
266
-        return (qint64)bytesWritten;
267
-
268
-    lastErr = E_WRITE_FAILED;
269
-    return -1;
270
-}
271
-
272
-void QextSerialPortPrivate::setDtr_sys(bool set) {
273
-    EscapeCommFunction(Win_Handle, set ? SETDTR : CLRDTR);
274
-}
275
-
276
-void QextSerialPortPrivate::setRts_sys(bool set) {
277
-    EscapeCommFunction(Win_Handle, set ? SETRTS : CLRRTS);
278
-}
279
-
280
-ulong QextSerialPortPrivate::lineStatus_sys(void) {
281
-    unsigned long Status=0, Temp=0;
282
-    GetCommModemStatus(Win_Handle, &Temp);
283
-    if (Temp & MS_CTS_ON) Status|=LS_CTS;
284
-    if (Temp & MS_DSR_ON) Status|=LS_DSR;
285
-    if (Temp & MS_RING_ON) Status|=LS_RI;
286
-    if (Temp & MS_RLSD_ON) Status|=LS_DCD;
287
-    return Status;
288
-}
289
-
290
-/*
291
-  Triggered when there's activity on our HANDLE.
292
-*/
293
-void QextSerialPortPrivate::_q_onWinEvent(HANDLE h)
294
-{
295
-    Q_Q(QextSerialPort);
296
-    if(h == overlap.hEvent) {
297
-        if (eventMask & EV_RXCHAR) {
298
-            if (q->sender() != q && bytesAvailable_sys() > 0)
299
-                _q_canRead();
300
-        }
301
-        if (eventMask & EV_TXEMPTY) {
302
-            /*
303
-              A write completed.  Run through the list of OVERLAPPED writes, and if
304
-              they completed successfully, take them off the list and delete them.
305
-              Otherwise, leave them on there so they can finish.
306
-            */
307
-            qint64 totalBytesWritten = 0;
308
-            QList<OVERLAPPED*> overlapsToDelete;
309
-            foreach(OVERLAPPED* o, pendingWrites) {
310
-                DWORD numBytes = 0;
311
-                if (GetOverlappedResult(Win_Handle, o, & numBytes, false)) {
312
-                    overlapsToDelete.append(o);
313
-                    totalBytesWritten += numBytes;
314
-                } else if( GetLastError() != ERROR_IO_INCOMPLETE ) {
315
-                    overlapsToDelete.append(o);
316
-                    QESP_WARNING()<<"CommEvent overlapped write error:" << GetLastError();
317
-                }
318
-            }
319
-
320
-            if (q->sender() != q && totalBytesWritten > 0) {
321
-                QWriteLocker writelocker(bytesToWriteLock);
322
-                Q_EMIT q->bytesWritten(totalBytesWritten);
323
-                _bytesToWrite = 0;
324
-            }
325
-
326
-            foreach(OVERLAPPED* o, overlapsToDelete) {
327
-                OVERLAPPED *toDelete = pendingWrites.takeAt(pendingWrites.indexOf(o));
328
-                CloseHandle(toDelete->hEvent);
329
-                delete toDelete;
330
-            }
331
-        }
332
-        if (eventMask & EV_DSR) {
333
-            if (lineStatus_sys() & LS_DSR)
334
-                Q_EMIT q->dsrChanged(true);
335
-            else
336
-                Q_EMIT q->dsrChanged(false);
337
-        }
338
-    }
339
-    WaitCommEvent(Win_Handle, &eventMask, &overlap);
340
-}
341
-
342
-void QextSerialPortPrivate::updatePortSettings()
343
-{
344
-    if (!q_ptr->isOpen() || !settingsDirtyFlags)
345
-        return;
346
-
347
-    //fill struct : COMMCONFIG
348
-    if (settingsDirtyFlags & DFE_BaudRate) {
349
-        Win_CommConfig.dcb.BaudRate = Settings.BaudRate;
350
-    }
351
-    if (settingsDirtyFlags & DFE_Parity) {
352
-        Win_CommConfig.dcb.Parity = (BYTE)Settings.Parity;
353
-        Win_CommConfig.dcb.fParity = (Settings.Parity == PAR_NONE) ? FALSE : TRUE;
354
-    }
355
-    if (settingsDirtyFlags & DFE_DataBits) {
356
-        Win_CommConfig.dcb.ByteSize = (BYTE)Settings.DataBits;
357
-    }
358
-    if (settingsDirtyFlags & DFE_StopBits) {
359
-        switch (Settings.StopBits) {
360
-        case STOP_1:
361
-            Win_CommConfig.dcb.StopBits = ONESTOPBIT;
362
-            break;
363
-        case STOP_1_5:
364
-            Win_CommConfig.dcb.StopBits = ONE5STOPBITS;
365
-            break;
366
-        case STOP_2:
367
-            Win_CommConfig.dcb.StopBits = TWOSTOPBITS;
368
-            break;
369
-        }
370
-    }
371
-    if (settingsDirtyFlags & DFE_Flow) {
372
-        switch(Settings.FlowControl) {
373
-        /*no flow control*/
374
-        case FLOW_OFF:
375
-            Win_CommConfig.dcb.fOutxCtsFlow=FALSE;
376
-            Win_CommConfig.dcb.fRtsControl=RTS_CONTROL_DISABLE;
377
-            Win_CommConfig.dcb.fInX=FALSE;
378
-            Win_CommConfig.dcb.fOutX=FALSE;
379
-            break;
380
-        /*software (XON/XOFF) flow control*/
381
-        case FLOW_XONXOFF:
382
-            Win_CommConfig.dcb.fOutxCtsFlow=FALSE;
383
-            Win_CommConfig.dcb.fRtsControl=RTS_CONTROL_DISABLE;
384
-            Win_CommConfig.dcb.fInX=TRUE;
385
-            Win_CommConfig.dcb.fOutX=TRUE;
386
-            break;
387
-        /*hardware flow control*/
388
-        case FLOW_HARDWARE:
389
-            Win_CommConfig.dcb.fOutxCtsFlow=TRUE;
390
-            Win_CommConfig.dcb.fRtsControl=RTS_CONTROL_HANDSHAKE;
391
-            Win_CommConfig.dcb.fInX=FALSE;
392
-            Win_CommConfig.dcb.fOutX=FALSE;
393
-            break;
394
-        }
395
-    }
396
-
397
-    //fill struct : COMMTIMEOUTS
398
-    if (settingsDirtyFlags & DFE_TimeOut) {
399
-        if (_queryMode != QextSerialPort::EventDriven) {
400
-            int millisec = Settings.Timeout_Millisec;
401
-            if (millisec == -1) {
402
-                Win_CommTimeouts.ReadIntervalTimeout = MAXDWORD;
403
-                Win_CommTimeouts.ReadTotalTimeoutConstant = 0;
404
-            } else {
405
-                Win_CommTimeouts.ReadIntervalTimeout = millisec;
406
-                Win_CommTimeouts.ReadTotalTimeoutConstant = millisec;
407
-            }
408
-            Win_CommTimeouts.ReadTotalTimeoutMultiplier = 0;
409
-            Win_CommTimeouts.WriteTotalTimeoutMultiplier = millisec;
410
-            Win_CommTimeouts.WriteTotalTimeoutConstant = 0;
411
-        }
412
-        else {
413
-            Win_CommTimeouts.ReadIntervalTimeout = MAXDWORD;
414
-            Win_CommTimeouts.ReadTotalTimeoutMultiplier = 0;
415
-            Win_CommTimeouts.ReadTotalTimeoutConstant = 0;
416
-            Win_CommTimeouts.WriteTotalTimeoutMultiplier = 0;
417
-            Win_CommTimeouts.WriteTotalTimeoutConstant = 0;
418
-        }
419
-    }
420
-
421
-
422
-    if (settingsDirtyFlags & DFE_Settings_Mask)
423
-        SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
424
-    if ((settingsDirtyFlags & DFE_TimeOut))
425
-        SetCommTimeouts(Win_Handle, &Win_CommTimeouts);
426
-    settingsDirtyFlags = 0;
427
-}

+ 0
- 414
src/3rdparty/qextserialport/src/extserialport/qextserialport_win.cpp.orig View File

@@ -1,414 +0,0 @@
1
-/****************************************************************************
2
-** Copyright (c) 2000-2003 Wayne Roth
3
-** Copyright (c) 2004-2007 Stefan Sander
4
-** Copyright (c) 2007 Michal Policht
5
-** Copyright (c) 2008 Brandon Fosdick
6
-** Copyright (c) 2009-2010 Liam Staskawicz
7
-** Copyright (c) 2011 Debao Zhang
8
-** All right reserved.
9
-** Web: http://code.google.com/p/qextserialport/
10
-**
11
-** Permission is hereby granted, free of charge, to any person obtaining
12
-** a copy of this software and associated documentation files (the
13
-** "Software"), to deal in the Software without restriction, including
14
-** without limitation the rights to use, copy, modify, merge, publish,
15
-** distribute, sublicense, and/or sell copies of the Software, and to
16
-** permit persons to whom the Software is furnished to do so, subject to
17
-** the following conditions:
18
-**
19
-** The above copyright notice and this permission notice shall be
20
-** included in all copies or substantial portions of the Software.
21
-**
22
-** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23
-** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
-** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25
-** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26
-** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27
-** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28
-** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
-**
30
-****************************************************************************/
31
-
32
-#include "qextserialport.h"
33
-#include "qextserialport_p.h"
34
-#include <QtCore/QThread>
35
-#include <QtCore/QReadWriteLock>
36
-#include <QtCore/QMutexLocker>
37
-#include <QtCore/QDebug>
38
-#include <QtCore/QRegExp>
39
-#include <QtCore/QMetaType>
40
-#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
41
-#  include <QtCore/private/qwineventnotifier_p.h>
42
-#else
43
-#  include <QtCore/QWinEventNotifier>
44
-#endif
45
-
46
-void QextSerialPortPrivate::platformSpecificInit()
47
-{
48
-    Win_Handle=INVALID_HANDLE_VALUE;
49
-    ZeroMemory(&overlap, sizeof(OVERLAPPED));
50
-    overlap.hEvent = CreateEvent(NULL, true, false, NULL);
51
-    winEventNotifier = 0;
52
-    bytesToWriteLock = new QReadWriteLock;
53
-    _bytesToWrite = 0;
54
-}
55
-
56
-void QextSerialPortPrivate::platformSpecificDestruct() {
57
-    CloseHandle(overlap.hEvent);
58
-    delete bytesToWriteLock;
59
-}
60
-
61
-
62
-/*!
63
-    \internal
64
-    COM ports greater than 9 need \\.\ prepended
65
-
66
-    This is only need when open the port.
67
-*/
68
-static QString fullPortNameWin(const QString & name)
69
-{
70
-    QRegExp rx(QLatin1String("^COM(\\d+)"));
71
-    QString fullName(name);
72
-    if(fullName.contains(rx))
73
-        fullName.prepend(QLatin1String("\\\\.\\"));
74
-    return fullName;
75
-}
76
-
77
-bool QextSerialPortPrivate::open_sys(QIODevice::OpenMode mode)
78
-{
79
-    Q_Q(QextSerialPort);
80
-    DWORD confSize = sizeof(COMMCONFIG);
81
-    Win_CommConfig.dwSize = confSize;
82
-    DWORD dwFlagsAndAttributes = FILE_FLAG_OVERLAPPED;
83
-
84
-    /*open the port*/
85
-    Win_Handle=CreateFileW((wchar_t*)fullPortNameWin(port).utf16(), GENERIC_READ|GENERIC_WRITE,
86
-                           0, NULL, OPEN_EXISTING, dwFlagsAndAttributes, NULL);
87
-    if (Win_Handle!=INVALID_HANDLE_VALUE) {
88
-        q->setOpenMode(mode);
89
-        /*configure port settings*/
90
-        GetCommConfig(Win_Handle, &Win_CommConfig, &confSize);
91
-        GetCommState(Win_Handle, &(Win_CommConfig.dcb));
92
-
93
-        /*set up parameters*/
94
-        Win_CommConfig.dcb.fBinary=TRUE;
95
-        Win_CommConfig.dcb.fInX=FALSE;
96
-        Win_CommConfig.dcb.fOutX=FALSE;
97
-        Win_CommConfig.dcb.fAbortOnError=FALSE;
98
-        Win_CommConfig.dcb.fNull=FALSE;
99
-        /* Dtr default to true. See Issue 122*/
100
-        Win_CommConfig.dcb.fDtrControl=TRUE;
101
-        /*flush all settings*/
102
-        settingsDirtyFlags = DFE_ALL;
103
-        updatePortSettings();
104
-
105
-        //init event driven approach
106
-<<<<<<< local
107
-        if (_queryMode == QextSerialPort::EventDriven) {
108
-            if (!SetCommMask( Win_Handle, EV_TXEMPTY | EV_RXCHAR | EV_DSR)) {
109
-                QESP_WARNING()<<"failed to set Comm Mask. Error code:"<<GetLastError();
110
-                return false;
111
-            }
112
-            winEventNotifier = new WinEventNotifier(overlap.hEvent);
113
-            qRegisterMetaType<HANDLE>("HANDLE");
114
-            q->connect(winEventNotifier, SIGNAL(activated(HANDLE)), q, SLOT(_q_onWinEvent(HANDLE)), Qt::DirectConnection);
115
-            WaitCommEvent(Win_Handle, &eventMask, &overlap);
116
-=======
117
-        if (!SetCommMask( Win_Handle, EV_TXEMPTY | EV_RXCHAR | EV_DSR)) {
118
-            QESP_WARNING()<<"failed to set Comm Mask. Error code:"<<GetLastError();
119
-            return false;
120
->>>>>>> other
121
-        }
122
-        winEventNotifier = new QWinEventNotifier(overlap.hEvent, q);
123
-        qRegisterMetaType<HANDLE>("HANDLE");
124
-        q->connect(winEventNotifier, SIGNAL(activated(HANDLE)), q, SLOT(_q_onWinEvent(HANDLE)), Qt::DirectConnection);
125
-        WaitCommEvent(Win_Handle, &eventMask, &overlap);
126
-        return true;
127
-    }
128
-    return false;
129
-}
130
-
131
-bool QextSerialPortPrivate::close_sys()
132
-{
133
-    flush_sys();
134
-    CancelIo(Win_Handle);
135
-    if (CloseHandle(Win_Handle))
136
-        Win_Handle = INVALID_HANDLE_VALUE;
137
-    if (winEventNotifier){
138
-        winEventNotifier->setEnabled(false);
139
-        winEventNotifier->deleteLater();
140
-        winEventNotifier = 0;
141
-    }
142
-    _bytesToWrite = 0;
143
-
144
-    foreach(OVERLAPPED* o, pendingWrites) {
145
-        CloseHandle(o->hEvent);
146
-        delete o;
147
-    }
148
-    pendingWrites.clear();
149
-    return true;
150
-}
151
-
152
-bool QextSerialPortPrivate::flush_sys()
153
-{
154
-    FlushFileBuffers(Win_Handle);
155
-    return true;
156
-}
157
-
158
-qint64 QextSerialPortPrivate::bytesAvailable_sys() const
159
-{
160
-    DWORD Errors;
161
-    COMSTAT Status;
162
-    if (ClearCommError(Win_Handle, &Errors, &Status)) {
163
-        return Status.cbInQue;
164
-    }
165
-    return (qint64)-1;
166
-}
167
-
168
-/*
169
-    Translates a system-specific error code to a QextSerialPort error code.  Used internally.
170
-*/
171
-void QextSerialPortPrivate::translateError(ulong error) {
172
-    if (error&CE_BREAK) {
173
-        lastErr=QextSerialPort::E_BREAK_CONDITION;
174
-    }
175
-    else if (error&CE_FRAME) {
176
-        lastErr=QextSerialPort::E_FRAMING_ERROR;
177
-    }
178
-    else if (error&CE_IOE) {
179
-        lastErr=QextSerialPort::E_IO_ERROR;
180
-    }
181
-    else if (error&CE_MODE) {
182
-        lastErr=QextSerialPort::E_INVALID_FD;
183
-    }
184
-    else if (error&CE_OVERRUN) {
185
-        lastErr=QextSerialPort::E_BUFFER_OVERRUN;
186
-    }
187
-    else if (error&CE_RXPARITY) {
188
-        lastErr=QextSerialPort::E_RECEIVE_PARITY_ERROR;
189
-    }
190
-    else if (error&CE_RXOVER) {
191
-        lastErr=QextSerialPort::E_RECEIVE_OVERFLOW;
192
-    }
193
-    else if (error&CE_TXFULL) {
194
-        lastErr=QextSerialPort::E_TRANSMIT_OVERFLOW;
195
-    }
196
-}
197
-
198
-/*
199
-    Reads a block of data from the serial port.  This function will read at most maxlen bytes from
200
-    the serial port and place them in the buffer pointed to by data.  Return value is the number of
201
-    bytes actually read, or -1 on error.
202
-    
203
-    \warning before calling this function ensure that serial port associated with this class
204
-    is currently open (use isOpen() function to check if port is open).
205
-*/
206
-qint64 QextSerialPortPrivate::readData_sys(char *data, qint64 maxSize)
207
-{
208
-    DWORD bytesRead = 0;
209
-    bool failed = false;
210
-    OVERLAPPED overlapRead;
211
-    ZeroMemory(&overlapRead, sizeof(OVERLAPPED));
212
-    if (!ReadFile(Win_Handle, (void*)data, (DWORD)maxSize, & bytesRead, & overlapRead)) {
213
-        if (GetLastError() == ERROR_IO_PENDING)
214
-            GetOverlappedResult(Win_Handle, & overlapRead, & bytesRead, true);
215
-        else
216
-            failed = true;
217
-    }
218
-
219
-    if (!failed)
220
-        return (qint64)bytesRead;
221
-
222
-    lastErr = QextSerialPort::E_READ_FAILED;
223
-    return -1;
224
-}
225
-
226
-/*
227
-    Writes a block of data to the serial port.  This function will write len bytes
228
-    from the buffer pointed to by data to the serial port.  Return value is the number
229
-    of bytes actually written, or -1 on error.
230
-    
231
-    \warning before calling this function ensure that serial port associated with this class
232
-    is currently open (use isOpen() function to check if port is open).
233
-*/
234
-qint64 QextSerialPortPrivate::writeData_sys(const char *data, qint64 maxSize)
235
-{
236
-    DWORD bytesWritten = 0;
237
-    bool failed = false;
238
-    OVERLAPPED* newOverlapWrite = new OVERLAPPED;
239
-    ZeroMemory(newOverlapWrite, sizeof(OVERLAPPED));
240
-    newOverlapWrite->hEvent = CreateEvent(NULL, true, false, NULL);
241
-    if (WriteFile(Win_Handle, (void*)data, (DWORD)maxSize, & bytesWritten, newOverlapWrite)) {
242
-        CloseHandle(newOverlapWrite->hEvent);
243
-        delete newOverlapWrite;
244
-    }
245
-    else if (GetLastError() == ERROR_IO_PENDING) {
246
-        // writing asynchronously...not an error
247
-        QWriteLocker writelocker(bytesToWriteLock);
248
-        _bytesToWrite += maxSize;
249
-        pendingWrites.append(newOverlapWrite);
250
-    }
251
-    else {
252
-        QESP_WARNING()<<"QextSerialPort write error:"<<GetLastError();
253
-        failed = true;
254
-        if(!CancelIo(newOverlapWrite->hEvent))
255
-            QESP_WARNING("QextSerialPort: couldn't cancel IO");
256
-        if(!CloseHandle(newOverlapWrite->hEvent))
257
-            QESP_WARNING("QextSerialPort: couldn't close OVERLAPPED handle");
258
-        delete newOverlapWrite;
259
-    }
260
-
261
-    if (!failed)
262
-        return (qint64)bytesWritten;
263
-
264
-    lastErr = QextSerialPort::E_WRITE_FAILED;
265
-    return -1;
266
-}
267
-
268
-void QextSerialPortPrivate::setDtr_sys(bool set) {
269
-    EscapeCommFunction(Win_Handle, set ? SETDTR : CLRDTR);
270
-}
271
-
272
-void QextSerialPortPrivate::setRts_sys(bool set) {
273
-    EscapeCommFunction(Win_Handle, set ? SETRTS : CLRRTS);
274
-}
275
-
276
-ulong QextSerialPortPrivate::lineStatus_sys(void) {
277
-    unsigned long Status=0, Temp=0;
278
-    GetCommModemStatus(Win_Handle, &Temp);
279
-    if (Temp & MS_CTS_ON) Status|=QextSerialPort::LS_CTS;
280
-    if (Temp & MS_DSR_ON) Status|=QextSerialPort::LS_DSR;
281
-    if (Temp & MS_RING_ON) Status|=QextSerialPort::LS_RI;
282
-    if (Temp & MS_RLSD_ON) Status|=QextSerialPort::LS_DCD;
283
-    return Status;
284
-}
285
-
286
-/*
287
-  Triggered when there's activity on our HANDLE.
288
-*/
289
-void QextSerialPortPrivate::_q_onWinEvent(HANDLE h)
290
-{
291
-    Q_Q(QextSerialPort);
292
-    if(h == overlap.hEvent) {
293
-        if (eventMask & EV_RXCHAR) {
294
-            if (q->sender() != q && bytesAvailable_sys() > 0)
295
-                _q_canRead();
296
-        }
297
-        if (eventMask & EV_TXEMPTY) {
298
-            /*
299
-              A write completed.  Run through the list of OVERLAPPED writes, and if
300
-              they completed successfully, take them off the list and delete them.
301
-              Otherwise, leave them on there so they can finish.
302
-            */
303
-            qint64 totalBytesWritten = 0;
304
-            QList<OVERLAPPED*> overlapsToDelete;
305
-            foreach(OVERLAPPED* o, pendingWrites) {
306
-                DWORD numBytes = 0;
307
-                if (GetOverlappedResult(Win_Handle, o, & numBytes, false)) {
308
-                    overlapsToDelete.append(o);
309
-                    totalBytesWritten += numBytes;
310
-                } else if( GetLastError() != ERROR_IO_INCOMPLETE ) {
311
-                    overlapsToDelete.append(o);
312
-                    QESP_WARNING()<<"CommEvent overlapped write error:" << GetLastError();
313
-                }
314
-            }
315
-
316
-            if (q->sender() != q && totalBytesWritten > 0) {
317
-                QWriteLocker writelocker(bytesToWriteLock);
318
-                Q_EMIT q->bytesWritten(totalBytesWritten);
319
-                _bytesToWrite = 0;
320
-            }
321
-
322
-            foreach(OVERLAPPED* o, overlapsToDelete) {
323
-                OVERLAPPED *toDelete = pendingWrites.takeAt(pendingWrites.indexOf(o));
324
-                CloseHandle(toDelete->hEvent);
325
-                delete toDelete;
326
-            }
327
-        }
328
-        if (eventMask & EV_DSR) {
329
-            if (lineStatus_sys() & QextSerialPort::LS_DSR)
330
-                Q_EMIT q->dsrChanged(true);
331
-            else
332
-                Q_EMIT q->dsrChanged(false);
333
-        }
334
-    }
335
-    WaitCommEvent(Win_Handle, &eventMask, &overlap);
336
-}
337
-
338
-void QextSerialPortPrivate::updatePortSettings()
339
-{
340
-    if (!q_ptr->isOpen() || !settingsDirtyFlags)
341
-        return;
342
-
343
-    //fill struct : COMMCONFIG
344
-    if (settingsDirtyFlags & DFE_BaudRate) {
345
-        Win_CommConfig.dcb.BaudRate = Settings.BaudRate;
346
-    }
347
-    if (settingsDirtyFlags & DFE_Parity) {
348
-        Win_CommConfig.dcb.Parity = (BYTE)Settings.Parity;
349
-        Win_CommConfig.dcb.fParity = (Settings.Parity == QextSerialPort::PAR_NONE) ? FALSE : TRUE;
350
-    }
351
-    if (settingsDirtyFlags & DFE_DataBits) {
352
-        Win_CommConfig.dcb.ByteSize = (BYTE)Settings.DataBits;
353
-    }
354
-    if (settingsDirtyFlags & DFE_StopBits) {
355
-        switch (Settings.StopBits) {
356
-        case QextSerialPort::STOP_1:
357
-            Win_CommConfig.dcb.StopBits = ONESTOPBIT;
358
-            break;
359
-        case QextSerialPort::STOP_1_5:
360
-            Win_CommConfig.dcb.StopBits = ONE5STOPBITS;
361
-            break;
362
-        case QextSerialPort::STOP_2:
363
-            Win_CommConfig.dcb.StopBits = TWOSTOPBITS;
364
-            break;
365
-        }
366
-    }
367
-    if (settingsDirtyFlags & DFE_Flow) {
368
-        switch(Settings.FlowControl) {
369
-        /*no flow control*/
370
-        case QextSerialPort::FLOW_OFF:
371
-            Win_CommConfig.dcb.fOutxCtsFlow=FALSE;
372
-            Win_CommConfig.dcb.fRtsControl=RTS_CONTROL_DISABLE;
373
-            Win_CommConfig.dcb.fInX=FALSE;
374
-            Win_CommConfig.dcb.fOutX=FALSE;
375
-            break;
376
-        /*software (XON/XOFF) flow control*/
377
-        case QextSerialPort::FLOW_XONXOFF:
378
-            Win_CommConfig.dcb.fOutxCtsFlow=FALSE;
379
-            Win_CommConfig.dcb.fRtsControl=RTS_CONTROL_DISABLE;
380
-            Win_CommConfig.dcb.fInX=TRUE;
381
-            Win_CommConfig.dcb.fOutX=TRUE;
382
-            break;
383
-        /*hardware flow control*/
384
-        case QextSerialPort::FLOW_HARDWARE:
385
-            Win_CommConfig.dcb.fOutxCtsFlow=TRUE;
386
-            Win_CommConfig.dcb.fRtsControl=RTS_CONTROL_HANDSHAKE;
387
-            Win_CommConfig.dcb.fInX=FALSE;
388
-            Win_CommConfig.dcb.fOutX=FALSE;
389
-            break;
390
-        }
391
-    }
392
-
393
-    //fill struct : COMMTIMEOUTS
394
-    if (settingsDirtyFlags & DFE_TimeOut) {
395
-        int millisec = Settings.Timeout_Millisec;
396
-        if (millisec == -1) {
397
-            Win_CommTimeouts.ReadIntervalTimeout = MAXDWORD;
398
-            Win_CommTimeouts.ReadTotalTimeoutConstant = 0;
399
-        } else {
400
-            Win_CommTimeouts.ReadIntervalTimeout = millisec;
401
-            Win_CommTimeouts.ReadTotalTimeoutConstant = millisec;
402
-        }
403
-        Win_CommTimeouts.ReadTotalTimeoutMultiplier = 0;
404
-        Win_CommTimeouts.WriteTotalTimeoutMultiplier = millisec;
405
-        Win_CommTimeouts.WriteTotalTimeoutConstant = 0;
406
-    }
407
-
408
-
409
-    if (settingsDirtyFlags & DFE_Settings_Mask)
410
-        SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
411
-    if ((settingsDirtyFlags & DFE_TimeOut))
412
-        SetCommTimeouts(Win_Handle, &Win_CommTimeouts);
413
-    settingsDirtyFlags = 0;
414
-}

+ 10
- 14
src/3rdparty/qextserialport/src/qextserialenumerator.cpp View File

@@ -39,12 +39,12 @@
39 39
 QextSerialEnumeratorPrivate::QextSerialEnumeratorPrivate(QextSerialEnumerator *enumrator)
40 40
     :q_ptr(enumrator)
41 41
 {
42
-    platformSpecificInit();
42
+    init_sys();
43 43
 }
44 44
 
45 45
 QextSerialEnumeratorPrivate::~QextSerialEnumeratorPrivate()
46 46
 {
47
-    platformSpecificDestruct();
47
+    destroy_sys();
48 48
 }
49 49
 
50 50
 /*!
@@ -75,7 +75,7 @@ QextSerialEnumeratorPrivate::~QextSerialEnumeratorPrivate()
75 75
     \bold Example
76 76
     \code
77 77
     QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
78
-    foreach( QextPortInfo port, ports ) {
78
+    foreach (QextPortInfo port, ports) {
79 79
         // inspect port...
80 80
     }
81 81
     \endcode
@@ -86,7 +86,7 @@ QextSerialEnumeratorPrivate::~QextSerialEnumeratorPrivate()
86 86
   
87 87
     \bold Example
88 88
     \code
89
-    QextSerialEnumerator* enumerator = new QextSerialEnumerator();
89
+    QextSerialEnumerator *enumerator = new QextSerialEnumerator();
90 90
     connect(enumerator, SIGNAL(deviceDiscovered(const QextPortInfo &)),
91 91
                myClass, SLOT(onDeviceDiscovered(const QextPortInfo &)));
92 92
     connect(enumerator, SIGNAL(deviceRemoved(const QextPortInfo &)),
@@ -103,7 +103,7 @@ QextSerialEnumeratorPrivate::~QextSerialEnumeratorPrivate()
103 103
 */
104 104
 
105 105
 /*!
106
-    \fn void QextSerialEnumerator::deviceDiscovered( const QextPortInfo & info )
106
+    \fn void QextSerialEnumerator::deviceDiscovered(const QextPortInfo &info)
107 107
     A new device has been connected to the system.
108 108
   
109 109
     setUpNotifications() must be called first to enable event-driven device notifications.
@@ -113,7 +113,7 @@ QextSerialEnumeratorPrivate::~QextSerialEnumeratorPrivate()
113 113
 */
114 114
 
115 115
 /*!
116
-   \fn void QextSerialEnumerator::deviceRemoved( const QextPortInfo & info );
116
+   \fn void QextSerialEnumerator::deviceRemoved(const QextPortInfo &info);
117 117
     A device has been disconnected from the system.
118 118
   
119 119
     setUpNotifications() must be called first to enable event-driven device notifications.
@@ -128,14 +128,14 @@ QextSerialEnumeratorPrivate::~QextSerialEnumeratorPrivate()
128 128
 QextSerialEnumerator::QextSerialEnumerator(QObject *parent)
129 129
     :QObject(parent), d_ptr(new QextSerialEnumeratorPrivate(this))
130 130
 {
131
-    if( !QMetaType::isRegistered( QMetaType::type("QextPortInfo") ) )
131
+    if (!QMetaType::isRegistered(QMetaType::type("QextPortInfo")))
132 132
         qRegisterMetaType<QextPortInfo>("QextPortInfo");
133 133
 }
134 134
 
135 135
 /*!
136 136
    Destructs the QextSerialEnumerator object.
137 137
 */
138
-QextSerialEnumerator::~QextSerialEnumerator( )
138
+QextSerialEnumerator::~QextSerialEnumerator()
139 139
 {
140 140
     delete d_ptr;
141 141
 }
@@ -147,9 +147,6 @@ QextSerialEnumerator::~QextSerialEnumerator( )
147 147
 */
148 148
 QList<QextPortInfo> QextSerialEnumerator::getPorts()
149 149
 {
150
-#if defined(Q_OS_UNIX) && !defined(Q_OS_LINUX) && !defined(Q_OS_MAC)
151
-    qCritical("Enumeration for POSIX systems (except Linux) is not implemented yet.");
152
-#endif
153 150
     return QextSerialEnumeratorPrivate::getPorts_sys();
154 151
 }
155 152
 
@@ -158,10 +155,9 @@ QList<QextPortInfo> QextSerialEnumerator::getPorts()
158 155
 */
159 156
 void QextSerialEnumerator::setUpNotifications()
160 157
 {
161
-#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
162
-    qCritical("Notifications for *Nix/FreeBSD are not implemented yet");
163
-#endif
164 158
     Q_D(QextSerialEnumerator);
165 159
     if (!d->setUpNotifications_sys(true))
166 160
         QESP_WARNING("Setup Notification Failed...");
167 161
 }
162
+
163
+#include "moc_qextserialenumerator.cpp"

+ 6
- 3
src/3rdparty/qextserialport/src/qextserialenumerator.h View File

@@ -51,18 +51,21 @@ class QEXTSERIALPORT_EXPORT QextSerialEnumerator : public QObject
51 51
     Q_OBJECT
52 52
     Q_DECLARE_PRIVATE(QextSerialEnumerator)
53 53
 public:
54
-    QextSerialEnumerator(QObject * parent=0);
54
+    QextSerialEnumerator(QObject *parent=0);
55 55
     ~QextSerialEnumerator();
56 56
 
57 57
     static QList<QextPortInfo> getPorts();
58 58
     void setUpNotifications();
59 59
 
60 60
 Q_SIGNALS:
61
-    void deviceDiscovered(const QextPortInfo & info);
62
-    void deviceRemoved(const QextPortInfo & info);
61
+    void deviceDiscovered(const QextPortInfo &info);
62
+    void deviceRemoved(const QextPortInfo &info);
63 63
 
64 64
 private:
65 65
     Q_DISABLE_COPY(QextSerialEnumerator)
66
+#if defined(Q_OS_LINUX) && !defined(QESP_NO_UDEV)
67
+    Q_PRIVATE_SLOT(d_func(), void _q_deviceEvent())
68
+#endif
66 69
     QextSerialEnumeratorPrivate *d_ptr;
67 70
 };
68 71
 

+ 210
- 0
src/3rdparty/qextserialport/src/qextserialenumerator_linux.cpp View File

@@ -0,0 +1,210 @@
1
+/****************************************************************************
2
+** Copyright (c) 2000-2003 Wayne Roth
3
+** Copyright (c) 2004-2007 Stefan Sander
4
+** Copyright (c) 2007 Michal Policht
5
+** Copyright (c) 2008 Brandon Fosdick
6
+** Copyright (c) 2009-2010 Liam Staskawicz
7
+** Copyright (c) 2011 Debao Zhang
8
+** Copyright (c) 2012 Doug Brown
9
+** All right reserved.
10
+** Web: http://code.google.com/p/qextserialport/
11
+**
12
+** Permission is hereby granted, free of charge, to any person obtaining
13
+** a copy of this software and associated documentation files (the
14
+** "Software"), to deal in the Software without restriction, including
15
+** without limitation the rights to use, copy, modify, merge, publish,
16
+** distribute, sublicense, and/or sell copies of the Software, and to
17
+** permit persons to whom the Software is furnished to do so, subject to
18
+** the following conditions:
19
+**
20
+** The above copyright notice and this permission notice shall be
21
+** included in all copies or substantial portions of the Software.
22
+**
23
+** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
+** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27
+** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28
+** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29
+** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
+**
31
+****************************************************************************/
32
+
33
+#include "qextserialenumerator.h"
34
+#include "qextserialenumerator_p.h"
35
+#include <QtCore/QDebug>
36
+#include <QtCore/QStringList>
37
+#include <QtCore/QDir>
38
+
39
+void QextSerialEnumeratorPrivate::init_sys()
40
+{
41
+#ifndef QESP_NO_UDEV
42
+    monitor = NULL;
43
+    notifierFd = -1;
44
+    notifier = NULL;
45
+
46
+    udev = udev_new();
47
+    if (!udev)
48
+        qCritical() << "Unable to initialize udev notifications";
49
+#endif
50
+}
51
+
52
+void QextSerialEnumeratorPrivate::destroy_sys()
53
+{
54
+#ifndef QESP_NO_UDEV
55
+    if (notifier) {
56
+        notifier->setEnabled(false);
57
+        delete notifier;
58
+    }
59
+
60
+    if (monitor)
61
+        udev_monitor_unref(monitor);
62
+
63
+    if (udev)
64
+        udev_unref(udev);
65
+#endif
66
+}
67
+
68
+#ifndef QESP_NO_UDEV
69
+static QextPortInfo portInfoFromDevice(struct udev_device *dev)
70
+{
71
+    QString vendor = QString::fromLatin1(udev_device_get_property_value(dev, "ID_VENDOR_ID"));
72
+    QString product = QString::fromLatin1(udev_device_get_property_value(dev, "ID_MODEL_ID"));
73
+
74
+    QextPortInfo pi;
75
+    pi.vendorID = vendor.toInt(0, 16);
76
+    pi.productID = product.toInt(0, 16);
77
+    pi.portName = QString::fromLatin1(udev_device_get_devnode(dev));
78
+    pi.physName = pi.portName;
79
+
80
+    return pi;
81
+}
82
+#endif
83
+
84
+QList<QextPortInfo> QextSerialEnumeratorPrivate::getPorts_sys()
85
+{
86
+    QList<QextPortInfo> infoList;
87
+#ifndef QESP_NO_UDEV
88
+    struct udev *ud = udev_new();
89
+    if (!ud) {
90
+        qCritical() << "Unable to enumerate ports because udev is not initialized.";
91
+        return infoList;
92
+    }
93
+
94
+    struct udev_enumerate *enumerate = udev_enumerate_new(ud);
95
+    udev_enumerate_add_match_subsystem(enumerate, "tty");
96
+    udev_enumerate_scan_devices(enumerate);
97
+    struct udev_list_entry *list = udev_enumerate_get_list_entry(enumerate);
98
+    struct udev_list_entry *entry;
99
+    udev_list_entry_foreach(entry, list) {
100
+        const char *path;
101
+        struct udev_device *dev;
102
+
103
+        // Have to grab the actual udev device here...
104
+        path = udev_list_entry_get_name(entry);
105
+        dev = udev_device_new_from_syspath(ud, path);
106
+
107
+        infoList.append(portInfoFromDevice(dev));
108
+
109
+        // Done with this device
110
+        udev_device_unref(dev);
111
+    }
112
+    // Done with the list and this udev
113
+    udev_enumerate_unref(enumerate);
114
+    udev_unref(ud);
115
+#else
116
+    QStringList portNamePrefixes, portNameList;
117
+    portNamePrefixes << QLatin1String("ttyS*"); // list normal serial ports first
118
+
119
+    QDir dir(QLatin1String("/dev"));
120
+    portNameList = dir.entryList(portNamePrefixes, (QDir::System | QDir::Files), QDir::Name);
121
+
122
+    // remove the values which are not serial ports for e.g.  /dev/ttysa
123
+    for (int i = 0; i < portNameList.size(); i++) {
124
+        bool ok;
125
+        QString current = portNameList.at(i);
126
+        // remove the ttyS part, and check, if the other part is a number
127
+        current.remove(0,4).toInt(&ok, 10);
128
+        if (!ok) {
129
+            portNameList.removeAt(i);
130
+            i--;
131
+        }
132
+    }
133
+
134
+    // get the non standard serial ports names
135
+    // (USB-serial, bluetooth-serial, 18F PICs, and so on)
136
+    // if you know an other name prefix for serial ports please let us know
137
+    portNamePrefixes.clear();
138
+    portNamePrefixes << QLatin1String("ttyACM*") << QLatin1String("ttyUSB*") << QLatin1String("rfcomm*");
139
+    portNameList += dir.entryList(portNamePrefixes, (QDir::System | QDir::Files), QDir::Name);
140
+
141
+    foreach (QString str , portNameList) {
142
+        QextPortInfo inf;
143
+        inf.physName = QLatin1String("/dev/")+str;
144
+        inf.portName = str;
145
+
146
+        if (str.contains(QLatin1String("ttyS"))) {
147
+            inf.friendName = QLatin1String("Serial port ")+str.remove(0, 4);
148
+        }
149
+        else if (str.contains(QLatin1String("ttyUSB"))) {
150
+            inf.friendName = QLatin1String("USB-serial adapter ")+str.remove(0, 6);
151
+        }
152
+        else if (str.contains(QLatin1String("rfcomm"))) {
153
+            inf.friendName = QLatin1String("Bluetooth-serial adapter ")+str.remove(0, 6);
154
+        }
155
+        inf.enumName = QLatin1String("/dev"); // is there a more helpful name for this?
156
+        infoList.append(inf);
157
+    }
158
+#endif
159
+
160
+    return infoList;
161
+}
162
+
163
+bool QextSerialEnumeratorPrivate::setUpNotifications_sys(bool setup)
164
+{
165
+    Q_UNUSED(setup);
166
+#ifndef QESP_NO_UDEV
167
+    Q_Q(QextSerialEnumerator);
168
+    if (!udev) {
169
+        qCritical() << "Unable to initialize notifications because udev is not initialized.";
170
+        return false;
171
+    }
172
+
173
+    // Emit signals immediately for devices already connected (Windows version seems to behave
174
+    // this way)
175
+    foreach (QextPortInfo i, getPorts_sys())
176
+        Q_EMIT q->deviceDiscovered(i);
177
+
178
+    // Look for tty devices from udev.
179
+    monitor = udev_monitor_new_from_netlink(udev, "udev");
180
+    udev_monitor_filter_add_match_subsystem_devtype(monitor, "tty", NULL);
181
+    udev_monitor_enable_receiving(monitor);
182
+    notifierFd = udev_monitor_get_fd(monitor);
183
+    notifier = new QSocketNotifier(notifierFd, QSocketNotifier::Read);
184
+    q->connect(notifier, SIGNAL(activated(int)), q, SLOT(_q_deviceEvent()));
185
+    notifier->setEnabled(true);
186
+
187
+    return true;
188
+#else
189
+    return false;
190
+#endif
191
+}
192
+
193
+#ifndef QESP_NO_UDEV
194
+void QextSerialEnumeratorPrivate::_q_deviceEvent()
195
+{
196
+    Q_Q(QextSerialEnumerator);
197
+    struct udev_device *dev = udev_monitor_receive_device(monitor);
198
+    if (dev) {
199
+        QextPortInfo pi = portInfoFromDevice(dev);
200
+        QLatin1String action(udev_device_get_action(dev));
201
+
202
+        if (action == QLatin1String("add"))
203
+            Q_EMIT q->deviceDiscovered(pi);
204
+        else if (action == QLatin1String("remove"))
205
+            Q_EMIT q->deviceRemoved(pi);
206
+
207
+        udev_device_unref(dev);
208
+    }
209
+}
210
+#endif

+ 41
- 47
src/3rdparty/qextserialport/src/qextserialenumerator_osx.cpp View File

@@ -36,13 +36,13 @@
36 36
 #include <CoreFoundation/CFNumber.h>
37 37
 #include <sys/param.h>
38 38
 
39
-void QextSerialEnumeratorPrivate::platformSpecificInit()
39
+void QextSerialEnumeratorPrivate::init_sys()
40 40
 {
41 41
 }
42 42
 
43
-void QextSerialEnumeratorPrivate::platformSpecificDestruct()
43
+void QextSerialEnumeratorPrivate::destroy_sys()
44 44
 {
45
-    IONotificationPortDestroy( notificationPortRef );
45
+    IONotificationPortDestroy(notificationPortRef);
46 46
 }
47 47
 
48 48
 // static
@@ -54,14 +54,14 @@ QList<QextPortInfo> QextSerialEnumeratorPrivate::getPorts_sys()
54 54
     CFMutableDictionaryRef matchingDictionary;
55 55
 
56 56
     // first try to get any serialbsd devices, then try any USBCDC devices
57
-    if( !(matchingDictionary = IOServiceMatching(kIOSerialBSDServiceValue) ) ) {
57
+    if (!(matchingDictionary = IOServiceMatching(kIOSerialBSDServiceValue))) {
58 58
         QESP_WARNING("IOServiceMatching returned a NULL dictionary.");
59 59
         return infoList;
60 60
     }
61 61
     CFDictionaryAddValue(matchingDictionary, CFSTR(kIOSerialBSDTypeKey), CFSTR(kIOSerialBSDAllTypes));
62 62
 
63 63
     // then create the iterator with all the matching devices
64
-    if( IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDictionary, &serialPortIterator) != KERN_SUCCESS ) {
64
+    if (IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDictionary, &serialPortIterator) != KERN_SUCCESS) {
65 65
         qCritical() << "IOServiceGetMatchingServices failed, returned" << kernResult;
66 66
         return infoList;
67 67
     }
@@ -69,12 +69,12 @@ QList<QextPortInfo> QextSerialEnumeratorPrivate::getPorts_sys()
69 69
     IOObjectRelease(serialPortIterator);
70 70
     serialPortIterator = 0;
71 71
 
72
-    if( !(matchingDictionary = IOServiceNameMatching("AppleUSBCDC")) ) {
72
+    if (!(matchingDictionary = IOServiceNameMatching("AppleUSBCDC"))) {
73 73
         QESP_WARNING("IOServiceNameMatching returned a NULL dictionary.");
74 74
         return infoList;
75 75
     }
76 76
 
77
-    if( IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDictionary, &serialPortIterator) != KERN_SUCCESS ) {
77
+    if (IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDictionary, &serialPortIterator) != KERN_SUCCESS) {
78 78
         qCritical() << "IOServiceGetMatchingServices failed, returned" << kernResult;
79 79
         return infoList;
80 80
     }
@@ -84,21 +84,20 @@ QList<QextPortInfo> QextSerialEnumeratorPrivate::getPorts_sys()
84 84
     return infoList;
85 85
 }
86 86
 
87
-void QextSerialEnumeratorPrivate::iterateServicesOSX(io_object_t service, QList<QextPortInfo> & infoList)
87
+void QextSerialEnumeratorPrivate::iterateServicesOSX(io_object_t service, QList<QextPortInfo> &infoList)
88 88
 {
89 89
     // Iterate through all modems found.
90 90
     io_object_t usbService;
91
-    while( ( usbService = IOIteratorNext(service) ) )
92
-    {
91
+    while ((usbService = IOIteratorNext(service))) {
93 92
         QextPortInfo info;
94 93
         info.vendorID = 0;
95 94
         info.productID = 0;
96
-        getServiceDetailsOSX( usbService, &info );
95
+        getServiceDetailsOSX(usbService, &info);
97 96
         infoList.append(info);
98 97
     }
99 98
 }
100 99
 
101
-bool QextSerialEnumeratorPrivate::getServiceDetailsOSX( io_object_t service, QextPortInfo* portInfo )
100
+bool QextSerialEnumeratorPrivate::getServiceDetailsOSX(io_object_t service, QextPortInfo *portInfo)
102 101
 {
103 102
     bool retval = true;
104 103
     CFTypeRef bsdPathAsCFString = NULL;
@@ -113,9 +112,8 @@ bool QextSerialEnumeratorPrivate::getServiceDetailsOSX( io_object_t service, Qex
113 112
     // vendor/product IDs and the product name, if available
114 113
     io_registry_entry_t parent;
115 114
     kern_return_t kernResult = IORegistryEntryGetParentEntry(service, kIOServicePlane, &parent);
116
-    while( kernResult == KERN_SUCCESS && !vendorIdAsCFNumber && !productIdAsCFNumber )
117
-    {
118
-        if(!productNameAsCFString)
115
+    while (kernResult == KERN_SUCCESS && !vendorIdAsCFNumber && !productIdAsCFNumber) {
116
+        if (!productNameAsCFString)
119 117
             productNameAsCFString = IORegistryEntrySearchCFProperty(parent,
120 118
                                                                     kIOServicePlane,
121 119
                                                                     CFSTR("Product Name"),
@@ -134,39 +132,35 @@ bool QextSerialEnumeratorPrivate::getServiceDetailsOSX( io_object_t service, Qex
134 132
     }
135 133
 
136 134
     io_string_t ioPathName;
137
-    IORegistryEntryGetPath( service, kIOServicePlane, ioPathName );
135
+    IORegistryEntryGetPath(service, kIOServicePlane, ioPathName);
138 136
     portInfo->physName = ioPathName;
139 137
 
140
-    if( bsdPathAsCFString )
141
-    {
138
+    if (bsdPathAsCFString) {
142 139
         char path[MAXPATHLEN];
143
-        if( CFStringGetCString((CFStringRef)bsdPathAsCFString, path,
144
-                               PATH_MAX, kCFStringEncodingUTF8) )
140
+        if (CFStringGetCString((CFStringRef)bsdPathAsCFString, path,
141
+                               PATH_MAX, kCFStringEncodingUTF8))
145 142
             portInfo->portName = path;
146 143
         CFRelease(bsdPathAsCFString);
147 144
     }
148 145
 
149
-    if(productNameAsCFString)
150
-    {
146
+    if (productNameAsCFString) {
151 147
         char productName[MAXPATHLEN];
152
-        if( CFStringGetCString((CFStringRef)productNameAsCFString, productName,
153
-                               PATH_MAX, kCFStringEncodingUTF8) )
148
+        if (CFStringGetCString((CFStringRef)productNameAsCFString, productName,
149
+                               PATH_MAX, kCFStringEncodingUTF8))
154 150
             portInfo->friendName = productName;
155 151
         CFRelease(productNameAsCFString);
156 152
     }
157 153
 
158
-    if(vendorIdAsCFNumber)
159
-    {
154
+    if (vendorIdAsCFNumber) {
160 155
         SInt32 vID;
161
-        if(CFNumberGetValue((CFNumberRef)vendorIdAsCFNumber, kCFNumberSInt32Type, &vID))
156
+        if (CFNumberGetValue((CFNumberRef)vendorIdAsCFNumber, kCFNumberSInt32Type, &vID))
162 157
             portInfo->vendorID = vID;
163 158
         CFRelease(vendorIdAsCFNumber);
164 159
     }
165 160
 
166
-    if(productIdAsCFNumber)
167
-    {
161
+    if (productIdAsCFNumber) {
168 162
         SInt32 pID;
169
-        if(CFNumberGetValue((CFNumberRef)productIdAsCFNumber, kCFNumberSInt32Type, &pID))
163
+        if (CFNumberGetValue((CFNumberRef)productIdAsCFNumber, kCFNumberSInt32Type, &pID))
170 164
             portInfo->productID = pID;
171 165
         CFRelease(productIdAsCFNumber);
172 166
     }
@@ -175,17 +169,17 @@ bool QextSerialEnumeratorPrivate::getServiceDetailsOSX( io_object_t service, Qex
175 169
 }
176 170
 
177 171
 // IOKit callbacks registered via setupNotifications()
178
-void deviceDiscoveredCallbackOSX( void *ctxt, io_iterator_t serialPortIterator )
172
+void deviceDiscoveredCallbackOSX(void *ctxt, io_iterator_t serialPortIterator)
179 173
 {
180
-    QextSerialEnumeratorPrivate* d = (QextSerialEnumeratorPrivate*)ctxt;
174
+    QextSerialEnumeratorPrivate *d = (QextSerialEnumeratorPrivate *)ctxt;
181 175
     io_object_t serialService;
182 176
     while ((serialService = IOIteratorNext(serialPortIterator)))
183 177
         d->onDeviceDiscoveredOSX(serialService);
184 178
 }
185 179
 
186
-void deviceTerminatedCallbackOSX( void *ctxt, io_iterator_t serialPortIterator )
180
+void deviceTerminatedCallbackOSX(void *ctxt, io_iterator_t serialPortIterator)
187 181
 {
188
-    QextSerialEnumeratorPrivate* d = (QextSerialEnumeratorPrivate*)ctxt;
182
+    QextSerialEnumeratorPrivate *d = (QextSerialEnumeratorPrivate *)ctxt;
189 183
     io_object_t serialService;
190 184
     while ((serialService = IOIteratorNext(serialPortIterator)))
191 185
         d->onDeviceTerminatedOSX(serialService);
@@ -195,28 +189,28 @@ void deviceTerminatedCallbackOSX( void *ctxt, io_iterator_t serialPortIterator )
195 189
   A device has been discovered via IOKit.
196 190
   Create a QextPortInfo if possible, and emit the signal indicating that we've found it.
197 191
 */
198
-void QextSerialEnumeratorPrivate::onDeviceDiscoveredOSX( io_object_t service )
192
+void QextSerialEnumeratorPrivate::onDeviceDiscoveredOSX(io_object_t service)
199 193
 {
200 194
     Q_Q(QextSerialEnumerator);
201 195
     QextPortInfo info;
202 196
     info.vendorID = 0;
203 197
     info.productID = 0;
204
-    if( getServiceDetailsOSX( service, &info ) )
205
-        Q_EMIT q->deviceDiscovered( info );
198
+    if (getServiceDetailsOSX(service, &info))
199
+        Q_EMIT q->deviceDiscovered(info);
206 200
 }
207 201
 
208 202
 /*
209 203
   Notification via IOKit that a device has been removed.
210 204
   Create a QextPortInfo if possible, and emit the signal indicating that it's gone.
211 205
 */
212
-void QextSerialEnumeratorPrivate::onDeviceTerminatedOSX( io_object_t service )
206
+void QextSerialEnumeratorPrivate::onDeviceTerminatedOSX(io_object_t service)
213 207
 {
214 208
     Q_Q(QextSerialEnumerator);
215 209
     QextPortInfo info;
216 210
     info.vendorID = 0;
217 211
     info.productID = 0;
218
-    if( getServiceDetailsOSX( service, &info ) )
219
-        Q_EMIT q->deviceRemoved( info );
212
+    if (getServiceDetailsOSX(service, &info))
213
+        Q_EMIT q->deviceRemoved(info);
220 214
 }
221 215
 
222 216
 /*
@@ -225,7 +219,7 @@ void QextSerialEnumeratorPrivate::onDeviceTerminatedOSX( io_object_t service )
225 219
   to these notifications once to arm them, and discover any devices that
226 220
   are currently connected at the time notifications are setup.
227 221
 */
228
-bool QextSerialEnumeratorPrivate::setUpNotifications_sys(bool setup)
222
+bool QextSerialEnumeratorPrivate::setUpNotifications_sys(bool /*setup*/)
229 223
 {
230 224
     kern_return_t kernResult;
231 225
     mach_port_t masterPort;
@@ -246,7 +240,7 @@ bool QextSerialEnumeratorPrivate::setUpNotifications_sys(bool setup)
246 240
     else
247 241
         CFDictionarySetValue(classesToMatch, CFSTR(kIOSerialBSDTypeKey), CFSTR(kIOSerialBSDAllTypes));
248 242
 
249
-    if( !(cdcClassesToMatch = IOServiceNameMatching("AppleUSBCDC") ) ) {
243
+    if (!(cdcClassesToMatch = IOServiceNameMatching("AppleUSBCDC"))) {
250 244
         QESP_WARNING("couldn't create cdc matching dict");
251 245
         return false;
252 246
     }
@@ -256,7 +250,7 @@ bool QextSerialEnumeratorPrivate::setUpNotifications_sys(bool setup)
256 250
     cdcClassesToMatch = (CFMutableDictionaryRef) CFRetain(cdcClassesToMatch);
257 251
 
258 252
     notificationPortRef = IONotificationPortCreate(masterPort);
259
-    if(notificationPortRef == NULL) {
253
+    if (notificationPortRef == NULL) {
260 254
         qDebug("IONotificationPortCreate return a NULL IONotificationPortRef.");
261 255
         return false;
262 256
     }
@@ -277,7 +271,7 @@ bool QextSerialEnumeratorPrivate::setUpNotifications_sys(bool setup)
277 271
     }
278 272
 
279 273
     // arm the callback, and grab any devices that are already connected
280
-    deviceDiscoveredCallbackOSX( this, portIterator );
274
+    deviceDiscoveredCallbackOSX(this, portIterator);
281 275
 
282 276
     kernResult = IOServiceAddMatchingNotification(notificationPortRef, kIOMatchedNotification, cdcClassesToMatch,
283 277
                                                   deviceDiscoveredCallbackOSX, this, &portIterator);
@@ -287,7 +281,7 @@ bool QextSerialEnumeratorPrivate::setUpNotifications_sys(bool setup)
287 281
     }
288 282
 
289 283
     // arm the callback, and grab any devices that are already connected
290
-    deviceDiscoveredCallbackOSX( this, portIterator );
284
+    deviceDiscoveredCallbackOSX(this, portIterator);
291 285
 
292 286
     kernResult = IOServiceAddMatchingNotification(notificationPortRef, kIOTerminatedNotification, classesToMatch,
293 287
                                                   deviceTerminatedCallbackOSX, this, &portIterator);
@@ -297,7 +291,7 @@ bool QextSerialEnumeratorPrivate::setUpNotifications_sys(bool setup)
297 291
     }
298 292
 
299 293
     // arm the callback, and clear any devices that are terminated
300
-    deviceTerminatedCallbackOSX( this, portIterator );
294
+    deviceTerminatedCallbackOSX(this, portIterator);
301 295
 
302 296
     kernResult = IOServiceAddMatchingNotification(notificationPortRef, kIOTerminatedNotification, cdcClassesToMatch,
303 297
                                                   deviceTerminatedCallbackOSX, this, &portIterator);
@@ -307,7 +301,7 @@ bool QextSerialEnumeratorPrivate::setUpNotifications_sys(bool setup)
307 301
     }
308 302
 
309 303
     // arm the callback, and clear any devices that are terminated
310
-    deviceTerminatedCallbackOSX( this, portIterator );
304
+    deviceTerminatedCallbackOSX(this, portIterator);
311 305
     return true;
312 306
 }
313 307
 

+ 41
- 21
src/3rdparty/qextserialport/src/qextserialenumerator_p.h View File

@@ -5,6 +5,7 @@
5 5
 ** Copyright (c) 2008 Brandon Fosdick
6 6
 ** Copyright (c) 2009-2010 Liam Staskawicz
7 7
 ** Copyright (c) 2011 Debao Zhang
8
+** Copyright (c) 2012 Doug Brown
8 9
 ** All right reserved.
9 10
 ** Web: http://code.google.com/p/qextserialport/
10 11
 **
@@ -44,15 +45,20 @@
44 45
 
45 46
 #include "qextserialenumerator.h"
46 47
 
47
-#ifdef Q_OS_WIN
48
+#ifdef  Q_CC_MINGW
48 49
 // needed for mingw to pull in appropriate dbt business...
49 50
 // probably a better way to do this
50 51
 // http://mingw-users.1079350.n2.nabble.com/DEV-BROADCAST-DEVICEINTERFACE-was-not-declared-in-this-scope-td3552762.html
51
-#  ifdef  __MINGW32__
52
-#    define _WIN32_WINNT 0x0500
53
-#    define _WIN32_WINDOWS 0x0500
54
-#    define WINVER 0x0500
52
+// http://msdn.microsoft.com/en-us/library/6sehtctf.aspx
53
+#  ifndef WINVER
54
+#    define WINVER 0x0501
55
+#  endif
56
+#  ifndef _WIN32_WINNT
57
+#    define _WIN32_WINNT WINVER
55 58
 #  endif
59
+#endif
60
+
61
+#ifdef Q_OS_WIN
56 62
 #  include <QtCore/qt_windows.h>
57 63
 #endif /*Q_OS_WIN*/
58 64
 
@@ -60,25 +66,30 @@
60 66
 #  include <IOKit/usb/IOUSBLib.h>
61 67
 #endif /*Q_OS_MAC*/
62 68
 
69
+#if defined(Q_OS_LINUX) && !defined(QESP_NO_UDEV)
70
+#  include <QSocketNotifier>
71
+extern "C" {
72
+#  include <libudev.h>
73
+}
74
+#endif
75
+
63 76
 class QextSerialRegistrationWidget;
64 77
 class QextSerialEnumeratorPrivate
65 78
 {
66 79
     Q_DECLARE_PUBLIC(QextSerialEnumerator)
67 80
 public:
68
-    QextSerialEnumeratorPrivate(QextSerialEnumerator * enumrator);
81
+    QextSerialEnumeratorPrivate(QextSerialEnumerator *enumrator);
69 82
     ~QextSerialEnumeratorPrivate();
70
-    void platformSpecificInit();
71
-    void platformSpecificDestruct();
83
+    void init_sys();
84
+    void destroy_sys();
72 85
 
73 86
     static QList<QextPortInfo> getPorts_sys();
74 87
     bool setUpNotifications_sys(bool setup);
75 88
 
76
-#ifdef Q_OS_WIN
77
-    LRESULT onDeviceChanged( WPARAM wParam, LPARAM lParam );
78
-    bool matchAndDispatchChangedDevice(const QString & deviceID, const GUID & guid, WPARAM wParam);
79
-#  ifdef QT_GUI_LIB
80
-    QextSerialRegistrationWidget* notificationWidget;
81
-#  endif
89
+#if defined(Q_OS_WIN) && defined(QT_GUI_LIB)
90
+    LRESULT onDeviceChanged(WPARAM wParam, LPARAM lParam);
91
+    bool matchAndDispatchChangedDevice(const QString &deviceID, const GUID &guid, WPARAM wParam);
92
+    QextSerialRegistrationWidget *notificationWidget;
82 93
 #endif /*Q_OS_WIN*/
83 94
 
84 95
 #ifdef Q_OS_MAC
@@ -86,18 +97,27 @@ public:
86 97
      * Search for serial ports using IOKit.
87 98
      *    \param infoList list with result.
88 99
      */
89
-    static void iterateServicesOSX(io_object_t service, QList<QextPortInfo> & infoList);
90
-    static bool getServiceDetailsOSX( io_object_t service, QextPortInfo* portInfo );
91
-    void onDeviceDiscoveredOSX( io_object_t service );
92
-    void onDeviceTerminatedOSX( io_object_t service );
93
-    friend void deviceDiscoveredCallbackOSX( void *ctxt, io_iterator_t serialPortIterator );
94
-    friend void deviceTerminatedCallbackOSX( void *ctxt, io_iterator_t serialPortIterator );
100
+    static void iterateServicesOSX(io_object_t service, QList<QextPortInfo> &infoList);
101
+    static bool getServiceDetailsOSX(io_object_t service, QextPortInfo *portInfo);
102
+    void onDeviceDiscoveredOSX(io_object_t service);
103
+    void onDeviceTerminatedOSX(io_object_t service);
104
+    friend void deviceDiscoveredCallbackOSX(void *ctxt, io_iterator_t serialPortIterator);
105
+    friend void deviceTerminatedCallbackOSX(void *ctxt, io_iterator_t serialPortIterator);
95 106
 
96 107
     IONotificationPortRef notificationPortRef;
97 108
 #endif // Q_OS_MAC
98 109
 
110
+#if defined(Q_OS_LINUX) && !defined(QESP_NO_UDEV)
111
+    QSocketNotifier *notifier;
112
+    int notifierFd;
113
+    struct udev *udev;
114
+    struct udev_monitor *monitor;
115
+
116
+    void _q_deviceEvent();
117
+#endif
118
+
99 119
 private:
100
-    QextSerialEnumerator * q_ptr;
120
+    QextSerialEnumerator *q_ptr;
101 121
 };
102 122
 
103 123
 #endif //_QEXTSERIALENUMERATOR_P_H_

+ 4
- 48
src/3rdparty/qextserialport/src/qextserialenumerator_unix.cpp View File

@@ -32,69 +32,25 @@
32 32
 #include "qextserialenumerator.h"
33 33
 #include "qextserialenumerator_p.h"
34 34
 #include <QtCore/QDebug>
35
-#include <QtCore/QStringList>
36
-#include <QtCore/QDir>
37 35
 
38
-void QextSerialEnumeratorPrivate::platformSpecificInit()
36
+void QextSerialEnumeratorPrivate::init_sys()
39 37
 {
40 38
 }
41 39
 
42
-void QextSerialEnumeratorPrivate::platformSpecificDestruct()
40
+void QextSerialEnumeratorPrivate::destroy_sys()
43 41
 {
44 42
 }
45 43
 
46 44
 QList<QextPortInfo> QextSerialEnumeratorPrivate::getPorts_sys()
47 45
 {
48 46
     QList<QextPortInfo> infoList;
49
-#ifdef Q_OS_LINUX
50
-    QStringList portNamePrefixes, portNameList;
51
-    portNamePrefixes << QLatin1String("ttyS*"); // list normal serial ports first
52
-
53
-    QDir dir(QLatin1String("/dev"));
54
-    portNameList = dir.entryList(portNamePrefixes, (QDir::System | QDir::Files), QDir::Name);
55
-
56
-    // remove the values which are not serial ports for e.g.  /dev/ttysa
57
-    for (int i = 0; i < portNameList.size(); i++) {
58
-        bool ok;
59
-        QString current = portNameList.at(i);
60
-        // remove the ttyS part, and check, if the other part is a number
61
-        current.remove(0,4).toInt(&ok, 10);
62
-        if (!ok) {
63
-            portNameList.removeAt(i);
64
-            i--;
65
-        }
66
-    }
67
-
68
-    // get the non standard serial ports names
69
-    // (USB-serial, bluetooth-serial, 18F PICs, and so on)
70
-    // if you know an other name prefix for serial ports please let us know
71
-    portNamePrefixes.clear();
72
-    portNamePrefixes << QLatin1String("ttyACM*") << QLatin1String("ttyUSB*") << QLatin1String("rfcomm*");
73
-    portNameList += dir.entryList(portNamePrefixes, (QDir::System | QDir::Files), QDir::Name);
74
-
75
-    foreach (QString str , portNameList) {
76
-        QextPortInfo inf;
77
-        inf.physName = QLatin1String("/dev/")+str;
78
-        inf.portName = str;
79
-
80
-        if (str.contains(QLatin1String("ttyS"))) {
81
-            inf.friendName = QLatin1String("Serial port ")+str.remove(0, 4);
82
-        }
83
-        else if (str.contains(QLatin1String("ttyUSB"))) {
84
-            inf.friendName = QLatin1String("USB-serial adapter ")+str.remove(0, 6);
85
-        }
86
-        else if (str.contains(QLatin1String("rfcomm"))) {
87
-            inf.friendName = QLatin1String("Bluetooth-serial adapter ")+str.remove(0, 6);
88
-        }
89
-        inf.enumName = QLatin1String("/dev"); // is there a more helpful name for this?
90
-        infoList.append(inf);
91
-    }
92
-#endif
47
+    QESP_WARNING("Enumeration for POSIX systems (except Linux) is not implemented yet.");
93 48
     return infoList;
94 49
 }
95 50
 
96 51
 bool QextSerialEnumeratorPrivate::setUpNotifications_sys(bool setup)
97 52
 {
98 53
     Q_UNUSED(setup)
54
+    QESP_WARNING("Notifications for *Nix/FreeBSD are not implemented yet");
99 55
     return false;
100 56
 }

+ 78
- 77
src/3rdparty/qextserialport/src/qextserialenumerator_win.cpp View File

@@ -34,13 +34,20 @@
34 34
 #include <QtCore/QDebug>
35 35
 #include <QtCore/QMetaType>
36 36
 #include <QtCore/QRegExp>
37
+#include <algorithm>
37 38
 #include <objbase.h>
38 39
 #include <initguid.h>
39 40
 #include <setupapi.h>
40 41
 #include <dbt.h>
41
-#include "qextserialport.h"
42 42
 
43 43
 #ifdef QT_GUI_LIB
44
+/*!
45
+  \internal
46
+  \class QextSerialRegistrationWidget
47
+
48
+  Internal window which is used to receive device arrvial and removal message.
49
+*/
50
+
44 51
 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
45 52
 #include <QtGui/QWidget>
46 53
 class QextSerialRegistrationWidget : public QWidget
@@ -50,7 +57,7 @@ class QextSerialRegistrationWidget : public QWindow
50 57
 #endif
51 58
 {
52 59
 public:
53
-    QextSerialRegistrationWidget(QextSerialEnumeratorPrivate* qese) {
60
+    QextSerialRegistrationWidget(QextSerialEnumeratorPrivate *qese) {
54 61
         this->qese = qese;
55 62
     }
56 63
     ~QextSerialRegistrationWidget() {}
@@ -58,25 +65,24 @@ public:
58 65
 protected:
59 66
 
60 67
 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
61
-    bool winEvent( MSG* message, long* result ) {
68
+    bool winEvent(MSG *message, long *result) {
62 69
 #else
63 70
     bool nativeEvent(const QByteArray & /*eventType*/, void *msg, long *result) {
64
-        MSG *message = static_cast<MSG*>(msg);
71
+        MSG *message = static_cast<MSG *>(msg);
65 72
 #endif
66
-        if ( message->message == WM_DEVICECHANGE ) {
67
-            qese->onDeviceChanged(message->wParam, message->lParam );
73
+        if (message->message == WM_DEVICECHANGE) {
74
+            qese->onDeviceChanged(message->wParam, message->lParam);
68 75
             *result = 1;
69 76
             return true;
70 77
         }
71 78
         return false;
72 79
     }
73 80
 private:
74
-    QextSerialEnumeratorPrivate* qese;
81
+    QextSerialEnumeratorPrivate *qese;
75 82
 };
76
-
77 83
 #endif // QT_GUI_LIB
78 84
 
79
-void QextSerialEnumeratorPrivate::platformSpecificInit()
85
+void QextSerialEnumeratorPrivate::init_sys()
80 86
 {
81 87
 #ifdef QT_GUI_LIB
82 88
     notificationWidget = 0;
@@ -86,32 +92,18 @@ void QextSerialEnumeratorPrivate::platformSpecificInit()
86 92
 /*!
87 93
   default
88 94
 */
89
-void QextSerialEnumeratorPrivate::platformSpecificDestruct()
95
+void QextSerialEnumeratorPrivate::destroy_sys()
90 96
 {
91 97
 #ifdef QT_GUI_LIB
92
-    if( notificationWidget )
98
+    if (notificationWidget)
93 99
         delete notificationWidget;
94 100
 #endif
95 101
 }
96 102
 
97
-// see http://msdn.microsoft.com/en-us/library/windows/hardware/ff553426(v=vs.85).aspx
98
-// for list of GUID classes
99
-#ifndef GUID_DEVCLASS_PORTS
100
-    DEFINE_GUID(GUID_DEVCLASS_PORTS, 0x4D36E978, 0xE325, 0x11CE, 0xBF, 0xC1, 0x08, 0x00, 0x2B, 0xE1, 0x03, 0x18 );
103
+#ifndef GUID_DEVINTERFACE_COMPORT
104
+DEFINE_GUID(GUID_DEVINTERFACE_COMPORT, 0x86e0d1e0L, 0x8089, 0x11d0, 0x9c, 0xe4, 0x08, 0x00, 0x3e, 0x30, 0x1f, 0x73);
101 105
 #endif
102 106
 
103
-/* Gordon Schumacher's macros for TCHAR -> QString conversions and vice versa */
104
-#ifdef UNICODE
105
-    #define QStringToTCHAR(x)     (wchar_t*) x.utf16()
106
-    #define PQStringToTCHAR(x)    (wchar_t*) x->utf16()
107
-    #define TCHARToQString(x)     QString::fromUtf16((ushort*)(x))
108
-    #define TCHARToQStringN(x,y)  QString::fromUtf16((ushort*)(x),(y))
109
-#else
110
-    #define QStringToTCHAR(x)     x.local8Bit().constData()
111
-    #define PQStringToTCHAR(x)    x->local8Bit().constData()
112
-    #define TCHARToQString(x)     QString::fromLocal8Bit((char*)(x))
113
-    #define TCHARToQStringN(x,y)  QString::fromLocal8Bit((char*)(x),(y))
114
-#endif /*UNICODE*/
115 107
 
116 108
 /*!
117 109
     \internal
@@ -125,12 +117,12 @@ static QString getRegKeyValue(HKEY key, LPCTSTR property)
125 117
 {
126 118
     DWORD size = 0;
127 119
     DWORD type;
128
-    ::RegQueryValueEx(key, property, NULL, NULL, NULL, & size);
129
-    BYTE* buff = new BYTE[size];
120
+    if (::RegQueryValueEx(key, property, NULL, NULL, NULL, &size) != ERROR_SUCCESS)
121
+        return QString();
122
+    BYTE *buff = new BYTE[size];
130 123
     QString result;
131
-    if(::RegQueryValueEx(key, property, NULL, &type, buff, & size) == ERROR_SUCCESS )
132
-        result = TCHARToQString(buff);
133
-    ::RegCloseKey(key);
124
+    if (::RegQueryValueEx(key, property, NULL, &type, buff, &size) == ERROR_SUCCESS)
125
+        result = QString::fromUtf16(reinterpret_cast<ushort *>(buff));
134 126
     delete [] buff;
135 127
     return result;
136 128
 }
@@ -138,21 +130,23 @@ static QString getRegKeyValue(HKEY key, LPCTSTR property)
138 130
 /*!
139 131
      \internal
140 132
      Get specific property from registry.
141
-     \a devInfo pointer to the device information set that contains the interface
133
+     \a devInfoSet pointer to the device information set that contains the interface
142 134
         and its underlying device. Returned by SetupDiGetClassDevs() function.
143
-     \a devData pointer to an SP_DEVINFO_DATA structure that defines the device instance.
135
+     \a devInfoData pointer to an SP_DEVINFO_DATA structure that defines the device instance.
144 136
         this is returned by SetupDiGetDeviceInterfaceDetail() function.
145 137
      \a property registry property. One of defined SPDRP_* constants.
146 138
 
147 139
      return property string.
148 140
  */
149
-static QString getDeviceProperty(HDEVINFO devInfo, PSP_DEVINFO_DATA devData, DWORD property)
141
+static QString getDeviceRegistryProperty(HDEVINFO devInfoSet, PSP_DEVINFO_DATA devInfoData, DWORD property)
150 142
 {
151 143
     DWORD buffSize = 0;
152
-    ::SetupDiGetDeviceRegistryProperty(devInfo, devData, property, NULL, NULL, 0, & buffSize);
153
-    BYTE* buff = new BYTE[buffSize];
154
-    ::SetupDiGetDeviceRegistryProperty(devInfo, devData, property, NULL, buff, buffSize, NULL);
155
-    QString result = TCHARToQString(buff);
144
+    ::SetupDiGetDeviceRegistryProperty(devInfoSet, devInfoData, property, NULL, NULL, 0, &buffSize);
145
+    if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
146
+        return QString();
147
+    BYTE *buff = new BYTE[buffSize];
148
+    ::SetupDiGetDeviceRegistryProperty(devInfoSet, devInfoData, property, NULL, buff, buffSize, NULL);
149
+    QString result = QString::fromUtf16(reinterpret_cast<ushort *>(buff));
156 150
     delete [] buff;
157 151
     return result;
158 152
 }
@@ -160,18 +154,21 @@ static QString getDeviceProperty(HDEVINFO devInfo, PSP_DEVINFO_DATA devData, DWO
160 154
 /*!
161 155
      \internal
162 156
 */
163
-static bool getDeviceDetailsWin( QextPortInfo* portInfo, HDEVINFO devInfo, PSP_DEVINFO_DATA devData
157
+static bool getDeviceDetailsInformation(QextPortInfo *portInfo, HDEVINFO devInfoSet, PSP_DEVINFO_DATA devInfoData
164 158
                                  , WPARAM wParam = DBT_DEVICEARRIVAL)
165 159
 {
166
-    portInfo->friendName = getDeviceProperty(devInfo, devData, SPDRP_FRIENDLYNAME);
167
-    if( wParam == DBT_DEVICEARRIVAL)
168
-        portInfo->physName = getDeviceProperty(devInfo, devData, SPDRP_PHYSICAL_DEVICE_OBJECT_NAME);
169
-    portInfo->enumName = getDeviceProperty(devInfo, devData, SPDRP_ENUMERATOR_NAME);
170
-    QString hardwareIDs = getDeviceProperty(devInfo, devData, SPDRP_HARDWAREID);
171
-    HKEY devKey = ::SetupDiOpenDevRegKey(devInfo, devData, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_QUERY_VALUE);
160
+    portInfo->friendName = getDeviceRegistryProperty(devInfoSet, devInfoData, SPDRP_FRIENDLYNAME);
161
+    if (wParam == DBT_DEVICEARRIVAL)
162
+        portInfo->physName = getDeviceRegistryProperty(devInfoSet, devInfoData, SPDRP_PHYSICAL_DEVICE_OBJECT_NAME);
163
+    portInfo->enumName = getDeviceRegistryProperty(devInfoSet, devInfoData, SPDRP_ENUMERATOR_NAME);
164
+
165
+    HKEY devKey = ::SetupDiOpenDevRegKey(devInfoSet, devInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_QUERY_VALUE);
172 166
     portInfo->portName = getRegKeyValue(devKey, TEXT("PortName"));
167
+    ::RegCloseKey(devKey);
168
+
169
+    QString hardwareIDs = getDeviceRegistryProperty(devInfoSet, devInfoData, SPDRP_HARDWAREID);
173 170
     QRegExp idRx(QLatin1String("VID_(\\w+)&PID_(\\w+)"));
174
-    if(hardwareIDs.toUpper().contains(idRx)) {
171
+    if (hardwareIDs.toUpper().contains(idRx)) {
175 172
         bool dummy;
176 173
         portInfo->vendorID = idRx.cap(1).toInt(&dummy, 16);
177 174
         portInfo->productID = idRx.cap(2).toInt(&dummy, 16);
@@ -183,19 +180,19 @@ static bool getDeviceDetailsWin( QextPortInfo* portInfo, HDEVINFO devInfo, PSP_D
183 180
 /*!
184 181
      \internal
185 182
 */
186
-static void enumerateDevicesWin( const GUID & guid, QList<QextPortInfo>* infoList )
183
+static void enumerateDevices(const GUID &guid, QList<QextPortInfo> *infoList)
187 184
 {
188
-    HDEVINFO devInfo;
189
-    if( (devInfo = ::SetupDiGetClassDevs(&guid, NULL, NULL, DIGCF_PRESENT)) != INVALID_HANDLE_VALUE) {
185
+    HDEVINFO devInfoSet = ::SetupDiGetClassDevs(&guid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
186
+    if (devInfoSet != INVALID_HANDLE_VALUE) {
190 187
         SP_DEVINFO_DATA devInfoData;
191 188
         devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
192
-        for(int i = 0; ::SetupDiEnumDeviceInfo(devInfo, i, &devInfoData); i++) {
189
+        for(int i = 0; ::SetupDiEnumDeviceInfo(devInfoSet, i, &devInfoData); i++) {
193 190
             QextPortInfo info;
194 191
             info.productID = info.vendorID = 0;
195
-            getDeviceDetailsWin( &info, devInfo, &devInfoData );
192
+            getDeviceDetailsInformation(&info, devInfoSet, &devInfoData);
196 193
             infoList->append(info);
197 194
         }
198
-        ::SetupDiDestroyDeviceInfoList(devInfo);
195
+        ::SetupDiDestroyDeviceInfoList(devInfoSet);
199 196
     }
200 197
 }
201 198
 
@@ -218,8 +215,8 @@ static bool lessThan(const QextPortInfo &s1, const QextPortInfo &s2)
218 215
 QList<QextPortInfo> QextSerialEnumeratorPrivate::getPorts_sys()
219 216
 {
220 217
     QList<QextPortInfo> ports;
221
-    enumerateDevicesWin(GUID_DEVCLASS_PORTS, &ports);
222
-    qSort(ports.begin(), ports.end(), lessThan);
218
+    enumerateDevices(GUID_DEVINTERFACE_COMPORT, &ports);
219
+    std::sort(ports.begin(), ports.end(), lessThan);
223 220
     return ports;
224 221
 }
225 222
 
@@ -235,7 +232,7 @@ bool QextSerialEnumeratorPrivate::setUpNotifications_sys(bool setup)
235 232
     return false;
236 233
 #else
237 234
     Q_Q(QextSerialEnumerator);
238
-    if(setup && notificationWidget) //already setup
235
+    if (setup && notificationWidget) //already setup
239 236
         return true;
240 237
     notificationWidget = new QextSerialRegistrationWidget(this);
241 238
 
@@ -243,60 +240,64 @@ bool QextSerialEnumeratorPrivate::setUpNotifications_sys(bool setup)
243 240
     ::ZeroMemory(&dbh, sizeof(dbh));
244 241
     dbh.dbcc_size = sizeof(dbh);
245 242
     dbh.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
246
-    ::CopyMemory(&dbh.dbcc_classguid, &GUID_DEVCLASS_PORTS, sizeof(GUID));
247
-    if(::RegisterDeviceNotification((HWND)notificationWidget->winId(), &dbh, DEVICE_NOTIFY_WINDOW_HANDLE ) == NULL) {
243
+    // dbh.dbcc_classguid = GUID_DEVCLASS_PORTS; //Ignored in such case
244
+    DWORD flags = DEVICE_NOTIFY_WINDOW_HANDLE|DEVICE_NOTIFY_ALL_INTERFACE_CLASSES;
245
+    if (::RegisterDeviceNotification((HWND)notificationWidget->winId(), &dbh, flags) == NULL) {
248 246
         QESP_WARNING() << "RegisterDeviceNotification failed:" << GetLastError();
249 247
         return false;
250 248
     }
251 249
     // setting up notifications doesn't tell us about devices already connected
252 250
     // so get those manually
253
-    foreach(QextPortInfo port, getPorts_sys())
254
-      Q_EMIT q->deviceDiscovered(port);
251
+    foreach (QextPortInfo port, getPorts_sys())
252
+        Q_EMIT q->deviceDiscovered(port);
255 253
     return true;
256 254
 #endif // QT_GUI_LIB
257 255
 }
258 256
 
259
-LRESULT QextSerialEnumeratorPrivate::onDeviceChanged( WPARAM wParam, LPARAM lParam )
257
+#ifdef QT_GUI_LIB
258
+LRESULT QextSerialEnumeratorPrivate::onDeviceChanged(WPARAM wParam, LPARAM lParam)
260 259
 {
261
-    if (DBT_DEVICEARRIVAL == wParam || DBT_DEVICEREMOVECOMPLETE == wParam ) {
260
+    if (DBT_DEVICEARRIVAL == wParam || DBT_DEVICEREMOVECOMPLETE == wParam) {
262 261
         PDEV_BROADCAST_HDR pHdr = (PDEV_BROADCAST_HDR)lParam;
263
-        if(pHdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE ) {
262
+        if (pHdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) {
264 263
             PDEV_BROADCAST_DEVICEINTERFACE pDevInf = (PDEV_BROADCAST_DEVICEINTERFACE)pHdr;
265 264
              // delimiters are different across APIs...change to backslash.  ugh.
266
-            QString deviceID = TCHARToQString(pDevInf->dbcc_name).toUpper().replace(QLatin1String("#"), QLatin1String("\\"));
265
+            QString deviceID = QString::fromUtf16(reinterpret_cast<ushort *>(pDevInf->dbcc_name));
266
+            deviceID = deviceID.toUpper().replace(QLatin1String("#"), QLatin1String("\\"));
267 267
 
268
-            matchAndDispatchChangedDevice(deviceID, GUID_DEVCLASS_PORTS, wParam);
268
+            matchAndDispatchChangedDevice(deviceID, GUID_DEVINTERFACE_COMPORT, wParam);
269 269
         }
270 270
     }
271 271
     return 0;
272 272
 }
273 273
 
274
-bool QextSerialEnumeratorPrivate::matchAndDispatchChangedDevice(const QString & deviceID, const GUID & guid, WPARAM wParam)
274
+bool QextSerialEnumeratorPrivate::matchAndDispatchChangedDevice(const QString &deviceID, const GUID &guid, WPARAM wParam)
275 275
 {
276 276
     Q_Q(QextSerialEnumerator);
277 277
     bool rv = false;
278
-    DWORD dwFlag = (DBT_DEVICEARRIVAL == wParam) ? DIGCF_PRESENT : DIGCF_ALLCLASSES;
279
-    HDEVINFO devInfo;
280
-    if( (devInfo = SetupDiGetClassDevs(&guid,NULL,NULL,dwFlag)) != INVALID_HANDLE_VALUE ) {
278
+    DWORD dwFlag = (DBT_DEVICEARRIVAL == wParam) ? DIGCF_PRESENT : DIGCF_PROFILE;
279
+    HDEVINFO devInfoSet  = SetupDiGetClassDevs(&guid, NULL, NULL, dwFlag | DIGCF_DEVICEINTERFACE);
280
+    if (devInfoSet != INVALID_HANDLE_VALUE) {
281 281
         SP_DEVINFO_DATA spDevInfoData;
282 282
         spDevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
283
-        for(int i=0; SetupDiEnumDeviceInfo(devInfo, i, &spDevInfoData); i++) {
284
-            DWORD nSize=0 ;
283
+        for(int i=0; SetupDiEnumDeviceInfo(devInfoSet, i, &spDevInfoData); i++) {
284
+            DWORD nSize = 0;
285 285
             TCHAR buf[MAX_PATH];
286
-            if ( SetupDiGetDeviceInstanceId(devInfo, &spDevInfoData, buf, MAX_PATH, &nSize) &&
287
-                    deviceID.contains(TCHARToQString(buf))) { // we found a match
286
+            if (SetupDiGetDeviceInstanceId(devInfoSet, &spDevInfoData, buf, MAX_PATH, &nSize)
287
+                    && deviceID.contains(QString::fromUtf16(reinterpret_cast<ushort *>(buf)))) { // we found a match
288 288
                 rv = true;
289 289
                 QextPortInfo info;
290 290
                 info.productID = info.vendorID = 0;
291
-                getDeviceDetailsWin( &info, devInfo, &spDevInfoData, wParam );
292
-                if( wParam == DBT_DEVICEARRIVAL )
291
+                getDeviceDetailsInformation(&info, devInfoSet, &spDevInfoData, wParam);
292
+                if (wParam == DBT_DEVICEARRIVAL)
293 293
                     Q_EMIT q->deviceDiscovered(info);
294
-                else if( wParam == DBT_DEVICEREMOVECOMPLETE )
294
+                else if (wParam == DBT_DEVICEREMOVECOMPLETE)
295 295
                     Q_EMIT q->deviceRemoved(info);
296 296
                 break;
297 297
             }
298 298
         }
299
-        SetupDiDestroyDeviceInfoList(devInfo);
299
+        SetupDiDestroyDeviceInfoList(devInfoSet);
300 300
     }
301 301
     return rv;
302 302
 }
303
+#endif //QT_GUI_LIB

+ 61
- 62
src/3rdparty/qextserialport/src/qextserialport.cpp View File

@@ -57,12 +57,12 @@ QextSerialPortPrivate::QextSerialPortPrivate(QextSerialPort *q)
57 57
     :lock(QReadWriteLock::Recursive), q_ptr(q)
58 58
 {
59 59
     lastErr = E_NO_ERROR;
60
-    Settings.BaudRate = BAUD9600;
61
-    Settings.Parity = PAR_NONE;
62
-    Settings.FlowControl = FLOW_OFF;
63
-    Settings.DataBits = DATA_8;
64
-    Settings.StopBits = STOP_1;
65
-    Settings.Timeout_Millisec = 10;
60
+    settings.BaudRate = BAUD9600;
61
+    settings.Parity = PAR_NONE;
62
+    settings.FlowControl = FLOW_OFF;
63
+    settings.DataBits = DATA_8;
64
+    settings.StopBits = STOP_1;
65
+    settings.Timeout_Millisec = 10;
66 66
     settingsDirtyFlags = DFE_ALL;
67 67
 
68 68
     platformSpecificInit();
@@ -91,10 +91,10 @@ void QextSerialPortPrivate::setBaudRate(BaudRateType baudRate, bool update)
91 91
     case BAUD150:
92 92
     case BAUD200:
93 93
     case BAUD1800:
94
-#ifdef B76800
94
+#  ifdef B76800
95 95
     case BAUD76800:
96
-#endif
97
-#if defined(B230400) && defined(B4000000)
96
+#  endif
97
+#  if defined(B230400) && defined(B4000000)
98 98
     case BAUD230400:
99 99
     case BAUD460800:
100 100
     case BAUD500000:
@@ -108,7 +108,7 @@ void QextSerialPortPrivate::setBaudRate(BaudRateType baudRate, bool update)
108 108
     case BAUD3000000:
109 109
     case BAUD3500000:
110 110
     case BAUD4000000:
111
-#endif
111
+#  endif
112 112
         QESP_PORTABILITY_WARNING()<<"QextSerialPort Portability Warning: Windows does not support baudRate:"<<baudRate;
113 113
 #endif
114 114
     case BAUD110:
@@ -122,13 +122,18 @@ void QextSerialPortPrivate::setBaudRate(BaudRateType baudRate, bool update)
122 122
     case BAUD38400:
123 123
     case BAUD57600:
124 124
     case BAUD115200:
125
-        Settings.BaudRate=baudRate;
125
+#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
126
+    default:
127
+#endif
128
+        settings.BaudRate = baudRate;
126 129
         settingsDirtyFlags |= DFE_BaudRate;
127 130
         if (update && q_func()->isOpen())
128 131
             updatePortSettings();
129 132
         break;
133
+#if !(defined(Q_OS_WIN) || defined(Q_OS_MAC))
130 134
     default:
131 135
         QESP_WARNING()<<"QextSerialPort does not support baudRate:"<<baudRate;
136
+#endif
132 137
     }
133 138
 }
134 139
 
@@ -136,7 +141,7 @@ void QextSerialPortPrivate::setParity(ParityType parity, bool update)
136 141
 {
137 142
     switch (parity) {
138 143
     case PAR_SPACE:
139
-        if (Settings.DataBits==DATA_8) {
144
+        if (settings.DataBits == DATA_8) {
140 145
 #ifdef Q_OS_WIN
141 146
             QESP_PORTABILITY_WARNING("QextSerialPort Portability Warning: Space parity with 8 data bits is not supported by POSIX systems.");
142 147
 #else
@@ -160,7 +165,7 @@ void QextSerialPortPrivate::setParity(ParityType parity, bool update)
160 165
         QESP_WARNING()<<"QextSerialPort does not support Parity:" << parity;
161 166
     }
162 167
 
163
-    Settings.Parity=parity;
168
+    settings.Parity = parity;
164 169
     settingsDirtyFlags |= DFE_Parity;
165 170
     if (update && q_func()->isOpen())
166 171
         updatePortSettings();
@@ -171,50 +176,49 @@ void QextSerialPortPrivate::setDataBits(DataBitsType dataBits, bool update)
171 176
     switch(dataBits) {
172 177
 
173 178
     case DATA_5:
174
-        if (Settings.StopBits==STOP_2) {
179
+        if (settings.StopBits == STOP_2) {
175 180
             QESP_WARNING("QextSerialPort: 5 Data bits cannot be used with 2 stop bits.");
176
-        }
177
-        else {
178
-            Settings.DataBits=dataBits;
181
+        } else {
182
+            settings.DataBits = dataBits;
179 183
             settingsDirtyFlags |= DFE_DataBits;
180 184
         }
181 185
         break;
182 186
 
183 187
     case DATA_6:
184 188
 #ifdef Q_OS_WIN
185
-        if (Settings.StopBits==STOP_1_5) {
189
+        if (settings.StopBits == STOP_1_5) {
186 190
             QESP_WARNING("QextSerialPort: 6 Data bits cannot be used with 1.5 stop bits.");
187 191
         }
188 192
         else
189 193
 #endif
190 194
         {
191
-            Settings.DataBits=dataBits;
195
+            settings.DataBits = dataBits;
192 196
             settingsDirtyFlags |= DFE_DataBits;
193 197
         }
194 198
         break;
195 199
 
196 200
     case DATA_7:
197 201
 #ifdef Q_OS_WIN
198
-        if (Settings.StopBits==STOP_1_5) {
202
+        if (settings.StopBits == STOP_1_5) {
199 203
             QESP_WARNING("QextSerialPort: 7 Data bits cannot be used with 1.5 stop bits.");
200 204
         }
201 205
         else
202 206
 #endif
203 207
         {
204
-            Settings.DataBits=dataBits;
208
+            settings.DataBits = dataBits;
205 209
             settingsDirtyFlags |= DFE_DataBits;
206 210
         }
207 211
         break;
208 212
 
209 213
     case DATA_8:
210 214
 #ifdef Q_OS_WIN
211
-        if (Settings.StopBits==STOP_1_5) {
215
+        if (settings.StopBits == STOP_1_5) {
212 216
             QESP_WARNING("QextSerialPort: 8 Data bits cannot be used with 1.5 stop bits.");
213 217
         }
214 218
         else
215 219
 #endif
216 220
         {
217
-            Settings.DataBits=dataBits;
221
+            settings.DataBits = dataBits;
218 222
             settingsDirtyFlags |= DFE_DataBits;
219 223
         }
220 224
         break;
@@ -231,7 +235,7 @@ void QextSerialPortPrivate::setStopBits(StopBitsType stopBits, bool update)
231 235
 
232 236
         /*one stop bit*/
233 237
     case STOP_1:
234
-        Settings.StopBits = stopBits;
238
+        settings.StopBits = stopBits;
235 239
         settingsDirtyFlags |= DFE_StopBits;
236 240
         break;
237 241
 
@@ -239,11 +243,10 @@ void QextSerialPortPrivate::setStopBits(StopBitsType stopBits, bool update)
239 243
         /*1.5 stop bits*/
240 244
     case STOP_1_5:
241 245
         QESP_PORTABILITY_WARNING("QextSerialPort Portability Warning: 1.5 stop bit operation is not supported by POSIX.");
242
-        if (Settings.DataBits!=DATA_5) {
246
+        if (settings.DataBits != DATA_5) {
243 247
             QESP_WARNING("QextSerialPort: 1.5 stop bits can only be used with 5 data bits");
244
-        }
245
-        else {
246
-            Settings.StopBits = stopBits;
248
+        } else {
249
+            settings.StopBits = stopBits;
247 250
             settingsDirtyFlags |= DFE_StopBits;
248 251
         }
249 252
         break;
@@ -251,11 +254,10 @@ void QextSerialPortPrivate::setStopBits(StopBitsType stopBits, bool update)
251 254
 
252 255
         /*two stop bits*/
253 256
     case STOP_2:
254
-        if (Settings.DataBits==DATA_5) {
257
+        if (settings.DataBits == DATA_5) {
255 258
             QESP_WARNING("QextSerialPort: 2 stop bits cannot be used with 5 data bits");
256
-        }
257
-        else {
258
-            Settings.StopBits = stopBits;
259
+        } else {
260
+            settings.StopBits = stopBits;
259 261
             settingsDirtyFlags |= DFE_StopBits;
260 262
         }
261 263
         break;
@@ -268,7 +270,7 @@ void QextSerialPortPrivate::setStopBits(StopBitsType stopBits, bool update)
268 270
 
269 271
 void QextSerialPortPrivate::setFlowControl(FlowType flow, bool update)
270 272
 {
271
-    Settings.FlowControl=flow;
273
+    settings.FlowControl = flow;
272 274
     settingsDirtyFlags |= DFE_Flow;
273 275
     if (update && q_func()->isOpen())
274 276
         updatePortSettings();
@@ -276,7 +278,7 @@ void QextSerialPortPrivate::setFlowControl(FlowType flow, bool update)
276 278
 
277 279
 void QextSerialPortPrivate::setTimeout(long millisec, bool update)
278 280
 {
279
-    Settings.Timeout_Millisec = millisec;
281
+    settings.Timeout_Millisec = millisec;
280 282
     settingsDirtyFlags |= DFE_TimeOut;
281 283
     if (update && q_func()->isOpen())
282 284
         updatePortSettings();
@@ -300,7 +302,7 @@ void QextSerialPortPrivate::_q_canRead()
300 302
 {
301 303
     qint64 maxSize = bytesAvailable_sys();
302 304
     if (maxSize > 0) {
303
-        char * writePtr = readBuffer.reserve(size_t(maxSize));
305
+        char *writePtr = readBuffer.reserve(size_t(maxSize));
304 306
         qint64 bytesRead = readData_sys(writePtr, maxSize);
305 307
         if (bytesRead < maxSize)
306 308
             readBuffer.chop(maxSize - bytesRead);
@@ -320,7 +322,7 @@ void QextSerialPortPrivate::_q_canRead()
320 322
 
321 323
     \bold Example
322 324
     \code
323
-    QextSerialPort* port = new QextSerialPort("COM1");
325
+    QextSerialPort *port = new QextSerialPort("COM1");
324 326
     connect(port, SIGNAL(readyRead()), myClass, SLOT(onDataAvailable()));
325 327
     port->open();
326 328
 
@@ -433,7 +435,7 @@ QextSerialPort::QextSerialPort(QextSerialPort::QueryMode mode, QObject *parent)
433 435
     \a name is the name of the device, which is windowsystem-specific,
434 436
     e.g."COM1" or "/dev/ttyS0". \a mode
435 437
 */
436
-QextSerialPort::QextSerialPort(const QString & name, QextSerialPort::QueryMode mode, QObject *parent)
438
+QextSerialPort::QextSerialPort(const QString &name, QextSerialPort::QueryMode mode, QObject *parent)
437 439
     : QIODevice(parent), d_ptr(new QextSerialPortPrivate(this))
438 440
 {
439 441
     setQueryMode(mode);
@@ -443,7 +445,7 @@ QextSerialPort::QextSerialPort(const QString & name, QextSerialPort::QueryMode m
443 445
 /*!
444 446
     Constructs a port with default name and specified \a settings.
445 447
 */
446
-QextSerialPort::QextSerialPort(const PortSettings& settings, QextSerialPort::QueryMode mode, QObject *parent)
448
+QextSerialPort::QextSerialPort(const PortSettings &settings, QextSerialPort::QueryMode mode, QObject *parent)
447 449
     : QIODevice(parent), d_ptr(new QextSerialPortPrivate(this))
448 450
 {
449 451
     Q_D(QextSerialPort);
@@ -454,7 +456,7 @@ QextSerialPort::QextSerialPort(const PortSettings& settings, QextSerialPort::Que
454 456
 /*!
455 457
     Constructs a port with specified \a name , \a mode and \a settings.
456 458
 */
457
-QextSerialPort::QextSerialPort(const QString & name, const PortSettings& settings, QextSerialPort::QueryMode mode, QObject *parent)
459
+QextSerialPort::QextSerialPort(const QString &name, const PortSettings &settings, QextSerialPort::QueryMode mode, QObject *parent)
458 460
     : QIODevice(parent), d_ptr(new QextSerialPortPrivate(this))
459 461
 {
460 462
     Q_D(QextSerialPort);
@@ -468,7 +470,7 @@ QextSerialPort::QextSerialPort(const QString & name, const PortSettings& setting
468 470
     Note that this function does not specify which device to open.
469 471
     Returns true if successful; otherwise returns false.This function has no effect
470 472
     if the port associated with the class is already open.  The port is also
471
-    configured to the current settings, as stored in the Settings structure.
473
+    configured to the current settings, as stored in the settings structure.
472 474
 */
473 475
 bool QextSerialPort::open(OpenMode mode)
474 476
 {
@@ -522,9 +524,8 @@ qint64 QextSerialPort::bytesAvailable() const
522 524
         if (bytes != -1) {
523 525
             return bytes + d_func()->readBuffer.size()
524 526
                     + QIODevice::bytesAvailable();
525
-        } else {
526
-            return -1;
527 527
         }
528
+        return -1;
528 529
     }
529 530
     return 0;
530 531
 }
@@ -564,15 +565,14 @@ void QextSerialPort::setQueryMode(QueryMode mode)
564 565
 {
565 566
     Q_D(QextSerialPort);
566 567
     QWriteLocker locker(&d->lock);
567
-    if (mode != d->_queryMode) {
568
-        d->_queryMode = mode;
569
-    }
568
+    if (mode != d->queryMode)
569
+        d->queryMode = mode;
570 570
 }
571 571
 
572 572
 /*!
573 573
     Sets the \a name of the device associated with the object, e.g. "COM1", or "/dev/ttyS0".
574 574
 */
575
-void QextSerialPort::setPortName(const QString & name)
575
+void QextSerialPort::setPortName(const QString &name)
576 576
 {
577 577
     Q_D(QextSerialPort);
578 578
     QWriteLocker locker(&d->lock);
@@ -591,7 +591,7 @@ QString QextSerialPort::portName() const
591 591
 QextSerialPort::QueryMode QextSerialPort::queryMode() const
592 592
 {
593 593
     QReadLocker locker(&d_func()->lock);
594
-    return d_func()->_queryMode;
594
+    return d_func()->queryMode;
595 595
 }
596 596
 
597 597
 /*!
@@ -612,7 +612,7 @@ QByteArray QextSerialPort::readAll()
612 612
 BaudRateType QextSerialPort::baudRate() const
613 613
 {
614 614
     QReadLocker locker(&d_func()->lock);
615
-    return d_func()->Settings.BaudRate;
615
+    return d_func()->settings.BaudRate;
616 616
 }
617 617
 
618 618
 /*!
@@ -622,7 +622,7 @@ BaudRateType QextSerialPort::baudRate() const
622 622
 DataBitsType QextSerialPort::dataBits() const
623 623
 {
624 624
     QReadLocker locker(&d_func()->lock);
625
-    return d_func()->Settings.DataBits;
625
+    return d_func()->settings.DataBits;
626 626
 }
627 627
 
628 628
 /*!
@@ -632,7 +632,7 @@ DataBitsType QextSerialPort::dataBits() const
632 632
 ParityType QextSerialPort::parity() const
633 633
 {
634 634
     QReadLocker locker(&d_func()->lock);
635
-    return d_func()->Settings.Parity;
635
+    return d_func()->settings.Parity;
636 636
 }
637 637
 
638 638
 /*!
@@ -642,7 +642,7 @@ ParityType QextSerialPort::parity() const
642 642
 StopBitsType QextSerialPort::stopBits() const
643 643
 {
644 644
     QReadLocker locker(&d_func()->lock);
645
-    return d_func()->Settings.StopBits;
645
+    return d_func()->settings.StopBits;
646 646
 }
647 647
 
648 648
 /*!
@@ -652,7 +652,7 @@ StopBitsType QextSerialPort::stopBits() const
652 652
 FlowType QextSerialPort::flowControl() const
653 653
 {
654 654
     QReadLocker locker(&d_func()->lock);
655
-    return d_func()->Settings.FlowControl;
655
+    return d_func()->settings.FlowControl;
656 656
 }
657 657
 
658 658
 /*!
@@ -760,9 +760,9 @@ QString QextSerialPort::errorString()
760 760
 */
761 761
 QextSerialPort::~QextSerialPort()
762 762
 {
763
-    if (isOpen()) {
763
+    if (isOpen())
764 764
         close();
765
-    }
765
+
766 766
     delete d_ptr;
767 767
 }
768 768
 
@@ -778,7 +778,7 @@ void QextSerialPort::setFlowControl(FlowType flow)
778 778
 {
779 779
     Q_D(QextSerialPort);
780 780
     QWriteLocker locker(&d->lock);
781
-    if (d->Settings.FlowControl != flow)
781
+    if (d->settings.FlowControl != flow)
782 782
         d->setFlowControl(flow, true);
783 783
 }
784 784
 
@@ -796,7 +796,7 @@ void QextSerialPort::setParity(ParityType parity)
796 796
 {
797 797
     Q_D(QextSerialPort);
798 798
     QWriteLocker locker(&d->lock);
799
-    if (d->Settings.Parity != parity)
799
+    if (d->settings.Parity != parity)
800 800
         d->setParity(parity, true);
801 801
 }
802 802
 
@@ -821,7 +821,7 @@ void QextSerialPort::setDataBits(DataBitsType dataBits)
821 821
 {
822 822
     Q_D(QextSerialPort);
823 823
     QWriteLocker locker(&d->lock);
824
-    if (d->Settings.DataBits != dataBits)
824
+    if (d->settings.DataBits != dataBits)
825 825
         d->setDataBits(dataBits, true);
826 826
 }
827 827
 
@@ -845,7 +845,7 @@ void QextSerialPort::setStopBits(StopBitsType stopBits)
845 845
 {
846 846
     Q_D(QextSerialPort);
847 847
     QWriteLocker locker(&d->lock);
848
-    if (d->Settings.StopBits != stopBits)
848
+    if (d->settings.StopBits != stopBits)
849 849
         d->setStopBits(stopBits, true);
850 850
 }
851 851
 
@@ -900,7 +900,7 @@ void QextSerialPort::setBaudRate(BaudRateType baudRate)
900 900
 {
901 901
     Q_D(QextSerialPort);
902 902
     QWriteLocker locker(&d->lock);
903
-    if (d->Settings.BaudRate != baudRate)
903
+    if (d->settings.BaudRate != baudRate)
904 904
         d->setBaudRate(baudRate, true);
905 905
 }
906 906
 
@@ -934,7 +934,7 @@ void QextSerialPort::setTimeout(long millisec)
934 934
 {
935 935
     Q_D(QextSerialPort);
936 936
     QWriteLocker locker(&d->lock);
937
-    if (d->Settings.Timeout_Millisec != millisec)
937
+    if (d->settings.Timeout_Millisec != millisec)
938 938
         d->setTimeout(millisec, true);
939 939
 }
940 940
 
@@ -982,9 +982,8 @@ qint64 QextSerialPort::readData(char *data, qint64 maxSize)
982 982
             return bytesFromBuffer;
983 983
     }
984 984
     qint64 bytesFromDevice = d->readData_sys(data+bytesFromBuffer, maxSize-bytesFromBuffer);
985
-    if (bytesFromDevice < 0) {
985
+    if (bytesFromDevice < 0)
986 986
         return -1;
987
-    }
988 987
     return bytesFromBuffer + bytesFromDevice;
989 988
 }
990 989
 

+ 7
- 7
src/3rdparty/qextserialport/src/qextserialport.h View File

@@ -178,10 +178,10 @@ public:
178 178
         EventDriven
179 179
     };
180 180
 
181
-    explicit QextSerialPort(QueryMode mode = EventDriven, QObject* parent = 0);
182
-    explicit QextSerialPort(const QString & name, QueryMode mode = EventDriven, QObject * parent = 0);
183
-    explicit QextSerialPort(const PortSettings & s, QueryMode mode = EventDriven, QObject * parent = 0);
184
-    QextSerialPort(const QString & name, const PortSettings& s, QueryMode mode = EventDriven, QObject *parent=0);
181
+    explicit QextSerialPort(QueryMode mode = EventDriven, QObject *parent = 0);
182
+    explicit QextSerialPort(const QString &name, QueryMode mode = EventDriven, QObject *parent = 0);
183
+    explicit QextSerialPort(const PortSettings &s, QueryMode mode = EventDriven, QObject *parent = 0);
184
+    QextSerialPort(const QString &name, const PortSettings &s, QueryMode mode = EventDriven, QObject *parent=0);
185 185
 
186 186
     ~QextSerialPort();
187 187
 
@@ -207,7 +207,7 @@ public:
207 207
     QString errorString();
208 208
 
209 209
 public Q_SLOTS:
210
-    void setPortName(const QString & name);
210
+    void setPortName(const QString &name);
211 211
     void setQueryMode(QueryMode mode);
212 212
     void setBaudRate(BaudRateType);
213 213
     void setDataBits(DataBitsType);
@@ -223,8 +223,8 @@ Q_SIGNALS:
223 223
     void dsrChanged(bool status);
224 224
 
225 225
 protected:
226
-    qint64 readData(char * data, qint64 maxSize);
227
-    qint64 writeData(const char * data, qint64 maxSize);
226
+    qint64 readData(char *data, qint64 maxSize);
227
+    qint64 writeData(const char *data, qint64 maxSize);
228 228
 
229 229
 private:
230 230
     Q_DISABLE_COPY(QextSerialPort)

+ 26
- 37
src/3rdparty/qextserialport/src/qextserialport.pri View File

@@ -1,47 +1,36 @@
1
-exists(../common.pri) {
2
-    #For case:
3
-    #  someone want to copy all file in the src/ directory
4
-    #  to their project src/ directory and they does not like
5
-    #  the common.pri file.
6
-    #In this case:
7
-    #  they can just include this file (qextserialport.pri) too.
8
-    include(../common.pri)
9
-}
10 1
 INCLUDEPATH += $$PWD
11 2
 DEPENDPATH += $$PWD
12 3
 
13
-qextserialport-library:!qextserialport-buildlib {
14
-    # Using QextSerialPort as shared or static library.
15
-    LIBS += -L$$QEXTSERIALPORT_LIBDIR -l$$QEXTSERIALPORT_LIBNAME
16
-   !qextserialport-static: DEFINES += QEXTSERIALPORT_USING_SHARED
17
-} else {
18
-    # Building library(shared or static)
19
-    # or including source files
20
-    HEADERS                += $$PWD/qextserialport.h \
21
-                              $$PWD/qextserialport_p.h \
22
-                              $$PWD/qextserialenumerator.h \
23
-                              $$PWD/qextserialenumerator_p.h \
24
-                              $$PWD/qextserialport_global.h
25
-    SOURCES                += $$PWD/qextserialport.cpp \
26
-                              $$PWD/qextserialenumerator.cpp
27
-    unix:SOURCES           += $$PWD/qextserialport_unix.cpp
28
-    unix:!macx:SOURCES     += $$PWD/qextserialenumerator_unix.cpp
29
-    macx:SOURCES           += $$PWD/qextserialenumerator_osx.cpp
30
-    win32:SOURCES          += $$PWD/qextserialport_win.cpp \
31
-                              $$PWD/qextserialenumerator_win.cpp
4
+PUBLIC_HEADERS         += $$PWD/qextserialport.h \
5
+                          $$PWD/qextserialenumerator.h \
6
+                          $$PWD/qextserialport_global.h
32 7
 
33
-    # For Windows user who doesn't have Qt4's Private files
34
-    win32:contains(QT_VERSION, ^4\\..*\\..*):!exists($$[QT_INSTALL_HEADERS]/QtCore/private/qwineventnotifier_p.h){
35
-        DEFINES            += QESP_NO_QT4_PRIVATE
36
-        HEADERS            += $$PWD/qextwineventnotifier_p.h
37
-        SOURCES            += $$PWD/qextwineventnotifier_p.cpp
38
-    }
8
+HEADERS                += $$PUBLIC_HEADERS \
9
+                          $$PWD/qextserialport_p.h \
10
+                          $$PWD/qextserialenumerator_p.h \
39 11
 
40
-    # For building shared library only
41
-    qextserialport-buildlib:contains(TEMPLATE, .*lib):contains(CONFIG, shared){
42
-        DEFINES += QEXTSERIALPORT_BUILD_SHARED
12
+SOURCES                += $$PWD/qextserialport.cpp \
13
+                          $$PWD/qextserialenumerator.cpp
14
+unix {
15
+    SOURCES            += $$PWD/qextserialport_unix.cpp
16
+    linux* {
17
+        SOURCES        += $$PWD/qextserialenumerator_linux.cpp
18
+    } else:macx {
19
+        SOURCES        += $$PWD/qextserialenumerator_osx.cpp
20
+    } else {
21
+        SOURCES        += $$PWD/qextserialenumerator_unix.cpp
43 22
     }
44 23
 }
24
+win32:SOURCES          += $$PWD/qextserialport_win.cpp \
25
+                          $$PWD/qextserialenumerator_win.cpp
26
+
27
+linux*{
28
+    !qesp_linux_udev:DEFINES += QESP_NO_UDEV
29
+    qesp_linux_udev: LIBS += -ludev
30
+}
45 31
 
46 32
 macx:LIBS              += -framework IOKit -framework CoreFoundation
47 33
 win32:LIBS             += -lsetupapi -ladvapi32 -luser32
34
+
35
+# moc doesn't detect Q_OS_LINUX correctly, so add this to make it work
36
+linux*:DEFINES += __linux__

+ 2
- 2
src/3rdparty/qextserialport/src/qextserialport_global.h View File

@@ -57,13 +57,13 @@
57 57
 
58 58
 /*macros for warning and debug messages*/
59 59
 #ifdef QESP_NO_PORTABILITY_WARN
60
-#  define QESP_PORTABILITY_WARNING  while(false)qWarning
60
+#  define QESP_PORTABILITY_WARNING  while (false)qWarning
61 61
 #else
62 62
 #  define QESP_PORTABILITY_WARNING qWarning
63 63
 #endif /*QESP_NOWARN_PORT*/
64 64
 
65 65
 #ifdef QESP_NO_WARN
66
-#  define QESP_WARNING while(false)qWarning
66
+#  define QESP_WARNING while (false)qWarning
67 67
 #else
68 68
 #  define QESP_WARNING qWarning
69 69
 #endif /*QESP_NOWARN*/

+ 27
- 34
src/3rdparty/qextserialport/src/qextserialport_p.h View File

@@ -78,7 +78,7 @@ public:
78 78
         return len == 0;
79 79
     }
80 80
 
81
-    inline int read(char* target, int size) {
81
+    inline int read(char *target, int size) {
82 82
         int r = qMin(size, len);
83 83
         if (r == 1) {
84 84
             *target = *first;
@@ -92,14 +92,14 @@ public:
92 92
         return r;
93 93
     }
94 94
 
95
-    inline char* reserve(size_t size) {
95
+    inline char *reserve(size_t size) {
96 96
         if ((first - buf) + len + size > capacity) {
97 97
             size_t newCapacity = qMax(capacity, basicBlockSize);
98
-            while (newCapacity < size)
98
+            while (newCapacity < len + size)
99 99
                 newCapacity *= 2;
100 100
             if (newCapacity > capacity) {
101 101
                 // allocate more space
102
-                char* newBuf = new char[newCapacity];
102
+                char *newBuf = new char[newCapacity];
103 103
                 memmove(newBuf, first, len);
104 104
                 delete [] buf;
105 105
                 buf = newBuf;
@@ -110,17 +110,16 @@ public:
110 110
             }
111 111
             first = buf;
112 112
         }
113
-        char* writePtr = first + len;
113
+        char *writePtr = first + len;
114 114
         len += (int)size;
115 115
         return writePtr;
116 116
     }
117 117
 
118 118
     inline void chop(int size) {
119
-        if (size >= len) {
119
+        if (size >= len)
120 120
             clear();
121
-        } else {
121
+        else
122 122
             len -= size;
123
-        }
124 123
     }
125 124
 
126 125
     inline void squeeze() {
@@ -132,7 +131,7 @@ public:
132 131
         while (newCapacity < size_t(len))
133 132
             newCapacity *= 2;
134 133
         if (newCapacity < capacity) {
135
-            char * tmp = static_cast<char*>(realloc(buf, newCapacity));
134
+            char *tmp = static_cast<char *>(realloc(buf, newCapacity));
136 135
             if (tmp) {
137 136
                 buf = tmp;
138 137
                 capacity = newCapacity;
@@ -141,15 +140,15 @@ public:
141 140
     }
142 141
 
143 142
     inline QByteArray readAll() {
144
-        char* f = first;
143
+        char *f = first;
145 144
         int l = len;
146 145
         clear();
147 146
         return QByteArray(f, l);
148 147
     }
149 148
 
150
-    inline int readLine(char* target, int size) {
149
+    inline int readLine(char *target, int size) {
151 150
         int r = qMin(size, len);
152
-        char* eol = static_cast<char*>(memchr(first, '\n', r));
151
+        char *eol = static_cast<char *>(memchr(first, '\n', r));
153 152
         if (eol)
154 153
             r = 1+(eol-first);
155 154
         memcpy(target, first, r);
@@ -164,13 +163,12 @@ public:
164 163
 
165 164
 private:
166 165
     int len;
167
-    char* first;
168
-    char* buf;
166
+    char *first;
167
+    char *buf;
169 168
     size_t capacity;
170 169
     size_t basicBlockSize;
171 170
 };
172 171
 
173
-class QextWinEventNotifier;
174 172
 class QWinEventNotifier;
175 173
 class QReadWriteLock;
176 174
 class QSocketNotifier;
@@ -179,7 +177,7 @@ class QextSerialPortPrivate
179 177
 {
180 178
     Q_DECLARE_PUBLIC(QextSerialPort)
181 179
 public:
182
-    QextSerialPortPrivate(QextSerialPort * q);
180
+    QextSerialPortPrivate(QextSerialPort *q);
183 181
     ~QextSerialPortPrivate();
184 182
     enum DirtyFlagEnum
185 183
     {
@@ -194,32 +192,27 @@ public:
194 192
     };
195 193
     mutable QReadWriteLock lock;
196 194
     QString port;
197
-    PortSettings Settings;
195
+    PortSettings settings;
198 196
     QextReadBuffer readBuffer;
199 197
     int settingsDirtyFlags;
200 198
     ulong lastErr;
201
-    QextSerialPort::QueryMode _queryMode;
199
+    QextSerialPort::QueryMode queryMode;
202 200
 
203 201
     // platform specific members
204 202
 #ifdef Q_OS_UNIX
205 203
     int fd;
206 204
     QSocketNotifier *readNotifier;
207
-    struct termios Posix_CommConfig;
208
-    struct termios old_termios;
205
+    struct termios currentTermios;
206
+    struct termios oldTermios;
209 207
 #elif (defined Q_OS_WIN)
210
-    HANDLE Win_Handle;
208
+    HANDLE handle;
211 209
     OVERLAPPED overlap;
212
-    COMMCONFIG Win_CommConfig;
213
-    COMMTIMEOUTS Win_CommTimeouts;
214
-#  ifndef QESP_NO_QT4_PRIVATE
210
+    COMMCONFIG commConfig;
211
+    COMMTIMEOUTS commTimeouts;
215 212
     QWinEventNotifier *winEventNotifier;
216
-#  else
217
-    QextWinEventNotifier *winEventNotifier;
218
-#  endif
219 213
     DWORD eventMask;
220
-    QList<OVERLAPPED*> pendingWrites;
221
-    QReadWriteLock* bytesToWriteLock;
222
-    qint64 _bytesToWrite;
214
+    QList<OVERLAPPED *> pendingWrites;
215
+    QReadWriteLock *bytesToWriteLock;
223 216
 #endif
224 217
 
225 218
     /*fill PortSettings*/
@@ -229,15 +222,15 @@ public:
229 222
     void setStopBits(StopBitsType stopbits, bool update=true);
230 223
     void setFlowControl(FlowType flow, bool update=true);
231 224
     void setTimeout(long millisec, bool update=true);
232
-    void setPortSettings(const PortSettings& settings, bool update=true);
225
+    void setPortSettings(const PortSettings &settings, bool update=true);
233 226
 
234 227
     void platformSpecificDestruct();
235 228
     void platformSpecificInit();
236 229
     void translateError(ulong error);
237 230
     void updatePortSettings();
238 231
 
239
-    qint64 readData_sys(char * data, qint64 maxSize);
240
-    qint64 writeData_sys(const char * data, qint64 maxSize);
232
+    qint64 readData_sys(char *data, qint64 maxSize);
233
+    qint64 writeData_sys(const char *data, qint64 maxSize);
241 234
     void setDtr_sys(bool set=true);
242 235
     void setRts_sys(bool set=true);
243 236
     bool open_sys(QIODevice::OpenMode mode);
@@ -251,7 +244,7 @@ public:
251 244
 #endif
252 245
     void _q_canRead();
253 246
 
254
-    QextSerialPort * q_ptr;
247
+    QextSerialPort *q_ptr;
255 248
 };
256 249
 
257 250
 #endif //_QEXTSERIALPORT_P_H_

+ 102
- 92
src/3rdparty/qextserialport/src/qextserialport_unix.cpp View File

@@ -55,38 +55,45 @@ void QextSerialPortPrivate::platformSpecificDestruct()
55 55
 {
56 56
 }
57 57
 
58
+static QString fullPortName(const QString &name)
59
+{
60
+    if (name.startsWith(QLatin1Char('/')))
61
+        return name;
62
+    return QLatin1String("/dev/")+name;
63
+}
64
+
58 65
 bool QextSerialPortPrivate::open_sys(QIODevice::OpenMode mode)
59 66
 {
60 67
     Q_Q(QextSerialPort);
61 68
     //note: linux 2.6.21 seems to ignore O_NDELAY flag
62
-    if ((fd = ::open(port.toAscii() ,O_RDWR | O_NOCTTY | O_NDELAY)) != -1) {
69
+    if ((fd = ::open(fullPortName(port).toLatin1() ,O_RDWR | O_NOCTTY | O_NDELAY)) != -1) {
63 70
 
64 71
         /*In the Private class, We can not call QIODevice::open()*/
65 72
         q->setOpenMode(mode);             // Flag the port as opened
66
-        ::tcgetattr(fd, &old_termios);    // Save the old termios
67
-        Posix_CommConfig = old_termios;   // Make a working copy
68
-        ::cfmakeraw(&Posix_CommConfig);   // Enable raw access
73
+        ::tcgetattr(fd, &oldTermios);    // Save the old termios
74
+        currentTermios = oldTermios;   // Make a working copy
75
+        ::cfmakeraw(&currentTermios);   // Enable raw access
69 76
 
70 77
         /*set up other port settings*/
71
-        Posix_CommConfig.c_cflag |= CREAD|CLOCAL;
72
-        Posix_CommConfig.c_lflag &= (~(ICANON|ECHO|ECHOE|ECHOK|ECHONL|ISIG));
73
-        Posix_CommConfig.c_iflag &= (~(INPCK|IGNPAR|PARMRK|ISTRIP|ICRNL|IXANY));
74
-        Posix_CommConfig.c_oflag &= (~OPOST);
75
-        Posix_CommConfig.c_cc[VMIN] = 0;
78
+        currentTermios.c_cflag |= CREAD|CLOCAL;
79
+        currentTermios.c_lflag &= (~(ICANON|ECHO|ECHOE|ECHOK|ECHONL|ISIG));
80
+        currentTermios.c_iflag &= (~(INPCK|IGNPAR|PARMRK|ISTRIP|ICRNL|IXANY));
81
+        currentTermios.c_oflag &= (~OPOST);
82
+        currentTermios.c_cc[VMIN] = 0;
76 83
 #ifdef _POSIX_VDISABLE  // Is a disable character available on this system?
77 84
         // Some systems allow for per-device disable-characters, so get the
78 85
         //  proper value for the configured device
79 86
         const long vdisable = ::fpathconf(fd, _PC_VDISABLE);
80
-        Posix_CommConfig.c_cc[VINTR] = vdisable;
81
-        Posix_CommConfig.c_cc[VQUIT] = vdisable;
82
-        Posix_CommConfig.c_cc[VSTART] = vdisable;
83
-        Posix_CommConfig.c_cc[VSTOP] = vdisable;
84
-        Posix_CommConfig.c_cc[VSUSP] = vdisable;
87
+        currentTermios.c_cc[VINTR] = vdisable;
88
+        currentTermios.c_cc[VQUIT] = vdisable;
89
+        currentTermios.c_cc[VSTART] = vdisable;
90
+        currentTermios.c_cc[VSTOP] = vdisable;
91
+        currentTermios.c_cc[VSUSP] = vdisable;
85 92
 #endif //_POSIX_VDISABLE
86 93
         settingsDirtyFlags = DFE_ALL;
87 94
         updatePortSettings();
88 95
 
89
-        if (_queryMode == QextSerialPort::EventDriven) {
96
+        if (queryMode == QextSerialPort::EventDriven) {
90 97
             readNotifier = new QSocketNotifier(fd, QSocketNotifier::Read, q);
91 98
             q->connect(readNotifier, SIGNAL(activated(int)), q, SLOT(_q_canRead()));
92 99
         }
@@ -102,9 +109,9 @@ bool QextSerialPortPrivate::close_sys()
102 109
     // Force a flush and then restore the original termios
103 110
     flush_sys();
104 111
     // Using both TCSAFLUSH and TCSANOW here discards any pending input
105
-    ::tcsetattr(fd, TCSAFLUSH | TCSANOW, &old_termios);   // Restore termios
112
+    ::tcsetattr(fd, TCSAFLUSH | TCSANOW, &oldTermios);   // Restore termios
106 113
     ::close(fd);
107
-    if(readNotifier) {
114
+    if (readNotifier) {
108 115
         delete readNotifier;
109 116
         readNotifier = 0;
110 117
     }
@@ -120,9 +127,8 @@ bool QextSerialPortPrivate::flush_sys()
120 127
 qint64 QextSerialPortPrivate::bytesAvailable_sys() const
121 128
 {
122 129
     int bytesQueued;
123
-    if (::ioctl(fd, FIONREAD, &bytesQueued) == -1) {
130
+    if (::ioctl(fd, FIONREAD, &bytesQueued) == -1)
124 131
         return (qint64)-1;
125
-    }
126 132
     return bytesQueued;
127 133
 }
128 134
 
@@ -179,12 +185,12 @@ unsigned long QextSerialPortPrivate::lineStatus_sys()
179 185
     ::ioctl(fd, TIOCMGET, &Temp);
180 186
     if (Temp & TIOCM_CTS) Status |= LS_CTS;
181 187
     if (Temp & TIOCM_DSR) Status |= LS_DSR;
182
-    if (Temp & TIOCM_RI ) Status |= LS_RI;
183
-    if (Temp & TIOCM_CD ) Status |= LS_DCD;
188
+    if (Temp & TIOCM_RI) Status |= LS_RI;
189
+    if (Temp & TIOCM_CD) Status |= LS_DCD;
184 190
     if (Temp & TIOCM_DTR) Status |= LS_DTR;
185 191
     if (Temp & TIOCM_RTS) Status |= LS_RTS;
186
-    if (Temp & TIOCM_ST ) Status |= LS_ST;
187
-    if (Temp & TIOCM_SR ) Status |= LS_SR;
192
+    if (Temp & TIOCM_ST) Status |= LS_ST;
193
+    if (Temp & TIOCM_SR) Status |= LS_SR;
188 194
     return Status;
189 195
 }
190 196
 
@@ -196,7 +202,7 @@ unsigned long QextSerialPortPrivate::lineStatus_sys()
196 202
     \warning before calling this function ensure that serial port associated with this class
197 203
     is currently open (use isOpen() function to check if port is open).
198 204
 */
199
-qint64 QextSerialPortPrivate::readData_sys(char * data, qint64 maxSize)
205
+qint64 QextSerialPortPrivate::readData_sys(char *data, qint64 maxSize)
200 206
 {
201 207
     int retVal = ::read(fd, data, maxSize);
202 208
     if (retVal == -1)
@@ -213,7 +219,7 @@ qint64 QextSerialPortPrivate::readData_sys(char * data, qint64 maxSize)
213 219
     \warning before calling this function ensure that serial port associated with this class
214 220
     is currently open (use isOpen() function to check if port is open).
215 221
 */
216
-qint64 QextSerialPortPrivate::writeData_sys(const char * data, qint64 maxSize)
222
+qint64 QextSerialPortPrivate::writeData_sys(const char *data, qint64 maxSize)
217 223
 {
218 224
     int retVal = ::write(fd, data, maxSize);
219 225
     if (retVal == -1)
@@ -242,154 +248,159 @@ void QextSerialPortPrivate::updatePortSettings()
242 248
         return;
243 249
 
244 250
     if (settingsDirtyFlags & DFE_BaudRate) {
245
-        switch (Settings.BaudRate) {
251
+        switch (settings.BaudRate) {
246 252
         case BAUD50:
247
-            setBaudRate2Termios(&Posix_CommConfig, B50);
253
+            setBaudRate2Termios(&currentTermios, B50);
248 254
             break;
249 255
         case BAUD75:
250
-            setBaudRate2Termios(&Posix_CommConfig, B75);
256
+            setBaudRate2Termios(&currentTermios, B75);
251 257
             break;
252 258
         case BAUD110:
253
-            setBaudRate2Termios(&Posix_CommConfig, B110);
259
+            setBaudRate2Termios(&currentTermios, B110);
254 260
             break;
255 261
         case BAUD134:
256
-            setBaudRate2Termios(&Posix_CommConfig, B134);
262
+            setBaudRate2Termios(&currentTermios, B134);
257 263
             break;
258 264
         case BAUD150:
259
-            setBaudRate2Termios(&Posix_CommConfig, B150);
265
+            setBaudRate2Termios(&currentTermios, B150);
260 266
             break;
261 267
         case BAUD200:
262
-            setBaudRate2Termios(&Posix_CommConfig, B200);
268
+            setBaudRate2Termios(&currentTermios, B200);
263 269
             break;
264 270
         case BAUD300:
265
-            setBaudRate2Termios(&Posix_CommConfig, B300);
271
+            setBaudRate2Termios(&currentTermios, B300);
266 272
             break;
267 273
         case BAUD600:
268
-            setBaudRate2Termios(&Posix_CommConfig, B600);
274
+            setBaudRate2Termios(&currentTermios, B600);
269 275
             break;
270 276
         case BAUD1200:
271
-            setBaudRate2Termios(&Posix_CommConfig, B1200);
277
+            setBaudRate2Termios(&currentTermios, B1200);
272 278
             break;
273 279
         case BAUD1800:
274
-            setBaudRate2Termios(&Posix_CommConfig, B1800);
280
+            setBaudRate2Termios(&currentTermios, B1800);
275 281
             break;
276 282
         case BAUD2400:
277
-            setBaudRate2Termios(&Posix_CommConfig, B2400);
283
+            setBaudRate2Termios(&currentTermios, B2400);
278 284
             break;
279 285
         case BAUD4800:
280
-            setBaudRate2Termios(&Posix_CommConfig, B4800);
286
+            setBaudRate2Termios(&currentTermios, B4800);
281 287
             break;
282 288
         case BAUD9600:
283
-            setBaudRate2Termios(&Posix_CommConfig, B9600);
289
+            setBaudRate2Termios(&currentTermios, B9600);
284 290
             break;
285 291
         case BAUD19200:
286
-            setBaudRate2Termios(&Posix_CommConfig, B19200);
292
+            setBaudRate2Termios(&currentTermios, B19200);
287 293
             break;
288 294
         case BAUD38400:
289
-            setBaudRate2Termios(&Posix_CommConfig, B38400);
295
+            setBaudRate2Termios(&currentTermios, B38400);
290 296
             break;
291 297
         case BAUD57600:
292
-            setBaudRate2Termios(&Posix_CommConfig, B57600);
298
+            setBaudRate2Termios(&currentTermios, B57600);
293 299
             break;
294 300
 #ifdef B76800
295 301
         case BAUD76800:
296
-            setBaudRate2Termios(&Posix_CommConfig, B76800);
302
+            setBaudRate2Termios(&currentTermios, B76800);
297 303
             break;
298 304
 #endif
299 305
         case BAUD115200:
300
-            setBaudRate2Termios(&Posix_CommConfig, B115200);
306
+            setBaudRate2Termios(&currentTermios, B115200);
301 307
             break;
302 308
 #if defined(B230400) && defined(B4000000)
303 309
         case BAUD230400:
304
-            setBaudRate2Termios(&Posix_CommConfig, B230400);
310
+            setBaudRate2Termios(&currentTermios, B230400);
305 311
             break;
306 312
         case BAUD460800:
307
-            setBaudRate2Termios(&Posix_CommConfig, B460800);
313
+            setBaudRate2Termios(&currentTermios, B460800);
308 314
             break;
309 315
         case BAUD500000:
310
-            setBaudRate2Termios(&Posix_CommConfig, B500000);
316
+            setBaudRate2Termios(&currentTermios, B500000);
311 317
             break;
312 318
         case BAUD576000:
313
-            setBaudRate2Termios(&Posix_CommConfig, B576000);
319
+            setBaudRate2Termios(&currentTermios, B576000);
314 320
             break;
315 321
         case BAUD921600:
316
-            setBaudRate2Termios(&Posix_CommConfig, B921600);
322
+            setBaudRate2Termios(&currentTermios, B921600);
317 323
             break;
318 324
         case BAUD1000000:
319
-            setBaudRate2Termios(&Posix_CommConfig, B1000000);
325
+            setBaudRate2Termios(&currentTermios, B1000000);
320 326
             break;
321 327
         case BAUD1152000:
322
-            setBaudRate2Termios(&Posix_CommConfig, B1152000);
328
+            setBaudRate2Termios(&currentTermios, B1152000);
323 329
             break;
324 330
         case BAUD1500000:
325
-            setBaudRate2Termios(&Posix_CommConfig, B1500000);
331
+            setBaudRate2Termios(&currentTermios, B1500000);
326 332
             break;
327 333
         case BAUD2000000:
328
-            setBaudRate2Termios(&Posix_CommConfig, B2000000);
334
+            setBaudRate2Termios(&currentTermios, B2000000);
329 335
             break;
330 336
         case BAUD2500000:
331
-            setBaudRate2Termios(&Posix_CommConfig, B2500000);
337
+            setBaudRate2Termios(&currentTermios, B2500000);
332 338
             break;
333 339
         case BAUD3000000:
334
-            setBaudRate2Termios(&Posix_CommConfig, B3000000);
340
+            setBaudRate2Termios(&currentTermios, B3000000);
335 341
             break;
336 342
         case BAUD3500000:
337
-            setBaudRate2Termios(&Posix_CommConfig, B3500000);
343
+            setBaudRate2Termios(&currentTermios, B3500000);
338 344
             break;
339 345
         case BAUD4000000:
340
-            setBaudRate2Termios(&Posix_CommConfig, B4000000);
346
+            setBaudRate2Termios(&currentTermios, B4000000);
347
+            break;
348
+#endif
349
+#ifdef Q_OS_MAC
350
+        default:
351
+            setBaudRate2Termios(&currentTermios, settings.BaudRate);
341 352
             break;
342 353
 #endif
343 354
         }
344 355
     }
345 356
     if (settingsDirtyFlags & DFE_Parity) {
346
-        switch (Settings.Parity) {
357
+        switch (settings.Parity) {
347 358
         case PAR_SPACE:
348 359
             /*space parity not directly supported - add an extra data bit to simulate it*/
349 360
             settingsDirtyFlags |= DFE_DataBits;
350 361
             break;
351 362
         case PAR_NONE:
352
-            Posix_CommConfig.c_cflag &= (~PARENB);
363
+            currentTermios.c_cflag &= (~PARENB);
353 364
             break;
354 365
         case PAR_EVEN:
355
-            Posix_CommConfig.c_cflag &= (~PARODD);
356
-            Posix_CommConfig.c_cflag |= PARENB;
366
+            currentTermios.c_cflag &= (~PARODD);
367
+            currentTermios.c_cflag |= PARENB;
357 368
             break;
358 369
         case PAR_ODD:
359
-            Posix_CommConfig.c_cflag |= (PARENB|PARODD);
370
+            currentTermios.c_cflag |= (PARENB|PARODD);
360 371
             break;
361 372
         }
362 373
     }
363 374
     /*must after Parity settings*/
364 375
     if (settingsDirtyFlags & DFE_DataBits) {
365
-        if (Settings.Parity != PAR_SPACE) {
366
-            Posix_CommConfig.c_cflag &= (~CSIZE);
367
-            switch(Settings.DataBits) {
376
+        if (settings.Parity != PAR_SPACE) {
377
+            currentTermios.c_cflag &= (~CSIZE);
378
+            switch(settings.DataBits) {
368 379
             case DATA_5:
369
-                Posix_CommConfig.c_cflag |= CS5;
380
+                currentTermios.c_cflag |= CS5;
370 381
                 break;
371 382
             case DATA_6:
372
-                Posix_CommConfig.c_cflag |= CS6;
383
+                currentTermios.c_cflag |= CS6;
373 384
                 break;
374 385
             case DATA_7:
375
-                Posix_CommConfig.c_cflag |= CS7;
386
+                currentTermios.c_cflag |= CS7;
376 387
                 break;
377 388
             case DATA_8:
378
-                Posix_CommConfig.c_cflag |= CS8;
389
+                currentTermios.c_cflag |= CS8;
379 390
                 break;
380 391
             }
381 392
         } else {
382 393
             /*space parity not directly supported - add an extra data bit to simulate it*/
383
-            Posix_CommConfig.c_cflag &= ~(PARENB|CSIZE);
384
-            switch(Settings.DataBits) {
394
+            currentTermios.c_cflag &= ~(PARENB|CSIZE);
395
+            switch(settings.DataBits) {
385 396
             case DATA_5:
386
-                Posix_CommConfig.c_cflag |= CS6;
397
+                currentTermios.c_cflag |= CS6;
387 398
                 break;
388 399
             case DATA_6:
389
-                Posix_CommConfig.c_cflag |= CS7;
400
+                currentTermios.c_cflag |= CS7;
390 401
                 break;
391 402
             case DATA_7:
392
-                Posix_CommConfig.c_cflag |= CS8;
403
+                currentTermios.c_cflag |= CS8;
393 404
                 break;
394 405
             case DATA_8:
395 406
                 /*this will never happen, put here to Suppress an warning*/
@@ -398,50 +409,49 @@ void QextSerialPortPrivate::updatePortSettings()
398 409
         }
399 410
     }
400 411
     if (settingsDirtyFlags & DFE_StopBits) {
401
-        switch (Settings.StopBits) {
412
+        switch (settings.StopBits) {
402 413
         case STOP_1:
403
-            Posix_CommConfig.c_cflag &= (~CSTOPB);
414
+            currentTermios.c_cflag &= (~CSTOPB);
404 415
             break;
405 416
         case STOP_2:
406
-            Posix_CommConfig.c_cflag |= CSTOPB;
417
+            currentTermios.c_cflag |= CSTOPB;
407 418
             break;
408 419
         }
409 420
     }
410 421
     if (settingsDirtyFlags & DFE_Flow) {
411
-        switch(Settings.FlowControl) {
422
+        switch(settings.FlowControl) {
412 423
         case FLOW_OFF:
413
-            Posix_CommConfig.c_cflag &= (~CRTSCTS);
414
-            Posix_CommConfig.c_iflag &= (~(IXON|IXOFF|IXANY));
424
+            currentTermios.c_cflag &= (~CRTSCTS);
425
+            currentTermios.c_iflag &= (~(IXON|IXOFF|IXANY));
415 426
             break;
416 427
         case FLOW_XONXOFF:
417 428
             /*software (XON/XOFF) flow control*/
418
-            Posix_CommConfig.c_cflag &= (~CRTSCTS);
419
-            Posix_CommConfig.c_iflag |= (IXON|IXOFF|IXANY);
429
+            currentTermios.c_cflag &= (~CRTSCTS);
430
+            currentTermios.c_iflag |= (IXON|IXOFF|IXANY);
420 431
             break;
421 432
         case FLOW_HARDWARE:
422
-            Posix_CommConfig.c_cflag |= CRTSCTS;
423
-            Posix_CommConfig.c_iflag &= (~(IXON|IXOFF|IXANY));
433
+            currentTermios.c_cflag |= CRTSCTS;
434
+            currentTermios.c_iflag &= (~(IXON|IXOFF|IXANY));
424 435
             break;
425 436
         }
426 437
     }
427 438
 
428
-    /*if any thing in Posix_CommConfig changed, flush*/
439
+    /*if any thing in currentTermios changed, flush*/
429 440
     if (settingsDirtyFlags & DFE_Settings_Mask)
430
-        ::tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig);
441
+        ::tcsetattr(fd, TCSAFLUSH, &currentTermios);
431 442
 
432 443
     if (settingsDirtyFlags & DFE_TimeOut) {
433
-        int millisec = Settings.Timeout_Millisec;
444
+        int millisec = settings.Timeout_Millisec;
434 445
         if (millisec == -1) {
435 446
             ::fcntl(fd, F_SETFL, O_NDELAY);
436
-        }
437
-        else {
447
+        } else {
438 448
             //O_SYNC should enable blocking ::write()
439 449
             //however this seems not working on Linux 2.6.21 (works on OpenBSD 4.2)
440 450
             ::fcntl(fd, F_SETFL, O_SYNC);
441 451
         }
442
-        ::tcgetattr(fd, & Posix_CommConfig);
443
-        Posix_CommConfig.c_cc[VTIME] = millisec/100;
444
-        ::tcsetattr(fd, TCSAFLUSH, & Posix_CommConfig);
452
+        ::tcgetattr(fd, &currentTermios);
453
+        currentTermios.c_cc[VTIME] = millisec/100;
454
+        ::tcsetattr(fd, TCSAFLUSH, &currentTermios);
445 455
     }
446 456
 
447 457
     settingsDirtyFlags = 0;

+ 113
- 135
src/3rdparty/qextserialport/src/qextserialport_win.cpp View File

@@ -39,22 +39,16 @@
39 39
 #include <QtCore/QMetaType>
40 40
 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
41 41
 #  include <QtCore/QWinEventNotifier>
42
-#  define WinEventNotifier QWinEventNotifier
43
-#elif !defined(QESP_NO_QT4_PRIVATE)
44
-#  include <QtCore/private/qwineventnotifier_p.h>
45
-#  define WinEventNotifier QWinEventNotifier
46 42
 #else
47
-#  include "qextwineventnotifier_p.h"
48
-#  define WinEventNotifier QextWinEventNotifier
43
+#  include <QtCore/private/qwineventnotifier_p.h>
49 44
 #endif
50 45
 void QextSerialPortPrivate::platformSpecificInit()
51 46
 {
52
-    Win_Handle=INVALID_HANDLE_VALUE;
47
+    handle = INVALID_HANDLE_VALUE;
53 48
     ZeroMemory(&overlap, sizeof(OVERLAPPED));
54 49
     overlap.hEvent = CreateEvent(NULL, true, false, NULL);
55 50
     winEventNotifier = 0;
56 51
     bytesToWriteLock = new QReadWriteLock;
57
-    _bytesToWrite = 0;
58 52
 }
59 53
 
60 54
 void QextSerialPortPrivate::platformSpecificDestruct() {
@@ -69,11 +63,11 @@ void QextSerialPortPrivate::platformSpecificDestruct() {
69 63
 
70 64
     This is only need when open the port.
71 65
 */
72
-static QString fullPortNameWin(const QString & name)
66
+static QString fullPortNameWin(const QString &name)
73 67
 {
74 68
     QRegExp rx(QLatin1String("^COM(\\d+)"));
75 69
     QString fullName(name);
76
-    if(fullName.contains(rx))
70
+    if (fullName.contains(rx))
77 71
         fullName.prepend(QLatin1String("\\\\.\\"));
78 72
     return fullName;
79 73
 }
@@ -82,42 +76,42 @@ bool QextSerialPortPrivate::open_sys(QIODevice::OpenMode mode)
82 76
 {
83 77
     Q_Q(QextSerialPort);
84 78
     DWORD confSize = sizeof(COMMCONFIG);
85
-    Win_CommConfig.dwSize = confSize;
79
+    commConfig.dwSize = confSize;
86 80
     DWORD dwFlagsAndAttributes = 0;
87
-    if (_queryMode == QextSerialPort::EventDriven)
81
+    if (queryMode == QextSerialPort::EventDriven)
88 82
         dwFlagsAndAttributes += FILE_FLAG_OVERLAPPED;
89 83
 
90 84
     /*open the port*/
91
-    Win_Handle=CreateFileW((wchar_t*)fullPortNameWin(port).utf16(), GENERIC_READ|GENERIC_WRITE,
85
+    handle = CreateFileW((wchar_t *)fullPortNameWin(port).utf16(), GENERIC_READ|GENERIC_WRITE,
92 86
                            0, NULL, OPEN_EXISTING, dwFlagsAndAttributes, NULL);
93
-    if (Win_Handle!=INVALID_HANDLE_VALUE) {
87
+    if (handle != INVALID_HANDLE_VALUE) {
94 88
         q->setOpenMode(mode);
95 89
         /*configure port settings*/
96
-        GetCommConfig(Win_Handle, &Win_CommConfig, &confSize);
97
-        GetCommState(Win_Handle, &(Win_CommConfig.dcb));
90
+        GetCommConfig(handle, &commConfig, &confSize);
91
+        GetCommState(handle, &(commConfig.dcb));
98 92
 
99 93
         /*set up parameters*/
100
-        Win_CommConfig.dcb.fBinary=TRUE;
101
-        Win_CommConfig.dcb.fInX=FALSE;
102
-        Win_CommConfig.dcb.fOutX=FALSE;
103
-        Win_CommConfig.dcb.fAbortOnError=FALSE;
104
-        Win_CommConfig.dcb.fNull=FALSE;
94
+        commConfig.dcb.fBinary = TRUE;
95
+        commConfig.dcb.fInX = FALSE;
96
+        commConfig.dcb.fOutX = FALSE;
97
+        commConfig.dcb.fAbortOnError = FALSE;
98
+        commConfig.dcb.fNull = FALSE;
105 99
         /* Dtr default to true. See Issue 122*/
106
-        Win_CommConfig.dcb.fDtrControl=TRUE;
100
+        commConfig.dcb.fDtrControl = TRUE;
107 101
         /*flush all settings*/
108 102
         settingsDirtyFlags = DFE_ALL;
109 103
         updatePortSettings();
110 104
 
111 105
         //init event driven approach
112
-        if (_queryMode == QextSerialPort::EventDriven) {
113
-            if (!SetCommMask( Win_Handle, EV_TXEMPTY | EV_RXCHAR | EV_DSR)) {
106
+        if (queryMode == QextSerialPort::EventDriven) {
107
+            if (!SetCommMask(handle, EV_TXEMPTY | EV_RXCHAR | EV_DSR)) {
114 108
                 QESP_WARNING()<<"failed to set Comm Mask. Error code:"<<GetLastError();
115 109
                 return false;
116 110
             }
117
-            winEventNotifier = new WinEventNotifier(overlap.hEvent, q);
111
+            winEventNotifier = new QWinEventNotifier(overlap.hEvent, q);
118 112
             qRegisterMetaType<HANDLE>("HANDLE");
119 113
             q->connect(winEventNotifier, SIGNAL(activated(HANDLE)), q, SLOT(_q_onWinEvent(HANDLE)), Qt::DirectConnection);
120
-            WaitCommEvent(Win_Handle, &eventMask, &overlap);
114
+            WaitCommEvent(handle, &eventMask, &overlap);
121 115
         }
122 116
         return true;
123 117
     }
@@ -127,17 +121,16 @@ bool QextSerialPortPrivate::open_sys(QIODevice::OpenMode mode)
127 121
 bool QextSerialPortPrivate::close_sys()
128 122
 {
129 123
     flush_sys();
130
-    CancelIo(Win_Handle);
131
-    if (CloseHandle(Win_Handle))
132
-        Win_Handle = INVALID_HANDLE_VALUE;
133
-    if (winEventNotifier){
124
+    CancelIo(handle);
125
+    if (CloseHandle(handle))
126
+        handle = INVALID_HANDLE_VALUE;
127
+    if (winEventNotifier) {
134 128
         winEventNotifier->setEnabled(false);
135 129
         winEventNotifier->deleteLater();
136 130
         winEventNotifier = 0;
137 131
     }
138
-    _bytesToWrite = 0;
139 132
 
140
-    foreach(OVERLAPPED* o, pendingWrites) {
133
+    foreach (OVERLAPPED *o, pendingWrites) {
141 134
         CloseHandle(o->hEvent);
142 135
         delete o;
143 136
     }
@@ -147,7 +140,7 @@ bool QextSerialPortPrivate::close_sys()
147 140
 
148 141
 bool QextSerialPortPrivate::flush_sys()
149 142
 {
150
-    FlushFileBuffers(Win_Handle);
143
+    FlushFileBuffers(handle);
151 144
     return true;
152 145
 }
153 146
 
@@ -155,9 +148,9 @@ qint64 QextSerialPortPrivate::bytesAvailable_sys() const
155 148
 {
156 149
     DWORD Errors;
157 150
     COMSTAT Status;
158
-    if (ClearCommError(Win_Handle, &Errors, &Status)) {
151
+    if (ClearCommError(handle, &Errors, &Status))
159 152
         return Status.cbInQue;
160
-    }
153
+
161 154
     return (qint64)-1;
162 155
 }
163 156
 
@@ -166,29 +159,22 @@ qint64 QextSerialPortPrivate::bytesAvailable_sys() const
166 159
 */
167 160
 void QextSerialPortPrivate::translateError(ulong error)
168 161
 {
169
-    if (error&CE_BREAK) {
170
-        lastErr=E_BREAK_CONDITION;
171
-    }
172
-    else if (error&CE_FRAME) {
173
-        lastErr=E_FRAMING_ERROR;
174
-    }
175
-    else if (error&CE_IOE) {
176
-        lastErr=E_IO_ERROR;
177
-    }
178
-    else if (error&CE_MODE) {
179
-        lastErr=E_INVALID_FD;
180
-    }
181
-    else if (error&CE_OVERRUN) {
182
-        lastErr=E_BUFFER_OVERRUN;
183
-    }
184
-    else if (error&CE_RXPARITY) {
185
-        lastErr=E_RECEIVE_PARITY_ERROR;
186
-    }
187
-    else if (error&CE_RXOVER) {
188
-        lastErr=E_RECEIVE_OVERFLOW;
189
-    }
190
-    else if (error&CE_TXFULL) {
191
-        lastErr=E_TRANSMIT_OVERFLOW;
162
+    if (error & CE_BREAK) {
163
+        lastErr = E_BREAK_CONDITION;
164
+    } else if (error & CE_FRAME) {
165
+        lastErr = E_FRAMING_ERROR;
166
+    } else if (error & CE_IOE) {
167
+        lastErr = E_IO_ERROR;
168
+    } else if (error & CE_MODE) {
169
+        lastErr = E_INVALID_FD;
170
+    } else if (error & CE_OVERRUN) {
171
+        lastErr = E_BUFFER_OVERRUN;
172
+    } else if (error & CE_RXPARITY) {
173
+        lastErr = E_RECEIVE_PARITY_ERROR;
174
+    } else if (error & CE_RXOVER) {
175
+        lastErr = E_RECEIVE_OVERFLOW;
176
+    } else if (error & CE_TXFULL) {
177
+        lastErr = E_TRANSMIT_OVERFLOW;
192 178
     }
193 179
 }
194 180
 
@@ -204,16 +190,16 @@ qint64 QextSerialPortPrivate::readData_sys(char *data, qint64 maxSize)
204 190
 {
205 191
     DWORD bytesRead = 0;
206 192
     bool failed = false;
207
-    if (_queryMode == QextSerialPort::EventDriven) {
193
+    if (queryMode == QextSerialPort::EventDriven) {
208 194
         OVERLAPPED overlapRead;
209 195
         ZeroMemory(&overlapRead, sizeof(OVERLAPPED));
210
-        if (!ReadFile(Win_Handle, (void*)data, (DWORD)maxSize, & bytesRead, & overlapRead)) {
196
+        if (!ReadFile(handle, (void *)data, (DWORD)maxSize, &bytesRead, &overlapRead)) {
211 197
             if (GetLastError() == ERROR_IO_PENDING)
212
-                GetOverlappedResult(Win_Handle, & overlapRead, & bytesRead, true);
198
+                GetOverlappedResult(handle, &overlapRead, &bytesRead, true);
213 199
             else
214 200
                 failed = true;
215 201
         }
216
-    } else if (!ReadFile(Win_Handle, (void*)data, (DWORD)maxSize, & bytesRead, NULL)) {
202
+    } else if (!ReadFile(handle, (void *)data, (DWORD)maxSize, &bytesRead, NULL)) {
217 203
         failed = true;
218 204
     }
219 205
     if (!failed)
@@ -235,30 +221,27 @@ qint64 QextSerialPortPrivate::writeData_sys(const char *data, qint64 maxSize)
235 221
 {
236 222
     DWORD bytesWritten = 0;
237 223
     bool failed = false;
238
-    if (_queryMode == QextSerialPort::EventDriven) {
239
-        OVERLAPPED* newOverlapWrite = new OVERLAPPED;
224
+    if (queryMode == QextSerialPort::EventDriven) {
225
+        OVERLAPPED *newOverlapWrite = new OVERLAPPED;
240 226
         ZeroMemory(newOverlapWrite, sizeof(OVERLAPPED));
241 227
         newOverlapWrite->hEvent = CreateEvent(NULL, true, false, NULL);
242
-        if (WriteFile(Win_Handle, (void*)data, (DWORD)maxSize, & bytesWritten, newOverlapWrite)) {
228
+        if (WriteFile(handle, (void *)data, (DWORD)maxSize, &bytesWritten, newOverlapWrite)) {
243 229
             CloseHandle(newOverlapWrite->hEvent);
244 230
             delete newOverlapWrite;
245
-        }
246
-        else if (GetLastError() == ERROR_IO_PENDING) {
231
+        } else if (GetLastError() == ERROR_IO_PENDING) {
247 232
             // writing asynchronously...not an error
248 233
             QWriteLocker writelocker(bytesToWriteLock);
249
-            _bytesToWrite += maxSize;
250 234
             pendingWrites.append(newOverlapWrite);
251
-        }
252
-        else {
235
+        } else {
253 236
             QESP_WARNING()<<"QextSerialPort write error:"<<GetLastError();
254 237
             failed = true;
255
-            if(!CancelIo(newOverlapWrite->hEvent))
238
+            if (!CancelIo(newOverlapWrite->hEvent))
256 239
                 QESP_WARNING("QextSerialPort: couldn't cancel IO");
257
-            if(!CloseHandle(newOverlapWrite->hEvent))
240
+            if (!CloseHandle(newOverlapWrite->hEvent))
258 241
                 QESP_WARNING("QextSerialPort: couldn't close OVERLAPPED handle");
259 242
             delete newOverlapWrite;
260 243
         }
261
-    } else if (!WriteFile(Win_Handle, (void*)data, (DWORD)maxSize, & bytesWritten, NULL)) {
244
+    } else if (!WriteFile(handle, (void *)data, (DWORD)maxSize, &bytesWritten, NULL)) {
262 245
         failed = true;
263 246
     }
264 247
 
@@ -270,20 +253,20 @@ qint64 QextSerialPortPrivate::writeData_sys(const char *data, qint64 maxSize)
270 253
 }
271 254
 
272 255
 void QextSerialPortPrivate::setDtr_sys(bool set) {
273
-    EscapeCommFunction(Win_Handle, set ? SETDTR : CLRDTR);
256
+    EscapeCommFunction(handle, set ? SETDTR : CLRDTR);
274 257
 }
275 258
 
276 259
 void QextSerialPortPrivate::setRts_sys(bool set) {
277
-    EscapeCommFunction(Win_Handle, set ? SETRTS : CLRRTS);
260
+    EscapeCommFunction(handle, set ? SETRTS : CLRRTS);
278 261
 }
279 262
 
280 263
 ulong QextSerialPortPrivate::lineStatus_sys(void) {
281
-    unsigned long Status=0, Temp=0;
282
-    GetCommModemStatus(Win_Handle, &Temp);
283
-    if (Temp & MS_CTS_ON) Status|=LS_CTS;
284
-    if (Temp & MS_DSR_ON) Status|=LS_DSR;
285
-    if (Temp & MS_RING_ON) Status|=LS_RI;
286
-    if (Temp & MS_RLSD_ON) Status|=LS_DCD;
264
+    unsigned long Status = 0, Temp = 0;
265
+    GetCommModemStatus(handle, &Temp);
266
+    if (Temp & MS_CTS_ON) Status |= LS_CTS;
267
+    if (Temp & MS_DSR_ON) Status |= LS_DSR;
268
+    if (Temp & MS_RING_ON) Status |= LS_RI;
269
+    if (Temp & MS_RLSD_ON) Status |= LS_DCD;
287 270
     return Status;
288 271
 }
289 272
 
@@ -293,7 +276,7 @@ ulong QextSerialPortPrivate::lineStatus_sys(void) {
293 276
 void QextSerialPortPrivate::_q_onWinEvent(HANDLE h)
294 277
 {
295 278
     Q_Q(QextSerialPort);
296
-    if(h == overlap.hEvent) {
279
+    if (h == overlap.hEvent) {
297 280
         if (eventMask & EV_RXCHAR) {
298 281
             if (q->sender() != q && bytesAvailable_sys() > 0)
299 282
                 _q_canRead();
@@ -305,25 +288,23 @@ void QextSerialPortPrivate::_q_onWinEvent(HANDLE h)
305 288
               Otherwise, leave them on there so they can finish.
306 289
             */
307 290
             qint64 totalBytesWritten = 0;
308
-            QList<OVERLAPPED*> overlapsToDelete;
309
-            foreach(OVERLAPPED* o, pendingWrites) {
291
+            QList<OVERLAPPED *> overlapsToDelete;
292
+            QWriteLocker writelocker(bytesToWriteLock);
293
+            foreach (OVERLAPPED *o, pendingWrites) {
310 294
                 DWORD numBytes = 0;
311
-                if (GetOverlappedResult(Win_Handle, o, & numBytes, false)) {
295
+                if (GetOverlappedResult(handle, o, &numBytes, false)) {
312 296
                     overlapsToDelete.append(o);
313 297
                     totalBytesWritten += numBytes;
314
-                } else if( GetLastError() != ERROR_IO_INCOMPLETE ) {
298
+                } else if (GetLastError() != ERROR_IO_INCOMPLETE) {
315 299
                     overlapsToDelete.append(o);
316 300
                     QESP_WARNING()<<"CommEvent overlapped write error:" << GetLastError();
317 301
                 }
318 302
             }
319 303
 
320
-            if (q->sender() != q && totalBytesWritten > 0) {
321
-                QWriteLocker writelocker(bytesToWriteLock);
304
+            if (q->sender() != q && totalBytesWritten > 0)
322 305
                 Q_EMIT q->bytesWritten(totalBytesWritten);
323
-                _bytesToWrite = 0;
324
-            }
325 306
 
326
-            foreach(OVERLAPPED* o, overlapsToDelete) {
307
+            foreach (OVERLAPPED *o, overlapsToDelete) {
327 308
                 OVERLAPPED *toDelete = pendingWrites.takeAt(pendingWrites.indexOf(o));
328 309
                 CloseHandle(toDelete->hEvent);
329 310
                 delete toDelete;
@@ -336,7 +317,7 @@ void QextSerialPortPrivate::_q_onWinEvent(HANDLE h)
336 317
                 Q_EMIT q->dsrChanged(false);
337 318
         }
338 319
     }
339
-    WaitCommEvent(Win_Handle, &eventMask, &overlap);
320
+    WaitCommEvent(handle, &eventMask, &overlap);
340 321
 }
341 322
 
342 323
 void QextSerialPortPrivate::updatePortSettings()
@@ -345,83 +326,80 @@ void QextSerialPortPrivate::updatePortSettings()
345 326
         return;
346 327
 
347 328
     //fill struct : COMMCONFIG
348
-    if (settingsDirtyFlags & DFE_BaudRate) {
349
-        Win_CommConfig.dcb.BaudRate = Settings.BaudRate;
350
-    }
329
+    if (settingsDirtyFlags & DFE_BaudRate)
330
+        commConfig.dcb.BaudRate = settings.BaudRate;
351 331
     if (settingsDirtyFlags & DFE_Parity) {
352
-        Win_CommConfig.dcb.Parity = (BYTE)Settings.Parity;
353
-        Win_CommConfig.dcb.fParity = (Settings.Parity == PAR_NONE) ? FALSE : TRUE;
354
-    }
355
-    if (settingsDirtyFlags & DFE_DataBits) {
356
-        Win_CommConfig.dcb.ByteSize = (BYTE)Settings.DataBits;
332
+        commConfig.dcb.Parity = (BYTE)settings.Parity;
333
+        commConfig.dcb.fParity = (settings.Parity == PAR_NONE) ? FALSE : TRUE;
357 334
     }
335
+    if (settingsDirtyFlags & DFE_DataBits)
336
+        commConfig.dcb.ByteSize = (BYTE)settings.DataBits;
358 337
     if (settingsDirtyFlags & DFE_StopBits) {
359
-        switch (Settings.StopBits) {
338
+        switch (settings.StopBits) {
360 339
         case STOP_1:
361
-            Win_CommConfig.dcb.StopBits = ONESTOPBIT;
340
+            commConfig.dcb.StopBits = ONESTOPBIT;
362 341
             break;
363 342
         case STOP_1_5:
364
-            Win_CommConfig.dcb.StopBits = ONE5STOPBITS;
343
+            commConfig.dcb.StopBits = ONE5STOPBITS;
365 344
             break;
366 345
         case STOP_2:
367
-            Win_CommConfig.dcb.StopBits = TWOSTOPBITS;
346
+            commConfig.dcb.StopBits = TWOSTOPBITS;
368 347
             break;
369 348
         }
370 349
     }
371 350
     if (settingsDirtyFlags & DFE_Flow) {
372
-        switch(Settings.FlowControl) {
351
+        switch(settings.FlowControl) {
373 352
         /*no flow control*/
374 353
         case FLOW_OFF:
375
-            Win_CommConfig.dcb.fOutxCtsFlow=FALSE;
376
-            Win_CommConfig.dcb.fRtsControl=RTS_CONTROL_DISABLE;
377
-            Win_CommConfig.dcb.fInX=FALSE;
378
-            Win_CommConfig.dcb.fOutX=FALSE;
354
+            commConfig.dcb.fOutxCtsFlow = FALSE;
355
+            commConfig.dcb.fRtsControl = RTS_CONTROL_DISABLE;
356
+            commConfig.dcb.fInX = FALSE;
357
+            commConfig.dcb.fOutX = FALSE;
379 358
             break;
380 359
         /*software (XON/XOFF) flow control*/
381 360
         case FLOW_XONXOFF:
382
-            Win_CommConfig.dcb.fOutxCtsFlow=FALSE;
383
-            Win_CommConfig.dcb.fRtsControl=RTS_CONTROL_DISABLE;
384
-            Win_CommConfig.dcb.fInX=TRUE;
385
-            Win_CommConfig.dcb.fOutX=TRUE;
361
+            commConfig.dcb.fOutxCtsFlow = FALSE;
362
+            commConfig.dcb.fRtsControl = RTS_CONTROL_DISABLE;
363
+            commConfig.dcb.fInX = TRUE;
364
+            commConfig.dcb.fOutX = TRUE;
386 365
             break;
387 366
         /*hardware flow control*/
388 367
         case FLOW_HARDWARE:
389
-            Win_CommConfig.dcb.fOutxCtsFlow=TRUE;
390
-            Win_CommConfig.dcb.fRtsControl=RTS_CONTROL_HANDSHAKE;
391
-            Win_CommConfig.dcb.fInX=FALSE;
392
-            Win_CommConfig.dcb.fOutX=FALSE;
368
+            commConfig.dcb.fOutxCtsFlow = TRUE;
369
+            commConfig.dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;
370
+            commConfig.dcb.fInX = FALSE;
371
+            commConfig.dcb.fOutX = FALSE;
393 372
             break;
394 373
         }
395 374
     }
396 375
 
397 376
     //fill struct : COMMTIMEOUTS
398 377
     if (settingsDirtyFlags & DFE_TimeOut) {
399
-        if (_queryMode != QextSerialPort::EventDriven) {
400
-            int millisec = Settings.Timeout_Millisec;
378
+        if (queryMode != QextSerialPort::EventDriven) {
379
+            int millisec = settings.Timeout_Millisec;
401 380
             if (millisec == -1) {
402
-                Win_CommTimeouts.ReadIntervalTimeout = MAXDWORD;
403
-                Win_CommTimeouts.ReadTotalTimeoutConstant = 0;
381
+                commTimeouts.ReadIntervalTimeout = MAXDWORD;
382
+                commTimeouts.ReadTotalTimeoutConstant = 0;
404 383
             } else {
405
-                Win_CommTimeouts.ReadIntervalTimeout = millisec;
406
-                Win_CommTimeouts.ReadTotalTimeoutConstant = millisec;
384
+                commTimeouts.ReadIntervalTimeout = millisec;
385
+                commTimeouts.ReadTotalTimeoutConstant = millisec;
407 386
             }
408
-            Win_CommTimeouts.ReadTotalTimeoutMultiplier = 0;
409
-            Win_CommTimeouts.WriteTotalTimeoutMultiplier = millisec;
410
-            Win_CommTimeouts.WriteTotalTimeoutConstant = 0;
411
-        }
412
-        else {
413
-            Win_CommTimeouts.ReadIntervalTimeout = MAXDWORD;
414
-            Win_CommTimeouts.ReadTotalTimeoutMultiplier = 0;
415
-            Win_CommTimeouts.ReadTotalTimeoutConstant = 0;
416
-            Win_CommTimeouts.WriteTotalTimeoutMultiplier = 0;
417
-            Win_CommTimeouts.WriteTotalTimeoutConstant = 0;
387
+            commTimeouts.ReadTotalTimeoutMultiplier = 0;
388
+            commTimeouts.WriteTotalTimeoutMultiplier = millisec;
389
+            commTimeouts.WriteTotalTimeoutConstant = 0;
390
+        } else {
391
+            commTimeouts.ReadIntervalTimeout = MAXDWORD;
392
+            commTimeouts.ReadTotalTimeoutMultiplier = 0;
393
+            commTimeouts.ReadTotalTimeoutConstant = 0;
394
+            commTimeouts.WriteTotalTimeoutMultiplier = 0;
395
+            commTimeouts.WriteTotalTimeoutConstant = 0;
418 396
         }
419 397
     }
420 398
 
421 399
 
422 400
     if (settingsDirtyFlags & DFE_Settings_Mask)
423
-        SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
401
+        SetCommConfig(handle, &commConfig, sizeof(COMMCONFIG));
424 402
     if ((settingsDirtyFlags & DFE_TimeOut))
425
-        SetCommTimeouts(Win_Handle, &Win_CommTimeouts);
403
+        SetCommTimeouts(handle, &commTimeouts);
426 404
     settingsDirtyFlags = 0;
427 405
 }

+ 0
- 247
src/3rdparty/qextserialport/src/qextwineventnotifier_p.cpp View File

@@ -1,247 +0,0 @@
1
-/****************************************************************************
2
-** Copyright (c) 2000-2003 Wayne Roth
3
-** Copyright (c) 2004-2007 Stefan Sander
4
-** Copyright (c) 2007 Michal Policht
5
-** Copyright (c) 2008 Brandon Fosdick
6
-** Copyright (c) 2009-2010 Liam Staskawicz
7
-** Copyright (c) 2011 Debao Zhang
8
-** All right reserved.
9
-** Web: http://code.google.com/p/qextserialport/
10
-**
11
-** Permission is hereby granted, free of charge, to any person obtaining
12
-** a copy of this software and associated documentation files (the
13
-** "Software"), to deal in the Software without restriction, including
14
-** without limitation the rights to use, copy, modify, merge, publish,
15
-** distribute, sublicense, and/or sell copies of the Software, and to
16
-** permit persons to whom the Software is furnished to do so, subject to
17
-** the following conditions:
18
-**
19
-** The above copyright notice and this permission notice shall be
20
-** included in all copies or substantial portions of the Software.
21
-**
22
-** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23
-** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
-** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25
-** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26
-** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27
-** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28
-** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
-**
30
-****************************************************************************/
31
-
32
-#include "qextwineventnotifier_p.h"
33
-#include <QtCore/QThread>
34
-#include <QtCore/QList>
35
-#include <QtCore/QMutex>
36
-#include <QtCore/QMutexLocker>
37
-#include <QtCore/QEvent>
38
-#include <QtCore/QDebug>
39
-#include <QtCore/QCoreApplication>
40
-
41
-class QextWinEventNotifierPrivate
42
-{
43
-    Q_DECLARE_PUBLIC(QextWinEventNotifier)
44
-public:
45
-    QextWinEventNotifierPrivate(HANDLE hEvent, QextWinEventNotifier * q)
46
-        :handleToEvent(hEvent), enabled(false), q_ptr(q)
47
-    {}
48
-
49
-    HANDLE handleToEvent;
50
-    bool enabled;
51
-private:
52
-    QextWinEventNotifier * q_ptr;
53
-};
54
-
55
-/*
56
-  \internal
57
-
58
-  \class QextWinEventNotifierThread
59
-
60
-  This class works more or less like an EventDispatcher.
61
-
62
-  The api function WaitForMultipleObjects() is used in the new thread
63
-  to wait for the  registered handle.
64
-*/
65
-class QextWinEventNotifierThread:public QThread
66
-{
67
-public:
68
-    explicit QextWinEventNotifierThread(QObject * parent=0);
69
-    ~QextWinEventNotifierThread();
70
-    void stop();
71
-    bool registerEventNotifier(QextWinEventNotifier * notifier);
72
-    void unregisterEventNotifier(QextWinEventNotifier * notifier);
73
-protected:
74
-    void run();
75
-private:
76
-    HANDLE hStopEvent; //stop thread when this event signaled.
77
-    HANDLE hUpdateEvent; //make sure eventlist updated.
78
-    QMutex mutex;
79
-    QList<QextWinEventNotifier *> winEventNotifierList;
80
-};
81
-
82
-Q_GLOBAL_STATIC(QextWinEventNotifierThread, notifierThread)
83
-
84
-QextWinEventNotifierThread::QextWinEventNotifierThread(QObject * parent)
85
-    :QThread(parent)
86
-{
87
-    hStopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
88
-    hUpdateEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
89
-    start();
90
-}
91
-
92
-QextWinEventNotifierThread::~QextWinEventNotifierThread()
93
-{
94
-    if (isRunning())
95
-        stop();
96
-    CloseHandle(hStopEvent);
97
-    CloseHandle(hUpdateEvent);
98
-}
99
-
100
-void QextWinEventNotifierThread::stop()
101
-{
102
-    {
103
-        QMutexLocker locker(&mutex);
104
-        SetEvent(hStopEvent);
105
-    }
106
-    wait();    /// Is this an good idea?
107
-}
108
-
109
-bool QextWinEventNotifierThread::registerEventNotifier(QextWinEventNotifier *notifier)
110
-{
111
-    QMutexLocker locker(&mutex);
112
-    if (!notifier) {
113
-        QESP_WARNING("QextWinEventNotifier: Internal error");
114
-        return false;
115
-    }
116
-    if (winEventNotifierList.contains(notifier))
117
-        return true;
118
-    if (winEventNotifierList.count() >= MAXIMUM_WAIT_OBJECTS - 3) {
119
-        QESP_WARNING("QextWinEventNotifier: Cannot have more than %d enabled at one time", MAXIMUM_WAIT_OBJECTS - 3);
120
-        return false;
121
-    }
122
-    winEventNotifierList.append(notifier);
123
-    SetEvent(hUpdateEvent);
124
-    return true;
125
-}
126
-
127
-void QextWinEventNotifierThread::unregisterEventNotifier(QextWinEventNotifier *notifier)
128
-{
129
-    QMutexLocker locker(&mutex);
130
-    if (!notifier) {
131
-        QESP_WARNING("QextWinEventNotifier: Internal error");
132
-        return;
133
-    }
134
-
135
-    int idx = winEventNotifierList.indexOf(notifier);
136
-    if (idx != -1) {
137
-        winEventNotifierList.takeAt(idx);
138
-        SetEvent(hUpdateEvent);
139
-    }
140
-}
141
-
142
-void QextWinEventNotifierThread::run()
143
-{
144
-    forever{
145
-        HANDLE pHandles[MAXIMUM_WAIT_OBJECTS - 1];
146
-        DWORD nCount = 0;
147
-        {
148
-            QMutexLocker locker(&mutex);
149
-            nCount = winEventNotifierList.count();
150
-            for (int i=0; i<(int)nCount; ++i)
151
-                pHandles[i] = winEventNotifierList.at(i)->handle();
152
-            pHandles[nCount] = hUpdateEvent;
153
-            pHandles[nCount+1] = hStopEvent;
154
-        }
155
-        DWORD ret = WaitForMultipleObjects(nCount+2, pHandles, FALSE, INFINITE);
156
-        if (ret >= WAIT_OBJECT_0 && ret < WAIT_OBJECT_0 + nCount) {
157
-            QEvent *evt = new QEvent(QEvent::User);
158
-            QMutexLocker locker(&mutex);
159
-            ResetEvent(pHandles[ret-WAIT_OBJECT_0]);
160
-            QObject * notifier = winEventNotifierList[ret - WAIT_OBJECT_0];
161
-            QCoreApplication::postEvent(notifier, evt);
162
-        }
163
-        else if (ret == WAIT_OBJECT_0 + nCount) {
164
-            //ResetEvent(hUpdateEvent);
165
-        }
166
-        else if (ret == WAIT_OBJECT_0 + nCount + 1) {
167
-            //qDebug()<<"quit...";
168
-            return;
169
-        }
170
-    }
171
-}
172
-
173
-/*!
174
-    \internal
175
-    \class QextWinEventNotifier
176
-    \brief The QextWinEventNotifier class provides support for the Windows Wait functions.
177
-
178
-    The QextWinEventNotifier class makes it possible to use the wait
179
-    functions on windows in a asynchronous manner. With this class
180
-    you can register a HANDLE to an event and get notification when
181
-    that event becomes signalled.
182
-
183
-    \bold Note: If it is a manual reset event ,it will be reset before
184
-    the notification. This is different from QWinEventNotifier.
185
-
186
-    \bold Note: All the registered handles will be waited under a new thread.
187
-    This is different from QWinEventNotifier whose event handle will be waited
188
-    in its affinal thread.
189
-*/
190
-
191
-QextWinEventNotifier::QextWinEventNotifier(QObject *parent)
192
-    : QObject(parent), d_ptr(new QextWinEventNotifierPrivate(0, this))
193
-{}
194
-
195
-QextWinEventNotifier::QextWinEventNotifier(HANDLE hEvent, QObject *parent)
196
- : QObject(parent), d_ptr(new QextWinEventNotifierPrivate(hEvent, this))
197
-{
198
-    setEnabled(true);
199
-}
200
-
201
-QextWinEventNotifier::~QextWinEventNotifier()
202
-{
203
-    setEnabled(false);
204
-}
205
-
206
-void QextWinEventNotifier::setHandle(HANDLE hEvent)
207
-{
208
-    setEnabled(false);
209
-    Q_D(QextWinEventNotifier);
210
-    d->handleToEvent = hEvent;
211
-}
212
-
213
-HANDLE  QextWinEventNotifier::handle() const
214
-{
215
-    return d_func()->handleToEvent;
216
-}
217
-
218
-bool QextWinEventNotifier::isEnabled() const
219
-{
220
-    return d_func()->enabled;
221
-}
222
-
223
-void QextWinEventNotifier::setEnabled(bool enable)
224
-{
225
-    Q_D(QextWinEventNotifier);
226
-
227
-    if (d->enabled == enable)
228
-        return;
229
-    d->enabled = enable;
230
-
231
-    if (d->enabled)
232
-        notifierThread()->registerEventNotifier(this);
233
-    else
234
-        notifierThread()->unregisterEventNotifier(this);
235
-}
236
-
237
-bool QextWinEventNotifier::event(QEvent * e)
238
-{
239
-    Q_D(QextWinEventNotifier);
240
-    QObject::event(e);
241
-    if (e->type() == QEvent::User) {
242
-        emit activated(d->handleToEvent);
243
-        return true;
244
-    }
245
-    return false;
246
-}
247
-

+ 0
- 80
src/3rdparty/qextserialport/src/qextwineventnotifier_p.h View File

@@ -1,80 +0,0 @@
1
-/****************************************************************************
2
-** Copyright (c) 2000-2003 Wayne Roth
3
-** Copyright (c) 2004-2007 Stefan Sander
4
-** Copyright (c) 2007 Michal Policht
5
-** Copyright (c) 2008 Brandon Fosdick
6
-** Copyright (c) 2009-2010 Liam Staskawicz
7
-** Copyright (c) 2011 Debao Zhang
8
-** All right reserved.
9
-** Web: http://code.google.com/p/qextserialport/
10
-**
11
-** Permission is hereby granted, free of charge, to any person obtaining
12
-** a copy of this software and associated documentation files (the
13
-** "Software"), to deal in the Software without restriction, including
14
-** without limitation the rights to use, copy, modify, merge, publish,
15
-** distribute, sublicense, and/or sell copies of the Software, and to
16
-** permit persons to whom the Software is furnished to do so, subject to
17
-** the following conditions:
18
-**
19
-** The above copyright notice and this permission notice shall be
20
-** included in all copies or substantial portions of the Software.
21
-**
22
-** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23
-** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
-** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25
-** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26
-** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27
-** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28
-** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
-**
30
-****************************************************************************/
31
-
32
-#ifndef QEXTWINEVENTNOTIFIER_P_H_
33
-#define QEXTWINEVENTNOTIFIER_P_H_
34
-
35
-//
36
-//  W A R N I N G
37
-//  -------------
38
-//
39
-// This file is not part of the QESP API.  It exists for the convenience
40
-// of other QESP classes.  This header file may change from version to
41
-// version without notice, or even be removed.
42
-//
43
-// We mean it.
44
-//
45
-
46
-#include <QtCore/QObject>
47
-#include <QtCore/qt_windows.h>
48
-#include "qextserialport_global.h"
49
-
50
-class QextWinEventNotifierPrivate;
51
-class QEXTSERIALPORT_EXPORT QextWinEventNotifier : public QObject
52
-{
53
-    Q_OBJECT
54
-    Q_DECLARE_PRIVATE(QextWinEventNotifier)
55
-
56
-public:
57
-    explicit QextWinEventNotifier(QObject *parent = 0);
58
-    explicit QextWinEventNotifier(HANDLE hEvent, QObject *parent = 0);
59
-    ~QextWinEventNotifier();
60
-
61
-    void setHandle(HANDLE hEvent);
62
-    HANDLE handle() const;
63
-
64
-    bool isEnabled() const;
65
-
66
-public Q_SLOTS:
67
-    void setEnabled(bool enable);
68
-
69
-Q_SIGNALS:
70
-    void activated(HANDLE hEvent);
71
-
72
-protected:
73
-    bool event(QEvent * e);
74
-
75
-private:
76
-    Q_DISABLE_COPY(QextWinEventNotifier)
77
-    QextWinEventNotifierPrivate * d_ptr;
78
-};
79
-
80
-#endif // QEXTWINEVENTNOTIFIER_P_H_

+ 0
- 77
src/3rdparty/qextserialport/tests/qextwineventnotifier/tst_qextwineventnotifier.cpp View File

@@ -1,77 +0,0 @@
1
-#include "qextwineventnotifier_p.h"
2
-#include <QtTest/QtTest>
3
-#include <QtCore/QTimer>
4
-
5
-class tst_QextWinEventNotifier : public QObject
6
-{
7
-    Q_OBJECT
8
-
9
-public:
10
-    tst_QextWinEventNotifier(){}
11
-    ~tst_QextWinEventNotifier(){}
12
-
13
-    void initTestCase(){}
14
-    void cleanupTestCase(){}
15
-    void init(){}
16
-    void cleanup(){}
17
-
18
-protected slots:
19
-    void simple_activated();
20
-    void simple_timerSet();
21
-
22
-private slots:
23
-    void empty();
24
-    void simple();
25
-
26
-private:
27
-    HANDLE simpleHEvent;
28
-    int simpleActivated;
29
-};
30
-
31
-void tst_QextWinEventNotifier::simple_activated()
32
-{
33
-    ++simpleActivated;
34
-    ResetEvent((HANDLE)simpleHEvent);
35
-    QTestEventLoop::instance().exitLoop();
36
-}
37
-
38
-void tst_QextWinEventNotifier::simple_timerSet()
39
-{
40
-    SetEvent((HANDLE)simpleHEvent);
41
-}
42
-
43
-void tst_QextWinEventNotifier::empty()
44
-{
45
-    QextWinEventNotifier n1, n2, n3;
46
-    n1.setEnabled(true);
47
-    n2.setEnabled(true);
48
-    n3.setEnabled(true);
49
-    n1.setEnabled(false);
50
-}
51
-
52
-void tst_QextWinEventNotifier::simple()
53
-{
54
-    simpleHEvent = CreateEvent(0, TRUE, FALSE, 0);
55
-    QVERIFY(simpleHEvent);
56
-
57
-    QextWinEventNotifier n(simpleHEvent);
58
-    QObject::connect(&n, SIGNAL(activated(HANDLE)), this, SLOT(simple_activated()));
59
-
60
-    simpleActivated = 0;
61
-    SetEvent((HANDLE)simpleHEvent);
62
-    QTestEventLoop::instance().enterLoop(30);
63
-    if (QTestEventLoop::instance().timeout())
64
-        QFAIL("Timed out");
65
-    QVERIFY(simpleActivated == 1);
66
-
67
-    simpleActivated = 0;
68
-    QTimer::singleShot(3000, this, SLOT(simple_timerSet()));
69
-    QTestEventLoop::instance().enterLoop(30);
70
-    if (QTestEventLoop::instance().timeout())
71
-        QFAIL("Timed out");
72
-    QVERIFY(simpleActivated == 1);
73
-}
74
-
75
-QTEST_MAIN(tst_QextWinEventNotifier)
76
-
77
-#include "tst_qextwineventnotifier.moc"

+ 0
- 2
src/3rdparty/qextserialport/tests/tests.pro View File

@@ -1,2 +0,0 @@
1
-TEMPLATE=subdirs
2
-win32:SUBDIRS += qextwineventnotifier

+ 1
- 1
src/Typica.pro View File

@@ -9,7 +9,7 @@ QT += xmlpatterns
9 9
 QT += scripttools
10 10
 QT += webkit
11 11
 
12
-include(3rdparty/qextserialport/src/qextserialport.pri)
12
+CONFIG += extserialport
13 13
 
14 14
 TEMPLATE = app
15 15
 TARGET =

Loading…
Cancel
Save