test.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 coordinates[10][2];
12
13
    int number_of_coordinates = -1;
14
15
    px=uart_string;
16
17
    memset(coordinates,0,sizeof(coordinates));
18
19
    while (*px)
20
    {
21
        switch (*px)
22
        {
23
            case 'G':
24
                number_of_coordinates++;
25
                break;
26
27
            case 'X':
28
                px++;
29
                coordinates[number_of_coordinates][0]=atof(px);
30
                break;
31
32
            case 'Y':
33
                px++;
34
                coordinates[number_of_coordinates][1]=atof(px);
35
                break;
36
37
            default:
38
                break;
39
        }
40
        px++;
41
    }
42
43
    for (number_of_coordinates=0;number_of_coordinates<10;number_of_coordinates++)
44
    {
45
        printf("%d\tx=%f\t\ty=%f\r\n",number_of_coordinates,coordinates[number_of_coordinates][0],coordinates[number_of_coordinates][1]);
46
    }
47
}