Page 1 of 2
Receive data over SDU
Posted: Tue Jan 15, 2013 11:11 am
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
Re: Receive data over SDU
Posted: Tue Jan 15, 2013 11:36 am
by Giovanni
That would be a chscanf() but we don't have that yet. It would be a good to have.
Giovanni
Re: Receive data over SDU
Posted: Tue Jan 15, 2013 11:39 am
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
Re: Receive data over SDU
Posted: Tue Jan 15, 2013 11:51 am
by Giovanni
Of course you can, SDU is a stream, use stream functions for reading and writing.
Giovanni
Re: Receive data over SDU
Posted: Tue Jan 15, 2013 2:11 pm
by Tectu
Giovanni, could you please give me a hand telling me what function(s) I am searching for? Thank you very much.
~ Tectu
Re: Receive data over SDU
Posted: Tue Jan 15, 2013 2:36 pm
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
Re: Receive data over SDU
Posted: Wed Jan 16, 2013 1:17 pm
by Tectu
Thank you very much for your help, Giovanni. I got it working!
~ Tectu
Re: Receive data over SDU
Posted: Thu Jan 17, 2013 8:18 am
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
Re: Receive data over SDU
Posted: Thu Jan 17, 2013 8:41 am
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
Re: Receive data over SDU
Posted: Thu Jan 17, 2013 12:10 pm
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