Changeset 238 in flair-src for trunk/lib/FlairSensorActuator/src
- Timestamp:
- May 15, 2018, 4:41:02 PM (7 years ago)
- Location:
- trunk/lib/FlairSensorActuator/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairSensorActuator/src/HostEthController.cpp
r230 r238 142 142 } 143 143 144 bool HostEthController::Connect edWithTarget() {144 bool HostEthController::ConnectWithTarget() { 145 145 char message[1024]; 146 146 ssize_t sent, received; … … 181 181 GetButtonData(); 182 182 183 if (Connect edWithTarget()) {183 if (ConnectWithTarget()) { 184 184 // read for commands from the target (remote control state change 185 185 // requests such as rumble or led on/off) … … 201 201 } 202 202 } else { // try to connect even if host is not sending anything 203 Connect edWithTarget();203 ConnectWithTarget(); 204 204 } 205 205 // Thread::Info("Debug: exiting acquisition loop\n"); … … 291 291 WaitPeriod(); 292 292 if (hostEthController->meaningfulDataAvailable && 293 hostEthController->Connect edWithTarget()) {293 hostEthController->ConnectWithTarget()) { 294 294 // send the data 295 295 hostEthController->BuildDataFrame(); -
trunk/lib/FlairSensorActuator/src/HostEthController.h
r214 r238 25 25 26 26 namespace flair { 27 namespace core {28 class Matrix;29 class TcpSocket;30 class UdpSocket;31 class Mutex;32 }33 namespace gui {34 class Tab;35 class TabWidget;36 class DataPlot1D;37 }27 namespace core { 28 class Matrix; 29 class TcpSocket; 30 class UdpSocket; 31 class Mutex; 32 } 33 namespace gui { 34 class Tab; 35 class TabWidget; 36 class DataPlot1D; 37 } 38 38 } 39 39 … … 47 47 *through ethernet connection 48 48 * 49 * There are 2communication channels:49 * There are 3 communication channels: 50 50 * - 1 connection with the ground station to display the values. Output for 51 *analog sticks is normalized in the range [-1, 1] (float values) 52 * - 1 connection with the target to send the controller values ( and receive53 * controller state modification requests)51 *analog sticks is normalized in the range [-1, 1] (float values) (through DrawUserInterface, use a UDT socket) 52 * - 1 connection with the target to send the controller values (through udp socket - high bandwitdh, packets may be discarded) 53 * - 1 connection with the target to receive controller state modification requests (through tcp socket - low bandwidth, packets must not be discarded) 54 54 */ 55 55 class HostEthController : public core::Thread, public core::IODevice { … … 107 107 108 108 bool ControllerInitialization(); 109 bool Connect edWithTarget();109 bool ConnectWithTarget(); 110 110 void SendControllerInfo(); 111 111 void Run(); -
trunk/lib/FlairSensorActuator/src/SimuCamera.cpp
r224 r238 80 80 output->GetMutex(); 81 81 //blocking read 82 shmem->Read(shmemReadBuf, buf_size); // remplacer copie par 83 // échange de pointeur sur 84 // double buffering 85 86 output->ReleaseMutex(); 87 memcpy(&time,shmemReadBuf+buf_size-sizeof(Time),sizeof(Time)); 88 output->SetDataTime(time); 82 if (shmem->Read(shmemReadBuf, buf_size, 1000000000)) { // remplacer copie par 83 // échange de pointeur sur 84 // double buffering 89 85 90 ProcessUpdate(output); 86 output->ReleaseMutex(); 87 memcpy(&time, shmemReadBuf + buf_size - sizeof(Time), sizeof(Time)); 88 output->SetDataTime(time); 89 90 ProcessUpdate(output); 91 } else { 92 output->ReleaseMutex(); 93 Thread::Warn("Read Timeout\n"); 94 } 91 95 } 92 96 } -
trunk/lib/FlairSensorActuator/src/TargetEthController.cpp
r214 r238 59 59 // socket to be closed by the client 60 60 controlSocket->RecvMessage(msg.buffer, msg.bufferSize); 61 delete controlSocket; 61 62 } 62 63 … … 65 66 SafeStop(); 66 67 Join(); 68 delete dataSocket; 69 delete listeningSocket; 67 70 } 68 71 … … 202 205 203 206 bool TargetEthController::ProcessMessage(Message *msg) { 204 return !(controlSocket->SendMessage(msg->buffer, msg->bufferSize, 0) < 0);207 return !(controlSocket->SendMessage(msg->buffer, msg->bufferSize, TIME_INFINITE) < 0); 205 208 } 206 209 … … 234 237 bool connectionAccepted = false; 235 238 while (!connectionAccepted) { 236 controlSocket = listeningSocket->Accept(10); 237 if (controlSocket == nullptr) { 238 // Timeout (or error btw) 239 try { 240 controlSocket = listeningSocket->Accept(100000000); 241 } catch (std::logic_error &e) { 242 Thread::Err(e.what()); 243 return false; 244 } catch (std::runtime_error e) { 245 // timeout 239 246 if (ToBeStopped()) 240 247 return false; 248 } 249 if (controlSocket == nullptr) { 250 return false; 241 251 } else 242 252 connectionAccepted = true; … … 248 258 while (!axisNumberRead) { 249 259 try { 250 axisNumber = controlSocket->ReadUInt32(10 );260 axisNumber = controlSocket->ReadUInt32(100000000); 251 261 // Thread::Info("Debug: axisNumber %d\n", axisNumber); 252 262 axisNumberRead = true; … … 260 270 while (!bitsPerAxisRead) { 261 271 try { 262 bitsPerAxis = controlSocket->ReadUInt32(10 );272 bitsPerAxis = controlSocket->ReadUInt32(100000000); 263 273 // Thread::Info("Debug: bits per axis %d\n", bitsPerAxis); 264 274 bitsPerAxisRead = true; … … 276 286 while (!stringSizeRead) { 277 287 try { 278 stringSize = controlSocket->ReadUInt32(10 );288 stringSize = controlSocket->ReadUInt32(100000000); 279 289 stringSizeRead = true; 280 290 } catch (std::runtime_error e) { … … 288 298 while (!axisNameRead) { 289 299 try { 290 axisName[i] = controlSocket->ReadString(stringSize, 10 );300 axisName[i] = controlSocket->ReadString(stringSize, 100000000); 291 301 axisNameRead = true; 292 302 } catch (std::runtime_error e) { … … 303 313 while (!buttonNumberRead) { 304 314 try { 305 buttonNumber = controlSocket->ReadUInt32(10 );315 buttonNumber = controlSocket->ReadUInt32(100000000); 306 316 buttonNumberRead = true; 307 317 } catch (std::runtime_error e) { … … 319 329 while (!stringSizeRead) { 320 330 try { 321 stringSize = controlSocket->ReadUInt32(10 );331 stringSize = controlSocket->ReadUInt32(100000000); 322 332 stringSizeRead = true; 323 333 } catch (std::runtime_error e) { … … 331 341 while (!buttonNameRead) { 332 342 try { 333 buttonName[i] = controlSocket->ReadString(stringSize, 10 );343 buttonName[i] = controlSocket->ReadString(stringSize, 10000000); 334 344 buttonNameRead = true; 335 345 } catch (std::runtime_error e) {
Note:
See TracChangeset
for help on using the changeset viewer.