Sync from remote server: 2025-10-12 18:56:41

This commit is contained in:
2025-10-12 18:56:59 +02:00
commit 7e8ee264aa
553 changed files with 161447 additions and 0 deletions

25
RSN/DB_date_time.m Executable file
View File

@@ -0,0 +1,25 @@
function [idElabData] = DB_date_time(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdate,conn)
nNodo = num2str(NodeNum);
l = ListaDate;
idElabData = zeros(l,1); % Contiene gli id delle date delle quali ho già dati
cc = 1; % contatore
for ii=1:l
dString = datestr(ARRAYdate(ii),'yyyy-mm-dd');
tString = datestr(ARRAYdate(ii),'HH:MM:SS');
comando = ['select idElabData from ELABDATADISP where UnitName = ''' ...
IDcentralina ''' and ToolNameID = ''' DTcatena ''' and NodeNum = ''' ...
nNodo ''' and EventDate = ''' dString ''' and EventTime = ''' tString ''' order by EventDate'];
curs = exec(conn,comando);
curs = fetch(curs);
idDate = curs.Data;
if strcmp(idDate,'No Data')
idElabData(cc,1) = 0; % 0 indica che il dato non è presente su DB
else
idElabData(cc,1) = cell2mat(idDate);
end
cc = cc+1;
end
end

25
RSN/DBwriteLL.m Executable file
View File

@@ -0,0 +1,25 @@
function DBwriteLL(DATAinsert,idElabData,ListaDate,NodeNum,IDcentralina,DTcatena,conn)
nNodo = num2str(NodeNum);
l = ListaDate;
for ii=1:l
idData = idElabData(ii,1);
if idData == 0 % Se la data non č su DB (=0), scrivo i dati
tablename = 'ELABDATADISP';
colnames = {'UnitName','ToolNameID','NodeNum','EventDate','EventTime','load_value','calcerr'};
data = [DATAinsert(ii,1),DATAinsert(ii,2),DATAinsert(ii,3),DATAinsert(ii,4),...
DATAinsert(ii,5),DATAinsert(ii,6),DATAinsert(ii,7)];
fastinsert(conn,tablename,colnames,data);
else % altrimenti li aggiorno
tablename = 'ELABDATADISP';
colnames = {'load_value','calcerr'};
data = [DATAinsert(ii,6),DATAinsert(ii,7)];
whereclause = ['WHERE UnitName = ''' IDcentralina ''' and ToolNameID = ''' DTcatena...
''' and NodeNum = ''' nNodo ''' and EventDate = ''' cell2mat(DATAinsert(ii,4))...
''' and EventTime = ''' cell2mat(DATAinsert(ii,5)) ''' '];
update(conn,tablename,colnames,data,whereclause)
end
end
end

27
RSN/DBwriteRSN.m Executable file
View File

@@ -0,0 +1,27 @@
function DBwriteRSN(DATAinsert,idElabData,ListaDate,NodeNum,IDcentralina,DTcatena,conn)
nNodo = num2str(NodeNum);
l = ListaDate;
for ii=1:l
idData = idElabData(ii,1);
if idData == 0 % Se la data non č su DB (=0), scrivo i dati
tablename = 'ELABDATADISP';
colnames = {'UnitName','ToolNameID','NodeNum','EventDate','EventTime',...
'AlfaX','AlfaY','T_node','calcerr'};
data = [DATAinsert(ii,1),DATAinsert(ii,2),DATAinsert(ii,3),...
DATAinsert(ii,4),DATAinsert(ii,5),DATAinsert(ii,6),...
DATAinsert(ii,7),DATAinsert(ii,8),DATAinsert(ii,9)];
fastinsert(conn,tablename,colnames,data);
else % altrimenti li aggiorno
tablename = 'ELABDATADISP';
colnames = {'AlfaX','AlfaY','T_node','calcerr'};
data = [DATAinsert(ii,6),DATAinsert(ii,7),DATAinsert(ii,8),DATAinsert(ii,9)];
whereclause = ['WHERE UnitName = ''' IDcentralina ''' and ToolNameID = ''' DTcatena ''' and NodeNum = ''' ...
nNodo ''' and EventDate = ''' cell2mat(DATAinsert(ii,4)) ''' and EventTime = ''' cell2mat(DATAinsert(ii,5)) ''' '];
update(conn,tablename,colnames,data,whereclause);
end
end
end

26
RSN/DBwriteRSNHR.m Executable file
View File

@@ -0,0 +1,26 @@
function DBwriteRSNHR(DATAinsert,idElabData,ListaDate,NodeNum,DTcatena,IDcentralina,conn)
nNodo = num2str(NodeNum);
l = ListaDate;
for ii=1:l
idData = idElabData(ii,1);
if idData == 0 % Se la data non č su DB (=0), scrivo i dati
tablename = 'ELABDATADISP';
colnames = {'UnitName','ToolNameID','NodeNum','EventDate','EventTime',...
'AlfaX','AlfaY','T_node','calcerr'};
data = [DATAinsert(ii,1),DATAinsert(ii,2),DATAinsert(ii,3),...
DATAinsert(ii,4),DATAinsert(ii,5),DATAinsert(ii,6),...
DATAinsert(ii,7),DATAinsert(ii,8),DATAinsert(ii,9)];
fastinsert(conn,tablename,colnames,data);
else % altrimenti li aggiorno
tablename = 'ELABDATADISP';
colnames = {'AlfaX','AlfaY','T_node','calcerr'};
data = [DATAinsert(ii,6),DATAinsert(ii,7),DATAinsert(ii,8),DATAinsert(ii,9)];
whereclause = ['WHERE UnitName = ''' IDcentralina ''' and ToolNameID = ''' DTcatena ''' and NodeNum = ''' ...
nNodo ''' and EventDate = ''' cell2mat(DATAinsert(ii,4)) ''' and EventTime = ''' cell2mat(DATAinsert(ii,5)) ''' '];
update(conn,tablename,colnames,data,whereclause);
end
end
end

25
RSN/DBwriteSS.m Executable file
View File

@@ -0,0 +1,25 @@
function DBwriteSS(DATAinsert,idElabData,ListaDate,NodeNum,IDcentralina,DTcatena,conn)
nNodo = num2str(NodeNum);
l = ListaDate;
for ii=1:l
idData = idElabData(ii,1);
if idData == 0 % Se la data non č su DB (=0), scrivo i dati
tablename = 'ELABDATADISP';
colnames = {'UnitName','ToolNameID','NodeNum','EventDate','EventTime','XShift','X','calcerr'};
data = [DATAinsert(ii,1),DATAinsert(ii,2),DATAinsert(ii,3),DATAinsert(ii,4),...
DATAinsert(ii,5),DATAinsert(ii,6),DATAinsert(ii,7),DATAinsert(ii,8)];
fastinsert(conn,tablename,colnames,data);
else % altrimenti li aggiorno
tablename = 'ELABDATADISP';
colnames = {'XShift','X','calcerr'};
data = [DATAinsert(ii,6),DATAinsert(ii,7),DATAinsert(ii,8)];
whereclause = ['WHERE UnitName = ''' IDcentralina ''' and ToolNameID = '''...
DTcatena ''' and NodeNum = ''' nNodo ''' and EventDate = ''' cell2mat(DATAinsert(ii,4))...
''' and EventTime = ''' cell2mat(DATAinsert(ii,5)) ''' '];
update(conn,tablename,colnames,data,whereclause)
end
end
end

25
RSN/DBwriteTrL.m Executable file
View File

@@ -0,0 +1,25 @@
function DBwriteTrL(DATAinsert,idElabData,ListaDate,NodeNum,IDcentralina,DTcatena,conn)
nNodo = num2str(NodeNum);
l = ListaDate;
for ii=1:l
idData = idElabData(ii,1);
if idData == 0 % Se la data non č su DB (=0), scrivo i dati
tablename = 'ELABDATADISP';
colnames = {'UnitName','ToolNameID','NodeNum','EventDate','EventTime','XShift','X','calcerr'};
data = [DATAinsert(ii,1),DATAinsert(ii,2),DATAinsert(ii,3),DATAinsert(ii,4),...
DATAinsert(ii,5),DATAinsert(ii,6),DATAinsert(ii,7),DATAinsert(ii,8)];
fastinsert(conn,tablename,colnames,data);
else % altrimenti li aggiorno
tablename = 'ELABDATADISP';
colnames = {'XShift','X','calcerr'};
data = [DATAinsert(ii,6),DATAinsert(ii,7),DATAinsert(ii,8)];
whereclause = ['WHERE UnitName = ''' IDcentralina ''' and ToolNameID = '''...
DTcatena ''' and NodeNum = ''' nNodo ''' and EventDate = ''' cell2mat(DATAinsert(ii,4))...
''' and EventTime = ''' cell2mat(DATAinsert(ii,5)) ''' '];
update(conn,tablename,colnames,data,whereclause)
end
end
end

15
RSN/IDunit.m Executable file
View File

@@ -0,0 +1,15 @@
function unitID = IDunit(IDcentralina,conn,FileName)
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'IDunit function started';
fprintf(fileID,fmt,text);
comando = ['select id from units where name like ''' IDcentralina ''' '];
unitID = fetch(conn,comando);
text = 'Unit ID downloaded correctly and IDunit function closed';
fprintf(fileID,fmt,text);
fclose(fileID);
end

946
RSN/LastElab.m Executable file
View File

@@ -0,0 +1,946 @@
function [NuovoZeroRSN,datainiRSN,tempoiniRSN,NuovoZeroRSNHR,datainiRSNHR,tempoiniRSNHR,...
DatiElabTriggerLink,NuovoZeroTrL,datainiTrL,tempoiniTrL,DatiElabShockSensor,NuovoZeroSS,...
datainiSS,tempoiniSS,NuovoZeroLL,datainiLL,tempoiniLL,datainiGF,tempoiniGF,datainiGS,tempoiniGS,...
DatiElabDebrisLink,NuovoZeroDL,datainiDL,tempoiniDL]...
= LastElab(conn,date,time,IDcentralina,DTcatena,NdatiMedia,NodoRSNLink,yesRSN,NodoRSNLinkHR,yesRSNHR,...
NodoTriggerLink,yesTrL,rTrL,NodoSS,yesSS,rSS,NodoLoadLink,yesLL,yesGF,yesGS,NodoDebrisLink,yesDL,...
rDL,Ndatidespike,FileName)
% Apro scrittura file
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'LastElab function started';
fprintf(fileID,fmt,text);
Data(1,1) = cellstr(date);
Data(1,2) = cellstr(time);
%% RSN Link
if yesRSN == 1 % Importo ultimo dato elaborato dei RSN Link
NodeNumRSN = num2str(cell2mat(NodoRSNLink(1,2))); % scarico i dati del primo nodo RSN Link
NodeType = 'RSN Link';
% Dati Grezzi
comando = ['select Date, Time from RawDataView where Date = ''' ...
date ''' and Time >= ''' time ''' and UnitName = ''' IDcentralina ''' and ToolNameID = '''...
DTcatena ''' and NodeType = ''' NodeType ''' and NodeNum =' NodeNumRSN ' '];
curs = exec(conn,comando);
curs = fetch(curs);
D_num_ini = curs.Data;
[rI,cI] = size(D_num_ini);
if rI == 1 && cI == 1 % Non ci sono dati per la data "date"
comando = ['select Date, Time from RawDataView where Date > ''' ...
date ''' and UnitName = ''' IDcentralina...
''' and ToolNameID = ''' DTcatena ''' and NodeType = ''' ...
NodeType ''' and NodeNum =' NodeNumRSN ' '];
curs = exec(conn,comando);
curs = fetch(curs);
D_num_ini = curs.Data;
[rI,cI] = size(D_num_ini);
end
if rI && cI == 1
Data_num_ini = 0;
else
Data_num_ini = [cell2mat(D_num_ini(:,1)) repmat(' ', [rI,1]) cell2mat(D_num_ini(:,2))];
end
Data_num_ini = datenum(Data_num_ini); % tutte le date presenti nel DB grezzo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
date ''' and UnitName = ''' IDcentralina ''' and ToolNameID = ''' DTcatena ...
''' and NodeType = ''' NodeType ''' and NodeNum =' NodeNumRSN ' '];
curs = exec(conn,comando);
curs = fetch(curs);
Data_LastElab = curs.Data;
[rLE,cLE] = size(Data_LastElab);
Date = [cell2mat(Data(1,1)) repmat(' ', [1,1]) cell2mat(Data(1,2))];
data1a = datenum(Date);
data1b = Data_num_ini(1);
if data1b>data1a
data1 = data1b;
else
data1 = data1a;
end
if rLE==1 && cLE==1
datainiRSN = datestr(data1,'yyyy-mm-dd');
tempoiniRSN = datestr(data1,'HH:MM:SS');
NuovoZeroRSN = 0;
else
% Modifico il formato di data e ora in DATini.
[rD,~] = size(Data_LastElab);
Data_numero = [cell2mat(Data_LastElab(:,1)) repmat(' ', [rD,1]) cell2mat(Data_LastElab(:,2))];
Data_numero = datenum(Data_numero); % tutte le date presenti nel DB grezzo
margine = 1;
if Ndatidespike > NdatiMedia
Ndati = Ndatidespike;
else
Ndati = NdatiMedia;
end
if margine < Ndati/2
margine = round(Ndati/2+1);
end
cont = Ndati + margine;
if cont < 3
cont = 3;
end
[rDS,~] = size(Data_numero);
if rDS <= cont
cont = rDS-1;
end
Data_scarico = Data_numero(end-cont);
Data_scarico = datestr(Data_scarico,'yyyy-mm-dd');
data2 = datenum(Data_scarico);
if data2 > data1
datainiRSN = datestr(data2,'yyyy-mm-dd');
tempoiniRSN = datestr(data2,'HH:MM:SS');
NuovoZeroRSN = 1;
else
datainiRSN = datestr(data1,'yyyy-mm-dd');
tempoiniRSN = datestr(data1,'HH:MM:SS');
NuovoZeroRSN = 0;
end
end
text = 'RSN Link executed during LastElab function';
fprintf(fileID,fmt,text);
else
datainiRSN = [];
tempoiniRSN = [];
NuovoZeroRSN = 0;
end
%% RSN Link HR
if yesRSNHR == 1 % Importo ultimo dato elaborato dei RSN Link HR
NodeNumRSNHR = num2str(cell2mat(NodoRSNLinkHR(1,2))); % scarico i dati del primo nodo RSN Link HR
NodeType = 'RSN Link HR';
% Dati Grezzi
comando = ['select Date, Time from RawDataView where Date = ''' ...
date ''' and Time >= ''' time ''' and UnitName = ''' IDcentralina ''' and ToolNameID = '''...
DTcatena ''' and NodeType = ''' NodeType ''' and NodeNum =' NodeNumRSNHR ' '];
curs = exec(conn,comando);
curs = fetch(curs);
D_num_ini = curs.Data;
[rI,cI] = size(D_num_ini);
if rI == 1 && cI == 1 % Non ci sono dati per la data "date"
comando = ['select Date, Time from RawDataView where Date > ''' ...
date ''' and UnitName = ''' IDcentralina...
''' and ToolNameID = ''' DTcatena ''' and NodeType = ''' ...
NodeType ''' and NodeNum =' NodeNumRSNHR ' '];
curs = exec(conn,comando);
curs = fetch(curs);
D_num_ini = curs.Data;
[rI,cI] = size(D_num_ini);
end
if rI && cI == 1
Data_num_ini = 0;
else
Data_num_ini = [cell2mat(D_num_ini(:,1)) repmat(' ', [rI,1]) cell2mat(D_num_ini(:,2))];
end
Data_num_ini = datenum(Data_num_ini); % tutte le date presenti nel DB grezzo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
date ''' and UnitName = ''' IDcentralina ''' and ToolNameID = ''' DTcatena...
''' and NodeType = ''' NodeType ''' and NodeNum =' NodeNumRSNHR ' '];
curs = exec(conn,comando);
curs = fetch(curs);
Data_LastElab = curs.Data;
[rLE,cLE] = size(Data_LastElab);
Date = [cell2mat(Data(1,1)) repmat(' ', [1,1]) cell2mat(Data(1,2))];
data1a = datenum(Date);
data1b = Data_num_ini(1);
if data1b>data1a
data1 = data1b;
else
data1 = data1a;
end
if rLE==1 && cLE==1
datainiRSNHR = datestr(data1,'yyyy-mm-dd');
tempoiniRSNHR = datestr(data1,'HH:MM:SS');
NuovoZeroRSNHR = 0;
else
% Modifico il formato di data e ora in DATini.
[rD,~] = size(Data_LastElab);
Data_numero = [cell2mat(Data_LastElab(:,1)) repmat(' ', [rD,1]) cell2mat(Data_LastElab(:,2))];
Data_numero = datenum(Data_numero); % tutte le date presenti nel DB grezzo
margine = 1;
if Ndatidespike > NdatiMedia
Ndati = Ndatidespike;
else
Ndati = NdatiMedia;
end
if margine < Ndati/2
margine = round(Ndati/2+1);
end
cont = Ndati + margine;
if cont < 3
cont = 3;
end
[rDS,~] = size(Data_numero);
if rDS <= cont
cont = rDS-1;
end
Data_scarico = Data_numero(end-cont);
Data_scarico = datestr(Data_scarico,'yyyy-mm-dd');
data2 = datenum(Data_scarico);
if data2 > data1
datainiRSNHR = datestr(data2,'yyyy-mm-dd');
tempoiniRSNHR = datestr(data2,'HH:MM:SS');
NuovoZeroRSNHR = 1; %1
else
datainiRSNHR = datestr(data1,'yyyy-mm-dd');
tempoiniRSNHR = datestr(data1,'HH:MM:SS');
NuovoZeroRSNHR = 0;
end
end
text = 'RSN Link HR executed during LastElab function';
fprintf(fileID,fmt,text);
else
datainiRSNHR = [];
tempoiniRSNHR = [];
NuovoZeroRSNHR = 0;
end
%% Trigger Link
if yesTrL == 1 % Importo ultimo dato elaborato dei Trigger Link
NodeNumTrL = num2str(cell2mat(NodoTriggerLink(1,2))); % scarico i dati del primo nodo Trigger Link
NodeType = 'Trigger Link';
% Dati Grezzi
comando = ['select Date, Time from RawDataView where Date = ''' ...
date ''' and Time >= ''' time ''' and UnitName = ''' IDcentralina ''' and ToolNameID = '''...
DTcatena ''' and NodeType = ''' NodeType ''' and NodeNum =' NodeNumTrL ' '];
curs = exec(conn,comando);
curs = fetch(curs);
D_num_ini = curs.Data;
[rI,cI] = size(D_num_ini);
if rI == 1 && cI == 1 % Non ci sono dati per la data "date"
comando = ['select Date, Time from RawDataView where Date > ''' ...
date ''' and UnitName = ''' IDcentralina...
''' and ToolNameID = ''' DTcatena ''' and NodeType = ''' ...
NodeType ''' and NodeNum =' NodeNumTrL ' '];
curs = exec(conn,comando);
curs = fetch(curs);
D_num_ini = curs.Data;
[rI,cI] = size(D_num_ini);
end
if rI && cI == 1
Data_num_ini = 0;
else
Data_num_ini = [cell2mat(D_num_ini(:,1)) repmat(' ', [rI,1]) cell2mat(D_num_ini(:,2))];
end
Data_num_ini = datenum(Data_num_ini); % tutte le date presenti nel DB grezzo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
date ''' and UnitName = ''' IDcentralina ''' and ToolNameID = ''' DTcatena ...
''' and NodeType = ''' NodeType ''' and NodeNum =' NodeNumTrL ' '];
curs = exec(conn,comando);
curs = fetch(curs);
Data_LastElab = curs.Data;
[rLE,cLE] = size(Data_LastElab);
Date = [cell2mat(Data(1,1)) repmat(' ', [1,1]) cell2mat(Data(1,2))];
data1a = datenum(Date);
data1b = Data_num_ini(1);
if data1b>data1a
data1 = data1b;
else
data1 = data1a;
end
if rLE==1 && cLE==1
datainiTrL = datestr(data1,'yyyy-mm-dd');
tempoiniTrL = datestr(data1,'HH:MM:SS');
NuovoZeroTrL = 0;
DatiElabTriggerLink = [];
else
% Modifico il formato di data e ora in DATini.
[rD,~] = size(Data_LastElab);
Data_numero = [cell2mat(Data_LastElab(:,1)) repmat(' ', [rD,1]) cell2mat(Data_LastElab(:,2))];
Data_numero = datenum(Data_numero); % tutte le date presenti nel DB grezzo
margine = 1;
Data_scarico = Data_numero(end)-margine;
Data_scarico = datestr(Data_scarico,'yyyy-mm-dd');
data2 = datenum(Data_scarico);
if data2 > data1
datainiTrL = datestr(data2,'yyyy-mm-dd');
tempoiniTrL = datestr(data2,'HH:MM:SS');
NuovoZeroTrL = 1;
else
datainiTrL = datestr(data1,'yyyy-mm-dd');
tempoiniTrL = datestr(data1,'HH:MM:SS');
NuovoZeroTrL = 0;
end
end
if NuovoZeroTrL == 1 % scarico gli ultimi dati elaborati
NAN = 0;
while NAN == 0
if datenum(datainiTrL) < datenum(date)
datainiTrL = date;
end
NTriggerLink = cell2mat(NodoTriggerLink(:,2));
ii = 1; % contatore
col = 3; % contatore colonne
Condition = 0;
while ii <= rTrL
ini_col = col-2;
nN = num2str(NTriggerLink(ii,1));
% Scarico di dati giorno X
comando = ['select EventDate, EventTime, X from ElabDataView where EventDate = ''' ...
Data_scarico(1,1:10) ''' and EventTime >= ''' Data_scarico(1,12:end) ''' and '...
'UnitName = ''' IDcentralina ''' and ToolNameID = '''...
DTcatena ''' and NodeType = ''' NodeType ''' and NodeNum = ''' nN ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DATnodoTrLd = curs.Data;
% Scarico di dati giorni successivi
comando = ['select EventDate, EventTime, X from ElabDataView where EventDate > ''' ...
Data_scarico(1,1:10) ''' and UnitName = ''' IDcentralina ''' and ToolNameID = '''...
DTcatena ''' and NodeType = ''' NodeType ''' and NodeNum = ''' nN ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DATnodoTrL = curs.Data;
[~,c1] = size(DATnodoTrL);
[~,c2] = size(DATnodoTrLd);
if c1 == c2
DATnodoTrL = [DATnodoTrLd; DATnodoTrL];
elseif c1 < c2 % solo giorno di riferimento
DATnodoTrL = DATnodoTrLd;
end
[rDAT,cDAT] = size(DATnodoTrL);
if rDAT==1 && cDAT==1
clear DatiElabTriggerLink
fclose(fileID);
cancellaDB(IDcentralina,DTcatena,Data_scarico,conn,FileName);
fileID = fopen(FileName,'a');
fmt = '%s \r';
Condition = 1;
break
else
if ii > 1 % Nodo successivo al primo
[rDE,~] = size(DatiElabTriggerLink);
if rDE ~= rDAT
clear DatiElabTriggerLink
fclose(fileID);
cancellaDB(IDcentralina,DTcatena,Data_scarico,conn,FileName);
fileID = fopen(FileName,'a');
fmt = '%s \r';
Condition = 1;
break
end
end
DatiElabTriggerLink(:,ini_col:col) = DATnodoTrL(:,:);
end
ii = ii+1;
end
if Condition == 1
datainiTrL = datenum(datainiTrL) - 1;
Data_scarico = datestr(datainiTrL,'yyyy-mm-dd HH:MM:SS');
datainiTrL = Data_scarico;
fileID = fopen(FileName,'a');
else
Check = isnan(cell2mat(DatiElabTriggerLink(1,3:16:end)));
for jj = 1:rTrL
if Check == 1
datainiTrL = datenum(datainiTrL) - 1;
Data_scarico = datestr(datainiTrL,'yyyy-mm-dd HH:MM:SS');
datainiTrL = Data_scarico;
break
else
NAN = 1;
end
end
end
end
text = 'Trigger Link executed during LastElab function';
fprintf(fileID,fmt,text);
else
DatiElabTriggerLink = [];
end
else
datainiTrL = [];
tempoiniTrL = [];
DatiElabTriggerLink = [];
NuovoZeroTrL = 0;
end
%% Shock Sensor
if yesSS == 1 % Importo ultimo dato elaborato
NodeNumSS = num2str(cell2mat(NodoSS(1,2))); % scarico i dati del primo nodo
NodeType = 'Shock Sensor';
% Dati Grezzi
comando = ['select Date, Time from RawDataView where Date = ''' ...
date ''' and Time >= ''' time ''' and UnitName = ''' IDcentralina ''' and ToolNameID = '''...
DTcatena ''' and NodeType = ''' NodeType ''' and NodeNum =' NodeNumSS ' '];
curs = exec(conn,comando);
curs = fetch(curs);
D_num_ini = curs.Data;
[rI,cI] = size(D_num_ini);
if rI == 1 && cI == 1 % Non ci sono dati per la data "date"
comando = ['select Date, Time from RawDataView where Date > ''' ...
date ''' and UnitName = ''' IDcentralina...
''' and ToolNameID = ''' DTcatena ''' and NodeType = ''' ...
NodeType ''' and NodeNum =' NodeNumSS ' '];
curs = exec(conn,comando);
curs = fetch(curs);
D_num_ini = curs.Data;
[rI,cI] = size(D_num_ini);
end
if rI && cI == 1
Data_num_ini = 0;
else
Data_num_ini = [cell2mat(D_num_ini(:,1)) repmat(' ', [rI,1]) cell2mat(D_num_ini(:,2))];
end
Data_num_ini = datenum(Data_num_ini); % tutte le date presenti nel DB grezzo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
date ''' and UnitName = ''' IDcentralina ''' and ToolNameID = ''' DTcatena ...
''' and NodeType = ''' NodeType ''' and NodeNum =' NodeNumSS ' '];
curs = exec(conn,comando);
curs = fetch(curs);
Data_LastElab = curs.Data;
[rLE,cLE] = size(Data_LastElab);
Date = [cell2mat(Data(1,1)) repmat(' ', [1,1]) cell2mat(Data(1,2))];
data1a = datenum(Date);
data1b = Data_num_ini(1);
if data1b>data1a
data1 = data1b;
else
data1 = data1a;
end
if rLE==1 && cLE==1
datainiSS = datestr(data1,'yyyy-mm-dd');
tempoiniSS = datestr(data1,'HH:MM:SS');
NuovoZeroSS = 0;
DatiElabShockSensor = [];
else
% Modifico il formato di data e ora in DATini.
[rD,~] = size(Data_LastElab);
Data_numero = [cell2mat(Data_LastElab(:,1)) repmat(' ', [rD,1]) cell2mat(Data_LastElab(:,2))];
Data_numero = datenum(Data_numero); % tutte le date presenti nel DB grezzo
margine = 1;
Data_scarico = Data_numero(end)-margine;
Data_scarico = datestr(Data_scarico,'yyyy-mm-dd');
data2 = datenum(Data_scarico);
if data2 > data1
datainiSS = datestr(data2,'yyyy-mm-dd');
tempoiniSS = datestr(data2,'HH:MM:SS');
NuovoZeroSS = 1;
else
datainiSS = datestr(data1,'yyyy-mm-dd');
tempoiniSS = datestr(data1,'HH:MM:SS');
NuovoZeroSS = 0;
end
end
if NuovoZeroSS == 1 % scarico gli ultimi dati elaborati
NAN = 0;
while NAN == 0
if datenum(datainiSS) < datenum(date)
datainiSS = date;
end
NShockSensor = cell2mat(NodoSS(:,2));
ii = 1; % contatore
col = 3; % contatore colonne
Condition = 0;
while ii <= rSS
ini_col = col-2;
nN = num2str(NShockSensor(ii,1));
% Scarico di dati giorno X
comando = ['select EventDate, EventTime, X from ElabDataView where EventDate = ''' ...
Data_scarico(1,1:10) ''' and EventTime >= ''' Data_scarico(1,12:end) ''' and '...
'UnitName = ''' IDcentralina ''' and ToolNameID = '''...
DTcatena ''' and NodeType = ''' NodeType ''' and NodeNum = ''' nN ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DATnodoSSd = curs.Data;
% Scarico di dati giorni successivi
comando = ['select EventDate, EventTime, X from ElabDataView where EventDate > ''' ...
Data_scarico(1,1:10) ''' and UnitName = ''' IDcentralina ''' and ToolNameID = '''...
DTcatena ''' and NodeType = ''' NodeType ''' and NodeNum = ''' nN ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DATnodoSS = curs.Data;
[~,c1] = size(DATnodoSS);
[~,c2] = size(DATnodoSSd);
if c1 == c2
DATnodoSS = [DATnodoSSd; DATnodoSS];
elseif c1 < c2 % solo giorno di riferimento
DATnodoSS = DATnodoSSd;
end
[rDAT,cDAT] = size(DATnodoSS);
if rDAT==1 && cDAT==1
clear DatiElabShockSensor
fclose(fileID);
cancellaDB(IDcentralina,DTcatena,Data_scarico,conn,FileName);
fileID = fopen(FileName,'a');
fmt = '%s \r';
Condition = 1;
break
else
if ii > 1 % Nodo successivo al primo
[rDE,~] = size(DatiElabShockSensor);
if rDE ~= rDAT
clear DatiElabShockSensor
fclose(fileID);
cancellaDB(IDcentralina,DTcatena,Data_scarico,conn,FileName);
fileID = fopen(FileName,'a');
fmt = '%s \r';
Condition = 1;
break
end
end
DatiElabShockSensor(:,ini_col:col) = DATnodoSS(:,:);
end
ii = ii+1;
end
if Condition == 1
datainiSS = datenum(datainiSS) - 1;
Data_scarico = datestr(datainiSS,'yyyy-mm-dd HH:MM:SS');
datainiSS = Data_scarico;
fileID = fopen(FileName,'a');
else
Check = isnan(cell2mat(DatiElabShockSensor(1,3:16:end)));
for jj = 1:rSS
if Check == 1
datainiSS = datenum(datainiSS) - 1;
Data_scarico = datestr(datainiSS,'yyyy-mm-dd HH:MM:SS');
datainiSS = Data_scarico;
break
else
NAN = 1;
end
end
end
end
text = 'Shock Sensor executed during LastElab function';
fprintf(fileID,fmt,text);
else
DatiElabShockSensor = [];
end
else
datainiSS = [];
tempoiniSS = [];
DatiElabShockSensor = [];
NuovoZeroSS = 0;
end
%% Load Link
if yesLL == 1 % Importo ultimo dato elaborato dei Load Link
NodeNumLL = num2str(cell2mat(NodoLoadLink(1,2))); % scarico i dati del primo nodo Load Link
NodeType = 'Load Link';
% Dati Grezzi
comando = ['select Date, Time from RawDataView where Date = ''' ...
date ''' and time >= ''' time ''' and UnitName = ''' IDcentralina ''' and ToolNameID = '''...
DTcatena ''' and NodeType = ''' NodeType ''' and NodeNum =' NodeNumLL ' '];
curs = exec(conn,comando);
curs = fetch(curs);
D_num_ini = curs.Data;
[rI,cI] = size(D_num_ini);
if rI == 1 && cI == 1 % Non ci sono dati per la data "date"
comando = ['select Date, Time from RawDataView where Date > ''' ...
date ''' and UnitName = ''' IDcentralina...
''' and ToolNameID = ''' DTcatena ''' and NodeType = ''' ...
NodeType ''' and NodeNum =' NodeNumLL ' '];
curs = exec(conn,comando);
curs = fetch(curs);
D_num_ini = curs.Data;
[rI,cI] = size(D_num_ini);
end
if rI && cI == 1
Data_num_ini = 0;
else
Data_num_ini = [cell2mat(D_num_ini(:,1)) repmat(' ', [rI,1]) cell2mat(D_num_ini(:,2))];
end
Data_num_ini = datenum(Data_num_ini); % tutte le date presenti nel DB grezzo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
date ''' and UnitName = ''' IDcentralina ''' and ToolNameID = ''' DTcatena ...
''' and NodeType = ''' NodeType ''' and NodeNum =' NodeNumLL ' '];
curs = exec(conn,comando);
curs = fetch(curs);
Data_LastElab = curs.Data;
[rLE,cLE] = size(Data_LastElab);
Date = [cell2mat(Data(1,1)) repmat(' ', [1,1]) cell2mat(Data(1,2))];
data1a = datenum(Date);
data1b = Data_num_ini(1);
if data1b>data1a
data1 = data1b;
else
data1 = data1a;
end
if rLE==1 && cLE==1
datainiLL = datestr(data1,'yyyy-mm-dd');
tempoiniLL = datestr(data1,'HH:MM:SS');
NuovoZeroLL = 0;
else
% Modifico il formato di data e ora in DATini.
[rD,~] = size(Data_LastElab);
Data_numero = [cell2mat(Data_LastElab(:,1)) repmat(' ', [rD,1]) cell2mat(Data_LastElab(:,2))];
Data_numero = datenum(Data_numero); % tutte le date presenti nel DB grezzo
margine = 1;
if Ndatidespike > NdatiMedia
Ndati = Ndatidespike;
else
Ndati = NdatiMedia;
end
if margine < Ndati/2
margine = round(Ndati/2+1);
end
cont = Ndati + margine;
if cont < 3
cont = 3;
end
[rDS,~] = size(Data_numero);
if rDS <= cont
cont = rDS-1;
end
Data_scarico = Data_numero(end-cont);
Data_scarico = datestr(Data_scarico,'yyyy-mm-dd');
data2 = datenum(Data_scarico);
if data2 > data1
datainiLL = datestr(data2,'yyyy-mm-dd');
tempoiniLL = datestr(data2,'HH:MM:SS');
NuovoZeroLL = 1; %1
else
datainiLL = datestr(data1,'yyyy-mm-dd');
tempoiniLL = datestr(data1,'HH:MM:SS');
NuovoZeroLL = 0;
end
end
text = 'Load Link executed during LastElab function';
fprintf(fileID,fmt,text);
else
datainiLL = [];
tempoiniLL = [];
NuovoZeroLL = 0;
end
%% G-Flow Link
if yesGF == 1 % Importo ultimo dato elaborato G-Flow
% Dati Grezzi
DATA = [date time];
comando = ['select EventDateTime from ELABDATAGFLOW where EventDateTime >= ''' ...
DATA ''' and unit_name = ''' IDcentralina ''' and tool_name = '''...
DTcatena ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
D_num_ini = curs.Data;
[rI,cI] = size(D_num_ini);
if rI == 1 && cI == 1
Data_num_ini = 0;
else
Data_num_ini = D_num_ini;
end
Data_num_ini = datenum(Data_num_ini); % tutte le date presenti nel DB grezzo
Date = [cell2mat(Data(1,1)) repmat(' ', [1,1]) cell2mat(Data(1,2))];
data1a = datenum(Date);
data1b = Data_num_ini(1);
if data1b>data1a
data1 = data1b;
else
data1 = data1a;
end
if rI==1 && cI==1
datainiGF = datestr(data1,'yyyy-mm-dd');
tempoiniGF = datestr(data1,'HH:MM:SS');
else
% Modifico il formato di data e ora in DATini.
Data_numero = Data_num_ini(end);
margine = 15;
if Ndatidespike > NdatiMedia
Ndati = Ndatidespike;
else
Ndati = NdatiMedia;
end
if margine < Ndati/2
margine = round(Ndati/2+1);
end
cont = Ndati + margine;
if cont < 2
cont = 2;
end
Data_scarico = Data_numero(end)-cont;
Data_scarico = datestr(Data_scarico,'yyyy-mm-dd');
data2 = datenum(Data_scarico);
if data2 > data1
datainiGF = datestr(data2,'yyyy-mm-dd');
tempoiniGF = datestr(data2,'HH:MM:SS');
else
datainiGF = datestr(data1,'yyyy-mm-dd');
tempoiniGF = datestr(data1,'HH:MM:SS');
end
end
text = 'G-Flow Link executed during LastElab function';
fprintf(fileID,fmt,text);
else
datainiGF = [];
tempoiniGF = [];
end
%% G-Shock Link
if yesGS == 1 % Importo ultimo dato elaborato dei RSN Link
% Dati Grezzi
DATA = [date time];
comando = ['select EventDateTime from ELABDATAGFLOW where EventDateTime >= ''' ...
DATA ''' and unit_name = ''' IDcentralina ''' and tool_name = '''...
DTcatena ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
D_num_ini = curs.Data;
[rI,cI] = size(D_num_ini);
if rI == 1 && cI == 1
Data_num_ini = 0;
else
Data_num_ini = D_num_ini;
end
Data_num_ini = datenum(Data_num_ini); % tutte le date presenti nel DB grezzo
Date = [cell2mat(Data(1,1)) repmat(' ', [1,1]) cell2mat(Data(1,2))];
data1a = datenum(Date);
data1b = Data_num_ini(1);
if data1b>data1a
data1 = data1b;
else
data1 = data1a;
end
if rI==1 && cI==1
datainiGS = datestr(data1,'yyyy-mm-dd');
tempoiniGS = datestr(data1,'HH:MM:SS');
else
% Modifico il formato di data e ora in DATini.
Data_numero = Data_num_ini(end);
margine = 15;
if Ndatidespike > NdatiMedia
Ndati = Ndatidespike;
else
Ndati = NdatiMedia;
end
if margine < Ndati/2
margine = round(Ndati/2+1);
end
cont = Ndati + margine;
if cont < 2
cont = 2;
end
Data_scarico = Data_numero(end-cont);
Data_scarico = datestr(Data_scarico,'yyyy-mm-dd');
data2 = datenum(Data_scarico);
if data2 > data1
datainiGS = datestr(data2,'yyyy-mm-dd');
tempoiniGS = datestr(data2,'HH:MM:SS');
else
datainiGS = datestr(data1,'yyyy-mm-dd');
tempoiniGS = datestr(data1,'HH:MM:SS');
end
end
text = 'G-Shock Link executed during LastElab function';
fprintf(fileID,fmt,text);
else
datainiGS = [];
tempoiniGS = [];
end
%% Debris Link
if yesDL == 1 % Importo ultimo dato elaborato dei RSN Link
NodeNumDL = num2str(cell2mat(NodoDebrisLink(1,2))); % scarico i dati del primo nodo
NodeType = 'Debris Link';
% Dati Grezzi
comando = ['select Date, Time from RawDataView where Date = ''' ...
date ''' and Time >= ''' time ''' and UnitName = ''' IDcentralina ''' and ToolNameID = '''...
DTcatena ''' and NodeType = ''' NodeType ''' and NodeNum =' NodeNumDL ' '];
curs = exec(conn,comando);
curs = fetch(curs);
D_num_ini = curs.Data;
[rI,cI] = size(D_num_ini);
if rI == 1 && cI == 1 % Non ci sono dati per la data "date"
comando = ['select Date, Time from RawDataView where Date > ''' ...
date ''' and UnitName = ''' IDcentralina...
''' and ToolNameID = ''' DTcatena ''' and NodeType = ''' ...
NodeType ''' and NodeNum =' NodeNumDL ' '];
curs = exec(conn,comando);
curs = fetch(curs);
D_num_ini = curs.Data;
[rI,cI] = size(D_num_ini);
end
if rI && cI == 1
Data_num_ini = 0;
else
Data_num_ini = [cell2mat(D_num_ini(:,1)) repmat(' ', [rI,1]) cell2mat(D_num_ini(:,2))];
end
Data_num_ini = datenum(Data_num_ini); % tutte le date presenti nel DB grezzo
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
date ''' and UnitName = ''' IDcentralina ''' and ToolNameID = ''' DTcatena ...
''' and NodeType = ''' NodeType ''' and NodeNum =' NodeNumDL ' '];
curs = exec(conn,comando);
curs = fetch(curs);
Data_LastElab = curs.Data;
[rLE,cLE] = size(Data_LastElab);
Date = [cell2mat(Data(1,1)) repmat(' ', [1,1]) cell2mat(Data(1,2))];
data1a = datenum(Date);
data1b = Data_num_ini(1);
if data1b>data1a
data1 = data1b;
else
data1 = data1a;
end
if rLE==1 && cLE==1
datainiDL = datestr(data1,'yyyy-mm-dd');
tempoiniDL = datestr(data1,'HH:MM:SS');
NuovoZeroDL = 0;
else
% Modifico il formato di data e ora in DATini.
[rD,~] = size(Data_LastElab);
Data_numero = [cell2mat(Data_LastElab(:,1)) repmat(' ', [rD,1]) cell2mat(Data_LastElab(:,2))];
Data_numero = datenum(Data_numero); % tutte le date presenti nel DB grezzo
margine = 1;
if Ndatidespike > NdatiMedia
Ndati = Ndatidespike;
else
Ndati = NdatiMedia;
end
if margine < Ndati/2
margine = round(Ndati/2+1);
end
cont = Ndati + margine;
if cont < 3
cont = 3;
end
[rDS,~] = size(Data_numero);
if rDS <= cont
cont = rDS-1;
end
Data_scarico = Data_numero(end-cont);
Data_scarico = datestr(Data_scarico,'yyyy-mm-dd');
data2 = datenum(Data_scarico);
if data2 > data1
datainiDL = datestr(data2,'yyyy-mm-dd');
tempoiniDL = datestr(data2,'HH:MM:SS');
NuovoZeroDL = 1;
else
datainiDL = datestr(data1,'yyyy-mm-dd');
tempoiniDL = datestr(data1,'HH:MM:SS');
NuovoZeroDL = 0;
end
end
if NuovoZeroDL == 1 % scarico gli ultimi dati elaborati
NAN = 0;
while NAN == 0
if datenum(datainiDL) < datenum(date)
datainiDL = date;
end
NDebrisLink = cell2mat(NodoDebrisLink(:,2));
ii = 1; % contatore
col = 11; % contatore colonne
Condition = 0;
while ii <= rDL
ini_col = col-10;
nN = num2str(NDebrisLink(ii,1));
% Scarico di dati di spostamenti
comando = ['select EventDate, EventTime, XShift, YShift, ZShift, X, Y, Z, T_node, AlfaX, AlfaY from ElabDataView where EventDate = ''' ...
Data_scarico(1,1:10) ''' and EventTime >= ''' Data_scarico(1,12:end) ''' and UnitName = ''' IDcentralina ''' and ToolNameID = '''...
DTcatena ''' and NodeType = ''' NodeType ''' and NodeNum = ''' nN ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DATnodoDLd = curs.Data;
% Scarico di dati di spostamenti
comando = ['select EventDate, EventTime, XShift, YShift, ZShift, X, Y, Z, T_node, AlfaX, AlfaY from ElabDataView where EventDate > ''' ...
Data_scarico(1,1:10) ''' and UnitName = ''' IDcentralina ''' and ToolNameID = '''...
DTcatena ''' and NodeType = ''' NodeType ''' and NodeNum = ''' nN ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DATnodoDL = curs.Data;
[~,c1] = size(DATnodoDL);
[~,c2] = size(DATnodoDLd);
if c1 == c2
DATnodoDL = [DATnodoDLd; DATnodoDL];
elseif c1 < c2 % solo giorno di riferimento
DATnodoDL = DATnodoDLd;
end
[rDAT,cDAT] = size(DATnodoDL);
if rDAT==1 && cDAT==1
clear DatiElabDebrisLink
fclose(fileID);
cancellaDB(IDcentralina,DTcatena,Data_scarico,FileName,conn);
fileID = fopen(FileName,'a');
fmt = '%s \r';
Condition = 1;
break
else
if ii > 1 % Nodo successivo al primo
[rDE,~] = size(DatiElabDebrisLink);
if rDE ~= rDAT
clear DatiElabDebrisLink
fclose(fileID);
cancellaDB(IDcentralina,DTcatena,Data_scarico,FileName,conn);
fileID = fopen(FileName,'a');
fmt = '%s \r';
Condition = 1;
break
end
end
DatiElabDebrisLink(:,ini_col:col) = DATnodoDL(:,:);
end
col = col+11;
ii = ii+1;
end
if Condition == 1
datainiDL = datenum(datainiDL) - 1;
Data_scarico = datestr(datainiDL,'yyyy-mm-dd HH:MM:SS');
datainiDL = Data_scarico;
fileID = fopen(FileName,'a');
else
Check = isnan(cell2mat(DatiElabDebrisLink(1,3:16:end)));
for jj = 1:rTuL
if Check == 1
datainiDL = datenum(datainiDL) - 1;
Data_scarico = datestr(datainiDL,'yyyy-mm-dd HH:MM:SS');
datainiDL = Data_scarico;
break
else
NAN = 1;
end
end
end
end
end
text = 'Debris Link executed during LastElab function';
fprintf(fileID,fmt,text);
else
datainiDL = [];
tempoiniDL = [];
NuovoZeroDL = 0;
DatiElabDebrisLink = [];
end
text = 'LastElab function worked correctly';
fprintf(fileID,fmt,text);
fclose(fileID);
end

46
RSN/LastElab_bisDL.m Executable file
View File

@@ -0,0 +1,46 @@
function DatiElabDebrisLink = LastElab_bisDL(conn,NodoDebrisLink,rDL,datainiDL,...
tempoiniDL,IDcentralina,DTcatena,FileName)
text = 'LastElab_bisDL function started';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
NDebrisLink = cell2mat(NodoDebrisLink(:,2));
NodeType = 'Debris Link';
ii = 1; % contatore
col = 11; % contatore colonne
while ii <= rDL
ini_col = col-10;
nN = num2str(NDebrisLink(ii,1));
% Scarico di dati di spostamenti - giorno X
comando = ['select EventDate, EventTime, XShift, YShift, ZShift, X, Y, Z, T_node, AlfaX, AlfaY from ElabDataView where EventDate = ''' ...
datainiDL ''' and EventTime >= ''' tempoiniDL ''' and UnitName = ''' IDcentralina ...
''' and ToolNameID = ''' DTcatena ''' and NodeType = ''' NodeType ''' and NodeNum = ''' nN ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DATnodoDLd = curs.Data;
% Scarico di dati di spostamenti - giorni successivi a X
comando = ['select EventDate, EventTime, XShift, YShift, ZShift, X, Y, Z, T_node, AlfaX, AlfaY from ElabDataView where EventDate >= ''' ...
datainiDL ''' and UnitName = ''' IDcentralina ''' and ToolNameID = ''' DTcatena ...
''' and NodeType = ''' NodeType ''' and NodeNum = ''' nN ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DATnodoDL = curs.Data;
[~,c1] = size(DATnodoDL);
[~,c2] = size(DATnodoDLd);
if c1 == c2
DATnodoDL = [DATnodoDLd; DATnodoDL];
elseif c1 < c2 % solo giorno di riferimento
DATnodoDL = DATnodoDLd;
end
DatiElabDebrisLink(:,ini_col:col) = DATnodoDL(:,:);
col = col+11;
ii = ii+1;
end
text = 'LastElab_bisDL function worked correctly';
fprintf(fileID,fmt,text);
fclose(fileID);
end

46
RSN/LastElab_bisSS.m Executable file
View File

@@ -0,0 +1,46 @@
function DatiElabShockSensor = LastElab_bisSS(conn,NodoShockSensor,rSS,datainiSS,...
tempoiniSS,IDcentralina,DTcatena,FileName)
text = 'LastElab_bisSS function started';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
NShockSensor = cell2mat(NodoShockSensor(:,2));
NodeType = 'Shock Sensor';
ii = 1; % contatore
col = 3; % contatore colonne
while ii <= rSS
ini_col = col-2;
nN = num2str(NShockSensor(ii,1));
% Scarico di dati di spostamenti - giorno X
comando = ['select EventDate, EventTime, X from ElabDataView where EventDate = ''' ...
datainiSS ''' and EventTime >= ''' tempoiniSS ''' and UnitName = ''' IDcentralina ...
''' and ToolNameID = ''' DTcatena ''' and NodeType = ''' NodeType ''' and NodeNum = ''' nN ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DATnodoSSd = curs.Data;
% Scarico di dati di spostamenti - giorni successivi a X
comando = ['select EventDate, EventTime, X from ElabDataView where EventDate >= ''' ...
datainiSS ''' and UnitName = ''' IDcentralina ''' and ToolNameID = ''' DTcatena ...
''' and NodeType = ''' NodeType ''' and NodeNum = ''' nN ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DATnodoSS = curs.Data;
[~,c1] = size(DATnodoSS);
[~,c2] = size(DATnodoSSd);
if c1 == c2
DATnodoSS = [DATnodoSSd; DATnodoSS];
elseif c1 < c2 % solo giorno di riferimento
DATnodoSS = DATnodoSSd;
end
DatiElabShockSensor(:,ini_col:col) = DATnodoSS(:,:);
col = col+3;
ii = ii+1;
end
text = 'LastElab_bisSS function worked correctly';
fprintf(fileID,fmt,text);
fclose(fileID);
end

45
RSN/LastElab_bisTrL.m Executable file
View File

@@ -0,0 +1,45 @@
function DatiElabTriggerLink = LastElab_bisTrL(conn,NodoTriggerLink,rTrL,datainiTrL,tempoiniTrL,IDcentralina,DTcatena,FileName)
text = 'LastElab_bisTrL function started';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
NTriggerLink = cell2mat(NodoTriggerLink(:,2));
NodeType = 'Trigger Link';
ii = 1; % contatore
col = 3; % contatore colonne
while ii <= rTrL
ini_col = col-2;
nN = num2str(NTriggerLink(ii,1));
% Scarico di dati di spostamenti - giorno X
comando = ['select EventDate, EventTime, X from ElabDataView where EventDate = ''' ...
datainiTrL ''' and EventTime >= ''' tempoiniTrL ''' and UnitName = ''' IDcentralina ...
''' and ToolNameID = ''' DTcatena ''' and NodeType = ''' NodeType ''' and NodeNum = ''' nN ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DATnodoTrLd = curs.Data;
% Scarico di dati di spostamenti - giorni successivi a X
comando = ['select EventDate, EventTime, X from ElabDataView where EventDate >= ''' ...
datainiTrL ''' and UnitName = ''' IDcentralina ''' and ToolNameID = ''' DTcatena ...
''' and NodeType = ''' NodeType ''' and NodeNum = ''' nN ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DATnodoTrL = curs.Data;
[~,c1] = size(DATnodoTrL);
[~,c2] = size(DATnodoTrLd);
if c1 == c2
DATnodoTrL = [DATnodoTrLd; DATnodoTrL];
elseif c1 < c2 % solo giorno di riferimento
DATnodoTrL = DATnodoTrLd;
end
DatiElabTriggerLink(:,ini_col:col) = DATnodoTrL(:,:);
col = col+3;
ii = ii+1;
end
text = 'LastElab_bisTrL function worked correctly';
fprintf(fileID,fmt,text);
fclose(fileID);
end

29
RSN/MediaDati_LL.m Executable file
View File

@@ -0,0 +1,29 @@
% Questa routine calcola le medie (giornaliere o per intervalli definiti)
% necessarie per le elaborazioni successive per la cella di carico
% LOADdef contiene le medie per l'intervallo definito dei valori di forza
% ARRAYdateLL contiene le date e il tempo per ogni dato (per media
% giornaliera, la data di quel giorno)
function [DatiLoad,ARRAYdateLL] = MediaDati_LL(DatiLoad,TimeLL,NdatiMedia,FileName)
text = 'MediaDati_LL function started';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
%% Accelerazione
[r,~] = size(DatiLoad);
if NdatiMedia > r
NdatiMedia = r;
end
% NON si fa la media dell'ultimo dato
DatiLoad_M = smoothdata(DatiLoad(1:end-1,:),'gaussian',NdatiMedia);
DatiLoad = [DatiLoad_M; DatiLoad(end,:)];
ARRAYdateLL = TimeLL;
text = 'Average mean of Load Link data executed correctly. MediaDati_LL function closed';
fprintf(fileID,fmt,text);
fclose(fileID);
end

32
RSN/MediaDati_RSN.m Executable file
View File

@@ -0,0 +1,32 @@
% Questa routine calcola le medie (giornaliere o per intervalli definiti)
% necessarie per le elaborazioni successive per i RSN Link
% ang_RSN contiene le medie per l'intervallo definito delle accelerazioni
% ARRAYdate contiene le date e il tempo per ogni dato (per media
% giornaliera, la data di quel giorno)
function [angRSN,ARRAYdateRSN,TempDef_RSN] = MediaDati_RSN(accRSN,TimeRSN,tempRSN,NdatiMedia,FileName)
text = 'MediaDati_RSN function started';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
%% Accelerazione
[r,~] = size(accRSN);
if NdatiMedia > r
NdatiMedia = r;
end
% NON si fa la media dell'ultimo dato
accRSN_M = smoothdata(accRSN(1:end-1,:),'gaussian',NdatiMedia);
angRSN = [accRSN_M; accRSN(end,:)];
ARRAYdateRSN = TimeRSN;
%% Temperatura
TempDef_RSN = tempRSN; % Non faccio la media, mi serve il dato come è per applicare i filtri
text = 'Average mean of RSN Link data executed correctly. MediaDati_RSN ended';
fprintf(fileID,fmt,text);
fclose(fileID);
end

33
RSN/MediaDati_RSNHR.m Executable file
View File

@@ -0,0 +1,33 @@
% Questa routine calcola le medie (giornaliere o per intervalli definiti)
% necessarie per le elaborazioni successive per i RSN Link HR
% ACCdefRSNHR contiene le medie per l'intervallo definito delle accelerazioni
% ARRAYdateRSNHR contiene le date e il tempo per ogni dato (per media
% giornaliera, la data di quel giorno)
function [angRSNHR,ARRAYdateRSNHR,TempDef_RSNHR] = MediaDati_RSNHR(angRSNHR,...
TimeRSNHR,T_RSNHR,NdatiMedia,FileName)
text = 'MediaDati_RSNHR function started';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
%% Angoli
[r,~] = size(angRSNHR);
if NdatiMedia > r
NdatiMedia = r;
end
% NON si fa la media dell'ultimo dato
angRSNHR_M = smoothdata(angRSNHR(1:end-1,:),'gaussian',NdatiMedia);
angRSNHR = [angRSNHR_M; angRSNHR(end,:)];
ARRAYdateRSNHR = TimeRSNHR;
%% Temperature
TempDef_RSNHR = T_RSNHR; % Non faccio la media, mi serve il dato come è per applicare i filtri
text = 'Average mean of RSN Link HR data executed correctly';
fprintf(fileID,fmt,text);
fclose(fileID);
end

58
RSN/NuovaConversione.m Executable file
View File

@@ -0,0 +1,58 @@
function [DCalRSNTot,DCalRSNHRTot,DCalLLTot,DCalDLTot] = NuovaConversione(DCalRSNTot,...
DCalRSNHRTot,DCalLLTot,DCalDLTot)
% Conversione del formato dati che usiamo con il database Ase_New
%% RSN Link
[r,c] = size(DCalRSNTot);
MATconv = zeros(r,c);
if r == 0 % Non ci sono dati
else
for ii = 1:r
for jj = 1:c
MATconv(ii,jj) = DCalRSNTot{ii,jj};
end
end
DCalRSNTot = MATconv;
end
%% RSN Link HR
[r,c] = size(DCalRSNHRTot);
MATconv = zeros(r,c);
if r == 0 % Non ci sono dati
else
for ii = 1:r
for jj = 1:c
MATconv(ii,jj) = DCalRSNHRTot{ii,jj};
end
end
DCalRSNHRTot = MATconv;
end
%% Load Link
[r,c] = size(DCalLLTot);
MATconv = zeros(r,c);
if r == 0 % Non ci sono dati
else
for ii = 1:r
for jj = 1:c
MATconv(ii,jj) = DCalLLTot{ii,jj};
end
end
DCalLLTot = MATconv;
end
%% Debris Link
[r,c] = size(DCalDLTot);
MATconv = zeros(r,c);
if r == 0 % Non ci sono dati
else
for ii = 1:r
for jj = 1:c
MATconv(ii,jj) = DCalDLTot{ii,jj};
end
end
DCalDLTot = MATconv;
end
end

52
RSN/Parametri_Installazione.m Executable file
View File

@@ -0,0 +1,52 @@
%% Funzione che definisce i parametri specifici di elaborazione
function [NdatiMedia,Ndatidespike,MEMS,tolleranzaAcc,pos_inst,Tmax,Tmin,SEL,...
MEL] = Parametri_Installazione(yesRSN,yesRSNHR,yesDL,idTool,conn,FileName)
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'Parametri_Installazione function started';
fprintf(fileID,fmt,text);
comando = ['select avg, despike from software where tool_id like ''' idTool ''' '];
Dati = fetch(conn,comando);
NdatiMedia = cell2mat(Dati(1));
Ndatidespike = cell2mat(Dati(2));
if yesRSN == 1 || yesRSNHR == 1 || yesDL == 1
%% Temperature
comando = ['select max_temp, min_temp from software where tool_id like ''' idTool ''' '];
Dati = fetch(conn,comando);
Tmax = cell2mat(Dati(1));
Tmin = cell2mat(Dati(2));
%% MEMS
if yesRSN == 1 || yesDL == 1
comando = ['select mems, toll_Acc, pos_inst, sel, mel from software where tool_id like ''' idTool ''' '];
Dati = fetch(conn,comando);
MEMS = cell2mat(Dati(1));
tolleranzaAcc = cell2mat(Dati(2));
pos_inst = cell2mat(Dati(3));
SEL = cell2mat(Dati(4));
MEL = cell2mat(Dati(5));
else
MEMS = [];
tolleranzaAcc = [];
pos_inst = [];
SEL = [];
MEL = [];
end
else
MEMS = [];
tolleranzaAcc = [];
Tmax = [];
Tmin = [];
pos_inst = [];
SEL = [];
MEL = [];
end
text = 'Chain parameters defined correctly and Parametri_Installazione function ended';
fprintf(fileID,fmt,text);
fclose(fileID);
end

375
RSN/RSN.m Executable file
View File

@@ -0,0 +1,375 @@
function RC = RSN(IDcentralina,DTcatena)
%%% Programma per l'elaborazione dei dati del Rockfall Safety Network
%%% Versione 2.0 del febbraio-giugno 2021
tic
RC = 1; %#ok<NASGU>
text = ['Elaboration of RSN chain ' DTcatena ' of control unit ' IDcentralina ' started correctly'];
d = datestr(datetime,'yyyy_mm_dd');
t = datestr(datetime,'HH_MM_SS');
FileName = ['LogFile_RSN-' IDcentralina '-' DTcatena '-' d '-' t '.txt'];
outdat = fopen(FileName,'wt+');
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
%% Parte generale
% Associo ID company al relativo DB
% Definisco i parametri del Database
IDcompany = '1'; % DA INTEGRARE IN VERSIONI FUTURE
DB = database_definition(IDcompany,FileName);
% Apro la connessione al DB
dbname = cell2mat(DB{1,1});
username = cell2mat(DB{2,1});
password = cell2mat(DB{3,1});
driver = cell2mat(DB{4,1});
dburl = 'jdbc:mysql://212.237.30.90:3306/ase_lar?useLegacyDatetimeCode=false&serverTimezone=Europe/Rome&';
conn = database(dbname, username, password, driver, dburl);
% scarico Contol Unit ID
unitID = IDunit(IDcentralina,conn,FileName);
% questa funzione considera la prima data e ora da cui caricare i dati a seconda della catena
[date,time,unitID] = datainiziale(DTcatena,unitID,conn,FileName);
% funzione che elenca tutti i nodi ed il loro numero presenti per ogni tipo di sensore.
[idTool,NodoRSNLink,NodoSS,NodoRSNLinkHR,~,NodoLoadLink,...
NodoTriggerLink,NodoGflowLink,NodoGshockLink,NodoDebrisLink] = tipologiaNodi(...
DTcatena,unitID,conn,FileName);
% funzione che ricostruisce i nodi della catena
catena = schema(idTool,conn,FileName);
% funzione che attiva/disattiva l'elaborazione per una determinata tipologia di nodo
[yesRSN,yesRSNHR,yesSS,yesLL,yesTrL,yesGF,yesGS,yesDL,rRSN,rRSNHR,...
rLL,rTrL,rSS,rDL] = YesNo(NodoRSNLink,NodoRSNLinkHR,NodoSS,NodoLoadLink,...
NodoTriggerLink,NodoGflowLink,NodoGshockLink,NodoDebrisLink,FileName);
% funzione che definisce tutti i parametri importanti a elaborare
% un'installazione
[NdatiMedia,Ndatidespike,MEMS,tolleranzaAcc,pos_inst,Tmax,Tmin,SEL,...
MEL] = Parametri_Installazione(yesRSN,yesRSNHR,yesDL,idTool,conn,FileName);
% funzione che carica i dati di calibrazione
[DCalRSNTot,DCalRSNHRTot,DCalLLTot,~,yesRSN,yesRSNHR,yesLL,yesDL]...
= letturaCal(MEMS,IDcentralina,DTcatena,catena,yesRSN,yesRSNHR,yesLL,yesDL,rRSN,...
rRSNHR,rLL,rDL,NodoRSNLink,NodoLoadLink,NodoDebrisLink,conn,FileName);
% tipologia di centralina
Unit = centralina(IDcentralina,conn,FileName);
%% Scarico dei dati
% Scarico l'ultima data elaborata: in questo modo far<EFBFBD> i calcoli a partire
% solo da qualche data prima, per incrementare le prestazioni del software
[NuovoZeroRSN,datainiRSN,tempoiniRSN,NuovoZeroRSNHR,datainiRSNHR,tempoiniRSNHR,...
DatiElabTriggerLink,NuovoZeroTrL,datainiTrL,tempoiniTrL,DatiElabShockSensor,NuovoZeroSS,...
datainiSS,tempoiniSS,NuovoZeroLL,datainiLL,tempoiniLL,datainiGF,tempoiniGF,datainiGS,tempoiniGS,...
DatiElabDebrisLink,NuovoZeroDL,datainiDL,tempoiniDL]...
= LastElab(conn,date,time,IDcentralina,DTcatena,NdatiMedia,NodoRSNLink,yesRSN,NodoRSNLinkHR,yesRSNHR,...
NodoTriggerLink,yesTrL,rTrL,NodoSS,yesSS,rSS,NodoLoadLink,yesLL,yesGF,yesGS,NodoDebrisLink,yesDL,...
rDL,Ndatidespike,FileName);
% Carico i dati dal database a seconda della catena
[Batteria,Batteria_LoRa,Type,DatiRSNLink,ErrRSNLink,DatiRSNLinkHR,ErrRSNLinkHR,DatiTriggerLink,ErrTriggerLink,...
DatiShockSensor,ErrShockSensor,DatiLoadLink,ErrLoadLink,DatiDebrisLink,ErrDebrisLink,DatiGFLink,ErrGFLink,...
DatiGSLink,ErrGSLink,yesRSN,yesRSNHR,yesTrL,yesLL,yesDL] = lettura(IDcentralina,DTcatena,MEMS,datainiRSN,tempoiniRSN,...
NodoRSNLink,NuovoZeroRSN,datainiSS,tempoiniSS,NodoSS,NuovoZeroSS,datainiRSNHR,tempoiniRSNHR,NodoRSNLinkHR,...
NuovoZeroRSNHR,datainiTrL,tempoiniTrL,NodoTriggerLink,NuovoZeroTrL,datainiLL,tempoiniLL,NodoLoadLink,NuovoZeroLL,...
datainiGF,tempoiniGF,datainiGS,tempoiniGS,datainiDL,tempoiniDL,NodoDebrisLink,yesRSN,yesSS,yesRSNHR,yesTrL,yesLL,...
yesGF,yesGS,yesDL,rRSN,rSS,rRSNHR,rTrL,rLL,rDL,conn,catena,date,time,FileName);
% Controllo incrociato fra la data iniziale definita da Lettura e la data
% iniziale definita da LastElab
[DatiElabTriggerLink,DatiElabShockSensor,DatiElabDebrisLink] = checkdata(...
yesTrL,yesSS,yesDL,DatiElabTriggerLink,DatiElabShockSensor,DatiElabDebrisLink,...
datainiTrL,datainiSS,datainiDL,rTrL,rSS,rDL,tempoiniTrL,tempoiniSS,tempoiniDL,...
NodoTriggerLink,NodoSS,NodoDebrisLink,NuovoZeroTrL,NuovoZeroSS,NuovoZeroDL,...
IDcentralina,DTcatena,conn,FileName);
%% ---Parte di definizione dati---
%% RSN Link
if yesRSN == 1 % attiva l'elaborazione dei RSN Link
[TimeRSN,accRSN,tempRSN,ErrRSNLink] = defDatiRSN(MEMS,DatiRSNLink,...
ErrRSNLink,rRSN,Ndatidespike,FileName);
% Conversione dei dati grezzi
[accRSN,ris_acc,tempRSN] = conv_grezziRSN(rRSN,accRSN,...
tempRSN,DCalRSNTot,MEMS,FileName);
% medie
[angRSN,ARRAYdateRSN,TempDef_RSN] = MediaDati_RSN(accRSN,TimeRSN,tempRSN,...
NdatiMedia,FileName);
else
ARRAYdateRSN = [];
end
% Pulisco le variabili che non uso
clear DatiRSNLink
clear TimeRSN
clear accRSN
clear tempRSN
clear DCalRSNTot
%% RSN Link HR
if yesRSNHR == 1 % attiva l'elaborazione dei RSN Link HR
[TimeRSNHR,angRSNHR,tempRSNHR,ErrRSNLinkHR] = defDatiRSNHR(DatiRSNLinkHR,...
ErrRSNLinkHR,rRSNHR,IDcentralina,DTcatena,Ndatidespike,NuovoZeroRSNHR,FileName);
% Conversione dei dati grezzi
[angRSNHR,T_RSNHR] = conv_grezziRSNHR(angRSNHR,tempRSNHR,DCalRSNHRTot,rRSNHR,FileName);
% Media
[angRSNHR,ARRAYdateRSNHR,TempDef_RSNHR] = MediaDati_RSNHR(angRSNHR,...
TimeRSNHR,T_RSNHR,NdatiMedia,FileName);
else
ARRAYdateRSNHR = [];
end
% Pulisco le variabili che non uso
clear DatiRSNLinkHR
clear TimeRSNHR
clear tempRSNHR
clear DCalRSNHRTot
clear T_RSNHR
%% Trigger Link
if yesTrL == 1 % attiva l' definizione dei dati dei Trigger Link
[ARRAYdateTrL,val_TrL,ErrTriggerLink] = defDatiTrL(DatiTriggerLink,...
Type,ErrTriggerLink,rTrL,NuovoZeroTrL,FileName);
else
ARRAYdateTrL = [];
end
clear Type
%% Shock Sensor
if yesSS == 1 % attiva l' definizione dei dati dei Trigger Link
[ARRAYdateSS,val_SS,ErrShockSensor] = defDatiSS(DatiShockSensor,...
ErrShockSensor,rSS,FileName);
else
ARRAYdateSS = [];
end
%% Load Link
if yesLL == 1 % attiva l'elaborazione dei Load Link
[TimeLL,ADCLoad,ErrLoadLink] = defDatiLL(DatiLoadLink,ErrLoadLink,rLL,Ndatidespike,FileName);
% Conversione dei dati grezzi
DatiLoad = conv_grezziLL(ADCLoad,DCalLLTot,NodoLoadLink,FileName);
% Media
[LoadDef,ARRAYdateLL] = MediaDati_LL(DatiLoad,TimeLL,NdatiMedia,FileName);
else
ARRAYdateLL = [];
end
% Pulisco le variabili che non uso
clear DatiLoadLink
clear TimeLL
clear ADCLoad
clear DCalLLTot
clear DatiLoad
%% ---Parte di Elaborazione---
%% RSN Link
if yesRSN == 1
[AlfaX,AlfaY,TempDef_RSN,ARRAYdateRSN,ErrRSNLink] = elaborazione_RSN(conn,...
IDcentralina,DTcatena,MEMS,rRSN,ris_acc,tolleranzaAcc,angRSN,Tmax,Tmin,TempDef_RSN,...
NodoRSNLink,ARRAYdateRSN,NuovoZeroRSN,NdatiMedia,Ndatidespike,ErrRSNLink,datainiRSN,...
pos_inst,FileName);
else
[AlfaX,AlfaY,TempDef_RSN,ARRAYdateRSN] = matrici_vuote_RSN(FileName);
end
clear MEMS
clear ris_acc
clear tolleranza Acc
clear angRSN
clear NuovoZeroRSN
%% RSN Link HR
if yesRSNHR == 1
[AlfaX_HR,AlfaY_HR,TempDef_RSNHR,ARRAYdateRSNHR,ErrRSNLinkHR] = ...
elaborazione_RSNHR(conn,IDcentralina,DTcatena,rRSNHR,angRSNHR,Tmax,Tmin,...
TempDef_RSNHR,NodoRSNLinkHR,ARRAYdateRSNHR,NuovoZeroRSNHR,NdatiMedia,...
Ndatidespike,datainiRSNHR,ErrRSNLinkHR,FileName);
else
[AlfaX_HR,AlfaY_HR,TempDef_RSNHR] = matrici_vuote_RSNHR(FileName);
end
clear angRSNHR
clear NuovoZeroRSNHR
%% Load Link
if yesLL == 1
[LoadDef,ErrLoadLink,ARRAYdateLL] = loadcell(LoadDef,ErrLoadLink,...
ARRAYdateLL,NuovoZeroLL,NdatiMedia,Ndatidespike,yesRSN,IDcentralina,DTcatena,FileName);
else
LoadDef = [];
end
clear NuovoZeroLL
%% Elaborazione Trigger Link
if yesTrL == 1
if NuovoZeroTrL == 1
cont = 3;
[ndate,~] = size(val_TrL);
StoricoTrigger = zeros(ndate,rTrL);
for n = 1:rTrL
StoricoTrigger(:,n) = cumsum(val_TrL(:,n))+cell2mat(DatiElabTriggerLink(1,cont));
cont = cont+3;
end
else
StoricoTrigger = cumsum(val_TrL);
end
text = 'Trigger Link elaborated correctly';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
else
StoricoTrigger = [];
val_TrL=[];
ARRAYdateTrL = [];
text = 'Trigger Link has not been elaborated';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end
clear NuovoZeroTrL
%% Elaborazione Shock Sensor
if yesSS == 1
if NuovoZeroSS == 1
cont = 3;
[ndate,~] = size(val_SS);
StoricoShock = zeros(ndate,rSS);
ss = 1;
while ss <= ndate
if val_SS(ss) == 1 && val_SS(ss+1) == 1 && val_SS(ss+2) == 1
val_SS(ss+1) = 0;
val_SS(ss+2) = 0;
ss = ss+3;
else
ss = ss+1;
end
end
for n = 1:rSS
StoricoShock(:,n) = cumsum(val_SS(:,n))+cell2mat(DatiElabShockSensor(1,cont));
cont = cont+3;
end
else
StoricoShock = cumsum(val_SS);
end
text = 'Shock Sensor elaborated correctly';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
else
StoricoShock = [];
val_SS = [];
ARRAYdateSS = [];
text = 'Shock Sensor has not been elaborated';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end
clear NuovoZeroSS
%% G-Flow
if yesGF == 1
ARRAYdateGF = datenum(DatiGFLink(:,1));
DatiGFLink = cell2mat(DatiGFLink(:,2:end));
else
ARRAYdateGF = [];
DatiGFLink = [];
end
%% G-Shock
if yesGS == 1
ARRAYdateGS = datenum(DatiGSLink(:,1));
DatiGSLink = cell2mat(DatiGSLink(:,2:end));
else
ARRAYdateGS = [];
DatiGSLink = [];
end
%% Scrittura Database
database_write(catena,IDcentralina,DTcatena,...
AlfaX,AlfaY,TempDef_RSN,ARRAYdateRSN,ErrRSNLink,...
AlfaX_HR,AlfaY_HR,TempDef_RSNHR,ARRAYdateRSNHR,ErrRSNLinkHR,...
LoadDef,ErrLoadLink,ARRAYdateLL,val_TrL,StoricoTrigger,ErrTriggerLink,ARRAYdateTrL,...
val_SS,StoricoShock,ErrShockSensor,ARRAYdateSS,conn,FileName);
%% Parte di lancio SW complementari
yesMusa = SWSearch(idTool,conn,FileName);
try
if yesMusa == 1
rilancio = ['/usr/local/matlab_func/run_Musa_lnx.sh /usr/local/MATLAB/MATLAB_Runtime/v93 ' IDcentralina ' ' DTcatena ''];
status = system(rilancio);
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'Musa relaunch operation executed with success';
fprintf(fileID,fmt,text);
fprintf(fileID,fmt,status);
fclose(fileID);
end
catch err
FileErr = ['ErrorFile-' IDcentralina '-' datestr(today) '-' datestr(now,'hhMMss')];
fid = fopen(FileErr,'a+');
fprintf(fid, '%s', err.getReport('extended','hyperlinks','off'));
fclose(fid);
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'relaunch operation FAILED';
fprintf(fileID,fmt,text);
fclose(fileID);
end
%% Parte di allertamento
% Determino gli utenti da utilizzare in tutte le funzioni successive
[Mail,~,~,Users_Report,~,activeEN,~,siteID,NomeSito,~] = Users_Def(IDcentralina,conn,FileName);
% Determino alcune informazioni del sito che mi servono nei passaggi
% successivi
[unitID,chainID,Chain_Scheme,num_nodi,alarms] = Site_Info(siteID,conn,FileName);
% Soglie e Trigger
SirenON = alert_Levels(IDcentralina,DTcatena,ARRAYdateTrL,ARRAYdateSS,...
ARRAYdateRSN,datainiRSN,ARRAYdateRSNHR,ARRAYdateLL,ARRAYdateGF,ARRAYdateGS,SEL,MEL,...
val_TrL,val_SS,LoadDef,DatiGFLink,DatiGSLink,rTrL,rRSN,rRSNHR,rLL,yesTrL,yesSS,...
yesRSN,yesRSNHR,yesLL,yesGF,yesGS,NomeSito,date,conn,FileName);
% Attivazione dispositivi come sirene, semafori, etc.
Siren(alarms,datainiSS,datainiTrL,datainiRSN,datainiRSNHR,datainiLL,...
tempoiniSS,tempoiniTrL,tempoiniRSN,tempoiniRSNHR,tempoiniLL,ARRAYdateSS,ARRAYdateTrL,...
ARRAYdateRSN,ARRAYdateRSNHR,ARRAYdateLL,SirenON,conn,date,time,FileName);
% Controllo del Livello della Batteria
checkBattery(Batteria,IDcentralina,Unit,Mail,conn,FileName);
% Controllo della data di chiusura piattaforma per una determinata centralina
checkUnit(IDcentralina,conn,FileName);
% Controllo della data di scadenza per una determinata SIM
checkSIM(IDcentralina,conn,FileName);
% Controllo della data di scadenza della visualizzazione GIS per un
% determinato sito
checkGIS(siteID,NomeSito,conn,FileName);
% Redazione del Report Automatico
Report_ASE(IDcentralina,unitID,chainID,alarms,Chain_Scheme,num_nodi,...
Users_Report,Mail,time,activeEN,siteID,conn,FileName);
% Chiudo connessione al database
close(conn)
T = num2str(toc);
text = ['RSN elaboration completed in ' T '!'];
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
RC = 0;
end

54
RSN/SWSearch.m Executable file
View File

@@ -0,0 +1,54 @@
function yesMusa = SWSearch(idTool,conn,FileName)
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'SWSearch function started';
fprintf(fileID,fmt,text);
yesMusa = 0;
%% Baro Musa Link
comando = ['select num, depth from nodes where tool_id = ''' idTool ''' and nodetype_id = 41 order by num'];
Leggo = fetch(conn,comando);
[~,cL] = size(Leggo);
if cL > 1
yesMusa = 1;
text = 'Baro Musa Links identified, Musa relaunch activated';
fprintf(fileID,fmt,text);
end
%% Humidity link
comando = ['select num, depth from nodes where tool_id = ''' idTool ''' and nodetype_id = 35 order by num'];
Leggo = fetch(conn,comando);
[~,cL] = size(Leggo);
if cL > 1
yesMusa = 1;
text = 'Humidity Links identified, Musa relaunch activated';
fprintf(fileID,fmt,text);
end
%% CO2 Link
comando = ['select num, depth from nodes where tool_id = ''' idTool ''' and nodetype_id = 33 order by num'];
Leggo = fetch(conn,comando);
[~,cL] = size(Leggo);
if cL > 1
yesMusa = 1;
text = 'CO2 Links identified, Musa relaunch activated';
fprintf(fileID,fmt,text);
end
%% Lux Link
comando = ['select num, depth from nodes where tool_id = ''' idTool ''' and nodetype_id = 34 order by num'];
Leggo = fetch(conn,comando);
[~,cL] = size(Leggo);
if cL > 1
yesMusa = 1;
text = 'Lux Links identified, Musa relaunch activated';
fprintf(fileID,fmt,text);
end
text = 'SWScheme function ended';
fprintf(fileID,fmt,text);
fclose(fileID);
end

225
RSN/Siren.m Executable file
View File

@@ -0,0 +1,225 @@
function Siren(alarms,datainiSS,datainiTrL,datainiRSN,datainiRSNHR,datainiLL,...
tempoiniSS,tempoiniTrL,tempoiniRSN,tempoiniRSNHR,tempoiniLL,ARRAYdateSS,ARRAYdateTrL,...
ARRAYdateRSN,ARRAYdateRSNHR,ARRAYdateLL,SirenON,conn,date,time,FileName)
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'Siren function started';
fprintf(fileID,fmt,text);
[rA,cA] = size(alarms);
sirena = 0;
if rA > 0 && cA > 1
for aa = 1:rA
if cell2mat(alarms(aa,3)) == 1
sirena = 1;
break
end
end
end
if cA ~= 1 && sirena == 1
% Attivazione della Sirena al superamento di una determinata soglia
if yesSS == 1
dataini = datainiSS;
tempoini = tempoiniSS;
ARRAYdateAL = ARRAYdateSS;
elseif yesTrL == 1
dataini = datainiTrL;
tempoini = tempoiniTrL;
ARRAYdateAL = ARRAYdateTrL;
elseif yesRSN == 1
dataini = datainiRSN;
tempoini = tempoiniRSN;
ARRAYdateAL = ARRAYdateRSN;
elseif yesRSNHR == 1
dataini = datainiRSNHR;
tempoini = tempoiniRSNHR;
ARRAYdateAL = ARRAYdateRSNHR;
elseif yesLL == 1
dataini = datainiLL;
tempoini = tempoiniLL;
ARRAYdateAL = ARRAYdateLL;
end
[ListaDate,~] = size(ARRAYdateAL);
val_AL = zeros(ListaDate,rA);
StoricoAllarmi = zeros(ListaDate,rA);
dateCheck = [date ' ' time];
if dataini < datenum(dateCheck)
dataini = date;
tempoini = time;
else
dataini = datestr(dataini,'yyyy-mm-dd HH:MM:SS');
end
%% QUI ANDRA' INSERITO IL CRITERIO DI ATTIVAZIONE DELL'ALLARME
% Criterio di attivazione dell'allarme
%-------------------------------------
if SirenON == 1
val_AL(end,:) = 1; % Da mettere a posto!
% Criterio di attivazione dell'SMS
AL = 1;
DATAinsert = cell(1,5);
Data = datestr(ARRAYdateAL(end,1),'yyyy-mm-dd HH:MM:SS');
for ii = 1:rA % numero di allarmi
if val_AL(end,ii) == 1 && ARRAYdateAL(end,1) > alarms(ii,end)
desc = strjoin(alarms(ii,5),alarms(ii,6),'ON');
DATAinsert{AL,1} = 6; % Sirena e lampeggiante
DATAinsert{AL,2} = alarms(ii,2); % ID del CT
DATAinsert{AL,3} = Data; % Data & ora
DATAinsert{AL,4} = 1; % SMS
DATAinsert{AL,5} = desc; % Codice da inviare
allarme = 1;
AL = AL+1;
end
end
if allarme == 1
AL = AL-1; % Numero totale di allarmi
for a = 1:AL
% Cerco se il dato è già presente
Data = DATAinsert{a,3};
type = num2str(DATAinsert{a,1}); % tipologia
IDtool = num2str(DATAinsert{a,2}); % ID del CT
desc = DATAinsert{a,5}; % Descrizione
comando = ['select id from alarms where tool_name = ''' IDtool ''' and date_time = ''' ...
Data ''' and type_id = ''' type ''' and description like ''' desc ''' order by date_time'];
curs = exec(conn,comando);
curs = fetch(curs);
idDate = curs.Data;
if cell2mat(idDate) == 0
idElabData = 0; % 0 indica che il dato non è presente su DB
else
idElabData = cell2mat(idDate);
end
tablename = 'alarms';
colnames = {'type_id','tool_name','date_time','send_sms','description'};
data = [DATAinsert(a,1),DATAinsert(a,2),DATAinsert(a,3),DATAinsert(a,4),DATAinsert(a,5)];
if idElabData == 0 % Scrivo
fastinsert(conn,tablename,colnames,data);
text = ['ALERT was written in the DB by Siren function for date: ''' Data ''' '];
else % Aggiorno
whereclause = ['WHERE tool_name = ''' DATAinsert{a,2} ''' and date_time = ''' DATAinsert{a,3} ...
''' and type_id = ''' type ''' and description like ''' desc ''' '];
update(conn,tablename,colnames,data,whereclause)
text = ['ALERT was updated in the DB by Siren function for date: ''' Data ''' '];
end
fprintf(fileID,fmt,text);
end
end
end
Control = 1;
while Control == 1
for nn = 1:rA
% Scarico i dati storici di attivazione dell'allarme
comando = ['select EventDate, EventTime, X from ELABDATACTRL where EventDate = ''' ...
dataini ''' and EventTime >= ''' tempoini ''' and CtrlToolName = '''...
char(alarms(nn,2)) ''' and NodeNum = 1 '];
curs = exec(conn,comando);
curs = fetch(curs);
AlarmTot_1 = curs.Data; % numero cumulato di attivazioni prima della lettura in elaborazione
comando = ['select EventDate, EventTime, X from ELABDATACTRL where EventDate > ''' ...
dataini ''' and CtrlToolName = ''' char(alarms(nn,2)) ''' and NodeNum = 1 '];
curs = exec(conn,comando);
curs = fetch(curs);
AlarmTot_2 = curs.Data; % numero cumulato di attivazioni prima della lettura in elaborazione
[r1,c1] = size(AlarmTot_1);
[r2,c2] = size(AlarmTot_2);
if r1 == 1 && c1 == 1
if r2 == 1 && c2 == 1
if dataini < datenum(dateCheck)
AlarmTot(1,1) = cellstr(date);
AlarmTot(1,2) = cellstr(time);
AlarmTot(1,3) = cell;
Control = 0;
else
dataini = dataini-1;
break
end
else
AlarmTot = AlarmTot_2;
Control = 0;
end
else
Control = 0;
if r2 == 1 && c2 == 1
AlarmTot = AlarmTot_1;
else
AlarmTot = [AlarmTot_1; AlarmTot_2];
end
end
[rA,~] = size(AlarmTot);
Data = [cell2mat(AlarmTot(:,1)) repmat(' ', [rA,1]) cell2mat(AlarmTot(:,2))];
Data = datenum(Data);
Var = find(Data < datenum(ARRAYdateAL(1,1)));
if isempty(Var) == 1
StoricoAllarmi(:,nn) = cumsum(val_AL);
else
StoricoAllarmi(:,nn) = cumsum(val_AL)+cell2mat(AlarmTot(Var(end),3));
end
DATAinsert = cell(ListaDate,6);
% Creo i dati da scrivere
for ii=1:ListaDate
DATAinsert{ii,1} = alarms(nn,2);
DATAinsert{ii,2} = datestr(ARRAYdateAL(ii),'yyyy-mm-dd');
DATAinsert{ii,3} = datestr(ARRAYdateAL(ii),'HH:MM:SS');
DATAinsert{ii,4} = val_AL(ii,nn);
DATAinsert{ii,5} = StoricoAllarmi(ii,nn);
DATAinsert{ii,6} = 1;
end
idElabData = zeros(ListaDate,1); % Contiene gli id delle date delle quali ho già dati
cc = 1; % contatore
% Cerco su DB se i dati sono da aggiornare o scrivere
for ii = 1:ListaDate
dString = datestr(ARRAYdateAL(ii),'yyyy-mm-dd');
tString = datestr(ARRAYdateAL(ii),'HH:MM:SS');
comando = ['select idElabDataCtrl from ELABDATACTRL where CtrlToolName = '''...
char(alarms(nn,2)) ''' and NodeNum = 1 and EventDate = ''' ...
dString ''' and EventTime = ''' tString ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
idDate = curs.Data;
if strcmp(idDate,'No Data')
idElabData(cc,1) = 0; % 0 indica che il dato non è presente su DB
else
idElabData(cc,1) = cell2mat(idDate);
end
cc = cc+1;
% Scrivo o Aggiorno i dati
idData = idElabData(ii,1);
tablename = 'ELABDATACTRL';
if idData == 0 % Se la data non è su DB (=0), scrivo i dati
colnames = {'CtrlToolName','EventDate','EventTime','XShift','X','NodeNum',};
data = [DATAinsert(ii,1),DATAinsert(ii,2),DATAinsert(ii,3),...
DATAinsert(ii,4),DATAinsert(ii,5),DATAinsert(ii,6)];
fastinsert(conn,tablename,colnames,data);
else % altrimenti li aggiorno
colnames = {'XShift','X'};
data = [DATAinsert(ii,4),DATAinsert(ii,5)];
whereclause = ['WHERE CtrlToolName = ''' char(alarms(nn,2)) ...
''' and NodeNum = 1 and EventDate = ''' cell2mat(DATAinsert(ii,2))...
''' and EventTime = ''' cell2mat(DATAinsert(ii,3)) ''' '];
update(conn,tablename,colnames,data,whereclause)
end
end
text = ['Data of Control Tools ' char(alarms(nn,2)) ' uploaded in the DB correctly'];
fprintf(fileID,fmt,text);
end
end
end
text = 'Siren function executed correctly';
fprintf(fileID,fmt,text);
fclose(fileID);
end

60
RSN/Site_Info.m Executable file
View File

@@ -0,0 +1,60 @@
function [unitID,chainID,Chain_Scheme,num_nodi,alarms] = Site_Info(siteID,conn,FileName)
text = 'Site_Info function started';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
% Scarico tutte le centraline presenti in sito
comando = ['select id, name from units where site_id = ''' siteID ''' order by name']; % il rapporto centralina sito è di 1 a 1
curs = exec(conn,comando);
curs = fetch(curs);
unitID = curs.Data;
col = size(unitID);
chainID = cell(1,4);
ini = 1;
for c = 1:col(1,1)
% dalle centraline presenti, risalgo alle catene disponibili
comando = ['select id, name from tools where unit_id = ''' num2str(cell2mat(unitID(c,1))) ''' order by name'];
curs = exec(conn,comando);
curs = fetch(curs);
chainID_down = curs.Data; % id tool, nome tool
[fin,~] = size(chainID_down);
fin = fin+ini-1;
chainID(ini:fin,3:4) = chainID_down;
for j = ini:fin
chainID(j,1:2) = unitID(c,1:2); % Id centralina, nome centralina, id tool, nome tool
end
ini = fin+1;
end
% Scarico gli schemi delle catene
[col,~] = size(chainID); % Numero di Array
Chain_Scheme = cell(1,3);
num_nodi = zeros(col,1);
ini = 1;
cont = 1;
for c = 1:col(1,1)
comando = ['select nodetype_id, depth, num from nodes where tool_id = ''' num2str(cell2mat(chainID(c,3))) ''' order by num'];
curs = exec(conn,comando);
curs = fetch(curs);
scheme_down = curs.Data; % id nodo, profondità, numero
[fin,~] = size(scheme_down);
num_nodi(cont) = fin;
Chain_Scheme(1:fin,ini:ini+2) = scheme_down;
ini = ini+3;
cont = cont+1;
end
% Scarico l'allarme relativo al sito
comando = ['select id, name, ctrltype_id, alarm_phone, conn_usr, conn_pwd, duedate from ctrltools where site_id = ''' siteID ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
alarms = curs.Data;
text = 'Site_Info function worked correctly';
fprintf(fileID,fmt,text);
fclose(fileID);
end

837
RSN/Triggercheck.m Executable file
View File

@@ -0,0 +1,837 @@
function [sogliaRSN,trigRSN,sogliaHR,trigHR,sogliaLL,trigLL,tipomail_MOD,...
codice_mail,codice_SMS,MATsoglie,DT_BPM] = Triggercheck...
(IDcentralina,DTcatena,conn,ARRAYdateTrL,TrigMod,i,j,date,FileName)
%% Individuo i moduli associati al Trigger
%scrivo nel logfile
text = 'Funzione Triggercheck per il controllo delle soglie di trend inizializzata';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
DT_BPM=TrigMod(:,j); %indice j --> numero trigger
%% Scarico i dati del Trigger Link
data_rif = ARRAYdateTrL(i,1)-7; %7--> n° giorni su cui calcolare il trend
if data_rif > datenum(date)
data = datestr(data_rif,'yyyy-mm-dd');
else
data = date;
end
NodeNum = num2str(j);
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
data ''' and ToolNameID = ''' DTcatena ''' and UnitName = ''' IDcentralina ...
''' and NodeNum = ''' NodeNum ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Dati = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,~] = size(Dati);
T = [cell2mat(Dati(:,1)) repmat(' ', [rD,1]) cell2mat(Dati(:,2))];
DateTrigger = datenum(T);
dataindex = find(DateTrigger(:,1) == ARRAYdateTrL(i,1));
DataRifTRIGGER = DateTrigger(dataindex-1); % ultima data PRIMA dell'attivazione del trigger
% Scarico i dati di attivazione del Trigger
comando = ['select Xshift from ElabDataView where EventDate >= ''' ...
data ''' and ToolNameID = ''' DTcatena ''' and UnitName = ''' IDcentralina ...
''' and NodeNum = ''' NodeNum ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DatiTrigger = cell2mat(curs.Data);
%% scarico dati per calcolo trend e confronto soglie
%inizializzo variabili
[rBPM,~]=size(DT_BPM);
sogliaRSN = zeros(rBPM,1); %soglie disattivate
sogliaHR = zeros(rBPM,1);
sogliaLL = zeros(rBPM,1);
tipomail_MOD = zeros(rBPM,1); %tipo di mail da inviare
tipomail_RSN = zeros(rBPM,1); %stato singoli sensori
tipomail_HR = zeros(rBPM,1);
tipomail_LL = zeros(rBPM,1);
codice_SMS = 0; %livello di allerta SMS
trigRSN(1:rBPM,1) = 99999; %valore "neutro" di incremento
trigHR(1:rBPM,1) = 99999;
trigLL(1:rBPM,1) = 99999;
for n=1:rBPM
if isempty(DT_BPM{n}) == 0 % ho un modulo BPM da elaborare
DTmodulo = char(DT_BPM(n));
AlfaX_RSN = []; % matrici di dati (azzerate per evitare problemi di dimensioni tra array)
AlfaX_HR = [];
DatiCella = [];
%scrivo nel logfile
text = ['Inizio confronto soglia di trend per modulo ' DTmodulo ''];
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
%% A partire dal nome della catena, risalgo all'identificativo con cui è
% definita nel Database (mi serve successivamente)
comando = ['select id from units where name = ''' IDcentralina ''' '];
unitID = num2str(cell2mat(fetch(conn,comando)));
comando = ['select id from tools where name = ''' DTmodulo ''' and unit_id = ''' unitID ''' '];
idTool = num2str(cell2mat(fetch(conn,comando))); % leggo e converto in stringa
%% Determino sensori per ciascun modulo RSN
comando = ['select nodetype_id, num from nodes where tool_id = ''' idTool ''' order by num'];
modulo = fetch(conn,comando);
usoRSN = find(cell2mat(modulo(:,1)) == 38); % controllo presenza di RSN Link
usoRSNHR = find(cell2mat(modulo(:,1)) == 39); % controllo presenza di RSNHR Link
usoLOAD = find(cell2mat(modulo(:,1)) == 15); % controllo presenza di Load Link
% RSN Link
if isempty(usoRSN)== 0
data_rif = ARRAYdateTrL(i,1)-7; %7--> n° giorni su cui calcolare il trend
if data_rif > datenum(date)
data = datestr(data_rif,'yyyy-mm-dd');
else
data = date;
end
NodeNum = num2str(cell2mat(modulo(usoRSN,2)));
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ...
''' and NodeNum = ''' NodeNum ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Dati = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,~] = size(Dati);
T = [cell2mat(Dati(:,1)) repmat(' ', [rD,1]) cell2mat(Dati(:,2))];
DateRSN = datenum(T);
indexRSN = find(DateRSN(:,1)<=DateTrigger(dataindex));
LastDataRSN = DateRSN(indexRSN(end));
% Scarico i dati X
comando = ['select AlfaX from ElabDataView where EventDate >= ''' ...
data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ...
''' and NodeNum = ''' NodeNum ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
AlfaX_RSN(:,1) = cell2mat(curs.Data);
% Scarico i dati calcerr
comando = ['select calcerr from ElabDataView where EventDate >= ''' ...
data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ...
''' and NodeNum = ''' NodeNum ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
AlfaX_RSN(:,2) = cell2mat(curs.Data);
%scrivo nel logfile
text = 'Dati elaborati scaricati per RSN Link';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end
% RSNHR Link
if isempty(usoRSNHR)== 0
data_rif = ARRAYdateTrL(i,1)-7; %7--> n° giorni su cui calcolare il trend
if data_rif > datenum(date)
data = datestr(data_rif,'yyyy-mm-dd');
else
data = date;
end
NodeNum = num2str(cell2mat(modulo(usoRSNHR,2)));
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ...
''' and NodeNum = ''' NodeNum ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Dati = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,~] = size(Dati);
T = [cell2mat(Dati(:,1)) repmat(' ', [rD,1]) cell2mat(Dati(:,2))];
DateHR = datenum(T);
indexHR = find(DateHR(:,1)<=DateTrigger(dataindex));
LastDataHR = DateHR(indexHR(end));
% Scarico i dati X
comando = ['select AlfaX from ElabDataView where EventDate >= ''' ...
data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ...
''' and NodeNum = ''' NodeNum ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
AlfaX_HR(:,1) = cell2mat(curs.Data);
% Scarico i dati calcerr
comando = ['select calcerr from ElabDataView where EventDate >= ''' ...
data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ...
''' and NodeNum = ''' NodeNum ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
AlfaX_HR(:,2) = cell2mat(curs.Data);
%scrivo nel logfile
text = 'Dati elaborati scaricati per RSNHR Link';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end
% Load Link
if isempty(usoLOAD)== 0
data_rif = ARRAYdateTrL(i,1)-7; %7--> n° giorni su cui calcolare il trend
if data_rif > datenum(date)
data = datestr(data_rif,'yyyy-mm-dd');
else
data = date;
end
NodeNum = num2str(cell2mat(modulo(usoLOAD,2)));
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ...
''' and NodeNum = ''' NodeNum ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Dati = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,~] = size(Dati);
T = [cell2mat(Dati(:,1)) repmat(' ', [rD,1]) cell2mat(Dati(:,2))];
DateLL = datenum(T);
indexLL = find(DateLL(:,1)<=DateTrigger(dataindex));
LastDataLOAD = DateLL(indexLL(end));
% Scarico i dati di carico
comando = ['select load_value from ElabDataView where EventDate >= ''' ...
data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ...
''' and NodeNum = ''' NodeNum ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DatiCella(:,1) = cell2mat(curs.Data);
% Scarico i dati calcerr
comando = ['select calcerr from ElabDataView where EventDate >= ''' ...
data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ...
''' and NodeNum = ''' NodeNum ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
DatiCella(:,2) = cell2mat(curs.Data);
%scrivo nel logfile
text = 'Dati elaborati scaricati per Load Link';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end
%% Rimuovo le letture dei moduli eseguite all'attivazione di un Trigger,
% non necessarie per il calcolo del trend
rT = dataindex; %contatore dati
MatRSN = AlfaX_RSN;
MatRSNHR = AlfaX_HR;
MatLOAD = DatiCella;
%creo nuovi indici da aggiornare per "seguire" la dimensione della
%matrice su cui calcolare il trend
indextrendRSN = indexRSN(end);
indextrendHR = indexHR(end);
indextrendLL = indexLL(end);
del = 0;
for k=1:rT
if DatiTrigger(k,1)>=1
del = del + 1 ;
if isempty(usoRSN)== 0
indextrendRSN = indextrendRSN - 1;
precedRSN = find(DateRSN(:,1) <= DateTrigger(k,1));
MatRSN(precedRSN(end),:) = [];
DateRSN(precedRSN(end),:) = [];
end
if isempty(usoRSNHR)== 0
indextrendHR = indextrendHR - 1;
precedRSNHR = find(DateHR(:,1) <= DateTrigger(k,1));
MatRSNHR(precedRSNHR(end),:)=[];
DateHR(precedRSNHR(end),:) = [];
end
if isempty(usoLOAD)== 0
indextrendLL = indextrendLL - 1;
precedLL = find(DateLL(:,1) <= DateTrigger(k,1));
MatLOAD(precedLL(end),:)=[];
DateLL(precedLL(end),:)=[];
end
end
end
%scrivo nel logfile
text = ['Creazione matrice di trend: Rimosse ' num2str(del) ' letture relative al modulo ' DTmodulo ''];
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
%% Calcolo il trend di ciascun sensore presente nel modulo
if isempty(usoRSN)== 0
nRSN = indextrendRSN;
toterrRSN = sum(MatRSN(1:indextrendRSN,2));
if toterrRSN/nRSN > 0.5 % dati insufficienti a calcolare un trend significativo
trendRSN=99999;
else
trendRSN = mean(diff(MatRSN(1:indextrendRSN,1)));
end
end
if isempty(usoRSNHR)== 0
nRSNHR = indextrendHR;
toterrRSNHR = sum(MatRSNHR(1:indextrendHR,2));
if toterrRSNHR/nRSNHR > 0.5 % dati insufficienti a calcolare un trend significativo
trendHR=99999;
else
trendHR = mean(diff(MatRSNHR(1:indextrendHR,1)));
end
end
if isempty(usoLOAD)== 0
nLL = indextrendLL;
toterrLL = sum(MatLOAD(1:indextrendLL,2));
if toterrLL/nLL > 0.5 % dati insufficienti a calcolare un trend significativo
trendLL=99999;
else
trendLL = mean(diff(MatLOAD(1:indextrendLL,1)));
end
end
%scrivo nel logfile
text = ['Trend calcolati per il modulo ' DTmodulo ''];
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
%% Controllo che il modulo BPM sia già stato elaborato, altrimenti forzo
% la funzione RSN per quel modulo in modo da avere l'ultimo dato elaborato
% RSN Link
%scrivo nel logfile
text = 'Inizio controllo soglie di trend per RSN';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
nuovidati = 0;
incRSN=1;
if isempty(usoRSN)== 0
if LastDataRSN >= DataRifTRIGGER
if AlfaX_RSN(indexRSN(end),2)==0 %lettura valida, calcolo incremento
valRSN = AlfaX_RSN(indexRSN(end),1);
trigRSN(n,1) = valRSN - AlfaX_RSN(indexRSN(end-1),1); %incremento allo scatto del trigger
%scrivo nel logfile
text = 'Confronto con soglia di trend RSN - nessun ricalcolo eseguito, incremento calcolato';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
elseif AlfaX_RSN(indexRSN(end),2)==1 && AlfaX_RSN(indexRSN(end-1),2)==0 %la lettura precedente NON è in errore, allarme
sogliaRSN(n,1)=1;
incRSN=0;
tipomail_RSN(n,1)=0.33;
%scrivo nel logfile
text = 'Confronto con soglia di trend RSN - nessun ricalcolo eseguito, incremento NON calcolato/allarme per lettura precedente NON errore';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
elseif AlfaX_RSN(indexRSN(end),2)==1 && AlfaX_RSN(indexRSN(end-1),2)==1 %letture in errore, trigger disattivato
sogliaRSN(n,1)=0;
incRSN=0;
%scrivo nel logfile
text = 'Confronto con soglia di trend RSN - nessun ricalcolo eseguito, incremento NON calcolato/modulo in errore';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end
else
rilancio = ['/usr/local/matlab_func/run_RSN_lnx.sh /usr/local/MATLAB/MATLAB_Runtime/v93 '...
IDcentralina ' ' DTmodulo ''];
status = system(rilancio); %forzo RSN
nuovidati = 1; %ultimi dati elaborati disponibili per tutti i sensori successivi
%scrivo nel logfile
text = 'Confronto con soglia di trend RSN - il software e'''' stato rilanciato!';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
data_rif = ARRAYdateTrL(i-1,1);
if data_rif > datenum(date)
data = datestr(data_rif,'yyyy-mm-dd');
else
data = date;
end
NodeNum = num2str(cell2mat(modulo(usoRSN,2)));
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ...
''' and NodeNum = ''' NodeNum ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Dati = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,~] = size(Dati);
T = [cell2mat(Dati(:,1)) repmat(' ', [rD,1]) cell2mat(Dati(:,2))];
Date = datenum(T);
indexRSN = indexRSN +1; % la data del Trigger è quella aggiunta dalla rielaborazione
% Scarico i dati X
comando = ['select AlfaX from ElabDataView where EventDate >= ''' ...
data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ...
''' and NodeNum = ''' NodeNum ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
valRSN = cell2mat(curs.Data); %valore post attivazione Trigger
valRSN = valRSN(indexRSN(end));
% Scarico i dati calcerr
comando = ['select calcerr from ElabDataView where EventDate >= ''' ...
data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ...
''' and NodeNum = ''' NodeNum ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
erroreRSN = cell2mat(curs.Data); %lettura valida-0 o in errore-1
erroreRSN = erroreRSN(indexRSN(end));
if erroreRSN ==0 %lettura valida, calcolo incremento
trigRSN(n,1) = valRSN - AlfaX_RSN(indexRSN(end),1); %incremento allo scatto del trigger
%scrivo nel logfile
text = 'Confronto con soglia di trend RSN - ricalcolo eseguito, incremento calcolato';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
elseif erroreRSN==1 && AlfaX_RSN(indexRSN(end),2)==0 %la lettura precedente NON è in errore, allarme
sogliaRSN(n,1)=1;
incRSN=0;
tipomail_RSN(n,1)=0.33;
%scrivo nel logfile
text = 'Confronto con soglia di trend RSN - ricalcolo eseguito, incremento NON calcolato/allarme per lettura precedente NON errore';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
elseif erroreRSN==1 && AlfaX_RSN(indexRSN(end),2)==1 %letture in errore, trigger disattivato
sogliaRSN(n,1)=0;
incRSN=0;
%scrivo nel logfile
text = 'Confronto con soglia di trend RSN - ricalcolo eseguito, incremento NON calcolato/modulo in errore';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end
end
if incRSN==1 && trendRSN ~= 99999 %devo calcolare un incremento
if abs(trigRSN(n,1))/abs(trendRSN) >= 1.3 %SOGLIA DI TREND SUPERATA!
sogliaRSN(n,1) = 1;
tipomail_RSN(n,1)=1;
%scrivo nel logfile
text = 'Soglia di trend per RSN Link superata!';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
else
sogliaRSN(n,1) = 0;
%scrivo nel logfile
text = 'Soglia di trend per RSN Link non superata!';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end
end
else
trigRSN(n,1)=99999; %manca il sensore RSN oppure dati insufficienti per calcolare trend
%scrivo nel logfile
text = 'RSN assente o dati insufficienti: impossibile calcolare la soglia di trend per RSN';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end
% RSNHR Link
%scrivo nel logfile
text = 'Inizio controllo soglie di trend per RSNHR';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
incHR=1;
if isempty(usoRSNHR)== 0
if LastDataHR >= DataRifTRIGGER
if AlfaX_HR(indexHR(end),2)==0 %lettura valida, calcolo incremento
valHR = AlfaX_HR(indexHR(end),1);
trigHR(n,1) = valHR - AlfaX_HR(indexHR(end-1),1); %incremento allo scatto del trigger
%scrivo nel logfile
text = 'Confronto con soglia di trend RSNHR - nessun ricalcolo eseguito, incremento calcolato';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
elseif AlfaX_HR(indexHR(end),2)==1 && AlfaX_HR(indexHR(end-1),2)==0 %la lettura precedente NON è in errore, allarme
sogliaHR(n,1)=1;
incHR=0;
tipomail_HR(n,1)=0.33;
%scrivo nel logfile
text = 'Confronto con soglia di trend RSNHR - nessun ricalcolo eseguito, incremento NON calcolato/allarme per lettura precedente NON errore';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
elseif AlfaX_HR(indexHR(end),2)==1 && AlfaX_HR(indexHR(end-1),2)==1 %letture in errore, trigger disattivato
sogliaHR(n,1)=0;
incHR=0;
%scrivo nel logfile
text = 'Confronto con soglia di trend RSNHR - nessun ricalcolo eseguito, incremento NON calcolato/modulo in errore';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end
else
if nuovidati == 0 %nessun sensore ha già forzato RSN
rilancio = ['/usr/local/matlab_func/run_RSN_lnx.sh /usr/local/MATLAB/MATLAB_Runtime/v93 '...
IDcentralina ' ' DTmodulo ''];
status = system(rilancio); %forzo RSN
nuovidati = 1;
%scrivo nel logfile
text = 'Confronto con soglia di trend RSN HR - il software e'''' stato rilanciato';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end
data_rif = ARRAYdateTrL(i-1,1);
if data_rif > datenum(date)
data = datestr(data_rif,'yyyy-mm-dd');
else
data = date;
end
NodeNum = num2str(cell2mat(modulo(usoRSNHR,2)));
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ...
''' and NodeNum = ''' NodeNum ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Dati = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,~] = size(Dati);
T = [cell2mat(Dati(:,1)) repmat(' ', [rD,1]) cell2mat(Dati(:,2))];
Date = datenum(T);
indexHR = indexHR + 1; % la data del Trigger è quella aggiunta dalla rielaborazione
% Scarico i dati X
comando = ['select AlfaX from ElabDataView where EventDate >= ''' ...
data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ...
''' and NodeNum = ''' NodeNum ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
valHR = cell2mat(curs.Data); %valore post attivazione Trigger
valHR = valHR(indexHR(end));
% Scarico i dati calcerr
comando = ['select calcerr from ElabDataView where EventDate >= ''' ...
data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ...
''' and NodeNum = ''' NodeNum ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
erroreHR = cell2mat(curs.Data);
erroreHR = erroreHR(indexHR(end));
if erroreHR ==0 %lettura valida, calcolo incremento
trigHR(n,1) = valHR - AlfaX_HR(indexHR(end),1); %incremento allo scatto del trigger
%scrivo nel logfile
text = 'Confronto con soglia di trend RSNHR - ricalcolo eseguito, incremento calcolato';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
elseif erroreHR==1 && AlfaX_HR(indexHR(end),2)==0 %la lettura precedente NON è in errore, allarme
sogliaHR(n,1)=1;
incHR=0;
tipomail_HR(n,1)=0.33;
%scrivo nel logfile
text = 'Confronto con soglia di trend RSNHR - ricalcolo eseguito, incremento NON calcolato/allarme per lettura precedente NON errore';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
elseif erroreHR==1 && AlfaX_HR(indexHR(end),2)==1 %letture in errore, trigger disattivato
sogliaRSN(n,1)=0;
incHR=0;
%scrivo nel logfile
text = 'Confronto con soglia di trend RSNHR - ricalcolo eseguito, incremento NON calcolato/trigger in errore';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end
end
if incHR==1 && trendHR ~= 99999
if abs(trigHR(n,1))/abs(trendHR) >= 1.3 %SOGLIA DI TREND SUPERATA!
sogliaHR(n,1) = 1;
tipomail_HR(n,1)=1;
%scrivo nel logfile
text = 'Soglia di trend per RSNHR Link superata!';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
else
sogliaHR(n,1) = 0;
%scrivo nel logfile
text = 'Soglia di trend per RSNHR Link non superata!';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end
end
else
trigHR(n,1)=99999; %manca il sensore RSN HR oppure dati insufficienti per calcolare trend
%scrivo nel logfile
text = 'RSNHR assente, letture in errore o dati insufficienti: impossibile calcolare la soglia di trend per RSNHR';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end
% Load Link
%scrivo nel logfile
text = 'Inizio controllo soglie di trend per LL';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
incLL=1;
if isempty(usoLOAD)== 0
if LastDataLOAD >= DataRifTRIGGER
if DatiCella(indexLL(end),2)==0 %lettura valida, calcolo incremento
valLL = DatiCella(indexLL(end),1);
trigLL(n,1) = valLL - DatiCella(indexLL(end-1),1); %incremento allo scatto del trigger
%scrivo nel logfile
text = 'Confronto con soglia di trend LL - nessun ricalcolo eseguito, incremento calcolato';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
elseif DatiCella(indexLL(end),2)==1 && DatiCella(indexLL(end-1),2)==0 %la lettura precedente NON è in errore, allarme
sogliaLL(n,1)=1;
incLL=0;
tipomail_LL(n,1)=0.33;
%scrivo nel logfile
text = 'Confronto con soglia di trend LL - nessun ricalcolo eseguito, incremento NON calcolato/allarme per lettura precedente NON errore';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
elseif DatiCella(indexLL(end),2)==1 && DatiCella(indexLL(end-1),2)==1 %la misura precedente è in errore, trigger disattivato
sogliaLL(n,1)=0;
incLL=0;
%scrivo nel logfile
text = 'Confronto con soglia di trend LL - nessun ricalcolo eseguito, incremento NON calcolato/trigger in errore';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end
else
if nuovidati == 0 %nessun sensore ha già forzato RSN
rilancio = ['/usr/local/matlab_func/run_RSN_lnx.sh /usr/local/MATLAB/MATLAB_Runtime/v93 '...
IDcentralina ' ' DTmodulo ''];
status = system(rilancio); %forzo RSN
nuovidati = 1;
%scrivo nel logfile
text = 'Confronto con soglia di trend LL - il software e'''' stato rilanciato';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end
data_rif = ARRAYdateTrL(i-1,1);
if data_rif > datenum(date)
data = datestr(data_rif,'yyyy-mm-dd');
else
data = date;
end
NodeNum = num2str(cell2mat(modulo(usoLOAD,2)));
comando = ['select EventDate, EventTime from ElabDataView where EventDate >= ''' ...
data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ...
''' and NodeNum = ''' NodeNum ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Dati = curs.Data;
% Modifico il formato di data e ora in DATini.
[rD,~] = size(Dati);
T = [cell2mat(Dati(:,1)) repmat(' ', [rD,1]) cell2mat(Dati(:,2))];
Date = datenum(T);
indexLL = indexLL + 1; % la lettura del Trigger è quella aggiunta dalla rielaborazione
comando = ['select load_value from ElabDataView where EventDate >= ''' ...
data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ...
''' and NodeNum = ''' NodeNum ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
valLL = cell2mat(curs.Data); %valore post attivazione Trigger
valLL = valLL(indexLL(end));
% Scarico i dati calcerr
comando = ['select calcerr from ElabDataView where EventDate >= ''' ...
data ''' and ToolNameID = ''' DTmodulo ''' and UnitName = ''' IDcentralina ...
''' and NodeNum = ''' NodeNum ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
erroreLL = cell2mat(curs.Data);
erroreLL = erroreLL(indexLL(end));
if erroreLL==0 %lettura valida, calcolo incremento
trigLL(n,1) = valLL - DatiCella(indexLL(end),1); %incremento allo scatto del trigger
%scrivo nel logfile
text = 'Confronto con soglia di trend LL - ricalcolo eseguito, incremento calcolato';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
elseif erroreLL==1 && DatiCella(indexLL(end),2)==0 %la lettura precedente NON è in errore, allarme
sogliaLL(n,1)=1;
incLL=0;
tipomail_LL(n,1)=0.33;
%scrivo nel logfile
text = 'Confronto con soglia di trend LL - ricalcolo eseguito, incremento NON calcolato/allarme per lettura precedente NON errore';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
elseif erroreLL==1 && DatiCella(indexLL(end),2)==1 %la misura precedente è in errore, trigger disattivato
sogliaLL(n,1)=0;
incLL=0;
%scrivo nel logfile
text = 'Confronto con soglia di trend LL - ricalcolo eseguito, incremento NON calcolato/trigger in errore';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end
end
if incLL==1 && trendLL ~= 99999
if abs(trigLL(n,1))/abs(trendLL) >= 1.3 %SOGLIA DI TREND SUPERATA!
sogliaLL(n,1) = 1;
tipomail_LL(n,1)=1;
%scrivo nel logfile
text = 'Soglia di trend per Load Link superata!';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
else
sogliaLL(n,1) = 0;
%scrivo nel logfile
text = 'Soglia di trend per Load Link non superata!';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end
end
else
trigLL(n,1)=99999; %manca il sensore LL oppure dati insufficienti per calcolare trend
%scrivo nel logfile
text = 'LL assente, letture in errore o dati insufficienti: impossibile calcolare la soglia di trend per LL';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end
soglie_modulo = [tipomail_RSN(n,1) tipomail_HR(n,1) tipomail_LL(n,1)];
MATsoglie = [];
if sum(soglie_modulo) == 0 || sum(soglie_modulo) == 1
tipomail_MOD(n,1) = 0;
elseif sum(soglie_modulo) > 0 && sum(soglie_modulo) < 2
tipomail_MOD(n,1) = 0.5;
elseif sum(soglie_modulo) >= 2
tipomail_MOD(n,1) = 1;
end
%scrivo nel logfile
text = ['Codice di invio mail definito per modulo ' DTmodulo ''];
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end
end
codice_mail = max(tipomail_MOD); %LIVELLO DI ALLERTAMENTO PER L'INVIO MAIL
%scrivo nel logfile
text = 'Funzione Triggercheck per il controllo delle soglie di trend eseguita correttamente';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);

308
RSN/Users_Def.m Executable file
View File

@@ -0,0 +1,308 @@
function [Mail,Users_Alert,Users_SMS,Users_Report,activeIT,activeEN,...
sms,siteID,NomeSito,ini_CoV] = Users_Def(IDcentralina,conn,FileName)
text = 'Users function started';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
% A partire dalla centralina, risalgo al site ID
comando = ['select site_id from units where name like ''' IDcentralina ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
siteID = num2str(cell2mat(curs.Data));
% --- Cerco gli utenti ---
% - Definisco gli Users
% A partire dal site ID, risalgo al company ID
comando = ['select company_id, name, lat, lon, alarm_email from sites where id like ''' siteID ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Site = curs.Data;
Company_id = num2str(cell2mat(Site(1,1)));
Email_Alarm_Site = Site(1,5);
NomeSito = Site(1,2);
% A partire dal company ID, mi scarico le info relative a Send Email Alarm
comando = ['select send_alarm from companies where id like ''' Company_id ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Mail = cell2mat(curs.Data);
if Mail == 1 % Significa che invio Mail alla Company del Sito
% La Mail la mando SOLO alla mail indicata nel campo del Sito (per quanto riguarda la company cliente)
if isempty(cell2mat(Email_Alarm_Site)) == 0
if strcmp(char(Email_Alarm_Site),'null') == 0
US = Email_Alarm_Site;
check = cell2mat(strfind(US,','));
if isempty(check)==1
% A partire dal company ID, risalgo agli utenti e alla loro mail di
% quella company che sono admin
comando = ['select fname, lname, language_id, info, phone, sms_alarm, report, report_cov, '...
'allertamento from users where email like '''...
char(US) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Info = curs.Data; % Cerco la lingua dell'unico destinatario
[~,cC] = size(Info);
if cC > 1
Users = Info(1:2);
Users(3) = US;
Users(4:5) = Info(3:4);
Users(6) = Info(5);
Users(7:10) = Info(6:9);
else
Users = [];
end
else
[~,cC] = size(check);
Users = cell(cC+1,6);
u = 1;
ini = 1;
for i=1:cC+1
utente = char(US);
% A partire dal company ID, risalgo agli utenti e alla loro mail di
% quella company che sono admin
if i == cC+1
comando = ['select fname, lname, language_id, info, phone, sms_alarm, report, report_cov, '...
'allertamento, email from users where email like ''' utente(ini:end) ''' '];
else
comando = ['select fname, lname, language_id, info, phone, sms_alarm, report, report_cov, '...
'allertamento, email from users where email like ''' utente(ini:check(i)-1) ''' '];
end
curs = exec(conn,comando);
curs = fetch(curs);
Info = curs.Data; % Cerco la lingua dell'unico destinatario
[~,cI] = size(Info);
if cI ~= 1
Users(u,1:2) = Info(1:2);
Users(u,3) = Info(10);
Users(u,4:5) = Info(3:4);
Users(u,6) = Info(5);
Users(u,7:10) = Info(6:9);
u = u+1;
end
if i ~= cC+1
ini = check(i)+1;
end
end
Users = Users(1:u-1,:);
end
else
% Company Manager
Role = ' 2 ';
% A partire dal company ID, risalgo agli utenti e alla loro mail di
% quella company che sono admin
comando = ['select fname, lname, email, language_id, info, phone, sms_alarm, report, report_cov, '...
'allertamento from users where company_id like ''' Company_id ''' and role_id = ''' Role ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Users = curs.Data;
end
else
% Company Manager
Role = ' 2 ';
% A partire dal company ID, risalgo agli utenti e alla loro mail di
% quella company che sono admin
comando = ['select fname, lname, email, language_id, info, phone, sms_alarm, report, report_cov, '...
'allertamento from users where company_id like ''' Company_id ''' and role_id = ''' Role ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Users = curs.Data;
end
else
Users = [];
end
% Elimino gli utenti che non possono essere allertati
[rU,cU] = size(Users);
al = 1;
sms = 1;
rpt = 1;
Users_Alert = cell(1,1);
Users_SMS = cell(1,1);
Users_Report = cell(1,1);
if cU > 1
for u = 1:rU
if cell2mat(Users(u,10)) == 1
[rUA,cUA] = size(Users_Alert);
if rUA == 1 && cUA == 1
clear Users_Alert
end
Users_Alert(al,:) = Users(u,:);
al = al+1;
if cell2mat(Users(u,7)) == 1
[rUA,cUA] = size(Users_SMS);
if rUA == 1 && cUA == 1
clear Users_SMS
end
Users_SMS(sms,:) = Users(u,:);
sms = sms+1;
end
end
if cell2mat(Users(u,8)) == 1
[rUA,cUA] = size(Users_Report);
if rUA == 1 && cUA == 1
clear Users_Report
end
Users_Report(rpt,:) = Users(u,:);
rpt = rpt+1;
end
end
end
ini_CoV = al;
% Cerco se allertare o meno i Cone of Visions
comando = ['select conn_path from units where name like ''' IDcentralina ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Auth = curs.Data; % Se pari a 1 autorizzo i Cone of Visions, altrimenti no
if strcmp(char(Auth),'Yes')
Mail = 1;
% Cone of vision
% A partire dal site ID, risalgo al USER ID degli utenti nel
% cone-of-vision per quel sito
comando = ['select user_id from coneofvisions where site_id like ''' siteID ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
CoV = cell2mat(curs.Data);
% A partire dal USER ID, risalgo agli utenti e alla loro email se sono company manager
[rC, ~] = size(CoV);
if strcmp(char(CoV(1,:)),'No Data') % almeno un utente da cercare nel database
Users_CoV = [];
else
ii = 1;
for i=1:rC
Utente = num2str(CoV(i,1));
Role = ' 2 ';
comando = ['select fname, lname, email, language_id, info, phone, sms_alarm, report, report_cov, '...
'allertamento from users where id = ''' Utente ''' and role_id = ''' Role ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
UC = curs.Data;
[~,cUC] = size(UC);
if cUC ~= 1
Users_CoV(ii,:) = UC;
ii = ii+1;
end
end
end
[rUC,cUC] = size(Users_CoV);
[rUA,cUA] = size(Users_Alert);
if cUC > 1
for u = 1:rUC
if cell2mat(Users_CoV(u,10)) == 1 && cell2mat(Users_CoV(u,9)) == 1
salta = 0;
for cov = 1:rUA
if cUA > 1
A = strfind(char(Users_CoV(u,3)),char(Users_Alert(cov,3)));
if A == 1
salta = 1;
break
end
end
end
if salta == 0
if cUA > 1
Users_Alert(al,:) = Users_CoV(u,:);
else
Users_Alert = Users_CoV(u,:);
end
al = al+1;
if cell2mat(Users_CoV(u,7)) == 1
Users_SMS(sms,:) = Users_CoV(u,:);
sms = sms+1;
end
end
end
if cell2mat(Users_CoV(u,9)) == 1
salta = 0;
for cov = 1:rUA
if cUA > 1
A = strfind(char(Users_CoV(u,3)),char(Users_Alert(cov,3)));
if A == 1
salta = 1;
break
end
end
end
if salta == 0
[rUA,cUA] = size(Users_Report);
if rUA == 1 && cUA == 1
clear Users_Report
end
Users_Report(rpt,:) = Users_CoV(u,:);
rpt = rpt+1;
end
end
end
end
else
Users_CoV = [];
end
[rU,cU] = size(Users);
[rC,cC] = size(Users_CoV);
if cC > 1 && rC > 0 && cU > 1 % comando ha trovato informazioni e le ha scritte in Users
Users(rU+1:rU+rC,1:10) = Users_CoV;
elseif cC > 1 && rC > 0 && cU == 0
Users = Users_CoV;
end
[rU,~] = size(Users);
if rU == 0
Mail = 0;
end
% Controllo che la centralina non sia scaduta
comando = ['select duedate from units where name = ''' IDcentralina ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Date = curs.Data;
Check = cell2mat(Date);
if strcmp(Check,'null') || strcmp(Check,'No Data')
% La data di scadenza centralina non è impostata
sms = 1;
else
if datenum(Date) < now % Centralina scaduta
sms = 0;
Users_Alert = [];
Users_SMS = [];
Users_Report = [];
else
sms = 1;
end
end
% A chi mando la mail
activeIT = 0;
activeEN = 0;
[~,c1] = size(Users_Alert);
[~,c2] = size(Users_Report);
if c1 == 1 && c2 == 1
Users_Lang = [];
elseif c1 == 1
Users_Lang = Users_Report;
elseif c2 == 1
Users_Lang = Users_Alert;
else
Users_Lang = [Users_Alert; Users_Report];
end
[rU,cU] = size(Users_Lang);
if cU >1 % sono presenti utenti a cui inviare la mail
for i = 1:rU
if Users_Lang{i,4} == 2
activeIT = 1;
else
activeEN = 1;
end
end
end
text = 'Users function worked correctly';
fprintf(fileID,fmt,text);
fclose(fileID);
end

82
RSN/YesNo.m Executable file
View File

@@ -0,0 +1,82 @@
%% funzione che attiva/disattiva l'elaborazione per una determinata tipologia di nodo
% Ad esempio se la matrice RSN Link è vuota i RSN Link non sono presenti
% e si scrive yesRSN = 0, altrimenti se ci sono dei dati, yesRSN = 1 e ne
% viene attivata l'elaborazione nelle fasi successive
function [yesRSN,yesRSNHR,yesSS,yesLL,yesTrL,yesGF,yesGS,yesDL,rRSN,rRSNHR,...
rLL,rTrL,rSS,rDL] = YesNo(NodoRSNLink,NodoRSNLinkHR,NodoSS,NodoLoadLink,...
NodoTriggerLink,NodoGflowLink,NodoGshockLink,NodoDebrisLink,FileName)
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'YesNo function started';
fprintf(fileID,fmt,text);
%% RSN Link
[rRSN,cRSN] = size(NodoRSNLink);
if rRSN == 0 && cRSN == 0
yesRSN = 0; % Non elaboro i RSN Link
else
yesRSN = 1; % attiva l'elaborazione dei RSN Link
end
%% RSN Link HR
[rRSNHR,cRSNHR] = size(NodoRSNLinkHR);
if rRSNHR == 0 && cRSNHR == 0
yesRSNHR = 0; % Non elaboro i RSN Link HR
else
yesRSNHR = 1; % attiva l'elaborazione dei RSN Link HR
end
%% Load Link
[rLL,cLL] = size(NodoLoadLink);
if rLL == 0 && cLL == 0
yesLL = 0; % Non elaboro i Load Link
else
yesLL = 1; % attiva l'elaborazione dei Load Link
end
%% Trigger Link
[rTrL,cTrL] = size(NodoTriggerLink);
if rTrL == 0 && cTrL == 0
yesTrL = 0; % Non elaboro i Trigger Link
else
yesTrL = 1; % attiva l'elaborazione dei Trigger Link
end
%% Shock Sensor
[rSS,cSS] = size(NodoSS);
if rSS==0 && cSS==0
yesSS = 0; % Non elaboro
else
yesSS = 1; % attiva l'elaborazione
end
%% G-Flow Link
[rGF,cGF] = size(NodoGflowLink);
if rGF == 0 && cGF == 0
yesGF = 0; % Non elaboro
else
yesGF = 1; % attiva l'elaborazione
end
%% G-Shock Link
[rGS,cGS] = size(NodoGshockLink);
if rGS == 0 && cGS == 0
yesGS = 0; % Non elaboro
else
yesGS = 1; % attiva l'elaborazione
end
%% Debris Link
[rDL,cDL] = size(NodoDebrisLink);
if rDL == 0 && cDL == 0
yesDL = 0; % Non elaboro
else
yesDL = 1; % attiva l'elaborazione
end
text = 'Activation parameters for the elaboration defined correctly, YesNo function closed';
fprintf(fileID,fmt,text);
fclose(fileID);
end

2176
RSN/alert_Levels.m Executable file

File diff suppressed because it is too large Load Diff

27
RSN/approx.m Executable file
View File

@@ -0,0 +1,27 @@
% Funzione che approssima il dato alla terza cifra decimale (millesimi di
% grado)
function [AlfaX,AlfaY,TempDef] = approx(AlfaX,AlfaY,TempDef,FileName)
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'approx function started';
fprintf(fileID,fmt,text);
conv = AlfaX*1000;
conv = round(conv);
AlfaX = conv/1000;
conv = AlfaY*1000;
conv = round(conv);
AlfaY = conv/1000;
conv = TempDef*10;
conv = round(conv);
TempDef = conv/10;
text = 'approx function executed correctly';
fprintf(fileID,fmt,text);
fclose(fileID);
end

27
RSN/approx_RSNHR.m Executable file
View File

@@ -0,0 +1,27 @@
% Funzione che approssima il dato alla quarta cifra decimale (decimo di
% millesimo di grado)
function [AlfaX_HR,AlfaY_HR,TempDef_RSNHR] = approx_RSNHR(AlfaX_HR,AlfaY_HR,...
TempDef_RSNHR,FileName)
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'approx_RSNHR function started';
fprintf(fileID,fmt,text);
conv = AlfaX_HR*10000;
conv = round(conv);
AlfaX_HR = conv/10000;
conv = AlfaY_HR*10000;
conv = round(conv);
AlfaY_HR = conv/10000;
conv = TempDef_RSNHR*10;
conv = round(conv);
TempDef_RSNHR = conv/10;
text = 'approx_RSNHR function executed correctly';
fprintf(fileID,fmt,text);
fclose(fileID);
end

61
RSN/azzeramenti.m Executable file
View File

@@ -0,0 +1,61 @@
%% Funzione che corregge gli angoli di alcuni nodi specifici
function angRSN = azzeramenti(conn,IDcentralina,DTcatena,angRSN,NodoRSNLink,ARRAYdateRSN,FileName)
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'azzeramenti function started';
fprintf(fileID,fmt,text);
NomeFile = strcat(IDcentralina,'-',DTcatena,'-','Azzeramenti.txt');
if isfile(NomeFile) == 1
Dati = importdata(NomeFile);
if Dati(1,1) == 99999
else
[c,~] = size(Dati);
i = 1;
while i <= c
if Dati(i,1) == 99999
break
else
NodeType ='RSN Link';
indice = Dati(i);
NodeNumRSN = num2str(cell2mat(NodoRSNLink(indice,2)));
dataRIF = num2str(ARRAYdateRSN(end)-7);
comando = ['select AlfaX, AlfaY from ElabDataView where EventDate >= ''' ...
dataRIF ''' and UnitName = ''' IDcentralina ...
''' and ToolNameID = ''' DTcatena ''' and NodeType = ''' NodeType ...
''' and NodeNum =' NodeNumRSN ' '];
curs = exec(conn,comando);
curs = fetch(curs);
Riferimento = curs.Data;
angRSN(:,2*indice-1:2*indice) = Riferimento(end,1:2);
text = ['Node RSN Link number ' NodeNumRSN ' has been corrected by azzeramenti function'];
fprintf(fileID,fmt,text);
i=i+1;
end
end
end
else
fclose(fileID);
Parametro1 = 99999;
Parametro2 = 999999999;
outdat = fopen(NomeFile,'wt+');
fopen(NomeFile,'wt');
fmt = '%d \r';
fileA = fopen(NomeFile,'a');
fprintf(fileA,fmt,Parametro1);
fprintf(fileA,fmt,Parametro2);
fclose(fileA);
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'azzeramenti function created the reference file correctly';
fprintf(fileID,fmt,text);
end
text = 'azzeramenti function executed correctly';
fprintf(fileID,fmt,text);
fclose(fileID);
end

68
RSN/azzeramenti_RSNHR.m Executable file
View File

@@ -0,0 +1,68 @@
%% Funzione che mette a zero gli spostamenti di alcuni nodi specifici
function angRSNHR = azzeramenti_RSNHR(conn,IDcentralina,DTcatena,angRSNHR,...
NodoRSNLinkHR,ARRAYdateRSNHR,FileName)
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'azzeramenti_RSNHR function started';
fprintf(fileID,fmt,text);
NomeFile = strcat(IDcentralina,'-',DTcatena,'-','Azzeramenti.txt');
if isfile(NomeFile) == 1
Dati = importdata(NomeFile);
i = 1;
while Dati(i,1) ~= 99999
i = i+1; % cerco il dato corrispondente al MEMS, il successivo è
% quello dell'ampolla corrispondente
end
i = i+1;
if Dati(i,1) == 999999999
else
[c,~] = size(Dati);
while i <= c
if Dati(i,1) == 999999999
break
else
NodeType ='RSN Link HR';
indice = Dati(i);
NodeNumRSNHR = num2str(cell2mat(NodoRSNLinkHR(indice,2)));
dataRIF = num2str(ARRAYdateRSNHR(end)-7);
comando = ['select AlfaX, AlfaY from ElabDataView where EventDate >= ''' ...
dataRIF ''' and UnitName = ''' IDcentralina ...
''' and ToolNameID = ''' DTcatena ''' and NodeType = ''' NodeType ...
''' and NodeNum =' NodeNumRSNHR ' '];
curs = exec(conn,comando);
curs = fetch(curs);
Riferimento = curs.Data;
angRSNHR(:,2*indice-1:2*indice) = Riferimento(end,1:2);
text = ['Node RSN Link HR number ' NodeNumRSNHR ' has been corrected by azzeramenti function'];
fprintf(fileID,fmt,text);
i=i+1;
end
end
end
else
fclose(fileID);
Parametro1 = 99999;
Parametro2 = 999999999;
outdat = fopen(NomeFile,'wt+');
fopen(NomeFile,'wt');
fmt = '%d \r';
fileA = fopen(NomeFile,'a');
fprintf(fileA,fmt,Parametro1);
fprintf(fileA,fmt,Parametro2);
fclose(fileA);
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'azzeramenti function created the reference file correctly';
fprintf(fileID,fmt,text);
end
text = 'azzeramenti_RSNHR function executed correctly';
fprintf(fileID,fmt,text);
fclose(fileID);
end

21
RSN/cancellaDB.m Executable file
View File

@@ -0,0 +1,21 @@
function cancellaDB(IDcentralina,DTcatena,Data_scarico,FileName,conn)
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'cancellaDB function started';
fprintf(fileID,fmt,text);
comando = ['delete from ELABDATADISP where UnitName = ''' IDcentralina...
''' and ToolNameID = ''' DTcatena ''' and EventDate >= ''' Data_scarico ''' '];
curs = exec(conn,comando);
text = strcat('Elaborated Data of Unit ', IDcentralina, ' Chain ',...
DTcatena,' deleted starting from date ',Data_scarico,' during the execution of LastElab function.');
fprintf(fileID,fmt,text);
text = 'cancellaDB function ended';
fprintf(fileID,fmt,text);
fclose(fileID);
end

16
RSN/cellMakerLL.m Executable file
View File

@@ -0,0 +1,16 @@
function DATAinsert = cellMakerLL(IDcentralina,DTcatena,NodeNum,cLL,ListaDate,ARRAYdateLL,LoadDef,ErrLoadLink)
l = ListaDate;
DATAinsert = cell(l,7);
for ii=1:l
DATAinsert{ii,1} = IDcentralina;
DATAinsert{ii,2} = DTcatena;
DATAinsert{ii,3} = NodeNum;
DATAinsert{ii,4} = datestr(ARRAYdateLL(ii),'yyyy-mm-dd');
DATAinsert{ii,5} = datestr(ARRAYdateLL(ii),'HH:MM:SS');
DATAinsert{ii,6} = LoadDef(ii,cLL);
DATAinsert{ii,7} = ErrLoadLink(ii,cLL);
end
end

21
RSN/cellMakerRSN.m Executable file
View File

@@ -0,0 +1,21 @@
function DATAinsert = cellMakerRSN(IDcentralina,DTcatena,NodeNum,cRSN,ListaDate,...
ErrRSNLink,ARRAYdateRSN,AlfaX,AlfaY,TempDef_RSN)
AlfaX=AlfaX';
AlfaY=AlfaY';
TempDef_RSN = TempDef_RSN';
l = ListaDate;
DATAinsert = cell(l,9);
for ii=1:l
DATAinsert{ii,1} = IDcentralina;
DATAinsert{ii,2} = DTcatena;
DATAinsert{ii,3} = NodeNum;
DATAinsert{ii,4} = datestr(ARRAYdateRSN(ii),'yyyy-mm-dd');
DATAinsert{ii,5} = datestr(ARRAYdateRSN(ii),'HH:MM:SS');
DATAinsert{ii,6} = AlfaX(cRSN,ii);
DATAinsert{ii,7} = AlfaY(cRSN,ii);
DATAinsert{ii,8} = TempDef_RSN(cRSN,ii);
DATAinsert{ii,9} = ErrRSNLink(cRSN,ii);
end
end

22
RSN/cellMakerRSNHR.m Executable file
View File

@@ -0,0 +1,22 @@
function DATAinsert = cellMakerRSNHR(IDcentralina,DTcatena,NodeNum,cRSNHR,ListaDate,...
ErrRSNLinkHR,ARRAYdateRSNHR,AlfaX_HR,AlfaY_HR,TempDef_RSNHR)
AlfaX_HR=AlfaX_HR';
AlfaY_HR=AlfaY_HR';
TempDef_RSNHR = TempDef_RSNHR';
l = ListaDate;
DATAinsert = cell(l,9);
for ii=1:l
DATAinsert{ii,1} = IDcentralina;
DATAinsert{ii,2} = DTcatena;
DATAinsert{ii,3} = NodeNum;
DATAinsert{ii,4} = datestr(ARRAYdateRSNHR(ii),'yyyy-mm-dd');
DATAinsert{ii,5} = datestr(ARRAYdateRSNHR(ii),'HH:MM:SS');
DATAinsert{ii,6} = AlfaX_HR(cRSNHR,ii);
DATAinsert{ii,7} = AlfaY_HR(cRSNHR,ii);
DATAinsert{ii,8} = TempDef_RSNHR(cRSNHR,ii);
DATAinsert{ii,9} = ErrRSNLinkHR(cRSNHR,ii);
end
end

18
RSN/cellMakerSS.m Executable file
View File

@@ -0,0 +1,18 @@
function DATAinsert = cellMakerSS(DTcatena,IDcentralina,NodeNum,ListaDate,...
ARRAYdateSS,val_SS,StoricoShock,cSS,ErrShockSensor)
l = ListaDate;
DATAinsert = cell(l,8);
for ii=1:l
DATAinsert{ii,1} = IDcentralina;
DATAinsert{ii,2} = DTcatena;
DATAinsert{ii,3} = NodeNum;
DATAinsert{ii,4} = datestr(ARRAYdateSS(ii),'yyyy-mm-dd');
DATAinsert{ii,5} = datestr(ARRAYdateSS(ii),'HH:MM:SS');
DATAinsert{ii,6} = val_SS(ii,cSS);
DATAinsert{ii,7} = StoricoShock(ii,cSS);
DATAinsert{ii,8} = ErrShockSensor(ii,cSS);
end
end

18
RSN/cellMakerTrL.m Executable file
View File

@@ -0,0 +1,18 @@
function DATAinsert = cellMakerTrL(DTcatena,IDcentralina,NodeNum,ListaDate,...
ARRAYdateTrL,val_TrL,StoricoTrigger,cTrL,ErrTriggerLink)
l = ListaDate;
DATAinsert = cell(l,8);
for ii=1:l
DATAinsert{ii,1} = IDcentralina;
DATAinsert{ii,2} = DTcatena;
DATAinsert{ii,3} = NodeNum;
DATAinsert{ii,4} = datestr(ARRAYdateTrL(ii),'yyyy-mm-dd');
DATAinsert{ii,5} = datestr(ARRAYdateTrL(ii),'HH:MM:SS');
DATAinsert{ii,6} = val_TrL(ii,cTrL);
DATAinsert{ii,7} = StoricoTrigger(ii,cTrL);
DATAinsert{ii,8} = ErrTriggerLink(ii,cTrL);
end
end

40
RSN/centralina.m Executable file
View File

@@ -0,0 +1,40 @@
function Unit = centralina(IDcentralina,conn,FileName)
text = 'centralina function started';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
comando = ['select type_id from units where name = ''' IDcentralina ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Type = cell2mat(curs.Data);
if Type == 1
Unit = 'G801';
elseif Type == 2
Unit = 'G802';
elseif Type == 3
Unit = 'G201';
elseif Type == 4
Unit = 'G301';
elseif Type == 5
Unit = 'D2W';
elseif Type == 6
Unit = 'GFLOW';
elseif Type == 7
Unit = 'Nesa';
elseif Type == 8
Unit = 'MUSA';
elseif Type == 9
Unit = 'Nesa evolution';
elseif Type == 10
Unit = 'CRX1000';
elseif Type == 11
Unit = 'LoRa 12 V';
elseif Type == 12
Unit = 'LoRa 6 V';
end
text = 'centralina function executed correctly';
fprintf(fileID,fmt,text);
fclose(fileID);

138
RSN/checkBattery.m Executable file
View File

@@ -0,0 +1,138 @@
function checkBattery(Batteria,Batteria_LoRa,IDcentralina,Unit,Mail,conn,FileName)
text = 'checkBattery function started';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
if strcmp(Unit,'G801') == 1 || strcmp(Unit,'G802') == 1 || strcmp(Unit,'G201') == 1 ...
|| strcmp(Unit,'G301') == 1 % G801, G802, G201, G301
Batt = 12;
Threshold = 11;
Dato = cellstr('12 V');
elseif strcmp(Unit,'D2W') == 1
Batt = 6;
Threshold = 5.6;
Dato = cellstr('6 V');
elseif strcmp(Unit,'Nesa') == 1
Batt = 3.4;
Threshold = 3;
Dato = cellstr('3.4 V');
elseif strcmp(Unit,'Nesa evolution') == 1
Batt = 12.2;
Threshold = 11.8;
Dato = cellstr('12.2 V');
elseif strcmp(Unit,'CRX1000') == 1
Batt = 12;
Threshold = 10;
Dato = cellstr('12 V');
end
FileNameBattery = strcat(IDcentralina,'-Batteria.txt');
if isfile(FileNameBattery) == 0 % NON Esiste
outdat = fopen(FileNameBattery,'wt+');
fileID_site = fopen(FileNameBattery,'a');
fmt = '%f \r';
fprintf(fileID_site,fmt,Batt);
fmt = '%.10f \r';
text = now;
fprintf(fileID_site,fmt,text);
fclose(fileID_site);
end
% Scarico dati di riferimento
FileNameBattery = ['' IDcentralina '-Batteria.txt'];
Dati = importdata(FileNameBattery);
[rA,~] = size(Dati);
if rA == 0
Livello_Rif = 0;
Data_Rif = 0;
elseif rA == 1
Livello_Rif = Dati(1,1);
Data_Rif = 0;
else
Livello_Rif = Dati(1,1);
Data_Rif = Dati(2,1);
end
if strcmp(Unit,'Nesa evolution') == 1
Level = str2double(cell2mat(Batteria(end,2)));
else
Level = cell2mat(Batteria(end,3));
end
activate = 0;
if Level < Threshold
if now-Data_Rif > 1 || Level < Livello_Rif
Data_Rif = now;
activate = 1;
end
end
if activate == 0
Mail = 0;
end
if Mail == 1
DATAinsert = cell(1,6);
sms = 0;
desc = Dato;
if strcmp(Unit,'Nesa evolution') == 1
Data = datestr(datenum(Batteria(end,1)),'yyyy-mm-dd HH:MM:SS');
else
Data = datestr(strjoin([Batteria(end,1) Batteria(end,2)]),'yyyy-mm-dd HH:MM:SS');
end
Livello = cell2mat(Batteria(end,3));
DATAinsert{1,1} = 2; % Allarme tipologia batteria
DATAinsert{1,2} = IDcentralina;
DATAinsert{1,3} = Data;
DATAinsert{1,4} = Livello;
DATAinsert{1,5} = sms;
DATAinsert{1,6} = desc;
% Cerco se il dato è già presente
comando = ['select id, type_id, date_time from alarms where unit_name = ''' ...
IDcentralina ''' and date_time = ''' Data ''' and type_id = ''' DATAinsert{1,1} ...
''' and registered_value = ''' Livello ''' and description like ''' desc ''' order by date_time'];
curs = exec(conn,comando);
curs = fetch(curs);
idDate = curs.Data;
[~,cI] = size(idDate);
if cI == 1
idElabData = 0; % 0 indica che il dato non è presente su DB
else
idElabData = cell2mat(idDate(:,1));
end
tablename = 'alarms';
colnames = {'type_id','unit_name','date_time','battery_level','send_sms','description'};
data = [DATAinsert(1,1),DATAinsert(1,2),DATAinsert(1,3),DATAinsert(1,4),...
DATAinsert(1,5),DATAinsert(1,6)];
if idElabData == 0 % Scrivo
fastinsert(conn,tablename,colnames,data);
text = ['ALERT was written in the DB by checkBattery function for date: ''' Data ''' '];
end
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end
outdat = fopen(FileNameBattery,'wt+');
fileID_site = fopen(FileNameBattery,'a');
text_B = cell2mat(Batteria(end,3));
fmt = '%f \r';
fprintf(fileID_site,fmt,text_B);
fmt = '%.10f \r';
text = Data_Rif;
fprintf(fileID_site,fmt,text);
fclose(fileID_site);
text = 'checkBattery function worked correctly';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end

117
RSN/checkGIS.m Executable file
View File

@@ -0,0 +1,117 @@
function checkGIS(siteID,NomeSito,conn,FileName)
text = 'checkGIS function started';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
comando = ['select gis_enable, gis_duedate from sites where id like ''' siteID ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
GIS = curs.Data;
if cell2mat(GIS(1)) == 1 % GIS attivato
if strcmp(char(GIS(2)),'null') == 0
FileNameGIS = ['GIS' siteID '-Deadline.txt'];
if isfile(FileNameGIS) == 0 % NON Esiste
outdat = fopen(FileNameGIS,'wt+');
fileID_site = fopen(FileNameGIS,'a');
text = now;
fmt = '%f \r';
fprintf(fileID_site,fmt,text);
fclose(fileID_site);
end
% Scarico dati di riferimento
Data_Rif = importdata(FileNameGIS);
[rA,~] = size(Data_Rif);
if rA == 0
Data_Rif = 0;
end
% Controllo la data di scadenza del GIS
G = cell2mat(GIS(2));
[lS] = length(G);
date = G(1:10);
time = G(12:lS);
Date = [date ' ' time];
Info = 0;
if now <= datenum(Date) && datenum(Date) < now+30 % fra 1 giorno e 1 Mese
if datenum(Data_Rif) > datenum(Date)-30
mail = 0; % la mail è già stata inviata
else
mail = 1;
end
elseif now > datenum(Date) && datenum(Data_Rif) < datenum(Date) % GIS scaduto
mail = 1;
Info = 1;
desc = 'Scaduto';
else
mail = 0;
end
if mail == 1
DATAinsert = cell(1,5);
sms = 0;
Data = datestr(now,'yyyy-mm-dd HH:MM:SS');
DATAinsert{1,1} = 8; % Allarme scadenza GIS
DATAinsert{1,2} = cellstr(['GIS|' char(NomeSito)]);
DATAinsert{1,3} = Data;
DATAinsert{1,4} = sms;
if Info == 1
DATAinsert{1,5} = desc;
end
% Cerco se il dato è già presente
if Info == 1
comando = ['select id, type_id, date_time from alarms where tool_name = ''' ...
NomeSito ''' and date_time = ''' Data ''' and type_id = ''' DATAinsert{1,1} ...
''' and description like ''' desc ''' order by date_time'];
else
comando = ['select id, type_id, date_time from alarms where tool_name = ''' ...
NomeSito ''' and date_time = ''' Data ''' and type_id = ''' DATAinsert{1,1} ...
''' order by date_time'];
end
curs = exec(conn,comando);
curs = fetch(curs);
idDate = curs.Data;
[~,cI] = size(idDate);
if cI == 1
idElabData = 0; % 0 indica che il dato non è presente su DB
else
idElabData = cell2mat(idDate(:,1));
end
tablename = 'alarms';
if Info == 1
colnames = {'type_id','tool_name','date_time','send_sms','description'};
data = [DATAinsert(1,1),DATAinsert(1,2),DATAinsert(1,3),DATAinsert(1,4),DATAinsert(1,5)];
else
colnames = {'type_id','tool_name','date_time','send_sms'};
data = [DATAinsert(1,1),DATAinsert(1,2),DATAinsert(1,3),DATAinsert(1,4)];
end
if idElabData == 0 % Scrivo
fastinsert(conn,tablename,colnames,data);
text = ['ALERT was written in the DB by checkGIS function for date: ''' Data ''' '];
end
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end
outdat = fopen(FileNameGIS,'wt+');
fileID_site = fopen(FileNameGIS,'a');
text = now;
fmt = '%f \r';
fprintf(fileID_site,fmt,text);
fclose(fileID_site);
end
end
text = 'checkGIS function worked correctly';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end

124
RSN/checkSIM.m Executable file
View File

@@ -0,0 +1,124 @@
function checkSIM(IDcentralina,conn,FileName)
text = 'checkSIM function started';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
comando = ['select sim_card_id from units where name = ''' IDcentralina ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
sim_ID = cell2mat(curs.Data);
if isnan(sim_ID) == 0
if sim_ID ~= 0
comando = ['select name, duedate from sim_cards where id = ''' num2str(sim_ID) ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
SIM = curs.Data;
Nome = char(SIM(1));
FileNameSIM = ['' Nome '-Deadline.txt'];
if isfile(FileNameSIM) == 0 % NON Esiste
outdat = fopen(FileNameSIM,'wt+');
fileID_site = fopen(FileNameSIM,'a');
text = now;
fmt = '%f \r';
fprintf(fileID_site,fmt,text);
fclose(fileID_site);
end
% Scarico dati di riferimento
FileNameSIM = ['' IDcentralina '-Deadline.txt'];
Data_Rif = importdata(FileNameSIM);
[rA,~] = size(Data_Rif);
if rA == 0
Data_Rif = 0;
end
% Controllo la data di scadenza della SIM
Date = SIM(2);
Check = cell2mat(Date);
Info = 0;
if strcmp(Check,'null') == 1|| strcmp(Check,'No Data') == 1
else
if now <= datenum(Date) && datenum(Date) < now+30 % fra 1 giorno e 1 Mese
if datenum(Data_Rif) > datenum(Date)-30
mail = 0; % la mail è già stata inviata
else
mail = 1;
end
elseif now > datenum(Date) && datenum(Data_Rif) < datenum(Date) % sim scaduta
mail = 1;
Info = 1;
desc = 'Scaduto';
else
mail = 0;
end
if mail == 1
DATAinsert = cell(1,6);
sms = 0;
Data = datestr(now,'yyyy-mm-dd HH:MM:SS');
DATAinsert{1,1} = 7; % Allarme scadenza SIM
DATAinsert{1,2} = Nome;
DATAinsert{1,3} = Data;
DATAinsert{1,4} = sms;
if Info == 1
DATAinsert{1,5} = desc;
end
% Cerco se il dato è già presente
if Info == 1
comando = ['select id, type_id, date_time from alarms where tool_name = ''' ...
Nome ''' and date_time = ''' Data ''' and type_id = ''' DATAinsert{1,1} ...
''' and description like ''' desc ''' order by date_time'];
else
comando = ['select id, type_id, date_time from alarms where tool_name = ''' ...
Nome ''' and date_time = ''' Data ''' and type_id = ''' DATAinsert{1,1} ...
''' order by date_time'];
end
curs = exec(conn,comando);
curs = fetch(curs);
idDate = curs.Data;
[~,cI] = size(idDate);
if cI == 1
idElabData = 0; % 0 indica che il dato non è presente su DB
else
idElabData = cell2mat(idDate(:,1));
end
tablename = 'alarms';
if Info == 1
colnames = {'type_id','tool_name','date_time','send_sms','description'};
data = [DATAinsert(1,1),DATAinsert(1,2),DATAinsert(1,3),DATAinsert(1,4),DATAinsert(1,5)];
else
colnames = {'type_id','tool_name','date_time','send_sms'};
data = [DATAinsert(1,1),DATAinsert(1,2),DATAinsert(1,3),DATAinsert(1,4)];
end
if idElabData == 0 % Scrivo
fastinsert(conn,tablename,colnames,data);
text = ['ALERT was written in the DB by checkSIM function for date: ''' Data ''' '];
end
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end
outdat = fopen(FileNameSIM,'wt+');
fileID_site = fopen(FileNameSIM,'a');
text = now;
fmt = '%f \r';
fprintf(fileID_site,fmt,text);
fclose(fileID_site);
end
end
end
text = 'checkSIM function worked correctly';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end

112
RSN/checkUnit.m Executable file
View File

@@ -0,0 +1,112 @@
function checkUnit(IDcentralina,conn,FileName)
text = 'checkUnit function started';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
FileNameUnit = ['' IDcentralina '-Deadline.txt'];
if isfile(FileNameUnit) == 0 % NON Esiste
outdat = fopen(FileNameUnit,'wt+');
fileID_site = fopen(FileNameUnit,'a');
text = now;
fmt = '%f \r';
fprintf(fileID_site,fmt,text);
fclose(fileID_site);
end
% Scarico dati di riferimento
FileNameUnit = ['' IDcentralina '-Deadline.txt'];
Data_Rif = importdata(FileNameUnit);
[rA,~] = size(Data_Rif);
if rA == 0
Data_Rif = 0;
end
% Cerco la data di scadenza della centralina
comando = ['select duedate from units where name = ''' IDcentralina ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
Date = curs.Data;
Check = cell2mat(Date);
Info = 0;
if strcmp(Check,'null') == 1|| strcmp(Check,'No Data') == 1
else
if now <= datenum(Date) && datenum(Date) < now+30 % fra 1 giorno e 1 Mese
if datenum(Data_Rif) > datenum(Date)-30
mail = 0; % la mail è già stata inviata
else
mail = 1;
end
elseif now > datenum(Date) && datenum(Data_Rif) < datenum(Date) % centralina scaduta
mail = 1;
Info = 1;
desc = 'Scaduto';
else
mail = 0;
end
if mail == 1
DATAinsert = cell(1,6);
sms = 0;
Data = datestr(now,'yyyy-mm-dd HH:MM:SS');
DATAinsert{1,1} = 5; % Allarme scadenza centralina
DATAinsert{1,2} = IDcentralina;
DATAinsert{1,3} = Data;
DATAinsert{1,4} = sms;
if Info == 1
DATAinsert{1,5} = desc;
end
if Info == 1
comando = ['select id, type_id, date_time from alarms where unit_name = ''' ...
IDcentralina ''' and date_time = ''' Data ''' and type_id = ''' DATAinsert{1,1} ...
''' and description like ''' desc ''' order by date_time'];
else
comando = ['select id, type_id, date_time from alarms where unit_name = ''' ...
IDcentralina ''' and date_time = ''' Data ''' and type_id = ''' DATAinsert{1,1} ...
''' order by date_time'];
end
curs = exec(conn,comando);
curs = fetch(curs);
idDate = curs.Data;
[~,cI] = size(idDate);
if cI == 1
idElabData = 0; % 0 indica che il dato non è presente su DB
else
idElabData = cell2mat(idDate(:,1));
end
tablename = 'alarms';
if Info == 1
colnames = {'type_id','unit_name','date_time','send_sms','description'};
data = [DATAinsert(1,1),DATAinsert(1,2),DATAinsert(1,3),DATAinsert(1,4),DATAinsert(1,5)];
else
colnames = {'type_id','unit_name','date_time','send_sms'};
data = [DATAinsert(1,1),DATAinsert(1,2),DATAinsert(1,3),DATAinsert(1,4)];
end
if idElabData == 0 % Scrivo
fastinsert(conn,tablename,colnames,data);
text = ['ALERT was written in the DB by checkUnit function for date: ''' Data ''' '];
end
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end
outdat = fopen(FileNameUnit,'wt+');
fileID_site = fopen(FileNameUnit,'a');
text = now;
fmt = '%f \r';
fprintf(fileID_site,fmt,text);
fclose(fileID_site);
end
text = 'checkUnit function worked correctly';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end

61
RSN/checkdata.m Executable file
View File

@@ -0,0 +1,61 @@
function [DatiElabTriggerLink,DatiElabShockSensor,DatiElabDebrisLink] = checkdata(...
yesTrL,yesSS,yesDL,DatiElabTriggerLink,DatiElabShockSensor,DatiElabDebrisLink,...
datainiTrL,datainiSS,datainiDL,rTrL,rSS,rDL,tempoiniTrL,tempoiniSS,tempoiniDL,...
NodoTriggerLink,NodoShockSensor,NodoDebrisLink,NuovoZeroTrL,NuovoZeroSS,NuovoZeroDL,...
IDcentralina,DTcatena,conn,FileName)
text = 'checkdata function started';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
%% Trigger Link
if yesTrL == 1 % Trigger Link
if NuovoZeroTrL == 1
data1 = datenum([char(DatiElabTriggerLink(1,1)) ' ' char(DatiElabTriggerLink(1,2))]);
data2 = datenum([datainiTrL(1,1:10) ' ' tempoiniTrL]);
if data1 ~= data2 % devo riscaricare l'ultimo dato elaborato a partire da dataini
datainiTrL = datestr(data2,'yyyy-mm-dd');
tempoiniTrL = datestr(data2,'HH:MM:SS');
DatiElabTriggerLink = LastElab_bisTrL(conn,NodoTriggerLink,rTrL,...
datainiTrL,tempoiniTrL,IDcentralina,DTcatena,FileName);
end
end
end
%% Shock Sensor
if yesSS == 1 %
if NuovoZeroSS == 1
data1 = datenum([char(DatiElabShockSensor(1,1)) ' ' char(DatiElabShockSensor(1,2))]);
data2 = datenum([datainiSS(1,1:10) ' ' tempoiniSS]);
if data1 ~= data2 % devo riscaricare l'ultimo dato elaborato a partire da dataini
datainiSS = datestr(data2,'yyyy-mm-dd');
tempoiniSS = datestr(data2,'HH:MM:SS');
DatiElabShockSensor = LastElab_bisSS(conn,NodoShockSensor,rSS,datainiSS,...
tempoiniSS,IDcentralina,DTcatena,FileName);
end
end
end
%% Debris Link
if yesDL == 1 % Debris Link
if NuovoZeroDL == 1
data1 = datenum([char(DatiElabDebrisLink(1,1)) ' ' char(DatiElabDebrisLink(1,2))]);
data2 = datenum([datainiDL(1,1:10) ' ' tempoiniDL]);
if data1 ~= data2 % devo riscaricare l'ultimo dato elaborato a partire da dataini
datainiDL = datestr(data2,'yyyy-mm-dd');
tempoiniDL = datestr(data2,'HH:MM:SS');
DatiElabDebrisLink = LastElab_bisDL(conn,NodoDebrisLink,rDL,...
datainiDL,tempoiniDL,IDcentralina,DTcatena,FileName);
end
end
end
text = 'checkdata function worked correctly';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end

39
RSN/conv_grezziLL.m Executable file
View File

@@ -0,0 +1,39 @@
% Funzione che converte i dati ADC della cella di carico in dati di forza
% mediante i valori di calibrazione.
% Il risultato è la matrico DatiLoad
function DatiLoad = conv_grezziLL(ADCLoad,DCalLLTot,NodoLoadLink,FileName)
text = 'conv_grezziLL function started';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
if strcmp(NodoLoadLink(1,4),'mV/V') || strcmp(NodoLoadLink(1,4),'ADC')
caLoad = DCalLLTot(:,1);
intLoad = DCalLLTot(:,2);
elseif strcmp(NodoLoadLink(1,4),'4-20 mA')
a_Load = DCalLLTot(:,1);
b_Load = DCalLLTot(:,2);
c_Load = DCalLLTot(:,3);
end
%% Conversione dei punti ADC in dati di carico
[rL,cL] = size(ADCLoad);
DatiLoad = zeros(rL,cL);
for j=1:rL % date
for i=1:cL % nodi
if strcmp(NodoLoadLink(i,4),'mV/V') || strcmp(NodoLoadLink(i,4),'ADC')
DatiLoad(j,i) = caLoad(i,1)*ADCLoad(j,i) + intLoad(i,1); % conversione lineare
elseif strcmp(NodoLoadLink(i,4),'4-20 mA')
DatiLoad(j,i) = a_Load(i,1)*ADCLoad(j,i).^2 + b_Load(i,1)*ADCLoad(j,i) + c_Load(i,1); % conversione parabolica
end
end
end
text = 'Raw Data of Load Link converted into physycal units correctly. conv_grezziLL function closed';
fprintf(fileID,fmt,text);
fclose(fileID);
end

168
RSN/conv_grezziRSN.m Executable file
View File

@@ -0,0 +1,168 @@
% Funzione che converte i dati grezzi in dati di accelerazione usando i
% valori delle calibrazioni per i RSN Link
% accRSN raccoglie le accelerazioni
function [accRSN,ris_acc,tempRSN] = conv_grezziRSN(rRSN,accRSN,...
tempRSN,DCalRSNTot,MEMS,FileName)
text = 'conv_grezziRSN function started';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
if MEMS == 2 % RSN Link 1.0
gainX = DCalRSNTot(:,1);
caX = DCalRSNTot(:,2);
intX = DCalRSNTot(:,3);
caASSX = DCalRSNTot(:,4);
intASSX = DCalRSNTot(:,5);
gainY = DCalRSNTot(:,6);
caY = DCalRSNTot(:,7);
intY = DCalRSNTot(:,8);
caASSY = DCalRSNTot(:,9);
intASSY = DCalRSNTot(:,10);
gainZ = DCalRSNTot(:,11);
caZ = DCalRSNTot(:,12);
intZ = DCalRSNTot(:,13);
% caASSZ = DCalRSNTot(:,14); --> non necessari
% intASSZ = DCalRSNTot(:,15); --> non necessari
caT = DCalRSNTot(:,16);
intT = DCalRSNTot(:,17);
[righeREL,~] = size(accRSN);
angREL_RSN = zeros(righeREL,rRSN*2);
%% Accelerometri
cont = 1;
cn = 1;
% Contatore dei nodi, corregge le accelerazioni con le calibrazioni
for ii=1:3*rRSN
if cont==1
accRSN(:,ii) = accRSN(:,ii)*gainX(cn)+(tempRSN(:,cn)*caX(cn)+intX(cn));
cont = cont+1;
elseif cont==2
accRSN(:,ii) = accRSN(:,ii)*gainY(cn)+(tempRSN(:,cn)*caY(cn)+intY(cn));
cont = cont+1;
else
accRSN(:,ii) = accRSN(:,ii)*gainZ(cn)+(tempRSN(:,cn)*caZ(cn)+intZ(cn));
cont = 1;
cn = cn+1;
end
end
% Calcolo e correggo angoli relativi in base al segno dell'asse Z
cont = 1;
contACC = 1;
for ii=1:3*rRSN
if cont==1 % X
angREL_RSN(:,contACC) = real(asind(accRSN(:,ii))); %calcolo angolo relativo
if angREL_RSN(:,contACC)>0 %check quando angolo relativo > 0
if accRSN(:,ii+2)<0 % check quando asse z < 0 --> il montante si è capovolto!
angREL_RSN(:,contACC) = 180 - angREL_RSN(:,contACC);
end
elseif angREL_RSN(:,ii)<0 %check quando angolo relativo < 0
if accRSN(:,ii+2)<0 % check quando asse z < 0 --> il montante si è capovolto!
angREL_RSN(:,contACC) = -180 - angREL_RSN(:,contACC);
end
end
cont = cont+1;
contACC = contACC+1;
elseif cont==2 % Y
angREL_RSN(:,contACC) = real(asind(accRSN(:,ii))); %calcolo angolo relativo
if angREL_RSN(:,contACC)>0 %check quando angolo relativo > 0
if accRSN(:,ii+1)<0 % check quando asse z < 0 --> il montante si è capovolto!
angREL_RSN(:,contACC) = 180 - angREL_RSN(:,contACC);
end
elseif angREL_RSN(:,ii)<0 %check quando angolo relativo < 0
if accRSN(:,ii+1)<0 % check quando asse z < 0 --> il montante si è capovolto!
angREL_RSN(:,contACC) = -180 - angREL_RSN(:,contACC);
end
end
cont = cont+1;
contACC = contACC+1;
else
cont = 1;
end
end
% Calcolo angoli assoluti
cont = 1;
cn = 1;
for ii=1:2*rRSN
if cont==1
accRSN(:,ii) = angREL_RSN(:,ii)*caASSX(cn)+intASSX(cn);
cont = cont+1;
elseif cont==2
accRSN(:,ii) = angREL_RSN(:,ii)*caASSY(cn)+intASSY(cn);
cont = cont+1;
else
cont = 1;
cn = cn+1;
end
end
%% Conversione delle temperature
[rT,~] = size(tempRSN);
T_RSN = zeros(rT,1);
for t = 1:rRSN
T_RSN(:,t) = tempRSN(:,t)*caT(t,1) + intT(t,1);
end
%% Risultanti
[rAcc,cAcc] = size(accRSN);
ris_acc = zeros(rAcc,cAcc/3); % matrice risultante accelerazioni
clear i
clear ii
clear cont
clear cn
cont = 1; % contatore
cn = 0;
n = 1;
%% Calcolo della risultante
for ii = 1:cAcc % colonne
if n == 4
n = 1;
end
for i = 1:rAcc % righe
ris_acc(i,cont) = (accRSN(i,cn*3+1)^2+accRSN(i,cn*3+2)^2+accRSN(i,cn*3+3)^2)^0.5;
end
if n == 3
cn = cn+1;
cont = cont+1;
end
n = n+1;
end
elseif MEMS == 3 % Murata
%% Risultanti
[rAcc,cAcc] = size(accRSN);
ris_acc = zeros(rAcc,cAcc/3); % matrice risultante accelerazioni
cont = 1; % contatore
cn = 0;
n = 1;
%% Calcolo della risultante
for ii = 1:cAcc % colonne
if n == 4
n = 1;
end
for i = 1:rAcc % righe
ris_acc(i,cont) = (sind(accRSN(i,cn*3+1))^2+sind(accRSN(i,cn*3+2))^2+sind(accRSN(i,cn*3+3))^2)^0.5;
end
if n == 3
cn = cn+1;
cont = cont+1;
end
n = n+1;
end
else
ris_acc = [];
end
text = 'Raw Data of RSN Link converted into physycal units correctly. conv_grezziRSN function ended';
fprintf(fileID,fmt,text);
fclose(fileID);
end

47
RSN/conv_grezziRSNHR.m Executable file
View File

@@ -0,0 +1,47 @@
% Funzione che converte i dati grezzi del RSN Link HR in dati di
% angoli (acc_RSNHR)
function [angRSNHR,T_RSNHR] = conv_grezziRSNHR(angRSNHR,tempRSNHR,DCalRSNHRTot,rRSNHR,FileName)
text = 'conv_grezziRSNHR function started';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
caX_RSNHR = DCalRSNHRTot(:,1);
intX_RSNHR = DCalRSNHRTot(:,2);
caY_RSNHR = DCalRSNHRTot(:,3);
intY_RSNHR = DCalRSNHRTot(:,4);
caT_RSNHR = DCalRSNHRTot(:,5);
intT_RSNHR = DCalRSNHRTot(:,6);
cont = 1;
cn = 1;
% Contatore dei nodi, converte i punti ADC con le calibrazioni in valori
% angolari
for ii=1:2*rRSNHR
if cont==1
angRSNHR(:,ii) = angRSNHR(:,ii)*caX_RSNHR(cn)+ intX_RSNHR(cn);
cont = cont+1;
elseif cont==2
angRSNHR(:,ii) = angRSNHR(:,ii)*caY_RSNHR(cn)+ intY_RSNHR(cn);
cont = cont+1;
else
cont = 1;
cn = cn+1;
end
end
%% Conversione delle temperature
[rT,~] = size(tempRSNHR);
T_RSNHR = zeros(rT,1);
for t = 1:rRSNHR
T_RSNHR(:,t) = tempRSNHR(:,t)*caT_RSNHR(t,1) + intT_RSNHR(t,1);
end
text = 'Raw Data of RSN Link HR converted into physycal units correctly. conv_grezziRSNHR function ended';
fprintf(fileID,fmt,text);
fclose(fileID);
end

27
RSN/database_definition.m Executable file
View File

@@ -0,0 +1,27 @@
function DB = database_definition(~,FileName)
%% DB ASE
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'database_definition function started';
fprintf(fileID,fmt,text);
Dati = importdata('DB.txt');
dbname = Dati{1,1};
username = Dati{2,1};
password = Dati{3,1};
driver = Dati{4,1};
dburl = Dati{5,1};
DB{1,1} = cellstr(dbname);
DB{2,1} = cellstr(username);
DB{3,1} = cellstr(password);
DB{4,1} = cellstr(driver);
DB{5,1} = cellstr(dburl);
text = 'Database defined correctly and database_definition function closed';
fprintf(fileID,fmt,text);
fclose(fileID);
end

150
RSN/database_write.m Executable file
View File

@@ -0,0 +1,150 @@
function database_write(catena,IDcentralina,DTcatena,...
AlfaX,AlfaY,TempDef_RSN,ARRAYdateRSN,ErrRSNLink,...
AlfaX_HR,AlfaY_HR,TempDef_RSNHR,ARRAYdateRSNHR,ErrRSNLinkHR,...
LoadDef,ErrLoadLink,ARRAYdateLL,val_TrL,StoricoTrigger,ErrTriggerLink,ARRAYdateTrL,...
val_SS,StoricoShock,ErrShockSensor,ARRAYdateSS,conn,FileName)
%% Attivo/disattivo la scrittura
[scrivoRSN,scrivoRSN_HR,scrivoLL,scrivoTrL,scrivoSS] = scrivo(AlfaX,...
AlfaX_HR,LoadDef,val_TrL,val_SS);
text = 'database_write function started';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
%% Contatori nodi
cRSN = 1; % RSN Link
cRSNHR = 1; % RSN Link HR
cLL = 1; % Load Link
cTrL = 1; % Trigger Link
cSS = 1; % Shock Sensor
% conto i dati
[~,colRSN] = size(AlfaX'); % controllo quanti dati ho
[~,colRSNHR] = size(AlfaX_HR'); % controllo quanti dati ho
[~,colLL] = size(LoadDef'); % controllo quanti dati ho
[~,colTrL] = size(val_TrL'); % controllo quanti dati ho
[~,colSS] = size(val_SS'); % controllo quanti dati ho
[rC,~] = size(catena);
idNodo = cell2mat(catena(:,1));
text = 'Upload of the results in the DB started';
fprintf(fileID,fmt,text);
%% Scrittura risultati su DB
for a = 1:rC
NodeNum = cell2mat(catena(a,3));
%% RSN Link
if idNodo(a,1) == 38
if scrivoRSN == 1 % se ho correttamente tutti i dati
ListaDate = colRSN;
DATAinsert = cellMakerRSN(IDcentralina,DTcatena,NodeNum,cRSN,ListaDate,...
ErrRSNLink,ARRAYdateRSN,AlfaX,AlfaY,TempDef_RSN);
idElabData = DB_date_time(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdateRSN,conn);
DBwriteRSN(DATAinsert,idElabData,ListaDate,NodeNum,IDcentralina,DTcatena,conn);
cRSN = cRSN+1;
clear DATAinsert
% Logfile
text = ['RSN Link node no. ' num2str(NodeNum) ' of ' ...
num2str(rC) ' of unit ' IDcentralina ' and chain ' DTcatena ' written in the DB!'];
fprintf(fileID,fmt,text);
end
%% RSN Link HR
elseif idNodo(a,1) == 39
if scrivoRSN_HR == 1 % se ho correttamente tutti i dati
ListaDate = colRSNHR;
DATAinsert = cellMakerRSNHR(IDcentralina,DTcatena,NodeNum,cRSNHR,ListaDate,...
ErrRSNLinkHR,ARRAYdateRSNHR,AlfaX_HR,AlfaY_HR,TempDef_RSNHR);
idElabData = DB_date_time(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdateRSNHR,conn);
DBwriteRSNHR(DATAinsert,idElabData,ListaDate,NodeNum,DTcatena,IDcentralina,conn);
cRSNHR = cRSNHR+1;
clear DATAinsert
% Logfile
text = ['RSN Link HR node no. ' num2str(NodeNum) ' of ' ...
num2str(rC) ' of unit ' IDcentralina ' and chain ' DTcatena ' written in the DB!'];
fprintf(fileID,fmt,text);
end
%% Load Link
elseif idNodo(a,1) == 15 % Load Link
if scrivoLL == 1
ListaDate = colLL;
DATAinsert = cellMakerLL(IDcentralina,DTcatena,NodeNum,cLL,...
ListaDate,ARRAYdateLL,LoadDef,ErrLoadLink);
idElabData = DB_date_time(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdateLL,conn);
DBwriteLL(DATAinsert,idElabData,ListaDate,NodeNum,IDcentralina,DTcatena,conn);
cLL = cLL+1;
clear DATAinsert
% Logfile
text = ['Load Link node no. ' num2str(NodeNum) ' of ' ...
num2str(rC) ' of unit ' IDcentralina ' and chain ' DTcatena ' written in the DB!'];
fprintf(fileID,fmt,text);
end
%% Trigger Link
elseif idNodo(a,1) == 40 % Trigger Link
if scrivoTrL == 1
ListaDate = colTrL;
DATAinsert = cellMakerTrL(DTcatena,IDcentralina,NodeNum,ListaDate,...
ARRAYdateTrL,val_TrL,StoricoTrigger,cTrL,ErrTriggerLink);
idElabData = DB_date_time(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdateTrL,conn);
DBwriteTrL(DATAinsert,idElabData,ListaDate,NodeNum,IDcentralina,DTcatena,conn);
cTrL = cTrL+1;
clear DATAinsert
% Logfile
text = ['Trigger Link node no. ' num2str(NodeNum) ' of ' ...
num2str(rC) ' of unit ' IDcentralina ' and chain ' DTcatena ' written in the DB!'];
fprintf(fileID,fmt,text);
end
%% Shock Sensor
elseif idNodo(a,1) == 54 % Shock Sensor
if scrivoSS == 1
ListaDate = colSS;
DATAinsert = cellMakerSS(DTcatena,IDcentralina,NodeNum,ListaDate,...
ARRAYdateSS,val_SS,StoricoShock,cSS,ErrShockSensor);
idElabData = DB_date_time(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdateSS,conn);
DBwriteSS(DATAinsert,idElabData,ListaDate,NodeNum,IDcentralina,DTcatena,conn);
cTrL = cTrL+1;
clear DATAinsert
% Logfile
text = ['Trigger Link node no. ' num2str(NodeNum) ' of ' ...
num2str(rC) ' of unit ' IDcentralina ' and chain ' DTcatena ' written in the DB!'];
fprintf(fileID,fmt,text);
end
end
end
text = 'DB upload completed. database_write function ended';
fprintf(fileID,fmt,text);
fclose(fileID);
end

21
RSN/datainiziale.m Executable file
View File

@@ -0,0 +1,21 @@
% Funzione che scarica la data iniziale per quell'installazione
function [date,time,unitID] = datainiziale(DTcatena,unitID,conn,FileName)
text = 'datainiziale function started';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
unitID = num2str(cell2mat(unitID));
comando = ['select prod_date from tools where unit_ID like ''' unitID ''' and name like ''' DTcatena ''' '];
data_ini = fetch(conn,comando);
stringa = cell2mat(data_ini);
[lS] = length(stringa);
date = stringa(1,1:10);
time = stringa(1,12:lS);
text = ['Starting date for the download of data: ' date ' ' time '. datainiziale function closed.'];
fprintf(fileID,fmt,text);
fclose(fileID);
end

40
RSN/defDatiLL.m Executable file
View File

@@ -0,0 +1,40 @@
% funzione che definisce i dati per la cella di carico, in particolare
% tempo (TimeLL), batteria (BattLL) e ADC (ADCLoad)
function [TimeLL,ADCLoad,ErrLoadLink] = defDatiLL(DatiLoadLink,ErrLoadLink,...
rLL,Ndatidespike,FileName)
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'defDatiLL function started';
fprintf(fileID,fmt,text);
[r,c]=size(DatiLoadLink);
Ncorr = 0;
% Elimino gli eventuali Not a Number
for a = 2:r
for b = 1:c
check = isnan(DatiLoadLink(a,b));
if check == 1
DatiLoadLink(a,b) = DatiLoadLink(a-1,b);
ErrLoadLink(a,b) = 1;
Ncorr = Ncorr+1;
end
end
end
text = ['' num2str(Ncorr) ' NaN of Load Link corrected by defDatiLL function'];
fprintf(fileID,fmt,text);
TimeLL = DatiLoadLink(:,1); % data
ADCLoad = DatiLoadLink(:,2:end); % dati ADC Analog Link
for s = 1:rLL
% despiking
ADCLoad(1:end-1,s) = filloutliers(ADCLoad(1:end-1,s),'linear','movmedian',Ndatidespike);
end
text = 'Data of Load Link defined correctly. defDatiLL function closed';
fprintf(fileID,fmt,text);
fclose(fileID);
end

71
RSN/defDatiRSN.m Executable file
View File

@@ -0,0 +1,71 @@
% Funzione che definisce accelerazioni (accRSN) e temperature (tempRSN)
% per i nodi di tipo RSN Link
function [TimeRSN,accRSN,tempRSN,ErrRSNLink] = defDatiRSN(MEMS,DatiRSNLink,...
ErrRSNLink,rRSN,Ndatidespike,FileName)
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'defDatiRSN function started';
fprintf(fileID,fmt,text);
[r,c] = size(DatiRSNLink);
Ncorr = 0;
% Elimino gli eventuali Not a Number
for a = 2:r
for b = 1:c
check = isnan(DatiRSNLink(a,b));
if check == 1
DatiRSNLink(a,b) = DatiRSNLink(a-1,b);
ErrRSNLink(a,b) = 1;
Ncorr = Ncorr+1;
end
end
end
text = ['' num2str(Ncorr) ' NaN of RSN Link corrected by defDatiRSN function'];
fprintf(fileID,fmt,text);
% Definisco Data (gg:mm:aaaa hh:mm), Batteria, i 3 dati di accelerometro
% e la Temperatura per la calibrazione
TimeRSN = DatiRSNLink(:,1); % data
accRSN = zeros(r,rRSN*3); % dati accelerometro
tempRSN = zeros(r,rRSN); % temperatura del nodo
p = 4; % passo nella definizione dei dati
s = 1;
for i = 1:rRSN
accRSN(:,s) = DatiRSNLink(:,2+(i-1)*p);
accRSN(:,s+1) = DatiRSNLink(:,3+(i-1)*p);
accRSN(:,s+2) = DatiRSNLink(:,4+(i-1)*p);
s = s+3;
tempRSN(:,i) = DatiRSNLink(:,5+(i-1)*p);
if MEMS == 2
[rT,~] = size(tempRSN);
for j = 1:rT
if tempRSN(j,i) > 200
tempRSN(j,i) = tempRSN(j,i) - 256; % Correzione della temperatura dei nuovi MEMS
end
end
end
end
% il despike NON viene mai eseguito sull'ultimo dato disponibile
Num_Dati = Ndatidespike; % numero di dati per il despike
if Num_Dati > r
Num_Dati = r;
end
s = 1;
for i = 1:rRSN
% despiking accelerometri
accRSN(1:end-1,s) = filloutliers(accRSN(1:end-1,s),'linear','movmedian',Num_Dati);
accRSN(1:end-1,s+1) = filloutliers(accRSN(1:end-1,s+1),'linear','movmedian',Num_Dati);
accRSN(1:end-1,s+2) = filloutliers(accRSN(1:end-1,s+2),'linear','movmedian',Num_Dati);
s = s+3;
end
text = 'Data of RSN Link defined correctly';
fprintf(fileID,fmt,text);
fclose(fileID);
end

124
RSN/defDatiRSNHR.m Executable file
View File

@@ -0,0 +1,124 @@
function [TimeRSNHR,angRSNHR,tempRSNHR,ErrRSNLinkHR] = defDatiRSNHR(DatiRSNLinkHR,...
ErrRSNLinkHR,rRSNHR,IDcentralina,DTcatena,Ndatidespike,NuovoZeroRSNHR,FileName)
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'defDatiRSNHR function started';
fprintf(fileID,fmt,text);
[r,c] = size(DatiRSNLinkHR);
Ncorr = 0;
% Elimino gli eventuali Not a Number
for a = 2:r
for b = 1:c
check = isnan(DatiRSNLinkHR(a,b));
if check == 1
DatiRSNLinkHR(a,b) = DatiRSNLinkHR(a-1,b);
ErrRSNLinkHR(a,b) = 1;
Ncorr = Ncorr+1;
end
end
end
text = ['' num2str(Ncorr) ' NaN of RSN Link HR corrected by defDatiRSNHR function'];
fprintf(fileID,fmt,text);
TimeRSNHR = DatiRSNLinkHR(:,1); % data
angRSNHR = zeros(r,rRSNHR*2); % dati angolari
tempRSNHR = zeros(r,rRSNHR); % temperatura del nodo per la calibrazione
p = 2; % passo
s = 1;
for i = 1:rRSNHR
angRSNHR(:,s:s+1) = DatiRSNLinkHR(:,p:p+1);
s = s+2;
tempRSNHR(:,i) = DatiRSNLinkHR(:,p+2);
p = p+3;
end
s = 1;
Num_Dati = Ndatidespike; % numero di dati per il despike
if Num_Dati > r
Num_Dati = r;
end
% il despike NON viene eseguito per l'ultimo dato disponibile
for i = 1:rRSNHR
% despiking accelerometri
angRSNHR(1:end-1,s) = filloutliers(angRSNHR(1:end-1,s),'linear','movmedian',Num_Dati);
angRSNHR(1:end-1,s+1) = filloutliers(angRSNHR(1:end-1,s+1),'linear','movmedian',Num_Dati);
s = s+2;
end
%% !!! Controllo che le ampolle non siano fuori scala (32768)
AmpolleUpdate = ['' IDcentralina '-' DTcatena '-Ampolle.csv'];
[rC,cC] = size(angRSNHR);
if NuovoZeroRSNHR == 1 && isfile(AmpolleUpdate) == 1
Dati = csvread(AmpolleUpdate);
[rD,~] = size(Dati);
num = 1;
cont = 1;
if rD ~= 0
for j = 1:rC
for ii = 1:cC
segno1 = 0;
for a = 2:rD
if TimeRSNHR(j,1) == Dati(a,1)
segno1 = sign(Dati(a-1,ii+1)); % segno del valore alla data precedente
break
end
end
if segno1 == 0
if j == 1
else
segno1 = sign(angRSNHR(j-1,ii)); % segno del valore alla data precedente
end
end
segno2 = sign(angRSNHR(j,ii)); % segno del valore alla data successiva
if segno2 ~= segno1 % se i due segni sono diversi
if abs(angRSNHR(j,ii)) > 15000
if segno1 == 1
angRSNHR(j,ii) = 32768 + (32768 + angRSNHR(j,ii)); % Fondo scala positivo
elseif segno1 == -1
angRSNHR(j,ii) = -32768 + (-32768 + angRSNHR(j,ii)); % Fondo scala negativo
end
text = ['RSN Link HR was out of range on node ' mat2str(cell2mat(NodoRSNLinkHR(num,2))) ''];
fprintf(fileID,fmt,text);
end
end
cont = cont+1;
if cont == 3
cont = 1;
num = num+1;
end
end
cont = 1;
num = 1;
end
indice = 1;
for j=1:rC
if Dati(end,1) == TimeRSNHR(j,1)
indice = j+1;
break
end
end
else
indice = [];
end
else
indice = 1;
end
if isempty(indice) == 0
datiHR = [TimeRSNHR(indice:end,1) angRSNHR(indice:end,:)];
dat=isempty(datiHR);
if dat==0
if NuovoZeroRSNHR == 1 && isfile(AmpolleUpdate) == 1
delete(AmpolleUpdate);
end
csvwrite(AmpolleUpdate,datiHR);
end
end
text = 'Data of RSN Link HR defined correctly. defDatiRSNHR function closed';
fprintf(fileID,fmt,text);
fclose(fileID);
end

54
RSN/defDatiSS.m Executable file
View File

@@ -0,0 +1,54 @@
% Funzione che definisce le attivazioni di fine corsa per i nodi di tipo Trigger Link
function [ARRAYdateSS,val_SS,ErrShockSensor] = defDatiSS(DatiShockSensor,...
ErrShockSensor,rSS,FileName)
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'defDatiSS function started';
fprintf(fileID,fmt,text);
[r,c]=size(DatiShockSensor);
Ncorr = 0;
% Elimino gli eventuali Not a Number
for a = 2:r
for b = 1:c
check = isnan(DatiShockSensor(a,b));
if check == 1
DatiShockSensor(a,b) = DatiShockSensor(a-1,b);
ErrShockSensor(a,b) = 1;
Ncorr = Ncorr+1;
end
end
end
text = ['' num2str(Ncorr) ' NaN of Shock Sensor corrected by defDatiSS function'];
fprintf(fileID,fmt,text);
[r,~] = size(DatiShockSensor);
TimeSS = DatiShockSensor(:,1); % data
val_SS = zeros(r,rSS); % dati shock sensor
i = 1;
while i <= rSS
for j = 1:r
if DatiShockSensor(j,1+i) == 1 || DatiShockSensor(j,1+i) == 2 || DatiShockSensor(j,1+i) == 3
if DatiShockSensor(j,1+i) == 1
val_SS(j,i) = 1;
elseif j > 1 && DatiShockSensor(j,1+i) == 2 && DatiShockSensor(j-1,1+i) ~= 1
val_SS(j,i) = 1;
elseif j > 1 && DatiShockSensor(j,1+i) == 3 && DatiShockSensor(j-1,1+i) ~= 1 && DatiShockSensor(j-1,1+i) ~= 2
val_SS(j,i) = 1;
end
else
val_SS(j,i) = 0;
end
end
i = i+1;
end
ARRAYdateSS = TimeSS;
text = 'Data of Shock Sensor defined correctly';
fprintf(fileID,fmt,text);
fclose(fileID);
end

70
RSN/defDatiTrL.m Executable file
View File

@@ -0,0 +1,70 @@
% Funzione che definisce le attivazioni di fine corsa per i nodi di tipo Trigger Link
function [ARRAYdateTrL,val_TrL,ErrTriggerLink] = defDatiTrL(DatiTriggerLink,...
Type,ErrTriggerLink,rTrL,NuovoZeroTrL,FileName)
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'defDatiTrL function started';
fprintf(fileID,fmt,text);
[r,c]=size(DatiTriggerLink);
Ncorr = 0;
% Elimino gli eventuali Not a Number
for a = 2:r
for b = 1:c
check = isnan(DatiTriggerLink(a,b));
if check == 1
DatiTriggerLink(a,b) = DatiTriggerLink(a-1,b);
ErrTriggerLink(a,b) = 1;
Ncorr = Ncorr+1;
end
end
end
if NuovoZeroTrL == 1
DatiTriggerLink = DatiTriggerLink(2:end,:);
ErrTriggerLink = ErrTriggerLink(2:end,:);
end
text = ['' num2str(Ncorr) ' NaN of Trigger Link corrected by defDatiTrL function'];
fprintf(fileID,fmt,text);
[r,~] = size(DatiTriggerLink);
TimeTrL = DatiTriggerLink(:,1); % data
val_TrL = zeros(r,rTrL); % dati fine corsa
if Type == 7
code = 16;
else
code = 1;
end
i = 1;
while i <= rTrL
for j = 1:r
if DatiTriggerLink(j,1+i) == code % Se la prima colonna ha il codice associato al Trigger
if j > 1 && Type == 7
check = DatiTriggerLink(j,1+i)-DatiTriggerLink(j-1,1+i);
else
check = 1;
end
if check > 0
val_TrL(j,i) = 1;
end
else
val_TrL(j,i) = 0;
end
end
if Type == 7
i = i+2;
else
i = i+1;
end
end
ARRAYdateTrL = TimeTrL;
text = 'Data of Trigger Link defined correctly';
fprintf(fileID,fmt,text);
fclose(fileID);
end

304
RSN/elaborazione_RSN.m Executable file
View File

@@ -0,0 +1,304 @@
%% Funzione che calcola gli spostamenti in modalità triassiale per i Tilt Link
function [AlfaX,AlfaY,TempDef_RSN,ARRAYdateRSN,ErrRSNLink] = elaborazione_RSN(conn,...
IDcentralina,DTcatena,MEMS,rRSN,ris_acc,tolleranzaAcc,angRSN,Tmax,Tmin,TempDef_RSN,...
NodoRSNLink,ARRAYdateRSN,NuovoZeroRSN,NdatiMedia,Ndatidespike,ErrRSNLink,datainiRSN,...
pos_inst,FileName)
% Inizio del ciclo di elaborazione
text = 'elaborazione_RSN function started';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
if NuovoZeroRSN == 1
if NdatiMedia > Ndatidespike
Ndati = NdatiMedia;
else
Ndati = Ndatidespike;
end
ini = round(Ndati/2)+1;
if rem(Ndati,2) == 0
ini = ini+1;
end
clear NDati
angRSN = angRSN(ini:end,:);
ris_acc = ris_acc(ini:end,:);
TempDef_RSN = TempDef_RSN(ini:end,:);
ARRAYdateRSN = ARRAYdateRSN(ini:end,1);
ErrRSNLink = ErrRSNLink(ini:end,:);
end
Nnodi = rRSN;
% Inizio del ciclo di elaborazione
text = 'Elaboration of RSN Link started';
fprintf(fileID,fmt,text);
TempDef_RSN = TempDef_RSN';
[rr,cc] = size(angRSN);
if MEMS == 2
cc = cc/2;
else
cc = cc/3;
end
%% Controllo delle risultanti di accelerazione
if MEMS == 2 % Il controllo lo eseguo solo per i MEMS FreeScale
ris_acc = ris_acc'; % Nodi in riga, date in colonna
[r,c] = size(ris_acc);
% controllo che le matrici con le risultanti delle accelerazioni e
% le matrici con i dati di angolo di inclinazione assoluto
% abbiano le stesse dimensioni (r con cc e c con rr perchè matrice
% ris_acc è trasposta!)
if r~=cc
text = ['Warning! Number of row of absolute angle data do not correspond '...
'to the number of acceleration cosine vector!'];
fprintf(fileID,fmt,text);
end
if c~=rr
text = ['Warning! Number of column of absolute angle data do not correspond '...
'to the number of acceleration cosine vector!'];
fprintf(fileID,fmt,text);
end
cont = 1; % contatore
cont2 = 1; % contatore
angRSN = angRSN';
textA = 'There are not correction of RSN Link based on acceleration vectors filter';
textA2 = 'There are not correction of RSN Link based on uncalibrated acceleration vectors';
for j = 2:c % Data
nodo = 1;
for i = 1:r % Nodo
% se il valore assoluto della differenza è maggiore della
% tolleranza, pongo l'angolo pari al valore precendete
if abs(ris_acc(i,j)-ris_acc(i,j-1)) > tolleranzaAcc
angRSN(nodo:nodo+1,j) = angRSN(nodo:nodo+1,j-1);
textA = ['' num2str(cont) ' correction executed for RSN Link - Acceleration vector filter!'];
cont = cont+1;
end
if ris_acc(i,j) < 0.8 || ris_acc(i,j) > 1.3 % Il nodo è fuori taratura!
if j == 1
nn = 2;
while nn <= c
if ris_acc(i,nn) < 0.8 || ris_acc(i,nn) > 1.2
angRSN(nodo:nodo+1,j) = angRSN(nodo:nodo+1,nn);
break
end
end
else
angRSN(nodo:nodo+1,j) = angRSN(nodo:nodo+1,j-1);
TempDef_RSN(i,j) = TempDef_RSN(i,j-1);
end
textA2 = ['' num2str(cont2) ' correction executed for RSN Link - uncalibrated Acceleration vector!'];
cont2 = cont2+1;
end
nodo = nodo+2;
end
end
fprintf(fileID,fmt,textA);
fprintf(fileID,fmt,textA2);
else
[c,r] = size(ris_acc);
angRSN = angRSN';
end
%% Temperatura
cont3 = 0; % contatore
FileTemperature = ['' IDcentralina '-' DTcatena '-RSN-Therm.csv'];
if isfile(FileTemperature) == 1
DatiRaw = csvread(FileTemperature);
[rDR,cDR] = size(DatiRaw);
DatiRaw(:,1) = DatiRaw(:,1) + 730000;
else
rDR = 1;
cDR = 1;
end
textT = 'There are not correction of RSN Link based on temperature filter';
for b = 1:c % Data
nodo = 1;
for a = 1:r % Nodo
% NON considero i dati al di sopra dei 80 °C o al di sotto dei -30 °C!
if TempDef_RSN(a,b) > Tmax || TempDef_RSN(a,b) < Tmin
cont3 = cont3+1;
if b == 1
if isfile(FileTemperature) == 1
RawDate = find(DatiRaw(:,1)<=datenum(datainiRSN));
if isempty(RawDate) == 1
cc = 2;
while cc <= c
if TempDef_RSN(a,cc) > Tmax || TempDef_RSN(a,cc) < Tmin
cc = cc+1;
else
break
end
end
TempDef_RSN(a,b) = TempDef_RSN(a,cc);
angRSN(nodo:nodo+1,b) = angRSN(nodo:nodo+1,cc);
else
if isnan(DatiRaw(RawDate(end),a+1)) == 0
TempDef_RSN(a,b) = cellstr(num2str(DatiRaw(b+1,RawDate(end))));
angRSN(nodo:nodo+1,b) = cellstr(num2str(DatiRaw(1+a*2:2+a*2,RawDate(end))));
if ErrRSNLink(b,jj) == 0
ErrRSNLink(b,jj) = 0.5;
end
wardat = 'Temperature data of RSN Link nodes corrected using Raw Data of reference Csv file.';
fprintf(fileID,fmt,wardat);
else
cc = 2;
while cc <= c
if TempDef_RSN(a,cc) > Tmax || TempDef_RSN(a,cc) < Tmin
cc = cc+1;
else
break
end
end
TempDef_RSN(a,b) = TempDef_RSN(a,cc);
angRSN(nodo:nodo+1,b) = angRSN(nodo:nodo+1,cc);
end
end
else
cc = 2;
while cc <= c
if TempDef_RSN(a,cc) > Tmax || TempDef_RSN(a,cc) < Tmin
cc = cc+1;
else
break
end
end
TempDef_RSN(a,b) = TempDef_RSN(a,cc);
end
else
TempDef_RSN(a,b) = TempDef_RSN(a,b-1);
angRSN(nodo:nodo+1,j) = angRSN(nodo:nodo+1,j-1);
if ErrRSNLink(b,jj) == 0
ErrRSNLink(b,jj) = 0.5;
end
end
textT = ['' num2str(cont3) ' correction executed for RSN Link - Temperature filter!'];
end
nodo = nodo+2;
end
end
if rDR~=1 && cDR~=1 && isempty(DatiRaw) == 0
RawDate1 = find(DatiRaw(:,1)<=ARRAYdateRSN(1));
if isempty(RawDate1) == 1
RawDate2 = 1;
elseif RawDate1(end) == rDR
RawDate2 = find(ARRAYdateRSN(:,1)>DatiRaw(end,1));
else
RawDate2 = find(ARRAYdateRSN(:,1)>DatiRaw(RawDate1(end)+1,1));
end
else
RawDate1 = [];
RawDate2 = 1;
end
if isempty(RawDate1) == 0 && isempty(RawDate2) == 0
Dati = [DatiRaw(1:RawDate1(end),:); ARRAYdateRSN(RawDate2(1):end) TempDef_RSN(:,RawDate2(1):end)' angRSN(:,RawDate2(1):end)'];
elseif isempty(RawDate1) == 1 && isempty(RawDate2) == 0
Dati = [ARRAYdateRSN TempDef_RSN' angRSN'];
else
Dati = DatiRaw;
end
% Elimino appoggio più vecchio di un mese
RawDate3 = find(Dati(:,1)<now-30);
if isempty(RawDate3) == 0
[rDati,~] = size(Dati);
if RawDate3(end) == rDati
else
Dati = Dati(RawDate3(end)+1:end,:);
end
end
if isfile(FileTemperature) == 1
delete(FileTemperature);
end
Dati(:,1) = Dati(:,1) - 730000;
csvwrite(FileTemperature,Dati);
TempDef_RSN = TempDef_RSN';
angRSN = angRSN';
fprintf(fileID,fmt,textT);
% modifica di alcuni nodi in particolare
angRSN = azzeramenti(conn,IDcentralina,DTcatena,angRSN,NodoRSNLink,...
ARRAYdateRSN,FileName);
AlfaX = zeros(rr,Nnodi);
AlfaY = zeros(rr,Nnodi);
for i = 1:Nnodi
if pos_inst == 1
AlfaX(:,i) = angRSN(:,(i-1)*2+1); % ax
AlfaY(:,i) = angRSN(:,(i-1)*2+2); % ay
elseif pos_inst == 2
AlfaX(:,i) = -angRSN(:,(i-1)*2+1); % ax
AlfaY(:,i) = -angRSN(:,(i-1)*2+2); % ay
elseif pos_inst == 3
AlfaX(:,i) = -angRSN(:,(i-1)*2+1); % ax
AlfaY(:,i) = -angRSN(:,(i-1)*2+2); % ay
elseif pos_inst == 4
AlfaX(:,i) = angRSN(:,(i-1)*2+1); % ax
AlfaY(:,i) = angRSN(:,(i-1)*2+2); % ay
elseif pos_inst == 5
AlfaX(:,i) = angRSN(:,(i-1)*2+2); % ay
AlfaY(:,i) = -angRSN(:,(i-1)*2+1); % ax
elseif pos_inst == 6
AlfaX(:,i) = -angRSN(:,(i-1)*2+2); % ay
AlfaY(:,i) = angRSN(:,(i-1)*2+1); % ax
elseif pos_inst == 7
AlfaX(:,i) = -angRSN(:,(i-1)*2+2); % ay
AlfaY(:,i) = angRSN(:,(i-1)*2+1); % ax
elseif pos_inst == 8
AlfaX(:,i) = angRSN(:,(i-1)*2+2); % ay
AlfaY(:,i) = -angRSN(:,(i-1)*2+1); % ax
end
end
fclose(fileID);
% Approssimo i dati con il corretto numero di cifre decimali
[AlfaX,AlfaY,TempDef_RSN] = approx(AlfaX,AlfaY,TempDef_RSN,FileName);
%% Calcolo differenziali
NomeFileX = ['' IDcentralina '-' DTcatena '-RifX.csv'];
NomeFileY = ['' IDcentralina '-' DTcatena '-RifY.csv'];
if NuovoZeroRSN == 0 % prima elaborazione
csvwrite(NomeFileX,AlfaX(1,:));
AlfaX = AlfaX - AlfaX(1,:);
csvwrite(NomeFileY,AlfaY(1,:));
AlfaY = AlfaY - AlfaY(1,:);
else % Ci sono già dei dati elaborati
RIF_X = csvread(NomeFileX);
AlfaX = AlfaX - RIF_X;
RIF_Y = csvread(NomeFileY);
AlfaY = AlfaY - RIF_Y;
end
[r,~] = size(ErrRSNLink);
Matrice_err = zeros(r,rRSN);
for i = 1:r % date
d = 1;
for n = 1:rRSN % nodi
j = 1;
err = ErrRSNLink(i,d:d+3);
while j <= 4
if err(1,j) == 1
Matrice_err(i,n) = 1;
break
elseif err(1,j) == 0.5 && Matrice_err(i,n) ~= 1
Matrice_err(i,n) = 0.5;
end
j = j+1;
end
d = d+4;
end
end
ErrRSNLink = Matrice_err';
text = 'RSN Link elaboration executed correctly. elaborazione_RSN function closed';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end

211
RSN/elaborazione_RSNHR.m Executable file
View File

@@ -0,0 +1,211 @@
%% Funzione che calcola gli angoli assoluti per i RSN Link HR (ampolle)
function [AlfaX_HR,AlfaY_HR,TempDef_RSNHR,ARRAYdateRSNHR,ErrRSNLinkHR] = ...
elaborazione_RSNHR(conn,IDcentralina,DTcatena,rRSNHR,angRSNHR,Tmax,Tmin,...
TempDef_RSNHR,NodoRSNLinkHR,ARRAYdateRSNHR,NuovoZeroRSNHR,NdatiMedia,...
Ndatidespike,datainiRSNHR,ErrRSNLinkHR,FileName)
% Inizio del ciclo di elaborazione
text = 'elaborazione_RSNHR function started';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
if NuovoZeroRSNHR == 1
if NdatiMedia > Ndatidespike
Ndati = NdatiMedia;
else
Ndati = Ndatidespike;
end
ini = round(Ndati/2)+1;
if rem(Ndati,2) == 0
ini = ini+1;
end
clear NDati
angRSNHR = angRSNHR(ini:end,:);
TempDef_RSNHR = TempDef_RSNHR(ini:end,:);
ARRAYdateRSNHR = ARRAYdateRSNHR(ini:end,1);
ErrRSNLinkHR = ErrRSNLinkHR(ini:end,:);
end
%% Temperatura
cont3 = 0; % contatore
FileTemperature = ['' IDcentralina '-' DTcatena '-RSNHR-Therm.csv'];
if isfile(FileTemperature) == 1
DatiRaw = csvread(FileTemperature);
[rDR,cDR] = size(DatiRaw);
DatiRaw(:,1) = DatiRaw(:,1) + 730000;
else
rDR = 1;
cDR = 1;
end
[Ndate,~] = size(ARRAYdateRSNHR);
Nnodi = rRSNHR;
TempDef_RSNHR = TempDef_RSNHR';
angRSNHR = angRSNHR';
textT = 'No correction needed for RSN Link HR - Temperature filter';
for b = 1:Ndate % Data
nodo = 1;
for a = 1:Nnodi % Nodo
% NON considero i dati al di sopra dei 80 °C o al di sotto dei -30 °C!
if TempDef_RSNHR(a,b) > Tmax || TempDef_RSNHR(a,b) < Tmin
cont3 = cont3+1;
if b == 1
if isfile(FileTemperature) == 1
RawDate = find(DatiRaw(:,1)<=datenum(datainiRSNHR));
if isempty(RawDate) == 1
cc = 2;
while cc <= c
if TempDef_RSNHR(a,cc) > Tmax || TempDef_RSNHR(a,cc) < Tmin
cc = cc+1;
else
break
end
end
TempDef_RSNHR(a,b) = TempDef_RSNHR(a,cc);
angRSNHR(nodo:nodo+1,b) = angRSNHR(nodo:nodo+1,cc);
else
if isnan(DatiRaw(RawDate(end),a+1)) == 0
TempDef_RSNHR(a,b) = cellstr(num2str(DatiRaw(b+1,RawDate(end))));
angRSNHR(nodo:nodo+1,b) = cellstr(num2str(DatiRaw(1+a*2:2+a*2,RawDate(end))));
if ErrRSNLinkHR(b,a) == 0
ErrRSNLinkHR(b,a) = 0.5;
end
wardat = 'Temperature data of RSN Link HR nodes corrected using Raw Data of reference Csv file.';
fprintf(fileID,fmt,wardat);
else
cc = 2;
while cc <= c
if TempDef_RSNHR(a,cc) > Tmax || TempDef_RSNHR(a,cc) < Tmin
cc = cc+1;
else
break
end
end
TempDef_RSNHR(a,b) = TempDef_RSNHR(a,cc);
angRSNHR(nodo:nodo+1,b) = angRSNHR(nodo:nodo+1,cc);
end
end
else
cc = 2;
while cc <= c
if TempDef_RSNHR(a,cc) > Tmax || TempDef_RSNHR(a,cc) < Tmin
cc = cc+1;
else
break
end
end
TempDef_RSNHR(a,b) = TempDef_RSNHR(a,cc);
end
else
TempDef_RSNHR(a,b) = TempDef_RSNHR(a,b-1);
angRSNHR(nodo:nodo+1,b) = angRSNHR(nodo:nodo+1,b-1);
if ErrRSNLinkHR(b,a) == 0
ErrRSNLinkHR(b,a) = 0.5;
end
end
textT = ['' num2str(cont3) ' correction executed for RSN Link HR - Temperature filter!'];
end
nodo = nodo+2;
end
end
if rDR~=1 && cDR~=1 && isempty(DatiRaw) == 0
RawDate1 = find(DatiRaw(:,1)<=ARRAYdateRSNHR(1));
if isempty(RawDate1) == 1
RawDate2 = 1;
elseif RawDate1(end) == rDR
RawDate2 = find(ARRAYdateRSNHR(:,1)>DatiRaw(end,1));
else
RawDate2 = find(ARRAYdateRSNHR(:,1)>DatiRaw(RawDate1(end)+1,1));
end
else
RawDate1 = [];
RawDate2 = 1;
end
if isempty(RawDate1) == 0 && isempty(RawDate2) == 0
Dati = [DatiRaw(1:RawDate1(end),:); ARRAYdateRSNHR(RawDate2(1):end) TempDef_RSNHR(:,RawDate2(1):end)' angRSNHR(:,RawDate2(1):end)'];
elseif isempty(RawDate1) == 1 && isempty(RawDate2) == 0
Dati = [ARRAYdateRSNHR TempDef_RSNHR' angRSNHR'];
else
Dati = DatiRaw;
end
% Elimino appoggio più vecchio di un mese
RawDate3 = find(Dati(:,1)<now-30);
if isempty(RawDate3) == 0
[rDati,~] = size(Dati);
if RawDate3(end) == rDati
else
Dati = Dati(RawDate3(end)+1:end,:);
end
end
if isfile(FileTemperature) == 1
delete(FileTemperature);
end
Dati(:,1) = Dati(:,1) - 730000;
csvwrite(FileTemperature,Dati);
TempDef_RSNHR = TempDef_RSNHR';
angRSNHR = angRSNHR';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,textT);
fclose(fileID);
% azzeramenti di alcuni nodi in particolare
angRSNHR = azzeramenti_RSNHR(conn,IDcentralina,DTcatena,angRSNHR,...
NodoRSNLinkHR,ARRAYdateRSNHR,FileName);
%% Definizione dati
NnodiHR = rRSNHR;
[Ndate,~] = size(ARRAYdateRSNHR);
AlfaX_HR = zeros(Ndate,NnodiHR);
AlfaY_HR = zeros(Ndate,NnodiHR);
for i = 1:NnodiHR
a = angRSNHR(:,(i-1)*2+1); % aHRx
AlfaX_HR(:,i) = a;
b = angRSNHR(:,(i-1)*2+2); % aHRy
AlfaY_HR(:,i) = b;
end
% Inizio del ciclo di elaborazione
text = 'Elaboration of RSN Link HR started';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
% Approssimo i dati con il corretto numero di cifre decimali
[AlfaX_HR,AlfaY_HR,TempDef_RSNHR] = approx_RSNHR(AlfaX_HR,AlfaY_HR,TempDef_RSNHR,FileName);
[r,~] = size(ErrRSNLinkHR);
Matrice_err = zeros(r,rRSNHR);
clear j
for i = 1:r % date
d = 1;
for n = 1:rRSNHR % nodi
j = 1;
err = ErrRSNLinkHR(i,d:d+2);
while j <= 3
if err(1,j) == 1
Matrice_err(i,n) = 1;
elseif err(1,j) == 0.5 && Matrice_err(i,n) == 0
Matrice_err(i,n) = 0.5;
end
j = j+1;
end
d = d+3;
end
end
ErrRSNLinkHR = Matrice_err';
text = 'RSN Link HR elaboration executed correctly. elaborazione_RSNHR function closed';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end

2287
RSN/lettura.m Executable file

File diff suppressed because it is too large Load Diff

168
RSN/letturaCal.m Executable file
View File

@@ -0,0 +1,168 @@
% Funzione che legge i valori di calibrazione per i vari sensori
function [DCalRSNTot,DCalRSNHRTot,DCalLLTot,DCalDLTot,yesRSN,yesRSNHR,yesLL,yesDL]...
= letturaCal(MEMS,IDcentralina,DTcatena,catena,yesRSN,yesRSNHR,yesLL,yesDL,rRSN,...
rRSNHR,rLL,rDL,NodoRSNLink,NodoLoadLink,NodoDebrisLink,conn,FileName)
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'letturaCal function started';
fprintf(fileID,fmt,text);
% Inizializzo le matrici
[rC,~] = size(catena);
idNodo = cell2mat(catena(:,1));
% RSN
if isempty(NodoRSNLink) == 1
DCalRSNTot = [];
else
if strcmp(NodoRSNLink(1,4),'ADC') || strcmp(NodoRSNLink(1,4),'null') || isempty(NodoRSNLink(1,4)) == 1
DCalRSNTot = cell(rRSN,17); % matrice che concatena i dati di calibrazione relativi a ciascun nodo RSN Link
elseif strcmp(NodoRSNLink(1,4),'Gradi')
DCalRSNTot = [];
end
end
% RSN HR
DCalRSNHRTot = cell(rRSNHR,6); % matrice che concatena i dati relativi a ciascun nodo RSN Link HR
% Load Link
if isempty(NodoLoadLink) == 1
DCalLLTot = [];
else
if strcmp(NodoLoadLink(1,4),'4-20 mA')
DCalLLTot = cell(rLL,3); % matrice che concatena i dati relativi a ciascun nodo Load Link [4-20mA]
elseif strcmp(NodoLoadLink(1,4),'mV/V') || strcmp(NodoLoadLink(1,4),'ADC')
DCalLLTot = cell(rLL,2); % matrice che concatena i dati relativi a ciascun nodo Load Link [mV/V]
end
end
% Debris LInk
if isempty(NodoDebrisLink) == 1
DCalDLTot = [];
else
if strcmp(NodoDebrisLink(1,4),'ADC') || strcmp(NodoDebrisLink(1,4),'null') || isempty(NodoDebrisLink(1,4)) == 1
DCalDLTot = cell(rDL,11); % matrice che concatena i dati di calibrazione relativi a ciascun nodo RSN Link
elseif strcmp(NodoRSNLink(1,4),'Gradi')
DCalDLTot = [];
end
end
% Matrice con testi di conferma lettura o warning di lettura per le varie tipologie di nodi
RSNL = 1;
RSNLHR = 1;
LL = 1;
DL = 1;
for a = 1:rC
nNodo = mat2str(cell2mat(catena(a,3)));
if idNodo(a,1) == 38 % RSN Link
if MEMS == 2
%% Importazione dei dati di calibrazione per RSN Link
comando = ['select Cal0, Cal1, Cal2, Cal3, Cal4, Cal5, Cal6, Cal7, Cal8, '...
'CalA, CalB, CalC, CalD, CalE, CalF, CalG, CalH from CalibrationView where UnitName = '''...
IDcentralina ''' and ToolNameID = ''' DTcatena ''' and NodeNum = ''' nNodo ''''];
curs = exec(conn,comando);
curs = fetch(curs);
DCalRSN = curs.Data; % matrice che raccoglie i dati del nodo numero 'a' di tipo RSN Link
[rr,cc] = size(DCalRSN);
if rr==1 && cc==1
w = ['Warning: there was an error reading calibration values of RSN Link node number ' nNodo ''];
fprintf(fileID,fmt,w);
yesRSN = 0;
else
DCalRSNTot(RSNL,:) = DCalRSN(:,:);
RSNL = RSNL+1;
ok = ['Calibration parameters of RSN Link node number ' nNodo ' downloaded correctly'];
fprintf(fileID,fmt,ok);
end
else
ok = ['Calibration parameters of RSN Link node number ' nNodo ' NOT downloaded because the node is RSN Link 2.0 - Murata MEMS'];
fprintf(fileID,fmt,ok);
end
elseif idNodo(a,1) == 39 % RSN Link HR
%% Importazione dei dati di calibrazione per RSN Link HR
comando = ['select Cal0, Cal1, Cal2, Cal3, Cal4, Cal5 from CalibrationView where UnitName = '''...
IDcentralina ''' and ToolNameID = ''' DTcatena ''' and NodeNum = ''' nNodo ''''];
curs = exec(conn,comando);
curs = fetch(curs);
DCalRSNHR = curs.Data; % matrice che raccoglie i dati del nodo numero 'a' di tipo RSN Link HR
[rr,cc] = size(DCalRSNHR);
if rr==1 && cc==1
w = ['Warning: there was an error reading calibration values of RSN Link HR node number ' nNodo ''];
fprintf(fileID,fmt,w);
yesRSNHR = 0;
else
DCalRSNHRTot(RSNLHR,:) = DCalRSNHR(:,:);
RSNLHR = RSNLHR+1;
ok = ['Calibration parameters of RSN Link HR node number ' nNodo ' downloaded correctly'];
fprintf(fileID,fmt,ok);
end
elseif idNodo(a,1) == 15 % Load Link
%% Importazione dei dati di calibrazione per Load Link
if strcmp(NodoLoadLink(1,4),'4-20 mA')
comando = ['select Cal0, Cal1, Cal2 from CalibrationView where UnitName = '''...
IDcentralina ''' and ToolNameID = ''' DTcatena ''' and NodeNum = ''' nNodo ''' '];
elseif strcmp(NodoLoadLink(1,4),'mV/V')
comando = ['select Cal1, Cal2 from CalibrationView where UnitName = '''...
IDcentralina ''' and ToolNameID = ''' DTcatena ''' and NodeNum = ''' nNodo ''' '];
elseif strcmp(NodoLoadLink(1,4),'ADC')
comando = ['select Cal0, Cal1 from CalibrationView where UnitName = '''...
IDcentralina ''' and ToolNameID = ''' DTcatena ''' and NodeNum = ''' nNodo ''' '];
end
curs = exec(conn,comando);
curs = fetch(curs);
DCalLL = curs.Data; % matrice che raccoglie i dati del nodo numero 'a' di tipo Load Link
[rr,cc] = size(DCalLL);
if rr==1 && cc==1
w = ['Warning: there was an error reading calibration values of node Load Link number ' nNodo ''];
fprintf(fileID,fmt,w);
yesLL = 0;
else
DCalLLTot(LL,:) = DCalLL(:,:);
LL = LL+1;
ok = ['Calibration of node Load Link number ' nNodo ' downloaded correctly'];
fprintf(fileID,fmt,ok);
end
elseif idNodo(a,1) == 49 % Debris Link
if MEMS == 2
comando = ['select Cal0, Cal1, Cal2, Cal3, Cal4, Cal5, Cal6, Cal7, Cal8, CalA, CalB from CalibrationView where UnitName = ''' ...
IDcentralina ''' and ToolNameID = ''' DTcatena ''' and NodeNum = ''' nNodo ''''];
curs = exec(conn,comando);
curs = fetch(curs);
DCalDL = curs.Data; % matrice che raccoglie i dati del nodo numero 'a' di tipo Tunnel Link
[rr,cc] = size(DCalDL);
if rr==1 && cc==1
text = ['Warning: there was an error reading Debris Link node number ' nNodo ''];
fprintf(fileID,fmt,text);
yesDL = 0;
else
DCalDLTot(DL,:) = DCalDL(:,:);
DL = DL+1;
text = ['Calibration of Debris Link node number ' nNodo ' downloaded correctly'];
fprintf(fileID,fmt,text);
end
else
ok = ['Calibration parameters of Debris Link node number ' nNodo ' NOT downloaded because the node is Murata MEMS'];
fprintf(fileID,fmt,ok);
end
end
end
text = 'NuovaConversione function started';
fprintf(fileID,fmt,text);
% Nuova conversione da fare per il nuovo database
[DCalRSNTot,DCalRSNHRTot,DCalLLTot,DCalDLTot] = NuovaConversione(DCalRSNTot,...
DCalRSNHRTot,DCalLLTot,DCalDLTot);
text = 'NuovaConversione & letturaCal functions ended';
fprintf(fileID,fmt,text);
fclose(fileID);
end

93
RSN/loadcell.m Executable file
View File

@@ -0,0 +1,93 @@
%% Funzione che elabora i Load Link
function [LoadDef,ErrLoadLink,ARRAYdateLL] = loadcell(LoadDef,ErrLoadLink,...
ARRAYdateLL,NuovoZeroLL,NdatiMedia,Ndatidespike,yesRSN,IDcentralina,DTcatena,FileName)
% Inizio del ciclo di elaborazione
text = 'loadcell function started';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
if NuovoZeroLL == 1
if NdatiMedia > Ndatidespike
Ndati = NdatiMedia;
else
Ndati = Ndatidespike;
end
ini = round(Ndati/2)+1;
if rem(Ndati,2) == 0
ini = ini+1;
end
clear NDati
LoadDef = LoadDef(ini:end,:);
ARRAYdateLL = ARRAYdateLL(ini:end,1);
ErrLoadLink = ErrLoadLink(ini:end,:);
end
if yesRSN == 1 % filtro SOLO le celle connesse a un modulo BPM
newdata = 0; % n° dati filtrati
[rLL,cLL]=size(LoadDef);
CelleUpdate = ['' IDcentralina '-' DTcatena '-LoadCell.csv'];
if isfile(CelleUpdate) == 1
ValoriCelle = csvread(CelleUpdate);
ValoriCelle(:,1) = ValoriCelle(:,1) + 730000;
for n = 1:cLL % celle
for d = 1:rLL %date
if LoadDef(d,n) < -50 % kN
if d == 1
[~,cC] = size(ValoriCelle);
if cC ~= 1
LastData = find(ValoriCelle(:,1)<datenum(ARRAYdateLL(1,1)));
if isempty(LastData) == 0
LoadDef(d,n) = ValoriCelle(LastData(end),n+1);
ErrLoadLink(d,n) = 1;
newdata = newdata+1;
end
end
else
LoadDef(d,n) = LoadDef(d-1,n);
ErrLoadLink(d,n) = 1;
newdata = newdata + 1;
end
end
end
end
end
text = ['--- Load Link elaboration: ' num2str(newdata) ' data filtered. ---'];
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
if isempty(LoadDef) == 0 && isfile(CelleUpdate) == 1
Nuovedate = [ValoriCelle(:,1); ARRAYdateLL];
Nuovivalori = [ValoriCelle(:,2); LoadDef];
Nuovofile = [Nuovedate Nuovivalori];
elseif isempty(LoadDef) == 0
Nuovofile = [ARRAYdateLL LoadDef];
else
Nuovofile = [ValoriCelle(:,1) ValoriCelle(:,2)];
end
[rN,~] = size(Nuovofile);
% scrivo sul csv solo dati compresi al massimo nei 30 gg precedenti
Datimese = find(Nuovofile(:,1) < now-30);
if isempty(Datimese) == 0 && Datimese(end) ~= rN
Nuovofile = Nuovofile(Datimese(end)+1:end,:);
end
if isfile(CelleUpdate) == 1
delete(CelleUpdate);
end
Nuovofile(:,1) = Nuovofile(:,1) - 730000;
csvwrite(CelleUpdate,Nuovofile);
end
text = 'Load Link elaborated correctly';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end

14
RSN/matrici_vuote_RSN.m Executable file
View File

@@ -0,0 +1,14 @@
function [AlfaX,AlfaY,TempDef,ARRAYdateRSN] = matrici_vuote_RSN(FileName)
AlfaX = [];
AlfaY = [];
TempDef = [];
ARRAYdateRSN = [];
text = 'RSN Link has not been elaborated. matrici_vuote_RSN execued';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end

15
RSN/matrici_vuote_RSNHR.m Executable file
View File

@@ -0,0 +1,15 @@
function [AlfaX_HR,AlfaY_HR,TempDef_RSNHR] = matrici_vuote_RSNHR(FileName)
AlfaX_HR = [];
AlfaY_HR = [];
TempDef_RSNHR = [];
text = 'RSN Link HR has not been elaborated. matrici_vuote_RSNHR function executed';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);
end

17
RSN/schema.m Executable file
View File

@@ -0,0 +1,17 @@
% Funzione che mi ricostruisce la composizione della catena
function catena = schema(idTool,conn,FileName)
text = 'Schema function started';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
comando = ['select nodetype_id, depth, num from nodes where tool_id = ''' idTool ''' order by num'];
catena = fetch(conn,comando);
text = 'Schema function ended';
fprintf(fileID,fmt,text);
fclose(fileID);
end

45
RSN/scrivo.m Executable file
View File

@@ -0,0 +1,45 @@
% Funzione che attiva o disattiva la scrittura dei sensori
function [scrivoRSN,scrivoRSN_HR,scrivoLL,scrivoTrL,scrivoSS] = scrivo(AlfaX,...
AlfaX_HR,LoadDef,val_TrL,val_SS)
%% RSN Link
RSN = isempty(AlfaX);
if RSN == 1
scrivoRSN = 0;
else
scrivoRSN = 1;
end
%% RSN Link HR
RSN_HR = isempty(AlfaX_HR);
if RSN_HR == 1
scrivoRSN_HR = 0;
else
scrivoRSN_HR = 1;
end
%% Load Link
LL = isempty(LoadDef);
if LL == 1
scrivoLL = 0;
else
scrivoLL = 1;
end
%% Trigger Link
TrL = isempty(val_TrL);
if TrL == 1
scrivoTrL = 0;
else
scrivoTrL = 1;
end
%% Shock Sensor
SS = isempty(val_SS);
if SS == 1
scrivoSS = 0;
else
scrivoSS = 1;
end
end

256
RSN/tipologiaNodi.m Executable file
View File

@@ -0,0 +1,256 @@
% Funzione che ricostruisce la tipologia di nodi presenti
% NodoRSNLink ad esempio contiene numero del nodo e profondità per tutti i
% nodi di questo tipo
% idTool rappresenta l'identificativo con cui sono definite le
% installazioni su DB, serve più avanti nell'elaborazione
% idNode scrive gli identificativi dei nodi del DB. E' un output di
% controllo
function [idTool,NodoRSNLink,NodoSS,NodoRSNLinkHR,NodoRSNLinkHR3D,NodoLoadLink,...
NodoTriggerLink,NodoGflowLink,NodoGshockLink,NodoDebrisLink] = tipologiaNodi(...
DTcatena,unitID,conn,FileName)
%% Informazioni e credenziali relative al DataBase da leggere
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'tipologiaNodi function started';
fprintf(fileID,fmt,text);
%% A partire dal nome della catena, risalgo all'identificativo con cui è
% definita nel Database (mi serve successivamente)
comando = ['select id from tools where name = ''' DTcatena ''' and unit_id = ''' num2str(unitID) ''' '];
idTool = num2str(cell2mat(fetch(conn,comando))); % leggo e converto in stringa
%% RSN Link
% carico le informazioni relative al numero e alla profondità per RSN LINK
comando = ['select num, depth, measurment from nodes where tool_id = ''' idTool ''' and nodetype_id = 38 order by num'];
Leggo = fetch(conn,comando);
[rL,cL] = size(Leggo);
if rL <= 1 && cL <= 1
textRSN = 'There are no RSN Link; ';
NodoRSNLink = [];
nodoRSN = 0; % mi serve nei RSN Link HR3D (SVILUPPO FUTURO?)
else
nodoRSN = 1; % mi serve nei RSN Link HR3D (SVILUPPO FUTURO?)
depth = cell2mat(Leggo(:,2));
depth = num2cell(depth);
nome = cell(rL,1);
for i=1:rL
nome(i,1) = cellstr('RSN Link');
end
NodoRSNLink = [nome Leggo(:,1) depth Leggo(:,3)];
textRSN = ['There are ',num2str(rL),' RSN Link nodes; '];
end
fprintf(fileID,fmt,textRSN);
%% Shock Sensor
% carico le informazioni relative al numero e alla profondità per SHOCK SENSOR
comando = ['select num, depth, measurment from nodes where tool_id = ''' idTool ''' and nodetype_id = 54 order by num'];
Leggo = fetch(conn,comando);
[rL,cL] = size(Leggo);
if rL <= 1 && cL <= 1
textSS = 'There are no Shock Sensor; ';
NodoSS = [];
else
depth = cell2mat(Leggo(:,2));
depth = num2cell(depth);
nome = cell(rL,1);
for i=1:rL
nome(i,1) = cellstr('Shock Sensor');
end
NodoSS = [nome Leggo(:,1) depth Leggo(:,3)];
textSS = ['There are ',num2str(rL),' Shock Sensor nodes; '];
end
fprintf(fileID,fmt,textSS);
%% RSN Link HR
% carico le informazioni relative al numero e alla profondità per
% RSN LINK HR
comando = ['select num, depth, measurment from nodes where tool_id = ''' idTool ''' and nodetype_id = 39 order by num'];
Leggo = fetch(conn,comando);
[rL,cL] = size(Leggo);
if rL <= 1 && cL <= 1
textRSNHR = 'There are not RSN HR Link; ';
NodoRSNLinkHR = [];
nodoRSNHR = 0; % mi serve nei RSN Link HR3D (SVILUPPO FUTURO?)
else
nodoRSNHR = 1; % mi serve nei RSN Link HR3D (SVILUPPO FUTURO?)
depth = cell2mat(Leggo(:,2));
depth = num2cell(depth);
nome = cell(rL,1);
for i=1:rL
nome(i,1) = cellstr('RSN Link HR');
end
NodoRSNLinkHR = [nome Leggo(:,1) depth Leggo(:,3)];
textRSNHR = ['There are ',num2str(rL),' RSN Link HR nodes; '];
end
fprintf(fileID,fmt,textRSNHR);
% confrontando le profondità di RSN Link e RSN Link HR riconosco i RSN LINK HR 3D
if nodoRSN == 1 && nodoRSNHR == 1
[rRSN,~] = size(NodoRSNLink);
[rRSNHR,~] = size(NodoRSNLinkHR);
NodoRSNLinkHR3Dwork = cell(rRSN,4); % creo matrice di zeri
p=1;
Control = 0;
for i=1:rRSN
for j=1:rRSNHR
if cell2mat(NodoRSNLink(i,3)) == cell2mat(NodoRSNLinkHR(j,3))
prof = NodoRSNLink(i,3);
nome = cellstr('RSN Link HR 3D');
% il numero nodo del RSN Link lo faccio diventare il numero nodo del RSN Link HR3D
num = NodoRSNLink(i,2);
num2 = NodoRSNLinkHR(j,2);
Leggo = [nome,num,num2,prof];
NodoRSNLinkHR3Dwork(p,:) = Leggo;
p = p+1;
Control = 1;
break
end
end
end
% elimino gli zeri in più
q = 1;
rL = 0;
[s,~] = size(NodoRSNLinkHR3Dwork);
a = 1;
while a == 1
if q > s
a = 0;
else
if strcmp(cell2mat(NodoRSNLinkHR3Dwork(q,1)),'RSN Link HR 3D')
rL = 1+rL; % ultima riga con dati che non siano celle vuote
end
end
q = q+1;
end
if Control == 1
NodoRSNLinkHR3D = NodoRSNLinkHR3Dwork(1:rL,:);
elseif Control == 0
NodoRSNLinkHR3D = [];
end
textRSNHR3D = ['There are ',num2str(rL),' RSN Link HR 3D nodes; '];
else
textRSNHR3D = 'There are no RSN Link HR 3D; ';
NodoRSNLinkHR3D = [];
end
fprintf(fileID,fmt,textRSNHR3D);
%% Load Link
% carico le informazioni relative al numero e alla profondità per LOAD LINK
comando = ['select num, depth, measurment from nodes where tool_id = ''' idTool ''' and nodetype_id = 15 order by num'];
curs = exec(conn,comando);
curs = fetch(curs);
Leggo = curs.Data;
[rL,cL] = size(Leggo);
if rL == 1 && cL == 1
textLL = 'There are not Load Link; ';
NodoLoadLink = [];
else
depth = cell2mat(Leggo(:,2));
depth = num2cell(depth);
nome = cell(rL,1);
for i=1:rL
nome(i,1) = cellstr('Load Link');
end
NodoLoadLink = [nome Leggo(:,1) depth Leggo(:,3)];
% inverto la matrice Nodi (il primo nodo è il più profondo)
textLL = ['There are ',num2str(rL),' Load Link nodes; '];
end
fprintf(fileID,fmt,textLL);
%% Trigger Link
% carico le informazioni relative al numero e alla profondità per TRIGGER LINK
comando = ['select num, depth, measurment from nodes where tool_id = ''' idTool ''' and nodetype_id = 40 order by num'];
curs = exec(conn,comando);
curs = fetch(curs);
Leggo = curs.Data;
[rL,cL] = size(Leggo);
if rL == 1 && cL == 1
textTrL = 'There are not Trigger Link; ';
NodoTriggerLink = [];
else
depth = cell2mat(Leggo(:,2));
depth = num2cell(depth);
nome = cell(rL,1);
for i=1:rL
nome(i,1) = cellstr('Trigger Link');
end
NodoTriggerLink = [nome Leggo(:,1) depth Leggo(:,3)];
% inverto la matrice Nodi (il primo nodo è il più profondo)
textTrL = ['There are ',num2str(rL),' Trigger Link nodes; '];
end
fprintf(fileID,fmt,textTrL);
%% G-Flow Link
comando = ['select num, depth, measurment from nodes where tool_id = ''' idTool ''' and nodetype_id = 48 order by num'];
curs = exec(conn,comando);
curs = fetch(curs);
Leggo = curs.Data;
[rL,cL] = size(Leggo);
if rL == 1 && cL == 1
textGFL = 'There are not G-Flow Link; ';
NodoGflowLink = [];
else
depth = cell2mat(Leggo(:,2));
depth = num2cell(depth);
nome = cell(rL,1);
for i=1:rL
nome(i,1) = cellstr('G-Flow Link');
end
NodoGflowLink = [nome Leggo(:,1) depth Leggo(:,3)];
% inverto la matrice Nodi (il primo nodo è il più profondo)
textGFL = ['There are ',num2str(rL),' G-Flow Link nodes; '];
end
fprintf(fileID,fmt,textGFL);
%% G-Shock Link
comando = ['select num, depth, measurment from nodes where tool_id = ''' idTool ''' and nodetype_id = 50 order by num'];
curs = exec(conn,comando);
curs = fetch(curs);
Leggo = curs.Data;
[rL,cL] = size(Leggo);
if rL == 1 && cL == 1
textGS = 'There are not G-Shock Link; ';
NodoGshockLink = [];
else
depth = cell2mat(Leggo(:,2));
depth = num2cell(depth);
nome = cell(rL,1);
for i=1:rL
nome(i,1) = cellstr('G-Shock Link');
end
NodoGshockLink = [nome Leggo(:,1) depth Leggo(:,3)];
% inverto la matrice Nodi (il primo nodo è il più profondo)
textGS = ['There are ',num2str(rL),' G-Shock Link nodes; '];
end
fprintf(fileID,fmt,textGS);
%% Debris Link
comando = ['select num, depth, measurment from nodes where tool_id = ''' idTool ''' and nodetype_id = 49 order by num'];
curs = exec(conn,comando);
curs = fetch(curs);
Leggo = curs.Data;
[rL,cL] = size(Leggo);
if rL == 1 && cL == 1
textDL = 'There are not Debris Link; ';
NodoDebrisLink = [];
else
depth = cell2mat(Leggo(:,2));
depth = num2cell(depth);
nome = cell(rL,1);
for i=1:rL
nome(i,1) = cellstr('Debris Link');
end
NodoDebrisLink = [nome Leggo(:,1) depth Leggo(:,3)];
% inverto la matrice Nodi (il primo nodo è il più profondo)
textDL = ['There are ',num2str(rL),' Debris Link nodes; '];
end
fprintf(fileID,fmt,textDL);
text = 'Nodes defined correctly and tipologiaNodi function closed';
fprintf(fileID,fmt,text);
fclose(fileID);
end