2013-03-30 02:49 AM
Hello, I�m begineer in programming in C and microcontrollers, so I�m sorry for stupid question. I receive commands via USART. What is the best way to compare RxBuffer with command saved in memory? Now I use comparing single bytes (1.byte with 1.byte, 2.byte with 2.byte,...), but this isn�t good solution(big code,...). Thanks for answers.
uint8_t RxBuffer[100]; // for example RxBuffer[0]=82, RxBuffer[1]=83, // RxBuffer[2]=84, RxBuffer[3]=10 ...RST\n uint8_t IDNcommand[] = ''IDN\n''; uint8_t RSTcommand[] = ''RST\n''; . . . // how to smartly compare these buffers? // problem: they have different size #parser #parsing2013-03-30 04:30 AM
Have you looked at the functions available in the standard 'C' library?
http://blog.antronics.co.uk/2011/08/08/so-youre-thinking-of-starting-with-c/
One way of parsing an input stream is to use a so-called State Machine aka Finite State Machine (FSM) or Finite State Automaton (plural: Automata) eg,http://www.visualgps.net/WhitePapers/NMEAParser/NMEAParser.html
2013-04-05 06:20 AM
Hi,
You can try:
int strncmp ( const char * str1, const char * str2, size_t num );search the function on the web, you'll get it :)Regards,Mihai