mirror of https://github.com/vitalif/GPX
More work on 2.0
Added scale, log to file, trunkate 8.3 filename comand line switches. Serial IO implementation continues.master
parent
687ea2bb64
commit
3570fc9518
|
@ -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;
|
617
gpx-main.c
617
gpx-main.c
|
@ -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,231 +132,9 @@ static void usage()
|
|||
exit(1);
|
||||
}
|
||||
|
||||
// GPX program entry point
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
static void sio_open(char *filename, speed_t baud_rate)
|
||||
{
|
||||
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");
|
||||
|
@ -411,14 +196,329 @@ int main(int argc, char * argv[])
|
|||
exit(-1);
|
||||
}
|
||||
|
||||
if(gpx.flag.verboseMode) fprintf(stderr, "Communicating via: %s" EOL, filename);
|
||||
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;
|
||||
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_load_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:de:gf:ilm:n:pqrstvwx: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);
|
||||
// fall through
|
||||
case 's':
|
||||
serial_io = 1;
|
||||
gpx.flag.framingEnabled = 1;
|
||||
break;
|
||||
case 'c':
|
||||
config = optarg;
|
||||
break;
|
||||
case 'd':
|
||||
gpx.flag.dittoPrinting = 1;
|
||||
break;
|
||||
case 'e':
|
||||
eeprom = optarg;
|
||||
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 '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 't':
|
||||
truncate_filename = 1;
|
||||
break;
|
||||
case 'v':
|
||||
gpx.flag.verboseMode = 1;
|
||||
break;
|
||||
case 'w':
|
||||
gpx.flag.rewrite5D = 1;
|
||||
break;
|
||||
case 'x':
|
||||
gpx.user.offset.x = strtod(optarg, NULL);
|
||||
break;
|
||||
case 'y':
|
||||
gpx.user.offset.y = strtod(optarg, NULL);
|
||||
break;
|
||||
case 'z':
|
||||
gpx.user.offset.z = strtod(optarg, NULL);
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
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(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();
|
||||
}
|
||||
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, gpx.log);
|
||||
}
|
||||
|
||||
// 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
|
||||
else if(argc > 0) {
|
||||
filename = argv[0];
|
||||
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);
|
||||
}
|
||||
// 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(serial_io) {
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
// trim build name extension
|
||||
char *dot = strrchr(buildname, '.');
|
||||
if(dot) *dot = 0;
|
||||
|
||||
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.
|
||||
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);
|
||||
}
|
||||
|
||||
// READ INPUT AND CONVERT TO OUTPUT
|
||||
/* 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. */
|
||||
|
||||
gpx_start_build(&gpx, buildname);
|
||||
|
||||
if(gpx.flag.serialIO) {
|
||||
rval = gpx_send_file(&gpx, file_in, sio_port);
|
||||
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 {
|
||||
rval = gpx_convert_file(&gpx, file_in, file_out, file_out2);
|
||||
// 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_end_build(&gpx);
|
||||
|
||||
gpx_start_convert(&gpx, buildname);
|
||||
rval = gpx_convert(&gpx, file_in, file_out, file_out2);
|
||||
gpx_end_convert(&gpx);
|
||||
}
|
||||
exit(rval);
|
||||
}
|
||||
|
|
56
gpx.h
56
gpx.h
|
@ -35,6 +35,16 @@ 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 {
|
||||
|
@ -315,25 +337,31 @@ extern "C" {
|
|||
|
||||
// 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_register_callback(Gpx *gpx, int (*callbackHandler)(Gpx *gpx, void *callbackData, char *buffer, size_t length), void *callbackData);
|
||||
|
||||
void gpx_start_build(Gpx *gpx, char *buildName);
|
||||
void gpx_end_build(Gpx *gpx);
|
||||
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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue