Browse Source

add zoom nilm functions

git-svn-id: https://bucket.mit.edu/svn/nilm/zoom@7609 ddd99763-3ecb-0310-9145-efcb8ce7c51f
tags/zoom-1.0
jim 12 years ago
parent
commit
c8c5a7a846
4 changed files with 98 additions and 2 deletions
  1. +4
    -2
      pc/Makefile
  2. +7
    -0
      pc/calibrate.c
  3. +75
    -0
      pc/zoom.c
  4. +12
    -0
      pc/zoom.h

+ 4
- 2
pc/Makefile View File

@@ -6,13 +6,15 @@ serial-util.o: serial-util.h

gpib.o: serial-util.h

zoom.o: serial-util.h

read.o: serial-util.h

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

read: read.o serial-util.o

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

clean:
rm -f *.o read calibrate

+ 7
- 0
pc/calibrate.c View File

@@ -12,6 +12,7 @@
#include <sys/signal.h>
#include "serial-util.h"
#include "gpib.h"
#include "zoom.h"

void calibrate(int zoom, int gpib);
#define info(x...) fprintf(stderr,x)
@@ -84,6 +85,12 @@ void calibrate(int zoom, int gpib)
{
float i;

info("Initializing Zoom NILM\n");
if (zoom_init(zoom) < 0) {
info("Not responding\n");
return;
}

info("Initializing GPIB\n");
gpib_init(gpib);



+ 75
- 0
pc/zoom.c View File

@@ -0,0 +1,75 @@
#include <stdio.h>
#include <string.h>
#define __USE_ISOC99
#include <math.h>
#include "zoom.h"
#include "serial-util.h"

#define zputs(s) do { if (safewrite(fd, s, strlen(s)) != strlen(s)) return -1; } while(0)
#define zputc(ch) do { const char ____c = ch; if (safewrite(fd, &____c, 1) != 1) return -1; } while(0)

static int verify_prompt(int fd)
{
char s[128];
int dac1, dac2, adc1, adc2;
if (fdgets(s, 128, fd, 1000) == NULL)
return -1;
chomp(s);
if (sscanf(s, "%x %d %x %d", &dac1, &dac2, &adc1, &adc1) != 4)
return -1;
if (dac1 != dac2 || adc1 != adc2)
return -1;
return 0;
}

int zoom_init(int fd)
{
zputs("00000000");
drain(fd);
zputc('0');
if (verify_prompt(fd) < 0)
return -1;
return 0;
}

int zoom_zero_start(int fd)
{
char s[128];
zputc('z');
if (fdgets(s, 128, fd, 1000) == NULL)
return -1;
chomp(s);
if (strcmp(s, "zeroing input...") != 0)
return -1;
return 0;
}

int zoom_zero_stop(int fd)
{
zputc(' ');
if (verify_prompt(fd) < 0)
return -1;
return 0;
}

int zoom_sweep(int fd, int dac[ZOOM_SWEEP_COUNT], int adc[ZOOM_SWEEP_COUNT])
{
char s[128];
int i;
char c;
zputc('s');
if (fdgets(s, 128, fd, 1000) == NULL)
return -1;
if (strncmp(s, "sweep around", 12) != 0)
return -1;
for (i = 0; i < ZOOM_SWEEP_COUNT; i++) {
if (fdgets(s, 128, fd, 1000) == NULL)
return -1;
chomp(s);
if (sscanf(s, "%d %d%c", &dac[i], &adc[i], &c) != 2)
return -2;
}
if (verify_prompt(fd) < 0)
return -3;
return 0;
}

+ 12
- 0
pc/zoom.h View File

@@ -0,0 +1,12 @@
#ifndef ZOOM_H
#define ZOOM_H

#define ZOOM_SWEEP_COUNT 3000

int zoom_init(int fd);
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]);

#endif


Loading…
Cancel
Save