mirror of
https://github.com/eddyem/tsys01.git
synced 2025-12-06 10:35:14 +03:00
fix bug in logger
This commit is contained in:
parent
74c21e8b0f
commit
a6ef59c73e
@ -4,7 +4,7 @@ LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-a
|
|||||||
LDFLAGS += -lm -pthread
|
LDFLAGS += -lm -pthread
|
||||||
SRCS := $(wildcard *.c)
|
SRCS := $(wildcard *.c)
|
||||||
DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111
|
DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111
|
||||||
DEFINES += -DEBUG
|
#DEFINES += -DEBUG
|
||||||
OBJDIR := mk
|
OBJDIR := mk
|
||||||
CFLAGS += -Wall -Wextra -Werror -O2 -Wno-trampolines -std=gnu99
|
CFLAGS += -Wall -Wextra -Werror -O2 -Wno-trampolines -std=gnu99
|
||||||
OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o))
|
OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o))
|
||||||
@ -31,7 +31,7 @@ $(OBJDIR)/%.o: %.c
|
|||||||
|
|
||||||
clean:
|
clean:
|
||||||
@echo -e "\t\tCLEAN"
|
@echo -e "\t\tCLEAN"
|
||||||
@rm -f $(OBJS) $(DEPS) mk/*.d
|
@rm -f $(OBJS) $(DEPS)
|
||||||
@rmdir $(OBJDIR) 2>/dev/null || true
|
@rmdir $(OBJDIR) 2>/dev/null || true
|
||||||
|
|
||||||
xclean: clean
|
xclean: clean
|
||||||
|
|||||||
@ -9,3 +9,5 @@ tsys_daemon - simple data logger
|
|||||||
-o, --output=arg output file name
|
-o, --output=arg output file name
|
||||||
-r, --rewrite rewrite existing log file
|
-r, --rewrite rewrite existing log file
|
||||||
-t, --poll-time=arg pause between subsequent readings (default: 5sec)
|
-t, --poll-time=arg pause between subsequent readings (default: 5sec)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -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
|
|
||||||
14
src/term.c
14
src/term.c
@ -306,19 +306,19 @@ static void gettemp(int fd, size_t L){
|
|||||||
if(!Ti[i]) continue;
|
if(!Ti[i]) continue;
|
||||||
// check coefficients & try to get them again if absent
|
// check coefficients & try to get them again if absent
|
||||||
int C=0, j;
|
int C=0, j;
|
||||||
for(j = 0; j < 5; ++j) if(coefficients[0][i][j]) ++C;
|
for(j = 0; j < 5; ++j) if(coefficients[L][i][j]) ++C;
|
||||||
if(C != 5 && !get_coefficients(0)) continue;
|
if(C != 5 && !get_coefficients(L)) continue;
|
||||||
double d = (double)Ti[i]/256., tmp = 0.;
|
double d = (double)Ti[i]/256., tmp = 0.;
|
||||||
DBG("val256=%g", d);
|
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))))
|
// 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.};
|
double mul[5] = {-1.5e-2, 1., -2., 4., -2.};
|
||||||
for(j = 4; j > 0; --j){
|
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;
|
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]);
|
DBG("tmp: %g, mul[0]=%g, c0=%d", tmp, mul[0], coefficients[L][i][0]);
|
||||||
tmp = tmp/10. + mul[0]*coefficients[0][i][0];
|
tmp = tmp/10. + mul[0]*coefficients[L][i][0];
|
||||||
Td[i] = tmp;
|
Td[i] = tmp;
|
||||||
DBG("Got temp: %g", tmp);
|
DBG("Got temp: %g", tmp);
|
||||||
}
|
}
|
||||||
@ -374,7 +374,7 @@ void begin_logging(int fd, double pause){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// try to convert temperature
|
// try to convert temperature
|
||||||
gettemp(fd, L);
|
gettemp(fd, n);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(i == NTRY) emptyrec();
|
if(i == NTRY) emptyrec();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user