test2.c


1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <string.h>
4
#include <math.h>
5
6
char uart_string[]="G01 X69.204775 Y23.337389 Z-0.100000 G01 X80.964849 Y21.666507 Z-0.100000 G00 Z0.100000";
7
8
int main(void)
9
{
10
    char *px;
11
    float  coord[10][3];
12
13
    int number_of_coord = -1;
14
15
    px=uart_string;
16
17
    memset( coord,0,sizeof( coord));
18
19
    while (*px)
20
    {
21
        switch (*px)
22
        {
23
            case 'G':
24
                number_of_coord++;
25
                break;
26
27
            case 'X':
28
                px++;
29
                 coord[number_of_coord][0]=atof(px);
30
                break;
31
32
            case 'Y':
33
                px++;
34
                 coord[number_of_coord][1]=atof(px);
35
                break;
36
        
37
            case 'Z':
38
                px++;
39
                 coord[number_of_coord][2]=atof(px);
40
                break;
41
42
            default:
43
                break;
44
        }
45
        px++;
46
    }
47
48
    for (number_of_coord=0;number_of_coord<10;number_of_coord++)
49
    {
50
        printf("%d\tx=%f\t\ty=%f\t\tz=%f\r\n",number_of_coord, coord[number_of_coord][0], coord[number_of_coord][1], coord[number_of_coord][2]);
51
    }
52
}