mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2024-12-23 07:31:11 +02:00
6271d5f721
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.
66 lines
1.1 KiB
C
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;
|
|
}
|