Browse Source

changes from warit

git-svn-id: https://bucket.mit.edu/svn/nilm/zoom@7701 ddd99763-3ecb-0310-9145-efcb8ce7c51f
tags/zoom-1.0
nilm 15 years ago
parent
commit
8cffb081ec
1 changed files with 76 additions and 1 deletions
  1. +76
    -1
      pc/calibrate.c

+ 76
- 1
pc/calibrate.c View File

@@ -19,6 +19,7 @@ void startup_zero(int zoom);
void calibrate(int zoom, int gpib);
void sweep_ota(int zoom, int gpib, int ota_sweep_count);
void hold_ota(int zoom, int gpib, int ota_cmd);
void hold_ota2(int zoom, int gpib, int ota_cmd);

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

@@ -127,7 +128,7 @@ int main(int argc, char *argv[])
sweep_ota(zoom, gpib, ota_sweep_count);
break;
case 2:
hold_ota(zoom, gpib, ota_cmd);
hold_ota2(zoom, gpib, ota_cmd);
break;
default:
calibrate(zoom, gpib);
@@ -353,6 +354,80 @@ void hold_ota(int zoom, int gpib, int ota_cmd)



safecleanup:
return;

fail:
info("Failed (code %d)\n", r);
goto safecleanup;
}

void hold_ota2(int zoom, int gpib, int ota_cmd)
{
int i;
int r = 0;
char buf[128];
char zcmd[128];
int dac1, dac2, adc1, adc2;
info("Initializing Zoom NILM\n");
if (zoom_init(zoom) < 0) goto fail;

//info("Initializing GPIB\n");
//if (gpib_init(gpib) < 0) goto fail;

//info("Initializing Keithley 2002 Multimeter\n");
//if (gpib_addr(gpib, 23) < 0) goto fail;
//if (keithley2002_init2(gpib) < 0) goto fail;
//if (isnan(keithley2002_read(gpib))) goto fail;

buf[0] = '0';
if (safewrite(zoom, buf, 1) != 1)
errx(1, "write failed");
if (fdgets(buf, 128, zoom, 1000) == NULL)
errx(1, "read timeout");
drain(zoom);

if(ota_cmd > 65535 || ota_cmd < 0)
errx(1, "ota command out-of-range");

if(sprintf(zcmd,"v%.4x",(ota_cmd)) < 5)
errx(1, "fail hex conversion");

if (safewrite(zoom, zcmd, 5) != 5)
errx(1, "write failed");
if (fdgets(buf, 128, zoom, 1000) == NULL)
errx(1, "read timeout");
usleep(100);

zcmd[0] = ' ';

info("Holding OTA\n");
for (i = 0; i <= 1000 && !g_quit; i++){

if(safewrite(zoom,zcmd,1) != 1)
errx(1, "write failed");

if (fdgets(buf, 128, zoom, 1000) == NULL)
errx(1, "read timeout");

if (sscanf(buf,"%x %d %x %d", &dac1, &dac2, &adc1, &adc2) != 4)
errx(1, "read error");
printf("%d %d\n", dac2, adc2);
}

// return to zero
buf[0] = '0';
if (safewrite(zoom, buf, 1) != 1)
errx(1, "write failed");
if (fdgets(buf, 128, zoom, 1000) == NULL)
errx(1, "read timeout");



safecleanup:
return;



Loading…
Cancel
Save