diff --git a/src/netdaemon/gnuplot.c b/src/netdaemon/gnuplot.c index 2ec2e0a..1442f71 100644 --- a/src/netdaemon/gnuplot.c +++ b/src/netdaemon/gnuplot.c @@ -25,7 +25,6 @@ #include // PATH_MAX #include "usefull_macros.h" // putlog #include "cmdlnopts.h" // glob_pars -#include "sens_place.h" extern glob_pars *G; @@ -46,7 +45,7 @@ char *mkname(char *path, char *fname){ * @param Z (i) - 0 for upper and 1 for lower sensors (Z-coord) * @return 1 if all OK */ -static int formfile(char *fname, double data[2][8][8], int Z){ +static int formfile(char *fname, double data[2][NCHANNEL_MAX+1][NCTRLR_MAX+1], int Z){ FILE *F = fopen(fname, "w"); if(!F) return 0; for(int i = 1; i <= NCTRLR_MAX; ++i){ @@ -90,9 +89,9 @@ static void gnuplot(char *path, char *fname){ } } -void plot(double data[2][8][8], char *savepath){ +void plot(double data[2][NCHANNEL_MAX+1][NCTRLR_MAX+1], char *savepath){ /* - double dY[8][8]; // vertical gradients (top - bottom) + double dY[NCH][NC]; // vertical gradients (top - bottom) // calculate gradients for(int i = 1; i < 8; ++i){ for(int N = 0; N < 8; ++ N){ diff --git a/src/netdaemon/gnuplot.h b/src/netdaemon/gnuplot.h index ad5bebb..1114800 100644 --- a/src/netdaemon/gnuplot.h +++ b/src/netdaemon/gnuplot.h @@ -24,6 +24,8 @@ #ifndef __GNUPLOT_H__ #define __GNUPLOT_H__ -void plot(double data[2][8][8], char *savepath); +#include "sens_place.h" + +void plot(double data[2][NCHANNEL_MAX+1][NCTRLR_MAX+1], char *savepath); #endif // __GNUPLOT_H__ diff --git a/src/netdaemon/socket.c b/src/netdaemon/socket.c index d3e920d..27f1f30 100644 --- a/src/netdaemon/socket.c +++ b/src/netdaemon/socket.c @@ -284,15 +284,15 @@ static void process_T(){ time_t tmeasmax = 0; double arr[128]; // mean temperatures over 15 scans - static double Tmean[2][8][8]; + static double Tmean[2][NCHANNEL_MAX+1][NCTRLR_MAX+1]; static int Nmean; // amount of measurements for Tmean // get statistics poll_sensors(0); // poll N2 // scan over controllers on mirror & calculate median - for(i = 1; i < 8; ++i){ + for(i = 1; i <= NCTRLR_MAX; ++i){ if(poll_sensors(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 <= NCHANNEL_MAX; ++ N){ double T = t_last[p][N][i]; time_t t = tmeasured[p][N][i]; if(T > -100. && T < 100.){ @@ -309,8 +309,8 @@ static void process_T(){ // throw out all more than +-3degrC and calculate meanT Num = 0; double Tsum = 0.; - for(i = 1; i < 8; ++i){ - for(p = 0; p < 2; ++p) for(N = 0; N < 8; ++ N){ + for(i = 1; i <= NCTRLR_MAX; ++i){ + for(p = 0; p < 2; ++p) for(N = 0; N <= NCHANNEL_MAX; ++N){ double T = t_last[p][N][i]; if(T > Ttop || T < Tbot || tmeasmax - tmeasured[p][N][i] > 1800){ t_last[p][N][i] = -300.; @@ -324,11 +324,11 @@ static void process_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){ + for(i = 1; i <= NCTRLR_MAX; ++i)for(p = 0; p < 2; ++p)for(N = 0; N <= NCHANNEL_MAX; ++ N){ Tmean[p][N][i] /= Nmean; } plot(Tmean, G->savepath); - memset(Tmean, 0, sizeof(double)*2*8*8); + memset(Tmean, 0, sizeof(double)*2*(NCTRLR_MAX+1)*(NCHANNEL_MAX+1)); Nmean = 0; } } diff --git a/src/netdaemon/term.c b/src/netdaemon/term.c index a3ee505..d5a4081 100644 --- a/src/netdaemon/term.c +++ b/src/netdaemon/term.c @@ -27,9 +27,9 @@ #define BUFLEN 1024 // UNIX time of temperatures measurement: [Ngroup][Nsensor][Ncontroller] -time_t tmeasured[2][8][8]; +time_t tmeasured[2][NCHANNEL_MAX+1][NCTRLR_MAX+1]; // last temperatures read: [Ngroup][Nsensor][Ncontroller] -double t_last[2][8][8]; +double t_last[2][NCHANNEL_MAX+1][NCTRLR_MAX+1]; /** * read strings from terminal (ending with '\n') with timeout @@ -131,10 +131,11 @@ static int parse_answer(char *buf, int N){ //DBG("buf: %s", buf); int v = getint(buf); //DBG("sensor #%d", v); - if(v < 0 || v > 81) return 0; + //if(v < 0 || v > 81) return 0; i = v/10; v -= i*10; + if(i < 0 || i > NCTRLR_MAX) return 0; //DBG("i=%d, v=%d", i,v); - if((v & 1) != v) return 0; + if((v & 1) != v) return 0; // should be only 0 or 1 if(*buf != '=' ) return 0; ++buf; int T = getint(buf); @@ -154,14 +155,26 @@ static int parse_answer(char *buf, int N){ * @return 0 if all OK */ static int send_cmd(int N, char cmd){ - if(N < 0 || N > 7) return 1; - char buf[4] = {(char)N + '0', cmd, '\n', 0}; + if(N < 0 || N > NCTRLR_MAX) return 1; + char buf[3] = {0}; + int n = 3; char *rtn; + if(N){ // CAN-bus + buf[0] = (char)N + '0'; + buf[1] = cmd; + buf[2] = '\n'; + }else{ // local command + n = 2; + buf[0] = cmd; + buf[1] = '\n'; + } // clear all incomint data while(read_string()); - //DBG("send cmd %s", buf); - if(write_tty(buf, 3)) return 1; + DBG("send cmd %s", buf); + if(write_tty(buf, n)) return 1; + if(N == 0) return 0; if((rtn = read_string())){ + DBG("read_string: %s", rtn); if(*rtn == cmd) return 0; } return 1; @@ -186,7 +199,7 @@ int poll_sensors(int N){ while(dtime() - t0 < T_POLLING_TMOUT && ngot < 16){ // timeout reached or got data from all if((ans = read_string())){ // parse new data //DBG("got %s", ans); - if(*ans == 'T'){ // data from sensor + if(*ans == CMD_MEASURE_T){ // data from sensor //DBG("ptr: %s", ans); ngot += parse_answer(ans, N); } @@ -205,8 +218,8 @@ int check_sensors(){ green(_("Check if there's a sensors...\n")); int i, v, N, found = 0; char *ans; - for(N=0;N<8;++N)for(i=0;i<8;++i)for(v=0;v<2;++v) t_last[v][i][N] = -300.; // clear data - for(i = 1; i < 8; ++i){ + for(N=0;N<=NCTRLR_MAX;++N)for(i=0;i<=NCHANNEL_MAX;++i)for(v=0;v<2;++v) t_last[v][i][N] = -300.; // clear data + for(i = 1; i <= NCTRLR_MAX; ++i){ //red("i = %d\n", i); double t0 = dtime(); while(dtime() - t0 < POLLING_TMOUT){ diff --git a/src/netdaemon/term.h b/src/netdaemon/term.h index cbe400f..e8e7a0f 100644 --- a/src/netdaemon/term.h +++ b/src/netdaemon/term.h @@ -22,6 +22,8 @@ #ifndef __TERM_H__ #define __TERM_H__ +#include "sens_place.h" // NCTRLR + #define FRAME_MAX_LENGTH (300) #define MAX_MEMORY_DUMP_SIZE (0x800 * 4) // Terminal timeout (seconds) @@ -43,8 +45,8 @@ #define CMD_MEASURE_LOCAL 't' #define ANS_PONG "PONG" -extern time_t tmeasured[2][8][8]; -extern double t_last[2][8][8]; +extern time_t tmeasured[2][NCHANNEL_MAX+1][NCTRLR_MAX+1]; +extern double t_last[2][NCHANNEL_MAX+1][NCTRLR_MAX+1]; // communication errors typedef enum{