source: pacpussensors/trunk/driver/win32SerialPort.h@ 132

Last change on this file since 132 was 59, checked in by DHERBOMEZ Gérald, 10 years ago

Integration of new modules:

  • GPS NMEA0183 decoder
  • Span CPT Decoder

Update of:

File size: 2.9 KB
RevLine 
[59]1/*********************************************************************
2// created: 2005/09/02 - 8:01
3// filename: win32SerialPort.h
4//
5// author: Gerald Dherbomez
6//
7// version: $Id: win32SerialPort.h 1277 2013-01-10 16:49:06Z bonnetst $
8//
9// purpose: This class defines a Windows (32bits) driver for serial port
10*********************************************************************/
11
12#ifndef WIN32SERIALPORT_H
13#define WIN32SERIALPORT_H
14
15#ifdef WIN32
16# include <windows.h>
17#endif
18
19#include "Pacpus/kernel/pacpus.h"
20#include "dataFrame.h"
21
22#include <QByteArray>
23#include <QMutex>
24#include <QQueue>
25#include <QThread>
26#include <string>
27
28typedef struct {
29 unsigned int length; // Deprecated, needed by some legacy code
30 road_time_t t;
31 road_timerange_t tr;
32 QByteArray data;
33} FRAME;
34
35class Win32SerialPort
36 : public QThread
37{
38 Q_OBJECT
39
40public:
41 enum PpsSense { RISING, FALLING, BOTH };
42
43
44 Win32SerialPort(QString name);
45 ~Win32SerialPort();
46
47 /*!< returns the number of items in the queue */
48 int numberOfFrames();
49
50 /*!< returns the first frame in the queue without removing it */
51 FRAME* firstFrame();
52
53 /*!< remove the first data frame from the queue */
54 int removeFirstFrame();
55
56 /*!< return the next dataFrame in the list and removes it */
57 FRAME* getNextFrame();
58
59 /*!< open the port 'name'
60 return true if success
61 */
62 bool openPort(const char * name);
63
64 /*!< close the port
65 return true if success
66 */
67 int closePort();
68
69 /*!< configure the port
70 return true if success
71 */
72 int configurePort(unsigned long baudRate, unsigned char byteSize, unsigned char parity, unsigned char stopBits);
73
74 /*!< set the mode of usage of the port
75 */
76 void setMode(const DWORD overlappedModeAttribute = 0); // FILE_FLAG_OVERLAPPED
77
78 void setPpsSense(enum PpsSense);
79
80 BOOL THREAD_ALIVE;
81
82Q_SIGNALS:
83 void newDataAvailable(int);
84
85protected:
86 QString componentName;
87
88private:
89 void setPortName(const char * name);
90 bool setPort(long baudrate,char parity,int byteSize,int stopBits );
91
92 void processIncomingEvent();
93 void processIncomingData();
94 int readBuffer(char * buffer, int maxLength);
95 DWORD nbBytesToRead();
96
97 void dumpParameters(QString filename);
98
99 void run();
100
101private:
102 HANDLE handlePort;
103
104 DWORD overlappedMode;
105 OVERLAPPED overlappedStructure;
106 COMMCONFIG commConfigStructure;
107 COMMTIMEOUTS commTimeoutsStructure;
108 UINT inputBufferSize;
109 UINT outputBufferSize;
110
111 DWORD baudRate_;
112 BYTE byteSize_;
113 BYTE parity_;
114 BYTE stopBits_;
115
116 PpsSense ppsSense_;
117
118 DWORD evtMask;
119 COMSTAT comStat;
120 DWORD comErr;
121 DWORD comOperationStatus;
122
123 QByteArray receivedBuffer_;
124 int numberBytesToRead;
125 int numberBytesRead;
126 BOOL ringIndicatorDetected;
127
128 QQueue<FRAME *> dataFrameQueue;
129
130 std::string portName;
131
132 // local variables
133 road_time_t t_;
134
135 QMutex frameLock_;
136};
137
138#endif // WIN32SERIALPORT_H
Note: See TracBrowser for help on using the repository browser.