passing the data to the write()

2 posts / 0 new
Last post
s10
Offline
Last seen: 7 years 9 months ago
Joined: 02/07/2017
Posts: 1
passing the data to the write()

Hello
I've searched across to find a good example that explains how to pass the data generated by another application to the publisher. I went over the examples provided in rti-workspace/5.2.3/examples/connext_dds but i'm not sure how to do this.
Basically, I have one application that continuously genrates the coordinates (say x,y,z) and I would like to pass this data as it being generated to the publisher. I can generate IDL file with the struct that contains the coordinates, but then I'm not sure how should  I refer this data in write() ?
Any example would be appreciated, thank you!

Fernando Garcia's picture
Offline
Last seen: 4 months 1 week ago
Joined: 05/18/2011
Posts: 200

Hi Stan,

Let's assume that you are using C++ (we could port this to other languages), that you have a Coordinates class like the following, and that the value of x, y, an z is constantly being updated.

class Coordinates {
public:
    Coordinates(int x, int y, int z) : x_(x), y_(y), z_(z)
    {
    }
   
    int x()
    {
        return x_; 
    }
    
    int y()
    {
        return y_;
    }
    
    int z()
    {
        return z_; 
    }

    // Omitting setters  
 
private:
    int x_;
    int y_;
    int z_;  
};  

If you want to pass the value of x, y, and z to the write() method you will have to do the following:

  1. Define what the data type is going to look like in IDL.
    // coordinates.idl
     
    struct Coordinates {
        long x;
        long y;
        long z;
    };
  2. Run rtiddsgen to generate code.
    rtiddsgen -example <your_architecture> -language C++ coordinates.idl
  3. Modify the generated coordinates_publisher.cxx file as follows:
        ...
    
        // Main loop
        for (count=0; (sample_count == 0) || (count < sample_count); ++count) {
    
            printf("Writing coordinates, count %d\n", count);
    
            // Modify the data to be sent here
            instance->x = coordinates.x();
            instance->y = coordinates.y();
            instance->z = coordinates.z();
    
            retcode = waitsets_writer->write(*instance, instance_handle);
            if (retcode != DDS_RETCODE_OK) {
                printf("write error %d\n", retcode);
            }
    
            NDDSUtility::sleep(send_period);
        }
    

Please, let me know if this helps.

Thanks,
Fernando,