mirror of https://github.com/vitalif/GPX
GPX 2.0-alpha
The GPX has been refactored to support re-entrant serial communication using a pacet driver style callback interface. At this point the existing code base has been adapted, however the serial interface driver is still to be written.master
parent
4d4438667d
commit
687ea2bb64
4
Makefile
4
Makefile
|
@ -4,7 +4,7 @@ CC_FLAGS = -w
|
|||
L_FLAGS = -lm
|
||||
|
||||
# File names
|
||||
VERSION = 1.5
|
||||
VERSION = 2.0
|
||||
PLATFORM=osx
|
||||
ARCHIVE = gpx-$(PLATFORM)-$(VERSION)
|
||||
PREFIX = /usr/local
|
||||
|
@ -48,7 +48,7 @@ release: gpx
|
|||
rm -f $(ARCHIVE).zip
|
||||
rm -f $(ARCHIVE).dmg
|
||||
mkdir $(ARCHIVE)
|
||||
cp gpx *.ini *.gcode *.py $(ARCHIVE)
|
||||
cp -r gpx examples scripts *.ini $(ARCHIVE)
|
||||
tar cf - $(ARCHIVE) | gzip -9c > $(ARCHIVE).tar.gz
|
||||
zip -r $(ARCHIVE).zip $(ARCHIVE)
|
||||
test -f /usr/bin/hdiutil && hdiutil create -format UDZO -srcfolder $(ARCHIVE) $(ARCHIVE).dmg
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
GPX was created by Dr. Henry Thomas (aka Wingcommander) in April 2013
|
||||
|
||||
GPX is a post processing utility for converting gcode output from 3D slicing software like
|
||||
Cura, KISSlicer, S3DCreator and Slic3r to x3g files for standalone 3D printing on Makerbot
|
||||
Cupcake, ThingOMatic, and Replicator 1/2/2x printers - with support for both stock and
|
||||
sailfish firmwares. My hope is that is little utility will open up Makerbot 3D printers to
|
||||
a range of new and exciting sources and utilities for 3D printing input.
|
||||
|
||||
Usage:
|
||||
|
||||
gpx [-dgiprsvw] [-b B] [-c C] [-f F] [-m M] [-x X] [-y Y] [-z Z] IN [OUT]
|
||||
|
||||
Options:
|
||||
|
||||
-d simulated ditto printing
|
||||
-g Makerbot/ReplicatorG GCODE flavor
|
||||
-i enable stdin and stdout support for command line pipes
|
||||
-p override build percentage
|
||||
-r Reprap GCODE flavor
|
||||
-s enable USB serial I/O and send x3G output to 3D printer
|
||||
-v verose mode
|
||||
-w rewrite 5d extrusion values
|
||||
|
||||
B is baudrate for serial I/O (default is 115200)
|
||||
|
||||
C is the filename of a custom machine definition (ini)
|
||||
|
||||
F is the actual filament diameter in the printer
|
||||
|
||||
M is the predefined machine type:
|
||||
|
||||
c3 = Cupcake Gen3 XYZ, Mk5/6 + Gen4 Extruder
|
||||
c4 = Cupcake Gen4 XYZ, Mk5/6 + Gen4 Extruder
|
||||
cp4 = Cupcake Pololu XYZ, Mk5/6 + Gen4 Extruder
|
||||
cpp = Cupcake Pololu XYZ, Mk5/6 + Pololu Extruder
|
||||
t6 = TOM Mk6 - single extruder
|
||||
t7 = TOM Mk7 - single extruder
|
||||
t7d = TOM Mk7 - dual extruder
|
||||
r1 = Replicator 1 - single extruder
|
||||
r1d = Replicator 1 - dual extruder
|
||||
r2 = Replicator 2 (default)
|
||||
r2h = Replicator 2 with HBP
|
||||
r2x = Replicator 2X
|
||||
|
||||
X,Y & Z are the coordinate system offsets for the conversion:
|
||||
|
||||
X = the x axis offset
|
||||
Y = the y axis offset
|
||||
Z = the z axis offset
|
||||
|
||||
IN is the name of the sliced gcode input filename
|
||||
|
||||
OUT is the name of the x3g output filename or the serial I/O port
|
||||
|
||||
Examples:
|
||||
|
||||
gpx -p -m r2 my-sliced-model.gcode
|
||||
gpx -c custom-tom.ini example.gcode /volumes/things/example.x3g
|
||||
gpx -x 3 -y -3 offset-model.gcode
|
||||
gpx -m c4 -s sio-example.gcode /dev/tty.usbmodem
|
||||
|
6
getopt.h
6
getopt.h
|
@ -17,8 +17,8 @@ Added documentation to this header, so know what everything does.
|
|||
|
||||
*/
|
||||
|
||||
#ifndef getopt_h
|
||||
#define getopt_h
|
||||
#ifndef __getopt_h__
|
||||
#define __getopt_h__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -71,4 +71,4 @@ int getopt(int argc, char **argv, char *opts);
|
|||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif /* __getopt_h__ */
|
||||
|
|
|
@ -0,0 +1,470 @@
|
|||
//
|
||||
// gpx-main.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
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
# include "getopt.h"
|
||||
#endif
|
||||
|
||||
#include "gpx.h"
|
||||
|
||||
// Global variables
|
||||
|
||||
static Gpx gpx;
|
||||
|
||||
static FILE *file_in = NULL;
|
||||
static FILE *file_out = NULL;
|
||||
static FILE *file_out2 = NULL;
|
||||
static int sio_port = -1;
|
||||
|
||||
// cleanup code in case we encounter an error that causes the program to exit
|
||||
|
||||
static void exit_handler(void)
|
||||
{
|
||||
// close open files
|
||||
if(file_in != stdin) {
|
||||
fclose(file_in);
|
||||
if(file_out != stdout) {
|
||||
if(ferror(file_out)) {
|
||||
perror("Error writing to output file");
|
||||
}
|
||||
fclose(file_out);
|
||||
}
|
||||
if(file_out2) {
|
||||
fclose(file_out2);
|
||||
}
|
||||
}
|
||||
if(sio_port > 2) {
|
||||
close(sio_port);
|
||||
}
|
||||
}
|
||||
|
||||
// display usage and exit
|
||||
|
||||
static void usage()
|
||||
{
|
||||
fputs("GPX " GPX_VERSION " Copyright (c) 2013 WHPThomas, All rights reserved." EOL, stderr);
|
||||
|
||||
fputs(EOL "This program is free software; you can redistribute it and/or modify" EOL, stderr);
|
||||
fputs("it under the terms of the GNU General Public License as published by" EOL, stderr);
|
||||
fputs("the Free Software Foundation; either version 2 of the License, or" EOL, stderr);
|
||||
fputs("(at your option) any later version." EOL, stderr);
|
||||
|
||||
fputs(EOL "This program is distributed in the hope that it will be useful," EOL, stderr);
|
||||
fputs("but WITHOUT ANY WARRANTY; without even the implied warranty of" EOL, stderr);
|
||||
fputs("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" EOL, stderr);
|
||||
fputs("GNU General Public License for more details." EOL, stderr);
|
||||
|
||||
fputs(EOL "Usage: gpx [-dgiprsvw] [-b B] [-c C] [-f F] [-m M] [-x X] [-y Y] [-z Z] IN [OUT]" EOL, stderr);
|
||||
fputs(EOL "Options:" EOL, stderr);
|
||||
fputs("\t-d\tsimulated ditto printing" EOL, stderr);
|
||||
fputs("\t-g\tMakerbot/ReplicatorG GCODE flavor" EOL, stderr);
|
||||
fputs("\t-i\tenable stdin and stdout support for command line pipes" EOL, stderr);
|
||||
fputs("\t-p\toverride build percentage" EOL, stderr);
|
||||
fputs("\t-r\tReprap GCODE flavor" EOL, stderr);
|
||||
fputs("\t-s\tenable USB serial I/O and send x3G output to 3D printer" EOL, stderr);
|
||||
fputs("\t-v\tverose mode" EOL, stderr);
|
||||
fputs("\t-w\trewrite 5d extrusion values" EOL, stderr);
|
||||
fputs(EOL "B is baudrate for serial I/O (default is 115200)" EOL, stderr);
|
||||
fputs("C is the filename of a custom machine definition (ini)" EOL, stderr);
|
||||
fputs("F is the actual filament diameter in the printer" EOL, stderr);
|
||||
fputs(EOL "M is the predefined machine type:" EOL, stderr);
|
||||
fputs("\tc3 = Cupcake Gen3 XYZ, Mk5/6 + Gen4 Extruder" EOL, stderr);
|
||||
fputs("\tc4 = Cupcake Gen4 XYZ, Mk5/6 + Gen4 Extruder" EOL, stderr);
|
||||
fputs("\tcp4 = Cupcake Pololu XYZ, Mk5/6 + Gen4 Extruder" EOL, stderr);
|
||||
fputs("\tcpp = Cupcake Pololu XYZ, Mk5/6 + Pololu Extruder" EOL, stderr);
|
||||
fputs("\tt6 = TOM Mk6 - single extruder" EOL, stderr);
|
||||
fputs("\tt7 = TOM Mk7 - single extruder" EOL, stderr);
|
||||
fputs("\tt7d = TOM Mk7 - dual extruder" EOL, stderr);
|
||||
fputs("\tr1 = Replicator 1 - single extruder" EOL, stderr);
|
||||
fputs("\tr1d = Replicator 1 - dual extruder" EOL, stderr);
|
||||
fputs("\tr2 = Replicator 2 (default)" EOL, stderr);
|
||||
fputs("\tr2h = Replicator 2 with HBP" EOL, stderr);
|
||||
fputs("\tr2x = Replicator 2X" EOL, stderr);
|
||||
fputs(EOL "X,Y & Z are the coordinate system offsets for the conversion:" EOL, stderr);
|
||||
fputs("\tX = the x axis offset" EOL, stderr);
|
||||
fputs("\tY = the y axis offset" EOL, stderr);
|
||||
fputs("\tZ = the z axis offset" EOL, stderr);
|
||||
fputs(EOL "IN is the name of the sliced gcode input filename" EOL, stderr);
|
||||
fputs("OUT is the name of the x3g output filename or the serial I/O port" EOL, stderr);
|
||||
fputs(EOL "Examples:" EOL, stderr);
|
||||
fputs("\tgpx -p -m r2 my-sliced-model.gcode" EOL, stderr);
|
||||
fputs("\tgpx -c custom-tom.ini example.gcode /volumes/things/example.x3g" EOL, stderr);
|
||||
fputs("\tgpx -x 3 -y -3 offset-model.gcode" EOL, stderr);
|
||||
fputs("\tgpx -m c4 -s sio-example.gcode /dev/tty.usbmodem" EOL EOL, stderr);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// GPX program entry point
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
int c, i, rval;
|
||||
int standard_io = 0;
|
||||
char *config = NULL;
|
||||
double filament_diameter = 0;
|
||||
char *buildname = "GPX " GPX_VERSION;
|
||||
char *filename;
|
||||
struct termios tp;
|
||||
speed_t baud_rate = B115200;
|
||||
|
||||
// default to standard I/O
|
||||
file_in = stdin;
|
||||
file_out = stdout;
|
||||
|
||||
// register cleanup function
|
||||
atexit(exit_handler);
|
||||
|
||||
gpx_initialize(&gpx, 1);
|
||||
|
||||
// READ GPX.INI
|
||||
|
||||
// if present, read the gpx.ini file from the program directory
|
||||
{
|
||||
char *appname = argv[0];
|
||||
// check for .exe extension
|
||||
char *dot = strrchr(appname, '.');
|
||||
if(dot) {
|
||||
long l = dot - appname;
|
||||
memcpy(gpx.buffer.out, appname, l);
|
||||
appname = gpx.buffer.out + l;
|
||||
}
|
||||
// or just append .ini if no extension is present
|
||||
else {
|
||||
size_t sl = strlen(appname);
|
||||
memcpy(gpx.buffer.out, appname, sl);
|
||||
appname = gpx.buffer.out + sl;
|
||||
}
|
||||
*appname++ = '.';
|
||||
*appname++ = 'i';
|
||||
*appname++ = 'n';
|
||||
*appname++ = 'i';
|
||||
*appname++ = '\0';
|
||||
appname = gpx.buffer.out;
|
||||
i = gpx_read_config(&gpx, appname);
|
||||
if(i == 0) {
|
||||
if(gpx.flag.verboseMode) fprintf(stderr, "Loaded config: %s" EOL, appname);
|
||||
}
|
||||
else if (i > 0) {
|
||||
fprintf(stderr, "(line %u) Configuration syntax error in gpx.ini: unrecognised paremeters" EOL, i);
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
// READ COMMAND LINE
|
||||
|
||||
// get the command line options
|
||||
while ((c = getopt(argc, argv, "b:c:dgf:im:prsvwx:y:z:?")) != -1) {
|
||||
switch (c) {
|
||||
case 'b':
|
||||
i = atoi(optarg);
|
||||
switch(i) {
|
||||
case 4800:
|
||||
baud_rate=B4800;
|
||||
break;
|
||||
case 9600:
|
||||
baud_rate=B9600;
|
||||
break;
|
||||
#ifdef B14400
|
||||
case 14400:
|
||||
baud_rate=B14400;
|
||||
break;
|
||||
#endif
|
||||
case 19200:
|
||||
baud_rate=B19200;
|
||||
break;
|
||||
#ifdef B28800
|
||||
case 28800:
|
||||
baud_rate=B28800;
|
||||
break;
|
||||
#endif
|
||||
case 38400:
|
||||
baud_rate=B38400;
|
||||
break;
|
||||
case 57600:
|
||||
baud_rate=B57600;
|
||||
break;
|
||||
case 115200:
|
||||
baud_rate=B115200;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Command line error: unsupported baud rate '%s'" EOL, optarg);
|
||||
usage();
|
||||
}
|
||||
if(gpx.flag.verboseMode) fprintf(stderr, "Setting baud rate to: %i bps" EOL, i);
|
||||
break;
|
||||
case 'c':
|
||||
config = optarg;
|
||||
break;
|
||||
case 'd':
|
||||
gpx.flag.dittoPrinting = 1;
|
||||
break;
|
||||
case 'g':
|
||||
gpx.flag.reprapFlavor = 0;
|
||||
break;
|
||||
case 'f':
|
||||
filament_diameter = strtod(optarg, NULL);
|
||||
if(filament_diameter > 0.0001) {
|
||||
gpx.override[0].actual_filament_diameter = filament_diameter;
|
||||
gpx.override[1].actual_filament_diameter = filament_diameter;
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
standard_io = 1;
|
||||
break;
|
||||
case 'm':
|
||||
if(gpx_set_property(&gpx, "printer", "machine_type", optarg)) {
|
||||
usage();
|
||||
}
|
||||
break;
|
||||
case 'p':
|
||||
gpx.flag.buildProgress = 1;
|
||||
break;
|
||||
case 'r':
|
||||
gpx.flag.reprapFlavor = 1;
|
||||
break;
|
||||
case 's':
|
||||
gpx.flag.serialIO = 1;
|
||||
gpx.flag.framingEnabled = 1;
|
||||
break;
|
||||
case 'v':
|
||||
gpx.flag.verboseMode = 1;
|
||||
break;
|
||||
case 'w':
|
||||
gpx.flag.rewrite5D = 1;
|
||||
break;
|
||||
case 'x':
|
||||
gpx.userOffset.x = strtod(optarg, NULL);
|
||||
break;
|
||||
case 'y':
|
||||
gpx.userOffset.y = strtod(optarg, NULL);
|
||||
break;
|
||||
case 'z':
|
||||
gpx.userOffset.z = strtod(optarg, NULL);
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
// READ CONFIGURATION
|
||||
|
||||
if(config) {
|
||||
if(gpx.flag.verboseMode) fprintf(stderr, "Reading custom config: %s" EOL, config);
|
||||
i = gpx_read_config(&gpx, config);
|
||||
if (i < 0) {
|
||||
fprintf(stderr, "Command line error: cannot load configuration file '%s'" EOL, config);
|
||||
usage();
|
||||
}
|
||||
else if (i > 0) {
|
||||
fprintf(stderr, "(line %u) Configuration syntax error in %s: unrecognised paremeters" EOL, i, config);
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
if(baud_rate == B57600 && gpx.machine.type >= MACHINE_TYPE_REPLICATOR_1) {
|
||||
if(gpx.flag.verboseMode) fputs("WARNING: a 57600 bps baud rate will cause problems with Repicator 2/2X Mightyboards" EOL, stderr);
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
// OPEN FILES AND PORTS FOR INPUT AND OUTPUT
|
||||
|
||||
// open the input filename if one is provided
|
||||
if(argc > 0) {
|
||||
filename = argv[0];
|
||||
if(gpx.flag.verboseMode) fprintf(stderr, "Reading from: %s" EOL, filename);
|
||||
if((file_in = fopen(filename, "rw")) == NULL) {
|
||||
perror("Error opening input");
|
||||
exit(1);
|
||||
}
|
||||
// assign build name
|
||||
buildname = strrchr(filename, PATH_DELIM);
|
||||
if(buildname) {
|
||||
buildname++;
|
||||
}
|
||||
else {
|
||||
buildname = filename;
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
// use the output filename if one is provided
|
||||
if(argc > 0) {
|
||||
filename = argv[0];
|
||||
}
|
||||
else {
|
||||
if(gpx.flag.serialIO) {
|
||||
fputs("Command line error: port required for serial I/O" EOL, stderr);
|
||||
usage();
|
||||
}
|
||||
// or use the input filename with a .x3g extension
|
||||
char *dot = strrchr(filename, '.');
|
||||
if(dot) {
|
||||
long l = dot - filename;
|
||||
memcpy(gpx.buffer.out, filename, l);
|
||||
filename = gpx.buffer.out + l;
|
||||
}
|
||||
// or just append one if no .gcode extension is present
|
||||
else {
|
||||
size_t sl = strlen(filename);
|
||||
memcpy(gpx.buffer.out, filename, sl);
|
||||
filename = gpx.buffer.out + sl;
|
||||
}
|
||||
*filename++ = '.';
|
||||
*filename++ = 'x';
|
||||
*filename++ = '3';
|
||||
*filename++ = 'g';
|
||||
*filename++ = '\0';
|
||||
filename = gpx.buffer.out;
|
||||
}
|
||||
if(gpx.flag.serialIO) {
|
||||
// open and configure the serial port
|
||||
if((sio_port = open(filename, O_RDWR | O_NOCTTY | O_NONBLOCK)) < 0) {
|
||||
perror("Error opening port");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if(fcntl(sio_port, F_SETFL, O_RDWR) < 0) {
|
||||
perror("Setting port descriptor flags");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if(tcgetattr(sio_port, &tp) < 0) {
|
||||
perror("Error getting port attributes");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
cfmakeraw(&tp);
|
||||
|
||||
/*
|
||||
// 8N1
|
||||
tp.c_cflag &= ~PARENB;
|
||||
tp.c_cflag &= ~CSTOPB;
|
||||
tp.c_cflag &= ~CSIZE;
|
||||
tp.c_cflag |= CS8;
|
||||
|
||||
// no flow control
|
||||
tp.c_cflag &= ~CRTSCTS;
|
||||
|
||||
// disable hang-up-on-close to avoid reset
|
||||
//tp.c_cflag &= ~HUPCL;
|
||||
|
||||
// turn on READ & ignore ctrl lines
|
||||
tp.c_cflag |= CREAD | CLOCAL;
|
||||
|
||||
// turn off s/w flow ctrl
|
||||
tp.c_cflag &= ~(IXON | IXOFF | IXANY);
|
||||
|
||||
// make raw
|
||||
tp.c_cflag &= ~(ICANON | ECHO | ECHOE | ISIG);
|
||||
tp.c_cflag &= ~OPOST;
|
||||
|
||||
// see: http://unixwiz.net/techtips/termios-vmin-vtime.html
|
||||
tp.c_cc[VMIN] = 0;
|
||||
tp.c_cc[VTIME] = 0;
|
||||
*/
|
||||
|
||||
cfsetspeed(&tp, baud_rate);
|
||||
// cfsetispeed(&tp, baud_rate);
|
||||
// cfsetospeed(&tp, baud_rate);
|
||||
|
||||
if(tcsetattr(sio_port, TCSANOW, &tp) < 0) {
|
||||
perror("Error setting port attributes");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
sleep(2);
|
||||
if(tcflush(sio_port, TCIOFLUSH) < 0) {
|
||||
perror("Error flushing port");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if(gpx.flag.verboseMode) fprintf(stderr, "Communicating via: %s" EOL, filename);
|
||||
}
|
||||
else {
|
||||
if((file_out = fopen(filename, "wb")) == NULL) {
|
||||
perror("Error creating output");
|
||||
exit(-1);
|
||||
}
|
||||
if(gpx.flag.verboseMode) fprintf(stderr, "Writing to: %s" EOL, filename);
|
||||
// write a second copy to the SD Card
|
||||
if(gpx.sdCardPath) {
|
||||
long sl = strlen(gpx.sdCardPath);
|
||||
if(gpx.sdCardPath[sl - 1] == PATH_DELIM) {
|
||||
gpx.sdCardPath[--sl] = 0;
|
||||
}
|
||||
char *delim = strrchr(filename, PATH_DELIM);
|
||||
if(delim) {
|
||||
memcpy(gpx.buffer.out, gpx.sdCardPath, sl);
|
||||
long l = strlen(delim);
|
||||
memcpy(gpx.buffer.out + sl, delim, l);
|
||||
gpx.buffer.out[sl + l] = 0;
|
||||
}
|
||||
else {
|
||||
memcpy(gpx.buffer.out, gpx.sdCardPath, sl);
|
||||
gpx.buffer.out[sl++] = PATH_DELIM;
|
||||
long l = strlen(filename);
|
||||
memcpy(gpx.buffer.out + sl, filename, l);
|
||||
gpx.buffer.out[sl + l] = 0;
|
||||
}
|
||||
file_out2 = fopen(gpx.buffer.out, "wb");
|
||||
if(file_out2 && gpx.flag.verboseMode) fprintf(stderr, "Writing to: %s" EOL, gpx.buffer.out);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(!standard_io) {
|
||||
fputs("Command line error: provide an input file or enable standard I/O" EOL, stderr);
|
||||
usage();
|
||||
}
|
||||
|
||||
// at this point we have read the command line, set the machine definition
|
||||
// and both the input and output files or ports are open, so its time to parse
|
||||
// the gcode input and convert it to x3g output.
|
||||
|
||||
// READ INPUT AND CONVERT TO OUTPUT
|
||||
|
||||
gpx_start_build(&gpx, buildname);
|
||||
|
||||
if(gpx.flag.serialIO) {
|
||||
rval = gpx_send_file(&gpx, file_in, sio_port);
|
||||
}
|
||||
else {
|
||||
rval = gpx_convert_file(&gpx, file_in, file_out, file_out2);
|
||||
}
|
||||
|
||||
gpx_end_build(&gpx);
|
||||
|
||||
exit(rval);
|
||||
}
|
149
gpx.h
149
gpx.h
|
@ -24,19 +24,31 @@
|
|||
// 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
|
||||
#ifndef __gpx_h__
|
||||
#define __gpx_h__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define GPX_VERSION "1.5"
|
||||
#define GPX_VERSION "2.0-alpha"
|
||||
|
||||
#define COMMAND_QUE_MAX 15
|
||||
#define STREAM_VERSION_HIGH 0
|
||||
#define STREAM_VERSION_LOW 0
|
||||
|
||||
/* Nonzero to 'simulate' RPM using 5D, zero to disable */
|
||||
#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 TEMPERATURE_MAX 280
|
||||
|
@ -152,6 +164,10 @@ typedef struct tExtruder {
|
|||
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;
|
||||
|
@ -163,7 +179,7 @@ typedef struct tMachine {
|
|||
double nozzle_diameter;
|
||||
unsigned extruder_count;
|
||||
unsigned timeout;
|
||||
unsigned ordinal;
|
||||
unsigned type;
|
||||
} Machine;
|
||||
|
||||
typedef struct tTool {
|
||||
|
@ -202,6 +218,125 @@ typedef struct tCommandAt {
|
|||
|
||||
#define COMMAND_AT_MAX 128
|
||||
|
||||
#define BUFFER_MAX 1024
|
||||
#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
|
||||
int positionKnown; // is the current extruder position known
|
||||
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;
|
||||
|
||||
Point2d excess; // the accumulated rounding error in mm to step conversion
|
||||
Point3d offset[7]; // G10 offsets
|
||||
Point3d userOffset; // command line offset
|
||||
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 rewrite5D:1; // calculate 5D E values rather than scaling them
|
||||
unsigned serialIO:1; // output to serial io port
|
||||
|
||||
// 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
|
||||
unsigned framingEnabled:1; // enable framming of packets with header and crc
|
||||
unsigned showErrorMessages:1;
|
||||
} 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);
|
||||
void *callbackData;
|
||||
|
||||
};
|
||||
|
||||
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_read_config(Gpx *gpx, const char *filename);
|
||||
|
||||
void gpx_register_callback(Gpx *gpx, int (*callbackHandler)(Gpx *gpx, void *callbackData), void *callbackData);
|
||||
|
||||
void gpx_start_build(Gpx *gpx, char *buildName);
|
||||
void gpx_end_build(Gpx *gpx);
|
||||
|
||||
int gpx_convert_line(Gpx *gpx, char *gcode_line);
|
||||
int gpx_convert_file(Gpx *gpx, FILE *file_in, FILE *file_out, FILE *file_out2);
|
||||
int gpx_send_file(Gpx *gpx, FILE *file_in, int sio_port);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __gpx_h__ */
|
||||
|
|
174
ini.c
174
ini.c
|
@ -1,174 +0,0 @@
|
|||
/* inih -- simple .INI file parser
|
||||
|
||||
inih is released under the New BSD license (see LICENSE.txt). Go to the project
|
||||
home page for more info:
|
||||
|
||||
http://code.google.com/p/inih/
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ini.h"
|
||||
|
||||
#if !INI_USE_STACK
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#define MAX_SECTION 50
|
||||
#define MAX_NAME 50
|
||||
|
||||
/* Strip whitespace chars off end of given string, in place. Return s. */
|
||||
static char* rstrip(char* s)
|
||||
{
|
||||
char* p = s + strlen(s);
|
||||
while (p > s && isspace((unsigned char)(*--p)))
|
||||
*p = '\0';
|
||||
return s;
|
||||
}
|
||||
|
||||
/* Return pointer to first non-whitespace char in given string. */
|
||||
static char* lskip(const char* s)
|
||||
{
|
||||
while (*s && isspace((unsigned char)(*s)))
|
||||
s++;
|
||||
return (char*)s;
|
||||
}
|
||||
|
||||
/* Return pointer to first char c or ';' comment in given string, or pointer to
|
||||
null at end of string if neither found. ';' must be prefixed by a whitespace
|
||||
character to register as a comment. */
|
||||
static char* find_char_or_comment(const char* s, char c)
|
||||
{
|
||||
int was_whitespace = 0;
|
||||
while (*s && *s != c && !(was_whitespace && *s == ';')) {
|
||||
was_whitespace = isspace((unsigned char)(*s));
|
||||
s++;
|
||||
}
|
||||
return (char*)s;
|
||||
}
|
||||
|
||||
/* Version of strncpy that ensures dest (size bytes) is null-terminated. */
|
||||
static char* strncpy0(char* dest, const char* src, size_t size)
|
||||
{
|
||||
strncpy(dest, src, size);
|
||||
dest[size - 1] = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
/* See documentation in header file. */
|
||||
int ini_parse_file(FILE* file,
|
||||
int (*handler)(unsigned, const char*, const char*,
|
||||
char*))
|
||||
{
|
||||
/* Uses a fair bit of stack (use heap instead if you need to) */
|
||||
#if INI_USE_STACK
|
||||
char line[INI_MAX_LINE];
|
||||
#else
|
||||
char* line;
|
||||
#endif
|
||||
char section[MAX_SECTION] = "";
|
||||
char prev_name[MAX_NAME] = "";
|
||||
|
||||
char* start;
|
||||
char* end;
|
||||
char* name;
|
||||
char* value;
|
||||
int lineno = 0;
|
||||
int error = 0;
|
||||
|
||||
#if !INI_USE_STACK
|
||||
line = (char*)malloc(INI_MAX_LINE);
|
||||
if (!line) {
|
||||
return -2;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Scan through file line by line */
|
||||
while (fgets(line, INI_MAX_LINE, file) != NULL) {
|
||||
lineno++;
|
||||
|
||||
start = line;
|
||||
#if INI_ALLOW_BOM
|
||||
if (lineno == 1 && (unsigned char)start[0] == 0xEF &&
|
||||
(unsigned char)start[1] == 0xBB &&
|
||||
(unsigned char)start[2] == 0xBF) {
|
||||
start += 3;
|
||||
}
|
||||
#endif
|
||||
start = lskip(rstrip(start));
|
||||
|
||||
if (*start == ';' || *start == '#') {
|
||||
/* Per Python ConfigParser, allow '#' comments at start of line */
|
||||
}
|
||||
#if INI_ALLOW_MULTILINE
|
||||
else if (*prev_name && *start && start > line) {
|
||||
/* Non-black line with leading whitespace, treat as continuation
|
||||
of previous name's value (as per Python ConfigParser). */
|
||||
if (!handler(lineno, section, prev_name, start) && !error)
|
||||
error = lineno;
|
||||
}
|
||||
#endif
|
||||
else if (*start == '[') {
|
||||
/* A "[section]" line */
|
||||
end = find_char_or_comment(start + 1, ']');
|
||||
if (*end == ']') {
|
||||
*end = '\0';
|
||||
strncpy0(section, start + 1, sizeof(section));
|
||||
*prev_name = '\0';
|
||||
}
|
||||
else if (!error) {
|
||||
/* No ']' found on section line */
|
||||
error = lineno;
|
||||
}
|
||||
}
|
||||
else if (*start && *start != ';') {
|
||||
/* Not a comment, must be a name[=:]value pair */
|
||||
end = find_char_or_comment(start, '=');
|
||||
if (*end != '=') {
|
||||
end = find_char_or_comment(start, ':');
|
||||
}
|
||||
if (*end == '=' || *end == ':') {
|
||||
*end = '\0';
|
||||
name = rstrip(start);
|
||||
value = lskip(end + 1);
|
||||
end = find_char_or_comment(value, '\0');
|
||||
if (*end == ';')
|
||||
*end = '\0';
|
||||
rstrip(value);
|
||||
|
||||
/* Valid name[=:]value pair found, call handler */
|
||||
strncpy0(prev_name, name, sizeof(prev_name));
|
||||
if (!handler(lineno, section, name, value) && !error)
|
||||
error = lineno;
|
||||
}
|
||||
else if (!error) {
|
||||
/* No '=' or ':' found on name[=:]value line */
|
||||
error = lineno;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if !INI_USE_STACK
|
||||
free(line);
|
||||
#endif
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
/* See documentation in header file. */
|
||||
int ini_parse(const char* filename,
|
||||
int (*handler)(unsigned, const char*, const char*, char*))
|
||||
{
|
||||
FILE* file;
|
||||
int error;
|
||||
|
||||
file = fopen(filename, "r");
|
||||
if (!file)
|
||||
return -1;
|
||||
error = ini_parse_file(file, handler);
|
||||
fclose(file);
|
||||
return error;
|
||||
}
|
70
ini.h
70
ini.h
|
@ -1,70 +0,0 @@
|
|||
/* inih -- simple .INI file parser
|
||||
|
||||
inih is released under the New BSD license (see LICENSE.txt). Go to the project
|
||||
home page for more info:
|
||||
|
||||
http://code.google.com/p/inih/
|
||||
|
||||
*/
|
||||
|
||||
#ifndef __INI_H__
|
||||
#define __INI_H__
|
||||
|
||||
/* Make this header file easier to include in C++ code */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* Parse given INI-style file. May have [section]s, name=value pairs
|
||||
(whitespace stripped), and comments starting with ';' (semicolon). Section
|
||||
is "" if name=value pair parsed before any section heading. name:value
|
||||
pairs are also supported as a concession to Python's ConfigParser.
|
||||
|
||||
For each name=value pair parsed, call handler function with given user
|
||||
pointer as well as section, name, and value (data only valid for duration
|
||||
of handler call). Handler should return nonzero on success, zero on error.
|
||||
|
||||
Returns 0 on success, line number of first error on parse error (doesn't
|
||||
stop on first error), -1 on file open error, or -2 on memory allocation
|
||||
error (only when INI_USE_STACK is zero).
|
||||
*/
|
||||
int ini_parse(const char* filename,
|
||||
int (*handler)(unsigned lineno, const char* section,
|
||||
const char* name, char* value));
|
||||
|
||||
/* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't
|
||||
close the file when it's finished -- the caller must do that. */
|
||||
int ini_parse_file(FILE* file,
|
||||
int (*handler)(unsigned lineno, const char* section,
|
||||
const char* name, char* value));
|
||||
|
||||
/* Nonzero to allow multi-line value parsing, in the style of Python's
|
||||
ConfigParser. If allowed, ini_parse() will call the handler with the same
|
||||
name for each subsequent line parsed. */
|
||||
#ifndef INI_ALLOW_MULTILINE
|
||||
#define INI_ALLOW_MULTILINE 1
|
||||
#endif
|
||||
|
||||
/* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of
|
||||
the file. See http://code.google.com/p/inih/issues/detail?id=21 */
|
||||
#ifndef INI_ALLOW_BOM
|
||||
#define INI_ALLOW_BOM 1
|
||||
#endif
|
||||
|
||||
/* Nonzero to use stack, zero to use heap (malloc/free). */
|
||||
#ifndef INI_USE_STACK
|
||||
#define INI_USE_STACK 1
|
||||
#endif
|
||||
|
||||
/* Maximum line length for any line in INI file. */
|
||||
#ifndef INI_MAX_LINE
|
||||
#define INI_MAX_LINE 200
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INI_H__ */
|
|
@ -1,5 +1,5 @@
|
|||
#Name: GPX
|
||||
#Info: GCode to x3g conversion post processor
|
||||
#Info: Cura x3g conversion post processor
|
||||
#Help: GPX
|
||||
#Depend: GCode
|
||||
#Type: postprocess
|
Loading…
Reference in New Issue