-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcode_parser.c
105 lines (99 loc) · 2.34 KB
/
gcode_parser.c
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <stdio.h>
#include <string.h>
static int contains(char* target, char* arr[], int size)
{
for(int i = 0; arr[i]!='\0';i++)
{
if(!strcmp(arr[i],target))
return 1;
}
return 0;
}
static char* cutter_pos[] = {"Operation,",
"Tool #,",
"X position,",
"Y Postion,",
"Z position,",
"Command Details",
"\n"
} ;
static char* output_heading[] = {
"Tool number,",
"Rapid (Z),",
"Rapid (X-Y),",
"Rapid Rate,",
"Tool Diameter,",
"cut speed,",
"# of Flutes,",
"Feed/Tooth,",
"Cut length,",
"Spdl acel/decel,",
"Spindle Speed,",
"Feed Rate,",
"Machine Idle,",
"Cut Time,",
"Tool Change Time,",
"Rapid Time,",
"Total Op time,"};
static char* output_units[] = {
"(Inches),",
"(inches),",
"(IPM),",
"(inches),",
"(feet/minute),",
"(ul),",
"(inches),",
"(inches - est),",
"(sec),",
"(RPM),",
"(IPM),",
"(sec),",
"(sec),",
"(sec),",
"(sec),",
"(seconds),"
};
static void setupOutput(char type, FILE *output){
switch(type){
case '0':
for(int i =0; i<7; i++){
printf("%s\n",cutter_pos[i]);
fputs(cutter_pos[i], output);
}
break;
case '1':
for(int i =0; i<17; i++){
printf("%s\n",output_heading[i]);
fputs(output_heading[i], output);
}
fputs("\n",output);
for(int i =0; i<17; i++){
printf("%s\n",output_units[i]);
fputs(output_units[i], output);
//output.write(output_heading[i]);
//output.write(",");
}
break;
default:
fputs("Make sure you specify a type or it won't work", output);
break;
}
}
int main(int argc, char* argv[]) {
FILE *gcode, *output;
printf("Hello World\n");
printf("Number of args: %d\n",argc);
printf("%s\n",argv[1]);
char* gcode_move_cmds[] = {"G00","G01","G02","G03"};
gcode=fopen(argv[1], "r");
output = fopen("output.csv", "w");
setupOutput(*argv[2],output);
char* line;
while(fgets(line,0xFFFF,gcode)!= NULL){
printf("%s\n",line);
}
// char* token = strtok()
printf("Made it here\n");
//output.write("\n");
return 0;
}