Code covered by the BSD License  

Highlights from
Task Scheduler beta

image thumbnail

Task Scheduler beta

by

 

This GUI application makes possible to schedule a set of tasks using classical scheduling protocol.

TaskScheduler(varargin)
function varargout = TaskScheduler(varargin)
% TASKSCHEDULER M-file for TaskScheduler.fig
%      TASKSCHEDULER, by itself, creates a new TASKSCHEDULER or raises the existing
%      singleton*.
%
%      H = TASKSCHEDULER returns the handle to a new TASKSCHEDULER or the handle to
%      the existing singleton*.
%
%      TASKSCHEDULER('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in TASKSCHEDULER.M with the given input arguments.
%
%      TASKSCHEDULER('Property','Value',...) creates a new TASKSCHEDULER or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before TaskScheduler_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to TaskScheduler_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help TaskScheduler

% Last Modified by GUIDE v2.5 20-Jan-2013 15:34:11

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @TaskScheduler_OpeningFcn, ...
                   'gui_OutputFcn',  @TaskScheduler_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
end
% --- Executes just before TaskScheduler is made visible.
function TaskScheduler_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to TaskScheduler (see VARARGIN)

% Choose default command line output for TaskScheduler
handles.output = hObject;
movegui(hObject,'center');
% Update handles structure
set(handles.edit1,'TooltipString','<html>Insert the number of tasks to schedule.');
set(handles.edit4,'TooltipString','<html>It models the time taken to switch between tasks.<br/> This parameter is still experimental and could provoque unexpected behavior.');
set(handles.edit3,'TooltipString','<html>It is the calculation step. All parameters shall be a multiple of this value.<br/> A non-optimized value (beta) is given by Step_Adviced in the output frame.');
set(handles.radiobutton5,'TooltipString','<html>The Hyperperiod is the Least Common Multiple of all the tasks'' period.<br/> To be schedulable on the hyperperiod is a sufficient condition to prove the schedulability of a task.<br/> However, the calculation can be long. ');
set(handles.radiobutton6,'TooltipString','<html>Select Custom if you prefer to set your own limit of runtime.<br/>It is extremely usefull to shorten the time execution of the script');
set(handles.uitable2,'TooltipString','<html>It contains all the tasks parameters:<br/> + Phase: The task will be available to scheduling at that time.<br/> + Period: Task''s period.<br/> + Execution Time : It indicates how long the task must execute.<br/> + Deadline : Indicate the time when the task must have finished to execute.');
set(handles.pushbutton12,'TooltipString','<html>Load all the tasks'' parameters (table above)');
set(handles.pushbutton11,'TooltipString','<html>Save all the tasks'' parameters (table above)');
set(handles.pushbutton4,'TooltipString','<html>Useful to set or change tasks'' colors for the tasks schedule display');
set(handles.popupmenu1,'TooltipString','<html>Choose the scheduling that must be used.');
set(handles.popupmenu2,'TooltipString','<html>Indicate if one of the tasks is a Sporadic Server');
set(handles.popupmenu3,'TooltipString','<html>Indicate if one of the tasks is an Aperiodic Server and choose its type.');
set(handles.edit8,'TooltipString','<html>Indicate the number of Sporadic Jobs handled by the Server');
set(handles.edit9,'TooltipString','<html>Indicate the number of Aperiodic Jobs handled by the Server');
set(handles.edit6,'TooltipString','<html>Indicate which task is the server');
set(handles.edit7,'TooltipString','<html>Indicate which task is the server');
set(handles.uitable4,'TooltipString','<html>It contains all the sporadic jobs parameters');
set(handles.uitable5,'TooltipString','<html>It contains all the aperiodic jobs parameters');
set(handles.pushbutton14,'TooltipString','<html>Load all the parameters');
set(handles.pushbutton13,'TooltipString','<html>Save all the parameters');
set(handles.pushbutton15,'TooltipString','<html>More help...');
set(handles.pushbutton8,'TooltipString','<html>It processes all the data and calculate the schedule, the budget, the slack, the time demand analysis.<br/> RED : An error occured.<br/> ORANGE : Calculation is still going on.<br/> Green : The calculation has succeed.');
set(handles.pushbutton2,'TooltipString','<html>Draw the schedule.<br/> RED : Schedule is not available (or an error occured).<br/> ORANGE : Schedule is available.<br/> Green : Schedule has been displayed.');
set(handles.pushbutton16,'TooltipString','<html>Draw the budget.<br/> RED : Budget is not available (or an error occured).<br/> ORANGE : Budget is available.<br/> Green : Budget has been displayed.');
set(handles.pushbutton17,'TooltipString','<html>Draw the slack.<br/> RED : Slack is not available (or an error occured).<br/> ORANGE : Slack is available.<br/> Green : Slack has been displayed.');
set(handles.pushbutton1,'TooltipString','<html>Draw the time demand analysis.<br/> RED : Time demand analysis is not available (or an error occured).<br/> ORANGE : Time demand analysis is available.<br/> Green : Time demand analysis has been displayed.');
% Update handles structure
set(handles.pushbutton1,'Background','red');
set(handles.pushbutton2,'Background','red');
set(handles.pushbutton16,'Background','red');
set(handles.pushbutton17,'Background','red');
set(handles.uitable4,'Visible','off');
set(handles.text19,'Visible','off');
set(handles.text21,'Visible','off');
set(handles.edit6,'Visible','off');
set(handles.edit8,'Visible','off');
set(handles.uitable5,'Visible','off');
set(handles.text20,'Visible','off');
set(handles.text22,'Visible','off');
set(handles.edit7,'Visible','off');
set(handles.edit9,'Visible','off');
set(handles.uitable2,'data',zeros(4,5));
set(handles.uitable2,'UserData',zeros(4,5));

get(handles.uitable2,'ColumnName');
ColumnName = cell(5,1);
ColumnName = get(handles.uitable2,'ColumnName');
ColumnName{5,1} = '';
set(handles.uitable2,'ColumnName',ColumnName);
 myCell = cell(1,5);
[myCell{:,:}] = deal('numeric');
set(handles.uitable2,'ColumnFormat',myCell);
myCell = cell(1,5);
[myCell{:,:}] = deal(true);
set(handles.uitable2,'ColumnEditable',cell2mat(myCell));
myCell = cell(1,5);
[myCell{:,:}] = deal('auto');
myCell{1,5} = 0;
set(handles.uitable2,'ColumnWidth',myCell);


set(handles.uitable4,'data',zeros(4,3));
set(handles.uitable4,'UserData',zeros(4,3));

 myCell = cell(1,3);
[myCell{:,:}] = deal('numeric');
set(handles.uitable4,'ColumnFormat',myCell);
myCell = cell(1,3);
[myCell{:,:}] = deal(true);
set(handles.uitable4,'ColumnEditable',cell2mat(myCell));
myCell = cell(1,5);
[myCell{:,:}] = deal('auto');
myCell{1,4} = 0;
myCell{1,5} = 0;
set(handles.uitable4,'ColumnWidth',myCell);
set(handles.uitable5,'data',zeros(4,2));
set(handles.uitable5,'UserData',zeros(4,2));
 myCell = cell(1,2);
[myCell{:,:}] = deal('numeric');
set(handles.uitable5,'ColumnFormat',myCell);
myCell = cell(1,2);
[myCell{:,:}] = deal(true);
set(handles.uitable5,'ColumnEditable',cell2mat(myCell));
myCell = cell(1,4);
[myCell{:,:}] = deal('auto');
myCell{1,3} = 0;
myCell{1,4} = 0;
set(handles.uitable5,'ColumnWidth',myCell);



handles.TableTasksDim=5;

handles.Options.precision = -10; % means that there won't be a value smaller than 10^precision in all the processing         
                       % IMPORTANT NOTE: All other values MUST be greater than
                       % precision to get a correct behaviour.
handles.Options.CST=0.0;
handles.Options.Step=0.1;  
handles.Options.MaxTime = 0;
handles.Options.schedule = 'None';
handles.Tasks_Param.Tasks = zeros(4,4);
handles.Weight_Tasks = zeros(1,4);
handles.Tasks_Param.Nb_Tasks = 4;
%%%%%%%%%%%%%%%%%%%%%%%%% 
%%% Server options      % This server is used to schedule Jobs that come aperiodically 
%%% for Aperiodic Tasks % 
handles.Aperiodic_Param.Server='None'; % Determine which kind of Server we will use
handles.Aperiodic_Param.Aperiodic_Jobs= zeros(4,2);  %[ Phase , Execution Time ]
handles.Aperiodic_Param.Nb_Aperiodic_Jobs=4;
handles.Aperiodic_Param.Server_Status=zeros(handles.Tasks_Param.Nb_Tasks,1); % Determine which Tasks will be the server

%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Server options      % This server is used to schedule sporadic Jobs  ( Aperiodic Jobs with a deadline ) 
%%% for Sporadic Tasks  % 
handles.Sporadic_Param.Server = false;
handles.Sporadic_Param.Sporadic_Jobs = zeros(4,3); %[ Phase , Execution Time , Deadline ]
handles.Sporadic_Param.Server_Status = zeros(handles.Tasks_Param.Nb_Tasks,1);
handles.Sporadic_Param.Nb_Sporadic_Jobs = 4;
set(handles.edit3,'String',handles.Options.Step);
set(handles.edit4,'String',handles.Options.CST);
handles.Tasks_Param.Tasks = zeros(4,4);
handles.Tasks_Param.Nb_Tasks = 4;
handles.Options.color = [1 0 0;0 1 0;1 1 0;0 0 1];
%handles = Update_Colors(handles.uitable3,handles);

set(handles.text5,'String',num2str(0));
set(handles.text7,'String',num2str(0));
set(handles.text14,'String',num2str(0));
set(handles.text16,'String',num2str(0));
set(handles.text18,'String',num2str(0));
guidata(hObject, handles);
% UIWAIT makes TaskScheduler wait for user response (see UIRESUME)
% uiwait(handles.figure1);
end

% --- Outputs from this function are returned to the command line.
function varargout = TaskScheduler_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;
end


function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double
Number_Of_Tasks = str2double(get(hObject,'String'));
handles.Tasks_Param.Nb_Tasks = Number_Of_Tasks;
set(hObject,'UserData',Number_Of_Tasks);
Previous_Task_List = get(handles.uitable2,'UserData');

Previous_Number_Of_Tasks = size(Previous_Task_List,1);
    if Previous_Number_Of_Tasks ~= Number_Of_Tasks
        if Previous_Number_Of_Tasks > Number_Of_Tasks
            New_List_Of_Tasks = zeros(Number_Of_Tasks,handles.TableTasksDim)+Previous_Task_List(1:Number_Of_Tasks,:);    
        else
            New_List_Of_Tasks = zeros(Number_Of_Tasks,handles.TableTasksDim);
            New_List_Of_Tasks(1:Previous_Number_Of_Tasks,:) = New_List_Of_Tasks(1:Previous_Number_Of_Tasks,:)+Previous_Task_List(1:Previous_Number_Of_Tasks,:);             
        end
        

        set(handles.uitable2,'data',New_List_Of_Tasks);
        set(handles.uitable2,'UserData',New_List_Of_Tasks);
        handles.Weight_Tasks = New_List_Of_Tasks(:,5);
    end
    handles.Aperiodic_Param.Server_Status=zeros(handles.Tasks_Param.Nb_Tasks,1);
    handles.Sporadic_Param.Server_Status=zeros(handles.Tasks_Param.Nb_Tasks,1);
 guidata(hObject, handles);   
end
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
end

% --------------------------------------------------------------------
function Untitled_1_Callback(hObject, eventdata, handles)
% hObject    handle to Untitled_1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
end

% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu1

Popup_Value = get(hObject, 'Value');
Popup_String = get(hObject, 'String');
Schedule_Selected = Popup_String{Popup_Value};

get(handles.uitable2,'ColumnName');
ColumnName = cell(5,1);
ColumnName = get(handles.uitable2,'ColumnName');
ColumnName{5,1} = '';
set(handles.uitable2,'ColumnName',ColumnName);
 myCell = cell(1,5);
[myCell{:,:}] = deal('numeric');
set(handles.uitable2,'ColumnFormat',myCell);
myCell = cell(1,5);
[myCell{:,:}] = deal(false);
set(handles.uitable2,'ColumnEditable',cell2mat(myCell));
myCell = cell(1,5);
[myCell{:,:}] = deal('auto');
myCell{1,5} = 0;
set(handles.uitable2,'ColumnWidth',myCell);
        handles.TableTasksDim=5;

switch(Schedule_Selected)
    
    
    case{'Scheduling protocol'}
        handles.Options.schedule='None';     
    case{'Rate Monotonic Scheduling                    (RMS)'}
        handles.Options.schedule='RMS';
	case{'Deadline Monotonic Scheduling            (DMS)'}
        handles.Options.schedule='DMS';        
	case{'Earliest Deadline First Scheduling        (EDF)'}
        handles.Options.schedule='EDF'; 
	case{'Least Slack Time First Scheduling        (LST)'}
        handles.Options.schedule='LST';        
	case{'Round-Robin Scheduling                        (RRS)'}   
        handles.Options.schedule='RRS';
        get(handles.uitable2,'ColumnName');
        ColumnName = cell(5,1);
        ColumnName = get(handles.uitable2,'ColumnName');
        ColumnName{5,1} = 'Weight';
        set(handles.uitable2,'ColumnName',ColumnName);
         myCell = cell(1,5);
        [myCell{:,:}] = deal('numeric');
        set(handles.uitable2,'ColumnFormat',myCell);
        myCell = cell(1,5);
        [myCell{:,:}] = deal(true);
        set(handles.uitable2,'ColumnEditable',cell2mat(myCell));
        myCell = cell(1,5);
        [myCell{:,:}] = deal('auto');
        set(handles.uitable2,'ColumnWidth',myCell);
        handles.TableTasksDim=5;
        %TODO
	case{'Weighted Round-Robin Scheduling      (WRRS)'}
        handles.Options.schedule='WRRS';
        get(handles.uitable2,'ColumnName');
        ColumnName = cell(5,1);
        ColumnName = get(handles.uitable2,'ColumnName');
        ColumnName{5,1} = 'Weight';
        set(handles.uitable2,'ColumnName',ColumnName);
         myCell = cell(1,5);
        [myCell{:,:}] = deal('numeric');
        set(handles.uitable2,'ColumnFormat',myCell);
        myCell = cell(1,5);
        [myCell{:,:}] = deal(true);
        set(handles.uitable2,'ColumnEditable',cell2mat(myCell));
        myCell = cell(1,5);
        [myCell{:,:}] = deal('auto');
        set(handles.uitable2,'ColumnWidth',myCell);
        handles.TableTasksDim=5;
    otherwise
        handles.Options.schedule='None';     
        
end
guidata(hObject, handles);


end

% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
end


% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
end

% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
end

% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
end

% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
end

% --- Executes when entered data in editable cell(s) in uitable2.
function uitable2_CellEditCallback(hObject, eventdata, handles)
% hObject    handle to uitable2 (see GCBO)
% eventdata  structure with the following fields (see UITABLE)
%	Indices: row and column indices of the cell(s) edited
%	PreviousData: previous data for the cell(s) edited
%	EditData: string(s) entered by the user
%	NewData: EditData or its converted form set on the Data property. Empty if Data was not changed
%	Error: error string when failed to convert EditData to appropriate value for Data
% handles    structure with handles and user data (see GUIDATA)
Data_Tasks_List_TEMP = get(hObject,'data');
Data_Tasks_List =zeros(size(Data_Tasks_List_TEMP,1),size(Data_Tasks_List_TEMP,2));
if iscell(Data_Tasks_List_TEMP)
    for i=1:1:size(Data_Tasks_List_TEMP,1)
       for j=1:1:size(Data_Tasks_List_TEMP,2)
          if isnan(str2double(Data_Tasks_List_TEMP{i,j})) == 0
            Data_Tasks_List(i,j) = str2double(Data_Tasks_List_TEMP{i,j});
          else
            Data_Tasks_List(i,j) = 0;
          end
       end    
    end
else
   Data_Tasks_List = Data_Tasks_List_TEMP;
end

handles.Tasks_Param.Tasks = Data_Tasks_List(:,1:4);
handles.Tasks_Param.Nb_Tasks = size(handles.Tasks_Param.Tasks,1);
if strcmp(handles.Options.schedule,'RRS')
    if (eventdata.Indices(2) == 5)
    Data_Tasks_List(:,5) = deal(Data_Tasks_List(eventdata.Indices(1),eventdata.Indices(2)));
    end
end
set(hObject,'UserData',Data_Tasks_List);
set(hObject,'data',Data_Tasks_List);
    if ~isnumeric(Data_Tasks_List)
        error('The table must only contain number');
    end
handles.Weight_Tasks = Data_Tasks_List(:,5);
handles.Aperiodic_Param.Server_Status=zeros(handles.Tasks_Param.Nb_Tasks,1);
handles.Sporadic_Param.Server_Status=zeros(handles.Tasks_Param.Nb_Tasks,1);
guidata(hObject, handles);
end



function edit3_Callback(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit3 as text
%        str2double(get(hObject,'String')) returns contents of edit3 as a double

handles.Options.Step = str2double(get(hObject,'String'));
guidata(hObject, handles);
end

% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
end


function edit4_Callback(hObject, eventdata, handles)
% hObject    handle to edit4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit4 as text
%        str2double(get(hObject,'String')) returns contents of edit4 as a double
handles.Options.CST = str2double(get(hObject,'String'));
guidata(hObject, handles);
end

% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
end


% --- Executes on selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu2 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu2

Popup_Value = get(hObject, 'Value');
Popup_String = get(hObject, 'String');
Sporadic_Server_Selected = Popup_String{Popup_Value};
if strcmp(Sporadic_Server_Selected,'Yes')
    handles.Sporadic_Param.Server = true;
    set(handles.uitable4,'Visible','on');
    set(handles.text19,'Visible','on');
    set(handles.text21,'Visible','on');
    set(handles.edit6,'Visible','on');
    set(handles.edit8,'Visible','on');
else
    handles.Sporadic_Param.Server = false;
        set(handles.uitable4,'Visible','off');
        set(handles.text19,'Visible','off');
        set(handles.text21,'Visible','off');
        set(handles.edit6,'Visible','off');
        set(handles.edit8,'Visible','off');
end
guidata(hObject, handles);
end

% --- Executes during object creation, after setting all properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
end

% --- Executes on selection change in popupmenu3.
function popupmenu3_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu3 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from
%        popupmenu3
Popup_Value = get(hObject, 'Value');
Popup_String = get(hObject, 'String');
Schedule_Selected = Popup_String{Popup_Value};
switch(Schedule_Selected)  
    case{'Aperiodic Server','None'}
        handles.Aperiodic_Param.Server='None'; 
        set(handles.uitable5,'Visible','off');
        set(handles.text20,'Visible','off');
        set(handles.text22,'Visible','off');
        set(handles.edit7,'Visible','off');
        set(handles.edit9,'Visible','off');
    case{'Background'}
        handles.Aperiodic_Param.Server='Background';
        set(handles.uitable5,'Visible','on');
        set(handles.text20,'Visible','on');
        set(handles.text22,'Visible','off');
        set(handles.edit7,'Visible','on');
        set(handles.edit9,'Visible','off');
	case{'Polling'}
        handles.Aperiodic_Param.Server='Polling';   
        set(handles.uitable5,'Visible','on');
        set(handles.text20,'Visible','on');
        set(handles.text22,'Visible','on');
        set(handles.edit7,'Visible','on');
        set(handles.edit9,'Visible','on');
	case{'Deferrable'}
        handles.Aperiodic_Param.Server='Deferrable'; 
        set(handles.uitable5,'Visible','on');
        set(handles.text20,'Visible','on');
        set(handles.text22,'Visible','on');
        set(handles.edit7,'Visible','on');
        set(handles.edit9,'Visible','on');
	case{'Sporadic'}
        handles.Aperiodic_Param.Server='Sporadic'; 
        set(handles.uitable5,'Visible','on');
        set(handles.text20,'Visible','on');
        set(handles.text22,'Visible','on');
        set(handles.edit7,'Visible','on');
        set(handles.edit9,'Visible','on');
    otherwise
        handles.Aperiodic_Param.Server='None';
        set(handles.uitable5,'Visible','off');
        set(handles.text20,'Visible','off');
        set(handles.text22,'Visible','off');
        set(handles.edit7,'Visible','off');
        set(handles.edit9,'Visible','off');
end
guidata(hObject, handles);

end

% --- Executes during object creation, after setting all properties.
function popupmenu3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
end

% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
end

% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
end


% --- Executes when entered data in editable cell(s) in uitable3.
function uitable3_CellEditCallback(hObject, eventdata, handles)
% hObject    handle to uitable3 (see GCBO)
% eventdata  structure with the following fields (see UITABLE)
%	Indices: row and column indices of the cell(s) edited
%	PreviousData: previous data for the cell(s) edited
%	EditData: string(s) entered by the user
%	NewData: EditData or its converted form set on the Data property. Empty if Data was not changed
%	Error: error string when failed to convert EditData to appropriate value for Data
% handles    structure with handles and user data (see GUIDATA)
%%%%%handles = Update_Colors(hObject,handles);
guidata(hObject, handles);
end

% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
Previous_Color_List = handles.Options.color;
Number_Of_Tasks =  handles.Tasks_Param.Nb_Tasks;
Previous_Number_Of_Tasks = size(handles.Options.color,1);
    if Previous_Number_Of_Tasks ~= Number_Of_Tasks
        if Previous_Number_Of_Tasks > Number_Of_Tasks
            New_List_Of_Color = zeros(Number_Of_Tasks,3)+Previous_Color_List(1:Number_Of_Tasks,:);    
        else
            New_List_Of_Color = zeros(Number_Of_Tasks,3);
            New_List_Of_Color(1:Previous_Number_Of_Tasks,:) = New_List_Of_Color(1:Previous_Number_Of_Tasks,:)+Previous_Color_List(1:Previous_Number_Of_Tasks,:);             
        end
        handles.Options.color = New_List_Of_Color;
    end
    
    h = DrawOptions(hObject,handles);
    uiwait(h);
    handles.Options.color ;
    load 'colorTemp.mat' color;
    delete 'colorTemp.mat'
    handles.Options.color = color;
    guidata(hObject, handles);
end



function edit5_Callback(hObject, eventdata, handles)
% hObject    handle to edit5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit5 as text
%        str2double(get(hObject,'String')) returns contents of edit5 as a double
    handles.Options.MaxTime = str2double(get(handles.edit5,'String'));

    guidata(hObject, handles);

end

% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
end

% --- Executes on button press in radiobutton5.
function radiobutton5_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton5
    Value = get(hObject,'Value');
    if Value == 1
        set(handles.radiobutton6,'Value',0);
        set(handles.edit5,'Visible','off');
        handles.Options.MaxTime = 0; 
    end 
    guidata(hObject, handles);
    
end

% --- Executes on button press in radiobutton6.
function radiobutton6_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton6
    Value = get(hObject,'Value');
    if Value == 1
        set(handles.radiobutton5,'Value',0);
        set(handles.edit5,'Visible','on');
    end
    handles.Options.MaxTime = str2double(get(handles.edit5,'String'));

    guidata(hObject, handles);
end




% --- Executes when entered data in editable cell(s) in uitable4.
function uitable4_CellEditCallback(hObject, eventdata, handles)
% hObject    handle to uitable4 (see GCBO)
% eventdata  structure with the following fields (see UITABLE)
%	Indices: row and column indices of the cell(s) edited
%	PreviousData: previous data for the cell(s) edited
%	EditData: string(s) entered by the user
%	NewData: EditData or its converted form set on the Data property. Empty if Data was not changed
%	Error: error string when failed to convert EditData to appropriate value for Data
% handles    structure with handles and user data (see GUIDATA)
Data_Tasks_List_TEMP = get(hObject,'data');
Data_Tasks_List =zeros(size(Data_Tasks_List_TEMP,1),size(Data_Tasks_List_TEMP,2));
if iscell(Data_Tasks_List_TEMP)
    for i=1:1:size(Data_Tasks_List_TEMP,1)
       for j=1:1:size(Data_Tasks_List_TEMP,2)
          if isnan(str2double(Data_Tasks_List_TEMP{i,j})) == 0
            Data_Tasks_List(i,j) = str2double(Data_Tasks_List_TEMP{i,j});
          else
            Data_Tasks_List(i,j) = 0;
          end
       end    
    end
else
   Data_Tasks_List = Data_Tasks_List_TEMP;
end
set(hObject,'UserData',Data_Tasks_List);
    if ~isnumeric(Data_Tasks_List)
        error('The table must only contain number');
    end
handles.Sporadic_Param.Sporadic_Jobs = Data_Tasks_List;
handles.Sporadic_Param.Nb_Sporadic_Jobs = size(handles.Sporadic_Param.Sporadic_Jobs,1);

guidata(hObject, handles);
end



function edit6_Callback(hObject, eventdata, handles) %  number of Sporadic tasks
% hObject    handle to edit6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit6 as text
%        str2double(get(hObject,'String')) returns contents of edit6 as a double
Number_Of_Tasks = str2double(get(hObject,'String'));
handles.Sporadic_Param.Nb_Sporadic_Jobs = Number_Of_Tasks;
set(hObject,'UserData',Number_Of_Tasks);
Previous_Task_List = get(handles.uitable4,'UserData');
Previous_Number_Of_Tasks = size(Previous_Task_List,1);
    if Previous_Number_Of_Tasks ~= Number_Of_Tasks
        if Previous_Number_Of_Tasks > Number_Of_Tasks
            New_List_Of_Tasks = zeros(Number_Of_Tasks,3)+Previous_Task_List(1:Number_Of_Tasks,:);    
        else
            New_List_Of_Tasks = zeros(Number_Of_Tasks,3);
            New_List_Of_Tasks(1:Previous_Number_Of_Tasks,:) = New_List_Of_Tasks(1:Previous_Number_Of_Tasks,:)+Previous_Task_List(1:Previous_Number_Of_Tasks,:);             
        end
        

        set(handles.uitable4,'data',New_List_Of_Tasks);
        set(handles.uitable4,'UserData',New_List_Of_Tasks);
        
    end
 guidata(hObject, handles);  
end

% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
end


function edit7_Callback(hObject, eventdata, handles)
% hObject    handle to edit7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit7 as text
%        str2double(get(hObject,'String')) returns contents of edit7 as a double
Number_Of_Tasks = str2double(get(hObject,'String'));
handles.Aperiodic_Param.Nb_Aperiodic_Jobs = Number_Of_Tasks;
set(hObject,'UserData',Number_Of_Tasks);
Previous_Task_List = get(handles.uitable5,'UserData');
Previous_Number_Of_Tasks = size(Previous_Task_List,1);
    if Previous_Number_Of_Tasks ~= Number_Of_Tasks
        if Previous_Number_Of_Tasks > Number_Of_Tasks
            New_List_Of_Tasks = zeros(Number_Of_Tasks,2)+Previous_Task_List(1:Number_Of_Tasks,:);    
        else
            New_List_Of_Tasks = zeros(Number_Of_Tasks,2);
            New_List_Of_Tasks(1:Previous_Number_Of_Tasks,:) = New_List_Of_Tasks(1:Previous_Number_Of_Tasks,:)+Previous_Task_List(1:Previous_Number_Of_Tasks,:);             
        end
        

        set(handles.uitable5,'data',New_List_Of_Tasks);
        set(handles.uitable5,'UserData',New_List_Of_Tasks);
    end
 guidata(hObject, handles);  
end

% --- Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
end


% --- Executes when entered data in editable cell(s) in uitable5.
function uitable5_CellEditCallback(hObject, eventdata, handles)
% hObject    handle to uitable5 (see GCBO)
% eventdata  structure with the following fields (see UITABLE)
%	Indices: row and column indices of the cell(s) edited
%	PreviousData: previous data for the cell(s) edited
%	EditData: string(s) entered by the user
%	NewData: EditData or its converted form set on the Data property. Empty if Data was not changed
%	Error: error string when failed to convert EditData to appropriate value for Data
% handles    structure with handles and user data (see GUIDATA)
    Data_Tasks_List_TEMP = get(hObject,'data');
    Data_Tasks_List =zeros(size(Data_Tasks_List_TEMP,1),size(Data_Tasks_List_TEMP,2));
    if iscell(Data_Tasks_List_TEMP)
        for i=1:1:size(Data_Tasks_List_TEMP,1)
           for j=1:1:size(Data_Tasks_List_TEMP,2)
              if isnan(str2double(Data_Tasks_List_TEMP{i,j})) == 0
                Data_Tasks_List(i,j) = str2double(Data_Tasks_List_TEMP{i,j});
              else
                Data_Tasks_List(i,j) = 0;
              end
           end    
        end
    else
       Data_Tasks_List = Data_Tasks_List_TEMP;
    end
    set(hObject,'UserData',Data_Tasks_List);
        if ~isnumeric(Data_Tasks_List)
            error('The table must only contain number');
        end
    handles.Aperiodic_Param.Aperiodic_Jobs = Data_Tasks_List;
    handles.Aperiodic_Param.Nb_Aperiodic_Jobs = size(handles.Aperiodic_Param.Aperiodic_Jobs,1);
    
    guidata(hObject, handles);
end
% --- Executes on button press in pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles) % save
% hObject    handle to pushbutton11 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

Tasks = get(handles.uitable2,'data');
uisave('Tasks','MyTasksList.mat');


end

% --- Executes on button press in pushbutton12.
function pushbutton12_Callback(hObject, eventdata, handles) % Load Tasks
% hObject    handle to pushbutton12 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
    uiopen('load')
    handles.Tasks_Param.Tasks = Tasks(:,1:4);
    handles.Weight_Tasks = Tasks(:,5);
	handles.Tasks_Param.Nb_Tasks = size(handles.Tasks_Param.Tasks,1);
    set(handles.uitable2,'data',Tasks);
    set(handles.edit1,'String',num2str(size(Tasks,1)));
    handles.Aperiodic_Param.Server_Status = zeros(handles.Tasks_Param.Nb_Tasks,1);
    handles.Sporadic_Param.Server_Status = zeros(handles.Tasks_Param.Nb_Tasks,1);
    guidata(hObject, handles);
end


% --- Executes on button press in pushbutton13.
function pushbutton13_Callback(hObject, eventdata, handles) % Save all
% hObject    handle to pushbutton13 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
Data.Options = handles.Options;
Data.Tasks_Param = handles.Tasks_Param;
Data.Aperiodic_Param = handles.Aperiodic_Param;
Data.Sporadic_Param = handles.Sporadic_Param;
Data.Weight_Tasks = handles.Weight_Tasks;
uisave('Data','MyConfiguration.mat');
end

% --- Executes on button press in pushbutton14.
function pushbutton14_Callback(hObject, eventdata, handles) % Load all
% hObject    handle to pushbutton14 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
    uiopen('load');
    
    handles.Options = Data.Options;
    handles.Tasks_Param = Data.Tasks_Param;
    handles.Aperiodic_Param = Data.Aperiodic_Param;
    handles.Sporadic_Param = Data.Sporadic_Param; 
    handles.Tasks_Param.Tasks = Data.Tasks_Param.Tasks;
    handles.Weight_Tasks = Data.Weight_Tasks;    
    Tasks = zeros(size(handles.Tasks_Param.Tasks,1),5);
    Tasks(:,1:4) = handles.Tasks_Param.Tasks;
    Tasks(:,5) = handles.Weight_Tasks;

    set(handles.edit1,'String',num2str(size(Tasks,1)));    
    set(handles.uitable2,'data',Tasks);
    set(handles.uitable2,'UserData',Tasks);
    
    set(handles.uitable4,'data',handles.Sporadic_Param.Sporadic_Jobs);
    set(handles.uitable4,'UserData',handles.Sporadic_Param.Sporadic_Jobs);
    set(handles.edit6,'String',num2str(size(handles.Sporadic_Param.Sporadic_Jobs,1)));
    
    set(handles.uitable5,'data',handles.Aperiodic_Param.Aperiodic_Jobs);
    set(handles.uitable5,'UserData',handles.Aperiodic_Param.Aperiodic_Jobs);
    set(handles.edit7,'String',num2str(size(handles.Aperiodic_Param.Aperiodic_Jobs,1)));
    
    set(handles.edit3,'String',handles.Options.Step);
    set(handles.edit4,'String',handles.Options.CST);
    
get(handles.uitable2,'ColumnName');
ColumnName = cell(5,1);
ColumnName = get(handles.uitable2,'ColumnName');
ColumnName{5,1} = '';
set(handles.uitable2,'ColumnName',ColumnName);
 myCell = cell(1,5);
[myCell{:,:}] = deal('numeric');
set(handles.uitable2,'ColumnFormat',myCell);
myCell = cell(1,5);
[myCell{:,:}] = deal(false);
set(handles.uitable2,'ColumnEditable',cell2mat(myCell));
myCell = cell(1,5);
[myCell{:,:}] = deal('auto');
myCell{1,5} = 0;
set(handles.uitable2,'ColumnWidth',myCell);
        handles.TableTasksDim=5;
    % Update schedule
switch(handles.Options.schedule)
    case{'None'}
       % Schedule_Selected = 'Scheduling protocol'     ;
        Value = 1;
    case{'RMS'}
        %Schedule_Selected = 'Rate Monotonic Scheduling                    (RMS)';
        Value = 2;
	case{'DMS'}
        %Schedule_Selected = 'Deadline Monotonic Scheduling            (DMS)'   ;  
        Value = 3;
	case{'EDF'}
      %  Schedule_Selected = 'Earliest Deadline First Scheduling        (EDF)';
        Value = 4;
	case{'LST'}
       % Schedule_Selected = 'Least Slack Time First Scheduling        (LST)'  ;
        Value = 5;
	case{'RRS'}       
        %Schedule_Selected = 'Round-Robin Scheduling                        (RRS)';
        Value = 6;
        get(handles.uitable2,'ColumnName');
        ColumnName = cell(5,1);
        ColumnName = get(handles.uitable2,'ColumnName');
        ColumnName{5,1} = 'Weight';
        set(handles.uitable2,'ColumnName',ColumnName);
         myCell = cell(1,5);
        [myCell{:,:}] = deal('numeric');
        set(handles.uitable2,'ColumnFormat',myCell);
        myCell = cell(1,5);
        [myCell{:,:}] = deal(true);
        set(handles.uitable2,'ColumnEditable',cell2mat(myCell));
        myCell = cell(1,5);
        [myCell{:,:}] = deal('auto');
        set(handles.uitable2,'ColumnWidth',myCell);
	case{'WRRS'}
        %Schedule_Selected = 'Weighted Round-Robin Scheduling      (WRRS)';
        Value = 7;
                get(handles.uitable2,'ColumnName')
        ColumnName = cell(5,1);
        ColumnName = get(handles.uitable2,'ColumnName');
        ColumnName{5,1} = 'Weight';
        set(handles.uitable2,'ColumnName',ColumnName);
         myCell = cell(1,5);
        [myCell{:,:}] = deal('numeric');
        set(handles.uitable2,'ColumnFormat',myCell);
        myCell = cell(1,5);
        [myCell{:,:}] = deal(true);
        set(handles.uitable2,'ColumnEditable',cell2mat(myCell));
        myCell = cell(1,5);
        [myCell{:,:}] = deal('auto');
        set(handles.uitable2,'ColumnWidth',myCell);
    otherwise
       % Schedule_Selected = 'Scheduling protocol';      
        Value = 1;
end

set(handles.popupmenu1, 'Value',Value);
  
    % Update Sporadic
if handles.Sporadic_Param.Server == true
    set(handles.popupmenu2, 'Value',2);
    set(handles.uitable4,'Visible','on');
    set(handles.text19,'Visible','on');
    set(handles.text21,'Visible','on');
    set(handles.edit6,'Visible','on');
    set(handles.edit8,'Visible','on');
    set(handles.edit8,'String',num2str(handles.Sporadic_Param.Server_Status==1));
elseif handles.Sporadic_Param.Server == false
    set(handles.popupmenu2, 'Value',3);
    set(handles.uitable4,'Visible','off');
    set(handles.text19,'Visible','off');
    set(handles.text21,'Visible','off');
    set(handles.edit6,'Visible','off');
    set(handles.edit8,'Visible','off');
else
    set(handles.popupmenu2, 'Value',1); 
end
    % Update Aperiodic
    
switch(handles.Aperiodic_Param.Server)  
    case{'Aperiodic Server','None'}
        Value = 2; 
        set(handles.uitable5,'Visible','off');
        set(handles.text20,'Visible','off');
        set(handles.text22,'Visible','off');
        set(handles.edit7,'Visible','off');
        set(handles.edit9,'Visible','off');
    case{'Background'}
        Value = 3;
        set(handles.uitable5,'Visible','on');
        set(handles.text20,'Visible','on');
        set(handles.text22,'Visible','off');
        set(handles.edit7,'Visible','on');
        set(handles.edit9,'Visible','off');
	case{'Polling'}
        Value = 4; 
        set(handles.uitable5,'Visible','on');
        set(handles.text20,'Visible','on');
        set(handles.text22,'Visible','on');
        set(handles.edit7,'Visible','on');
        set(handles.edit9,'Visible','on');
	case{'Deferrable'}
        Value = 5;
        set(handles.uitable5,'Visible','on');
        set(handles.text20,'Visible','on');
        set(handles.text22,'Visible','on');
        set(handles.edit7,'Visible','on');
        set(handles.edit9,'Visible','on');
	case{'Sporadic'}
        Value = 6;
        set(handles.uitable5,'Visible','on');
        set(handles.text20,'Visible','on');
        set(handles.text22,'Visible','on');
        set(handles.edit7,'Visible','on');
        set(handles.edit9,'Visible','on');
    otherwise
        Value = 1;
        set(handles.uitable5,'Visible','off');
        set(handles.text20,'Visible','off');
        set(handles.text22,'Visible','off');
        set(handles.edit7,'Visible','off');
        set(handles.edit9,'Visible','off');
end
    set(handles.popupmenu3, 'Value',Value);
    
if(handles.Options.MaxTime == 0)
        set(handles.radiobutton6,'Value',0);
        set(handles.radiobutton5,'Value',1);
        set(handles.edit5,'Visible','off');
else
        set(handles.radiobutton6,'Value',1);
        set(handles.radiobutton5,'Value',0);
        set(handles.edit5,'Visible','on');
        set(handles.edit5,'String',num2str(handles.Options.MaxTime));
end
    set(handles.edit9,'String',num2str(find(handles.Aperiodic_Param.Server_Status)));
    set(handles.edit8,'String',num2str(find(handles.Sporadic_Param.Server_Status)));
    guidata(hObject, handles);
end


% --- Executes on button press in pushbutton15.
function pushbutton15_Callback(hObject, eventdata, handles) % HELP button
% hObject    handle to pushbutton15 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
Help_Message = cell(1,11);
Help_Message{1} = sprintf(' This help gives the procedure that should be followed to create a schedule.\n\n\n');
Help_Message{2} = sprintf('     1. First, select the number of tasks you want to schedule and then create your tasks.\n\n');
Help_Message{3} = sprintf('     2. Then, choose carefully the step used for the calculation. Processing time depends directly of this value.\n\n');
Help_Message{4} = sprintf('     3. Choose a schedule. If you choose a time-driven scheduling, do not forget to fulfill the Weight column in the Tasks table\n\n');
Help_Message{5} = sprintf('     4. If you want to handle sporadic jobs, indicate the server, and the number of sporadic jobs.\n\n');
Help_Message{6} = sprintf('     5. If you want to handle aperiodic jobs, indicate the server, and the number of aperiodic jobs.\n\n');
Help_Message{7} = sprintf('     6. Save your configuration and do not forget to change tasks colors with the drawing options.\n\n');
Help_Message{8} = sprintf('     7. Press the calculate button and then draw your schedule, budget, slack, or the time demand analysis.\n\n');
Help_Message{9} = sprintf(' The tool is in beta version and is not free of bugs. The option Context Switch Time may introduce strange behaviors.\n\n');
Help_Message{10} = sprintf(' Some examples are available in the folder : Examples. Just use the "Load All Parameters" button to use them.\n\n');
Help_Message{11} = sprintf('\t\t\t\t\t\tby  Vincent Changala(vincent.changala@gmail.com)');

helpdlg(cell2mat(Help_Message))
end



function edit8_Callback(hObject, eventdata, handles) % Sporadic Server number
% hObject    handle to edit8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit8 as text
%        str2double(get(hObject,'String')) returns contents of edit8 as a double
    Index = str2double(get(hObject,'String'));
    if  Index >= handles.Tasks_Param.Nb_Tasks
        Index = handles.Tasks_Param.Nb_Tasks;
    elseif Index <= 1
        Index = 1;
    end
    set(hObject,'String',num2str(Index));
    handles.Sporadic_Param.Nb_Sporadic_Jobs = Index;
    handles.Sporadic_Param.Server_Status = zeros(handles.Tasks_Param.Nb_Tasks,1);
    handles.Sporadic_Param.Server_Status(Index) = 1;
    guidata(hObject, handles);
end

% --- Executes during object creation, after setting all properties.
function edit8_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
end


function edit9_Callback(hObject, eventdata, handles)
% hObject    handle to edit9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit9 as text
%        str2double(get(hObject,'String')) returns contents of edit9 as a double
    Index = str2double(get(hObject,'String'));
    if  Index >= handles.Tasks_Param.Nb_Tasks
        Index = handles.Tasks_Param.Nb_Tasks;

    elseif Index <= 1
        Index = 1;
    end
    set(hObject,'String',num2str(Index));
    handles.Aperiodic_Param.Nb_Aperiodic_Jobs = Index;
    handles.Aperiodic_Param.Server_Status = zeros(handles.Tasks_Param.Nb_Tasks,1);
    handles.Aperiodic_Param.Server_Status(Index) = 1;
    guidata(hObject, handles);
end

% --- Executes during object creation, after setting all properties.
function edit9_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
end
% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles) % Calculate Button
% hObject    handle to pushbutton8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(hObject,'Background',[1 0.5 0]); %Orange
pause(0.2);
try
   handles = CalculateGUI( handles );
