35 Commits

Author SHA1 Message Date
zacharyc
ec1ae04a5b Bumped version number and finished fixing up Windows autodetect support.
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7454 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-04-17 17:06:26 +00:00
zacharyc
67163dc1a2 Added Windows stub support for autodetection.
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7453 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-04-17 16:14:36 +00:00
zacharyc
a29bf180ab Implemented Jim's hdhomerun autodetect for POSIX. Works great.
Windows testing next.


git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7452 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-04-17 15:57:42 +00:00
zacharyc
4cccb783f0 Fixed up "range" argument
Took Jim's suggestions about addressing and device options
Made autodetection a better fallback.


git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7450 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-04-16 23:12:15 +00:00
nilm
5e7f4ac97e Increased timeout to at least 1 minute
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7433 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-04-14 15:49:53 +00:00
zacharyc
a57c0c22c2 Massive cleanup and refactoring of data_stream function.
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7431 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-04-11 17:35:54 +00:00
zacharyc
2e3f2f4b23 Made ethstream reset a little easier.
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7426 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-04-10 20:35:36 +00:00
zacharyc
4592b6a75b Changed nerdjack limits
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7423 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-04-10 17:17:39 +00:00
nilm
d1447e2af8 Changed clock again
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7421 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-04-10 15:58:33 +00:00
nilm
b9130788f2 Fixed annoying bug with NerdJack header
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7419 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-04-09 22:00:15 +00:00
nilm
ed150ead35 Changed around packet structure
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7416 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-04-08 15:37:07 +00:00
nilm
519a0c2e29 Made changes to ethstream to work with new clock
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7415 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-04-07 15:38:19 +00:00
zacharyc
190fd3f3a7 Reverted clock change.
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7406 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-04-03 17:44:57 +00:00
zacharyc
9c174d12b0 Forgot a carriage return
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7404 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-04-03 17:04:29 +00:00
zacharyc
b1e049eed0 Changed clock rate of NerdJack and added error checking to packets
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7403 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-04-03 17:03:00 +00:00
zacharyc
d461365275 Added better error recovery code.
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7314 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-03-19 22:19:05 +00:00
zacharyc
a4eede145b Added limits to issue warnings about high sample rates
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7303 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-03-18 22:36:31 +00:00
zacharyc
6562c0b787 Fixed bug when output pipe is closed without a KILL signal
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7301 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-03-18 17:27:46 +00:00
zacharyc
7f79ec8ff3 Ran indent on code to fix inconsistent style.
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7298 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-03-18 15:23:10 +00:00
zacharyc
1dd09ea52d Made timeouts more reasonable for small sample rates.
Fixed error in period calculation's interaction with the PWM bug


git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7297 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-03-18 15:20:41 +00:00
zacharyc
ded6c7e5f4 Removed silicon workaround
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7289 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-03-17 21:32:50 +00:00
zacharyc
f2d6566051 Packet reordering shifted PC side.
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7287 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-03-17 21:07:18 +00:00
zacharyc
357e808986 Introduced usage of full 20 bits of PWM period counter
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7286 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-03-17 20:25:49 +00:00
zacharyc
0ed2935deb Better command structure using hton, ntoh, and friends
Altered command structure to support full 20 bit period


git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7282 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-03-13 20:33:52 +00:00
zacharyc
1a2ed51d0c Added one second sleep in code to let nerdjack recover from previous run
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7274 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-03-12 21:50:37 +00:00
zacharyc
679b4ef64f Fixed a few bugs to increase reliability and drop first line.
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7262 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-03-09 21:36:59 +00:00
zacharyc
770a83b8f7 Fixed bug in precision argument for ethstream
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7260 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-03-09 18:12:09 +00:00
zacharyc
627a1bf22b Slight bit of code cleanup. More to come
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7254 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-03-06 17:20:49 +00:00
zacharyc
43c8e19c67 Basic resume functionality working
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7250 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-03-05 21:43:25 +00:00
zacharyc
4aab606162 Fixed up rate determination and added memory test routine for NerdJack
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7235 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-03-02 16:35:54 +00:00
zacharyc
c81d372d23 Made commands fixed width
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7220 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-02-24 14:50:11 +00:00
zacharyc
407a91c764 Merged Jim's changes to ljstream. This now should respect disk full errors
and allow hex output


git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7214 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-02-23 15:47:55 +00:00
zacharyc
1d760e033b Updated ethstream to have separate Command and Data ports for NerdJack
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7212 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-02-23 14:39:26 +00:00
zacharyc
57cfac2bec Changed output format so that numbers are between 0 and 65536 instead of
signed output. This matches LabJack behavior


git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7141 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-02-02 20:09:01 +00:00
zacharyc
5b731f3e7e Now ethstream falls back from Labjack to Nerdjack
git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7140 ddd99763-3ecb-0310-9145-efcb8ce7c51f
2009-02-02 18:29:05 +00:00
21 changed files with 2528 additions and 1722 deletions

View File

@@ -21,7 +21,7 @@ BINPATH = ${PREFIX}/bin
WINCC = i386-mingw32-gcc WINCC = i386-mingw32-gcc
WINCFLAGS += $(CFLAGS) WINCFLAGS += $(CFLAGS)
WINLDFLAGS += $(LDFLAGS) -lws2_32 -s WINLDFLAGS += $(LDFLAGS) -lws2_32 -liphlpapi -s
# Targets # Targets

View File

@@ -1 +1 @@
1.0 1.1

View File

