What would cause Endpoint_Read_Stream_LE to read only 8 bytes?

12 views
Skip to first unread message

ulao

unread,
Nov 10, 2021, 9:33:33 PM11/10/21
to LUFA Library Support List
I wrote my original logic like this.
if (  Endpoint_BytesInEndpoint() )
            {
                if (dataSize == 0)
                {
                    GenericData[0] =  Endpoint_Read_8(); //report
                    dataSize = Endpoint_BytesInEndpoint(); //save size
                    memset(GenericData + 1,0,dataSize);//set memory
                }

                GenericData[dataSize - Endpoint_BytesInEndpoint() + 1]  = Endpoint_Read_8();
                   
                if ( Endpoint_BytesInEndpoint() == 1 )
                {               
                    FfbProcessor(GenericData );
                }            
            } else { Endpoint_ClearOUT(); dataSize=0; }


but I didn't like it, was ugly and seems like an overkill, so I tried to use Endpoint_Read_Stream_LE

It reads all my reports accept the one report that is > 8 bytes.

code is simply
if (Endpoint_IsReadWriteAllowed() )
                {

                    memset(GenericData ,0, FFB_EPSIZE);
                    Endpoint_Read_Stream_LE(&GenericData, FFB_EPSIZE, NULL);   
                    FfbProcessor(GenericData);

                }
                Endpoint_ClearOUT();

the report is
1,1,1,f4,1,0,0,0,0,ff,ff,4,3f,0,0

I do use a if (  Endpoint_IsOUTReceived() )  beforehand



ulao

unread,
Nov 11, 2021, 8:29:19 AM11/11/21
to LUFA Library Support List
Ok this worked but would like to know what I was doing wrong.

memset(GenericData ,0, FFB_EPSIZE);
while(Endpoint_Read_Stream_LE(&GenericData, Endpoint_BytesInEndpoint(), NULL) != ENDPOINT_RWSTREAM_NoError);
  FfbProcessor(GenericData);

Dean Camera

unread,
Nov 28, 2021, 1:51:32 AM11/28/21
to lufa-s...@googlegroups.com, ulao

The difference between the two is the first version is reading a fixed number of bytes, blocking until all the data is recived, and the second is only reading out the exact number of bytes that have currently been buffered. The second version ensures that the stream read function won't block, but it also might not have all the data you expect if your message is larger than the endpoint size.

If you need to read in a larger message but don't want to block, you can use the last parameter to get the number of bytes actually read, and use that to accumulate the reads until the entire message has been read. When given the out size parameter, the stream read functions will update it and exit immediately once all the buffered data has been read out, instead of blocking. It's then the responisbility of your program to keep calling the stream read functions until you've got all the data you need to process the message.

Cheers,

- Dean

--
You received this message because you are subscribed to the Google Groups "LUFA Library Support List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lufa-support...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lufa-support/672d559a-a48d-4fdf-b67d-a869beab4698n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages