Changeset 99 in pacpussensors for trunk/driver


Ignore:
Timestamp:
Oct 15, 2015, 2:47:01 PM (9 years ago)
Author:
nguyenhu
Message:

compilation under linux with 0.2.X framework

Location:
trunk/driver
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/driver/PosixSerialPort.cpp

    r59 r99  
    44//
    55// author:     Gerald Dherbomez
    6 // 
     6//
    77// version:    $Id: $
    88//
     
    2424
    2525PosixSerialPort::~PosixSerialPort() {
    26     qDebug() << "The win32 serial port " << componentName << " was destroyed";
     26    qDebug() << "The Posix serial port " << componentName << " was destroyed";
    2727}
    2828
    2929PosixSerialPort::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
    3637//////////////////////////////////////////////////////////////////////////
    3738
     
    4546
    4647//////////////////////////////////////////////////////////////////////////
    47 // return a pointer to the first frame in the list 
     48// return a pointer to the first frame in the list
    4849//////////////////////////////////////////////////////////////////////////
    4950
     
    5354
    5455
    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//////////////////////////////////////////////////////////////////////////
     60FRAME * 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
    6175//////////////////////////////////////////////////////////////////////////
    6276
     
    7084    }
    7185    dataFrameList.removeFirst();
    72     delete[] tmp->data;
     86    //delete[] tmp->data;
    7387    delete tmp;
    7488    tmp = NULL;
     
    8094
    8195/*!< open the port 'name'
    82 return true if success 
     96return true if success
    8397 */
    8498bool PosixSerialPort::openPort(const char * name) {
     
    96110
    97111/*!< close the port
    98 return true if success 
     112return true if success
    99113 */
    100114int PosixSerialPort::closePort() {
     
    102116}
    103117
    104 /*!< configure the port 
    105 return true if success 
     118/*!< configure the port
     119return true if success
    106120 */
    107121int PosixSerialPort::configurePort(long baudRate, int byteSize, char parity, int stopBits) {
     
    116130            cfsetospeed(&port_settings, B4800);
    117131            break;
    118          
     132
    119133        case 9600:
    120134            cfsetispeed(&port_settings, B9600); // set baud rates
     
    145159
    146160//////////////////////////////////////////////////////////////////////////
    147 // Read 'maxLength' bytes on the port and copy them in buffer 
     161// Read 'maxLength' bytes on the port and copy them in buffer
    148162// return the number of bytes read
    149163//////////////////////////////////////////////////////////////////////////
     
    167181      memset(receivedBuffer_,0,numberBytesToRead);
    168182      numberBytesRead = readBuffer(receivedBuffer_,numberBytesToRead);
    169       processIncomingData(); 
     183      processIncomingData();
    170184    }
    171185    else
    172186    {
    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 !
    175189      usleep(1000);
    176190    }
     
    184198
    185199    ioctl(handlePort, FIONREAD, &bytes);
    186    
     200
    187201    return bytes;
    188202}
     
    195209    // data frame
    196210    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_;
    211224    receivedBuffer_ = NULL;
    212225  }
     
    214227  if (ringIndicatorDetected) {
    215228    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);
    227240  }
    228241
    229242  // re-initialization
    230243  t_ = 0;
    231   numberBytesToRead = 0; 
    232 } 
     244  numberBytesToRead = 0;
     245}
  • trunk/driver/PosixSerialPort.h

    r59 r99  
    3434  road_timerange_t tr;
    3535  unsigned long length;
    36   char * data;
     36  QByteArray data; //char *
    3737}FRAME;
    3838
     
    5151  /*!< return the first dataFrame in the list */
    5252  FRAME* firstFrame();
     53
     54  /*!< return the next dataFrame in the list and removes it */
     55  FRAME* getNextFrame();
    5356
    5457  /*!< remove the first dataFrame in the list */
Note: See TracChangeset for help on using the changeset viewer.