@@ -3,55 +3,83 @@
#include "compat.h" #include "compat.h"
#include <windows.h> #include <windows.h>
unsigned int sleep(unsigned int seconds) unsigned int
sleep (unsigned int seconds)
{ {
Sleep(seconds * 1000); Sleep (seconds * 1000);
return 0; return 0;
} }
static struct { static struct
int num;
char *msg;
} win32_error[] = {
/* Errors that we might vaguely expect to see */
{ WSAEINTR, "Winsock: Interrupted system call" },
{ WSAEBADF, "Winsock: Bad file number" },
{ WSAEFAULT, "Winsock: Bad address" },
{ WSAEINVAL, "Winsock: Invalid argument" },
{ WSAEMFILE, "Winsock: Too many open files" },
{ WSAEWOULDBLOCK, "Winsock: Operation would block" },
{ WSAEINPROGRESS, "Winsock: Operation now in progress" },
{ WSAEALREADY, "Winsock: Operation already in progress" },
{ WSAENOTSOCK, "Winsock: Socket operation on nonsocket" },
{ WSAEADDRINUSE, "Winsock: Address already in use" },
{ WSAEADDRNOTAVAIL, "Winsock: Cannot assign requested address" },
{ WSAENETDOWN, "Winsock: Network is down" },
{ WSAENETUNREACH, "Winsock: Network is unreachable" },
{ WSAENETRESET, "Winsock: Network dropped connection on reset" },
{ WSAECONNABORTED, "Winsock: Software caused connection abort" },
{ WSAECONNRESET, "Winsock: Connection reset by peer" },
{ WSAETIMEDOUT, "Winsock: Connection timed out" },
{ WSAECONNREFUSED, "Winsock: Connection refused" },
{ WSAEHOSTDOWN, "Winsock: Host is down" },
{ WSAEHOSTUNREACH, "Winsock: No route to host" },
{ WSAVERNOTSUPPORTED, "Winsock: Unsupported Winsock version" },
{ ETIMEDOUT, "Connection timed out" },
{ ENOTCONN, "Not connected" },
{ -1, NULL },
};
char *compat_strerror(int errnum)
{ {
int i; int num;
static char buf[128]; char *msg;
} win32_error[] =
for (i = 0; win32_error[i].num != -1; i++) {
if (errnum == win32_error[i].num) /* Errors that we might vaguely expect to see */
return win32_error[i].msg; {
if (errnum >= 10000) { WSAEINTR, "Winsock: Interrupted system call"},
sprintf(buf, "Winsock: unknown error %d\n", errnum); {
return buf; WSAEBADF, "Winsock: Bad file number"},
} {
return strerror(errnum); WSAEFAULT, "Winsock: Bad address"},
{
WSAEINVAL, "Winsock: Invalid argument"},
{
WSAEMFILE, "Winsock: Too many open files"},
{
WSAEWOULDBLOCK, "Winsock: Operation would block"},
{
WSAEINPROGRESS, "Winsock: Operation now in progress"},
{
WSAEALREADY, "Winsock: Operation already in progress"},
{
WSAENOTSOCK, "Winsock: Socket operation on nonsocket"},
{
WSAEADDRINUSE, "Winsock: Address already in use"},
{
WSAEADDRNOTAVAIL, "Winsock: Cannot assign requested address"},
{
WSAENETDOWN, "Winsock: Network is down"},
{
WSAENETUNREACH, "Winsock: Network is unreachable"},
{
WSAENETRESET, "Winsock: Network dropped connection on reset"},
{
WSAECONNABORTED, "Winsock: Software caused connection abort"},
{
WSAECONNRESET, "Winsock: Connection reset by peer"},
{
WSAETIMEDOUT, "Winsock: Connection timed out"},
{
WSAECONNREFUSED, "Winsock: Connection refused"},
{
WSAEHOSTDOWN, "Winsock: Host is down"},
{
WSAEHOSTUNREACH, "Winsock: No route to host"},
{
WSAVERNOTSUPPORTED, "Winsock: Unsupported Winsock version"},
{
ETIMEDOUT, "Connection timed out"},
{
ENOTCONN, "Not connected"},
{
-1, NULL},};
char *
compat_strerror (int errnum)
{
int i;
static char buf[128];
for (i = 0; win32_error[i].num != -1; i++)
if (errnum == win32_error[i].num)
return win32_error[i].msg;
if (errnum >= 10000)
{
sprintf (buf, "Winsock: unknown error %d\n", errnum);
return buf;
}
return strerror (errnum);
} }
#ifdef __WIN32__ #ifdef __WIN32__
@@ -80,4 +108,3 @@ char *compat_strerror(int errnum)
} }
*/ */
#endif #endif

View File

@@ -2,8 +2,8 @@
#define COMPAT_H #define COMPAT_H
#ifdef __WIN32__ #ifdef __WIN32__
unsigned int sleep(unsigned int seconds); unsigned int sleep (unsigned int seconds);
char *compat_strerror(int errnum); char *compat_strerror (int errnum);
//const char *inet_ntop(int af, void *src, const char *dst, socklen_t cnt); //const char *inet_ntop(int af, void *src, const char *dst, socklen_t cnt);
#define INET_ADDRSTRLEN 16 #define INET_ADDRSTRLEN 16
#define ETIMEDOUT 110 #define ETIMEDOUT 110

18
debug.c
View File

@@ -4,15 +4,15 @@
int verb_count = 0; int verb_count = 0;
int func_fprintf(const char *func, FILE *stream, const char *format, ...) int
func_fprintf (const char *func, FILE * stream, const char *format, ...)
{ {
va_list ap; va_list ap;
int ret; int ret;
fprintf(stream, "%s: ", func); fprintf (stream, "%s: ", func);
va_start(ap, format); va_start (ap, format);
ret = vfprintf(stream, format, ap); ret = vfprintf (stream, format, ap);
va_end(ap); va_end (ap);
return ret; return ret;
} }

View File

@@ -14,8 +14,8 @@ extern int verb_count;
#include <stdio.h> #include <stdio.h>
int func_fprintf(const char *func, FILE *stream, const char *format, int func_fprintf (const char *func, FILE * stream, const char *format,
...) __attribute__ ((format (printf, 3, 4))); ...) __attribute__ ((format (printf, 3, 4)));
#define debug(x...) ({ \ #define debug(x...) ({ \
if(verb_count >= 2) \ if(verb_count >= 2) \

File diff suppressed because it is too large Load Diff

8
ethstream.h Normal file
View File

@@ -0,0 +1,8 @@
#ifndef ETHSTREAM_H
#define ETHSTREAM_H
#define CONVERT_DEC 0
#define CONVERT_VOLTS 1
#define CONVERT_HEX 2
#endif

View File

@@ -25,74 +25,78 @@
#define UE9_COMMAND_PORT 52360 #define UE9_COMMAND_PORT 52360
struct options opt[] = { struct options opt[] = {
{ 'a', "address", "string", "host/address of UE9 (192.168.1.209)" }, {'a', "address", "string", "host/address of UE9 (192.168.1.209)"},
{ 'h', "help", NULL, "this help" }, {'h', "help", NULL, "this help"},
{ 'v', "verbose", NULL, "be verbose" }, {'v', "verbose", NULL, "be verbose"},
{ 'V', "version", NULL, "show version number and exit" }, {'V', "version", NULL, "show version number and exit"},
{ 0, NULL, NULL, NULL } {0, NULL, NULL, NULL}
}; };
int main(int argc, char *argv[]) int
main (int argc, char *argv[])
{ {
int optind; int optind;
char *optarg; char *optarg;
char c; char c;
FILE *help = stderr; FILE *help = stderr;
char *address = strdup(DEFAULT_HOST); char *address = strdup (DEFAULT_HOST);
int fd; int fd;
int ret; int ret;
/* Parse arguments */ /* Parse arguments */
opt_init(&optind); opt_init (&optind);
while ((c = opt_parse(argc, argv, &optind, &optarg, opt)) != 0) { while ((c = opt_parse (argc, argv, &optind, &optarg, opt)) != 0)
switch (c) { {
case 'a': switch (c)
free(address); {
address = strdup(optarg); case 'a':
break; free (address);
case 'v': address = strdup (optarg);
verb_count++; break;
break; case 'v':
case 'V': verb_count++;
printf("ljconfig " VERSION "\n"); break;
printf("Written by Jim Paris <jim@jtan.com>\n"); case 'V':
printf("This program comes with no warranty and is " printf ("ljconfig " VERSION "\n");
"provided under the GPLv2.\n"); printf ("Written by Jim Paris <jim@jtan.com>\n");
return 0; printf ("This program comes with no warranty and is "
break; "provided under the GPLv2.\n");
case 'h': return 0;
help = stdout; break;
default: case 'h':
printhelp: help = stdout;
fprintf(help, "Usage: %s [options]\n", *argv); default:
opt_help(opt, help); printhelp:
fprintf(help, "Displays/changes Labjack UE9 config.\n"); fprintf (help, "Usage: %s [options]\n", *argv);
return (help == stdout) ? 0 : 1; opt_help (opt, help);
} fprintf (help, "Displays/changes Labjack UE9 config.\n");
return (help == stdout) ? 0 : 1;
} }
}
if(optind<argc) { if (optind < argc)
info("Error: too many arguments (%s)\n\n", argv[optind]); {
goto printhelp; info ("Error: too many arguments (%s)\n\n", argv[optind]);
} goto printhelp;
}
ret = 1;
/* Open */ ret = 1;
fd = ue9_open(address, UE9_COMMAND_PORT);
if (fd < 0) {
info("Connect failed: %s:%d\n", address, UE9_COMMAND_PORT);
goto out0;
}
goto out1; /* Open */
fd = ue9_open (address, UE9_COMMAND_PORT);
if (fd < 0)
ret = 0; {
out1: info ("Connect failed: %s:%d\n", address, UE9_COMMAND_PORT);
/* Close */ goto out0;
ue9_close(fd); }
out0:
return ret; goto out1;
ret = 0;
out1:
/* Close */
ue9_close (fd);
out0:
return ret;
} }

