Browse Source

Continuing work...

git-svn-id: https://bucket.mit.edu/svn/nilm/zoom@7986 ddd99763-3ecb-0310-9145-efcb8ce7c51f
tags/zoom-1.0
jim 14 years ago
parent
commit
8cfabe4697
6 changed files with 192 additions and 6 deletions
  1. +8
    -3
      pc/Makefile
  2. +0
    -2
      pc/calibrate.c
  3. +170
    -0
      pc/dctest.c
  4. +1
    -1
      pc/read.c
  5. +9
    -0
      pc/zoom.c
  6. +4
    -0
      pc/zoom.h

+ 8
- 3
pc/Makefile View File

@@ -1,6 +1,6 @@
CFLAGS=-Wall -Werror
CFLAGS=-Wall

all: read calibrate
all: read calibrate dctest

serial-util.o: serial-util.h

@@ -12,9 +12,14 @@ read.o: serial-util.h

calibrate.o: serial-util.h gpib.h zoom.h

dctest.o: serial-util.h gpib.h zoom.h

read: read.o serial-util.o

calibrate: calibrate.o serial-util.o gpib.o zoom.o

dctest: LDFLAGS=-lpthread
dctest: dctest.o serial-util.o gpib.o zoom.o

clean:
rm -f *.o read calibrate
rm -f *.o read calibrate dctest

+ 0
- 2
pc/calibrate.c View File

@@ -149,8 +149,6 @@ int main(int argc, char *argv[])
if ((gpib = serial_open(gpibdev, 9600)) == -1)
err(1, "failed to open gpib device %s", gpibdev);

signal(SIGINT, handle_sig);

