-
Notifications
You must be signed in to change notification settings - Fork 1
/
Schedule_write.m
62 lines (55 loc) · 2.37 KB
/
Schedule_write.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function Schedule_write(SDFgraph, Schedule, filepath)
outpath = fullfile(filepath, [SDFgraph.filename '_' num2str(length(Schedule.taskGroup.scheduleGroups)) '_schedule.xml']);
docNode = com.mathworks.xml.XMLUtils.createDocument('CIC_Schedule');
CIC_Schedule = docNode.getDocumentElement;
CIC_Schedule.setAttribute('xmlns',Schedule.xmlns);
CIC_Schedule.setAttribute('type',Schedule.type);
mTaskGroups = docNode.createElement('taskGroups');
mTaskGroup = docNode.createElement('taskGroup');
mTaskGroup.setAttribute('name', Schedule.taskGroup.name);
mTaskGroup.setAttribute('buffer', num2str(Schedule.taskGroup.buffer));
nschel = length(Schedule.taskGroup.scheduleGroups);
for idx = 1:nschel
scheduleGroup = Schedule.taskGroup.scheduleGroups(idx);
mscheduleGroup = docNode.createElement('scheduleGroup');
mscheduleGroup.setAttribute('scheduleType', scheduleGroup.scheduleType);
mscheduleGroup.setAttribute('poolName', scheduleGroup.poolName);
mscheduleGroup.setAttribute('name', scheduleGroup.name);
mscheduleGroup.setAttribute('localId', num2str(idx-1));
scheduleGroup.tasks = refactor_task(scheduleGroup.tasks);
ntask = length(scheduleGroup.tasks);
for jdx = 1:ntask
task = scheduleGroup.tasks(jdx);
mScheduleElement = docNode.createElement('scheduleElement');
mTask = docNode.createElement('task');
mTask.setAttribute('startTime', num2str(task.startTime));
mTask.setAttribute('repetition', num2str(task.repetition));
mTask.setAttribute('name', task.name);
mTask.setAttribute('endTime', num2str(task.endTime));
mScheduleElement.appendChild(mTask);
mscheduleGroup.appendChild(mScheduleElement);
end
mTaskGroup.appendChild(mscheduleGroup);
end
mTaskGroups.appendChild(mTaskGroup);
CIC_Schedule.appendChild(mTaskGroups);
xmlwrite(outpath,docNode);
end
function ntasks = refactor_task(tasks)
ntasks = [];
num_tasks = length(tasks);
for jdx = 1:num_tasks
task = tasks(jdx);
if(~isempty(ntasks))
ntask = ntasks(end);
if(strcmp(task.name,ntask.name) && (task.startTime == ntask.endTime))
ntasks(end).repetition = ntasks(end).repetition + 1;
ntasks(end).endTime = task.endTime;
else
ntasks = [ntasks task];
end
else
ntasks = [ntasks task];
end
end
end