diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2016-11-30 11:33:44 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2016-11-30 13:33:16 -0500 |
commit | b14db404b55424ef783a163a02da8868120b36c9 (patch) | |
tree | a100ccc1d8a63af86f0fa57fa70c48c124014ad9 /klippy/serialqueue.c | |
parent | 7cb71df02cbe417798067a4f68a62dcbca8be025 (diff) | |
download | kutter-b14db404b55424ef783a163a02da8868120b36c9.tar.gz kutter-b14db404b55424ef783a163a02da8868120b36c9.tar.xz kutter-b14db404b55424ef783a163a02da8868120b36c9.zip |
pyhelper: Move helper functions from serialqueue.c to new file
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/serialqueue.c')
-rw-r--r-- | klippy/serialqueue.c | 60 |
1 files changed, 1 insertions, 59 deletions
diff --git a/klippy/serialqueue.c b/klippy/serialqueue.c index 0700ecc3..6274e277 100644 --- a/klippy/serialqueue.c +++ b/klippy/serialqueue.c @@ -12,7 +12,6 @@ // clock times, prioritizes commands, and handles retransmissions. A // background thread is launched to do this work and minimize latency. -#include <errno.h> // errno #include <math.h> // ceil #include <poll.h> // poll #include <pthread.h> // pthread_mutex_lock @@ -21,71 +20,14 @@ #include <stdio.h> // snprintf #include <stdlib.h> // malloc #include <string.h> // memset -#include <sys/time.h> // gettimeofday -#include <time.h> // struct timespec #include <termios.h> // tcflush #include <unistd.h> // pipe #include "list.h" // list_add_tail +#include "pyhelper.h" // get_time #include "serialqueue.h" // struct queue_message /**************************************************************** - * Helper functions - ****************************************************************/ - -// Return the current system time as a double -static double -get_time(void) -{ - struct timeval tv; - gettimeofday(&tv, NULL); - return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.; -} - -#if 0 -// Fill a 'struct timespec' with a system time stored in a double -struct timespec -fill_time(double time) -{ - time_t t = time; - return (struct timespec) {t, (time - t)*1000000000. }; -} -#endif - -// Report 'errno' in a message written to stderr -void -report_errno(char *where, int rc) -{ - int e = errno; - fprintf(stderr, "Got error %d in %s: (%d)%s\n", rc, where, e, strerror(e)); -} - -// Return a hex character for a given number -#define GETHEX(x) ((x) < 10 ? '0' + (x) : 'e' + (x) - 10) - -// Translate a binary string into an ASCII string with escape sequences -char * -dump_string(char *outbuf, int outbuf_size, uint8_t *inbuf, int inbuf_size) -{ - char *outend = &outbuf[outbuf_size-5], *o = outbuf; - uint8_t *inend = &inbuf[inbuf_size], *p = inbuf; - while (p < inend && o < outend) { - uint8_t c = *p++; - if (c > 31 && c < 127 && c != '\\') { - *o++ = c; - continue; - } - *o++ = '\\'; - *o++ = 'x'; - *o++ = GETHEX(c >> 4); - *o++ = GETHEX(c & 0x0f); - } - *o = '\0'; - return outbuf; -} - - -/**************************************************************** * Poll reactor ****************************************************************/ |