Changeset 116 in pacpussensors for trunk/CanGateway/CanGateway.cpp
- Timestamp:
- Dec 16, 2015, 4:57:50 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/CanGateway/CanGateway.cpp
r91 r116 59 59 60 60 // 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 } 65 68 else if (source_ == "vector") 66 69 { 67 canIf_.setSource(Win32CanInterface::VectorCard); 70 sameCanIf = true; 71 canIfRead_.setSource(Win32CanInterface::VectorCard); 68 72 // open the interface 69 if (!canIf _.openInterface(channel_, speed_))73 if (!canIfRead_.openInterface(channel_, speed_)) 70 74 qFatal("Failed to open the CAN interface num %d at speed %d",channel_,speed_); 71 75 } 72 76 else if (source_ == "vectorXL") 73 77 { 74 canIf_.setSource(Win32CanInterface::XLVectorCard); 78 sameCanIf = true; 79 canIfRead_.setSource(Win32CanInterface::XLVectorCard); 75 80 // open the interface 76 if (!canIf _.openInterface(channel_, speed_))81 if (!canIfRead_.openInterface(channel_, speed_)) 77 82 qFatal("Failed to open the CAN interface num %d at speed %d",channel_,speed_); 78 83 } 79 84 else if (source_ == "peak") 80 85 { 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) 84 90 qFatal("Failed to open the CAN interface port %s in %s mode",port_, accessMode_); 85 91 } 86 92 else if (source_ == "igep") 87 93 { 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) 91 98 qFatal("Failed to open the CAN interface port %s in %s mode",port_, accessMode_); 92 99 } 93 100 else if (source_ == "kvaser") 94 101 { 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) 98 111 qFatal("Failed to open the CAN interface num %d at speed %d",channel_,speed_); 99 112 } … … 105 118 106 119 // start the 2 threads: reception thread and decoding thread 107 canIf_.start(); 120 canIfRead_.start(); 121 108 122 start(); 109 123 } … … 117 131 { 118 132 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 } 123 141 124 canIf _.wait();142 canIfRead_.wait(); 125 143 126 144 // we stop the decoding thread … … 167 185 bool CanGateway::sendFrame(const CanFrame frame) 168 186 { 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 } 171 199 else 172 200 { 173 if (canIf _.canDriver_->sendFrame(frame))174 return true;201 if (canIfWrite_.canDriver_ == NULL) 202 return false; 175 203 else 176 return false; 204 { 205 if (canIfWrite_.canDriver_->sendFrame(frame)) 206 return true; 207 else 208 return false; 209 } 177 210 } 178 211 }
Note:
See TracChangeset
for help on using the changeset viewer.