catch err
   set(hObject,'Background','red');
   rethrow(err);
end
set(hObject,'Background','green');

switch handles.Options.schedule
    case{'RMS','DMS','EDF','LST'}
        if (strcmp(handles.Options.schedule,'RMS')||...
            strcmp(handles.Options.schedule,'DMS')) &&...
            (strcmp(handles.Aperiodic_Param.Server,'None')||strcmp(handles.Aperiodic_Param.Server,'Sporadic')...
            ||strcmp(handles.Aperiodic_Param.Server,'Deferrable'))
        set(handles.pushbutton1,'Background',[1 0.5 0]);
        else
            set(handles.pushbutton1,'Background','red');
        end
        if strcmp(handles.Options.schedule,'LST')
            set(handles.pushbutton17,'Background',[1 0.5 0]);
        else
            set(handles.pushbutton17,'Background','red');
        end   
        set(handles.pushbutton2,'Background',[1 0.5 0]);
        set(handles.pushbutton16,'Background',[1 0.5 0]);
    case{'RRS','WRRS'}
        
        set(handles.pushbutton2,'Background',[1 0.5 0]);    
        set(handles.pushbutton17,'Background','red');
        set(handles.pushbutton16,'Background',[1 0.5 0]);
    otherwise
        error('Fatal error');
        
