Reading past max_samples_per_read

4 posts / 0 new
Last post
Offline
Last seen: 8 years 3 weeks ago
Joined: 10/21/2012
Posts: 18
Reading past max_samples_per_read

The max_samples_per_read qos parameter (default value = 1024) limits the number of samples that may be read/taken in a single call.

When using read rather than take, once the first 1024 samples have been read, how would you go about reading samples beyond the first 1024 that have been returned?

I want to periodically read all of the data samples, so I don't want to use the sample state Read/Not_Read filter capability. I also realise that I could just increase the value of the qos parameter beyond its default value, but that just raises the limit to another finite value. Just delaying the inevitable.

Thanks

Dallas

Organization:
Gerardo Pardo's picture
Offline
Last seen: 3 weeks 5 days ago
Joined: 06/02/2010
Posts: 602

Hello Dallas,

The way to iterate over all instances, even if they have already been read, it is to use the operation read_next_instance() on the DataReader.  

Each time you want to begin an iteration you begin by calling read_next_instance() passing DDS_HANDLE_NIL as the value of the previous_handle parameter. This will give you all the samples associated with the first instance, then you call  read_next_instance() passing the instance_handle you get inside the DDS_SampleInfo as the value of previous_handle  and so forth until read_next_instance() returns DDS_RETCODE_NO_DATA.

Note however that you will be accessing samples ordered by instance, not ordered by the time when they were received. Samples returned on each call to   read_next_instance() will all be for the same instance and the will be ordered by reception time stamp. But samples returned by different calls to  read_next_instance() are not ordered.  

Gerardo

asanchez's picture
Offline
Last seen: 4 years 5 months ago
Joined: 11/16/2011
Posts: 50

Hi Dallas,

I have some questions: do you want to read only non-read samples on every period? why would you not want to use the DDS_SampleStateMask when reading? I don't see that for the fact of reading periodically you couldn't use such filter. I think that would solve the problem.

Regarding the max_samples_per_read, you can also achieve same behavior by using the read's argument max_samples; losing the ability of configuring at run time though. In any case, an example of how to read up to max_samples_per_read is shown below:

MAX_SAMPLES_PER_READ = 1024;
...
/* execute every period */
...
FooDataReader_read(
fooSeq,
infoSeq,
MAX_SAMPLES_PER_READ,
DDS_NOT_READ_SAMPLE_STATE,
DDS_ANY_VIEW_STATE,
DDS_ANY_INSTANCE_STATE);
...

This would deliver the samples ordered by reception timestamp. If you want to get the samples ordered by instance, then you can proceed as Gerardo suggests and apply the sample state filter as well.

Antonio

Offline
Last seen: 8 years 3 weeks ago
Joined: 10/21/2012
Posts: 18

Thanks Gerardo and Antonio for your responses.

The option of using read_next_instance seems to be the best fit for my application; a radar that needs to display both current and historical positions of detections. I'd rather not use the SampleStateMask option to only read non-read samples because that would mean that I would need to maintain my own internal database of historical data.

The length of the history for each detection is manageable, but the number of detections is indeterminate. So iterating over each instance in turn seems to be a better fit.

Dallas