add gnuplot plotting

This commit is contained in:
eddyem 2018-08-27 17:17:59 +03:00
parent bc1d8a2571
commit 07cadf587f
12 changed files with 271 additions and 61 deletions

View File

@ -11,3 +11,11 @@ Answer format: "X Y T t", where
- X and Y are cartesian coordinates relative to mirror center (decimeters), - X and Y are cartesian coordinates relative to mirror center (decimeters),
- T is measured temperature (degrees Celsium), - T is measured temperature (degrees Celsium),
- t is UNIX-time of last measurement. - t is UNIX-time of last measurement.
To look graph over gnuplot utility collect gnuplot javascript files in subdirectory js of web-server
images storing directory, copy there script 'plot' and run service as
netdaemon -g -s /path/to/web /path/to/log
Every 15 minutes it will calculate average values of thermal data and plot three graphs:
T0.html with top temperatures, T1.html with bottom and Tgrad.html with their differences (T0-T1).

View File

@ -30,7 +30,7 @@
* here are global parameters initialisation * here are global parameters initialisation
*/ */
int help; int help;
glob_pars G; static glob_pars G;
// default values for Gdefault & help // default values for Gdefault & help
#define DEFAULT_COMDEV "/dev/ttyUSB0" #define DEFAULT_COMDEV "/dev/ttyUSB0"
@ -42,6 +42,8 @@ glob_pars const Gdefault = {
.device = DEFAULT_COMDEV, .device = DEFAULT_COMDEV,
.port = DEFAULT_PORT, .port = DEFAULT_PORT,
.terminal = 0, .terminal = 0,
.savepath = NULL,
.makegraphs = 0,
.rest_pars = NULL, .rest_pars = NULL,
.rest_pars_num = 0 .rest_pars_num = 0
}; };
@ -56,6 +58,8 @@ myoption cmdlnopts[] = {
{"device", NEED_ARG, NULL, 'i', arg_string, APTR(&G.device), _("serial device name (default: " DEFAULT_COMDEV ")")}, {"device", NEED_ARG, NULL, 'i', arg_string, APTR(&G.device), _("serial device name (default: " DEFAULT_COMDEV ")")},
{"port", NEED_ARG, NULL, 'p', arg_string, APTR(&G.port), _("network port to connect (default: " DEFAULT_PORT ")")}, {"port", NEED_ARG, NULL, 'p', arg_string, APTR(&G.port), _("network port to connect (default: " DEFAULT_PORT ")")},
{"terminal",NO_ARGS, NULL, 't', arg_int, APTR(&G.terminal), _("run as terminal")}, {"terminal",NO_ARGS, NULL, 't', arg_int, APTR(&G.terminal), _("run as terminal")},
{"savepath",NEED_ARG, NULL, 's', arg_string, APTR(&G.savepath), _("path where files would be saved (if none - don't save)")},
{"graphplot",NO_ARGS, NULL, 'g', arg_int, APTR(&G.makegraphs),_("make graphics with gnuplot")},
end_option end_option
}; };

View File

@ -33,8 +33,10 @@ typedef struct{
char *device; // serial device name char *device; // serial device name
char *port; // port to connect char *port; // port to connect
int terminal; // run as terminal int terminal; // run as terminal
char *savepath; // path where data & graphical files would be saved
int makegraphs; // ==1 to make graphics with gnuplot
int rest_pars_num; // number of rest parameters int rest_pars_num; // number of rest parameters
char** rest_pars; // the rest parameters: array of char* char** rest_pars; // the rest parameters: array of char* (path to logfile and thrash)
} glob_pars; } glob_pars;

View File

