[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 |
|
---|
| 25 | #include "kernel/pacpus.h"
|
---|
| 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;
|
---|
| 36 | char * data;
|
---|
| 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 |
|
---|
| 54 | /*!< remove the first dataFrame in the list */
|
---|
| 55 | int removeFirstFrame();
|
---|
| 56 |
|
---|
| 57 | /*!< open the port 'name'
|
---|
| 58 | return true if success
|
---|
| 59 | */
|
---|
| 60 | bool openPort(const char * name);
|
---|
| 61 |
|
---|
| 62 | /*!< close the port
|
---|
| 63 | return true if success
|
---|
| 64 | */
|
---|
| 65 | int closePort();
|
---|
| 66 |
|
---|
| 67 | /*!< configure the port
|
---|
| 68 | return true if success
|
---|
| 69 | */
|
---|
| 70 | int configurePort(long baudRate, int byteSize, char parity, int stopBits);
|
---|
| 71 |
|
---|
| 72 | /*!< set the mode of usage of the port
|
---|
| 73 |
|
---|
| 74 | */
|
---|
| 75 | // void setMode(const DWORD overlappedModeAttribute = 0); // FILE_FLAG_OVERLAPPED
|
---|
| 76 |
|
---|
| 77 |
|
---|
| 78 | QList<FRAME*> dataFrameList;
|
---|
| 79 | bool THREAD_ALIVE;
|
---|
| 80 | char portName[PORT_NAME_MAXIMUM_LENGTH+1];
|
---|
| 81 |
|
---|
| 82 | signals:
|
---|
| 83 | void newDataAvailable(int);
|
---|
| 84 |
|
---|
| 85 | protected:
|
---|
| 86 | QString componentName;
|
---|
| 87 |
|
---|
| 88 | private:
|
---|
| 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 | int nbBytesToRead();
|
---|
| 96 |
|
---|
| 97 | void run();
|
---|
| 98 |
|
---|
| 99 | int handlePort;
|
---|
| 100 |
|
---|
| 101 | /*
|
---|
| 102 | DWORD overlappedMode;
|
---|
| 103 | OVERLAPPED overlappedStructure;
|
---|
| 104 | COMMCONFIG commConfigStructure;
|
---|
| 105 | COMMTIMEOUTS commTimeoutsStructure;
|
---|
| 106 | UINT inputBufferSize;
|
---|
| 107 | UINT outputBufferSize;
|
---|
| 108 |
|
---|
| 109 | DWORD baudRate_;
|
---|
| 110 | BYTE byteSize_;
|
---|
| 111 | BYTE parity_;
|
---|
| 112 | BYTE stopBits_;
|
---|
| 113 | */
|
---|
| 114 | /*
|
---|
| 115 | DWORD evtMask;
|
---|
| 116 | COMSTAT comStat;
|
---|
| 117 | DWORD comErr;
|
---|
| 118 | DWORD comOperationStatus;
|
---|
| 119 | */
|
---|
| 120 |
|
---|
| 121 | char * receivedBuffer_;
|
---|
| 122 | int numberBytesToRead;
|
---|
| 123 | int numberBytesRead;
|
---|
| 124 | bool ringIndicatorDetected;
|
---|
| 125 |
|
---|
| 126 | // local variables
|
---|
| 127 | road_time_t t_;
|
---|
| 128 |
|
---|
| 129 | QMutex frameLock_;
|
---|
| 130 | };
|
---|
| 131 |
|
---|
| 132 |
|
---|
| 133 |
|
---|
| 134 | #endif
|
---|