end


set(handles.text5,'String',num2str(handles.Options.Utilization))
set(handles.text7,'String',num2str(handles.Options.Utilization_Max))
set(handles.text18,'String',num2str(handles.Options.Density))
set(handles.text14,'String',num2str(handles.Options.Step_Adviced))
set(handles.text16,'String',num2str(handles.Options.Hyperperiod))
% Format Utilization String
if(handles.Options.Utilization > handles.Options.Utilization_Max) 
    set(handles.text5,'Foreground','red')
elseif(handles.Options.Utilization == handles.Options.Utilization_Max) 
    set(handles.text5,'Foreground',[1 0.5 0]) %Orange
else
    set(handles.text5,'Foreground','green')
end
% Format Density String
if(handles.Options.Density > 1) 
    set(handles.text18,'Foreground','red')
elseif(handles.Options.Density == 1) 
    set(handles.text18,'Foreground',[1 0.5 0]) %Orange
else
    set(handles.text18,'Foreground','green')
end
%Make the task list editable again (bug?)
myCell = cell(1,5);
[myCell{:,:}] = deal(true);
set(handles.uitable2,'ColumnEditable',cell2mat(myCell));
guidata(hObject, handles);

end

% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

        if (strcmp(handles.Options.schedule,'RMS')||...
            strcmp(handles.Options.schedule,'DMS')) &&...
            (strcmp(handles.Aperiodic_Param.Server,'None')||...
             strcmp(handles.Aperiodic_Param.Server,'Sporadic') ||...
             strcmp(handles.Aperiodic_Param.Server,'Deferrable'))
        	try
                handles.Options.TDA=1;
                handles.Tasks_Param.Tasks(:,3) = handles.Tasks_Param.Tasks(:,3) - 2*handles.Options.CST;
                [handles.Trace handles.Budget_Tasks handles.Slack handles.Aperiodic_Param handles.Sporadic_Param]=...
                    Calculation.Calcul_Schedule(handles.Time,handles.Tasks_Param,handles.Aperiodic_Param,handles.Sporadic_Param,handles.Options);
                Display.Display_TDA(handles.Time,handles.Tasks_Param,handles.Aperiodic_Param,handles.Trace,handles.Options);
            catch err
                set(hObject,'Background','red');
                rethrow(err);
                 
            end
            set(hObject,'Background','green');
        end      



