fix bug in logger

This commit is contained in:
eddyem 2018-05-27 18:48:49 +03:00
parent 74c21e8b0f
commit a6ef59c73e
5 changed files with 11 additions and 5463 deletions

View File

@ -4,7 +4,7 @@ LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-a
LDFLAGS += -lm -pthread
SRCS := $(wildcard *.c)
DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111
DEFINES += -DEBUG
#DEFINES += -DEBUG
OBJDIR := mk
CFLAGS += -Wall -Wextra -Werror -O2 -Wno-trampolines -std=gnu99
OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o))
@ -31,7 +31,7 @@ $(OBJDIR)/%.o: %.c
clean:
@echo -e "\t\tCLEAN"
@rm -f $(OBJS) $(DEPS) mk/*.d
@rm -f $(OBJS) $(DEPS)
@rmdir $(OBJDIR) 2>/dev/null || true
xclean: clean

View File

@ -9,3 +9,5 @@ tsys_daemon - simple data logger
-o, --output=arg output file name
-r, --rewrite rewrite existing log file
-t, --poll-time=arg pause between subsequent readings (default: 5sec)

5405
src/log

File diff suppressed because it is too large Load Diff

View File

@ -1,49 +0,0 @@
function [tm T goodrecs diffs] = readtemp(name)
% return arrays of unix time & temperatures from file `name`
% substitute missed values by interpolation
T = dlmread(name);
nrecs = size(T, 1);
nsensors = size(T, 2) - 1;
if(nrecs < 2 || nsensors < 2) return; endif
tm = T(:, 1);
tm -= tm(1);
T(:,1) = [];
goodrecs = [];
% interpolate missing values
for N = 1:nsensors
term = T(:, N);
badidxs = find(term < -275.);
bads = size(badidxs, 1);
if(bads == nrecs)
printf("%d: all data records are bad\n", N);
continue;
elseif(bads) % some records are bad, try to make interpolation
printf("%d: %d bad records\n", N, bads);
tmx = tm; Tx = term;
tmx(badidxs) = [];
Tx(badidxs) = [];
T(:, N) = interp1(tmx, Tx, tm);
endif
goodrecs = [goodrecs N];
endfor
% remove strings with NANs
ii = find(isnan(T));
s = size(T, 1);
idxs = ii - s*floor((ii-1)/s);
T(idxs, :) = [];
tm(idxs) = [];
diffs = T - median(T,2);
% now remove bad records
for N = goodrecs
term = abs(diffs(:, N));
badidxs = find(term > 3.);
bads = size(badidxs, 1);
if(bads)
tmx = tm; Tx = T(:, N);
tmx(badidxs) = [];
Tx(badidxs) = [];
T(:, N) = interp1(tmx, Tx, tm);
endif
endfor
diffs = T - median(T,2);
endfunction

View File

@ -306,19 +306,19 @@ static void gettemp(int fd, size_t L){
if(!Ti[i]) continue;
// check coefficients & try to get them again if absent
int C=0, j;
for(j = 0; j < 5; ++j) if(coefficients[0][i][j]) ++C;
if(C != 5 && !get_coefficients(0)) continue;
for(j = 0; j < 5; ++j) if(coefficients[L][i][j]) ++C;
if(C != 5 && !get_coefficients(L)) continue;
double d = (double)Ti[i]/256., tmp = 0.;
DBG("val256=%g", d);
// k0*(-1.5e-2) + 0.1*1e-5*val*(1*k1 + 1e-5*val*(-2.*k2 + 1e-5*val*(4*k3 + 1e-5*val*(-2*k4))))
double mul[5] = {-1.5e-2, 1., -2., 4., -2.};
for(j = 4; j > 0; --j){
tmp += mul[j] * (double)coefficients[0][i][j];
tmp += mul[j] * (double)coefficients[L][i][j];
tmp *= 1e-5*d;
DBG("tmp=%g, K=%d, mul=%g", tmp, coefficients[0][i][j], mul[j]);
DBG("tmp=%g, K=%d, mul=%g", tmp, coefficients[L][i][j], mul[j]);
}
DBG("tmp: %g, mul[0]=%g, c0=%d", tmp, mul[0], coefficients[0][i][0]);
tmp = tmp/10. + mul[0]*coefficients[0][i][0];
DBG("tmp: %g, mul[0]=%g, c0=%d", tmp, mul[0], coefficients[L][i][0]);
tmp = tmp/10. + mul[0]*coefficients[L][i][0];
Td[i] = tmp;
DBG("Got temp: %g", tmp);
}
@ -374,7 +374,7 @@ void begin_logging(int fd, double pause){
}
}
// try to convert temperature
gettemp(fd, L);
gettemp(fd, n);
break;
}
if(i == NTRY) emptyrec();