View File

@@ -16,52 +16,53 @@
#include "ue9.h" #include "ue9.h"
#include "compat.h" #include "compat.h"
int main(int argc, char *argv[]) int
main (int argc, char *argv[])
{ {
int fd_cmd; int fd_cmd;
struct ue9Calibration calib; struct ue9Calibration calib;
verb_count = 2; verb_count = 2;
fd_cmd = ue9_open("192.168.1.209", 52360); fd_cmd = ue9_open ("192.168.1.209", 52360);
if (fd_cmd < 0) { if (fd_cmd < 0)
fprintf(stderr, "ue9_open: %s\n", {
compat_strerror(errno)); fprintf (stderr, "ue9_open: %s\n", compat_strerror (errno));
return 1; return 1;
} }
if (ue9_get_calibration(fd_cmd, &calib) < 0) { if (ue9_get_calibration (fd_cmd, &calib) < 0)
fprintf(stderr, "ue9_get_calibration: %s\n", {
compat_strerror(errno)); fprintf (stderr, "ue9_get_calibration: %s\n", compat_strerror (errno));
return 1; return 1;
} }
printf("double unipolarSlope[0] = %lf\n", calib.unipolarSlope[0]); printf ("double unipolarSlope[0] = %lf\n", calib.unipolarSlope[0]);
printf("double unipolarSlope[1] = %lf\n", calib.unipolarSlope[1]); printf ("double unipolarSlope[1] = %lf\n", calib.unipolarSlope[1]);
printf("double unipolarSlope[2] = %lf\n", calib.unipolarSlope[2]); printf ("double unipolarSlope[2] = %lf\n", calib.unipolarSlope[2]);
printf("double unipolarSlope[3] = %lf\n", calib.unipolarSlope[3]); printf ("double unipolarSlope[3] = %lf\n", calib.unipolarSlope[3]);
printf("double unipolarOffset[0] = %lf\n", calib.unipolarOffset[0]); printf ("double unipolarOffset[0] = %lf\n", calib.unipolarOffset[0]);
printf("double unipolarOffset[1] = %lf\n", calib.unipolarOffset[1]); printf ("double unipolarOffset[1] = %lf\n", calib.unipolarOffset[1]);
printf("double unipolarOffset[2] = %lf\n", calib.unipolarOffset[2]); printf ("double unipolarOffset[2] = %lf\n", calib.unipolarOffset[2]);
printf("double unipolarOffset[3] = %lf\n", calib.unipolarOffset[3]); printf ("double unipolarOffset[3] = %lf\n", calib.unipolarOffset[3]);
printf("double bipolarSlope = %lf\n", calib.bipolarSlope); printf ("double bipolarSlope = %lf\n", calib.bipolarSlope);
printf("double bipolarOffset = %lf\n", calib.bipolarOffset); printf ("double bipolarOffset = %lf\n", calib.bipolarOffset);
printf("double DACSlope[0] = %lf\n", calib.DACSlope[0]); printf ("double DACSlope[0] = %lf\n", calib.DACSlope[0]);
printf("double DACSlope[1] = %lf\n", calib.DACSlope[1]); printf ("double DACSlope[1] = %lf\n", calib.DACSlope[1]);
printf("double DACOffset[0] = %lf\n", calib.DACOffset[0]); printf ("double DACOffset[0] = %lf\n", calib.DACOffset[0]);
printf("double DACOffset[1] = %lf\n", calib.DACOffset[1]); printf ("double DACOffset[1] = %lf\n", calib.DACOffset[1]);
printf("double tempSlope = %lf\n", calib.tempSlope); printf ("double tempSlope = %lf\n", calib.tempSlope);
printf("double tempSlopeLow = %lf\n", calib.tempSlopeLow); printf ("double tempSlopeLow = %lf\n", calib.tempSlopeLow);
printf("double calTemp = %lf\n", calib.calTemp); printf ("double calTemp = %lf\n", calib.calTemp);
printf("double Vref = %lf\n", calib.Vref); printf ("double Vref = %lf\n", calib.Vref);
printf("double VrefDiv2 = %lf\n", calib.VrefDiv2); printf ("double VrefDiv2 = %lf\n", calib.VrefDiv2);
printf("double VsSlope = %lf\n", calib.VsSlope); printf ("double VsSlope = %lf\n", calib.VsSlope);
printf("double hiResUnipolarSlope = %lf\n", calib.hiResUnipolarSlope); printf ("double hiResUnipolarSlope = %lf\n", calib.hiResUnipolarSlope);
printf("double hiResUnipolarOffset = %lf\n", calib.hiResUnipolarOffset); printf ("double hiResUnipolarOffset = %lf\n", calib.hiResUnipolarOffset);
printf("double hiResBipolarSlope = %lf\n", calib.hiResBipolarSlope); printf ("double hiResBipolarSlope = %lf\n", calib.hiResBipolarSlope);
printf("double hiResBipolarOffset = %lf\n", calib.hiResBipolarOffset); printf ("double hiResBipolarOffset = %lf\n", calib.hiResBipolarOffset);
ue9_close(fd_cmd); ue9_close (fd_cmd);
return 0; return 0;
} }

File diff suppressed because it is too large Load Diff

View File

@@ -16,29 +16,48 @@
#include "netutil.h" #include "netutil.h"
#define NERDJACK_CHANNELS 12 #define NERDJACK_CHANNELS 12
#define NERDJACK_CLOCK_RATE 54000000 #define NERDJACK_CLOCK_RATE 66000000
#define NERDJACK_DATA_PORT 49155 #define NERDJACK_DATA_PORT 49155
#define NERDJACK_UDP_RECEIVE_PORT 49156 #define NERDJACK_UDP_RECEIVE_PORT 49156
#define NERDJACK_COMMAND_PORT 49157
#define NERDJACK_PACKET_SIZE 1460 #define NERDJACK_PACKET_SIZE 1460
#define NERDJACK_NUM_SAMPLES 724 #define NERDJACK_NUM_SAMPLES 726
/* Packet structure used in message to start sampling on NerdJack */
typedef struct __attribute__ ((__packed__))
{
char word[4];
unsigned long period;
unsigned short channelbit;
unsigned char precision;
unsigned char prescaler;
} getPacket;
/* Open/close TCP/IP connection to the NerdJack */ /* Open/close TCP/IP connection to the NerdJack */
int nerd_open(const char *address,int port); int nerd_open (const char *address, int port);
int nerd_close_conn(int data_fd); int nerd_close_conn (int data_fd);
/* Generate the command word for the NerdJack */ /* Generate the command word for the NerdJack */
int nerd_generate_command(char * command, int * channel_list, int channel_count, int precision, int nerd_generate_command (getPacket * command, int *channel_list,
unsigned short period); int channel_count, int precision,
unsigned long period);
/* Send given command to NerdJack */
int nerd_send_command (const char *address, void *command, int length);
/* Stream data out of the NerdJack */ /* Stream data out of the NerdJack */
int nerd_data_stream(int data_fd, char * command, int numChannels, int * channel_list, int precision, int convert, int lines); int nerd_data_stream (int data_fd, int numChannels, int *channel_list,
int precision, int convert, int lines, int showmem,
unsigned short *currentcount, unsigned int period,
int wasreset);
/* Detect the IP Address of the NerdJack and return in ipAddress */ /* Detect the IP Address of the NerdJack and return in ipAddress */
int nerdjack_detect(char * ipAddress); int nerdjack_detect (char *ipAddress);
/* Choose the best ScanConfig and ScanInterval parameters for the /* Choose the best ScanConfig and ScanInterval parameters for the
desired scanrate. Returns -1 if no valid config found */ desired scanrate. Returns -1 if no valid config found */
int nerdjack_choose_scan(double desired_rate, double *actual_rate, int *period); int nerdjack_choose_scan (double desired_rate, double *actual_rate,
unsigned long *period);
#endif #endif

