clear all;
clc;
close all;

NA = 12; %num nodi ancora

RSSI_NA = zeros(104,NA);
num_Tot_rilev = zeros(104,1);
log = [];

for k=1:104
    
num_ric_NA = zeros(1,NA);
fid = fopen(['log' num2str(k) '.txt'], 'r');
tline = fgetl(fid);

while feof(fid) == 0
   num_Tot_rilev(k,1) = num_Tot_rilev(k,1)+1;
   tline = fgetl(fid);
   v = findstr(tline,'  ');
   a = v(1)+3;
   b = v(2)-2;
   ID = hex2dec(tline(a:b));
   if ID>=1 && ID<=12 
      RSSI = hex2dec(tline(2:v(1)-2));
      RSSI = dec2bin(RSSI,8);
      RSSI = mvl2dec(RSSI,true);
      if RSSI>=-60 && RSSI<=40
          num_ric_NA(ID) = num_ric_NA(ID)+1;
          RSSI_NA(k,ID) = RSSI_NA(k,ID)+RSSI;
      end
   end
end
fclose(fid);

for ID=1:NA
      if num_ric_NA(ID)~= 0
          RSSI_NA(k,ID) = RSSI_NA(k,ID)/num_ric_NA(ID);
      else
          RSSI_NA(k,ID) = -70;
      end
end

end

training_X = [];
test_X = [];

l=1;
for k=1:2:103
    training_X(l,:) = RSSI_NA(k,:);
    test_X(l,:) = RSSI_NA(k+1,:);
    l=l+1;
end

% save RSSI_rilevazioni training_X test_X
