Ignore:
Timestamp:
02/13/17 15:02:54 (7 years ago)
Author:
Sanahuja Guillaume
Message:

vrpn: improved timeout

File:
1 edited

Legend:

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

    r15 r136  
    4242
    4343VrpnClient_impl::VrpnClient_impl(VrpnClient *self, std::string name,
    44                                  std::string address, uint16_t us_period) {
    45   this->us_period = us_period;
     44                                 std::string address) {
    4645  this->self = self;
    4746  serialport = NULL;
     47        isConnected=false;
    4848
    4949  mutex = new Mutex(self, name);
     
    162162
    163163void VrpnClient_impl::Run(void) {
     164        struct timeval timeout;
     165        timeout.tv_sec=0;
     166        timeout.tv_usec=100000;
     167                       
    164168  while (!self->ToBeStopped()) {
    165169    if (UseXbee()) {
     
    200204              t.quat[i] = quat[i];
    201205            if (fabs(pos[0] > 10) || fabs(pos[1] > 10) || fabs(pos[2] > 10)) {
    202               printf("prob pos %f %f %f\n", pos[0], pos[1], pos[2]);
     206              Printf("prob pos %f %f %f\n", pos[0], pos[1], pos[2]);
    203207            } else {
    204208              // self->Printf("%i %f %f %f
     
    210214        }
    211215      }
    212     } else {
    213       connection->mainloop();
    214       mutex->GetMutex();
    215       for (unsigned int i = 0; i < trackables.size(); i++)
    216         trackables.at(i)->mainloop();
    217       mutex->ReleaseMutex();
    218 
    219       self->SleepUS(us_period);
     216    } else {//!UseXbee()
     217                        if(connection->connected()==vrpn_true && !isConnected) {
     218                                isConnected=true;
     219                                Printf("VRPN connected\n");
     220                        }
     221                        if(connection->connected()==vrpn_false && isConnected) {
     222                                isConnected=false;
     223                                Printf("VRPN disconnected\n");
     224                        }
     225                       
     226                        //timeout in mainloop is not well handled if not connected...
     227                        if(isConnected) {
     228                                //this is when trackables callbacks are called:
     229                                if(connection->mainloop(&timeout)!=0) {
     230                                        self->Warn("connection dropped\n");
     231                                }
     232                                //printf("%lld\n",GetTime()/(1000*1000));
     233                                mutex->GetMutex();
     234                                for (unsigned int i = 0; i < trackables.size(); i++)
     235                                        trackables.at(i)->mainloop();
     236                                mutex->ReleaseMutex();
     237                        } else {
     238                                connection->mainloop();
     239                                self->SleepMS(10);
     240                        }
    220241    }
    221242  }
Note: See TracChangeset for help on using the changeset viewer.