Changeset 116 in pacpussensors for trunk/CanGateway/CanGateway.cpp


Ignore:
Timestamp:
12/16/15 16:57:50 (9 years ago)
Author:
ydroniou
Message:

Fix KVaser for Linux \o/

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/CanGateway/CanGateway.cpp

    r91 r116  
    5959 
    6060        // set the exhange parameters for incoming CAN frames
    61         canIf_.setExchangeBuffer(incomingCanFrames_, INCOMINGCANFRAMES_SIZE);
    62         canIf_.setSignalSempahore(&semaphore_);
    63         if (source_ == "shMem")
    64                 canIf_.setSource(Win32CanInterface::SharedMemory);
     61        canIfRead_.setExchangeBuffer(incomingCanFrames_, INCOMINGCANFRAMES_SIZE);
     62        canIfRead_.setSignalSempahore(&semaphore_);
     63
     64        if (source_ == "shMem") {
     65                sameCanIf = true;
     66                canIfRead_.setSource(Win32CanInterface::SharedMemory);
     67        }
    6568        else if (source_ == "vector")
    6669        {
    67                 canIf_.setSource(Win32CanInterface::VectorCard);
     70                sameCanIf = true;
     71                canIfRead_.setSource(Win32CanInterface::VectorCard);
    6872                // open the interface
    69                 if (!canIf_.openInterface(channel_, speed_))
     73                if (!canIfRead_.openInterface(channel_, speed_))
    7074                        qFatal("Failed to open the CAN interface num %d at speed %d",channel_,speed_);
    7175        }
    7276        else if (source_ == "vectorXL")
    7377        {
    74                 canIf_.setSource(Win32CanInterface::XLVectorCard);
     78                sameCanIf = true;
     79                canIfRead_.setSource(Win32CanInterface::XLVectorCard);
    7580                // open the interface
    76                 if (!canIf_.openInterface(channel_, speed_))
     81                if (!canIfRead_.openInterface(channel_, speed_))
    7782                        qFatal("Failed to open the CAN interface num %d at speed %d",channel_,speed_);
    7883        }
    7984        else if (source_ == "peak")
    8085        {
    81                 canIf_.setSource(Win32CanInterface::PeakCard);
    82                 // open interface
    83                 if (canIf_.openInterface(port_, accessMode_)==0)
     86                sameCanIf = true;
     87                canIfRead_.setSource(Win32CanInterface::PeakCard);
     88                // open interface
     89                if (canIfRead_.openInterface(port_, accessMode_)==0)
    8490                        qFatal("Failed to open the CAN interface port %s in %s mode",port_, accessMode_);
    8591        }
    8692        else if (source_ == "igep")
    8793        {
    88                 canIf_.setSource(Win32CanInterface::igepCard);
    89                 // open interface
    90                 if (canIf_.openInterface(port_, accessMode_)==0)
     94                sameCanIf = true;
     95                canIfRead_.setSource(Win32CanInterface::igepCard);
     96                // open interface
     97                if (canIfRead_.openInterface(port_, accessMode_)==0)
    9198                        qFatal("Failed to open the CAN interface port %s in %s mode",port_, accessMode_);
    9299        }
    93100        else if (source_ == "kvaser")
    94101        {
    95                 canIf_.setSource(Win32CanInterface::KvaserCard);
    96                 // open interface
    97                 if (canIf_.openInterface(channel_,speed_)==0)
     102                sameCanIf = false;
     103                canIfRead_.setSource(Win32CanInterface::KvaserCard);
     104                // open interface
     105                if (canIfRead_.openInterface(channel_,speed_)==0)
     106                        qFatal("Failed to open the CAN interface num %d at speed %d",channel_,speed_);
     107
     108                canIfWrite_.setSource(Win32CanInterface::KvaserCard);
     109                // open interface
     110                if (canIfWrite_.openInterface(channel_,speed_)==0)
    98111                        qFatal("Failed to open the CAN interface num %d at speed %d",channel_,speed_);
    99112        }
     
    105118
    106119        // start the 2 threads: reception thread and decoding thread
    107         canIf_.start();
     120        canIfRead_.start();
     121
    108122        start();
    109123}
     
    117131{
    118132        counter_ = 0;
    119         canIf_.stop();
    120 
    121         if ((source_ == "vector")||(source_=="peak")||(source_=="vectorXL")||(source_=="igep")||(source_=="kvaser"))
    122                 canIf_.closeInterface(channel_);
     133
     134        canIfRead_.stop();
     135
     136        if ((source_ == "vector")||(source_=="peak")||(source_=="vectorXL")||(source_=="igep")||(source_=="kvaser")) {
     137                canIfRead_.closeInterface(channel_);
     138                if(!sameCanIf)
     139                        canIfWrite_.closeInterface(channel_);
     140        }
    123141       
    124         canIf_.wait();
     142        canIfRead_.wait();
    125143
    126144        // we stop the decoding thread
     
    167185bool CanGateway::sendFrame(const CanFrame frame)
    168186{
    169         if (canIf_.canDriver_ == NULL)
    170                 return false;
     187        if(sameCanIf)
     188        {
     189                if (canIfRead_.canDriver_ == NULL)
     190                        return false;
     191                else
     192                {
     193                        if (canIfWrite_.canDriver_->sendFrame(frame))
     194                                return true;
     195                        else
     196                                return false;
     197                }
     198        }
    171199        else
    172200        {
    173                 if (canIf_.canDriver_->sendFrame(frame))
    174                         return true;
     201                if (canIfWrite_.canDriver_ == NULL)
     202                        return false;
    175203                else
    176                         return false;
     204                {
     205                        if (canIfWrite_.canDriver_->sendFrame(frame))
     206                                return true;
     207                        else
     208                                return false;
     209                }
    177210        }
    178211}
Note: See TracChangeset for help on using the changeset viewer.