@ -52,7 +52,7 @@
*/ */
// sensors groups coordinates: [Nsensor][Ncontroller][xy] // sensors groups coordinates: [Nsensor][Ncontroller][xy]
static const int SensCoords[8][8][2] = { const int SensCoords[8][8][2] = {
// sensor 0, unloads: none,7,6,13,3 // sensor 0, unloads: none,7,6,13,3
{{0,0},{13,-4},{3,5},{-13,4},{-3,-5}}, {{0,0},{13,-4},{3,5},{-13,4},{-3,-5}},
// sensor 1, unloads: none,9,17,15,11 // sensor 1, unloads: none,9,17,15,11

111
src/netdaemon/gnuplot.c Normal file
View File

@ -0,0 +1,111 @@
/*
* geany_encoding=koi8-r
* gnuplot.c
*
* Copyright 2018 Edward V. Emelianov <eddy@sao.ru, edward.emelianoff@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*/
#include <stdio.h> // file operations
#include <unistd.h> // access() to check file exists
#include <linux/limits.h> // PATH_MAX
#include "usefull_macros.h" // putlog
#include "cmdlnopts.h" // glob_pars
extern const int SensCoords[8][8][2];
extern glob_pars *G;
static char fullpath[PATH_MAX];
// create full name from path and file
char *mkname(char *path, char *fname){
if(path[strlen(path)-1] == '/') snprintf(fullpath, PATH_MAX, "%s%s", path, fname);
else snprintf(fullpath, PATH_MAX, "%s/%s", path, fname);
DBG("fullpath: %s", fullpath);
return fullpath;
}
/**
* form files for gnuplot
* @param fname (i) - filename with full path
* @param data (i) - thermal data array
* @return 1 if all OK
*/
static int formfile(char *fname, double data[8][8]){
FILE *F = fopen(fname, "w");
if(!F) return 0;
int i, N;
for(i = 1; i < 8; ++i){
for(N = 0; N < 8; ++ N){
double T = data[N][i];
if(T > -100. && T < 100.){
fprintf(F, "%d\t%d\t%.2f\n", SensCoords[N][i][0],
SensCoords[N][i][1], T);
}
}
}
fclose(F);
DBG("File %s ready", fname);
return 1;
}
/**
* plot drawings with gnuplot
* @param path (i) - path to directory with data & scripts
* @param fname (i) - name of file with data
*/
static void gnuplot(char *path, char *fname){
char *ctmp = mkname(path, "plot");
char buf[PATH_MAX*2];
size_t L = PATH_MAX*2;
if(access(ctmp, F_OK)){
WARNX(_("Don't find %s to plot graphics"), ctmp);
putlog("Don't find %s to plot graphics", ctmp);
return;
}
ssize_t l = snprintf(buf, L, "%s ", ctmp);
if(l < 1) return;
ctmp = mkname(path, fname);
snprintf(buf+l, L, "%s", ctmp);
DBG("Run %s", buf);
if(system(buf)){
WARNX(_("Can't run `%s`"), buf);
putlog("Can't run `%s`", buf);
}
}
void plot(double data[2][8][8], char *savepath){
double dY[8][8]; // vertical gradients (top - bottom)
int i, N;
// calculate gradients
for(i = 1; i < 8; ++i){
for(N = 0; N < 8; ++ N){
double Ttop = data[0][N][i], Tbot = data[1][N][i];
if(Ttop > -100. && Ttop < 100. && Tbot > -100. && Tbot < 100.){
double dT = Ttop - Tbot;
if(dT > -2. && dT < 2.) dY[N][i] = dT;
else dY[N][i] = -300.;
}else dY[N][i] = -300.;
}
}
char *ctmp = mkname(savepath, "T0");
if(formfile(ctmp, data[0])) if(G->makegraphs) gnuplot(savepath, "T0");
ctmp = mkname(savepath, "T1");
if(formfile(ctmp, data[1])) if(G->makegraphs) gnuplot(savepath, "T1");
ctmp = mkname(savepath, "Tgrad");
if(formfile(ctmp, dY)) if(G->makegraphs) gnuplot(savepath, "Tgrad");
}

29
src/netdaemon/gnuplot.h Normal file
View File

@ -0,0 +1,29 @@
/*
* geany_encoding=koi8-r
* gnuplot.h
*
* Copyright 2018 Edward V. Emelianov <eddy@sao.ru, edward.emelianoff@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*/
#pragma once
#ifndef __GNUPLOT_H__
#define __GNUPLOT_H__
void plot(double data[2][8][8], char *savepath);
#endif // __GNUPLOT_H__

View File

@ -25,6 +25,8 @@
#include "cmdlnopts.h" #include "cmdlnopts.h"
#include "socket.h" #include "socket.h"
glob_pars *G;
void signals(int signo){ void signals(int signo){
restore_console(); restore_console();
restore_tty(); restore_tty();
@ -39,9 +41,12 @@ int main(int argc, char **argv){
signal(SIGINT, signals); // ctrl+C - quit signal(SIGINT, signals); // ctrl+C - quit
signal(SIGQUIT, signals); // ctrl+\ - quit signal(SIGQUIT, signals); // ctrl+\ - quit
signal(SIGTSTP, SIG_IGN); // ignore ctrl+Z signal(SIGTSTP, SIG_IGN); // ignore ctrl+Z
glob_pars *G = parse_args(argc, argv); G = parse_args(argc, argv);
if(G->rest_pars_num) if(G->rest_pars_num)
openlogfile(G->rest_pars[0]); openlogfile(G->rest_pars[0]);
if(G->makegraphs && !G->savepath){
ERRX(_("Point the path to graphical files"));
}
#ifndef EBUG #ifndef EBUG
if(daemon(1, 0)){ if(daemon(1, 0)){
ERR("daemon()"); ERR("daemon()");
@ -61,6 +66,7 @@ int main(int argc, char **argv){
} }
} }
#endif #endif
DBG("dev: %s", G->device);
try_connect(G->device); try_connect(G->device);
if(check_sensors()){ if(check_sensors()){
putlog("no sensors detected"); putlog("no sensors detected");

View File

@ -547,7 +547,8 @@ F_ULOCK
F_UNLCKÌ65536Ö0 F_UNLCKÌ65536Ö0
F_WRLCKÌ65536Ö0 F_WRLCKÌ65536Ö0
FlogÌ16384Ö0ÏFILE * FlogÌ16384Ö0ÏFILE *
GÌ16384Ö0Ïglob_pars GÌ16384Ö0Ïglob_pars *
GÌ32768Ö0Ïglob_pars *
GAI_NOWAITÌ65536Ö0 GAI_NOWAITÌ65536Ö0
GAI_WAITÌ65536Ö0 GAI_WAITÌ65536Ö0
GREENÌ65536Ö0 GREENÌ65536Ö0
@ -998,7 +999,7 @@ MSG_ZEROCOPY
MS_ASYNCÌ65536Ö0 MS_ASYNCÌ65536Ö0
MS_INVALIDATEÌ65536Ö0 MS_INVALIDATEÌ65536Ö0
MS_SYNCÌ65536Ö0 MS_SYNCÌ65536Ö0
MULT_PARÌ4Îanon_enum_3Ö0 MULT_PARÌ4Îanon_enum_4Ö0
M_1_PIÌ65536Ö0 M_1_PIÌ65536Ö0
M_1_PIf128Ì65536Ö0 M_1_PIf128Ì65536Ö0
M_1_PIf32Ì65536Ö0 M_1_PIf32Ì65536Ö0
@ -1098,7 +1099,7 @@ NAME_MAX
NANÌ65536Ö0 NANÌ65536Ö0
NCCÌ65536Ö0 NCCÌ65536Ö0
NCCSÌ65536Ö0 NCCSÌ65536Ö0
NEED_ARGÌ4Îanon_enum_3Ö0 NEED_ARGÌ4Îanon_enum_4Ö0
NETDB_INTERNALÌ65536Ö0 NETDB_INTERNALÌ65536Ö0
NETDB_SUCCESSÌ65536Ö0 NETDB_SUCCESSÌ65536Ö0
NFDBITSÌ65536Ö0 NFDBITSÌ65536Ö0
@ -1125,7 +1126,7 @@ NL_SETMAX
NL_TEXTMAXÌ65536Ö0 NL_TEXTMAXÌ65536Ö0
NOFLSHÌ65536Ö0 NOFLSHÌ65536Ö0
NO_ADDRESSÌ65536Ö0 NO_ADDRESSÌ65536Ö0
NO_ARGSÌ4Îanon_enum_3Ö0 NO_ARGSÌ4Îanon_enum_4Ö0
NO_DATAÌ65536Ö0 NO_DATAÌ65536Ö0
NO_RECOVERYÌ65536Ö0 NO_RECOVERYÌ65536Ö0
NR_OPENÌ65536Ö0 NR_OPENÌ65536Ö0
@ -1159,7 +1160,7 @@ ONLRET
ONOCRÌ65536Ö0 ONOCRÌ65536Ö0
OPEN_MAXÌ65536Ö0 OPEN_MAXÌ65536Ö0
OPOSTÌ65536Ö0 OPOSTÌ65536Ö0
OPT_ARGÌ4Îanon_enum_3Ö0 OPT_ARGÌ4Îanon_enum_4Ö0
O_ACCMODEÌ65536Ö0 O_ACCMODEÌ65536Ö0
O_APPENDÌ65536Ö0 O_APPENDÌ65536Ö0
O_ASYNCÌ65536Ö0 O_ASYNCÌ65536Ö0
@ -2147,6 +2148,7 @@ S_TYPEISMQ
S_TYPEISSEMÌ131072Í(buf)Ö0 S_TYPEISSEMÌ131072Í(buf)Ö0
S_TYPEISSHMÌ131072Í(buf)Ö0 S_TYPEISSHMÌ131072Í(buf)Ö0
SensCoordsÌ16384Ö0Ïconst int SensCoordsÌ16384Ö0Ïconst int
SensCoordsÌ32768Ö0Ïconst int
TAB0Ì65536Ö0 TAB0Ì65536Ö0
TAB1Ì65536Ö0 TAB1Ì65536Ö0
TAB2Ì65536Ö0 TAB2Ì65536Ö0
@ -2258,9 +2260,9 @@ TIOCSWINSZ
TIOCVHANGUPÌ65536Ö0 TIOCVHANGUPÌ65536Ö0
TMP_MAXÌ65536Ö0 TMP_MAXÌ65536Ö0
TOSTOPÌ65536Ö0 TOSTOPÌ65536Ö0
TRANS_ERRORÌ4Îanon_enum_6Ö0 TRANS_ERRORÌ4Îanon_enum_2Ö0
TRANS_SUCCEEDÌ4Îanon_enum_6Ö0 TRANS_SUCCEEDÌ4Îanon_enum_2Ö0
TRANS_TIMEOUTÌ4Îanon_enum_6Ö0 TRANS_TIMEOUTÌ4Îanon_enum_2Ö0
TRAP_BRKPTÌ65536Ö0 TRAP_BRKPTÌ65536Ö0
TRAP_TRACEÌ65536Ö0 TRAP_TRACEÌ65536Ö0
TRUEÌ65536Ö0 TRUEÌ65536Ö0
@ -3633,6 +3635,7 @@ __GNUC_STDC_INLINE__
__GNUC_VA_LISTÌ65536Ö0 __GNUC_VA_LISTÌ65536Ö0
__GNUC__Ì65536Ö0 __GNUC__Ì65536Ö0
__GNUG__Ì65536Ö0 __GNUG__Ì65536Ö0
__GNUPLOT_H__Ì65536Ö0
__GNU_GETTEXT_SUPPORTED_REVISIONÌ131072Í(major)Ö0 __GNU_GETTEXT_SUPPORTED_REVISIONÌ131072Í(major)Ö0
__GNU_LIBRARY__Ì65536Ö0 __GNU_LIBRARY__Ì65536Ö0
__GXX_ABI_VERSIONÌ65536Ö0 __GXX_ABI_VERSIONÌ65536Ö0
@ -4545,8 +4548,8 @@ __kernel_caddr_t
__kernel_clock_tÌ4096Ö0Ï__kernel_long_t __kernel_clock_tÌ4096Ö0Ï__kernel_long_t
__kernel_clockid_tÌ4096Ö0Ïint __kernel_clockid_tÌ4096Ö0Ïint
__kernel_daddr_tÌ4096Ö0Ïint __kernel_daddr_tÌ4096Ö0Ïint
__kernel_fd_setÌ4096Ö0Ïanon_struct_21 __kernel_fd_setÌ4096Ö0Ïanon_struct_8
__kernel_fsid_tÌ4096Ö0Ïanon_struct_22 __kernel_fsid_tÌ4096Ö0Ïanon_struct_9
__kernel_gid16_tÌ4096Ö0Ïunsigned short __kernel_gid16_tÌ4096Ö0Ïunsigned short
__kernel_gid32_tÌ4096Ö0Ïunsigned int __kernel_gid32_tÌ4096Ö0Ïunsigned int
__kernel_gid_tÌ4096Ö0Ïunsigned int __kernel_gid_tÌ4096Ö0Ïunsigned int
@ -4623,7 +4626,6 @@ __sigevent_t_defined
__siginfo_t_definedÌ65536Ö0 __siginfo_t_definedÌ65536Ö0
__sigset_t_definedÌ65536Ö0 __sigset_t_definedÌ65536Ö0
__sigstack_definedÌ65536Ö0 __sigstack_definedÌ65536Ö0
__sigval_tÌ4096Ö0Ïsigval
__sigval_t_definedÌ65536Ö0 __sigval_t_definedÌ65536Ö0
__size_tÌ65536Ö0 __size_tÌ65536Ö0
__size_t__Ì65536Ö0 __size_t__Ì65536Ö0
@ -4695,13 +4697,7 @@ __wsum
__wurÌ65536Ö0 __wurÌ65536Ö0
__x86_64Ì65536Ö0 __x86_64Ì65536Ö0
__x86_64__Ì65536Ö0 __x86_64__Ì65536Ö0
_attributeÌ64Îsigevent::anon_union_8::anon_struct_9Ö0Ïpthread_attr_t *
_functionÌ1024Í(__sigval_t)Îsigevent::anon_union_8::anon_struct_9Ö0Ïvoid
_padÌ64Îsigevent::anon_union_8Ö0Ïint
_pthread_cleanup_bufferÌ2048Ö0 _pthread_cleanup_bufferÌ2048Ö0
_sigev_threadÌ64Îsigevent::anon_union_8Ö0Ïanon_struct_9
_sigev_unÌ64ÎsigeventÖ0Ïanon_union_8
_tidÌ64Îsigevent::anon_union_8Ö0Ï__pid_t
abortÌ64ÎstdÖ0Ïusing abortÌ64ÎstdÖ0Ïusing
abortÌ65536Ö0 abortÌ65536Ö0
absÌ64ÎstdÖ0Ïusing absÌ64ÎstdÖ0Ïusing
@ -4726,31 +4722,29 @@ anon_enum_19
anon_enum_2Ì2Ö0 anon_enum_2Ì2Ö0
anon_enum_20Ì2Ö0 anon_enum_20Ì2Ö0
anon_enum_3Ì2Ö0 anon_enum_3Ì2Ö0
anon_enum_6Ì2Ö0 anon_enum_4Ì2Ö0
anon_struct_0Ì2048Ö0 anon_struct_0Ì2048Ö0
anon_struct_1Ì2048Ö0 anon_struct_1Ì2048Ö0
anon_struct_10Ì2048Ö0 anon_struct_10Ì2048Ö0
anon_struct_21Ì2048Ö0
anon_struct_22Ì2048Ö0
anon_struct_4Ì2048Ö0
anon_struct_5Ì2048Ö0 anon_struct_5Ì2048Ö0
anon_struct_6Ì2048Ö0
anon_struct_7Ì2048Ö0 anon_struct_7Ì2048Ö0
anon_struct_9Ì2048Îsigevent::anon_union_8Ö0 anon_struct_8Ì2048Ö0
anon_union_8Ì8192ÎsigeventÖ0 anon_struct_9Ì2048Ö0
arg_doubleÌ4Îanon_enum_2Ö0 arg_doubleÌ4Îanon_enum_3Ö0
arg_endÌ64Îprctl_mm_mapÖ0Ï__u64 arg_endÌ64Îprctl_mm_mapÖ0Ï__u64
arg_floatÌ4Îanon_enum_2Ö0 arg_floatÌ4Îanon_enum_3Ö0
arg_functionÌ4Îanon_enum_2Ö0 arg_functionÌ4Îanon_enum_3Ö0
arg_intÌ4Îanon_enum_2Ö0 arg_intÌ4Îanon_enum_3Ö0
arg_longlongÌ4Îanon_enum_2Ö0 arg_longlongÌ4Îanon_enum_3Ö0
arg_noneÌ4Îanon_enum_2Ö0 arg_noneÌ4Îanon_enum_3Ö0
arg_startÌ64Îprctl_mm_mapÖ0Ï__u64 arg_startÌ64Îprctl_mm_mapÖ0Ï__u64
arg_stringÌ4Îanon_enum_2Ö0 arg_stringÌ4Îanon_enum_3Ö0
argfnÌ4096Ö0Ïtypedef bool argfnÌ4096Ö0Ïtypedef bool
argptrÌ64Îanon_struct_4Ö0Ïvoid *
argptrÌ64Îanon_struct_5Ö0Ïvoid * argptrÌ64Îanon_struct_5Ö0Ïvoid *
argptrÌ64Îanon_struct_6Ö0Ïvoid *
argsortÌ16Í(const void *a1, const void *a2)Ö0Ïint argsortÌ16Í(const void *a1, const void *a2)Ö0Ïint
argtypeÌ4096Ö0Ïanon_enum_2 argtypeÌ4096Ö0Ïanon_enum_3
asinÌ64ÎstdÖ0Ïusing asinÌ64ÎstdÖ0Ïusing
asinÌ65536Ö0 asinÌ65536Ö0
asinhÌ64ÎstdÖ0Ïusing asinhÌ64ÎstdÖ0Ïusing
@ -4865,8 +4859,8 @@ fdim
fdimÌ65536Ö0 fdimÌ65536Ö0
fdimfÌ65536Ö0 fdimfÌ65536Ö0
fdimlÌ65536Ö0 fdimlÌ65536Ö0
fds_bitsÌ64Îanon_struct_21Ö0Ïunsigned long fds_bitsÌ64Îanon_struct_8Ö0Ïunsigned long
flagÌ64Îanon_struct_4Ö0Ïint * flagÌ64Îanon_struct_5Ö0Ïint *
floorÌ64ÎstdÖ0Ïusing floorÌ64ÎstdÖ0Ïusing
floorÌ65536Ö0 floorÌ65536Ö0
fmaÌ64ÎstdÖ0Ïusing fmaÌ64ÎstdÖ0Ïusing
@ -4883,6 +4877,7 @@ fminf
fminlÌ65536Ö0 fminlÌ65536Ö0
fmodÌ64ÎstdÖ0Ïusing fmodÌ64ÎstdÖ0Ïusing
fmodÌ65536Ö0 fmodÌ65536Ö0
formfileÌ16Í(char *fname, double data[8][8])Ö0Ïint
fpclassifyÌ64ÎstdÖ0Ïusing fpclassifyÌ64ÎstdÖ0Ïusing
fpclassifyÌ65536Ö0 fpclassifyÌ65536Ö0
fpclassifyÌ131072Í(x)Ö0 fpclassifyÌ131072Í(x)Ö0
@ -4892,6 +4887,7 @@ free
freqÌ64ÎtimexÖ0Ï__syscall_slong_t freqÌ64ÎtimexÖ0Ï__syscall_slong_t
frexpÌ64ÎstdÖ0Ïusing frexpÌ64ÎstdÖ0Ïusing
frexpÌ65536Ö0 frexpÌ65536Ö0
fullpathÌ16384Ö0Ïchar
g_pr_Ì16Í(const char *fmt, ...)Ö0Ïint g_pr_Ì16Í(const char *fmt, ...)Ö0Ïint
get_aptrÌ16Í(void *paptr, argtype type)Ö0Ïvoid * get_aptrÌ16Í(void *paptr, argtype type)Ö0Ïvoid *
get_optindÌ16Í(int opt, myoption *options)Ö0Ïint get_optindÌ16Í(int opt, myoption *options)Ö0Ïint
@ -4904,14 +4900,15 @@ gid_t
globErrÌ16384Ö0Ïint globErrÌ16384Ö0Ïint
globErrÌ32768Ö0Ïint globErrÌ32768Ö0Ïint
glob_parsÌ4096Ö0Ïanon_struct_7 glob_parsÌ4096Ö0Ïanon_struct_7
gnuplotÌ16Í(char *path, char *fname)Ö0Ïvoid
greenÌ1024Í(const char *fmt, ...)Ö0Ïint greenÌ1024Í(const char *fmt, ...)Ö0Ïint
h_addrÌ65536Ö0 h_addrÌ65536Ö0
h_errnoÌ65536Ö0 h_errnoÌ65536Ö0
handle_socketÌ16Í(void *asock)Ö0Ïvoid * handle_socketÌ16Í(void *asock)Ö0Ïvoid *
has_argÌ64Îanon_struct_4Ö0Ïhasarg
has_argÌ64Îanon_struct_5Ö0Ïhasarg has_argÌ64Îanon_struct_5Ö0Ïhasarg
hasargÌ4096Ö0Ïanon_enum_3 has_argÌ64Îanon_struct_6Ö0Ïhasarg
helpÌ64Îanon_struct_4Ö0Ïconst char * hasargÌ4096Ö0Ïanon_enum_4
helpÌ64Îanon_struct_5Ö0Ïconst char *
helpÌ16384Ö0Ïint helpÌ16384Ö0Ïint
helpstringÌ16384Ö0Ïchar * helpstringÌ16384Ö0Ïchar *
htobe16Ì131072Í(x)Ö0 htobe16Ì131072Í(x)Ö0
@ -5031,6 +5028,7 @@ lround
lroundfÌ65536Ö0 lroundfÌ65536Ö0
lroundlÌ65536Ö0 lroundlÌ65536Ö0
mainÌ16Í(int argc, char **argv)Ö0Ïint mainÌ16Í(int argc, char **argv)Ö0Ïint
makegraphsÌ64Îanon_struct_7Ö0Ïint
mallocÌ64ÎstdÖ0Ïusing mallocÌ64ÎstdÖ0Ïusing
mallocÌ65536Ö0 mallocÌ65536Ö0
math_errhandlingÌ65536Ö0 math_errhandlingÌ65536Ö0
@ -5044,6 +5042,7 @@ mbtowc
mbtowcÌ65536Ö0 mbtowcÌ65536Ö0
meanTÌ16384Ö0Ïdouble meanTÌ16384Ö0Ïdouble
minÌ65536Ö0 minÌ65536Ö0
mknameÌ16Í(char *path, char *fname)Ö0Ïchar *
mmapbufÌ4096Ö0Ïanon_struct_1 mmapbufÌ4096Ö0Ïanon_struct_1
mode_tÌ4096Ö0Ï__mode_t mode_tÌ4096Ö0Ï__mode_t
modesÌ64ÎtimexÖ0Ïunsigned int modesÌ64ÎtimexÖ0Ïunsigned int
@ -5056,14 +5055,14 @@ myatod
myatollÌ16Í(void *num, char *str, argtype t)Ö0Ïbool myatollÌ16Í(void *num, char *str, argtype t)Ö0Ïbool
mygetcharÌ16Í()Ö0Ïint mygetcharÌ16Í()Ö0Ïint
mygetcharÌ1024Í()Ö0Ïint mygetcharÌ1024Í()Ö0Ïint
myoptionÌ4096Ö0Ïanon_struct_4 myoptionÌ4096Ö0Ïanon_struct_5
mysuboptionÌ4096Ö0Ïanon_struct_5 mysuboptionÌ4096Ö0Ïanon_struct_6
n_addrtypeÌ64ÎnetentÖ0Ïint n_addrtypeÌ64ÎnetentÖ0Ïint
n_aliasesÌ64ÎnetentÖ0Ïchar * * n_aliasesÌ64ÎnetentÖ0Ïchar * *
n_nameÌ64ÎnetentÖ0Ïchar * n_nameÌ64ÎnetentÖ0Ïchar *
n_netÌ64ÎnetentÖ0Ïuint32_t n_netÌ64ÎnetentÖ0Ïuint32_t
nameÌ64Îanon_struct_4Ö0Ïconst char *
nameÌ64Îanon_struct_5Ö0Ïconst char * nameÌ64Îanon_struct_5Ö0Ïconst char *
nameÌ64Îanon_struct_6Ö0Ïconst char *
nanÌ65536Ö0 nanÌ65536Ö0
nanfÌ65536Ö0 nanfÌ65536Ö0
nanlÌ65536Ö0 nanlÌ65536Ö0
@ -5097,6 +5096,8 @@ parse_args
parse_argsÌ1024Í(int argc, char **argv)Ö0Ïglob_pars * parse_argsÌ1024Í(int argc, char **argv)Ö0Ïglob_pars *
parseargsÌ16Í(int *argc, char ***argv, myoption *options)Ö0Ïvoid parseargsÌ16Í(int *argc, char ***argv, myoption *options)Ö0Ïvoid
parseargsÌ1024Í(int *argc, char ***argv, myoption *options)Ö0Ïvoid parseargsÌ1024Í(int *argc, char ***argv, myoption *options)Ö0Ïvoid
plotÌ16Í(double data[2][8][8], char *savepath)Ö0Ïvoid
plotÌ1024Í(double data[2][8][8], char *savepath)Ö0Ïvoid
poll_sensorsÌ16Í(int N)Ö0Ïint poll_sensorsÌ16Í(int N)Ö0Ïint
poll_sensorsÌ1024Í(int N)Ö0Ïint poll_sensorsÌ1024Í(int N)Ö0Ïint
portÌ64Îanon_struct_7Ö0Ïchar * portÌ64Îanon_struct_7Ö0Ïchar *
@ -5162,6 +5163,7 @@ s6_addr32
s_WARNÌ16Í(const char *fmt, ...)Ö0Ïint s_WARNÌ16Í(const char *fmt, ...)Ö0Ïint
sa_handlerÌ65536Ö0 sa_handlerÌ65536Ö0
sa_sigactionÌ65536Ö0 sa_sigactionÌ65536Ö0
savepathÌ64Îanon_struct_7Ö0Ïchar *
scalblnÌ64ÎstdÖ0Ïusing scalblnÌ64ÎstdÖ0Ïusing
scalblnÌ65536Ö0 scalblnÌ65536Ö0
scalblnfÌ65536Ö0 scalblnfÌ65536Ö0
@ -5201,27 +5203,19 @@ si_uid
si_upperÌ65536Ö0 si_upperÌ65536Ö0
si_utimeÌ65536Ö0 si_utimeÌ65536Ö0
si_valueÌ65536Ö0 si_valueÌ65536Ö0
sigev_notifyÌ64ÎsigeventÖ0Ïint
sigev_notify_attributesÌ65536Ö0 sigev_notify_attributesÌ65536Ö0
sigev_notify_functionÌ65536Ö0 sigev_notify_functionÌ65536Ö0
sigev_signoÌ64ÎsigeventÖ0Ïint
sigev_valueÌ64ÎsigeventÖ0Ï__sigval_t
sigeventÌ2048Ö0
sigeventÌ32768Ö0 sigeventÌ32768Ö0
sigevent_tÌ4096Ö0Ïsigevent
sigmaskÌ131072Í(sig)Ö0 sigmaskÌ131072Í(sig)Ö0
signalsÌ16Í(int signo)Ö0Ïvoid signalsÌ16Í(int signo)Ö0Ïvoid
signalsÌ1024Í(int sig)Ö0Ïvoid signalsÌ1024Í(int sig)Ö0Ïvoid
signbitÌ64ÎstdÖ0Ïusing signbitÌ64ÎstdÖ0Ïusing
signbitÌ65536Ö0 signbitÌ65536Ö0
signbitÌ131072Í(x)Ö0 signbitÌ131072Í(x)Ö0
sigvalÌ8192Ö0
sinÌ64ÎstdÖ0Ïusing sinÌ64ÎstdÖ0Ïusing
sinÌ65536Ö0 sinÌ65536Ö0
sinhÌ64ÎstdÖ0Ïusing sinhÌ64ÎstdÖ0Ïusing
sinhÌ65536Ö0 sinhÌ65536Ö0
sival_intÌ64ÎsigvalÖ0Ïint
sival_ptrÌ64ÎsigvalÖ0Ïvoid *
sqrtÌ64ÎstdÖ0Ïusing sqrtÌ64ÎstdÖ0Ïusing
sqrtÌ65536Ö0 sqrtÌ65536Ö0
srandÌ64ÎstdÖ0Ïusing srandÌ64ÎstdÖ0Ïusing
@ -5295,7 +5289,7 @@ tm_zone
tmeasuredÌ16384Ö0Ïtime_t tmeasuredÌ16384Ö0Ïtime_t
tmeasuredÌ32768Ö0Ïtime_t tmeasuredÌ32768Ö0Ïtime_t
toleranceÌ64ÎtimexÖ0Ï__syscall_slong_t toleranceÌ64ÎtimexÖ0Ï__syscall_slong_t
trans_statusÌ4096Ö0Ïanon_enum_6 trans_statusÌ4096Ö0Ïanon_enum_2
truncÌ64ÎstdÖ0Ïusing truncÌ64ÎstdÖ0Ïusing
truncÌ65536Ö0 truncÌ65536Ö0
truncfÌ65536Ö0 truncfÌ65536Ö0
@ -5307,8 +5301,8 @@ tty_init
tty_initÌ1024Í(char *comdev)Ö0Ïvoid tty_initÌ1024Í(char *comdev)Ö0Ïvoid
tv_nsecÌ64ÎtimespecÖ0Ï__syscall_slong_t tv_nsecÌ64ÎtimespecÖ0Ï__syscall_slong_t
tv_secÌ64ÎtimespecÖ0Ï__time_t tv_secÌ64ÎtimespecÖ0Ï__time_t
typeÌ64Îanon_struct_4Ö0Ïargtype
typeÌ64Îanon_struct_5Ö0Ïargtype typeÌ64Îanon_struct_5Ö0Ïargtype
typeÌ64Îanon_struct_6Ö0Ïargtype
uid_tÌ4096Ö0Ï__uid_t uid_tÌ4096Ö0Ï__uid_t
uint16_tÌ4096Ö0Ï__uint16_t uint16_tÌ4096Ö0Ï__uint16_t
uint32_tÌ4096Ö0Ï__uint32_t uint32_tÌ4096Ö0Ï__uint32_t
@ -5329,8 +5323,8 @@ va_arg
va_copyÌ131072Í(d,s)Ö0 va_copyÌ131072Í(d,s)Ö0
va_endÌ131072Í(v)Ö0 va_endÌ131072Í(v)Ö0
va_startÌ131072Í(v,l)Ö0 va_startÌ131072Í(v,l)Ö0
valÌ64Îanon_struct_22Ö0Ïint valÌ64Îanon_struct_5Ö0Ïint
valÌ64Îanon_struct_4Ö0Ïint valÌ64Îanon_struct_9Ö0Ïint
waittoreadÌ16Í(int sock)Ö0Ïint waittoreadÌ16Í(int sock)Ö0Ïint
wcstombsÌ64ÎstdÖ0Ïusing wcstombsÌ64ÎstdÖ0Ïusing
wcstombsÌ65536Ö0 wcstombsÌ65536Ö0

35
src/netdaemon/plot Executable file
View File

@ -0,0 +1,35 @@
#!/bin/bash
cat << EOF > gnutplt
#!/usr/bin/gnuplot
set contour
unset surface
set cntrparam order 4
set cntrparam bspline
set cntrparam levels auto 6
set view map
set size square
set xrange [-30:30]
set yrange [-30:30]
set dgrid3d 20,20,20
set table "contour.txt"
splot '$1' u 1:2:3
unset table
unset contour
set surface
set table "dgrid.txt"
splot '$1' u 1:2:3
unset table
reset
set terminal canvas enhanced mousing size 1024,768 jsdir 'js'
set output "$1.html"
set size square
set xrange [-30:30]
set yrange [-30:30]
set pm3d map
unset key
#set label font ",2"
splot 'dgrid.txt' w pm3d, 'contour.txt' w l lc rgb "black", '$1' u 1:2:3:3 with labels font ",8"
EOF
chmod 755 gnutplt
./gnutplt

View File

@ -32,6 +32,8 @@
#include <sys/syscall.h> // syscall #include <sys/syscall.h> // syscall
#include "datapoints.xy" // sensors coordinates #include "datapoints.xy" // sensors coordinates
#include "gnuplot.h" // plot graphs
#include "cmdlnopts.h" // glob_pars
#define BUFLEN (10240) #define BUFLEN (10240)
// Max amount of connections // Max amount of connections
@ -42,6 +44,8 @@ static char strT[3][BUFLEN];
// mean temperature // mean temperature
static double meanT; static double meanT;
extern glob_pars *G;
/**************** COMMON FUNCTIONS ****************/ /**************** COMMON FUNCTIONS ****************/
/** /**
* wait for answer from socket * wait for answer from socket
@ -276,9 +280,12 @@ Item quick_select(Item *idata, int n){
#undef ELEM_SWAP #undef ELEM_SWAP
static void process_T(){ static void process_T(){
int i, Num = 0; int i, N, p, Num = 0;
time_t tmeasmax = 0; time_t tmeasmax = 0;
double arr[128]; double arr[128];
// mean temperatures over 15 scans
static double Tmean[2][8][8];
static int Nmean; // amount of measurements for Tmean
// get statistics // get statistics
poll_sensors(0); // poll N2 poll_sensors(0); // poll N2
// scan over controllers on mirror & calculate median // scan over controllers on mirror & calculate median
@ -303,16 +310,28 @@ static void process_T(){
Num = 0; Num = 0;
double Tsum = 0.; double Tsum = 0.;
for(i = 1; i < 8; ++i){ for(i = 1; i < 8; ++i){
int N, p;
for(p = 0; p < 2; ++p) for(N = 0; N < 8; ++ N){ for(p = 0; p < 2; ++p) for(N = 0; N < 8; ++ N){
double T = t_last[p][N][i]; double T = t_last[p][N][i];
if(T > Ttop || T < Tbot || tmeasmax - tmeasured[p][N][i] > 1800){ if(T > Ttop || T < Tbot || tmeasmax - tmeasured[p][N][i] > 1800){
t_last[p][N][i] = -300.; t_last[p][N][i] = -300.;
Tmean[p][N][i] = -3e9;
}else{ }else{
++Num; Tsum += T; ++Num; Tsum += T;
Tmean[p][N][i] += T;
} }
} }
} }
// make graphics
if(G->savepath){
if(++Nmean == GRAPHS_AMOUNT){
for(i = 1; i < 8; ++i)for(p = 0; p < 2; ++p)for(N = 0; N < 8; ++ N){
Tmean[p][N][i] /= Nmean;
}
plot(Tmean, G->savepath);
memset(Tmean, 0, sizeof(double)*2*8*8);
Nmean = 0;
}
}
meanT = Tsum / Num; meanT = Tsum / Num;
DBG("got %d, mean: %g\n\n", Num, meanT); DBG("got %d, mean: %g\n\n", Num, meanT);
} }
@ -340,9 +359,10 @@ static void daemon_(int sock){
if(dtime() - tgot < T_INTERVAL) continue; if(dtime() - tgot < T_INTERVAL) continue;
// get data // get data
int i; int i;
char bufs[3][BUFLEN]; // temporary buffers char bufs[3][BUFLEN]; // temporary buffers: T0, T1, TN2
char *ptrs[3] = {bufs[0], bufs[1], bufs[2]}; char *ptrs[3] = {bufs[0], bufs[1], bufs[2]};
size_t lens[3] = {BUFLEN, BUFLEN, BUFLEN}; // free space size_t lens[3] = {BUFLEN, BUFLEN, BUFLEN}; // free space
tgot = dtime();
process_T(); // get new temperatures & throw out bad results process_T(); // get new temperatures & throw out bad results
for(i = 0; i < 8; ++i){ // scan over controllers for(i = 0; i < 8; ++i){ // scan over controllers
int N, p; int N, p;
@ -370,7 +390,6 @@ static void daemon_(int sock){
} }
} }
//DBG("BUF0:\n%s\nBUF1:\n%s\nBUF2:\n%s", bufs[0],bufs[1],bufs[2]); //DBG("BUF0:\n%s\nBUF1:\n%s\nBUF2:\n%s", bufs[0],bufs[1],bufs[2]);
tgot = dtime();
// copy temporary buffers to main // copy temporary buffers to main
pthread_mutex_lock(&mutex); pthread_mutex_lock(&mutex);
memcpy(strT, bufs, sizeof(strT)); memcpy(strT, bufs, sizeof(strT));

View File

@ -32,6 +32,8 @@
#define T_POLLING_TMOUT (5.0) #define T_POLLING_TMOUT (5.0)
// T measurement time interval - 1 minute // T measurement time interval - 1 minute
#define T_INTERVAL (60.0) #define T_INTERVAL (60.0)
// amount of measurement to plot mean graphs
#define GRAPHS_AMOUNT (15)
// Protocol // Protocol
#define CMD_SENSORS_OFF 'F' #define CMD_SENSORS_OFF 'F'

View File

@ -290,7 +290,7 @@ void restore_tty(){
#endif #endif
// init: // init:
void tty_init(char *comdev){ void tty_init(char *comdev){
DBG("\nOpen port...\n"); DBG("\nOpen port %s ...\n", comdev);
do{ do{
comfd = open(comdev,O_RDWR|O_NOCTTY|O_NONBLOCK); comfd = open(comdev,O_RDWR|O_NOCTTY|O_NONBLOCK);
}while (comfd == -1 && errno == EINTR); }while (comfd == -1 && errno == EINTR);