196 lines
6.7 KiB
Matlab
Executable File
196 lines
6.7 KiB
Matlab
Executable File
% Funzione che definisce accelerazioni, dati magnetici, temperature, date e
|
|
% livello della batteria per i nodi di tipo Tilt Link
|
|
function [TimeIPLHR,angIPLHR,tempIPLHR,ErrInPlaceLinkHR] = defDatiIPLHR(...
|
|
DatiInPlaceLinkHR,ErrInPlaceLinkHR,Ndatidespike,rIPLHR,NodoInPlaceLinkHR,...
|
|
NuovoZeroIPLHR,IDcentralina,DTcatena,Unit,FileName)
|
|
|
|
fileID = fopen(FileName,'a');
|
|
fmt = '%s \r';
|
|
text = 'defDatiIPLHR function started';
|
|
fprintf(fileID,fmt,text);
|
|
|
|
[r,c]=size(DatiInPlaceLinkHR);
|
|
Ncorr = 0;
|
|
% Elimino gli eventuali Not a Number
|
|
for a = 2:r % Date
|
|
for b = 1:c
|
|
check = isnan(DatiInPlaceLinkHR(a,b));
|
|
if check == 1
|
|
DatiInPlaceLinkHR(a,b) = DatiInPlaceLinkHR(a-1,b);
|
|
ErrInPlaceLinkHR(a,b-1) = 1;
|
|
Ncorr = Ncorr+1;
|
|
end
|
|
end
|
|
end
|
|
|
|
text = [num2str(Ncorr) ' NaN of In Place Link HR corrected by defDatiIPLHR function'];
|
|
fprintf(fileID,fmt,text);
|
|
|
|
TimeIPLHR = DatiInPlaceLinkHR(:,1); % data
|
|
angIPLHR = zeros(r,rIPLHR*2); % dati angolari
|
|
|
|
if strcmp(NodoInPlaceLinkHR(1,4),'ADC') || strcmp(NodoInPlaceLinkHR{1,4} ,'null') || isempty(NodoInPlaceLinkHR{1,4}) == 1
|
|
controllo_IPLHR = zeros(r,rIPLHR*3);
|
|
tempIPLHR = zeros(r,rIPLHR); % temperatura del nodo per la calibrazione
|
|
ctl = 1;
|
|
p = 2; % passo
|
|
s = 1;
|
|
for i = 1:rIPLHR
|
|
angIPLHR(:,s:s+1) = DatiInPlaceLinkHR(:,p:p+1);
|
|
s = s+2;
|
|
controllo_IPLHR(:,ctl:ctl+2) = DatiInPlaceLinkHR(:,p+2:p+4);
|
|
ctl = ctl+3;
|
|
tempIPLHR(:,i) = DatiInPlaceLinkHR(:,p+5);
|
|
p = p+6;
|
|
end
|
|
elseif strcmp(NodoInPlaceLinkHR{1,4} ,'digit')
|
|
tempIPLHR = zeros(r,rIPLHR); % temperatura del nodo per la calibrazione
|
|
p = 2; % passo
|
|
s = 1;
|
|
for i = 1:rIPLHR
|
|
angIPLHR(:,s:s+1) = DatiInPlaceLinkHR(:,p:p+1);
|
|
s = s+2;
|
|
tempIPLHR(:,i) = DatiInPlaceLinkHR(:,p+2);
|
|
p = p+3;
|
|
end
|
|
end
|
|
|
|
if strcmp(Unit,'G301') == 1
|
|
i = 1;
|
|
j = 1;
|
|
C = 1;
|
|
while i <= 2*rIPLHR
|
|
for ii = 2:r
|
|
if angIPLHR(ii,i) == -8191 && angIPLHR(ii,i+1) == 0 && controllo_IPLHR(ii,C) == 0 ...
|
|
&& controllo_IPLHR(ii,C+1) == 0 && controllo_IPLHR(ii,C+2) == 0
|
|
angIPLHR(ii,i) = angIPLHR(ii-1,i);
|
|
angIPLHR(ii,i+1) = angIPLHR(ii-1,i+1);
|
|
tempIPLHR(ii,j) = tempIPLHR(ii-1,j);
|
|
ErrInPlaceLinkHR(ii,i) = 1;
|
|
end
|
|
end
|
|
i = i+2;
|
|
j = j+1;
|
|
C = C+3;
|
|
end
|
|
end
|
|
|
|
s = 1;
|
|
Num_Dati = Ndatidespike; % numero di dati per il despike
|
|
if Num_Dati > r
|
|
Num_Dati = r;
|
|
end
|
|
for i = 1:rIPLHR
|
|
% despiking accelerometri
|
|
angIPLHR(:,s) = filloutliers(angIPLHR(:,s),'linear','movmedian',Num_Dati);
|
|
angIPLHR(:,s+1) = filloutliers(angIPLHR(:,s+1),'linear','movmedian',Num_Dati);
|
|
s = s+2;
|
|
end
|
|
|
|
%% !!! Controllo che le ampolle non siano fuori scala (32768)
|
|
if strcmp(NodoInPlaceLinkHR(1,4),'ADC') || strcmp(NodoInPlaceLinkHR{1,4} ,'null') || isempty(NodoInPlaceLinkHR{1,4}) == 1
|
|
[rC,cC] = size(angIPLHR);
|
|
AmpolleUpdate = ['' IDcentralina '-' DTcatena '-Ampolle.csv'];
|
|
if NuovoZeroIPLHR == 1
|
|
Dati = csvread(AmpolleUpdate);
|
|
Dati(:,1) = Dati(:,1) + 730000;
|
|
[rD,~] = size(Dati);
|
|
num = 1;
|
|
cont = 1;
|
|
if rD ~= 0
|
|
for j = 1:rC
|
|
for ii = 1:cC
|
|
segno1 = 0;
|
|
if j == 1
|
|
for a = 2:rD
|
|
if TimeIPLHR(j,1) >= Dati(a,1)
|
|
segno1 = sign(Dati(a-1,ii+1)); % segno del valore alla data precedente
|
|
break
|
|
end
|
|
end
|
|
end
|
|
if segno1 == 0
|
|
if j == 1
|
|
else
|
|
segno1 = sign(angIPLHR(j-1,ii)); % segno del valore alla data precedente
|
|
end
|
|
end
|
|
segno2 = sign(angIPLHR(j,ii)); % segno del valore alla data successiva
|
|
if segno2 ~= segno1 % se i due segni sono diversi
|
|
if abs(angIPLHR(j,ii)) > 15000
|
|
if segno1 == 1
|
|
angIPLHR(j,ii) = 32768 + (32768 + angIPLHR(j,ii)); % Fondo scala positivo
|
|
elseif segno1 == -1
|
|
angIPLHR(j,ii) = -32768 + (-32768 + angIPLHR(j,ii)); % Fondo scala negativo
|
|
end
|
|
text = ['In Place Link HR was out of range on node ' mat2str(cell2mat(NodoInPlaceLinkHR(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) == TimeIPLHR(j,1)
|
|
indice = j+1;
|
|
break
|
|
end
|
|
end
|
|
else
|
|
indice = [];
|
|
end
|
|
else
|
|
indice = 1;
|
|
end
|
|
|
|
%% Controllo che l'ampolla non venga letta come MEMS!
|
|
index = 1;
|
|
nodo = 1;
|
|
for b = 1:rIPLHR % nodi
|
|
for a = 1:rC % date
|
|
if controllo_IPLHR(a,index)~=0 && controllo_IPLHR(a,index+1)~=0 && controllo_IPLHR(a,index+2)~=0
|
|
if a == 1
|
|
if NuovoZeroIPLHR == 1
|
|
for aa = 2:rD
|
|
if TimeIPLHR(a,1) == Dati(aa,1)
|
|
angIPLHR(a,2*nodo-1:2*nodo) = Dati(aa-1,2*nodo:2*nodo+1); % valore alla data precedente
|
|
break
|
|
end
|
|
end
|
|
end
|
|
else
|
|
angIPLHR(a,2*nodo-1:2*nodo) = angIPLHR(a-1,2*nodo-1:2*nodo);
|
|
end
|
|
ErrInPlaceLinkHR(a,2*nodo-1:2*nodo) = 1;
|
|
end
|
|
end
|
|
index = index+3;
|
|
nodo = nodo+1;
|
|
end
|
|
if isempty(indice) == 0
|
|
Dati = TimeIPLHR(indice:end,1);
|
|
Dati(:,1) = Dati(:,1) - 730000;
|
|
datiHR = [Dati(:,1) angIPLHR(indice:end,:)];
|
|
dat=isempty(datiHR);
|
|
if dat==0
|
|
if NuovoZeroIPLHR == 1
|
|
delete(AmpolleUpdate);
|
|
end
|
|
csvwrite(AmpolleUpdate,datiHR);
|
|
end
|
|
end
|
|
end
|
|
|
|
text = 'Data of In Place Link HR defined correctly. defDatiIPLHR function ended';
|
|
fprintf(fileID,fmt,text);
|
|
fclose(fileID);
|
|
|
|
end
|