Skip to content
Browse files

Remove libreprap since it is no longer needed. libreprap functionalit…

…y is now included in printer/printer_serial
  • Loading branch information...
1 parent 319eb59 commit 851af062788c14f7a1298d19ac2f2b60f79268c3 @maurerpe maurerpe committed Feb 2, 2013
View
1 Makefile.am
@@ -3,7 +3,6 @@ ACLOCAL_AMFLAGS = -I m4
CLEANFILES = repsnapper.desktop
-DISTCHECK_CONFIGURE_FLAGS = @DISTCHECK_LIBREPRAP_FLAGS@
DISTCLEANFILES = tools/gitversion.sh
BUILT_SOURCES = tools/gitversion.sh
View
6 TODO
@@ -67,12 +67,6 @@
+ prompt to save changes on selection ...
* Serial
- + libreprap:
- + don't write anything (particularly a re-send) while
- a partial read is underway [?]
- + add a 'comms_debug' boolean ...
- + replace libreprap by an IOChannel
-
+ add a test serial connection ...
+ error dialogs - "failed to connect ?"
+ /dev/ttyUSB0 - EACCES
View
38 configure.ac
@@ -56,44 +56,6 @@ AC_OPENMP()
PKG_CHECK_MODULES(LIBZIP, libzip >= 0.10)
-
-dnl ------------------------------------------------------------------
-dnl libreprap is (for now) built in from a copy in libraries/libreprap
-dnl thus avoiding cmake, and user confusion.
-dnl ------------------------------------------------------------------
-dnl
-dnl Empty flags to be substituted below.
-DISTCHECK_LIBREPRAP_FLAGS=
-dnl Look for libreprap, either in the system paths or in the path
-dnl provided (defaults to --prefix)
-dnl AC_ARG_WITH(libreprap,
-dnl AS_HELP_STRING([--with-libreprap],
-dnl [Extra prefix in which to look for libreprap. (default is $prefix)]),
-dnl [ LIBREPRAP_PREFIX="$withval" ], [ LIBREPRAP_PREFIX="$prefix" ])
-dnl
-dnl if test "x${LIBREPRAP_PREFIX}" != xNONE; then
-dnl xLIBREPRAP_CFLAGS="-I${LIBREPRAP_PREFIX}/include"
-dnl xLIBREPRAP_LIBS="-L${LIBREPRAP_PREFIX}/lib -lreprap"
-dnl DISTCHECK_LIBREPRAP_FLAGS="--with-libreprap=$LIBREPRAP_PREFIX"
-dnl else
-dnl xLIBREPRAP_LIBS="-lreprap"
-dnl fi
-dnl
-dnl OLD_CPPFLAGS="$CPPFLAGS"; CPPFLAGS="${xLIBREPRAP_CFLAGS} $CPPFLAGS"
-dnl OLD_LIBS="$LIBS"; LIBS="${xLIBREPRAP_LIBS} $LIBS"
-dnl AC_CHECK_HEADER(reprap/comms.h,
-dnl [LIBREPRAP_CFLAGS="${xLIBREPRAP_CFLAGS}"],
-dnl AC_MSG_ERROR([cannot find headers for libreprap]))
-dnl dnl we require the 'meeks' branch of libreprap
-dnl AC_CHECK_LIB(reprap, rr_dev_create,
-dnl [LIBREPRAP_LIBS="${xLIBREPRAP_LIBS}"],
-dnl AC_MSG_ERROR([cannot find binary for libreprap - check out the README]))
-dnl CPPFLAGS="$OLD_CPPFLAGS"; LIBS="$OLD_LIBS"
-dnl AC_SUBST(LIBREPRAP_CFLAGS)
-dnl AC_SUBST(LIBREPRAP_LIBS)
-
-AC_SUBST(DISTCHECK_LIBREPRAP_FLAGS)
-
case "$host_os" in
mingw*)
GL_LIBS="-lopengl32"
View
1 libraries/Makefile.am
@@ -1,5 +1,4 @@
include libraries/lmfit/Makefile.am
-include libraries/libreprap/Makefile.am
include libraries/vmmlib/Makefile.am
include libraries/clipper/Makefile.am
include libraries/poly2tri/Makefile.am
View
18 libraries/libreprap/Makefile.am
@@ -1,18 +0,0 @@
-noinst_LTLIBRARIES += libreprap.la
-
-libreprap_la_CPPFLAGS = -I$(srcdir) $(EXTRA_CFLAGS)
-
-libreprap_la_SOURCES = \
- libraries/libreprap/comms.c \
- libraries/libreprap/comms.h \
- libraries/libreprap/comms_private.h \
- libraries/libreprap/fived.c \
- libraries/libreprap/fived.h \
- libraries/libreprap/serial.c \
- libraries/libreprap/serial.h \
- libraries/libreprap/tonokip.c \
- libraries/libreprap/tonokip.h \
- libraries/libreprap/util.c \
- libraries/libreprap/util.h
-
-EXTRA_DIST += libraries/libreprap/TODO libraries/libreprap/README
View
17 libraries/libreprap/README
@@ -1,17 +0,0 @@
-Libreprap is a library intended to abstract host <-> reprap communication, allowing all reprap host software to share common code for this task.
-
-Code hosting was: https://github.com/Ralith/libreprap
-Page on the reprap wiki: http://reprap.org/wiki/Libreprap
-
-A heavily patched copy of this is hosted inside repsnapper to avoid the compound grief of multiple repos and permissions.
-
-Currently, gcdump (from reprap-tools) and the development branch of RepSnapper is using this lib, but once it matures, the intention is for every host software to start using it.
-
-== Development ==
-You can debug the serial code wihtout an actual firmware by using socat:
-* sudo socat -d -d pty,link=/dev/libreprap,raw,echo=0 readline,raw,echo=0
-** This gives a simple serial terminal that you can use to talk to libreprap
-* connect your client software to /dev/libreprap
-** now send anything and see it appear on the socat terminal
-* for testing libreprap with minimal distractions, try gcdump from https://github.com/Ralith/reprap-utils
-** "gcdump -v -p 3 /dev/libreprap" eats from stdin and outputs to stdout. Use "-p 5" instead for comms checksumming
View
141 libraries/libreprap/TODO
@@ -1,141 +0,0 @@
-cf. process_g_code.pde ('talkToHost.get()') ...
-
-A "rs" - should re-wind the send queue back to that item
- + pull all that lot back off the back-queue and
- onto the send-queue ...
-
-
-G1 F1000
-G1 X1.06066 Y1.06066 F4000
-G1 X9.33434 Y9.33434 F4000
-G1 X10.395 Y10.395 F1000
-G1 F1000
-G1 X11.895 E1.425 F4000
-G1 X84.105 E70.0245 F4000
-G1 X85.605 E71.4495 F1000
-G1 F1000
-G1 Y11.895 E72.8745 F4000
-G1 Y18 E78.6743 F4000
-G1 Y19.5 E80.0993 F1000
-G1 F1000
-
-G1 X85.6628 Y19.6397 E80.2429 F1302.32
-
-s 21 Serial Error: checksum mismatch. Remote (25) not equal to local (87), line received: N21 G1 X85.66282.32*25
-
-
-N21 G1 X85.6628 Y19.6397 E80.2429 F1302.32*25
-
-rs 21 Serial Error: checksum mismatch. Remote (25) not equal to local (87), line received: N21 G1 X85.66282.32*25
-
-N21 G1 X85.6628 Y19.6397 E80.2429 F1302.32*25
-; writeable - wait ok count is 0, queue 4 resend 0
-rs 21 Serial Error: checksum mismatch. Remote (25) not equal to local (70), line received: N21 G1 X82.32*25
-rs 21 Serial Error: checksum mismatch. Remote (25) not equal to local (70), line received: N21 G1 X82.32*25
-N21 G1 X85.6628 Y19.6397 E80.2429 F1302.32*25
-N21 G1 X85.6628 Y19.6397 E80.2429 F1302.32*25
-
-
- + FIXME - we need to have a nice "startup" pre-amble, that
- checks that everything is in sync - and fetches version
- info etc.
- + so we don't destroy our first commands to a new reprap ...
-
-
-* Do we need to send a command for every 'ok' ? is that how the
- queue mgmt works ? cf.:
-
-15830 read(8, "ok\r\nok\r\nok\r\n", 252) = 12
-
-* a 'start' must purge / renumber everything in the queues [!?]
-
-* add a log_printf method to output to the log ;-)
-
-* Accounting for 'OK's and sent lines, and filling the queue
-initially with four whatnots ...
-
-* These Errors ? [!?]
-
-* pre-filling the device queue to the right depth:
- + not done - need to push 4 lines in [!] ...
-
-* We need to log how many lines are on the device ;-)
-
-
-
-* Quite nice - strobing 'want write' and 'not want write' etc. :-)
-
-
-
-Buffering the entire file is not desirable; it's implemented that way
-in repsnapper as a temporary measure only. Refer to gcdump for
-intended libreprap use patterns.
-
-
-The application is expected to do flow control based on RR_OK receipt
-by only ever enqueueing enough messages to fill the device's buffer.
-The alternative to this is having enqueue return success/failure and a
-configurable maximum host and device buffer size. I agree that it's
-better to have libreprap handle this, especially as we can include
-safe defaults for the major firmware this way--and it makes it harder
-to use libreprap wrong, too, which is always good.
-
-
-* The queue does make it easier ... [ I think ]
- + but - we should manage the queue
- + so that it is ~always empty ...
-
-/*
-I'm not sure there's actually any need for a host buffer, though, as
-correctly written application software should respond effectively
-instantly to space becoming available in the device buffer.
-*/
-
- - Good ! :-) - bin that buffer [!] ...
-
-* No host buffers == no priority queues, can leave prio bits I guess.
- + several command(s) being written - do it async ?
- +
-
-* What API basically do we want:
-
- + bool wants_write();
- + void write_stuff() ...
- + callbacks:
-x + read_result ...
- + please_write_more
-x + error: disconnect
- + [log data]
- + [hidden] - resend
-
- + get_buffer_status [etc.]
-
-* I/O coupling:
- + rr_dev_set_need_write_cb ();
- +
-
-/* start:
- for (int i = 0; i < recv_size; i++)
- more_cb() ... ?
-
-
-"\r\n" was sent because that was what the protocol documentation I
-referred to specified. For protocols that expect only '\n', please do
-correct that, but be sure not to break any protocols that expect both.
-
-I suppose pausing the send queues is somewhat useful, though generally
-you're not meant to have very much data sitting in them. Then again,
-it's always best to be as responsive as possible, and a single G code
-can easily occupy the machine for several seconds--so I have no
-objection to supporting it. I don't know what you mean by "how deep
-that should be." Perhaps you refer to the configurable buffer sizes I
-mentioned above?
-
-Using the alternative flow control approach described above, it
-shouldn't be necessary to do any manual processing of reply
-confirmations, let alone pausing beyond user pause requests.
-
-
-
-- writable:
- + do we do all writes in response to polling for write-ability ?
View
793 libraries/libreprap/comms.c
@@ -1,793 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <assert.h>
-#include <stdarg.h>
-#include <ctype.h>
-
-#include "comms_private.h"
-#include "serial.h"
-#include "fived.h"
-#include "tonokip.h"
-
-/* print to the log */
-void
-rr_dev_log (rr_dev dev, int debug_level, const char *format, ...)
-{
- int len;
- va_list args;
- char buffer[4096];
-
- if (debug_level > dev->debug_output)
- return;
-
- va_start (args, format);
- len = vsnprintf (buffer, 4095, format, args);
- access (buffer, 0);
- if (dev->opt_log_cb)
- dev->opt_log_cb (dev, RR_LOG_MSG, buffer, len, dev->opt_log_cl);
- va_end (args);
-}
-
-static void
-blocknode_free (blocknode* node)
-{
- free (node->block);
- free (node);
-}
-
-static void
-rr_dev_append_to_queue (rr_dev dev, rr_prio priority,
- blocknode *node)
-{
- if (!dev->sendhead[priority]) {
- dev->sendsize[priority] = 1;
- dev->sendhead[priority] = node;
- dev->sendtail[priority] = node;
- } else {
- dev->sendsize[priority]++;
- dev->sendtail[priority]->next = node;
- dev->sendtail[priority] = node;
- }
-}
-
-static void
-rr_dev_prepend_to_queue (rr_dev dev, rr_prio priority,
- blocknode *node)
-{
- node->next = dev->sendhead[priority];
- dev->sendhead[priority] = node;
- if (!node->next) {
- dev->sendtail[priority] = node;
- dev->sendsize[priority] = 1;
- } else
- dev->sendsize[priority]++;
-}
-
-static blocknode *
-rr_dev_pop_from_queue (rr_dev dev, rr_prio priority)
-{
- blocknode *node = dev->sendhead[priority];
-
- if (!node)
- return NULL;
-
- dev->sendhead[priority] = node->next;
- if (!node->next)
- dev->sendtail[priority] = NULL;
- dev->sendsize[priority]--;
-
- return node;
-}
-
-static void
-empty_queue (rr_dev dev, int prio)
-{
- while (dev->sendhead[prio]) {
- blocknode *node = rr_dev_pop_from_queue (dev, prio);
- blocknode_free (node);
- }
- assert (dev->sendhead[prio] == NULL);
- assert (dev->sendtail[prio] == NULL);
- dev->sendsize[prio] = 0;
-}
-
-static void
-empty_buffers (rr_dev dev)
-{
- unsigned int i;
- for (i = 0; i < RR_PRIO_ALL_QUEUES; ++i)
- empty_queue (dev, i);
-}
-
-rr_dev
-rr_dev_create (rr_proto proto,
- /* how many commands can we push */
- size_t dev_cmdqueue_size,
- /* callbacks cf. above */
- rr_reply_fn reply_cb, void *reply_cl,
- rr_more_fn more_cb, void *more_cl,
- rr_error_fn error_cb, void *error_cl,
- /* notify when socket is writeable */
- rr_wait_wr_fn wait_wr_cb, void *wait_wr_cl,
- /* optional (or NULL, NULL) */
- rr_log_fn opt_log_cb, void *opt_log_cl)
-{
- unsigned int i;
- rr_dev dev;
-
- /* Required callbacks */
- if (!reply_cb || !more_cb || !error_cb || !wait_wr_cb)
- return NULL;
-
- dev = malloc (sizeof(struct rr_dev_t));
- if (!dev)
- return NULL;
-
- dev->proto = proto;
- dev->dev_cmdqueue_size = dev_cmdqueue_size;
- dev->reply_cb = reply_cb;
- dev->reply_cl = reply_cl;
- dev->more_cb = more_cb;
- dev->more_cl = more_cl;
- dev->error_cb = error_cb;
- dev->error_cl = error_cl;
- dev->wait_wr_cb = wait_wr_cb;
- dev->wait_wr_cl = wait_wr_cl;
- dev->opt_log_cb = opt_log_cb;
- dev->opt_log_cl = opt_log_cl;
-
- dev->lineno = 0;
- dev->fd = SERIAL_INVALID_INIT;
- dev->send_next = 0;
- dev->init_send_count = dev->dev_cmdqueue_size;
- dev->debug_output = 0;
- if (getenv("RR_DEBUG"))
- dev->debug_output = atoi (getenv("RR_DEBUG"));
-
- dev->sentcachesize = dev_cmdqueue_size * 4 + 64;
-
- for (i = 0; i < RR_PRIO_ALL_QUEUES; ++i) {
- dev->sendsize[i] = 0;
- dev->sendhead[i] = NULL;
- dev->sendtail[i] = NULL;
- dev->paused[i] = 0;
- }
- dev->sendbuf_fill = 0;
- dev->bytes_sent = 0;
- dev->recvbufsize = INITIAL_RECVBUFSIZE;
- dev->recvbuf = calloc (dev->recvbufsize + 1, sizeof (char));
- dev->recvbuf_fill = 0;
-
- rr_dev_log (dev, RR_DEBUG_ALWAYS, "Connecting with libreprap\n");
-
- return dev;
-}
-
-void
-rr_dev_free (rr_dev dev)
-{
- rr_dev_close (dev);
- empty_buffers (dev);
- free (dev->recvbuf);
- free (dev);
-}
-
-int
-rr_dev_open (rr_dev dev, const char *port, long speed)
-{
- char *error = NULL;
- dev->fd = serial_open (port, speed, &error);
- if (SERIAL_INVALID_CHECK(dev->fd) < 0)
- {
- rr_dev_log (dev, RR_DEBUG_ALWAYS, "Failed to open device %s", error ? error : "<no error>");
- fprintf (stderr, "%s\n", error ? error : "<null>");
- return -1;
- }
- else
- return 0;
-}
-
-int
-rr_dev_close (rr_dev dev)
-{
- int result = serial_close(dev->fd);
- dev->fd = SERIAL_INVALID_INIT;
- rr_dev_reset (dev);
- return result;
-}
-
-static ssize_t
-fmtblock_simple (char *buf, const char *block)
-{
- char work[SENDBUFSIZE+1];
- int result;
- result = snprintf(work, SENDBUFSIZE+1, "%s" BLOCK_TERMINATOR, block);
- if (result >= SENDBUFSIZE+1)
- return RR_E_BLOCK_TOO_LARGE;
- size_t len = (result > SENDBUFSIZE) ? SENDBUFSIZE : result;
- strncpy(buf, work, len);
-
- return len;
-}
-
-ssize_t fmtblock_fived(char *buf, const char *block, unsigned long line)
-{
- char work[SENDBUFSIZE+1];
- int result;
- char checksum = 0;
- result = snprintf(work, GCODE_BLOCKSIZE+1, "N%ld %s", line, block);
- if (result >= GCODE_BLOCKSIZE+1)
- return RR_E_BLOCK_TOO_LARGE;
- ssize_t i;
- for (i = 0; i < result; ++i)
- checksum ^= work[i];
-
- result = snprintf(work, SENDBUFSIZE+1, "N%ld %s*%d\n", line, block, checksum);
- if (result >= SENDBUFSIZE+1)
- return RR_E_BLOCK_TOO_LARGE;
-
- size_t len = (result > SENDBUFSIZE) ? SENDBUFSIZE : result;
- strncpy(buf, work, len);
-
- return len;
-}
-
-static ssize_t
-fmtblock (rr_dev dev, blocknode *node)
-{
- char *terminated = calloc(node->blocksize + 1, sizeof(char));
- strncpy(terminated, node->block, node->blocksize);
- terminated[node->blocksize] = '\0';
-
- ssize_t result;
- switch (dev->proto) {
- case RR_PROTO_SIMPLE:
- result = fmtblock_simple(dev->sendbuf, terminated);
- break;
-
- case RR_PROTO_FIVED:
- case RR_PROTO_TONOKIP:
- if (node->line >= 0) {
- /* Block has an explicit line number; may be out of sequence
- * (i.e. a resend) */
- result = fmtblock_fived(dev->sendbuf, terminated, node->line);
- } else {
- result = fmtblock_fived(dev->sendbuf, terminated, dev->lineno);
- }
- break;
-
- default:
- result = RR_E_UNSUPPORTED_PROTO;
- break;
- }
-
- free (terminated);
- return result;
-}
-
-int
-rr_dev_enqueue_internal (rr_dev dev, rr_prio priority,
- const char *block, size_t nbytes,
- long long line)
-{
- char *comment;
- /*
- * comments are normal in gcode, preceeded by a ';'
- * but we don't want to send those either
- */
- if ((comment = strchr (block, ';')))
- nbytes = comment - block;
-
- /*
- * Elide both newlines, and whitespace that gets in the way
- * of checksums that are valid.
- */
- while (nbytes > 0 && isspace (block[nbytes - 1]))
- nbytes--;
-
- if (nbytes == 0)
- return 0;
-
- blocknode *node = malloc(sizeof(blocknode));
- node->next = NULL;
- node->block = malloc (nbytes + 1);
- node->blocksize = nbytes;
- node->line = line;
- memcpy(node->block, block, nbytes);
- node->block[nbytes] = '\0';
-
- rr_dev_append_to_queue (dev, priority, node);
-
- dev->wait_wr_cb (dev, 1, dev->wait_wr_cl);
-
- return 0;
-}
-
-int
-rr_dev_resend (rr_dev dev, unsigned long lineno, const char *reply, size_t nbytes)
-{
- int resent = 0;
- blocknode *node;
-
- /* sent cache slot 0 is most recent */
- while (1) {
- if (!(node = rr_dev_pop_from_queue (dev, RR_PRIO_SENTCACHE)))
- break;
- rr_dev_log (dev, RR_DEBUG_HIGH, "pop sent node line %d '%s' (%d bytes)\n",
- (int)node->line, node->block, node->blocksize);
- if (node->line >= lineno) {
- rr_dev_prepend_to_queue (dev, RR_PRIO_RESEND, node);
- resent++;
- } else { /* put it back and look elsewhere */
- rr_dev_prepend_to_queue (dev, RR_PRIO_SENTCACHE, node);
- break;
- }
- }
-
- if (resent == 0) {
- /* Perhaps line is in the resend queue, and we got an:
- * rs: 3
- * rs: 6
- * type sequence so try peel forward the resend queue.
- */
-
- while (1) {
- if (!(node = rr_dev_pop_from_queue (dev, RR_PRIO_RESEND)))
- break;
- rr_dev_log (dev, RR_DEBUG_HIGH,
- "pop resend node line %d '%s' (%d bytes)\n",
- (int)node->line, node->block, node->blocksize);
- if (node->line < lineno) {
- rr_dev_prepend_to_queue (dev, RR_PRIO_SENTCACHE, node);
- resent++;
- } else { /* put it back and give up */
- rr_dev_prepend_to_queue (dev, RR_PRIO_RESEND, node);
- break;
- }
- }
-
- if (resent == 0) {
- rr_dev_log (dev, RR_DEBUG_ALWAYS,
- "re-send request for unknown (too old) line %ld from cache size %d\n",
- lineno, dev->sendsize[RR_PRIO_SENTCACHE]);
- rr_dev_emit_error (dev, RR_E_UNCACHED_RESEND, reply, nbytes);
- }
- }
-
- dev->send_next = 1;
- dev->wait_wr_cb (dev, 1, dev->wait_wr_cl);
-
- return 0;
-}
-
-void
-rr_dev_reset_lineno (rr_dev dev)
-{
- dev->lineno = 0;
- /* we invalidate all these line numbers */
- empty_queue (dev, RR_PRIO_RESEND);
- empty_queue (dev, RR_PRIO_SENTCACHE);
- rr_dev_enqueue_internal (dev, RR_PRIO_HIGH, "M110", 4, -1);
- dev->init_send_count = dev->dev_cmdqueue_size - 1;
-}
-
-void
-rr_dev_reset (rr_dev dev)
-{
- empty_buffers (dev);
- rr_dev_log (dev, RR_DEBUG_MEDIUM, "reset dev size to zero\n");
- rr_dev_reset_lineno (dev);
- dev->recvbuf_fill = 0;
-}
-
-void
-rr_dev_reset_device (rr_dev dev)
-{
- serial_setDTR(dev->fd, 1);
- serial_setDTR(dev->fd, 0);
-}
-
-static void
-debug_log_block (rr_dev dev, const char *block, int nbytes)
-{
- char buffer[4096], *p;
- int num = nbytes >= 4096 ? 4095 : nbytes;
- strncpy (buffer, block, num);
- buffer[num] = '\0';
- if ((p = strchr (buffer, '\n')))
- *p = '\0';
- if ((p = strchr (buffer, '\r')))
- *p = '\0';
- rr_dev_log (dev, RR_DEBUG_MEDIUM, "API enqueue of '%s' queue size %d\n",
- buffer, rr_dev_buffered_lines (dev));
-}
-
-int
-rr_dev_enqueue_cmd (rr_dev dev, rr_prio priority,
- const char *block, int opt_nbytes)
-{
- if (opt_nbytes < 0)
- opt_nbytes = strlen (block);
- if (dev->debug_output >= RR_DEBUG_MEDIUM)
- debug_log_block (dev, block, opt_nbytes);
-
- return rr_dev_enqueue_internal (dev, priority, block, opt_nbytes, -1);
-}
-
-void
-rr_dev_handle_ok (rr_dev dev)
-{
- int buffered = rr_dev_buffered_lines (dev);
-
- /* Send as many commands as we get ok's */
- if (dev->init_send_count > 0)
- dev->init_send_count--;
- dev->send_next = 1;
-
- if (buffered < dev->dev_cmdqueue_size) {
- rr_dev_log (dev, RR_DEBUG_MEDIUM,
- "request more %d < %d\n", buffered, dev->dev_cmdqueue_size);
- dev->more_cb (dev, dev->more_cl);
- }
- dev->wait_wr_cb (dev, 1, dev->wait_wr_cl);
-
- if (dev->debug_output > RR_DEBUG_ALWAYS)
- { /* Check the sendsize accounts add up */
- int i = 0;
- for (i = 0; i < RR_PRIO_COUNT; ++i) {
- blocknode *p;
- int count = 0;
- for (p = dev->sendhead[i]; p; p = p->next) {
- if (!p->next && dev->sendtail[i] != p)
- rr_dev_log (dev, RR_DEBUG_MEDIUM,
- "Error: queue (%d) broken tail pointer %p vs %p\n",
- i, p, dev->sendtail[i]);
- count++;
- }
- if (count != dev->sendsize[i])
- rr_dev_log (dev, RR_DEBUG_MEDIUM,
- "Error: queue (%d) size mismatch: %d vs %d\n",
- i, count, dev->sendsize[i]);
- }
- }
-}
-
-int
-rr_dev_handle_start (rr_dev dev)
-{
- /*
- * This is non-intuitive. If we reset the controller, when we next send
- * a command sequence, on the first command we will get a 'start',
- * meaning we should reset the line number. Problem is we then send
- * the rest of the command sequence and get another 'start' in mid
- * flow for some controllers, which gets us out of sync. Ergo we need
- * to reset the line number with a command each time we hit one of
- * these.
- */
- rr_dev_reset_lineno (dev);
- return 0;
-}
-
-static int
-handle_reply (rr_dev dev, const char *reply, size_t nbytes, size_t term_bytes)
-{
- if (dev->opt_log_cb)
- dev->opt_log_cb (dev, RR_LOG_RECV, reply, nbytes + term_bytes, dev->opt_log_cl);
-
- switch(dev->proto) {
- case RR_PROTO_FIVED:
- return fived_handle_reply (dev, reply, nbytes);
-
- case RR_PROTO_TONOKIP:
- return tonokip_handle_reply (dev, reply, nbytes);
-
- case RR_PROTO_SIMPLE:
- if (!strncasecmp ("ok", reply, 2) && dev->reply_cb) {
- rr_dev_handle_ok (dev);
- dev->reply_cb (dev, RR_OK, 0.0, NULL, dev->reply_cl);
- } else if (dev->error_cb)
- dev->error_cb (dev, RR_E_UNKNOWN_REPLY, reply, nbytes, dev->error_cl);
- return 0;
-
- default:
- return RR_E_UNSUPPORTED_PROTO;
- }
-
- return 0;
-}
-
-int
-rr_dev_handle_readable (rr_dev dev)
-{
- int i;
-
- /* Grow receive buffer if it's full */
- if (dev->recvbuf_fill >= dev->recvbufsize) {
- dev->recvbufsize *= 2;
- dev->recvbuf = realloc (dev->recvbuf, dev->recvbufsize + 1);
- }
-
- ssize_t result;
-
- do {
- result = read (dev->fd, dev->recvbuf + dev->recvbuf_fill, dev->recvbufsize - dev->recvbuf_fill);
- } while (result < 0 && errno == EINTR);
-
- if (result < 0)
- return result;
-
- dev->recvbuf_fill += result;
-
- /* string terminate */
- dev->recvbuf[dev->recvbuf_fill] = '\0';
-
- /* validate the stream is ascii and of the correct length */
- for (i = 0; i < dev->recvbuf_fill; i++) {
- if (dev->recvbuf[i] == '\0' || !isascii (dev->recvbuf[i])) {
- rr_dev_log (dev, RR_DEBUG_ALWAYS,
- "invalid char in recvbuf at char %d (0x%2x) full "
- "msg: '%s', truncating here", i, dev->recvbuf[i],
- dev->recvbuf);
- dev->recvbuf_fill = i;
- dev->recvbuf[dev->recvbuf_fill] = '\0';
- break;
- }
- }
-
- /* spot control characters */
- if (dev->recvbuf[0] == 1) {
- rr_dev_log (dev, RR_DEBUG_ALWAYS,
- "unusual - control character 0x%2x 0x%2x\n",
- dev->recvbuf[0], dev->recvbuf[1]);
- memmove (dev->recvbuf, dev->recvbuf + 2, dev->recvbuf_fill - 2);
- dev->recvbuf_fill -= 2;
- }
-
- /* Scan the buffer and shift it down if we detect a full command */
- size_t reply_span, term_span;
- while (1) {
- /* How many non terminator chars and how many terminator chars after them */
- reply_span = strcspn (dev->recvbuf, REPLY_TERMINATOR);
- term_span = strspn (dev->recvbuf + reply_span, REPLY_TERMINATOR);
-
- if (term_span > 0) {
- if (reply_span > 0)
- handle_reply (dev, dev->recvbuf, reply_span, term_span);
- /* else - perhaps a prepended \n having sent in reaction to \r previously */
-
- size_t len = reply_span + term_span;
- //assert (dev->recvbuf_fill >= len);
- if (dev->recvbuf_fill < len) {
- return -1;
- }
- dev->recvbuf_fill -= len;
- memmove (dev->recvbuf, dev->recvbuf + len, dev->recvbuf_fill + 1);
- continue;
- }
- break;
- }
-
- return 0;
-}
-
-/* free extra elements at the end of the sentcache */
-static void
-shrink_sentcache (rr_dev dev)
-{
- int i;
- blocknode *next, *l = dev->sendhead[RR_PRIO_SENTCACHE];
- for (i = 0; i < dev->sentcachesize; i++)
- l = l ? l->next : NULL;
- if (!l)
- return;
- dev->sendtail[RR_PRIO_SENTCACHE] = l;
- next = l->next;
- l->next = NULL;
-
- for (l = next; l; l = next) {
- next = l->next;
- blocknode_free (l);
- dev->sendsize[RR_PRIO_SENTCACHE]--;
- }
-}
-
-int
-rr_dev_handle_writable (rr_dev dev)
-{
- ssize_t result;
-
- if (dev->sendbuf_fill == 0) {
- if (dev->init_send_count <= 0 && !dev->send_next) {
- rr_dev_log (dev, RR_DEBUG_MEDIUM,
- "writeable - init count is %d, no send_next queue %d resend %d\n",
- dev->init_send_count, dev->dev_cmdqueue_size,
- dev->sendsize[RR_PRIO_RESEND]);
- /* wait until there is space in the device buffer and/or an ok */
- dev->wait_wr_cb (dev, 0, dev->wait_wr_cl);
- return 0;
- }
-
- /* Last block is gone; prepare to send a new block */
- int prio;
- blocknode *node = NULL;
- for (prio = RR_PRIO_COUNT - 1; prio >= 0; --prio) {
-
- if (dev->paused[prio])
- continue;
-
- node = dev->sendhead[prio];
- if (node) {
- /* We have a block to send! Get it ready. */
- dev->bytes_sent = 0;
- result = fmtblock (dev, node);
- if (result < 0) {
- /* FIXME: This will confuse code expecting errno to be set */
- return result;
- }
- if (result == 0)
- rr_dev_log (dev, RR_DEBUG_ALWAYS,
- "unusual error - nothing in block to write\n");
-
- dev->send_next = 0;
- dev->sendbuf_fill = result;
- dev->sending_prio = prio;
- break;
- }
- }
- if (!node) {
- /* No data to write */
- dev->wait_wr_cb (dev, 0, dev->wait_wr_cl);
- return 0;
- }
- }
-
- /* Perform write */
- do {
- result = write (dev->fd, dev->sendbuf + dev->bytes_sent, dev->sendbuf_fill - dev->bytes_sent);
- } while (result < 0 && errno == EINTR);
-
- if (result < 0)
- return result;
-
- if (dev->opt_log_cb)
- dev->opt_log_cb (dev, RR_LOG_SEND, dev->sendbuf + dev->bytes_sent,
- dev->sendbuf_fill - dev->bytes_sent,
- dev->opt_log_cl);
-
- dev->bytes_sent += result;
-
- if (dev->bytes_sent == dev->sendbuf_fill) {
- /* We've sent the complete block. */
- blocknode *node = rr_dev_pop_from_queue (dev, dev->sending_prio);
-
- if (node->line < 0) {
- node->line = dev->lineno;
- ++(dev->lineno);
- }
-
- /* Update sent cache */
- assert (node->block != NULL);
- rr_dev_prepend_to_queue (dev, RR_PRIO_SENTCACHE, node);
- if (dev->sendsize[RR_PRIO_SENTCACHE] > (dev->sentcachesize * 3 / 2))
- shrink_sentcache (dev);
-
- /* Indicate that we're ready for the next. */
- dev->sendbuf_fill = 0;
- }
-
- return result;
-}
-
-int rr_flush (rr_dev dev)
-{
-#ifndef WIN32
- /* Disable non-blocking mode */
- int flags;
- if ((flags = fcntl (dev->fd, F_GETFL, 0)) < 0)
- return flags;
-
- if (fcntl (dev->fd, F_SETFL, flags & ~O_NONBLOCK) == -1)
- return -1;
-#endif
-
- int result = 0;
- while (rr_dev_buffered (dev) && result >= 0)
- result = rr_dev_handle_writable (dev);
-
-#ifndef WIN32
- /* Restore original mode */
- if (result >= 0)
- result = fcntl (dev->fd, F_SETFL, flags);
- else
- fcntl (dev->fd, F_SETFL, flags);
-#endif
-
- return result;
-}
-
-#ifndef WIN32
-int
-rr_dev_fd (rr_dev dev)
-{
- return dev->fd;
-}
-#endif
-
-int
-rr_dev_is_connected (rr_dev dev)
-{
- return SERIAL_INVALID_CHECK(dev->fd) < 0 ? 0 : 1;
-}
-
-unsigned long
-rr_dev_lineno (rr_dev dev)
-{
- return dev->lineno;
-}
-
-int
-rr_dev_buffered_lines (rr_dev dev)
-{
- int i, size = 0;
- for (i = 0; i < RR_PRIO_COUNT; i++)
- size += dev->sendsize[i];
- return size;
-}
-
-int
-rr_dev_buffered (rr_dev dev)
-{
- if (rr_dev_buffered_lines (dev) > 0)
- return 1;
- else
- return dev->sendbuf_fill;
-}
-
-int
-rr_dev_write_more (rr_dev dev)
-{
- /* arbitrarily keep a cmdqueue of the same size internally */
- return rr_dev_buffered_lines (dev) < dev->dev_cmdqueue_size;
-}
-
-void
-rr_dev_enable_debugging (rr_dev dev, int debug_output)
-{
- dev->debug_output = debug_output;
-}
-
-void
-rr_dev_set_paused (rr_dev dev, int priority, int paused)
-{
- dev->paused[priority] = paused;
-
- /* re-start client's writing */
- if (!paused) {
- dev->more_cb (dev, dev->more_cl);
- dev->wait_wr_cb (dev, 1, dev->wait_wr_cl);
- }
-}
-
-/* Helper for emitting and returning errors */
-rr_error
-rr_dev_emit_error (rr_dev dev, rr_error err, const char *block, int nbytes)
-{
- if (dev->error_cb)
- dev->error_cb (dev, err, block, nbytes, dev->error_cl);
- return err;
-}
-
-/* What an horrible method - the protocol is so bad flow control
- wise we can jam up, and need to be coaxed back into life */
-void
-rr_dev_kick (rr_dev dev)
-{
- dev->send_next = 1;
- dev->init_send_count = dev->dev_cmdqueue_size - 1;
- dev->wait_wr_cb (dev, 1, dev->wait_wr_cl);
-}
View
147 libraries/libreprap/comms.h
@@ -1,147 +0,0 @@
-#ifndef _REPRAP_COMMS_H_
-#define _REPRAP_COMMS_H_
-
-#include <sys/types.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define BLOCK_TERMINATOR "\r\n"
-#define BLOCK_TERMINATOR_LEN 2
-#define REPLY_TERMINATOR "\r\n"
-
-typedef enum {
- /* Standard gcode, 'ok' response */
- RR_PROTO_SIMPLE,
- /* Simple + line numbers, checksums, mandatory feedrate */
- RR_PROTO_FIVED,
- /* 5D with different syntax for some absurd reason */
- RR_PROTO_TONOKIP,
-} rr_proto;
-
-typedef enum {
- RR_E_BLOCK_TOO_LARGE = -1,
- RR_E_WRITE_FAILED = -2,
- RR_E_UNSUPPORTED_PROTO = -3,
- RR_E_UNKNOWN_REPLY = -4,
- RR_E_UNCACHED_RESEND = -5,
- RR_E_HARDWARE_FAULT = -6,
- RR_E_UNSENT_RESEND = -7,
- RR_E_MALFORMED_RESEND_REQUEST = -8,
-} rr_error;
-
-/* Must be ordered ascending by priority */
-typedef enum {
- RR_PRIO_NORMAL = 0,
- RR_PRIO_HIGH,
- RR_PRIO_RESEND,
- RR_PRIO_COUNT,
- RR_PRIO_SENTCACHE, // internal impl. detail
- RR_PRIO_ALL_QUEUES
-} rr_prio;
-
-typedef enum {
- RR_OK,
- RR_NOZZLE_TEMP,
- RR_BED_TEMP,
- RR_X_POS,
- RR_Y_POS,
- RR_Z_POS,
- RR_E_POS,
-} rr_reply;
-
-typedef enum {
- RR_LOG_RECV,
- RR_LOG_SEND,
- RR_LOG_MSG
-} rr_logtype;
-
-typedef struct rr_dev_t *rr_dev;
-
-/* Got a reply we can parse, of type 'type' and value 'value' */
-typedef void (*rr_reply_fn) (rr_dev dev, int type, float value,
- void *expansion, void *closure);
-/* Called when we should write more to the device */
-typedef void (*rr_more_fn) (rr_dev dev, void *closure);
-/* Called on error - with a suitable message etc. */
-typedef void (*rr_error_fn) (rr_dev dev, int error_code, const char *msg, size_t len, void *closure);
-/* Called when we cannot write more, to wait for buffer space */
-typedef void (*rr_wait_wr_fn) (rr_dev dev, int wait, void *closure);
-/* We sent or recieved some data - tell the world so we can log it */
-typedef void (*rr_log_fn) (rr_dev dev, int type, const char *buffer, size_t len, void *closure);
-
-/* Initializes device with supplied params */
-/* Note that want_writable may be called redundantly. */
-rr_dev rr_dev_create (rr_proto proto,
- /* how many commands can we push */
- size_t dev_cmdqueue_size,
- /* callbacks cf. above */
- rr_reply_fn reply_cb, void *reply_cl,
- rr_more_fn more_cb, void *more_cl,
- rr_error_fn error_cb, void *error_cl,
- /* notify when socket is writeable */
- rr_wait_wr_fn wait_wr_cb, void *wait_wr_cl,
- /* optional (or NULL, NULL) */
- rr_log_fn opt_log_cb, void *opt_log_cl);
-void rr_dev_free (rr_dev dev);
-
-int rr_dev_open (rr_dev dev, const char *port, long speed);
-int rr_dev_close (rr_dev dev);
-void rr_dev_reset_lineno (rr_dev dev);
-void rr_dev_reset (rr_dev dev);
-void rr_dev_reset_device (rr_dev dev);
-void rr_dev_kick (rr_dev dev);
-
-/* Accessors */
-#ifndef WIN32
-/* File descriptor; <0 if not connected */
-int rr_dev_fd (rr_dev dev);
-#else
-/* FIXME: Win32 equivalent for rr_dev_fd()? */
-#endif
-/* Returns 1 if connected, 0 if not */
-int rr_dev_is_connected (rr_dev dev);
-
-/* Number of lines that have been since open */
-unsigned long rr_dev_lineno (rr_dev dev);
-
-/* Returns nonzero if and only if there is data waiting to be written */
-int rr_dev_buffered (rr_dev dev);
-
-/* Returns count of commands that are buffered & un-written */
-int rr_dev_buffered_lines (rr_dev dev);
-
-/* Returns nonzero if dev can accept more data */
-int rr_dev_write_more (rr_dev dev);
-
-/* Pause or resume a priority queue */
-void rr_dev_set_paused (rr_dev dev, int priority, int paused);
-
-/* Enable lots more comms debugging output */
-void rr_dev_enable_debugging (rr_dev dev, int debug_output);
-
-/* I/O abstraction for integration into
- system mainloops in combination with
- wait_wr_cb */
-
-/* Call when there is data to read */
-int rr_dev_handle_readable(rr_dev dev);
-/* Call when there is space to write */
-int rr_dev_handle_writable(rr_dev dev);
-
-/* use to check if it is sensible to enqueue more commands */
-int rr_dev_queue_size (rr_dev dev);
-
-/* nbytes MUST be < GCODE_BLOCKSIZE, or -1 to for strlen(block) */
-/* returns non-zero on failure */
-int rr_dev_enqueue_cmd (rr_dev dev, rr_prio priority, const char *block, int opt_nbytes);
-
-/* Blocks until all buffered data has been written */
-int rr_flush (rr_dev dev);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
View
80 libraries/libreprap/comms_private.h
@@ -1,80 +0,0 @@
-#ifndef _COMMS_PRIVATE_H_
-#define _COMMS_PRIVATE_H_
-
-/* size_t */
-#include <stdlib.h>
-
-#include "comms.h"
-#include "serial.h"
-
-#define RR_DEBUG_ALWAYS 0
-#define RR_DEBUG_MEDIUM 1
-#define RR_DEBUG_HIGH 2
-
-/* Do not change */
-#define GCODE_BLOCKSIZE 256
-#define SENDBUFSIZE (GCODE_BLOCKSIZE + BLOCK_TERMINATOR_LEN)
-#define INITIAL_RECVBUFSIZE 256
-
-typedef struct blocknode {
- struct blocknode *next;
- char *block;
- size_t blocksize;
- long long line;
-} blocknode;
-
-struct rr_dev_t {
- rr_proto proto;
- int dev_cmdqueue_size;
- rr_reply_fn reply_cb; void *reply_cl;
- rr_more_fn more_cb; void *more_cl;
- rr_error_fn error_cb; void *error_cl;
- rr_wait_wr_fn wait_wr_cb; void *wait_wr_cl;
- rr_log_fn opt_log_cb; void *opt_log_cl;
-
- Serial fd;
- /* Line currently being sent */
- unsigned long lineno;
-
- int init_send_count;
- int send_next;
- int sendsize[RR_PRIO_ALL_QUEUES];
- blocknode *sendhead[RR_PRIO_ALL_QUEUES];
- blocknode *sendtail[RR_PRIO_ALL_QUEUES];
- int paused[RR_PRIO_ALL_QUEUES];
- char sendbuf[SENDBUFSIZE];
- rr_prio sending_prio;
- size_t sendbuf_fill;
- size_t bytes_sent;
-
- char *recvbuf;
- size_t recvbufsize;
- size_t recvbuf_fill;
-
- size_t sentcachesize;
-
- int debug_output;
-};
-
-/* Re-send a line number */
-int rr_dev_resend (rr_dev device, unsigned long lineno, const char *reply, size_t nbytes);
-
-/* Helper for emitting and returning errors */
-rr_error rr_dev_emit_error (rr_dev dev, rr_error err, const char *block, int nbytes);
-
-/* Get flow control right */
-void rr_dev_handle_ok (rr_dev dev);
-
-/* Handle start semantics */
-int rr_dev_handle_start (rr_dev dev);
-
-/* print to the log */
-void rr_dev_log (rr_dev dev, int level, const char *format, ...);
-
-/* internal queue command allowing explicit line no. */
-int rr_dev_enqueue_internal (rr_dev dev, rr_prio priority,
- const char *block, size_t nbytes,
- long long line);
-
-
-#endif
View
97 libraries/libreprap/fived.c
@@ -1,97 +0,0 @@
-#include "fived.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-
-#include "comms_private.h"
-
-static void
-float_reply (rr_dev dev, char **i, rr_reply type)
-{
- if (dev->reply_cb)
- dev->reply_cb (dev, type, strtof (*i + 2, i), NULL, dev->reply_cl);
-}
-
-int
-fived_handle_reply (rr_dev dev, const char *reply, size_t nbytes)
-{
- int okoffset = 2;
- // a single T/B message (waiting for warm up (M109/M190)):
- if (!strncasecmp ("T:", reply, 2) ||
- !strncasecmp ("B:", reply, 2)) okoffset = 0;
- if (okoffset==0 || !strncasecmp ("ok", reply, 2)) {
- rr_dev_handle_ok (dev);
-
- /* Parse values */
- char *i;
- for (i = (char*)reply + okoffset; i < reply + nbytes; ++i) {
- if (isspace (*i))
- continue;
- switch (toupper (*i)) {
- case 'T':
- float_reply (dev, &i, RR_NOZZLE_TEMP);
- break;
- case 'B':
- float_reply (dev, &i, RR_BED_TEMP);
- break;
- case 'C':
- break;
- case 'X':
- float_reply (dev, &i, RR_X_POS);
- break;
- case 'Y':
- float_reply (dev, &i, RR_Y_POS);
- break;
- case 'Z':
- float_reply (dev, &i, RR_Z_POS);
- break;
- case 'E':
- float_reply (dev, &i, RR_E_POS);
- break;
- default:
- break;
- //return rr_dev_emit_error (dev, RR_E_UNKNOWN_REPLY, reply, nbytes);
- }
- }
- return 0;
-
- } else if (!strncasecmp ("rs", reply, 2) ||
- !strncasecmp ("resend", reply, 6)) {
- /* check where the line number starts */
- size_t n_start = strcspn (reply, "123456789");
- if (n_start) {
- long long lineno = strtoll (reply + n_start, NULL, 10);
-
- if (dev->sendsize[RR_PRIO_SENTCACHE] +
- dev->sendsize[RR_PRIO_RESEND] <= 1) {
- /*
- * oh dear - most likely we re-connected to a device that
- * had problems mid-flow, now we need to re-send the
- * line-number reset as if it was this line-no it is asking
- * for a re-send of, or there will be no peace
- */
- rr_dev_log (dev, RR_DEBUG_ALWAYS,
- "resetting confused firmware with synthetic resend of line %d\n",
- lineno);
- rr_dev_enqueue_internal (dev, RR_PRIO_HIGH, "M110", 4, lineno);
- /* re-start the print */
- rr_dev_resend (dev, 0, "synthetic restart", 16);
- return rr_dev_emit_error (dev, RR_E_UNSENT_RESEND, reply, nbytes);
- }
- return rr_dev_resend (dev, lineno, reply, nbytes);
- } else
- return rr_dev_emit_error (dev, RR_E_MALFORMED_RESEND_REQUEST, reply, nbytes);
-
- } else if (!strncmp("!!", reply, 2)) {
- return rr_dev_emit_error (dev, RR_E_HARDWARE_FAULT, reply, nbytes);
-
- } else if (!strncasecmp ("start", reply, 5)) {
- return rr_dev_handle_start (dev);
-
- } else if (!strncasecmp ("echo", reply, 4)) {
- return 0;
-
- } else
- return rr_dev_emit_error (dev, RR_E_UNKNOWN_REPLY, reply, nbytes);
-}
View
8 libraries/libreprap/fived.h
@@ -1,8 +0,0 @@
-#ifndef _FIVED_H_
-#define _FIVED_H_
-
-#include "comms.h"
-
-int fived_handle_reply(rr_dev device, const char *reply, size_t nbytes);
-
-#endif
View
388 libraries/libreprap/serial.c
@@ -1,388 +0,0 @@
-#include "serial.h"
-
-#ifdef WIN32
-/* Pull in win32 source file instead */
-#include "serialwin32.c"
-#else
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <termios.h>
-#include <errno.h>
-
-
-#ifdef __linux__
-//#ifdef HAVE_ASM_IOCTLS_H
-#include <asm/ioctls.h>
-#include <sys/ioctl.h>
-//#endif
-
-struct linux_serial_struct {
- int type;
- int line;
- int port;
- int irq;
- int flags;
- int xmit_fifo_size;
- int custom_divisor;
- int baud_base;
- unsigned short close_delay;
- char io_type;
- char reserved_char[1];
- int hub6;
- unsigned short closing_wait; /* time to wait before closing */
- unsigned short closing_wait2; /* no longer used... */
- unsigned char *iomem_base;
- unsigned short iomem_reg_shift;
- int reserved[2];
-};
-#define ASYNC_SPD_MASK 0x1030
-#define ASYNC_SPD_CUST 0x0030 /* Use user-specified divisor */
-
-
-linux_set_speed_custom(int fd, long baud){
- struct linux_serial_struct serinfo;
- serinfo.reserved_char[0] = 0;
- if (ioctl(fd, TIOCGSERIAL, &serinfo) < 0) {
- perror("Cannot get serial info from port");
- return -1;
- }
- int speed = (int)baud;
- /* printf("old baud_base %li divisor %li = %li\n", */
- /* serinfo.baud_base , serinfo.custom_divisor, */
- /* serinfo.baud_base / serinfo.custom_divisor); */
-
- if ( (serinfo.baud_base / serinfo.custom_divisor) != speed ) {
- int divisor = (int)(serinfo.baud_base / baud);
- int closestSpeed = (int)(serinfo.baud_base / divisor);
- if (closestSpeed < speed * 98 / 100 || closestSpeed > speed * 102 / 100) {
- printf("Cannot set serial port speed to %li. Closest possible is %li\n",
- speed, closestSpeed);
- return -1;
- }
- serinfo.custom_divisor = divisor;
- serinfo.flags = (serinfo.flags | ASYNC_SPD_CUST);
- printf("setting baud_base %li divisor %li = %li baud\n",
- serinfo.baud_base, serinfo.custom_divisor,
- (long)(serinfo.baud_base / serinfo.custom_divisor));
- if (ioctl(fd, TIOCSSERIAL, &serinfo) < 0) {
- perror("Cannot set serial speed");
- return -1;
- }
- }
-
-#ifdef B38400
- return B38400; // this is the value used to connect
-#else
- printf("could not set custom baud rate %i", baud);
- return -1;
-#endif
-}
-
-#endif // __linux__
-
-
-// Convert between the numeric speed and the termios representation
-// thereof. Returns < 0 if argument is an unsupported speed.
-static speed_t ntocf(const long l) {
-#ifdef __linux__
- switch(l) {
-#ifdef B0
- case 0:
- return B0;
-#endif
-#ifdef B50
- case 50:
- return B50;
-#endif
-#ifdef B75
- case 75:
- return B75;
-#endif
-#ifdef B110
- case 110:
- return B110;
-#endif
-#ifdef B134
- case 134:
- return B134;
-#endif
-#ifdef B150
- case 150:
- return B150;
-#endif
-#ifdef B200
- case 200:
- return B200;
-#endif
-#ifdef B300
- case 300:
- return B300;
-#endif
-#ifdef B600
- case 600:
- return B600;
-#endif
-#ifdef B1200
- case 1200:
- return B1200;
-#endif
-#ifdef B1800
- case 1800:
- return B1800;
-#endif
-#ifdef B2400
- case 2400:
- return B2400;
-#endif
-#ifdef B4800
- case 4800:
- return B4800;
-#endif
-#ifdef B9600
- case 9600:
- return B9600;
-#endif
-#ifdef B19200
- case 19200:
- return B19200;
-#endif
-#ifdef B38400
- case 38400:
- /* reset ??? */
- /* ioctl(mHandle, TIOCGSERIAL, &ss); */
- /* ss.flags &= ~ASYNC_SPD_MASK; */
- /* ioctl(mHandle, TIOCSSERIAL, &ss); */
- return B38400;
-#endif
-#ifdef B57600
- case 57600:
- return B57600;
-#endif
-#ifdef B115200
- case 115200:
- return B115200;
-#endif
-#ifdef B230400
- case 230400:
- return B230400;
-#endif
-#ifdef B460800
- case 460800:
- return B460800;
-#endif
-#ifdef B500000
- case 500000:
- return B500000;
-#endif
-#ifdef B576000
- case 576000:
- return B576000;
-#endif
-#ifdef B921600
- case 921600:
- return B921600;
-#endif
-#ifdef B1000000
- case 1000000:
- return B1000000;
-#endif
-#ifdef B1152000
- case 1152000:
- return B1152000;
-#endif
-#ifdef B1500000
- case 1500000:
- return B1500000;
-#endif
-#ifdef B2000000
- case 2000000:
- return B2000000;
-#endif
-#ifdef B2500000
- case 2500000:
- return B2500000;
-#endif
-#ifdef B3000000
- case 3000000:
- return B3000000;
-#endif
-#ifdef B3500000
- case 3500000:
- return B3500000;
-#endif
-#ifdef B4000000
- case 4000000:
- return B4000000;
-#endif
- default:
- printf( "non-standard baudrate %i\n", l);
- return -1;
- }
-#else /* non-linux : */
- return (speed_t) l;
-#endif // __linux__
-}
-
-// Repeated many times to allow errors to be isolated to the specific
-// setting that failed to apply. Returns < 0 on failure.
-static int
-serial_set_attrib(int fd, struct termios* attribp) {
- if(tcsetattr(fd, TCSANOW, attribp) < 0) {
- return -1;
- }
- return 0;
-}
-
-static int
-serial_init(int fd, long speed, char **detail)
-{
- int status;
- struct termios attribs;
- // Initialize attribs
- if(tcgetattr(fd, &attribs) < 0) {
- int tmp = errno;
- *detail = "not a serial device";
- close(fd);
- errno = tmp;
- return -1;
- }
-
- /* Handle software flow control bytes from machine */
- attribs.c_iflag |= IXOFF;
- serial_set_attrib(fd, &attribs);
- if((status = serial_set_attrib(fd, &attribs)) < 0) {
- *detail = "serial device has no flow control";
- return status;
- }
-
- /* Set speed */
- {
- speed_t cfspeed = ntocf(speed);
- if(cfsetispeed(&attribs, cfspeed) < 0) {
-#ifdef __linux__
- if (linux_set_speed_custom(fd, speed) < 0){
- *detail = "can't set input speed";
- return -1;
- }
-#else
- *detail = "can't set input speed";
- return -1;
-#endif
- }
- serial_set_attrib(fd, &attribs);
- if(cfsetospeed(&attribs, cfspeed) < 0) {
- *detail = "can't set ouput speed";
- return -1;
- }
- serial_set_attrib(fd, &attribs);
- }
-
- /* Set non-canonical mode */
- attribs.c_cc[VTIME] = 0;
- if((status = serial_set_attrib(fd, &attribs)) < 0) {
- *detail = "can't set non-canonical mode (vtime)";
- return status;
- }
- attribs.c_cc[VMIN] = 0;
- if((status = serial_set_attrib(fd, &attribs)) < 0) {
- *detail = "can't set non-canonical mode (vmin)";
- return status;
- }
- cfmakeraw(&attribs);
- if((status = serial_set_attrib(fd, &attribs)) < 0) {
- *detail = "can't set raw mode";
- return status;
- }
-
- /* Prevents DTR from being dropped, resetting the MCU when using
- * an Arduino bootloader */
- attribs.c_cflag &= ~HUPCL;
- if((status = serial_set_attrib(fd, &attribs)) < 0) {
- *detail = "can't prevent DTR from being dropped";
- return status;
- }
-
- return 0;
-}
-
-/* Returns a prepared FD for the serial device specified, or some
- * value < 0 if an error occurred. */
-Serial serial_open(const char *path, long speed, char **error)
-{
- int fd;
- int flags;
- int status;
- char *detail = NULL;
-
- *error = NULL;
- do {
- fd = open(path, O_RDWR | O_NOCTTY | O_NDELAY);
- } while(fd < 0 && errno == EINTR);
- if(fd < 0)
- {
- detail = "failed to open socket path";
- goto err_out;
- }
-
- if((status = serial_init(fd, speed, &detail)) < 0)
- goto err_out;
-
- if((flags = fcntl(fd, F_GETFL, 0)) < 0) {
- detail = "getting socket flags";
- goto err_out;
- }
-
- if(fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) {
- detail = "setting non-blocking flag on socket";
- goto err_out;
- }
- return fd;
- err_out:
- {
- const char *errstr = strerror(errno);
- *error = malloc(strlen(detail) + strlen (path) + strlen(errstr) + 64);
- strcpy (*error, "Error opening port '");
- strcat (*error, path);
- strcat (*error, "' - ");
- strcat (*error, detail);
- strcat (*error, " : ");
- strcat (*error, errstr);
- }
- close (fd);
- return -1;
-}
-
-int
-serial_close(Serial fd)
-{
- int result;
-
- if (SERIAL_INVALID_CHECK(fd) >= 0) {
- do {
- result = close (fd);
- } while (result < 0 && errno == EINTR);
- }
-
- return result;
-}
-
-
-int
-serial_setDTR(Serial fd, short dtr)
-{
- /* printf("DTR %i\n",dtr); */
- char TIOCM_DTR_str[4];
- sprintf(TIOCM_DTR_str, "%u", TIOCM_DTR);
- if (dtr==1)
- ioctl(fd, TIOCMBIS, TIOCM_DTR_str);
- else if (dtr==0)
- ioctl(fd, TIOCMBIC, TIOCM_DTR_str);
-
-}
-
-#endif // !WIN32
View
28 libraries/libreprap/serial.h
@@ -1,28 +0,0 @@
-#ifndef _SERIAL_H_
-#define _SERIAL_H_
-
-#include <sys/types.h>
-#ifdef WIN32
-#include <windows.h>
-#endif
-
-#ifndef WIN32
-typedef int Serial;
-#define SERIAL_INVALID_INIT (-1)
-/* Return -1 for an invalid Serial instance, 0 if valid */
-#define SERIAL_INVALID_CHECK(s) ((s) < 0 ? -1 : 0)
-#else
-typedef HANDLE Serial;
-#define SERIAL_INVALID_INIT (NULL)
-#define SERIAL_INVALID_CHECK(s) ((s) == NULL ? -1 : 0)
-#endif
-
-/* Opens serial port at path and speed.
- * Returns -1 on error, and allocated error
- * you need to free.
- */
-Serial serial_open(const char *path, long speed, char **error);
-/* Close a serial port. Can be called with an INVALID Serial instance */
-int serial_close(Serial fd);
-
-#endif
View
18 libraries/libreprap/serialwin32.c
@@ -1,18 +0,0 @@
-
-Serial
-serial_open(const char *path, long speed, char **error) {
-}
-
-int
-serial_close(Serial fd) {
-}
-
-int
-serial_setDTR(Serial fd, short dtr)
-{
-}
-
-int
-serial_flipDTR(Serial fd)
-{
-}
View
33 libraries/libreprap/tonokip.c
@@ -1,33 +0,0 @@
-#include "tonokip.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "comms_private.h"
-
-int
-tonokip_handle_reply (rr_dev dev, const char *reply, size_t nbytes) {
-
- if (!strncasecmp ("ok", reply, 2)) {
- rr_dev_handle_ok (dev);
- if (dev->reply_cb)
- dev->reply_cb (dev, RR_OK, 0.0, NULL, dev->reply_cl);
- return 0;
-
- } else if (!strncasecmp ("Resend:", reply, 7)) {
- /* Line number begins 7 bytes in */
- return rr_dev_resend (dev, atoll (reply + 7), reply, nbytes);
-
- } else if (!strncmp("T:", reply, 2)) {
- if (dev->reply_cb) {
- char *point = (char *)reply + 2;
- dev->reply_cb (dev, RR_NOZZLE_TEMP, strtof (reply + 2, &point), NULL, dev->reply_cl);
-
- if (!strncmp("B:", point + 1, 2))
- dev->reply_cb (dev, RR_BED_TEMP, strtof (point + 3, NULL), NULL, dev->reply_cl);
- }
- return 0;
-
- } else
- return rr_dev_emit_error (dev, RR_E_UNKNOWN_REPLY, reply, nbytes);
-}
View
8 libraries/libreprap/tonokip.h
@@ -1,8 +0,0 @@
-#ifndef _TONOKIP_H_
-#define _TONOKIP_H_
-
-#include "comms.h"
-
-int tonokip_handle_reply(rr_dev device, const char *reply, size_t nbytes);
-
-#endif
View
48 libraries/libreprap/util.c
@@ -1,48 +0,0 @@
-#include "util.h"
-
-#include <stdlib.h>
-#include <sys/types.h>
-#include <dirent.h>
-#include <string.h>
-#include <stdio.h>
-
-#define DEV_PATH "/dev/"
-#define DEV_PREFIXES ((char*[]){"ttyUSB", "ttyACM", NULL})
-#define GUESSES 8
-
-char **rr_enumerate_ports() {
- size_t size = 4, fill = 0;
- char **ports = malloc(size * sizeof(char*));
- DIR *devdir = opendir(DEV_PATH);
- if(!devdir) {
- return NULL;
- }
-
- struct dirent *file;
- while((file = readdir(devdir))) {
- size_t i;
- for(i = 0; DEV_PREFIXES[i]; ++i) {
- char *prefix = DEV_PREFIXES[i];
- if(!strncmp(file->d_name, prefix, strlen(prefix))) {
- /* TODO: Open connection and interrogate device */
- if(fill >= size) {
- size *= 2;
- ports = realloc(ports, size * sizeof(char*));
- }
- ports[fill] = malloc(strlen(file->d_name)+strlen(DEV_PATH)+1);
- strcpy(ports[fill], DEV_PATH);
- strcat(ports[fill], file->d_name);
- ++fill;
- }
- }
- }
- closedir(devdir);
-
- if(fill >= size) {
- ++size;
- ports = realloc(ports, size * sizeof(char*));
- }
- ports[fill] = NULL;
-
- return ports;
-}
View
15 libraries/libreprap/util.h
@@ -1,15 +0,0 @@
-#ifndef _REPRAP_UTIL_H_
-#define _REPRAP_UTIL_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Returns a NULL-terminated array of strings */
-char **rr_enumerate_ports();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
View
19 src/Makefile.am
@@ -13,6 +13,12 @@ bin_PROGRAMS = repsnapper
LIB_DIR=$(top_srcdir)/libraries
WARNING_FLAGS = -Wall -Wsign-compare -Wno-invalid-offsetof
+repsnapperdatadir = $(datadir)/@PACKAGE@
+dist_repsnapperdata_DATA = src/repsnapper.ui
+
+repsnapperconfdir = $(sysconfdir)/xdg/@PACKAGE@
+dist_repsnapperconf_DATA = src/repsnapper.conf
+
repsnapper_CPPFLAGS = \
-I$(LIB_DIR)/vmmlib/include \
-I$(LIB_DIR)/lmfit/lmfit-3.2/lib \
@@ -22,7 +28,6 @@ repsnapper_CPPFLAGS = \
-I$(top_builddir)/src \
-I$(LIB_DIR) \
-DHAVE_GTK $(CFLAGS) $(EXTRA_CFLAGS) -I$(LIB_DIR) $(GTKMM_CFLAGS) \
- $(LIBREPRAP_CFLAGS) \
-DRSDATADIR='$(repsnapperdatadir)' \
-DSYSCONFDIR='$(repsnapperconfdir)' \
-DLOCALEDIR='"$(localedir)"' \
@@ -79,16 +84,8 @@ FORCE:
built_header_make=src/gitversion.h
BUILT_SOURCES += $(built_header_make)
-EXTRA_DIST += $(built_header_make) \
- src/printer/printer_libreprap.cpp \
- src/printer/printer_iochannel.cpp
+EXTRA_DIST += $(built_header_make)
repsnapper_LDFLAGS = $(EXTRA_LDFLAGS)
-repsnapper_LDADD = libreprap.la libclipper.la libpoly2tri.la liblmfit.la libamf.la $(OPENMP_CFLAGS) $(OPENVRML_LIBS) $(GTKMM_LIBS) $(GL_LIBS) $(XMLPP_LIBS) $(LIBZIP_LIBS) $(BOOST_LDFLAGS)
-
-repsnapperdatadir = $(datadir)/@PACKAGE@
-dist_repsnapperdata_DATA = src/repsnapper.ui
-
-repsnapperconfdir = $(sysconfdir)/xdg/@PACKAGE@
-dist_repsnapperconf_DATA = src/repsnapper.conf
+repsnapper_LDADD = libclipper.la libpoly2tri.la liblmfit.la libamf.la $(OPENMP_CFLAGS) $(OPENVRML_LIBS) $(GTKMM_LIBS) $(GL_LIBS) $(XMLPP_LIBS) $(LIBZIP_LIBS) $(BOOST_LDFLAGS)
View
2 src/model.cpp
@@ -24,8 +24,6 @@
#include <functional>
#include <numeric>
-#include <libreprap/comms.h>
-
#include "stdafx.h"
#include "model.h"
#include "objtree.h"
View
2 src/model_slice.cpp
@@ -30,8 +30,6 @@
#include <sys/types.h>
#include <dirent.h>
-#include <libreprap/comms.h>
-
#ifdef _OPENMP
#include <omp.h>
#endif

0 comments on commit 851af06

Please sign in to comment.
Something went wrong with that request. Please try again.