Changeset 363 in flair-src for trunk/tools/VrpnLite/src


Ignore:
Timestamp:
Sep 3, 2020, 8:54:16 AM (4 years ago)
Author:
Sanahuja Guillaume
Message:

allow mutliple connection on udp (only nrt for the moment)

Location:
trunk/tools/VrpnLite/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/VrpnLite/src/VrpnLite.cpp

    r334 r363  
    3737  Time dataSocketTimeout;
    3838  char msg[256];
     39  int src_id;
    3940 
    4041  while (!ToBeStopped()) {
    41    
    4242    if(vrpnobjects.size()>0) {
    4343      //wait for last one to be sure all are up to date
     
    5151    }
    5252   
    53     ssize_t rcv=dataSocket->RecvMessage(msg,sizeof(msg),dataSocketTimeout);
     53    ssize_t rcv=dataSocket->RecvMessage(msg,sizeof(msg),dataSocketTimeout,NULL,NULL,&src_id);
    5454    if(rcv>0) {
    5555      string object=msg;
     
    5757      memcpy(&id,&msg[rcv-2],sizeof(id));
    5858      dataSocket->HostToNetwork((char*)&id,sizeof(id));
     59     
     60      if(src_id==vrpnobjects_list.size()) {
     61        vector<VrpnObject*> vect;
     62        vrpnobjects_list.push_back(vect);
     63        Printf("add vect %i\n",src_id);
     64      }
    5965      //assume we receive it in the good order
    60       if(id==vrpnobjects.size()) {
    61         Printf("adding object %s with id %i\n",object.c_str(),id);
     66      if(id==vrpnobjects_list.at(src_id).size()) {
     67        Printf("adding object %s with id %i from %i\n",object.c_str(),id,src_id);
    6268        VrpnObject* vrpnobject = new VrpnObject(object,vrpnclient->GetTabWidget());
    6369        vrpnobjects.push_back(vrpnobject);
     70        vrpnobjects_list.at(src_id).push_back(vrpnobject);
    6471      }else {
    6572        Err("adding object %s failed, expected id %i, got %i\n",object.c_str(),vrpnobjects.size(),id);
     
    7077
    7178void VrpnLite::SendObjects(void) const{
    72   int16_t position[3];
     79 return;
     80 int16_t position[3];
    7381  int16_t quaternion[4];
    7482  Time time;
    7583  char datas[vrpnobjects.size()*(sizeof(position)+sizeof(quaternion))+ sizeof(time)];
    7684  char *datasPtr=datas;
    77  
    78   for (vector<VrpnObject*>::const_iterator it = vrpnobjects.begin();it < vrpnobjects.end(); it++) {
    79     Vector3Df objectPosition;
    80     Quaternion objectQuaternion;
    81     const VrpnObject* vrpnobject=*it;
     85 
     86  //for (vector<vector<VrpnObject*>>::const_iterator connection= vrpnobjects_list.begin();connection < vrpnobjects_list.end(); connection++) {
     87  for (int i=0;i<vrpnobjects_list.size();i++) {
     88      for (vector<VrpnObject*>::const_iterator it = vrpnobjects_list.at(i).begin();it < vrpnobjects_list.at(i).end(); it++) {
     89        Vector3Df objectPosition;
     90        Quaternion objectQuaternion;
     91        const VrpnObject* vrpnobject=*it;
    8292
    83     vrpnobject->GetPosition(objectPosition);
    84     vrpnobject->GetQuaternion(objectQuaternion);
    85     time=vrpnobject->GetLastPacketTime();
     93        vrpnobject->GetPosition(objectPosition);
     94        vrpnobject->GetQuaternion(objectQuaternion);
     95        time=vrpnobject->GetLastPacketTime();
    8696
    87     position[0]=ConvertPosition(objectPosition.x);
    88     position[1]=ConvertPosition(objectPosition.y);
    89     position[2]=ConvertPosition(objectPosition.z);
    90     quaternion[0]=ConvertQuaternion(objectQuaternion.q0);
    91     quaternion[1]=ConvertQuaternion(objectQuaternion.q1);
    92     quaternion[2]=ConvertQuaternion(objectQuaternion.q2);
    93     quaternion[3]=ConvertQuaternion(objectQuaternion.q3);
     97        position[0]=ConvertPosition(objectPosition.x);
     98        position[1]=ConvertPosition(objectPosition.y);
     99        position[2]=ConvertPosition(objectPosition.z);
     100        quaternion[0]=ConvertQuaternion(objectQuaternion.q0);
     101        quaternion[1]=ConvertQuaternion(objectQuaternion.q1);
     102        quaternion[2]=ConvertQuaternion(objectQuaternion.q2);
     103        quaternion[3]=ConvertQuaternion(objectQuaternion.q3);
    94104
    95     for(int i=0;i<3;i++) dataSocket->HostToNetwork((char*)(&position[i]),sizeof(position[i]));
    96     for(int i=0;i<4;i++) dataSocket->HostToNetwork((char*)(&quaternion[i]),sizeof(quaternion[i]));
     105        for(int i=0;i<3;i++) dataSocket->HostToNetwork((char*)(&position[i]),sizeof(position[i]));
     106        for(int i=0;i<4;i++) dataSocket->HostToNetwork((char*)(&quaternion[i]),sizeof(quaternion[i]));
    97107
    98     memcpy(datasPtr,position, sizeof(position));
    99     datasPtr+=sizeof(position);
    100     memcpy(datasPtr,quaternion, sizeof(quaternion));
    101     datasPtr+=sizeof(quaternion);
     108        memcpy(datasPtr,position, sizeof(position));
     109        datasPtr+=sizeof(position);
     110        memcpy(datasPtr,quaternion, sizeof(quaternion));
     111        datasPtr+=sizeof(quaternion);
     112      }
     113      dataSocket->HostToNetwork((char*)(&time),sizeof(Time));
     114      memcpy(datasPtr,&time, sizeof(time));//only one time for all VrpnObject; suppose it is the same!
     115      dataSocket->SendMessage(datas,sizeof(datas),i);
    102116  }
    103  
    104   dataSocket->HostToNetwork((char*)(&time),sizeof(Time));
    105   memcpy(datasPtr,&time, sizeof(time));//only one time for all VrpnObject; suppose it is the same!
    106   dataSocket->SendMessage(datas,sizeof(datas));
    107117}
    108118
  • trunk/tools/VrpnLite/src/VrpnLite.h

    r330 r363  
    3737      flair::sensor::VrpnClient* vrpnclient;
    3838      std::vector<flair::sensor::VrpnObject*> vrpnobjects;
     39      std::vector<std::vector<flair::sensor::VrpnObject*>> vrpnobjects_list;
    3940      flair::core::UdpSocket* dataSocket;
    4041      void SendObjects(void) const;
Note: See TracChangeset for help on using the changeset viewer.