Changed according to new sensors places

This commit is contained in:
eddyem 2019-09-30 16:47:09 +03:00
parent 8491f4bf90
commit b4a8ed73c8
11 changed files with 292 additions and 5414 deletions

View File

@ -3,7 +3,7 @@ PROGRAM := netdaemon
LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all -pthread
SRCS := $(wildcard *.c)
DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111
DEFINES += -DEBUG
#DEFINES += -DEBUG
# baudrate for USB<->UART converter
DEFINES += -DBAUD_RATE=B115200
OBJDIR := mk

View File

@ -6,8 +6,9 @@ hostname:4444/Tx
where x is 0 for upper sensors, 1 for lower and 2 for T measured by main controller.
hostname:4444/Tmean returns mean temperature
Answer format: "X Y T t", where
Answer format: "ID X Y T t", where
- ID is numerical sensor identificator (1st digit is controller number, 2nd digit - sensors' pair number and 3rd digit - number of sensor in pair)
- X and Y are cartesian coordinates relative to mirror center (decimeters),
- T is measured temperature (degrees Celsium),
- t is UNIX-time of last measurement.

View File

@ -25,8 +25,8 @@
#include <linux/limits.h> // PATH_MAX
#include "usefull_macros.h" // putlog
#include "cmdlnopts.h" // glob_pars
#include "sens_place.h"
extern const int SensCoords[8][8][2];
extern glob_pars *G;
static char fullpath[PATH_MAX];
@ -43,18 +43,20 @@ char *mkname(char *path, char *fname){
* form files for gnuplot
* @param fname (i) - filename with full path
* @param data (i) - thermal data array
* @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[8][8]){
static int formfile(char *fname, double data[2][8][8], int Z){
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];
for(int i = 1; i <= NCTRLR_MAX; ++i){
for(int N = 0; N <= NCHANNEL_MAX; ++ N) for(int p = 0; p < 2; ++p){
double T = data[p][N][i];
if(T > -100. && T < 100.){
fprintf(F, "%d\t%d\t%.2f\n", SensCoords[N][i][0],
SensCoords[N][i][1], T);
const sensor_data *sdata = get_sensor_location(i, N, p);
if(!sdata) continue;
if(Z != sdata->Z) continue;
fprintf(F, "%d\t%d\t%.2f\n", sdata->X, sdata->Y, T - sdata->dt);
}
}
}
@ -89,11 +91,11 @@ static void gnuplot(char *path, char *fname){
}
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){
for(int i = 1; i < 8; ++i){
for(int 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;
@ -101,11 +103,11 @@ void plot(double data[2][8][8], char *savepath){
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");
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");
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");
}

View File

@ -69,8 +69,11 @@ int main(int argc, char **argv){
DBG("dev: %s", G->device);
try_connect(G->device);
if(check_sensors()){
putlog("no sensors detected");
if(!G->terminal) signals(15); // there's not main controller connected to given terminal
putlog("No CAN-controllers detected");
if(!poll_sensors(0)){ // there's not main controller connected to given terminal
putlog("Opened device is not main controller");
if(!G->terminal) signals(15);
}
}
if(G->terminal) run_terminal();
else daemonize(G->port);

File diff suppressed because it is too large Load Diff

View File

@ -1,43 +0,0 @@
[editor]
line_wrapping=false
line_break_column=100
auto_continue_multiline=true
[file_prefs]
final_new_line=true
ensure_convert_new_lines=true
strip_trailing_spaces=true
replace_tabs=true
[indentation]
indent_width=4
indent_type=0
indent_hard_tab_width=4
detect_indent=false
detect_indent_width=false
indent_mode=3
[project]
name=netdaemon
base_path=/home/eddy/Docs/SAO/BTA/MIRROR_CONTROL_termo/Project/netdaemon
description=
[long line marker]
long_line_behaviour=1
long_line_column=100
[files]
current_page=3
FILE_NAME_0=0;C;0;EKOI8-R;0;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FBTA%2FMIRROR_CONTROL_termo%2FProject%2Fnetdaemon%2Fcmdlnopts.c;0;4
FILE_NAME_1=0;C;0;EKOI8-R;0;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FBTA%2FMIRROR_CONTROL_termo%2FProject%2Fnetdaemon%2Fcmdlnopts.h;0;4
FILE_NAME_2=0;C;0;EKOI8-R;0;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FBTA%2FMIRROR_CONTROL_termo%2FProject%2Fnetdaemon%2Fmain.c;0;4
FILE_NAME_3=9982;C;0;EKOI8-R;0;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FBTA%2FMIRROR_CONTROL_termo%2FProject%2Fnetdaemon%2Fsocket.c;0;4
FILE_NAME_4=0;C;0;EKOI8-R;0;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FBTA%2FMIRROR_CONTROL_termo%2FProject%2Fnetdaemon%2Fsocket.h;0;4
FILE_NAME_5=4650;C;0;EKOI8-R;0;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FBTA%2FMIRROR_CONTROL_termo%2FProject%2Fnetdaemon%2Fterm.c;0;4
FILE_NAME_6=0;C;0;EKOI8-R;0;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FBTA%2FMIRROR_CONTROL_termo%2FProject%2Fnetdaemon%2Fterm.h;0;4
FILE_NAME_7=3250;C;0;EKOI8-R;0;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FBTA%2FMIRROR_CONTROL_termo%2FProject%2Fnetdaemon%2Fdatapoints.xy;0;4
FILE_NAME_8=7594;C;0;EUTF-8;0;1;0;%2Fhome%2Feddy%2FDropbox%2FProjects%2Ffits_filter%2Fmedian.c;0;4
FILE_NAME_9=0;C;0;EUTF-8;0;1;0;%2Fhome%2Feddy%2FDropbox%2FProjects%2Ffits_filter%2Fmedian.h;0;4
[VTE]
last_dir=/home/eddy

209
src/netdaemon/sens_place.c Normal file
View File

@ -0,0 +1,209 @@
/*
* This file is part of the TSYS01_netdaemon project.
* Copyright 2019 Edward V. Emelianov <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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "sens_place.h"
#include "stdbool.h"
#include "usefull_macros.h"
/**
Sensor place Dt X Y Z
100 36 -0.07 19 7 0
101 19 0.03 20 0 0
110 20 0.03 19 -7 0
111 20-21 -0.05 17 -10 1
120 40 0.02 17 -22 0
121 21 -0.03 15 -13 0
130 39 0.02 22 -17 0
131 38-39 -0.09 24 -14 1
140 38 0.03 25 -10 0
141 37 0.02 27 -4 0
150 60 -0.01 27 4 0
151 59 -0.09 25 10 0
160 58 0.07 22 17 0
161 58-59 0 24 14 1
170 56 0.02 10 25 0
171 57 0.08 17 22 0
200 55 -0.01 4 27 0
201 54-55 -0.03 0 27 1
210 54 0.04 -4 27 0
211 53 -0.01 -10 25 0
220 52 -0.02 -17 22 0
221 51 -0.04 -22 17 0
230 50 0.03 -25 10 0
231 50-51 -0.03 -24 14 1
240 48 -0.03 -27 -4 0
241 49 0.03 -27 4 0
250 47 -0.05 -25 -10 0
251 46-47 0 -24 -14 1
260 46 0.03 -22 -17 0
261 45 -0.05 -17 -22 0
270 44 -0.02 -10 -25 0
271 43 0.04 -4 -27 0
300 24 0.12 -3 -20 0
301 25 0 -10 -17 0
310 26 -0.08 -15 -13 0
311 26-27 -0.08 -17 -10 1
320 27 -0.1 -19 -7 0
321 28 -0.04 -20 0 0
330 29 -0.08 -19 7 0
331 29-30 0.03 -17 10 1
340 30 0.11 -15 13 0
341 31 0.07 -10 17 0
350 32 0.09 -3 20 0
351 32-33 -0.09 0 20 1
360 33 -0.1 3 20 0
361 34 0.04 10 17 0
370 35 0.05 15 13 0
371 35-36 -0.04 17 10 1
400 17 0.01 9 9 0
401 17-18 -0.04 11 7 1
410 16 0.01 3 13 0
411 15-16 -0.04 0 13 1
420 14 0.14 -9 9 0
421 15 0 -3 13 0
430 13 0.07 -13 3 0
431 13-14 -0.02 -11 7 1
440 12 0.04 -13 -3 0
441 11-12 -0.06 -11 -7 1
450 11 0.01 -9 -9 0
451 10 0.08 -3 -13 0
460 9 -0.09 3 -13 0
461 9-10 -0.04 0 -13 1
470 23 0.06 3 -20 0
471 23-24 -0.05 0 -20 1
500 42 0.05 4 -27 0
501 42-43 -0.08 0 -27 1
510 22 0.1 10 -17 0
511 41 -0.05 10 -25 0
520 8 0 9 -9 0
521 7-8 0.01 11 -7 1
530 2 0 3 -5 0
531 2-3 -0.02 0 -6 1
540 3 0.05 -3 -5 0
541 4 -0.03 -6 0 0
550 5 0.03 -3 5 0
551 5-6 0.06 0 6 1
560 6 0 3 5 0
561 1 -0.06 6 0 0
570 7 -0.07 13 -3 0
571 18 0.02 13 3 0
*/
static const sensor_data sensors[] = {
// {Dt,X,Y,Z},
{-0.07, 19, 7, 0}, // 0
{0.03, 20, 0, 0}, // 1
{0.03, 19, -7, 0}, // 2
{-0.05, 17, -10, 1}, // 3
{0.02, 17, -22, 0}, // 4
{-0.03, 15, -13, 0}, // 5
{0.02, 22, -17, 0}, // 6
{-0.09, 24, -14, 1}, // 7
{0.03, 25, -10, 0}, // 8
{0.02, 27, -4, 0}, // 9
{-0.01, 27, 4, 0}, // 10
{-0.09, 25, 10, 0}, // 11
{0.07, 22, 17, 0}, // 12
{0, 24, 14, 1}, // 13
{0.02, 10, 25, 0}, // 14
{0.08, 17, 22, 0}, // 15
{-0.01, 4, 27, 0}, // 16
{-0.03, 0, 27, 1}, // 17
{0.04, -4, 27, 0}, // 18
{-0.01, -10, 25, 0}, // 19
{-0.02, -17, 22, 0}, // 20
{-0.04, -22, 17, 0}, // 21
{0.03, -25, 10, 0}, // 22
{-0.03, -24, 14, 1}, // 23
{-0.03, -27, -4, 0}, // 24
{0.03, -27, 4, 0}, // 25
{-0.05, -25, -10, 0}, // 26
{0, -24, -14, 1}, // 27
{0.03, -22, -17, 0}, // 28
{-0.05, -17, -22, 0}, // 29
{-0.02, -10, -25, 0}, // 30
{0.04, -4, -27, 0}, // 31
{0.12, -3, -20, 0}, // 32
{0, -10, -17, 0}, // 33
{-0.08, -15, -13, 0}, // 34
{-0.08, -17, -10, 1}, // 35
{-0.1, -19, -7, 0}, // 36
{-0.04, -20, 0, 0}, // 37
{-0.08, -19, 7, 0}, // 38
{0.03, -17, 10, 1}, // 39
{0.11, -15, 13, 0}, // 40
{0.07, -10, 17, 0}, // 41
{0.09, -3, 20, 0}, // 42
{-0.09, 0, 20, 1}, // 43
{-0.1, 3, 20, 0}, // 44
{0.04, 10, 17, 0}, // 45
{0.05, 15, 13, 0}, // 46
{-0.04, 17, 10, 1}, // 47
{0.01, 9, 9, 0}, // 48
{-0.04, 11, 7, 1}, // 49
{0.01, 3, 13, 0}, // 50
{-0.04, 0, 13, 1}, // 51
{0.14, -9, 9, 0}, // 52
{0, -3, 13, 0}, // 53
{0.07, -13, 3, 0}, // 54
{-0.02, -11, 7, 1}, // 55
{0.04, -13, -3, 0}, // 56
{-0.06, -11, -7, 1}, // 57
{0.01, -9, -9, 0}, // 58
{0.08, -3, -13, 0}, // 59
{-0.09, 3, -13, 0}, // 60
{-0.04, 0, -13, 1}, // 61
{0.06, 3, -20, 0}, // 62
{-0.05, 0, -20, 1}, // 63
{0.05, 4, -27, 0}, // 64
{-0.08, 0, -27, 1}, // 65
{0.1, 10, -17, 0}, // 66
{-0.05, 10, -25, 0}, // 67
{0, 9, -9, 0}, // 68
{0.01, 11, -7, 1}, // 69
{0, 3, -5, 0}, // 70
{-0.02, 0, -6, 1}, // 71
{0.05, -3, -5, 0}, // 72
{-0.03, -6, 0, 0}, // 73
{0.03, -3, 5, 0}, // 74
{0.06, 0, 6, 1}, // 75
{0, 3, 5, 0}, // 76
{-0.06, 6, 0, 0}, // 77
{-0.07, 13, -3, 0}, // 78
{0.02, 13, 3, 0}, // 79
};
/**
* @brief get_sensor_location - return pointer to sensor_data for given sensor
* @param Nct - controller number
* @param Nch - channel number
* @param Ns - sensor number
* @return
*/
const sensor_data *get_sensor_location(int Nct, int Nch, int Ns){
if(Nct < 1 || Nct > NCTRLR_MAX || Nch > NCHANNEL_MAX || Ns > 1){
WARNX("Wrong sencor code: %s (%d%d%d)\n", Nct, Nct, Nch, Ns);
return NULL;
}
int idx = 2*(NCHANNEL_MAX+1)*(Nct - 1) + 2*Nch + Ns;
DBG("Sensor code %d%d%d (idx=%d):\n", Nct, Nch, Ns, idx);
const sensor_data *s = sensors + idx;
DBG("\tdT=%g; coords=(%d, %d, %d)\n", s->dt, s->X, s->Y, s->Z);
return s;
}

View File

@ -0,0 +1,36 @@
/*
* This file is part of the TSYS01_netdaemon project.
* Copyright 2019 Edward V. Emelianov <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 3 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, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#ifndef SENS_PLACE_H__
#define SENS_PLACE_H__
// max number of controller
#define NCTRLR_MAX (5)
// max number of channel
#define NCHANNEL_MAX (7)
typedef struct{
float dt;
int X;
int Y;
int Z;
} sensor_data;
const sensor_data *get_sensor_location(int Nct, int Nch, int Ns);
#endif // SENS_PLACE_H__

View File

@ -31,7 +31,7 @@
#include <unistd.h> // daemon
#include <sys/syscall.h> // syscall
#include "datapoints.xy" // sensors coordinates
#include "sens_place.h" // sensors coordinates
#include "gnuplot.h" // plot graphs
#include "cmdlnopts.h" // glob_pars
@ -39,7 +39,7 @@
// Max amount of connections
#define BACKLOG (30)
// temperatures: T0, T1, N2
// temperatures: T0 (mirror surface), T1 (mirror bottom), T2 (inside NES)
static char strT[3][BUFLEN];
// mean temperature
static double meanT;
@ -359,14 +359,14 @@ static void daemon_(int sock){
if(dtime() - tgot < T_INTERVAL) continue;
// get data
int i;
char bufs[3][BUFLEN]; // temporary buffers: T0, T1, TN2
char bufs[3][BUFLEN]; // temporary buffers: T0, T1, T2
char *ptrs[3] = {bufs[0], bufs[1], bufs[2]};
size_t lens[3] = {BUFLEN, BUFLEN, BUFLEN}; // free space
tgot = dtime();
process_T(); // get new temperatures & throw out bad results
for(i = 0; i < 8; ++i){ // scan over controllers
for(i = 0; i <= NCTRLR_MAX; ++i){ // scan over controllers
int N, p;
for(p = 0; p < 2; ++p) for(N = 0; N < 8; ++ N){
for(N = 0; N <= NCHANNEL_MAX; ++N) for(p = 0; p < 2; ++p){
double T = t_last[p][N][i];
char **buf;
size_t *len;
@ -379,10 +379,12 @@ static void daemon_(int sock){
l = snprintf(*buf, *len, "%d\t%d\t%.2f\t%ld\n", N, p, T,
tmeasured[p][N][i]);
}else{
buf = &ptrs[p]; len = &lens[p];
// x y T time
l = snprintf(*buf, *len, "%d\t%d\t%.2f\t%ld\n", SensCoords[N][i][0],
SensCoords[N][i][1], T, tmeasured[p][N][i]);
const sensor_data *sdata = get_sensor_location(i, N, p);
if(!sdata) continue; // wrong sensor number???
buf = &ptrs[sdata->Z]; len = &lens[sdata->Z];
// iNp x y T(corrected) time
l = snprintf(*buf, *len, "%d%d%d\t%d\t%d\t%.2f\t%ld\n", i, N, p,
sdata->X, sdata->Y, T - sdata->dt, tmeasured[p][N][i]);
}
*len -= l;
*buf += l;

View File

@ -26,8 +26,6 @@
#define BUFLEN 1024
// == 1 if given controller (except 0) presents on CAN bus
int8_t ctrlr_present[8] = {1,0,0};
// UNIX time of temperatures measurement: [Ngroup][Nsensor][Ncontroller]
time_t tmeasured[2][8][8];
// last temperatures read: [Ngroup][Nsensor][Ncontroller]
@ -172,12 +170,14 @@ static int send_cmd(int N, char cmd){
/**
* Poll sensor for new dataportion
* @param N - number of controller (1..7)
* @return: 0 if no data received or controller is absent, 1 if valid data received
* @return: 0 if no data received or controller is absent, number of data points if valid data received
*/
int poll_sensors(int N){
if(!ctrlr_present[N]) return 0;
char *ans;
if(send_cmd(N, CMD_MEASURE_T)){ // start polling
DBG("Poll controller #%d", N);
char cmd = CMD_MEASURE_LOCAL;
if(N) cmd = CMD_MEASURE_T;
if(send_cmd(N, cmd)){ // start polling
WARNX(_("can't request temperature"));
return 0;
}
@ -195,6 +195,8 @@ int poll_sensors(int N){
return 1;
}
/**
* check whether connected device is main Thermal controller
* @return 1 if NO
@ -215,7 +217,6 @@ int check_sensors(){
//DBG("PONG from %d", ans[sizeof(ANS_PONG)-1] - '0');
if(i == ans[sizeof(ANS_PONG)-1] - '0'){
++found;
ctrlr_present[i] = 1;
green(_("Found controller #%d\n"), i);
putlog("Found controller #%d", i);
break;

View File

@ -37,11 +37,12 @@
// Protocol
#define CMD_SENSORS_OFF 'F'
#define CMD_MEASURE_T 'T'
#define CMD_VOLTAGE 'K'
#define CMD_PING 'P'
#define CMD_MEASURE_T 'T'
#define CMD_MEASURE_LOCAL 't'
#define ANS_PONG "PONG"
extern int8_t ctrlr_present[8];
extern time_t tmeasured[2][8][8];
extern double t_last[2][8][8];