349
netutil.c
View File

@@ -5,239 +5,262 @@
#include <stdio.h> #include <stdio.h>
/* Initialize networking */ /* Initialize networking */
void net_init(void) void
net_init (void)
{ {
#ifdef __WIN32__ #ifdef __WIN32__
WSADATA blah; WSADATA blah;
WSAStartup(0x0101, &blah); WSAStartup (0x0101, &blah);
#endif #endif
} }
/* Set socket blocking/nonblocking */ /* Set socket blocking/nonblocking */
int soblock(int socket, int blocking) int
soblock (int socket, int blocking)
{ {
#ifdef __WIN32__ #ifdef __WIN32__
unsigned long arg = blocking ? 0 : 1; unsigned long arg = blocking ? 0 : 1;
if (ioctlsocket(socket, FIONBIO, &arg) != 0) if (ioctlsocket (socket, FIONBIO, &arg) != 0)
return -1; return -1;
return 0; return 0;
#else #else
int sockopt; int sockopt;
/* Get flags */ /* Get flags */
sockopt = fcntl(socket, F_GETFL); sockopt = fcntl (socket, F_GETFL);
if (sockopt == -1) { if (sockopt == -1)
return -1; {
} return -1;
}
/* Modify */ /* Modify */
if (blocking) if (blocking)
sockopt &= ~O_NONBLOCK; sockopt &= ~O_NONBLOCK;
else else
sockopt |= O_NONBLOCK; sockopt |= O_NONBLOCK;
/* Set flags */ /* Set flags */
if (fcntl(socket, F_SETFL, sockopt) != 0) if (fcntl (socket, F_SETFL, sockopt) != 0)
return -1; return -1;
return 0; return 0;
#endif #endif
} }
/* Like connect(2), but with a timeout. Socket must be non-blocking. */ /* Like connect(2), but with a timeout. Socket must be non-blocking. */
int connect_timeout(int s, const struct sockaddr *serv_addr, socklen_t addrlen, int
struct timeval *timeout) connect_timeout (int s, const struct sockaddr *serv_addr, socklen_t addrlen,
struct timeval *timeout)
{ {
int ret; int ret;
fd_set writefds; fd_set writefds;
fd_set exceptfds; fd_set exceptfds;
int optval; int optval;
socklen_t optlen; socklen_t optlen;
/* Start connect */ /* Start connect */
ret = connect(s, serv_addr, addrlen); ret = connect (s, serv_addr, addrlen);
if (ret == 0) { if (ret == 0)
/* Success */ {
return 0; /* Success */
} return 0;
}
/* Check for immediate failure */ /* Check for immediate failure */
#ifdef __WIN32__ #ifdef __WIN32__
errno = WSAGetLastError(); errno = WSAGetLastError ();
if (ret < 0 && errno != WSAEWOULDBLOCK && errno != WSAEINVAL) if (ret < 0 && errno != WSAEWOULDBLOCK && errno != WSAEINVAL)
return -1; return -1;
#else #else
if (ret < 0 && errno != EINPROGRESS && errno != EALREADY) if (ret < 0 && errno != EINPROGRESS && errno != EALREADY)
return -1; return -1;
#endif #endif
/* In progress, wait for result. */ /* In progress, wait for result. */
FD_ZERO(&writefds); FD_ZERO (&writefds);
FD_SET(s, &writefds); FD_SET (s, &writefds);
FD_ZERO(&exceptfds); FD_ZERO (&exceptfds);
FD_SET(s, &exceptfds); FD_SET (s, &exceptfds);
ret = select(s + 1, NULL, &writefds, &exceptfds, timeout); ret = select (s + 1, NULL, &writefds, &exceptfds, timeout);
if (ret < 0) { if (ret < 0)
/* Error */ {
return -1; /* Error */
} return -1;
if (ret == 0) { }
/* Timed out */ if (ret == 0)
errno = ETIMEDOUT; {
return -1; /* Timed out */
} errno = ETIMEDOUT;
return -1;
}
/* Check the socket state */ /* Check the socket state */
optlen = sizeof(optval); optlen = sizeof (optval);
if (getsockopt(s, SOL_SOCKET, SO_ERROR, (void *)&optval, &optlen) != 0) if (getsockopt (s, SOL_SOCKET, SO_ERROR, (void *) &optval, &optlen) != 0)
return -1; return -1;
if (optval != 0) { if (optval != 0)
/* Connection failed. */ {
errno = optval; /* Connection failed. */
return -1; errno = optval;
} return -1;
}
/* On Windows, SO_ERROR sometimes shows no error but the connection /* On Windows, SO_ERROR sometimes shows no error but the connection
still failed. Sigh. */ still failed. Sigh. */
if (FD_ISSET(s, &exceptfds) || !FD_ISSET(s, &writefds)) { if (FD_ISSET (s, &exceptfds) || !FD_ISSET (s, &writefds))
errno = EIO; {
return -1; errno = EIO;
} return -1;
}
/* Success */ /* Success */
return 0; return 0;
} }
/* Like send(2), but with a timeout. Socket must be non-blocking. /* Like send(2), but with a timeout. Socket must be non-blocking.
The timeout only applies if no data at all is sent -- this function The timeout only applies if no data at all is sent -- this function
may still send less than requested. */ may still send less than requested. */
ssize_t send_timeout(int s, const void *buf, size_t len, int flags, ssize_t
struct timeval *timeout) send_timeout (int s, const void *buf, size_t len, int flags,
struct timeval * timeout)
{ {
fd_set writefds; fd_set writefds;
int ret; int ret;
FD_ZERO(&writefds);
FD_SET(s, &writefds);
ret = select(s + 1, NULL, &writefds, NULL, timeout);
if (ret == 0) {
/* Timed out */
errno = ETIMEDOUT;
return -1;
}
if (ret != 1) {
/* Error */
return -1;
}
return send(s, buf, len, flags); FD_ZERO (&writefds);
FD_SET (s, &writefds);
ret = select (s + 1, NULL, &writefds, NULL, timeout);
if (ret == 0)
{
/* Timed out */
errno = ETIMEDOUT;
return -1;
}
if (ret != 1)
{
/* Error */
return -1;
}
return send (s, buf, len, flags);
} }
/* Like recv(2), but with a timeout. Socket must be non-blocking. /* Like recv(2), but with a timeout. Socket must be non-blocking.
The timeout only applies if no data at all is received -- this The timeout only applies if no data at all is received -- this
function may still return less than requested. */ function may still return less than requested. */
ssize_t recv_timeout(int s, void *buf, size_t len, int flags, ssize_t
struct timeval *timeout) recv_timeout (int s, void *buf, size_t len, int flags,
struct timeval * timeout)
{ {
fd_set readfds; fd_set readfds;
int ret; int ret;
FD_ZERO(&readfds);
FD_SET(s, &readfds);
ret = select(s + 1, &readfds, NULL, NULL, timeout);
if (ret == 0) {
/* Timed out */
errno = ETIMEDOUT;
return -1;
}
if (ret != 1) {
/* Error */
return -1;
}
return recv(s, buf, len, flags); FD_ZERO (&readfds);
FD_SET (s, &readfds);
ret = select (s + 1, &readfds, NULL, NULL, timeout);
if (ret == 0)
{
/* Timed out */
errno = ETIMEDOUT;
return -1;
}
if (ret != 1)
{
/* Error */
return -1;
}
return recv (s, buf, len, flags);
} }
/* Like recvfrom(2), but with a timeout. Socket must be non-blocking. /* Like recvfrom(2), but with a timeout. Socket must be non-blocking.
The timeout only applies if no data at all is received -- this The timeout only applies if no data at all is received -- this
function may still return less than requested. */ function may still return less than requested. */
ssize_t recvfrom_timeout(int s, void *buf, size_t len, int flags, struct sockaddr *address, socklen_t *address_len, ssize_t
struct timeval *timeout) recvfrom_timeout (int s, void *buf, size_t len, int flags,
struct sockaddr * address, socklen_t * address_len,
struct timeval * timeout)
{ {
fd_set readfds; fd_set readfds;
int ret; int ret;
FD_ZERO(&readfds);
FD_SET(s, &readfds);
ret = select(s + 1, &readfds, NULL, NULL, timeout);
if (ret == 0) {
/* Timed out */
errno = ETIMEDOUT;
return -1;
}
if (ret != 1) {
/* Error */
return -1;
}
return recvfrom(s, buf, len, flags, address, address_len); FD_ZERO (&readfds);
FD_SET (s, &readfds);
ret = select (s + 1, &readfds, NULL, NULL, timeout);
if (ret == 0)
{
/* Timed out */
errno = ETIMEDOUT;
return -1;
}
if (ret != 1)
{
/* Error */
return -1;
}
return recvfrom (s, buf, len, flags, address, address_len);
} }
/* Like send_timeout, but retries (with the same timeout) in case of /* Like send_timeout, but retries (with the same timeout) in case of
partial transfers. This is a stronger attempt to send all partial transfers. This is a stronger attempt to send all
requested data. */ requested data. */
ssize_t send_all_timeout(int s, const void *buf, size_t len, int flags, ssize_t
struct timeval *timeout) send_all_timeout (int s, const void *buf, size_t len, int flags,
struct timeval * timeout)
{ {
struct timeval tv; struct timeval tv;
size_t left = len; size_t left = len;
ssize_t ret; ssize_t ret;
while (left > 0) { while (left > 0)
tv.tv_sec = timeout->tv_sec; {
tv.tv_usec = timeout->tv_usec; tv.tv_sec = timeout->tv_sec;
ret = send_timeout(s, buf, left, flags, &tv); tv.tv_usec = timeout->tv_usec;
ret = send_timeout (s, buf, left, flags, &tv);
if (ret < 0) if (ret < 0)
return ret; return ret;
if (ret == 0) if (ret == 0)
break; break;
left -= ret; left -= ret;
buf += ret; buf += ret;
} }
return len - left; return len - left;
} }
/* Like recv_timeout, but retries (with the same timeout) in case of /* Like recv_timeout, but retries (with the same timeout) in case of
partial transfers. This is a stronger attempt to recv all partial transfers. This is a stronger attempt to recv all
requested data. */ requested data. */
ssize_t recv_all_timeout(int s, void *buf, size_t len, int flags, ssize_t
struct timeval *timeout) recv_all_timeout (int s, void *buf, size_t len, int flags,
struct timeval * timeout)
{ {
struct timeval tv; struct timeval tv;
size_t left = len; size_t left = len;
ssize_t ret; ssize_t ret;
while (left > 0) { while (left > 0)
tv.tv_sec = timeout->tv_sec; {
tv.tv_usec = timeout->tv_usec; tv.tv_sec = timeout->tv_sec;
ret = recv_timeout(s, buf, left, flags, &tv); tv.tv_usec = timeout->tv_usec;
ret = recv_timeout (s, buf, left, flags, &tv);
if (ret < 0) if (ret < 0)
return ret; return ret;
if (ret == 0) if (ret == 0)
break; break;
left -= ret; left -= ret;
buf += ret; buf += ret;
} }
return len - left; return len - left;
} }

