blob: ebdf0604bf504fde275cb89e9615e1cd38d81b06 [file] [log] [blame]
package templates
import com.inchron.realtime.root.model.Model
import com.inchron.realtime.root.model.ModelFactory
import com.inchron.realtime.root.model.TimeUnit
import java.util.List
import java.util.Map
import org.eclipse.app4mc.amalthea.model.Amalthea
import org.eclipse.app4mc.amalthea.model.InterProcessStimulus
import org.eclipse.app4mc.amalthea.model.PeriodicStimulus
import org.eclipse.app4mc.amalthea.model.Stimulus
import org.eclipse.app4mc.amalthea.model.Task
import org.eclipse.app4mc.amalthea.model.Time
import org.eclipse.emf.common.util.EList
import templates.utils.AmltCacheModel
public class StimuliTransformer extends AbstractAmaltheaInchronTransformer {
/**
* This method is used to perform following:
*
* <br>1.Build a cache of "InterProcess Stimuli name" and "List of Tasks" which are triggered by it
* <br>2.Create ActivationConnection for each InterProcessStimulus
*/
public def void createInchronActivationConnections(EList<Task> amltTasks,Model inchronModel){
val AmltCacheModel amltCache=customObjsStore.getInstance(AmltCacheModel)
for (process : amltTasks) {
process.stimuli.forEach[stimuli | {
if(stimuli instanceof InterProcessStimulus){
amltCache.cacheInterProcessTriggerRelations(stimuli.name, process)
}
}]
}
/*-For each InterProcessStimulus, create corresponding ActivationConnection in Inchron and store this info in the cache */
amltCache.interProcessTriggerRelationsMap.keySet.forEach[stimuliName|{
val inchronConnection=ModelFactory.eINSTANCE.createActivationConnection
inchronConnection.name=stimuliName
/*-Adding ActivationConnect object to Inchron Model */
inchronModel.connections.add(inchronConnection)
/*-Adding ActivationConnect object to Cache */
amltCache.cacheInchronConnection(stimuliName,inchronConnection)
}]
}
/**
* This method is used to create SimulationScenario based on Periodic Stimulus objects present in Amalthea model
*/
public def create inchronStimulationFactory.createStimulationScenario createstimulationScenario(Amalthea amaltheaModel) {
val AmltCacheModel amltCache=customObjsStore.getInstance(AmltCacheModel)
val Map<String, List<com.inchron.realtime.root.model.Process>> stimuliCache = amltCache.amltStimuliInchronProcessElementsMap;
for (Stimulus stimuli : amaltheaModel?.stimuliModel?.stimuli) {
if (stimuli instanceof PeriodicStimulus) {
val inchronProcessList = stimuliCache.get(stimuli.name)
if (inchronProcessList != null) {
for (com.inchron.realtime.root.model.Process inchronProcess : inchronProcessList) {
it.generators.add(createRandomStimuliGenerator(stimuli, inchronProcess))
}
}
}
}
}
/**
* This method is used to create RandomStimuliGenerator object, based on the Amalthea PeriodicStimulus object and Inchron Process object
*/
public def create inchronStimulationFactory.createRandomStimuliGenerator createRandomStimuliGenerator(PeriodicStimulus amltStimuli, com.inchron.realtime.root.model.Process inchronProcess) {
if (amltStimuli?.minDistance != null)
it.minInterArrivalTime = getInchronTimeValue(amltStimuli?.minDistance)
it.period = getInchronTimeValue(amltStimuli.recurrence)
it.startOffset = getInchronTimeValue(amltStimuli?.offset)
//it.clock; //need the clock
it.relative = false; //only for sporadics
it.iterations = -1 //right?
//it.startOffsetVariation; //don't know
//TODO: Change in 2.98.2 Till 2.98.1 target was referring to Process object. From 2.98.1 there is a change
// it.target = inchronProcess;
//it.variation
//jitter
if (amltStimuli?.jitter != null) {
var timeDistribution=inchronModelFactory.createTimeDistribution
if (amltStimuli?.jitter?.lowerBound != null) {
timeDistribution.bcet = getInchronTimeValue(amltStimuli?.jitter?.lowerBound)
}
if (amltStimuli?.jitter?.upperBound != null) {
timeDistribution.wcet = getInchronTimeValue(amltStimuli?.jitter?.upperBound)
}
//TODO: handle more complex distributions
it.variation = timeDistribution
}
}
def com.inchron.realtime.root.model.Time getInchronTimeValue(Time amltTime) {
var result = inchronModelFactory.createTime
result.value = amltTime.value.longValue;
switch (amltTime.unit.getName) {
case "s": {
result.unit = TimeUnit.S
}
case "ms": {
result.unit = TimeUnit.MS
}
case "us": {
result.unit = TimeUnit.US
}
case "ns": {
result.unit = TimeUnit.NS
}
case "ps": {
result.unit = TimeUnit.PS
}
}
return result;
}
}