forked from markwal/GPX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpx.h
370 lines (284 loc) · 9.73 KB
/
gpx.h
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
//
// gpx.c
//
// Created by WHPThomas <me(at)henri(dot)net> on 1/04/13.
//
// Copyright (c) 2013 WHPThomas, All rights reserved.
//
// gpx references ReplicatorG sources from /src/replicatorg/drivers
// which are part of the ReplicatorG project - http://www.replicat.org
// Copyright (c) 2008 Zach Smith
// and Makerbot4GSailfish.java Copyright (C) 2012 Jetty / Dan Newman
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#ifndef __gpx_h__
#define __gpx_h__
#ifdef __cplusplus
extern "C" {
#endif
#include <limits.h>
#include <stdio.h>
#define GPX_VERSION "2.0-alpha"
#define HOST_VERSION 50
#define END_OF_FILE 1
#define SUCCESS 0
#define ERROR -1
#define ESIOWRITE -2
#define ESIOREAD -3
#define ESIOFRAME -4
#define ESIOCRC -5
#define STREAM_VERSION_HIGH 0
#define STREAM_VERSION_LOW 0
#define COMMAND_QUE_MAX 20
// Nonzero to 'simulate' RPM using 5D, zero to disable
#define ENABLE_SIMULATED_RPM 1
// Nonzero to trigger tool changes on wait, zero to disable
#define ENABLE_TOOL_CHANGE_ON_WAIT 0
// BOUNDS CHECKING VARIABLES
#define NOZZLE_MAX 280
#define NOZZLE_TIME 0.6
#define HBP_MAX 120
#define HBP_TIME 6
#define AMBIENT_TEMP 24
#define ACCELERATION_TIME 1.15
#define MAX_TIMEOUT 0xFFFF
#ifdef _WIN32
# define PATH_DELIM '\\'
# define EOL "\r\n"
#else
# define PATH_DELIM '/'
# define EOL "\n"
#endif
// x3g axes bitfields
#define X_IS_SET 0x1
#define Y_IS_SET 0x2
#define Z_IS_SET 0x4
#define A_IS_SET 0x8
#define B_IS_SET 0x10
#define XYZ_BIT_MASK 0x7
#define AXES_BIT_MASK 0x1F
#define E_IS_SET 0x20
#define F_IS_SET 0x40
#define P_IS_SET 0x100
#define R_IS_SET 0x400
#define S_IS_SET 0x800
// commands
#define G_IS_SET 0x1000
#define M_IS_SET 0x2000
#define T_IS_SET 0x4000
#define COMMENT_IS_SET 0x8000
typedef struct tPoint2d {
double a;
double b;
} Point2d, *Ptr2d;
typedef struct tPoint3d {
double x;
double y;
double z;
} Point3d, *Ptr3d;
typedef struct tPoint5d {
double x;
double y;
double z;
double a;
double b;
} Point5d, *Ptr5d;
typedef struct tCommand {
// parameters
double x;
double y;
double z;
double a;
double b;
double e;
double f;
double p;
double r;
double s;
// commands
unsigned g;
unsigned m;
unsigned t;
// comments
char *comment;
// state
int flag;
} Command, *PtrCommand;
// endstop flags
#define ENDSTOP_IS_MIN 0
#define ENDSTOP_IS_MAX 1
// tool id
#define MAX_TOOL_ID 1
#define BUILD_PLATE_ID 2
// state
#define READY_STATE 0
#define RUNNING_STATE 1
#define ENDED_STATE 2
typedef struct tAxis {
double max_feedrate;
double home_feedrate;
double steps_per_mm;
unsigned endstop;
} Axis;
typedef struct tExtruder {
double max_feedrate;
double steps_per_mm;
double motor_steps;
unsigned has_heated_build_platform;
} Extruder;
#define MACHINE_TYPE_REPLICATOR_1 7
#define MACHINE_TYPE_REPLICATOR_2 9
typedef struct tMachine {
Axis x;
Axis y;
Axis z;
Extruder a;
Extruder b;
double nominal_filament_diameter;
double nominal_packing_density;
double nozzle_diameter;
unsigned extruder_count;
unsigned timeout;
unsigned type;
} Machine;
typedef struct tTool {
unsigned motor_enabled;
#if ENABLE_SIMULATED_RPM
unsigned rpm;
#endif
unsigned nozzle_temperature;
unsigned build_platform_temperature;
} Tool;
typedef struct tOverride {
double actual_filament_diameter;
double filament_scale;
double packing_density;
unsigned standby_temperature;
unsigned active_temperature;
unsigned build_platform_temperature;
} Override;
typedef struct tFilament {
char *colour;
double diameter;
unsigned temperature;
unsigned LED;
} Filament;
#define FILAMENT_MAX 32
typedef struct tCommandAt {
double z;
unsigned filament_index;
unsigned nozzle_temperature;
unsigned build_platform_temperature;
} CommandAt;
#define COMMAND_AT_MAX 128
#define BUFFER_MAX 1023
// GPX CONTEXT
typedef struct tGpx Gpx;
struct tGpx {
// IO
struct {
char in[BUFFER_MAX + 1];
char out[BUFFER_MAX + 1];
char *ptr;
} buffer;
// DATA
Machine machine; // machine definition
Command command; // the gcode command line
struct {
Point5d position; // the target position the extruder will move to (including G10 offsets)
int extruder; // the target extruder (on the virtual tool carosel)
} target;
struct {
Point5d position; // the current position of the extruder in 5D space
double feedrate; // the current feed rate
int extruder; // the currently selected extruder being used by the bot
int offset; // current G10 offset
unsigned percent; // current percent progress
} current;
struct {
unsigned int positionKnown; // axis bitfields for known positions of the extruder
unsigned int mask;
} axis;
Point2d excess; // the accumulated rounding error in mm to step conversion
Point3d offset[7]; // G10 offsets
struct {
Point3d offset; // command line offset
double scale; // command line scale
} user;
Tool tool[2]; // tool state
Override override[2]; // gcode override
Filament filament[FILAMENT_MAX];
int filamentLength;
CommandAt commandAt[COMMAND_AT_MAX];
int commandAtIndex;
int commandAtLength;
double commandAtZ;
// SETTINGS
char *sdCardPath;
char *buildName;
struct {
unsigned relativeCoordinates:1; // signals relitive or absolute coordinates
unsigned extruderIsRelative:1; // signals relitive or absolute coordinates for extruder
unsigned reprapFlavor:1; // reprap gcode flavor
unsigned dittoPrinting:1; // enable ditto printing
unsigned buildProgress:1; // override build percent
unsigned verboseMode:1; // verbose output
unsigned logMessages:1; // enable stderr message logging
unsigned rewrite5D:1; // calculate 5D E values rather than scaling them
// STATE
unsigned programState:8; // gcode program state used to trigger start and end code sequences
unsigned doPauseAtZPos:8; // signals that a pause is ready to be
unsigned pausePending:1; // signals a pause is pending before the macro script has started
unsigned macrosEnabled:1; // M73 P1 or ;@body encountered signalling body start (so we don't pause during homing)
unsigned loadMacros:1; // used by the multi-pass converter to maintain state
unsigned runMacros:1; // used by the multi-pass converter to maintain state
unsigned framingEnabled:1; // enable framming of packets with header and crc
} flag;
double layerHeight; // the current layer height
unsigned lineNumber; // the current line number
int longestDDA;
// STATISTICS
struct {
double a;
double b;
double time;
unsigned long bytes;
} accumulated;
struct {
double length;
double time;
unsigned long bytes;
} total;
// CALLBACK
int (*callbackHandler)(Gpx *gpx, void *callbackData, char *buffer, size_t length);
void *callbackData;
// LOGGING
FILE *log;
};
void gpx_initialize(Gpx *gpx, int firstTime);
int gpx_set_machine(Gpx *gpx, char *machine);
int gpx_set_property(Gpx *gpx, const char* section, const char* property, char* value);
int gpx_load_config(Gpx *gpx, const char *filename);
void gpx_register_callback(Gpx *gpx, int (*callbackHandler)(Gpx *gpx, void *callbackData, char *buffer, size_t length), void *callbackData);
void gpx_start_convert(Gpx *gpx, char *buildName);
int gpx_convert_line(Gpx *gpx, char *gcode_line);
int gpx_convert(Gpx *gpx, FILE *file_in, FILE *file_out, FILE *file_out2);
int gpx_convert_and_send(Gpx *gpx, FILE *file_in, int sio_port);
void gpx_end_convert(Gpx *gpx);
int eeprom_load_config(Gpx *gpx, const char *filename);
#ifdef __cplusplus
}
#endif
#endif /* __gpx_h__ */