View File

@@ -11,35 +11,44 @@
# define socklen_t int # define socklen_t int
# define in_addr_t uint32_t # define in_addr_t uint32_t
# define in_port_t uint16_t # define in_port_t uint16_t
# include <windows.h>
# include <iphlpapi.h>
# define USE_IPHLPAPI 1
#else #else
# include <sys/socket.h> # include <sys/socket.h>
# include <netinet/in.h> # include <netinet/in.h>
# include <arpa/inet.h> # include <arpa/inet.h>
# include <netdb.h> # include <netdb.h>
# include <net/if.h>
# include <sys/ioctl.h>
#ifndef _SIZEOF_ADDR_IFREQ
#define _SIZEOF_ADDR_IFREQ(x) sizeof(x)
#endif
#endif #endif
/* Initialize networking */ /* Initialize networking */
void net_init(void); void net_init (void);
/* Set socket blocking/nonblocking */ /* Set socket blocking/nonblocking */
int soblock(int socket, int blocking); int soblock (int socket, int blocking);
/* Like send(2), recv(2), connect(2), but with timeouts. /* Like send(2), recv(2), connect(2), but with timeouts.
Socket must be O_NONBLOCK. */ Socket must be O_NONBLOCK. */
int connect_timeout(int s, const struct sockaddr *serv_addr, socklen_t addrlen, int connect_timeout (int s, const struct sockaddr *serv_addr,
struct timeval *timeout); socklen_t addrlen, struct timeval *timeout);
ssize_t send_timeout(int s, const void *buf, size_t len, int flags, ssize_t send_timeout (int s, const void *buf, size_t len, int flags,
struct timeval *timeout); struct timeval *timeout);
ssize_t recv_timeout(int s, void *buf, size_t len, int flags, ssize_t recv_timeout (int s, void *buf, size_t len, int flags,
struct timeval *timeout); struct timeval *timeout);
ssize_t recvfrom_timeout(int s, void *buf, size_t len, int flags, struct sockaddr *address, socklen_t *address_len, ssize_t recvfrom_timeout (int s, void *buf, size_t len, int flags,
struct timeval *timeout); struct sockaddr *address, socklen_t * address_len,
struct timeval *timeout);
/* Like send_timeout and recv_timeout, but they retry (with the same timeout) /* Like send_timeout and recv_timeout, but they retry (with the same timeout)
in case of partial transfers, in order to try to transfer all data. */ in case of partial transfers, in order to try to transfer all data. */
ssize_t send_all_timeout(int s, const void *buf, size_t len, int flags, ssize_t send_all_timeout (int s, const void *buf, size_t len, int flags,
struct timeval *timeout); struct timeval *timeout);
ssize_t recv_all_timeout(int s, void *buf, size_t len, int flags, ssize_t recv_all_timeout (int s, void *buf, size_t len, int flags,
struct timeval *timeout); struct timeval *timeout);
#endif #endif