end

% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles) % Draw schedule button
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

    try
        Display.Display_Schedule(handles.Time,...
                                 handles.Tasks_Param,...
                                 handles.Aperiodic_Param,...
                                 handles.Sporadic_Param,...
                                 handles.Options,...
                                 handles.Trace); %Display the schedule for every tasks.
    catch err
        set(hObject,'Background','red');
        rethrow(err);
        
    end
    set(hObject,'Background','green');     
                             
                             
end

% --- Executes on button press in pushbutton16.
function pushbutton16_Callback(hObject, ~, handles)
% hObject    handle to pushbutton16 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
    try
        Display.Display_Budget(handles.Time,handles.Tasks_Param,handles.Budget_Tasks,handles.Trace,handles.Options);
    catch err
        set(hObject,'Background','red');
        rethrow(err);
        
    end
    set(hObject,'Background','green');     

end

% --- Executes on button press in pushbutton17.
function pushbutton17_Callback(hObject, ~, handles)
% hObject    handle to pushbutton17 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
        if strcmp(handles.Options.schedule,'LST')
            try
        	Display.Display_Slack(handles.Time,handles.Tasks_Param,handles.Slack,handles.Trace,handles.Options);
            catch err
                set(hObject,'Background','red');
                rethrow(err);

            end
            set(hObject,'Background','green');
        end       

