close all
clear all

if(1)
filenames = { ...
    '2024.09.16T07.06.40_raw', ...
    '2024.09.16T08.06.43_raw', ...
    '2024.09.16T08.51.04_raw', ...
    '2024.09.16T09.51.06_raw', ...
    '2024.09.16T10.51.08_raw', ...
    '2024.09.16T11.51.10_raw', ...
    '2024.09.16T12.51.12_raw', ...
    '2024.09.16T13.51.14_raw', ...
    '2024.09.16T14.51.17_raw', ...
};

else
filenames = { ...
    '2024.09.17T18.52.14_raw', ...
    '2024.09.17T19.52.16_raw', ...
};
end


data = load(['..\DecodedResults\' filenames{1}]);
for i = 2:length(filenames)
    data_tmp = load(['..\DecodedResults\' filenames{i}]);
    data.PC_Time = [data.PC_Time; data_tmp.PC_Time];
    data.PC_RPM = [data.PC_RPM; data_tmp.PC_RPM];
    data.PC_Voltage = [data.PC_Voltage; data_tmp.PC_Voltage];
    data.PC_WindingCurrent = [data.PC_WindingCurrent; data_tmp.PC_WindingCurrent];
    data.PC_BattCurr = [data.PC_BattCurr; data_tmp.PC_BattCurr];
    data.PC_LoadCurr = [data.PC_LoadCurr; data_tmp.PC_LoadCurr];
    data.PC_TargCurr = [data.PC_TargCurr; data_tmp.PC_TargCurr];

    data.BC_Time = [data.BC_Time; data_tmp.BC_Time];
    data.BC_GroundFault = [data.BC_GroundFault; data_tmp.BC_GroundFault];
    data.BC_Voltage = [data.BC_Voltage; data_tmp.BC_Voltage];  

end

n_plots = 6; k = 1;
figure('Position',[836 48 1057 1383]);
ah(k) = subplot(n_plots,1,k); k = k+1;
plot(data.PC_Time,data.PC_RPM,'x');
%xlabel('time');
ylabel('RPM');
datetick('x');
grid on;
title([filenames{1} ' -> ' filenames{end}])

ah(k) = subplot(n_plots,1,k); k = k+1;
plot(data.PC_Time,data.PC_Voltage,'x');
hold all
plot(data.BC_Time,data.BC_Voltage,'x');
legend('PC Voltage','Batt Voltage');
%xlabel('time');
ylabel('Voltage');
datetick('x');
grid on;


ah(k) = subplot(n_plots,1,k); k = k+1;
plot(data.PC_Time,data.PC_WindingCurrent,'x');
hold all
plot(data.PC_Time,data.PC_TargCurr,'x');
legend('Winding Curr','Targ Curr');
%xlabel('time');
ylabel('Winding Current');
datetick('x');
grid on;

ah(k) = subplot(n_plots,1,k); k = k+1;
plot(data.PC_Time,data.PC_LoadCurr,'x');
%xlabel('time');
ylabel('Load Current');
datetick('x');
grid on;

ah(k) = subplot(n_plots,1,k); k = k+1;
plot(data.PC_Time,data.PC_BattCurr,'x');
%xlabel('time');
ylabel('Batt Current');
datetick('x');
grid on;


ah(k) = subplot(n_plots,1,k); k = k+1;
plot(data.BC_Time,data.BC_GroundFault,'x');
xlabel('time');
ylabel('Ground Fault');
datetick('x');
grid on;


linkaxes(ah,'x');
