cancel
Showing results for 
Search instead for 
Did you mean: 

The best way to compare two buffers

j3lda
Associate II
Posted on March 30, 2013 at 10:49

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 #parsing
2 REPLIES 2
Posted on March 30, 2013 at 12:30

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

petre
Associate II
Posted on April 05, 2013 at 15:20

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