end


% --- Executes on button press in pushbutton18.
function pushbutton18_Callback(hObject, eventdata, handles) % Reset
% hObject    handle to pushbutton18 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%clear all;
% Update handles structure
set(handles.edit1,'TooltipString','<html>Insert the number of tasks to schedule.');
set(handles.edit4,'TooltipString','<html>It models the time taken to switch between tasks.<br/> This parameter is still experimental and could provoque unexpected behavior.');
set(handles.edit3,'TooltipString','<html>It is the calculation step. All parameters shall be a multiple of this value.<br/> A non-optimized working value is given by Step_Adviced in the output frame.');
set(handles.radiobutton5,'TooltipString','<html>The Hyperperiod is the Least Common Multiple of all the tasks'' period.<br/> To be schedulable on the hyperperiod is a sufficient condition to prove the schedulability of a task.<br/> However, the calculation can be long. ');
set(handles.radiobutton6,'TooltipString','<html>Select Custom if you prefer to set your own limit of runtime.<br/>It is extremely usefull to shorten the time execution of the script');
set(handles.uitable2,'TooltipString','<html>It contains all the tasks parameters:<br/> + Phase: The task will be available to scheduling at that time.<br/> + Period: Task''s period.<br/> + Execution Time : It indicates how long the task must execute.<br/> + Deadline : Indicate the time when the task must have finished to execute.');
set(handles.pushbutton12,'TooltipString','<html>Load all the tasks'' parameters (table above)');
set(handles.pushbutton11,'TooltipString','<html>Save all the tasks'' parameters (table above)');
set(handles.pushbutton4,'TooltipString','<html>Useful to set or change tasks'' colors for the tasks schedule display');
set(handles.popupmenu1,'TooltipString','<html>Choose the scheduling that must be used.');
set(handles.popupmenu2,'TooltipString','<html>Indicate if one of the tasks is a Sporadic Server');
set(handles.popupmenu3,'TooltipString','<html>Indicate if one of the tasks is an Aperiodic Server and choose its type.');
set(handles.edit8,'TooltipString','<html>Indicate the number of Sporadic Jobs handled by the Server');
set(handles.edit9,'TooltipString','<html>Indicate the number of Aperiodic Jobs handled by the Server');
set(handles.edit6,'TooltipString','<html>Indicate which task is the server');
set(handles.edit7,'TooltipString','<html>Indicate which task is the server');
set(handles.uitable4,'TooltipString','<html>It contains all the sporadic jobs parameters');
set(handles.uitable5,'TooltipString','<html>It contains all the aperiodic jobs parameters');
set(handles.pushbutton14,'TooltipString','<html>Load all the parameters');
set(handles.pushbutton13,'TooltipString','<html>Save all the parameters');
set(handles.pushbutton15,'TooltipString','<html>More help...');
set(handles.pushbutton8,'TooltipString','<html>It processes all the data and calculate the schedule, the budget, the slack, the time demand analysis.<br/> RED : An error occured.<br/> ORANGE : Calculation is still going on.<br/> Green : The calculation has succeed.');
set(handles.pushbutton2,'TooltipString','<html>Draw the schedule.<br/> RED : Schedule is not available (or an error occured).<br/> ORANGE : Schedule is available.<br/> Green : Schedule has been displayed.');
set(handles.pushbutton16,'TooltipString','<html>Draw the budget.<br/> RED : Budget is not available (or an error occured).<br/> ORANGE : Budget is available.<br/> Green : Budget has been displayed.');
set(handles.pushbutton17,'TooltipString','<html>Draw the slack.<br/> RED : Slack is not available (or an error occured).<br/> ORANGE : Slack is available.<br/> Green : Slack has been displayed.');
set(handles.pushbutton1,'TooltipString','<html>Draw the time demand analysis.<br/> RED : Time demand analysis is not available (or an error occured).<br/> ORANGE : Time demand analysis is available.<br/> Green : Time demand analysis has been displayed.');
% Update handles structure
set(handles.pushbutton8,'BackgroundColor',[0.941 0.941 0.941]);
set(handles.pushbutton1,'Background','red');
set(handles.pushbutton2,'Background','red');
set(handles.pushbutton16,'Background','red');
set(handles.pushbutton17,'Background','red');
set(handles.uitable4,'Visible','off');
set(handles.text19,'Visible','off');
set(handles.text21,'Visible','off');
set(handles.edit6,'Visible','off');
set(handles.edit8,'Visible','off');
set(handles.uitable5,'Visible','off');
set(handles.text20,'Visible','off');
set(handles.text22,'Visible','off');
set(handles.edit7,'Visible','off');
set(handles.edit9,'Visible','off');
set(handles.uitable2,'data',zeros(4,5));
set(handles.uitable2,'UserData',zeros(4,5));

