The video I uploaded shows how the program should work. I want to join a project group in my university so I'm learning Arudino and communication protocols. This program must communicate with UART ( Serial )
So if input's first bit is 'S', continues with '0' or '1', continues with an integer between 0-255, continues with '0' or '1' continues with an integer between 0-255, and finally finishes 'F', it prints the values. If there is useless, random letters and numbers, program eliminates them find the needed information.
UKHeliBob:
Do you know how to read characters from Serial and test their value ?
Can you not just read characters and ignore irrelevant values ?
I know most of the serial functions and I know how to read characters. I don't know how to test their values, though. And I don't know how to ignore some values as well.
Can you give some examples of what the received strings will be? Particularly when there is useless random letters mixed in - where do those come from?
wildbill:
Can you give some examples of what the received strings will be? Particularly when there is useless random letters mixed in - where do those come from?
Actually the video I uploaded shows program should work. Program only prints if inputs are in desired order and that order is 'S' - '0' or '1' (it shows which way is motor running, forward or reverse) - number between '000' and '255'(it's motor's speed) - '0' or '1' (other motor's direction) - number between '000' and '255' and 'F'. English is not my mother language so I understand that I can't explain exactly how it works but I'm doing my best.
So it looks as though you're simply concerned about user error on input. Given that you're pressed for time, I'd suggest that you start out with writing something that deals with well formed input and then add some defense against bad data.
Which would basically be:
Read and throw away characters until you see an S
Read and store characters until you see an F
Chop out the fields you want and print them.
The first (vital) defense against bad data would be to ensure that the data you're reading isn't longer than the array you defined to put it in.
wildbill:
A second thing that would eliminate most of your bad data would simply be to only store digits when you've seen an 'S' and are looking for an 'F'.
I checked it out but my problem seems like much more complex than examples in that tutorial. I don't even know how to approach to this problem or where to start.
wildbill:
Start with code that works for the simple case only as I suggested in reply #7. Once you have that you can tweak it to deal with error cases.
Are your users going to deliberately try to break your system or are you just worried about typos?
They are going to deliberately try to break it. They would give inputs in every possible ways.