167
opt.c
View File

@@ -11,85 +11,98 @@
#include <string.h> #include <string.h>
#include "opt.h" #include "opt.h"
void opt_init(int *optind) { void
*optind=0; opt_init (int *optind)
{
*optind = 0;
} }
char opt_parse(int argc, char **argv, int *optind, char **optarg, char
struct options *opt) { opt_parse (int argc, char **argv, int *optind, char **optarg,
char c; struct options *opt)
int i; {
(*optind)++; char c;
if(*optind>=argc) int i;
return 0; (*optind)++;
if (*optind >= argc)
if(argv[*optind][0]=='-' && return 0;
argv[*optind][1]!='-' &&
argv[*optind][1]!=0) { if (argv[*optind][0] == '-' &&
/* Short option (or a bunch of 'em) */ argv[*optind][1] != '-' && argv[*optind][1] != 0)
/* Save this and shift others over */ {
c=argv[*optind][1]; /* Short option (or a bunch of 'em) */
for(i=2;argv[*optind][i]!=0;i++) /* Save this and shift others over */
argv[*optind][i-1]=argv[*optind][i]; c = argv[*optind][1];
argv[*optind][i-1]=0; for (i = 2; argv[*optind][i] != 0; i++)
if(argv[*optind][1]!=0) argv[*optind][i - 1] = argv[*optind][i];
(*optind)--; argv[*optind][i - 1] = 0;
/* Now find it */ if (argv[*optind][1] != 0)
for(i=0;opt[i].shortopt!=0;i++) (*optind)--;
if(opt[i].shortopt==c) /* Now find it */
break; for (i = 0; opt[i].shortopt != 0; i++)
if(opt[i].shortopt==0) { if (opt[i].shortopt == c)
fprintf(stderr,"Error: unknown option '-%c'\n",c); break;
return '?'; if (opt[i].shortopt == 0)
} {
if(opt[i].arg==NULL) fprintf (stderr, "Error: unknown option '-%c'\n", c);
return c; return '?';
(*optind)++;
if(*optind>=argc || (argv[*optind][0]=='-' &&
argv[*optind][1]!=0)) {
fprintf(stderr,"Error: option '-%c' requires an "
"argument\n",c);
return '?';
}
(*optarg)=argv[*optind];
return c;
} else if(argv[*optind][0]=='-' &&
argv[*optind][1]=='-' &&
argv[*optind][2]!=0) {
/* Long option */
for(i=0;(c=opt[i].shortopt)!=0;i++)
if(strcmp(opt[i].longopt,argv[*optind]+2)==0)
break;
if(opt[i].shortopt==0) {
fprintf(stderr,"Error: unknown option '%s'\n",
argv[*optind]);
return '?';
}
if(opt[i].arg==NULL)
return c;
(*optind)++;
if(*optind>=argc || (argv[*optind][0]=='-' &&
argv[*optind][1]!=0)) {
fprintf(stderr,"Error: option '%s' requires an "
"argument\n",argv[*optind-1]);
return '?';
}
(*optarg)=argv[*optind];
return c;
} else {
/* End of options */
return 0;
} }
} if (opt[i].arg == NULL)
return c;
void opt_help(struct options *opt, FILE *out) { (*optind)++;
int i; if (*optind >= argc || (argv[*optind][0] == '-' &&
int printed; argv[*optind][1] != 0))
{
for(i=0;opt[i].shortopt!=0;i++) { fprintf (stderr, "Error: option '-%c' requires an "
fprintf(out," -%c, --%s%n",opt[i].shortopt, "argument\n", c);
opt[i].longopt,&printed); return '?';
fprintf(out," %-*s%s\n",30-printed,
opt[i].arg?opt[i].arg:"",opt[i].help);
} }
(*optarg) = argv[*optind];
return c;
}
else if (argv[*optind][0] == '-' &&
argv[*optind][1] == '-' && argv[*optind][2] != 0)
{
/* Long option */
for (i = 0; (c = opt[i].shortopt) != 0; i++)
if (strcmp (opt[i].longopt, argv[*optind] + 2) == 0)
break;
if (opt[i].shortopt == 0)
{
fprintf (stderr, "Error: unknown option '%s'\n", argv[*optind]);
return '?';
}
if (opt[i].arg == NULL)
return c;
(*optind)++;
if (*optind >= argc || (argv[*optind][0] == '-' &&
argv[*optind][1] != 0))
{
fprintf (stderr, "Error: option '%s' requires an "
"argument\n", argv[*optind - 1]);
return '?';
}
(*optarg) = argv[*optind];
return c;
}
else
{
/* End of options */
return 0;
}
}
void
opt_help (struct options *opt, FILE * out)
{
int i;
int printed;
for (i = 0; opt[i].shortopt != 0; i++)
{
fprintf (out, " -%c, --%s%n", opt[i].shortopt,
opt[i].longopt, &printed);
fprintf (out, " %-*s%s\n", 30 - printed,
opt[i].arg ? opt[i].arg : "", opt[i].help);
}
} }

19
opt.h
View File

@@ -11,18 +11,19 @@
#include <stdlib.h> #include <stdlib.h>
struct options { struct options
char shortopt; {
char *longopt; char shortopt;
char *arg; char *longopt;
char *help; char *arg;
char *help;
}; };
void opt_init(int *optind); void opt_init (int *optind);
char opt_parse(int argc, char **argv, int *optind, char **optarg, char opt_parse (int argc, char **argv, int *optind, char **optarg,
struct options *opt); struct options *opt);
void opt_help(struct options *opt, FILE *out); void opt_help (struct options *opt, FILE * out);
#endif #endif

1032
ue9.c

File diff suppressed because it is too large Load Diff

143
ue9.h
View File