get(handles.uitable2,'ColumnName');
ColumnName = cell(5,1);
ColumnName = get(handles.uitable2,'ColumnName');
ColumnName{5,1} = '';
set(handles.uitable2,'ColumnName',ColumnName);
 myCell = cell(1,5);
[myCell{:,:}] = deal('numeric');
set(handles.uitable2,'ColumnFormat',myCell);
myCell = cell(1,5);
[myCell{:,:}] = deal(true);
set(handles.uitable2,'ColumnEditable',cell2mat(myCell));
myCell = cell(1,5);
[myCell{:,:}] = deal('auto');
myCell{1,5} = 0;
set(handles.uitable2,'ColumnWidth',myCell);


set(handles.uitable4,'data',zeros(4,3));
set(handles.uitable4,'UserData',zeros(4,3));

 myCell = cell(1,3);
[myCell{:,:}] = deal('numeric');
set(handles.uitable4,'ColumnFormat',myCell);
myCell = cell(1,3);
[myCell{:,:}] = deal(true);
set(handles.uitable4,'ColumnEditable',cell2mat(myCell));
myCell = cell(1,5);
[myCell{:,:}] = deal('auto');
myCell{1,4} = 0;
myCell{1,5} = 0;
set(handles.uitable4,'ColumnWidth',myCell);
set(handles.uitable5,'data',zeros(4,2));
set(handles.uitable5,'UserData',zeros(4,2));
 myCell = cell(1,2);
