Changeset 89 in pacpussensors for trunk/CanGateway


Ignore:
Timestamp:
Jul 28, 2015, 3:28:21 PM (9 years ago)
Author:
DHERBOMEZ Gérald
Message:

Add KVASER CAN driver support for CanGateway component. Tested only for Windows.

Location:
trunk/CanGateway
Files:
19 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/CanGateway/CMakeLists.txt

    r59 r89  
    3737        ${PACPUS_LIB_DIR}
    3838        ${CanGateway_SOURCE_DIR}/driver/libs
     39        ${CanGateway_SOURCE_DIR}/driver/libs/kvaser/MS
    3940)
    4041
     
    5960    DbtRawCanReader.cpp
    6061        structureCan.h
     62        driver/KVaserCanDriver.cpp
     63        driver/KVaserCanDriver.h
    6164    ${PLUGIN_CPP}
    6265)
     
    129132        optimized vxlapi.lib debug vxlapi.lib
    130133                optimized PCANBasic.lib debug PCANBasic.lib
     134                optimized canlib32.lib debug canlib32.lib
    131135    )
    132136endif(WIN32)
  • trunk/CanGateway/Win32CanInterface.cpp

    r41 r89  
    44//
    55//  author:     Gerald Dherbomez
    6 //              Copyright Heudiasyc UMR UTC/CNRS 6599
     6//              Copyright Heudiasyc UMR UTC/CNRS 7253
    77//
    88//  version:    $Id: $
    99//
    10 //  purpose:    Windows specific management of the Can Interface
     10//  purpose:    Management of the Can Interface
    1111//
    1212*********************************************************************/
     
    115115  case XLVectorCard:
    116116    vectorXlLoop();
     117  case KvaserCard:
     118    kvaserLoop();
    117119    break;
    118120  default:
     
    145147/// The loop used for waiting CAN data from XL Vector card
    146148void Win32CanInterface::vectorXlLoop()
     149{
     150  while(continue_) {
     151    // Wait incoming data from the CAN bus
     152    if (canDriver_->receiveFrame(frame_) == 0) {
     153      receivedFrames_[counter_].time = road_time();
     154      receivedFrames_[counter_].timerange = 0;
     155      memcpy(&(receivedFrames_[counter_].frame), &frame_, sizeof(CanFrame));
     156      semaphore_->release();
     157      counter_++;
     158      counter_ = counter_ % receivedFramesArraySize_;
     159    }
     160  }
     161}
     162
     163/************************************************************************/
     164/// The loop used for waiting CAN data from Kvaser card
     165void Win32CanInterface::kvaserLoop()
    147166{
    148167  while(continue_) {
  • trunk/CanGateway/Win32CanInterface.h

    r74 r89  
    1818#ifdef WIN32
    1919//#   define CAN_DRIVER_TYPE       VECTOR_CAN_DRIVER
    20 #   define CAN_DRIVER_TYPE       VECTOR_CANXL_DRIVER
     20//#   define CAN_DRIVER_TYPE       VECTOR_CANXL_DRIVER
    2121//#   define CAN_DRIVER_TYPE       PEAK_CAN_DRIVER_WIN
     22#   define CAN_DRIVER_TYPE         KVASER_CAN_DRIVER_WIN
    2223#else
    2324#   define CAN_DRIVER_TYPE       IGEP_CAN_DRIVER
     
    4445  ~Win32CanInterface();
    4546
    46   enum DataSource {VectorCard, SharedMemory, PeakCard, XLVectorCard, igepCard};
     47  enum DataSource {VectorCard, SharedMemory, PeakCard, XLVectorCard, igepCard, KvaserCard};
    4748
    4849  bool openInterface(const int number, const unsigned int speed);
     
    6263  void igepLoop();
    6364  void vectorXlLoop();
     65  void kvaserLoop();
     66
    6467
    6568private:
  • trunk/CanGateway/driver/CanDriver.h

    r86 r89  
    2626#define PEAK_CAN_DRIVER_WIN     6
    2727#define SOFTING_CAN_DRIVER      7
     28#define KVASER_CAN_DRIVER_WIN 8
    2829
    2930
     
    4950#include "SoftingCanDriver.h"
    5051#define CanDriverType SoftingCanDriver
     52#elif CAN_DRIVER_TYPE == KVASER_CAN_DRIVER_WIN
     53#include "KVaserCanDriver.h"
     54#define CanDriverType KVaserCanDriver
    5155#else
    5256#define CanDriverType CanDriverUnknown
  • trunk/CanGateway/driver/XLVectorCanDriver.cpp

    r40 r89  
    412412                xlCanTransmit(this->port, this->accessMask, &count, &e));
    413413
    414         /*
    415   Vstatus vErr;
    416   Vevent event;
    417   Vevent * pEvent = NULL;
    418 
    419   // Create frame to send
    420   event.tag                 = V_TRANSMIT_MSG;
    421   event.tagData.msg.id      = frame.id;
    422   event.tagData.msg.flags   = 0;
    423   event.tagData.msg.dlc     = frame.dlc;
    424 
    425   for (int i = 0; i < frame.dlc; i++)
    426     event.tagData.msg.data[i] = frame.data[i];
    427 
    428   // Send the frame
    429   vErr = ncdTransmit (gPortHandle, gChannelMask, &event);
    430 
    431   //printf("sendFrame ncdTransmit  --  vErr=%d, event=0x%x\n", vErr, event);
    432 
    433   if (vErr==VERR_QUEUE_IS_FULL)
    434   {
    435     printf("!");
    436   }
    437 
    438   else if (vErr)
    439   {
    440     printf ("ERROR:(send frame) %s!\n", ncdGetErrorString (vErr));             
    441     //          ncdDeactivateChannel (gPortHandle, gChannelMask);
    442     //          cleanUpPort ();
    443     return vErr;
    444   }
    445 
    446   return VSUCCESS;
    447 
    448   // Wait the acknowledgement frame
    449   waitReceivingFrame();
    450 
    451   // Read the acknowledgement frame in the buffer
    452   vErr = ncdReceive1 (gPortHandle,&pEvent);
    453   //printf("sendFrame ncdReceive1  --  vErr=%d, pEvent=0x%x\n", vErr, pEvent);
    454 
    455   if ( (pEvent==NULL) && (vErr==VERR_QUEUE_IS_EMPTY) )
    456   {
    457     printf ("%s\n",ncdGetErrorString (vErr));
    458     printf ("%s!\n",ncdGetErrorString (vErr));
    459     //          ncdDeactivateChannel (gPortHandle, gChannelMask);
    460     //          cleanUpPort ();
    461     return vErr;
    462   }
    463 
    464   // If frame is well acknoledged
    465   if (pEvent->tagData.msg.flags & 0x40) 
    466     return VSUCCESS;
    467   else
    468   {
    469    //printf("%x ",pEvent->tagData.msg.flags);
    470    //printf (" no acknolegement of frame!\n");
    471    
    472     return VERROR;
    473   }*/
     414       
    474415
    475416        return 1;
     
    497438
    498439        int queueSize;
    499         //bool found = false;
    500         //DWORD begin = timeGetTime();
    501         //while ( !found ) {
    502                 /*DWORD now = timeGetTime();
    503                 /DEBUG("begin: %ld, now: %ld", begin, now);
    504                 if ( now - begin >= timeout ) {
    505                         return NULL;
    506                 }
    507 */
     440
    508441                traceXLCommand("xlGetReceiveQueueLevel",
    509442                        xlGetReceiveQueueLevel(this->port, &queueSize));
     
    526459                        return 1;
    527460                }
    528         //}
    529 
    530         //return new CanMessage(e);
    531 
    532 
    533         /*
    534   int L ;
    535   Vstatus vErr;
    536   Vevent * pEvent = NULL;
    537 
    538   do {
    539     // Read frame in the buffer
    540     ncdGetReceiveQueueLevel( gPortHandle , &L );
    541     if( L <= 0 )
    542     {
    543       if (WaitForSingleObject (gEventHandle,WAIT_RECEIVING_FRAME_TIMEOUT) == WAIT_TIMEOUT)
    544       {
    545         //printf("no frame receiving in the %d last seconds\n", WAIT_RECEIVING_FRAME_TIMEOUT/1000);
    546         return VERR_QUEUE_IS_EMPTY;
    547       }
    548     }
    549 
    550     vErr = ncdReceive1 (gPortHandle,&pEvent);
    551     if( vErr == VERROR )
    552     {
    553       printf ("receiveframe ERROR  - ERROR: %s\n", ncdGetErrorString (vErr));           
    554       //                ncdDeactivateChannel (gPortHandle, gChannelMask);
    555       //                cleanUpPort ();
    556 
    557       return vErr;
    558     }
    559 
    560   } while((( pEvent==NULL ) && ( vErr==VERR_QUEUE_IS_EMPTY )) || ( vErr == VERROR ));
    561 
    562   // Return the flags field, dlc field and data field of the sent frame
    563   //frame.flags = pEvent->tagData.msg.flags;
    564   frame.dlc = pEvent->tagData.msg.dlc;
    565   frame.id =  pEvent->tagData.msg.id;
    566   if( ( frame.dlc > 8 ) || ( frame.dlc < 0 ))     
    567     frame.dlc = 8;
    568 
    569   memcpy(frame.data,pEvent->tagData.msg.data, frame.dlc);
    570 
    571   return VSUCCESS;*/
     461       
    572462       
    573463}
Note: See TracChangeset for help on using the changeset viewer.