3

I'm doing reverse engineering about a ultrasound probe on the Linux side. I want to capture raw data from an ultrasound probe. I'm programming with C and using the libusb API.

There are two BULK IN endpoints in the device (2 and 6). The device is sending 2048 bytes data, but it is sending data as 512 bytes with four block.

Enter image description here

This picture is data flow on the Windows side, and I want to copy that to the Linux side. You see four data blocks with endpoint 02 and after that four data blocks with endpoint 06.

But there is a problem about timing. The first data block of endpoint 02's and first data block of endpoint 06's are close to each other acoording to time. But in data flow they are not in sequence.

I see that the computer is reading the first data blocks of endpoint 02 and 06. After that, the computer is reading the other three data blocks of endpoint 02 and endpoint 06. But in USB Analyzer, the data flow is being viewed according to the endpoint number. The sequence is different according to time.

On the Linux side, I write code like this:

int index = 0;

imageBuffer2 = (unsigned char *) malloc(2048);
imageBuffer6 = (unsigned char *) malloc(2048);

while (1) {
    libusb_bulk_transfer(devh, BULK_EP_2, imageBuffer2, 2048, &actual2, 0);

    libusb_bulk_transfer(devh, BULK_EP_6, imageBuffer6, 2048, &actual6, 0);

    //Delay
    for(index = 0; index <= 10000000; index ++)
    {

    }
}

So that result is in picture as below

Enter image description here

In other words, in my code all reading data is being read in sequence according to time and endpoint number. My result is different from the data flow on the Windows side.

In brief, I have two BULK IN endpoints, and they are starting read data close according to time. How is it possible?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
bzkrtmurat
  • 189
  • 1
  • 3
  • 15
  • 1
    BTW, there are better ways to delay your loops: man 3 nanosleep – asamarin Feb 12 '15 at 10:03
  • 1
    actually a sleep() or nanosleep() is the better option for delay; a for loop executing nothing might be optimized out by the compiler – Pandrei Feb 12 '15 at 11:18
  • 1
    try adding a nanosleep() for the delay and see if that solves your problem. it might be that you are reading faster than data is available – Pandrei Feb 12 '15 at 11:20
  • 1
    I will try this. Actually my problem is about first data group that is from 6 endpoint is getting before data group that is from 2 endpoint but as you can see in data flow data group that is from 6 endpoint is below data group that is from 2 endpoint in data list @Pandrei Note : First picture is data flow in windows side, second picture is data flow in linux side that is doing by me – bzkrtmurat Feb 12 '15 at 12:57
  • @Pandrei I did this. I'm using nanosleep now. But it is not solution of my problem – bzkrtmurat Feb 13 '15 at 08:40
  • ok...what seem to be the problem? I read the original question about 3 times and still can't get what's wrong – Pandrei Feb 13 '15 at 09:31
  • I editted my question. Hopefully it is clear :( @Pandrei – bzkrtmurat Feb 13 '15 at 12:49
  • I haven't solved my question yet. – bzkrtmurat Feb 16 '15 at 12:27

1 Answers1

2

It's not clear to me whether you're using a different method for getting the data on Windows or not, I'm going to assume that you are.

I'm not an expert on libusb by any means, but my guess would be that you are overwriting you data with each call, since you're using the same buffer each time. Try giving your buffer a fixed value before using the transfer method, and then evaluate the result. If it is the case, I believe something along the lines of the following would also work in C:

imageBuffer2 = (unsigned char *) malloc(2048);
char *imageBuffer2P = imageBuffer2;
imageBuffer6 = (unsigned char *) malloc(2048);
char *imageBuffer6P = imageBuffer6;
int dataRead2 = 0;
int dataRead6 = 0;

while(dataRead2 < 2048 || dataRead6 < 2048)
{
  int actual2 = 0;
  int actual6 = 0;
  libusb_bulk_transfer(devh, BULK_EP_2, imageBuffer2P, 2048-dataRead2, &actual2, 200);
  libusb_bulk_transfer(devh, BULK_EP_6, imageBuffer6P, 2048-dataRead6, &actual6, 200);
  dataRead2 += actual2;
  dataRead6 += actual6;
  imageBuffer2P += actual2;
  imageBuffer6P += actual6;
  usleep(1);
}
Jaciq
  • 158
  • 7