blob: 9dc84d7123509fe6e5a869149ab00643e1537924 [file] [log] [blame]
Zakir Meer9f251f52018-06-17 16:21:31 +02001package templates
2
3import com.inchron.realtime.root.model.Model
4import com.inchron.realtime.root.model.ModelFactory
5import com.inchron.realtime.root.model.TimeUnit
6import java.util.List
7import java.util.Map
8import org.eclipse.app4mc.amalthea.model.Amalthea
9import org.eclipse.app4mc.amalthea.model.InterProcessStimulus
10import org.eclipse.app4mc.amalthea.model.PeriodicStimulus
11import org.eclipse.app4mc.amalthea.model.Stimulus
12import org.eclipse.app4mc.amalthea.model.Task
13import org.eclipse.app4mc.amalthea.model.Time
14import org.eclipse.emf.common.util.EList
15import templates.utils.AmltCacheModel
16
17public class StimuliTransformer extends AbstractAmaltheaInchronTransformer {
18
19 /**
20 * This method is used to perform following:
21 *
22 * <br>1.Build a cache of "InterProcess Stimuli name" and "List of Tasks" which are triggered by it
23 * <br>2.Create ActivationConnection for each InterProcessStimulus
24 */
25 public def void createInchronActivationConnections(EList<Task> amltTasks,Model inchronModel){
26
27 val AmltCacheModel amltCache=customObjsStore.getInstance(AmltCacheModel)
28
29 for (process : amltTasks) {
30 process.stimuli.forEach[stimuli | {
31 if(stimuli instanceof InterProcessStimulus){
32 amltCache.cacheInterProcessTriggerRelations(stimuli.name, process)
33 }
34
35 }]
36 }
37
38 /*-For each InterProcessStimulus, create corresponding ActivationConnection in Inchron and store this info in the cache */
39
40 amltCache.interProcessTriggerRelationsMap.keySet.forEach[stimuliName|{
41
42 val inchronConnection=ModelFactory.eINSTANCE.createActivationConnection
43
44 inchronConnection.name=stimuliName
45
46 /*-Adding ActivationConnect object to Inchron Model */
47 inchronModel.connections.add(inchronConnection)
48
49 /*-Adding ActivationConnect object to Cache */
50 amltCache.cacheInchronConnection(stimuliName,inchronConnection)
51
52
53 }]
54
55 }
56 /**
57 * This method is used to create SimulationScenario based on Periodic Stimulus objects present in Amalthea model
58 */
59 public def create inchronStimulationFactory.createStimulationScenario createstimulationScenario(Amalthea amaltheaModel) {
60 val AmltCacheModel amltCache=customObjsStore.getInstance(AmltCacheModel)
61
62 val Map<String, List<com.inchron.realtime.root.model.Process>> stimuliCache = amltCache.amltStimuliInchronProcessElementsMap;
63
64 for (Stimulus stimuli : amaltheaModel?.stimuliModel?.stimuli) {
65
66 if (stimuli instanceof PeriodicStimulus) {
67
68 val inchronProcessList = stimuliCache.get(stimuli.name)
69
70 if (inchronProcessList != null) {
71
72 for (com.inchron.realtime.root.model.Process inchronProcess : inchronProcessList) {
73
74 it.generators.add(createRandomStimuliGenerator(stimuli, inchronProcess))
75 }
76
77 }
78 }
79
80 }
81 }
82
83 /**
84 * This method is used to create RandomStimuliGenerator object, based on the Amalthea PeriodicStimulus object and Inchron Process object
85 */
86 public def create inchronStimulationFactory.createRandomStimuliGenerator createRandomStimuliGenerator(PeriodicStimulus amltStimuli, com.inchron.realtime.root.model.Process inchronProcess) {
87 if (amltStimuli?.minDistance != null)
88 it.minInterArrivalTime = getInchronTimeValue(amltStimuli?.minDistance)
89 it.period = getInchronTimeValue(amltStimuli.recurrence)
90 it.startOffset = getInchronTimeValue(amltStimuli?.offset)
91 //it.clock; //need the clock
92 it.relative = false; //only for sporadics
93 it.iterations = -1 //right?
94 //it.startOffsetVariation; //don't know
95 it.target = inchronProcess;
96 //it.variation
97
98
99 //jitter
100 if (amltStimuli?.jitter != null) {
101 var timeDistribution=inchronModelFactory.createTimeDistribution
102 if (amltStimuli?.jitter?.lowerBound != null) {
103 timeDistribution.bcet = getInchronTimeValue(amltStimuli?.jitter?.lowerBound)
104 }
105 if (amltStimuli?.jitter?.upperBound != null) {
106 timeDistribution.wcet = getInchronTimeValue(amltStimuli?.jitter?.upperBound)
107 }
108
109 //TODO: handle more complex distributions
110 it.variation = timeDistribution
111 }
112
113
114 }
115
116 def com.inchron.realtime.root.model.Time getInchronTimeValue(Time amltTime) {
117 var result = inchronModelFactory.createTime
118
119 result.value = amltTime.value.longValue;
120 switch (amltTime.unit.getName) {
121 case "s": {
122 result.unit = TimeUnit.S
123 }
124 case "ms": {
125 result.unit = TimeUnit.MS
126 }
127 case "us": {
128 result.unit = TimeUnit.US
129 }
130 case "ns": {
131 result.unit = TimeUnit.NS
132 }
133 case "ps": {
134 result.unit = TimeUnit.PS
135 }
136 }
137 return result;
138 }
139
140}