|
|
@@ -17,6 +17,9 @@ |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
#define info(x...) fprintf(stderr,x) |
|
|
|
|
|
|
|
int g_quit = 0; |
|
|
@@ -29,18 +32,23 @@ int main(int argc, char *argv[]) |
|
|
|
int getopt_index; |
|
|
|
int zoom, gpib; |
|
|
|
int do_zero = 0; |
|
|
|
int ota_opt = 0; |
|
|
|
int ota_sweep_count = 64; |
|
|
|
int ota_cmd = 32768; |
|
|
|
|
|
|
|
static struct option long_opts[] = { |
|
|
|
{ "zoom-device", required_argument, NULL, 'z' }, |
|
|
|
{ "gpib-device", required_argument, NULL, 'g' }, |
|
|
|
{ "startup-zero", required_argument, NULL, 's' }, |
|
|
|
{ "ota-sweep", required_argument, NULL, 'o' }, |
|
|
|
{ "ota-hold", required_argument, NULL, 'l' }, |
|
|
|
{ "help", no_argument, NULL, 'h' }, |
|
|
|
{ 0, 0, 0, 0 } |
|
|
|
{ 0, 0, 0, 0} |
|
|
|
}; |
|
|
|
int help=0; |
|
|
|
char c; |
|
|
|
|
|
|
|
while ((c = getopt_long(argc, argv, "z:g:sh?", |
|
|
|
while ((c = getopt_long(argc, argv, "z:g:solh?", |
|
|
|
long_opts, &getopt_index)) != -1) { |
|
|
|
switch(c) |
|
|
|
{ |
|
|
@@ -55,7 +63,14 @@ int main(int argc, char *argv[]) |
|
|
|
case 's': |
|
|
|
do_zero = 1; |
|
|
|
break; |
|
|
|
case 'o': |
|
|
|
ota_opt = 1; |
|
|
|
break; |
|
|
|
case 'l': |
|
|
|
ota_opt = 2; |
|
|
|
break; |
|
|
|
case 'h': |
|
|
|
|
|
|
|
case '?': |
|
|
|
default: |
|
|
|
help = 1; |
|
|
@@ -69,6 +84,8 @@ int main(int argc, char *argv[]) |
|
|
|
fprintf(stderr, " -z, --zoom-device %-14s zoom NILM serial port\n", "/dev/xxx" /*zoomdev*/); |
|
|
|
fprintf(stderr, " -g, --gpib-device %-14s GPIB serial port\n", "/dev/xxx" /*gpibdev*/); |
|
|
|
fprintf(stderr, " -s, --startup-zero assist startup by writing '0' to zoom NILM\n"); |
|
|
|
fprintf(stderr, " -o, --ota-sweep sweep OTA\n"); |
|
|
|
fprintf(stderr, " -l, --ota-hold hold OTA constantt\n"); |
|
|
|
fprintf(stderr, " -h, --help this help\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
@@ -88,7 +105,22 @@ int main(int argc, char *argv[]) |
|
|
|
err(1, "failed to open gpib device %s", gpibdev); |
|
|
|
|
|
|
|
signal(SIGINT, handle_sig); |
|
|
|
calibrate(zoom, gpib); |
|
|
|
|
|
|
|
/* sweep OTA only */ |
|
|
|
if(ota_opt == 1){ |
|
|
|
sweep_ota(zoom, gpib, ota_sweep_count); |
|
|
|
|
|
|
|
} |
|
|
|
else if(ota_opt == 2){ |
|
|
|
if(argc > 2){ |
|
|
|
sscanf(argv[2],"%d",&ota_cmd); |
|
|
|
} |
|
|
|
|
|
|
|
hold_ota(zoom, gpib, ota_cmd); |
|
|
|
} |
|
|
|
else{ |
|
|
|
calibrate(zoom, gpib); |
|
|
|
} |
|
|
|
|
|
|
|
close(zoom); |
|
|
|
close(gpib); |
|
|
@@ -157,7 +189,7 @@ fail: |
|
|
|
info("Failed (code %d)\n", r); |
|
|
|
goto safecleanup; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void startup_zero(int zoom) |
|
|
|
{ |
|
|
|
char buf[128]; |
|
|
@@ -175,3 +207,144 @@ void startup_zero(int zoom) |
|
|
|
printf("%s\n", buf); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void sweep_ota(int zoom, int gpib, int ota_sweep_count) |
|
|
|
{ |
|
|
|
double iactual; |
|
|
|
int i,j; |
|
|
|
int r = 0; |
|
|
|
char buf[128]; |
|
|
|
char zcmd[128]; |
|
|
|
int mycmd = 0; |
|
|
|
int cmd_inc = 4096; |
|
|
|
|
|
|
|
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_init(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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
info("Sweeping OTA\n"); |
|
|
|
for (i = 0; i <= 16 && !g_quit; i++){ |
|
|
|
|
|
|
|
for(j = -2; j <= 2; j++){ |
|
|
|
if(mycmd+j > 65535 || mycmd+j < 0) |
|
|
|
continue; |
|
|
|
|
|
|
|
if(sprintf(zcmd,"v%.4x",(mycmd +j)) < 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); |
|
|
|
|
|
|
|
iactual = keithley2002_read(gpib); |
|
|
|
|
|
|
|
printf("%d %.8f\n",(int)(mycmd + j), iactual); |
|
|
|
} |
|
|
|
|
|
|
|
mycmd += cmd_inc; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 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; |
|
|
|
|
|
|
|
fail: |
|
|
|
info("Failed (code %d)\n", r); |
|
|
|
goto safecleanup; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void hold_ota(int zoom, int gpib, int ota_cmd) |
|
|
|
{ |
|
|
|
double iactual; |
|
|
|
double tx; |
|
|
|
int i; |
|
|
|
int r = 0; |
|
|
|
char buf[128]; |
|
|
|
char zcmd[128]; |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
info("Holding OTA\n"); |
|
|
|
for (i = 0; i <= 500 && !g_quit; i++){ |
|
|
|
|
|
|
|
iactual = keithley2002_read2(gpib, &tx); |
|
|
|
|
|
|
|
printf("%.8f %.8f\n", tx, iactual); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 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; |
|
|
|
|
|
|
|
fail: |
|
|
|
info("Failed (code %d)\n", r); |
|
|
|
goto safecleanup; |
|
|
|
} |