Browse Source

Add temperature conversion. Example usage: ethstream -vvv -c -L -C 141 -r 10

git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@9728 ddd99763-3ecb-0310-9145-efcb8ce7c51f
tags/ethstream-1.3
jim 12 years ago
parent
commit
3ba616841e
3 changed files with 33 additions and 10 deletions
  1. +15
    -9
      ethstream.c
  2. +15
    -1
      ue9.c
  3. +3
    -0
      ue9.h

+ 15
- 9
ethstream.c View File

@@ -57,7 +57,7 @@ struct options opt[] = {
{'g', "gain", "a,b,c", "Set Labjack AIN channel gains: 0,1,2,4,8 in -C channel order"},
{'o', "oneshot", NULL, "don't retry in case of errors"},
{'f', "forceretry", NULL, "retry no matter what happens"},
{'c', "convert", NULL, "convert output to volts"},
{'c', "convert", NULL, "convert output to volts/temperature"},
{'H', "converthex", NULL, "convert output to hex"},
{'m', "showmem", NULL, "output memory stats with data (NJ only)"},
{'l', "lines", "num", "if set, output this many lines and quit"},
@@ -765,16 +765,22 @@ int data_callback(int channels, int *channel_list, int gain_count, int *gain_lis
/* CONVERT_VOLTS */
if (i < gain_count)
{
if (printf("%lf", ue9_binary_to_analog(
&ci->calib, gain_list[i],
12, data[i])) < 0)
goto bad;
if (printf("%lf", ue9_binary_to_analog(
&ci->calib, gain_list[i],
12, data[i])) < 0)
goto bad;
} else {
if (printf("%lf", ue9_binary_to_analog(
&ci->calib, 0,
12, data[i])) < 0)
goto bad;
if (printf("%lf", ue9_binary_to_analog(
&ci->calib, 0,
12, data[i])) < 0)
goto bad;
}
} else if (ci->convert == CONVERT_VOLTS &&
(channel_list[i] == 141 || channel_list[i] == 133)) {
/* CONVERT_VOLTS but output temperature */
if (printf("%lf", ue9_binary_to_temperature(
&ci->calib, data[i])) < 0)
goto bad;
} else if (ci->convert == CONVERT_HEX) {
/* CONVERT_HEX */
if (printf("%04X", data[i]) < 0)


+ 15
- 1
ue9.c View File

@@ -116,6 +116,20 @@ int ue9_verify_extended(uint8_t * buffer, size_t len)
return 1;
}

/* Temperature conversion. If calib is NULL, use uncalibrated conversions. */
double ue9_binary_to_temperature(struct ue9Calibration *calib, uint16_t data)
{
double slope;

if (calib == NULL) {
slope = 0.012683;
} else {
slope = calib->tempSlope;
}

return data * slope; /* output is in Kelvin */
}

/* Data conversion. If calib is NULL, use uncalibrated conversions. */
double
ue9_binary_to_analog(struct ue9Calibration *calib,
@@ -804,6 +818,6 @@ ue9_stream_data(int fd, int channels, int *channel_list, int gain_count, int *ga

/*
Local variables:
c-basic-offset: 2
c-basic-offset: 8
End:
*/

+ 3
- 0
ue9.h View File

@@ -106,6 +106,9 @@ int ue9_get_control_config(int fd, struct ue9ControlConfig *config);
double ue9_binary_to_analog(struct ue9Calibration *calib,
int gain, uint8_t resolution, uint16_t data);

/* Temperature conversion. If calib is NULL, use uncalibrated conversions. */
double ue9_binary_to_temperature(struct ue9Calibration *calib, uint16_t data);

/* Compute scanrate based on the provided values. */
double ue9_compute_rate(uint8_t scanconfig, uint16_t scaninterval);



Loading…
Cancel
Save