Receive data over SDU

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Receive data over SDU

Post by Tectu »

Hello folks,

I did use the SDU stuff often to create a serial connection to my host computer. I always used it to chprintf() over it. However, I'd now need a way to receive data over it. The data are simply integer values separated by a semicolon.
What's exactly the right way to do this job?

I took a look to the SDU documentation and I did found the sduDataReceived() function which is mentioned to only be used as a callback, not to get the data. How am I supposed to use this to get the actual data? Is this even the right way to go?
I thought there might be a function similar to chprintf() which does take the BaseSequentialStream* as a paramter, but I didn't found any.


~ Tectu
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Receive data over SDU

Post by Giovanni »

That would be a chscanf() but we don't have that yet. It would be a good to have.

Giovanni
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: Receive data over SDU

Post by Tectu »

Wait... there's really currently no way to receive a bytestream? How does the shell do it?
Of course a scanf function would be nice, but currently it would be okay if I got the data actually inside the memory where I can parse it further.


~ Tectu
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Receive data over SDU

Post by Giovanni »

Of course you can, SDU is a stream, use stream functions for reading and writing.

Giovanni
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: Receive data over SDU

Post by Tectu »

Giovanni, could you please give me a hand telling me what function(s) I am searching for? Thank you very much.

~ Tectu
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Receive data over SDU

Post by Giovanni »

The ones in chstreams.h and also the ones in io_channel.h, those files contain the ancestor interfaces of the SDU stream.

Note, stream methods are C macros.

Giovanni
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: Receive data over SDU

Post by Tectu »

Thank you very much for your help, Giovanni. I got it working!


~ Tectu
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: Receive data over SDU

Post by Tectu »

Okay, sorry for getting this up once again, Giovanni, but I'd need some more help:

I could successfully read from the stream using chSequentialStreamRead().
However, currently I'm just calling that function and then I poll until I receive the right amount of bytes. What's exactly the way not to have to poll? Am I right that I can use sduDataReceived() with chEvtRegister?


~ Tectu
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Receive data over SDU

Post by Giovanni »

If you specify a number of bytes and TIME_INFINITE to a read function then it will wait until the number has been reached. Note that the behavior in case of errors is not defined by the interface.
On communication channels you should always be listening for condition flags too and read the channel using TIME_IMMEDIATE when data is available.

Giovanni
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: Receive data over SDU

Post by Tectu »

Hey Giovanni,

I'm just not quite sure what exactly I have to give chEvtRegister() as the first parameter (the event source). How can I get an event when I receive data?

Also, I read through the STM32F103-FATFS demo. I don't understand why the chEvtDispatch() is called in the loop. Can you explain that to me?


~ Tectu
Post Reply