Parsing (OP-LIB-002)

From openPicus Wiki
Jump to: navigation, search

Contents

Description

This library allows to parse in a string or more strings. The library can be used in many ways and to parse so many different string type: XML files, NMEA strings from GPS, HTTP requests and much more.

Content

  • parse.c
  • parse.h

Download

OP-LIB-002

Example of usage

Example of usage for NMEA strings from a GPS module:

 
char str1[50]; char str2[50]; char str3[50]; char str4[50]; char str5[50]; 
char *arraySUBSTRING[]={ str1, str2, str3, str4, str5}; 
char buffer[]="$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47"; 
multiPARSEbetween( buffer, ",", ",", arraySUBSTRING, 5);
UARTWrite(1,"UTC "); 
UARTWrite(1,str1); 
UARTWrite(1," Lat "); 
UARTWrite(1,str2); 
UARTWrite(1," "); 
UARTWrite(1,str3); 
UARTWrite(1," Log "); 
UARTWrite(1,str4); 
UARTWrite(1," "); 
UARTWrite(1,str5);

Output: UTC 123519 Lat 4807.038 N Log 01131.000 E

Importing into OpenPicus IDE

Import ALL the files of the library using the button “external lib” of the IDE, then Include parse.h in the files in which you want to use the functions (using the directive #include “parse.h”).

How To import external Lib Tutorial

Commands


dynamicPARSE

Function to parse strings

dynamicPARSE(char *tab[][5], int rows)
Argument Description
char *tab[][5] pointer to bidimensional array
int rows number of the array rows
*tab[][5] Description
tab[0][0] type of parse (use denfine)
  • BETWEEN
  • BEFORE
  • AFTER
tab[0][1] string/token where to start
tab[0][2] string/token where to stop
tab[0][3] destination string
tab[0][4] source string


HTTPdynamicPARSE

HTTPdynamicPARSE(char host[], char command[], char *tab[][5], int rows, int snifftime)
Argument Description
char host[] IP or Website address to which want to connect
char command[] command to be sent through the TCPClient
char *tab[][5] pointer to bidimensional array
int rows number of the array rows int snifftime - time in 10 microseconds to accumulate more characters
int snifftime time in 10 microseconds to accumulate more characters
*tab[][5] Description
tab[0][0] type of parse (use denfine)
  • BETWEEN
  • BEFORE
  • AFTER
tab[0][1] string/token where to start
tab[0][2] string/token where to stop
tab[0][3] destination string
tab[0][4] option destination string (use denfine)
  • YES destination string = buffer
  • NO destination string = tab[0][3]


multiPARSEbetween

Function to use more PARSEbetween in a string.

multiPARSEbetween(char str[], char start[], char stop[], char *substr[], int multi)
Argument Description
char str[] source string
char start[] string/token where to start
char stop[] string/token where to stop
char *substr[] pointer to destination string
int multi number of executions of the PARSEbetween function



PARSEafter

Function to parse a string and rewrite it from start token to the end.

PARSEafter(char str[], char start[], char substr[])
Argument Description
char str[] source string
char start[] string/token where to start
char substr[] destination string


PARSEbefore

Function to parse a string and rewrite it from start to the stop token.

PARSEbefore(char str[], char stop[], char substr[])
Argument Description
char str[] source string
char stop[] string/token where to stop
char substr[] destination string


PARSEbetween

Function to parse a string and rewrite it from start token to the stop token.

PARSEbetween(char str[], char start[], char stop[], char substr[])
Argument Description
char str[] source string
char start[] string/token where to start
char stop[] string/token where to stop
char substr[] destination string

Related Resources

Credits

Stefano Saccucci - v1.0

Special thanks to settorezero.com

Personal tools
Namespaces

Variants
Actions
START HERE
DEVELOPMENT
HARDWARE INFO
RESOURCES
PHASED OUT
Toolbox