Changeset 116 in pacpussensors for trunk/CanGateway/Win32CanInterface.cpp
- Timestamp:
- Dec 16, 2015, 4:57:50 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/CanGateway/Win32CanInterface.cpp
r94 r116 5 5 // author: Gerald Dherbomez 6 6 // Copyright Heudiasyc UMR UTC/CNRS 7253 7 // 7 // 8 8 // version: $Id: $ 9 9 // … … 37 37 38 38 /************************************************************************/ 39 /// Opens the CAN interface of the number given in argument 39 /// Opens the CAN interface of the number given in argument 40 40 bool Win32CanInterface::openInterface(const int number, const unsigned int speed) 41 41 { 42 42 canDriver_ = new CanDriver(number, speed); 43 44 //connection to CAN bus 43 44 //connection to CAN bus 45 45 if(canDriver_->initPort() != 0) 46 46 { … … 69 69 /************************************************************************/ 70 70 /// Close the CAN interface 71 /// todo: close only the port identified by number 72 /// make a function that close the driver or close the driver only if 71 /// todo: close only the port identified by number 72 /// make a function that close the driver or close the driver only if 73 73 /// there is no more pending connections 74 74 bool Win32CanInterface::closeInterface(const int /*number*/) 75 75 { 76 if(canDriver_->cleanUpPort() != 0) 77 { 78 cout << "CAN disconnection fails" << endl; 79 delete canDriver_; 80 return false; 76 if(canDriver_ != NULL) { 77 if(canDriver_->cleanUpPort() != 0) 78 { 79 cout << "CAN disconnection fails" << endl; 80 delete canDriver_; 81 return false; 82 } 83 else 84 { 85 delete canDriver_; 86 return true; 87 } 81 88 } 82 89 else 83 {84 delete canDriver_;85 90 return true; 86 }87 91 } 88 92 … … 95 99 96 100 if (!receivedFramesArraySize_) 97 qFatal("receivedFramesArraySize_ not initialized, division by zero may occur if you continue. Context:%s:L%d",__FILE__, __LINE__); 101 qFatal("receivedFramesArraySize_ not initialized, division by zero may occur if you continue. Context:%s:L%d",__FILE__, __LINE__); 98 102 99 103 cout << "Win32CanInterface starts" << endl; … … 102 106 { 103 107 case VectorCard: 104 vectorLoop(); 108 case PeakCard: 109 case igepCard: 110 case XLVectorCard: 111 case KvaserCard: 112 defaultLoop(); 105 113 break; 106 // case SharedMemory: // runtime crash because PosixShMem 107 // shMemLoop(); 108 // break; 109 case PeakCard: 110 peakLoop(); 111 break; 112 case igepCard: 113 igepLoop(); 114 break; 115 case XLVectorCard: 116 vectorXlLoop(); 117 case KvaserCard: 118 kvaserLoop(); 119 break; 120 default: 114 default: 121 115 break; 122 116 } … … 128 122 /************************************************************************/ 129 123 /// The loop used for waiting CAN data from Vector card 130 void Win32CanInterface::vectorLoop() 131 { 132 while (continue_) 133 { 134 // Wait incoming data from the CAN bus 135 if (canDriver_->receiveFrame(frame_) == 0) { 136 receivedFrames_[counter_].time = road_time(); 137 receivedFrames_[counter_].timerange = 0; 138 memcpy(&(receivedFrames_[counter_].frame), &frame_, sizeof(CanFrame) ); 139 semaphore_->release(); 140 counter_++; 141 counter_ = counter_ % receivedFramesArraySize_; 142 } 143 } 144 } 124 // Default for vector, vectorXL, kvaser, Peak, Igep 145 125 146 /************************************************************************/ 147 /// The loop used for waiting CAN data from XL Vector card 148 void Win32CanInterface::vectorXlLoop() 126 void Win32CanInterface::defaultLoop() 149 127 { 150 128 while(continue_) { 151 // Wait incoming data from the CAN bus 129 // Wait incoming data from the CAN bus 152 130 if (canDriver_->receiveFrame(frame_) == 0) { 153 131 receivedFrames_[counter_].time = road_time(); … … 155 133 memcpy(&(receivedFrames_[counter_].frame), &frame_, sizeof(CanFrame)); 156 134 semaphore_->release(); 157 counter_++; 158 counter_ = counter_ % receivedFramesArraySize_; 159 } 160 } 161 } 162 163 /************************************************************************/ 164 /// The loop used for waiting CAN data from Kvaser card 165 void Win32CanInterface::kvaserLoop() 166 { 167 while(continue_) { 168 // Wait incoming data from the CAN bus 169 if (canDriver_->receiveFrame(frame_) == 0) { 170 receivedFrames_[counter_].time = road_time(); 171 receivedFrames_[counter_].timerange = 0; 172 memcpy(&(receivedFrames_[counter_].frame), &frame_, sizeof(CanFrame)); 173 semaphore_->release(); 174 counter_++; 135 counter_++; 175 136 counter_ = counter_ % receivedFramesArraySize_; 176 137 } … … 195 156 // memcpy(&(receivedFrames_[counter_].frame), &frame_, sizeof(CanFrame) ); 196 157 // semaphore_->release(); 197 // counter_++; 158 // counter_++; 198 159 // counter_ = counter_ % receivedFramesArraySize_; 199 160 // } 200 161 // } // END while (continue_) 201 162 202 163 // delete shMem_; 203 164 // } 204 165 205 /************************************************************************/206 /// The loop used for waiting CAN data from Peak card207 void Win32CanInterface::peakLoop()208 {209 std::cout << "In peak loop" << std::endl;210 while(continue_)211 {212 // Wait incoming data from the CAN bus213 if ( canDriver_->receiveFrame(frame_) == 0 ) {214 receivedFrames_[counter_].time = road_time();215 receivedFrames_[counter_].timerange = 0;216 memcpy(&(receivedFrames_[counter_].frame), &frame_, sizeof(CanFrame) );217 semaphore_->release();218 counter_++;219 counter_ = counter_ % receivedFramesArraySize_;220 }221 }222 }223 224 /************************************************************************/225 /// The loop used for waiting CAN data from igep card226 void Win32CanInterface::igepLoop()227 {228 std::cout << "In igep loop" << std::endl;229 230 while(continue_)231 {232 // Wait incoming data from the CAN bus233 if ( canDriver_->receiveFrame(frame_) == 0 ) {234 receivedFrames_[counter_].time = road_time();235 receivedFrames_[counter_].timerange = 0;236 memcpy(&(receivedFrames_[counter_].frame), &frame_, sizeof(CanFrame) );237 semaphore_->release();238 counter_++;239 counter_ = counter_ % receivedFramesArraySize_;240 }241 }242 }243 166 /************************************************************************/ 244 167 /// Stops the thread … … 251 174 /// Defines the place where the incoming frames will be copied 252 175 void Win32CanInterface::setExchangeBuffer(TimestampedCanFrame * framesArray, const int framesArraySize) 253 { 176 { 254 177 receivedFrames_ = framesArray; 255 178 receivedFramesArraySize_ = framesArraySize;
Note:
See TracChangeset
for help on using the changeset viewer.