1
0
mirror of git://projects.qi-hardware.com/cae-tools.git synced 2024-12-23 09:43:20 +02:00
cae-tools/spool/spool.c
Werner Almesberger 6271d5f721 spool/: job spooler for CNC mill (migrated from Openmoko)
From
http://svn.openmoko.org/developers/werner/cncmap/spool/

Fixed a buffer termination bug that caused the mill to do strange
(yet almost always harmless) things at the end of a job.
2012-03-11 09:37:38 -03:00

66 lines
1.1 KiB
C

/*
* spool.c - Send a file to a Roland MDX series CNC mill
*
* Written 2009, 2010, 2012 by Werner Almesberger
* Copyright 2009, 2010, 2012 Werner Almesberger
*
* 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.
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include "serial.h"
#define DEFAULT_PORT "/dev/ttyS0"
#define BUF_SIZE 8192
static void usage(const char *name)
{
fprintf(stderr, "usage: %s [file]\n", name);
exit(1);
}
int main(int argc, const char **argv)
{
FILE *file;
char buf[BUF_SIZE+1];
size_t n;
char *port;
switch (argc) {
case 1:
file = stdin;
break;
case 2:
file = fopen(argv[1], "r");
if (!file) {
perror(argv[1]);
exit(1);
}
break;
default:
usage(*argv);
}
port = getenv("PORT");
serial_open(port ? port : DEFAULT_PORT);
while (1) {
n = fread(buf, 1, BUF_SIZE, file);
if (!n)
break;
buf[n] = 0;
serial_printf("%s", buf);
}
sleep(3600);
serial_close();
return 0;
}