[myCell{:,:}] = deal('numeric');
set(handles.uitable5,'ColumnFormat',myCell);
myCell = cell(1,2);
[myCell{:,:}] = deal(true);
set(handles.uitable5,'ColumnEditable',cell2mat(myCell));
myCell = cell(1,4);
[myCell{:,:}] = deal('auto');
myCell{1,3} = 0;
myCell{1,4} = 0;
set(handles.uitable5,'ColumnWidth',myCell);



handles.TableTasksDim=5;

handles.Options.precision = -10; % means that there won't be a value smaller than 10^precision in all the processing         
                       % IMPORTANT NOTE: All other values MUST be greater than
                       % precision to get a correct behaviour.
handles.Options.CST=0.0;
handles.Options.Step=0.1;  
handles.Options.MaxTime = 0;
handles.Options.schedule = 'None';
handles.Tasks_Param.Tasks = zeros(4,4);
handles.Weight_Tasks = zeros(1,4);
handles.Tasks_Param.Nb_Tasks = 4;
%%%%%%%%%%%%%%%%%%%%%%%%% 
%%% Server options      % This server is used to schedule Jobs that come aperiodically 
%%% for Aperiodic Tasks % 
handles.Aperiodic_Param.Server='None'; % Determine which kind of Server we will use
handles.Aperiodic_Param.Aperiodic_Jobs= zeros(4,2);  %[ Phase , Execution Time ]
handles.Aperiodic_Param.Nb_Aperiodic_Jobs=4;
handles.Aperiodic_Param.Server_Status=zeros(handles.Tasks_Param.Nb_Tasks,1); % Determine which Tasks will be the server

