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

141
ATD/defDatiPCLHR.m Executable file
View File

@@ -0,0 +1,141 @@
% Funzione che definisce angoli (ang_PCLHR), temperature (tempPCLHR),
% date (TimePCLHR) per i nodi di tipo PreConv Link HR
function [TimePCLHR,angPCLHR,tempPCLHR,ErrPreConvLinkHR] = defDatiPCLHR(...
DatiPreConvLinkHR,ErrPreConvLinkHR,NodoPreConvLinkHR,Ndatidespike,rPCLHR,IDcentralina,...
DTcatena,FileName)
fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'defDatiPCLHR function started';
fprintf(fileID,fmt,text);
[r,c] = size(DatiPreConvLinkHR);
Ncorr = 0;
% Elimino gli eventuali Not a Number
for a = 2:r
for b = 2:c
check = isnan(DatiPreConvLinkHR(a,b));
if check == 1
DatiPreConvLinkHR(a,b) = DatiPreConvLinkHR(a-1,b);
ErrPreConvLinkHR(a,b-1) = 1;
Ncorr = Ncorr+1;
end
end
end
text = ['' num2str(Ncorr) ' NaN of PreConv Link HR corrected by defDatiPCLHR function'];
fprintf(fileID,fmt,text);
% Definisco Data (gg:mm:aaaa hh:mm), Batteria, i 2 dati di accelerometro
% e la Temperatura
TimePCLHR = DatiPreConvLinkHR(:,1); % data
angPCLHR = zeros(r,rPCLHR*2); % dati angoli
controllo_PCLHR = zeros(r,rPCLHR*3);
tempPCLHR = zeros(r,rPCLHR); % temperatura del nodo per la calibrazione
ctl = 1;
p = 2; % passo
s = 1;
for i = 1:rPCLHR
angPCLHR(:,s_s+1) = DatiPreConvLinkHR(:,p:p+1);
s = s+2;
controllo_PCLHR(:,ctl:ctl+2) = DatiPreConvLinkHR(:,p+2:p+4);
ctl = ctl+3;
tempPCLHR(:,i) = DatiPreConvLinkHR(:,p+5);
p = p+6;
end
s = 1;
Num_Dati = Ndatidespike; % numero di dati per il despike
if Num_Dati > r
Num_Dati = r;
end
for i = 1:rPCLHR
% despiking cella elettrolitica
angPCLHR(:,s) = filloutliers(angPCLHR(:,s),'linear','movmedian',Num_Dati);
angPCLHR(:,s+1) = filloutliers(angPCLHR(:,s+1),'linear','movmedian',Num_Dati);
s = s+2;
end
%% !!! Controllo che le ampolle non siano fuori scala (32768)
AmpolleUpdate = ['' IDcentralina '-' DTcatena '-Ampolle.csv'];
Dati = csvread(AmpolleUpdate);
[rD,~] = size(Dati);
[rC,cC] = size(angPCLHR);
if rD ~= 0
for j = 1:rC
for ii = 1:cC
segno1 = 0;
for a = 2:rD
if TimePCLHR(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(angPCLHR(j-1,ii)); % segno del valore alla data precedente
end
end
segno2 = sign(angPCLHR(j,ii)); % segno del valore alla data successiva
if segno2 ~= segno1 % se i due segni sono diversi
if abs(angPCLHR(j,ii)) > 15000
if segno1 == 1
angPCLHR(j,ii) = 32768 + (32768 + angPCLHR(j,ii)); % Fondo scala positivo
elseif segno1 == -1
angPCLHR(j,ii) = -32768 + (-32768 + angPCLHR(j,ii)); % Fondo scala negativo
end
text = ['PreConv Link HR was out of range on node ' NodoPreConvLinkHR(ii/2,2) ''];
fprintf(fileID,fmt,text);
end
end
end
end
indice = 1;
for j=1:rC
if Dati(end,1) == TimePCLHR(j,1)
indice = j+1;
break
end
end
else
indice = 1;
end
%% Controllo che l'ampolla non venga letta come MEMS!
index = 1;
nodo = 1;
for b = 1:rPCLHR % nodi
for a = 1:rC % date
if controllo_PCLHR(a,index)~=0 && controllo_PCLHR(a,index+1)~=0 && controllo_PCLHR(a,index+2)~=0
if a == 1
for aa = 2:rD
if TimePCLHR(a,1) == Dati(aa,1)
angPCLHR(a,2*nodo-1:2*nodo) = Dati(aa-1,2*nodo:2*nodo+1); % valore alla data precedente
break
end
end
else
angPCLHR(a,2*nodo-1:2*nodo) = angPCLHR(a-1,2*nodo-1:2*nodo);
end
ErrPreConvLinkHR(a,2*nodo-1:2*nodo) = 1;
end
end
index = index+3;
nodo = nodo+1;
end
if isempty(indice) == 0
datiHRH = [TimePCLHR(indice:end,1) angPCLHR(indice:end,:)];
dat=isempty(datiHRH);
if dat==0
delete(AmpolleUpdate);
csvwrite(AmpolleUpdate,datiHRH);
end
end
text = 'Data of PreConv Link HR defined correctly. defDatiPCLHR function closed';
fprintf(fileID,fmt,text);
fclose(fileID);
end