@@ -16,56 +16,59 @@
#include "netutil.h" #include "netutil.h"
/* Calibration data */ /* Calibration data */
struct ue9Calibration { struct ue9Calibration
double unipolarSlope[4]; {
double unipolarOffset[4]; double unipolarSlope[4];
double bipolarSlope; double unipolarOffset[4];
double bipolarOffset; double bipolarSlope;
double DACSlope[2]; double bipolarOffset;
double DACOffset[2]; double DACSlope[2];
double tempSlope; double DACOffset[2];
double tempSlopeLow; double tempSlope;
double calTemp; double tempSlopeLow;
double Vref; double calTemp;
double VrefDiv2; double Vref;
double VsSlope; double VrefDiv2;
double hiResUnipolarSlope; double VsSlope;
double hiResUnipolarOffset; double hiResUnipolarSlope;
double hiResBipolarSlope; double hiResUnipolarOffset;
double hiResBipolarOffset; double hiResBipolarSlope;
double hiResBipolarOffset;
}; };
/* Comm config */ /* Comm config */
struct ue9CommConfig { struct ue9CommConfig
uint8_t local_id; {
uint8_t power_level; uint8_t local_id;
in_addr_t address; uint8_t power_level;
in_addr_t gateway; in_addr_t address;
in_addr_t subnet; in_addr_t gateway;
in_port_t portA; in_addr_t subnet;
in_port_t portB; in_port_t portA;
uint8_t dhcp_enabled; in_port_t portB;
uint8_t product_id; uint8_t dhcp_enabled;
uint8_t mac_address[6]; uint8_t product_id;
double hw_version; uint8_t mac_address[6];
double comm_fw_version; double hw_version;
double comm_fw_version;
}; };
/* Control config */ /* Control config */
struct ue9ControlConfig { struct ue9ControlConfig
uint8_t power_level; {
uint8_t reset_source; uint8_t power_level;
double control_fw_version; uint8_t reset_source;
double control_bl_version; double control_fw_version;
uint8_t hires; double control_bl_version;
uint8_t fio_dir; uint8_t hires;
uint8_t fio_state; uint8_t fio_dir;
uint8_t eio_dir; uint8_t fio_state;
uint8_t eio_state; uint8_t eio_dir;
uint8_t cio_dirstate;; uint8_t eio_state;
uint8_t mio_dirstate; uint8_t cio_dirstate;;
uint16_t dac0; uint8_t mio_dirstate;
uint16_t dac1; uint16_t dac0;
uint16_t dac1;
}; };
#define UE9_UNIPOLAR_GAIN1 0x00 #define UE9_UNIPOLAR_GAIN1 0x00
@@ -77,65 +80,65 @@ struct ue9ControlConfig {
#define UE9_CHANNELS 14 #define UE9_CHANNELS 14
/* Fill checksums in data buffers */ /* Fill checksums in data buffers */
void ue9_checksum_normal(uint8_t *buffer, size_t len); void ue9_checksum_normal (uint8_t * buffer, size_t len);
void ue9_checksum_extended(uint8_t *buffer, size_t len); void ue9_checksum_extended (uint8_t * buffer, size_t len);
/* Verify checksums in data buffers. Returns 0 on error. */ /* Verify checksums in data buffers. Returns 0 on error. */
int ue9_verify_normal(uint8_t *buffer, size_t len); int ue9_verify_normal (uint8_t * buffer, size_t len);
int ue9_verify_extended(uint8_t *buffer, size_t len); int ue9_verify_extended (uint8_t * buffer, size_t len);
/* Open/close TCP/IP connection to the UE9 */ /* Open/close TCP/IP connection to the UE9 */
int ue9_open(const char *host, int port); int ue9_open (const char *host, int port);
void ue9_close(int fd); void ue9_close (int fd);
/* Read a memory block from the device. Returns -1 on error. */ /* Read a memory block from the device. Returns -1 on error. */
int ue9_memory_read(int fd, int blocknum, uint8_t *buffer, int len); int ue9_memory_read (int fd, int blocknum, uint8_t * buffer, int len);
/* Convert 64-bit fixed point to double type */ /* Convert 64-bit fixed point to double type */
double ue9_fp64_to_double(uint8_t *data); double ue9_fp64_to_double (uint8_t * data);
/* Retrieve calibration data or configuration from the device */ /* Retrieve calibration data or configuration from the device */
int ue9_get_calibration(int fd, struct ue9Calibration *calib); int ue9_get_calibration (int fd, struct ue9Calibration *calib);
int ue9_get_comm_config(int fd, struct ue9CommConfig *config); int ue9_get_comm_config (int fd, struct ue9CommConfig *config);
int ue9_get_control_config(int fd, struct ue9ControlConfig *config); int ue9_get_control_config (int fd, struct ue9ControlConfig *config);
/* Data conversion. If calib is NULL, use uncalibrated conversions. */ /* Data conversion. If calib is NULL, use uncalibrated conversions. */
double ue9_binary_to_analog(struct ue9Calibration *calib, double ue9_binary_to_analog (struct ue9Calibration *calib,
uint8_t gain, uint8_t resolution, uint16_t data); uint8_t gain, uint8_t resolution, uint16_t data);
/* Compute scanrate based on the provided values. */ /* Compute scanrate based on the provided values. */
double ue9_compute_rate(uint8_t scanconfig, uint16_t scaninterval); double ue9_compute_rate (uint8_t scanconfig, uint16_t scaninterval);
/* Choose the best ScanConfig and ScanInterval parameters for the /* Choose the best ScanConfig and ScanInterval parameters for the
desired scanrate. Returns 0 if nothing can be chosen. */ desired scanrate. Returns 0 if nothing can be chosen. */
int ue9_choose_scan(double desired_rate, double *actual_rate, int ue9_choose_scan (double desired_rate, double *actual_rate,
uint8_t *scanconfig, uint16_t *scaninterval); uint8_t * scanconfig, uint16_t * scaninterval);
/* Flush data buffers */ /* Flush data buffers */
void ue9_buffer_flush(int fd); void ue9_buffer_flush (int fd);
/* Stop stream. Returns < 0 on failure. */ /* Stop stream. Returns < 0 on failure. */
int ue9_stream_stop(int fd); int ue9_stream_stop (int fd);
/* Start stream. Returns < 0 on failure. */ /* Start stream. Returns < 0 on failure. */
int ue9_stream_start(int fd); int ue9_stream_start (int fd);
/* Execute a command on the UE9. Returns -1 on error. Fills the /* Execute a command on the UE9. Returns -1 on error. Fills the
checksums on the outgoing packets, and verifies them on the checksums on the outgoing packets, and verifies them on the
incoming packets. Data in "out" is transmitted, data in "in" is incoming packets. Data in "out" is transmitted, data in "in" is
received. */ received. */
int ue9_command(int fd, uint8_t *out, uint8_t *in, int inlen); int ue9_command (int fd, uint8_t * out, uint8_t * in, int inlen);
/* "Simple" stream configuration, assumes the channels are all /* "Simple" stream configuration, assumes the channels are all
configured with the same gain. */ configured with the same gain. */
int ue9_streamconfig_simple(int fd, int *channel_list, int channel_count, int ue9_streamconfig_simple (int fd, int *channel_list, int channel_count,
uint8_t scanconfig, uint16_t scaninterval, uint8_t scanconfig, uint16_t scaninterval,
uint8_t gain); uint8_t gain);
/* Stream data and pass it to the data callback. If callback returns /* Stream data and pass it to the data callback. If callback returns
negative, stops reading and returns 0. Returns < 0 on error. */ negative, stops reading and returns 0. Returns < 0 on error. */
typedef int (*ue9_stream_cb_t)(int channels, uint16_t *data, void *context); typedef int (*ue9_stream_cb_t) (int channels, uint16_t * data, void *context);
int ue9_stream_data(int fd, int channels, int ue9_stream_data (int fd, int channels,
ue9_stream_cb_t callback, void *context); ue9_stream_cb_t callback, void *context);
#endif #endif

View File

@@ -1,51 +1,52 @@
#include "ue9error.h" #include "ue9error.h"
const char *ue9_error_text[] = { const char *ue9_error_text[] = {
[0] = "(no error)", [0] = "(no error)",
[SCRATCH_WRT_FAIL] = "SCRATCH_WRT_FAIL", [SCRATCH_WRT_FAIL] = "SCRATCH_WRT_FAIL",
[SCRATCH_ERASE_FAIL] = "SCRATCH_ERASE_FAIL", [SCRATCH_ERASE_FAIL] = "SCRATCH_ERASE_FAIL",
[DATA_BUFFER_OVERFLOW] = "DATA_BUFFER_OVERFLOW", [DATA_BUFFER_OVERFLOW] = "DATA_BUFFER_OVERFLOW",
[ADC0_BUFFER_OVERFLOW] = "ADC0_BUFFER_OVERFLOW", [ADC0_BUFFER_OVERFLOW] = "ADC0_BUFFER_OVERFLOW",
[FUNCTION_INVALID] = "FUNCTION_INVALID", [FUNCTION_INVALID] = "FUNCTION_INVALID",
[SWDT_TIME_INVALID] = "SWDT_TIME_INVALID", [SWDT_TIME_INVALID] = "SWDT_TIME_INVALID",
[FLASH_WRITE_FAIL] = "FLASH_WRITE_FAIL", [FLASH_WRITE_FAIL] = "FLASH_WRITE_FAIL",
[FLASH_ERASE_FAIL] = "FLASH_ERASE_FAIL", [FLASH_ERASE_FAIL] = "FLASH_ERASE_FAIL",
[FLASH_JMP_FAIL] = "FLASH_JMP_FAIL", [FLASH_JMP_FAIL] = "FLASH_JMP_FAIL",
[FLASH_PSP_TIMEOUT] = "FLASH_PSP_TIMEOUT", [FLASH_PSP_TIMEOUT] = "FLASH_PSP_TIMEOUT",
[FLASH_ABORT_RECEIVED] = "FLASH_ABORT_RECEIVED", [FLASH_ABORT_RECEIVED] = "FLASH_ABORT_RECEIVED",
[FLASH_PAGE_MISMATCH] = "FLASH_PAGE_MISMATCH", [FLASH_PAGE_MISMATCH] = "FLASH_PAGE_MISMATCH",
[FLASH_BLOCK_MISMATCH] = "FLASH_BLOCK_MISMATCH", [FLASH_BLOCK_MISMATCH] = "FLASH_BLOCK_MISMATCH",
[FLASH_PAGE_NOT_IN_CODE_AREA] = "FLASH_PAGE_NOT_IN_CODE_AREA", [FLASH_PAGE_NOT_IN_CODE_AREA] = "FLASH_PAGE_NOT_IN_CODE_AREA",
[MEM_ILLEGAL_ADDRESS] = "MEM_ILLEGAL_ADDRESS", [MEM_ILLEGAL_ADDRESS] = "MEM_ILLEGAL_ADDRESS",
[FLASH_LOCKED] = "FLASH_LOCKED", [FLASH_LOCKED] = "FLASH_LOCKED",
[INVALID_BLOCK] = "INVALID_BLOCK", [INVALID_BLOCK] = "INVALID_BLOCK",
[FLASH_ILLEGAL_PAGE] = "FLASH_ILLEGAL_PAGE", [FLASH_ILLEGAL_PAGE] = "FLASH_ILLEGAL_PAGE",
[STREAM_IS_ACTIVE] = "STREAM_IS_ACTIVE", [STREAM_IS_ACTIVE] = "STREAM_IS_ACTIVE",
[STREAM_TABLE_INVALID] = "STREAM_TABLE_INVALID", [STREAM_TABLE_INVALID] = "STREAM_TABLE_INVALID",
[STREAM_CONFIG_INVALID] = "STREAM_CONFIG_INVALID", [STREAM_CONFIG_INVALID] = "STREAM_CONFIG_INVALID",
[STREAM_BAD_TRIGGER_SOURCE] = "STREAM_BAD_TRIGGER_SOURCE", [STREAM_BAD_TRIGGER_SOURCE] = "STREAM_BAD_TRIGGER_SOURCE",
[STREAM_NOT_RUNNING] = "STREAM_NOT_RUNNING", [STREAM_NOT_RUNNING] = "STREAM_NOT_RUNNING",
[STREAM_INVALID_TRIGGER] = "STREAM_INVALID_TRIGGER", [STREAM_INVALID_TRIGGER] = "STREAM_INVALID_TRIGGER",
[STREAM_CONTROL_BUFFER_OVERFLOW] = "STREAM_CONTROL_BUFFER_OVERFLOW", [STREAM_CONTROL_BUFFER_OVERFLOW] = "STREAM_CONTROL_BUFFER_OVERFLOW",
[STREAM_SCAN_OVERLAP] = "STREAM_SCAN_OVERLAP", [STREAM_SCAN_OVERLAP] = "STREAM_SCAN_OVERLAP",
[STREAM_SAMPLE_NUM_INVALID] = "STREAM_SAMPLE_NUM_INVALID", [STREAM_SAMPLE_NUM_INVALID] = "STREAM_SAMPLE_NUM_INVALID",
[STREAM_BIPOLAR_GAIN_INVALID] = "STREAM_BIPOLAR_GAIN_INVALID", [STREAM_BIPOLAR_GAIN_INVALID] = "STREAM_BIPOLAR_GAIN_INVALID",
[STREAM_SCAN_RATE_INVALID] = "STREAM_SCAN_RATE_INVALID", [STREAM_SCAN_RATE_INVALID] = "STREAM_SCAN_RATE_INVALID",
[TIMER_INVALID_MODE] = "TIMER_INVALID_MODE", [TIMER_INVALID_MODE] = "TIMER_INVALID_MODE",
[TIMER_QUADRATURE_AB_ERROR] = "TIMER_QUADRATURE_AB_ERROR", [TIMER_QUADRATURE_AB_ERROR] = "TIMER_QUADRATURE_AB_ERROR",
[TIMER_QUAD_PULSE_SEQUENCE] = "TIMER_QUAD_PULSE_SEQUENCE", [TIMER_QUAD_PULSE_SEQUENCE] = "TIMER_QUAD_PULSE_SEQUENCE",
[TIMER_BAD_CLOCK_SOURCE] = "TIMER_BAD_CLOCK_SOURCE", [TIMER_BAD_CLOCK_SOURCE] = "TIMER_BAD_CLOCK_SOURCE",
[TIMER_STREAM_ACTIVE] = "TIMER_STREAM_ACTIVE", [TIMER_STREAM_ACTIVE] = "TIMER_STREAM_ACTIVE",
[TIMER_PWMSTOP_MODULE_ERROR] = "TIMER_PWMSTOP_MODULE_ERROR", [TIMER_PWMSTOP_MODULE_ERROR] = "TIMER_PWMSTOP_MODULE_ERROR",
[EXT_OSC_NOT_STABLE] = "EXT_OSC_NOT_STABLE", [EXT_OSC_NOT_STABLE] = "EXT_OSC_NOT_STABLE",
[INVALID_POWER_SETTING] = "INVALID_POWER_SETTING", [INVALID_POWER_SETTING] = "INVALID_POWER_SETTING",
[PLL_NOT_LOCKED] = "PLL_NOT_LOCKED" [PLL_NOT_LOCKED] = "PLL_NOT_LOCKED"
}; };
const char *ue9_error(int errorcode) const char *
ue9_error (int errorcode)
{ {
if (errorcode > ARRAY_SIZE(ue9_error_text)) if (errorcode > ARRAY_SIZE (ue9_error_text))
return "(invalid errorcode)"; return "(invalid errorcode)";
else else
return ue9_error_text[errorcode]; return ue9_error_text[errorcode];
} }

View File

@@ -44,6 +44,6 @@
extern const char *ue9_error_text[]; extern const char *ue9_error_text[];
const char *ue9_error(int errorcode); const char *ue9_error (int errorcode);
#endif #endif

View File

@@ -1,2 +1,2 @@
/* This file was automatically generated. */ /* This file was automatically generated. */
#define VERSION "1.0 (2009-01-21)" #define VERSION "1.1 (2009-04-17)"