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