More work on 2.0

Added scale, log to file, trunkate 8.3 filename comand line switches.
Serial IO implementation continues.
master
WHPThomas 2014-01-09 04:20:51 +10:00
parent 687ea2bb64
commit 3570fc9518
5 changed files with 2156 additions and 417 deletions

178
examples/rep2-eeprom.ini Normal file
View File

@ -0,0 +1,178 @@
;
; Replicator 2 EEPROM setting configuration
;
[byte]
; VERSION_LOW
; Firmware Version, low byte: 1 byte
;0x0000=
; VERSION_HIGH
; Firmware Version, high byte: 1 byte
;0x0001=
; AXIS_INVERSION
; Axis inversion flags: 1 byte.
; Axis N (where X=0, Y=1, etc.) is inverted if the Nth bit is set.
; Bit 7 is used for HoldZ OFF: 1 = off, 0 = on
0x0002=
; ENDSTOP_INVERSION
; Endstop inversion flags: 1 byte.
; The endstops for axis N (where X=0, Y=1, etc.) are considered
; to be logically inverted if the Nth bit is set.
; Bit 7 is set to indicate endstops are present; it is zero to indicate
; that endstops are not present.
; Ordinary endstops (H21LOB et. al.) are inverted.
0x0004=
; DIGI_POT_SETTINGS
; Digital Potentiometer Settings : 5 Bytes
0x0006=
0x0007=
0x0008=
0x0009=
0x000A=
; AXIS_HOME_DIRECTION
; axis home direction (1 byte)
0x000C=
[integer]
; AXIS_HOME_POSITIONS_STEPS
; Default locations for the axis in step counts: 5 x 32 bit = 20 bytes
0x000E=
0x0012=
0x0016=
0x001A=
0x001E=
[string]
; MACHINE_NAME
; Name of this machine: 16 bytes (16 bytes extra buffer)
0x0022=Replicator 2
[byte]
; TOOL_COUNT
; Tool count : 1 byte
0x0042=1
; VID_PID_INFO
; Hardware ID. Must exactly match the USB VendorId/ProductId pair: 4 bytes
;0x0044=
;0x0045=
;0x0046=
;0x0047=
; INTERNAL_VERSION
; Version Number for internal releases
;0x0048=
; Versin number to be tagged with Git Commit
const static uint16_t COMMIT_VERSION = 0x004A;
; HBP Present or not
//$BEGIN_ENTRY
//$type:B
const static uint16_t HBP_PRESENT = 0x004C;
; 40 bytes padding
; Thermistor table 0: 128 bytes
const static uint16_t THERM_TABLE = 0x0074;
; Padding: 8 bytes
// Toolhead 0 data: 28 bytes (see above)
const static uint16_t T0_DATA_BASE = 0x0100;
// Toolhead 0 data: 28 bytes (see above)
const static uint16_t T1_DATA_BASE = 0x011C;
; unused 8 bytes = 0x0138;
; Light Effect table. 3 Bytes x 3 entries
const static uint16_t LED_STRIP_SETTINGS = 0x0140;
; Buzz Effect table. 4 Bytes x 3 entries
const static uint16_t BUZZ_SETTINGS = 0x014A;
; 1 byte. 0x01 for 'never booted before' 0x00 for 'have been booted before)
;const static uint16_t FIRST_BOOT_FLAG = 0x0156;
; 7 bytes, short int x 3 entries, 1 byte on/off
const static uint16_t PREHEAT_SETTINGS = 0x0158;
; 1 byte, 0x01 for help menus on, 0x00 for off
const static uint16_t FILAMENT_HELP_SETTINGS = 0x0160;
; This indicates how far out of tolerance the toolhead0 toolhead1 distance is
; in steps. 3 x 32 bits = 12 bytes
const static uint16_t TOOLHEAD_OFFSET_SETTINGS = 0x0162;
; Acceleraton settings 22 bytes: 1 byte (on/off), 2 bytes default acceleration rate,
//$BEGIN_ENTRY
//$eeprom_map:acceleration_eeprom_offsets
const static uint16_t ACCELERATION_SETTINGS = 0x016E;
; 2 bytes bot status info bytes
const static uint16_t BOT_STATUS_BYTES = 0x018A;
; axis lengths XYZ AB 5*32bit = 20 bytes
const static uint16_t AXIS_LENGTHS = 0x018C;
; total lifetime print hours, 3bytes
//$BEGIN_ENTRY
//$eeprom_map: build_time_offsets
const static uint16_t TOTAL_BUILD_TIME = 0x01A0;
; axis steps per mm XYZAB 5*32bit = 20 bytes
const static uint16_t AXIS_STEPS_PER_MM = 0x01A4;
; Filament lifetime counter (in steps) 8 bytes (int64) x 2 (for 2 extruders)
const static uint16_t FILAMENT_LIFETIME = 0x01B8;
; Filament trip counter (in steps) 8 bytes (int64) x 2 (for 2 extruders)
const static uint16_t FILAMENT_TRIP = 0x01C8;
; Acceleraton settings 60 bytes: 1 byte (on/off) + acceleration settings
const static uint16_t ACCELERATION2_SETTINGS = 0x01D8;
; axis max feedrates XYZAB 5*32bit = 20 bytes
const static uint16_t AXIS_MAX_FEEDRATES = 0x01F4;
; Hardware configuration settings
//$BEGIN_ENTRY
//$type:B
const static uint16_t BOTSTEP_TYPE = 0x0208;
; temperature offset calibration: 1 byte x 3 heaters = 3 bytes
//$BEGIN_ENTRY
//$type:BBB
const static uint16_t HEATER_CALIBRATION = 0x020A;
; start of free space
const static uint16_t FREE_EEPROM_STARTS = 0x020B;
//Sailfish specific settings work backwards from the end of the eeprom 0xFFF
//P-Stop enable (1 byte)
//$BEGIN_ENTRY
//$type:B
const static uint16_t PSTOP_ENABLE = 0x0F90;
//Use SD card CRC(1 byte)
//$BEGIN_ENTRY
//$type:B
const static uint16_t SD_USE_CRC = 0x0F91;
//Extruder hold (1 byte)
//$BEGIN_ENTRY
//$type:B
const static uint16_t EXTRUDER_HOLD = 0x0F92;
//Toolhead offset system (1 byte; 0x00 == RepG 39; 0x01 == RepG 40+)
//$BEGIN_ENTRY
//$type:B
const static uint16_t TOOLHEAD_OFFSET_SYSTEM = 0x0F93;
;Location of the profiles, 4 x 26 bytes (PROFILES_QUANTITY * PROFILE_SIZE)
const static uint16_t PROFILES_BASE = 0x0F94;
;1 byte, set to PROFILES_INITIALIZED (0xAC) when profiles have been initialized
const static uint16_t PROFILES_INIT = 0x0FFC;
const static uint16_t OVERRIDE_GCODE_TEMP = 0x0FFD;
const static uint16_t HEAT_DURING_PAUSE = 0x0FFE;
const static uint16_t DITTO_PRINT_ENABLED = 0x0FFF;

