1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
void WI968C::get_value(char * chaine, byte index, char * delimiter, char * get_val)
{
// Get the value from a char delimited with comma
// 123,rftzg,4568
// get_value(1), will return rftzg
// char chaine[]= {block0,block1,block2,block3}
// Initiate the
byte ind = 0; // Position of the block of data into the chaine
byte x = 0; // index of val. Value to retunr.
byte ic = 0; // Index Chaine
bool flag = false; // True when it's part of block we need to extract
// If we need the first block (block0), flag must be true
if(index == 0)
{
flag = true;
}
// In my comment, take in concideration that index is egal to 0. We need to print the first block : 'block0'
do // Go trough chaine, one by one
{
//Serial.println(chaine[ic]);
switch(chaine[ic]){
case ' ': // When it read a comma, increment ind. Ind will no be egal to index and then val will not take new value.
if(chaine[ic]==delimiter[0])
{
ind++; // See default:
ic++;
continue; // return to the begin of 'do' loop and check next position of chaine
}
case ',':
if(chaine[ic]==delimiter[0])
{
ind++;
ic++;
continue;
}
case ':':
if(chaine[ic]==delimiter[0])
{
ind++;
ic++;
continue;
}
default:
if(ind == index) // if ind is egal to index. Index is the block we decide to have printed
{
get_val[x] = chaine[ic]; // Store the desired value in val
// Serial.print(F("Def")); Serial.println(val[x]);
x++;
}
}
ic++; // Go to next position of chaine
//Serial.print(F("co")); Serial.println(co);
}while( ic <= strlen(chaine)); // As long as ic is < than the amount tof caracter in chaine, and then leave the do loop
get_val[x]='\0'; // Close val with \0
//Serial.print(F("sr:")); Serial.println(get_val);
//return get_val;
} |
Partager