blob: 6dff2d938d058f88ef53eb80c3fb1a344ca604a2 [file] [log] [blame]
/**
* *******************************************************************************
* Copyright (c) 2019 Robert Bosch GmbH and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Robert Bosch GmbH - initial API and implementation
* *******************************************************************************
*/
package templates.m2m.stimuli;
import com.google.inject.Inject
import com.inchron.realtime.root.model.Model
import org.eclipse.app4mc.amalthea.model.FrequencyDomain
import org.eclipse.app4mc.amalthea.model.PeriodicStimulus
import org.eclipse.app4mc.amalthea.model.StimuliModel
import org.eclipse.app4mc.amalthea.model.Stimulus
import templates.AbstractAmaltheaInchronTransformer
import templates.m2m.utils.TimeTransformer
import templates.utils.AmltCacheModel
import com.google.inject.Singleton
import templates.m2m.hw.FrequencyDomainTransformer
@Singleton
class StimuliTransformer extends AbstractAmaltheaInchronTransformer {
var AmltCacheModel cacheModel
@Inject TimeTransformer timeUtilsTransformer
@Inject FrequencyDomainTransformer frequencyDomainTransformer
def transformStimuliModel(StimuliModel amltStimuliModel, Model inchronModel) {
val inchronStimulationScenario = inchronStimulationFactory.createStimulationScenario
inchronStimulationScenario.name = "DefaultScenario"
amltStimuliModel?.stimuli?.forEach [ amltStimuli |
if (amltStimuli instanceof PeriodicStimulus) {
var inchronRandomStimuliGenerator = createRandomStimuliGenerator(amltStimuli)
inchronStimulationScenario.generators.add(inchronRandomStimuliGenerator)
}
]
inchronModel.stimulationScenarios.add(inchronStimulationScenario)
inchronModel.defaultScenario = inchronStimulationScenario
}
def create inchronStimulationFactory.createRandomStimuliGenerator createRandomStimuliGenerator(
Stimulus amltStimulus) {
cacheModel = customObjsStore.getInstance(AmltCacheModel)
it.name = amltStimulus.name
if (amltStimulus instanceof PeriodicStimulus) {
it.startOffset = timeUtilsTransformer.createTime(amltStimulus.offset)
it.period = timeUtilsTransformer.createTime(amltStimulus.recurrence)
var inchronActivationConnection = createActivationConnection(amltStimulus)
it.connections.add(inchronActivationConnection)
var inchronCallGraph = inchronModelFactory.createCallGraph
var inchronCallSequence = inchronModelFactory.createCallSequence
inchronCallSequence.name = "CS"
inchronCallGraph.graphEntries.add(inchronCallSequence)
var inchronActivationItem = inchronModelFactory.createActivationItem
inchronActivationItem.name = "ActivationItem"
inchronCallSequence.calls.add(inchronActivationItem)
inchronActivationItem.connection = inchronActivationConnection
it.targets = inchronCallGraph
// TODO: check if the right frequency can be fetched (below solution is good at present. In long run clarify this topic in detail)
var firstFrequencyDomain = getAmaltheaRoot().hwModel.domains.findFirst [ domain | domain instanceof FrequencyDomain]
if (firstFrequencyDomain !== null){
it.clock = frequencyDomainTransformer.createClock(firstFrequencyDomain as FrequencyDomain)
it.variation = inchronModelFactory.createTimeDistribution
it.minInterArrivalTime = inchronModelFactory.createTime
it.startOffsetVariation = inchronModelFactory.createTimeDistribution
}
}
}
def create inchronModelFactory.createActivationConnection createActivationConnection(Stimulus amltStimulus) {
}
}