View File

@ -24,6 +24,7 @@
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include <ctype.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
@ -84,20 +85,25 @@ static void usage()
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 "Usage:" EOL, stderr);
fputs("gpx [-dgilpqrstvw] [-b BAUDRATE] [-c CONFIG] [-e EEPROM] [-f DIAMETER] [-m MACHINE] [-n SCALE] [-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-l\tlog to file" EOL, stderr);
fputs("\t-p\toverride build percentage" EOL, stderr);
fputs("\t-q\tquiet mode" 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-t\ttruncate filename (DOS 8.3 format)" 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(EOL "BAUDRATE: the baudrate for serial I/O (default is 115200)" EOL, stderr);
fputs("CONFIG: the filename of a custom machine definition (ini file)" EOL, stderr);
fputs("EEPROM: the filename of an eeprom settings definition (ini file)" EOL, stderr);
fputs("DIAMETER: the actual filament diameter in the printer" EOL, stderr);
fputs(EOL "MACHINE: 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);
@ -110,12 +116,13 @@ static void usage()
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(EOL "SCALE: the coordinate system scale for the conversion (ABS = 1.0035)" EOL, stderr);
fputs("X,Y & Z: 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 "IN: the name of the sliced gcode input filename" EOL, stderr);
fputs("OUT: 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);
@ -125,17 +132,88 @@ static void usage()
exit(1);
}
static void sio_open(char *filename, speed_t baud_rate)
{
struct termios tp;
// 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(gpx.log, "Communicating via: %s" EOL, filename);
}
// GPX program entry point
int main(int argc, char * argv[])
{
int c, i, rval;
int log_to_file = 0;
int standard_io = 0;
int serial_io = 0;
int truncate_filename = 0;
char *config = NULL;
char *eeprom = 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
@ -171,7 +249,7 @@ int main(int argc, char * argv[])
*appname++ = 'i';
*appname++ = '\0';
appname = gpx.buffer.out;
i = gpx_read_config(&gpx, appname);
i = gpx_load_config(&gpx, appname);
if(i == 0) {
if(gpx.flag.verboseMode) fprintf(stderr, "Loaded config: %s" EOL, appname);
}
@ -184,7 +262,7 @@ int main(int argc, char * argv[])
// READ COMMAND LINE
// get the command line options
while ((c = getopt(argc, argv, "b:c:dgf:im:prsvwx:y:z:?")) != -1) {
while ((c = getopt(argc, argv, "b:c:de:gf:ilm:n:pqrstvwx:y:z:?")) != -1) {
switch (c) {
case 'b':
i = atoi(optarg);
@ -222,6 +300,10 @@ int main(int argc, char * argv[])
usage();
}
if(gpx.flag.verboseMode) fprintf(stderr, "Setting baud rate to: %i bps" EOL, i);
// fall through
case 's':
serial_io = 1;
gpx.flag.framingEnabled = 1;
break;
case 'c':
config = optarg;
@ -229,6 +311,9 @@ int main(int argc, char * argv[])
case 'd':
gpx.flag.dittoPrinting = 1;
break;
case 'e':
eeprom = optarg;
break;
case 'g':
gpx.flag.reprapFlavor = 0;
break;
@ -242,20 +327,29 @@ int main(int argc, char * argv[])
case 'i':
standard_io = 1;
break;
case 'l':
gpx.flag.verboseMode = 1;
log_to_file = 1;
break;
case 'm':
if(gpx_set_property(&gpx, "printer", "machine_type", optarg)) {
usage();
}
break;
case 'n':
gpx.user.scale = strtod(optarg, NULL);
break;
case 'p':
gpx.flag.buildProgress = 1;
break;
case 'q':
gpx.flag.logMessages = 0;
break;
case 'r':
gpx.flag.reprapFlavor = 1;
break;
case 's':
gpx.flag.serialIO = 1;
gpx.flag.framingEnabled = 1;
case 't':
truncate_filename = 1;
break;
case 'v':
gpx.flag.verboseMode = 1;
@ -264,13 +358,13 @@ int main(int argc, char * argv[])
gpx.flag.rewrite5D = 1;
break;
case 'x':
gpx.userOffset.x = strtod(optarg, NULL);
gpx.user.offset.x = strtod(optarg, NULL);
break;
case 'y':
gpx.userOffset.y = strtod(optarg, NULL);
gpx.user.offset.y = strtod(optarg, NULL);
break;
case 'z':
gpx.userOffset.z = strtod(optarg, NULL);
gpx.user.offset.z = strtod(optarg, NULL);
break;
case '?':
default:
@ -278,11 +372,44 @@ int main(int argc, char * argv[])
}
}
argc -= optind;
argv += optind;
// LOG TO FILE
if(log_to_file && argc > 0) {
filename = (argc > 1 && !serial_io) ? argv[1] : argv[0];
// or use the input filename with a .log 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++ = 'l';
*filename++ = 'o';
*filename++ = 'g';
*filename++ = '\0';
filename = gpx.buffer.out;
if((gpx.log = fopen(filename, "w+")) == NULL) {
gpx.log = stderr;
perror("Error opening log");
}
}
// READ CONFIGURATION
if(config) {
if(gpx.flag.verboseMode) fprintf(stderr, "Reading custom config: %s" EOL, config);
i = gpx_read_config(&gpx, config);
if(gpx.flag.verboseMode) fprintf(gpx.log, "Loading custom config: %s" EOL, config);
i = gpx_load_config(&gpx, config);
if (i < 0) {
fprintf(stderr, "Command line error: cannot load configuration file '%s'" EOL, config);
usage();
@ -294,18 +421,27 @@ int main(int argc, char * argv[])
}
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);
if(gpx.flag.verboseMode) fputs("WARNING: a 57600 bps baud rate will cause problems with Repicator 2/2X Mightyboards" EOL, gpx.log);
}
argc -= optind;
argv += optind;
// OPEN FILES AND PORTS FOR INPUT AND OUTPUT
if(standard_io) {
if(serial_io) {
if(argc > 0) {
filename = argv[0];
sio_open(filename, baud_rate);
}
else {
fputs("Command line error: port required for serial I/O" EOL, stderr);
usage();
}
}
}
// open the input filename if one is provided
if(argc > 0) {
else if(argc > 0) {
filename = argv[0];
if(gpx.flag.verboseMode) fprintf(stderr, "Reading from: %s" EOL, filename);
if(gpx.flag.verboseMode) fprintf(gpx.log, "Reading from: %s" EOL, filename);
if((file_in = fopen(filename, "rw")) == NULL) {
perror("Error opening input");
exit(1);
@ -318,6 +454,7 @@ int main(int argc, char * argv[])
else {
buildname = filename;
}
argc--;
argv++;
// use the output filename if one is provided
@ -325,7 +462,7 @@ int main(int argc, char * argv[])
filename = argv[0];
}
else {
if(gpx.flag.serialIO) {
if(serial_io) {
fputs("Command line error: port required for serial I/O" EOL, stderr);
usage();
}
@ -342,83 +479,46 @@ int main(int argc, char * argv[])
memcpy(gpx.buffer.out, filename, sl);
filename = gpx.buffer.out + sl;
}
*filename++ = '.';
*filename++ = 'x';
*filename++ = '3';
*filename++ = 'g';
*filename++ = '\0';
if(truncate_filename) {
char *s = gpx.buffer.out;
for(i = 0; s < filename && i < 8; i++) {
char c = *s;
if(isalnum(c)) {
*s++ = toupper(c);
}
else {
*s++ = '_';
}
}
*s++ = '.';
*s++ = 'X';
*s++ = '3';
*s++ = 'G';
*s++ = '\0';
}
else {
*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);
}
// trim build name extension
char *dot = strrchr(buildname, '.');
if(dot) *dot = 0;
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);
if(serial_io) {
sio_open(filename, baud_rate);
}
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);
if(gpx.flag.verboseMode) fprintf(gpx.log, "Writing to: %s" EOL, filename);
// write a second copy to the SD Card
if(gpx.sdCardPath) {
long sl = strlen(gpx.sdCardPath);
@ -440,31 +540,56 @@ int main(int argc, char * argv[])
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);
if(file_out2 && gpx.flag.verboseMode) fprintf(gpx.log, "Writing to: %s" EOL, gpx.buffer.out);
}
}
}
else if(!standard_io) {
else {
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);
if(log_to_file) {
if(gpx.flag.buildProgress) fputs("Build progress: enabled" EOL, gpx.log);
if(gpx.flag.dittoPrinting) fputs("Ditto printing: enabled" EOL, gpx.log);
if(serial_io) fputs("Serial IO: enabled" EOL, gpx.log);
fprintf(gpx.log, "GCode flavor: %s" EOL, gpx.flag.reprapFlavor ? "Reprap" : "Makerbot");
if(gpx.flag.rewrite5D) fputs("Rewrite 5D: enabled" EOL, gpx.log);
}
else {
rval = gpx_convert_file(&gpx, file_in, file_out, file_out2);
}
gpx_end_build(&gpx);
/* 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. */
if(serial_io) {
// READ CONFIG AND WRITE EEPROM SETTINGS
if(eeprom) {
if(gpx.flag.verboseMode) fprintf(gpx.log, "Loading eeprom config: %s" EOL, eeprom);
i = eeprom_load_config(&gpx, eeprom);
if (i < 0) {
fprintf(stderr, "Command line error: cannot load eeprom configuration file '%s'" EOL, eeprom);
usage();
}
else if (i > 0) {
fprintf(stderr, "(line %u) Eeprom configuration syntax error in %s: unrecognised paremeters" EOL, i, eeprom);
usage();
}
exit(SUCCESS);
}
else {
// READ INPUT AND SEND OUTPUT TO PRINTER
gpx_start_convert(&gpx, buildname);
rval = gpx_convert_and_send(&gpx, file_in, sio_port);
gpx_end_convert(&gpx);
}
}
else {
// READ INPUT AND CONVERT TO OUTPUT
gpx_start_convert(&gpx, buildname);
rval = gpx_convert(&gpx, file_in, file_out, file_out2);
gpx_end_convert(&gpx);
}
exit(rval);
}