switch (ota_opt) {
case 1:
sweep_ota(zoom, gpib, ota_sweep_count);


+ 170
- 0
pc/dctest.c View File

@@ -0,0 +1,170 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <errno.h>
#include <unistd.h>
#include <getopt.h>
#include <stdint.h>
#include <string.h>
#include <syslog.h>
#include <err.h>
#include <linux/serial.h>
#include <sys/signal.h>
#include "serial-util.h"
#include "gpib.h"
#include "zoom.h"
#include "math.h"
#include <pthread.h>

#define info(x...) fprintf(stderr,x)

void dctest(int zoom, int gpib);

int g_quit = 0;
void handle_sig(int sig) { g_quit = 1; }

int main(int argc, char *argv[])
{
char *zoomdev=strdup("/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A6007wc5-if00-port0");
char *gpibdev=strdup("/dev/serial/by-id/usb-Prologix_Prologix_GPIB-USB_Controller_PXQQY20G-if00-port0");
int rate=500000;
int getopt_index;
int zoom, gpib;

static struct option long_opts[] = {
{ "zoom-device", required_argument, NULL, 'Z' },
{ "gpib-device", required_argument, NULL, 'G' },
{ "rate", required_argument, NULL, 'r' },
{ "help", no_argument, NULL, 'h' },
{ 0, 0, 0, 0}
};
int help=0;
char c;

while ((c = getopt_long(argc, argv, "Z:G:r:h?",
long_opts, &getopt_index)) != -1) {
switch(c)
{
case 'Z':
free(zoomdev);
zoomdev = strdup(optarg);
break;
case 'G':
free(gpibdev);
gpibdev = strdup(optarg);
break;
case 'r':
rate = atoi(optarg);
if(rate == 0)
errx(1, "invalid rate: %s",optarg);
break;
case 'h':
case '?':
default:
help = 1;
break;
}
}
if (help) {
fprintf(stderr, "Zoom Nilm DC Test Tool\n");
fprintf(stderr, "usage: %s [options]\n\n", *argv);
fprintf(stderr, " -Z, --zoom-device %-9s zoom NILM serial port\n", "/dev/xxx");
fprintf(stderr, " -G, --gpib-device %-9s GPIB serial port\n", "/dev/xxx");
fprintf(stderr, " -r, --rate %-16d baud rate\n", rate);
fprintf(stderr, " -h, --help this help\n");
return 1;
}

signal(SIGINT, handle_sig);

/* open devices */
info("Opening Zoom NILM device %s\n", zoomdev);
if ((zoom = serial_open(zoomdev, rate)) == -1)
err(1, "failed to open zoom device %s", zoomdev);

info("Opening GPIB device %s\n", gpibdev);
if ((gpib = serial_open(gpibdev, 9600)) == -1)
err(1, "failed to open gpib device %s", gpibdev);

/* do the dc test */
dctest(zoom, gpib);
close(zoom);
close(gpib);
return 0;
}

struct threadinfo_t {
int quit_flag;
int fd;
};

void *read_data(void *arg)
{
struct threadinfo_t *ti = (struct threadinfo_t *)arg;

printf("ti->fd=%d\n", ti->fd);
while (!ti->quit_flag) {
printf("thread sleeping\n");
sleep(1);
}
printf("thread quitting\n");
return NULL;
}

void dctest(int zoom, int gpib)
{
// double idesired, iactual;
// int i;
// int zero;
// int dac[ZOOM_SWEEP_COUNT];
// int adc[ZOOM_SWEEP_COUNT];
pthread_t thread;
struct threadinfo_t threadinfo;
/* Do a calibration with Keithley off */
info("Triggering calibration\n");
zoomrun_trigger_calibrate(zoom);
usleep(500000);

printf("zoom=%d gpib=%d\n", zoom,gpib);
/* Init Keithley */
info("Initializing GPIB\n");
// if (gpib_init(gpib) < 0) { info("failed\n"); goto out1; }
info("Initializing Keithley\n");
// if (gpib_addr(gpib, 24) < 0) { info("failed\n"); goto out1; }
// if (keithley_init(gpib) < 0) { info("failed\n"); goto out2; }
// if (keithley_current(gpib, 0) < 0) { info("failed\n"); goto out2; }
// if (isnan(keithley_read(gpib))) { info("failed\n"); goto out2; }

/* Start the thread that reads and dumps data */
info("Spawning thread\n");
threadinfo.quit_flag = 0;
threadinfo.fd = zoom;
if (pthread_create(&thread, NULL, read_data, &threadinfo) != 0) {
info("failed\n");
goto out2;
}

/* Do another calibration now */
info("Triggering calibration\n");
zoomrun_trigger_calibrate(zoom);

/* Change Keithley values */
while (!g_quit) {
info("sleeping\n");
sleep(1);
}
printf("quitting\n");

threadinfo.quit_flag = 1;
pthread_join(thread, NULL);
out2:
keithley_off(gpib);
out1:
return;
}

+ 1
- 1
pc/read.c View File

@@ -21,7 +21,7 @@ int process(const uint8_t *buf, int len);

int main(int argc, char *argv[])
{
char *device=strdup("/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A6007wag-if00-port0");
char *device=strdup("/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A6007wc5-if00-port0");
int rate=500000;
int fd;
int getopt_index;


+ 9
- 0
pc/zoom.c View File

@@ -77,3 +77,12 @@ int zoom_sweep(int fd, int dac[ZOOM_SWEEP_COUNT], int adc[ZOOM_SWEEP_COUNT])
return -3;
return 0;
}

/* Run mode: */

void zoomrun_trigger_calibrate(int fd)
{
char c = 'c';
write(fd, &c, 1);
drain(fd);
}

+ 4
- 0
pc/zoom.h View File

@@ -3,6 +3,7 @@

#define ZOOM_SWEEP_COUNT 4000

/* debug mode */
int zoom_init_real(int fd, int dozero);
#define zoom_init(fd) zoom_init_real(fd, 1)
#define zoom_init_nozero(fd) zoom_init_real(fd, 0)
@@ -10,5 +11,8 @@ int zoom_zero_start(int fd);
int zoom_zero_stop(int fd);
int zoom_sweep(int fd, int dac[ZOOM_SWEEP_COUNT], int adc[ZOOM_SWEEP_COUNT]);

/* run mode */
void zoomrun_trigger_calibrate(int fd);

#endif


Loading…
Cancel
Save