%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Server options      % This server is used to schedule sporadic Jobs  ( Aperiodic Jobs with a deadline ) 
%%% for Sporadic Tasks  % 
handles.Sporadic_Param.Server = false;
handles.Sporadic_Param.Sporadic_Jobs = zeros(4,3); %[ Phase , Execution Time , Deadline ]
handles.Sporadic_Param.Server_Status = zeros(handles.Tasks_Param.Nb_Tasks,1);
handles.Sporadic_Param.Nb_Sporadic_Jobs = 4;
set(handles.edit3,'String',handles.Options.Step);
set(handles.edit4,'String',handles.Options.CST);
handles.Tasks_Param.Tasks = zeros(4,4);
handles.Tasks_Param.Nb_Tasks = 4;
handles.Options.color = [1 0 0;0 1 0;1 1 0;0 0 1];
%handles = Update_Colors(handles.uitable3,handles);
guidata(hObject, handles);

set(handles.radiobutton6,'Value',0);
set(handles.radiobutton5,'Value',1)
set(handles.edit5,'Visible','off');
handles.Options.MaxTime = 0; 
set(handles.popupmenu1,'Value',1);
set(handles.popupmenu2,'Value',1);
set(handles.popupmenu3,'Value',1);
set(handles.text5,'String',num2str(0));
set(handles.text7,'String',num2str(0));
set(handles.text14,'String',num2str(0));
set(handles.text16,'String',num2str(0));
set(handles.text18,'String',num2str(0));
end

Contact us