1974
gpx.c

File diff suppressed because it is too large Load Diff

64
gpx.h
View File

@ -35,7 +35,17 @@ extern "C" {
#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
@ -51,9 +61,14 @@ extern "C" {
// BOUNDS CHECKING VARIABLES
#define TEMPERATURE_MAX 280
#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 '\\'
@ -247,16 +262,23 @@ extern "C" {
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;
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
Point3d userOffset; // command line offset
struct {
Point3d offset; // command line offset
double scale; // command line scale
} user;
Tool tool[2]; // tool state
Override override[2]; // gcode override
@ -280,16 +302,17 @@ extern "C" {
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
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 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
unsigned showErrorMessages:1;
} flag;
@ -297,7 +320,6 @@ extern "C" {
unsigned lineNumber; // the current line number
int longestDDA;
// STATISTICS
struct {
@ -312,28 +334,34 @@ extern "C" {
double time;
unsigned long bytes;
} total;
// CALLBACK
int (*callbackHandler)(Gpx *gpx, void *callbackData);
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_read_config(Gpx *gpx, const char *filename);
int gpx_load_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);
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_file(Gpx *gpx, FILE *file_in, FILE *file_out, FILE *file_out2);
int gpx_send_file(Gpx *gpx, FILE *file_in, int sio_port);
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
}

View File

@ -1,10 +1,10 @@
#Name: GPX
#Info: Cura x3g conversion post processor
#Info: GCode to x3g conversion post processor
#Help: GPX
#Depend: GCode
#Type: postprocess
#Param: gpxPath(str:/Applications/GPX) GPX path
#Param: machineType(str:r2) Machine type
#Param: flags(str:-m r2) Flags
import platform
import os
@ -23,9 +23,5 @@ def getGpxAppName():
x3gFile = profile.getPreference('lastFile')
x3gFile = x3gFile[0:x3gFile.rfind('.')] + '.x3g'
commandList = [getGpxAppName(), '-p', '-r']
if machineType is not None and machineType != '':
commandList += ['-m', machineType]
commandList += [filename, x3gFile]
commandList = [getGpxAppName(), '-p', '-r', flags, filename, x3gFile]
call(commandList)