| View previous topic :: View next topic |
| Author |
Message |
cnrs-insu
Joined: 05 May 2009 Posts: 19
|
Posted: Tue Jul 07, 2009 1:01 pm Post subject: get my data to buffer |
|
|
Hello,
I am still working on X3-10M.
I develop from the snap example and adapt the source to a multithread console program.
When a packet is received, I need to extract the data from the packet to put it in a local buffer and add some other information.
For this purpose, I didn't find an example or something in the documentation.
The other thing that I need is the organisation of data as I am acquiring 4 channel of 2500 samples (xMHz) at each external trigger (20 Hz).
If you can help me on this point, it should be great.
Best regards |
|
| Back to top |
|
 |
jhenderson Site Admin
Joined: 07 Mar 2006 Posts: 2267 Location: So. Cal. USA
|
Posted: Tue Jul 07, 2009 2:36 pm Post subject: |
|
|
The data received from the board is formatted similar to that shown at forum post http://www.iidsp.com/forum/viewtopic.php?t=411&highlight=format. However, since you are using an X3-10M module with four channels enabled, the payload (which follows the header in each packet) will contain four interleaved channels of 16-bit, twos-complement binary data.
To process each channel within each packet, use code similar to the following within the HandleDataAvailable event handler method (as illustrated in the X3-10M Snap, ApplicationIo.cpp file:
| Code: | //
// Extract the packet from the Incoming Queue...
Event.Sender->Recv(Packet);
ShortDG Packet_DG(Packet);
int channels = Module.Input().Info().Channels().ActiveChannels();
unsigned int samples = Packet_DG.SizeInElements()/channels;
Buffer data(Holding<float>(Packet_DG.SizeInElements()));
FloatDG Data(data);
for (int ch = 0; ch < channels; ++ch)
{
for (unsigned int sample = 0; sample < samples; ++sample)
Data[sample] = Packet_DG[sample*channels+ch];
//Analyze Data buffer here - Application-specific
}
|
|
|
| Back to top |
|
 |
cnrs-insu
Joined: 05 May 2009 Posts: 19
|
Posted: Wed Jul 08, 2009 4:15 am Post subject: |
|
|
Thanks for your help. |
|
| Back to top |
|
 |
ballard
Joined: 29 Apr 2011 Posts: 65
|
Posted: Fri Nov 18, 2011 7:12 am Post subject: |
|
|
if i want to put 2 channels in 2 separate arrays can i use following code?
| Code: | //----------------------------------Extract the packet from the Incoming Queue...
Event.Sender->Recv(Packet);
ShortDG Packet_DG(Packet);
int channels = Module.Input().Info().Channels().ActiveChannels();
unsigned int samples = (int)Packet_DG.SizeInElements()/channels;
Buffer data(Holding<float>(Packet_DG.SizeInElements()));
Buffer data2(Holding<float>(Packet_DG.SizeInElements()));
FloatDG Data(data);
FloatDG Data2(data);
//---------------------------------set the scale of data
float scalefactor = 2.0 / (1 << 15);
//---------------------------------parsing the packet
for (int ch = 0; ch < channels; ++ch)
{
for (unsigned int sample = 0; sample < samples; ++sample) {
if (ch==0)
Data[sample] = Packet_DG[sample*channels+ch]*scalefactor;
if (ch==1)
Data2[sample] = Packet_DG[sample*channels+ch]*scalefactor;
}
//--------------------------------Analyze Data buffer here - Application-specific
} |
|
|
| Back to top |
|
 |
ballard
Joined: 29 Apr 2011 Posts: 65
|
Posted: Fri Nov 18, 2011 7:24 am Post subject: |
|
|
sorry:
| Code: | FloatDG Data(data);
FloatDG Data2(data2); |
|
|
| Back to top |
|
 |
jhenderson Site Admin
Joined: 07 Mar 2006 Posts: 2267 Location: So. Cal. USA
|
Posted: Fri Nov 18, 2011 8:10 am Post subject: |
|
|
| I think you code is close, but you neglected to compensate for the size of each sample, which is 16-bits on the 10M. |
|
| Back to top |
|
 |
ballard
Joined: 29 Apr 2011 Posts: 65
|
Posted: Thu Mar 01, 2012 2:34 am Post subject: |
|
|
| Quote: | | I think you code is close, but you neglected to compensate for the size of each sample, which is 16-bits on the 10M. |
Thanks for an answer, but how i can do this, can you explain and show? |
|
| Back to top |
|
 |
jhenderson Site Admin
Joined: 07 Mar 2006 Posts: 2267 Location: So. Cal. USA
|
Posted: Thu Mar 01, 2012 6:05 am Post subject: |
|
|
Try something like the following. Note, code below is untested.
| Code: | //----------------------------------Extract the packet from the Incoming Queue...
Event.Sender->Recv(Packet);
ShortDG Packet_DG(Packet);
int channels = Module.Input().Info().Channels().ActiveChannels();
size_t samples = Packet_DG.SizeInElements()/channels;
std::vector< std::vector<float> > Data(channels, std::vector<float>(samples));
//---------------------------------set the scale of data
float scalefactor = 2.0 / (1 << 15);
//---------------------------------parsing the packet
short * p = &Packet_DG[0];
for (size_t sample = 0; sample < samples; ++sample)
for (int ch = 0; ch < channels; ++ch)
Data[ch][sample] = (*p++) * scalefactor;
//--------------------------------Analyze Data buffer here - Application-specific |
|
|
| Back to top |
|
 |
|