Changeset 238 in flair-src for trunk/lib/FlairSensorActuator


Ignore:
Timestamp:
May 15, 2018, 4:41:02 PM (4 years ago)
Author:
Bayard Gildas
Message:

correction sémaphore. bloquant tout ça...

Location:
trunk/lib/FlairSensorActuator/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairSensorActuator/src/HostEthController.cpp

    r230 r238  
    142142}
    143143
    144 bool HostEthController::ConnectedWithTarget() {
     144bool HostEthController::ConnectWithTarget() {
    145145  char message[1024];
    146146  ssize_t sent, received;
     
    181181      GetButtonData();
    182182
    183       if (ConnectedWithTarget()) {
     183      if (ConnectWithTarget()) {
    184184        // read for commands from the target (remote control state change
    185185        // requests such as rumble or led on/off)
     
    201201      }
    202202    } else { // try to connect even if host is not sending anything
    203       ConnectedWithTarget();
     203      ConnectWithTarget();
    204204    }
    205205    // Thread::Info("Debug: exiting acquisition loop\n");
     
    291291    WaitPeriod();
    292292    if (hostEthController->meaningfulDataAvailable &&
    293         hostEthController->ConnectedWithTarget()) {
     293        hostEthController->ConnectWithTarget()) {
    294294      // send the data
    295295      hostEthController->BuildDataFrame();
  • trunk/lib/FlairSensorActuator/src/HostEthController.h

    r214 r238  
    2525
    2626namespace 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  }
    3838}
    3939
     
    4747*through ethernet connection
    4848*
    49 * There are 2 communication channels:
     49* There are 3 communication channels:
    5050*   - 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 receive
    53 *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)
    5454*/
    5555class HostEthController : public core::Thread, public core::IODevice {
     
    107107
    108108  bool ControllerInitialization();
    109   bool ConnectedWithTarget();
     109  bool ConnectWithTarget();
    110110  void SendControllerInfo();
    111111  void Run();
  • trunk/lib/FlairSensorActuator/src/SimuCamera.cpp

    r224 r238  
    8080    output->GetMutex();
    8181    //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
    8985
    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    }
    9195  }
    9296}
  • trunk/lib/FlairSensorActuator/src/TargetEthController.cpp

    r214 r238  
    5959    // socket to be closed by the client
    6060    controlSocket->RecvMessage(msg.buffer, msg.bufferSize);
     61    delete controlSocket;
    6162  }
    6263
     
    6566  SafeStop();
    6667  Join();
     68  delete dataSocket;
     69  delete listeningSocket;
    6770}
    6871
     
    202205
    203206bool 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);
    205208}
    206209
     
    234237  bool connectionAccepted = false;
    235238  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
    239246      if (ToBeStopped())
    240247        return false;
     248    }
     249    if (controlSocket == nullptr) {
     250      return false;
    241251    } else
    242252      connectionAccepted = true;
     
    248258  while (!axisNumberRead) {
    249259    try {
    250       axisNumber = controlSocket->ReadUInt32(10);
     260      axisNumber = controlSocket->ReadUInt32(100000000);
    251261      // Thread::Info("Debug: axisNumber %d\n", axisNumber);
    252262      axisNumberRead = true;
     
    260270  while (!bitsPerAxisRead) {
    261271    try {
    262       bitsPerAxis = controlSocket->ReadUInt32(10);
     272      bitsPerAxis = controlSocket->ReadUInt32(100000000);
    263273      // Thread::Info("Debug: bits per axis %d\n", bitsPerAxis);
    264274      bitsPerAxisRead = true;
     
    276286    while (!stringSizeRead) {
    277287      try {
    278         stringSize = controlSocket->ReadUInt32(10);
     288        stringSize = controlSocket->ReadUInt32(100000000);
    279289        stringSizeRead = true;
    280290      } catch (std::runtime_error e) {
     
    288298    while (!axisNameRead) {
    289299      try {
    290         axisName[i] = controlSocket->ReadString(stringSize, 10);
     300        axisName[i] = controlSocket->ReadString(stringSize, 100000000);
    291301        axisNameRead = true;
    292302      } catch (std::runtime_error e) {
     
    303313  while (!buttonNumberRead) {
    304314    try {
    305       buttonNumber = controlSocket->ReadUInt32(10);
     315      buttonNumber = controlSocket->ReadUInt32(100000000);
    306316      buttonNumberRead = true;
    307317    } catch (std::runtime_error e) {
     
    319329    while (!stringSizeRead) {
    320330      try {
    321         stringSize = controlSocket->ReadUInt32(10);
     331        stringSize = controlSocket->ReadUInt32(100000000);
    322332        stringSizeRead = true;
    323333      } catch (std::runtime_error e) {
     
    331341    while (!buttonNameRead) {
    332342      try {
    333         buttonName[i] = controlSocket->ReadString(stringSize, 10);
     343        buttonName[i] = controlSocket->ReadString(stringSize, 10000000);
    334344        buttonNameRead = true;
    335345      } catch (std::runtime_error e) {
Note: See TracChangeset for help on using the changeset viewer.