Changeset 99 in pacpussensors for trunk/driver/PosixSerialPort.cpp
- Timestamp:
- Oct 15, 2015, 2:47:01 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/driver/PosixSerialPort.cpp
r59 r99 4 4 // 5 5 // author: Gerald Dherbomez 6 // 6 // 7 7 // version: $Id: $ 8 8 // … … 24 24 25 25 PosixSerialPort::~PosixSerialPort() { 26 qDebug() << "The win32serial port " << componentName << " was destroyed";26 qDebug() << "The Posix serial port " << componentName << " was destroyed"; 27 27 } 28 28 29 29 PosixSerialPort::PosixSerialPort(QString name) { 30 31 } 32 33 34 ////////////////////////////////////////////////////////////////////////// 35 // return the number of frames that have not been yet decoded 30 componentName = name; 31 qDebug() << "The Posix serial port " << componentName << " was created"; 32 } 33 34 35 ////////////////////////////////////////////////////////////////////////// 36 // return the number of frames that have not been yet decoded 36 37 ////////////////////////////////////////////////////////////////////////// 37 38 … … 45 46 46 47 ////////////////////////////////////////////////////////////////////////// 47 // return a pointer to the first frame in the list 48 // return a pointer to the first frame in the list 48 49 ////////////////////////////////////////////////////////////////////////// 49 50 … … 53 54 54 55 55 56 57 58 ////////////////////////////////////////////////////////////////////////// 59 // remove the first frame of the list 60 // use this function as soon as you copy the frame 56 ////////////////////////////////////////////////////////////////////////// 57 // return a pointer to the first frame in the queue and removes it 58 // The reader is responsible for deleting the frame. 59 ////////////////////////////////////////////////////////////////////////// 60 FRAME * PosixSerialPort::getNextFrame() 61 { 62 FRAME *frame = NULL; 63 frameLock_.lock(); 64 if (!dataFrameList.isEmpty()) { 65 frame = dataFrameList.takeFirst(); 66 } 67 frameLock_.unlock(); 68 return frame; 69 } 70 71 72 ////////////////////////////////////////////////////////////////////////// 73 // remove the first frame of the list 74 // use this function as soon as you copy the frame 61 75 ////////////////////////////////////////////////////////////////////////// 62 76 … … 70 84 } 71 85 dataFrameList.removeFirst(); 72 delete[] tmp->data;86 //delete[] tmp->data; 73 87 delete tmp; 74 88 tmp = NULL; … … 80 94 81 95 /*!< open the port 'name' 82 return true if success 96 return true if success 83 97 */ 84 98 bool PosixSerialPort::openPort(const char * name) { … … 96 110 97 111 /*!< close the port 98 return true if success 112 return true if success 99 113 */ 100 114 int PosixSerialPort::closePort() { … … 102 116 } 103 117 104 /*!< configure the port 105 return true if success 118 /*!< configure the port 119 return true if success 106 120 */ 107 121 int PosixSerialPort::configurePort(long baudRate, int byteSize, char parity, int stopBits) { … … 116 130 cfsetospeed(&port_settings, B4800); 117 131 break; 118 132 119 133 case 9600: 120 134 cfsetispeed(&port_settings, B9600); // set baud rates … … 145 159 146 160 ////////////////////////////////////////////////////////////////////////// 147 // Read 'maxLength' bytes on the port and copy them in buffer 161 // Read 'maxLength' bytes on the port and copy them in buffer 148 162 // return the number of bytes read 149 163 ////////////////////////////////////////////////////////////////////////// … … 167 181 memset(receivedBuffer_,0,numberBytesToRead); 168 182 numberBytesRead = readBuffer(receivedBuffer_,numberBytesToRead); 169 processIncomingData(); 183 processIncomingData(); 170 184 } 171 185 else 172 186 { 173 receivedBuffer_ = NULL; 174 // todo : trouver une autre methode plus efficace que le polling et le sleep ! 187 receivedBuffer_ = NULL; 188 // todo : trouver une autre methode plus efficace que le polling et le sleep ! 175 189 usleep(1000); 176 190 } … … 184 198 185 199 ioctl(handlePort, FIONREAD, &bytes); 186 200 187 201 return bytes; 188 202 } … … 195 209 // data frame 196 210 if (numberBytesRead > 0) { 197 FRAME * frame = new FRAME; 198 frame->t = t_; 199 frame->tr = 0; 200 frame->length = numberBytesRead; 201 frame->data = new char[frame->length]; 202 memcpy(frame->data, receivedBuffer_, frame->length); 203 204 frameLock_.lock(); 205 dataFrameList.append( frame ); 206 frameLock_.unlock(); 207 208 //printf(receivedBuffer_); 209 emit newDataAvailable(1); 210 delete[] receivedBuffer_; 211 FRAME * frame = new FRAME; 212 frame->t = t_; 213 frame->tr = 0; 214 frame->length = numberBytesRead; 215 frame->data = QByteArray(receivedBuffer_, frame->length); 216 217 frameLock_.lock(); 218 dataFrameList.append( frame ); 219 frameLock_.unlock(); 220 221 //printf(receivedBuffer_); 222 emit newDataAvailable(1); 223 delete[] receivedBuffer_; 211 224 receivedBuffer_ = NULL; 212 225 } … … 214 227 if (ringIndicatorDetected) { 215 228 ringIndicatorDetected = false; 216 FRAME * frame = new FRAME; 217 frame->t = t_; 218 frame->tr = 0; 219 frame->length = 3; 220 frame->data = new char[frame->length];221 memcpy(frame->data, "PPS", frame->length); 222 frameLock_.lock(); 223 dataFrameList.append(frame); 224 frameLock_.unlock(); 225 226 emit newDataAvailable(1); 229 FRAME * frame = new FRAME; 230 frame->t = t_; 231 frame->tr = 0; 232 frame->length = 3; 233 frame->data = frame->data = QByteArray("PPS", frame->length); 234 235 frameLock_.lock(); 236 dataFrameList.append(frame); 237 frameLock_.unlock(); 238 239 emit newDataAvailable(1); 227 240 } 228 241 229 242 // re-initialization 230 243 t_ = 0; 231 numberBytesToRead = 0; 232 } 244 numberBytesToRead = 0; 245 }
Note:
See TracChangeset
for help on using the changeset viewer.