Skip to content
Snippets Groups Projects
Commit 83f11b1f authored by Florian Hölzl's avatar Florian Hölzl
Browse files

Started RasPi code generation.

refs 3079
parent 32e8e160
No related branches found
No related tags found
No related merge requests found
Showing
with 655 additions and 119 deletions
......@@ -151,6 +151,16 @@
type="org.fortiss.af3.platform.raspberry.model.RaspberryPi">
</input>
</propertySection>
<propertySection
afterSection="org.fortiss.tooling.kernel.ui.internal.properties.NamedCommentedPropertySection"
class="org.fortiss.af3.platform.raspberry.ui.properties.ActuatorPWMPropertySection"
enablesFor="1"
id="org.fortiss.af3.platform.raspberry.ui.properties.ActuatorPWMPropertySection"
tab="org.fortiss.tooling.kernel.ui.property.tab.general">
<input
type="org.fortiss.af3.platform.raspberry.model.ActuatorPWM">
</input>
</propertySection>
</propertySections>
</extension>
</plugin>
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2013 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.ui.properties;
import static org.fortiss.af3.expression.ui.databinding.validate.IntToStringConverter.INT_STRING_CONVERTER;
import static org.fortiss.af3.expression.ui.databinding.validate.StringToIntConverter.STRING_INT_CONVERTER;
import static org.fortiss.tooling.kernel.ui.util.DataBindingUtils.performComplexTextBinding;
import static org.fortiss.tooling.kernel.ui.util.ObservableUtils.observeValue;
import org.conqat.ide.commons.ui.databinding.validate.TextToIntegerValidator;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import org.fortiss.af3.platform.raspberry.model.ActuatorPWM;
import org.fortiss.af3.platform.raspberry.model.RaspberryPiModelPackage;
import org.fortiss.tooling.kernel.ui.extension.base.PropertySectionBase;
/**
* Property section for {@link ActuatorPWM}s.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 9E768B733BD37201F97399293FA0DFA7
*/
public class ActuatorPWMPropertySection extends PropertySectionBase {
/** The actuator. */
private ActuatorPWM actuator;
/** The PWM channel widget. */
private Text pwmChannelText;
/** {@inheritDoc} */
@Override
public void createControls(Composite parent, TabbedPropertySheetPage tabbedPropertySheetPage) {
super.createControls(parent, tabbedPropertySheetPage);
pwmChannelText = createDecoratedText("PWM Channel (0, 1)");
}
/** {@inheritDoc} */
@Override
protected void setSectionInput(Object input) {
actuator = (ActuatorPWM)input;
}
/** {@inheritDoc} */
@Override
public void refresh() {
super.refresh();
IObservableValue modelObservable =
observeValue(actuator, RaspberryPiModelPackage.Literals.ACTUATOR_PWM__CHANNEL_ID);
performComplexTextBinding(dbc, pwmChannelText, modelObservable, INT_STRING_CONVERTER,
STRING_INT_CONVERTER, TextToIntegerValidator.INSTANCE,
new BoundedIntPositiveZeroValidator(0, 1));
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2017 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.ui.properties;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
import org.fortiss.tooling.base.ui.databinding.NumberPositiveZeroValidator;
/**
* A {@link NumberPositiveZeroValidator} with boundary checking for int values.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class BoundedIntPositiveZeroValidator extends NumberPositiveZeroValidator {
/** The lower bound. */
private final int lowerBound;
/** The upper bound. */
private final int upperBound;
/** Constructor. */
public BoundedIntPositiveZeroValidator(int lower, int upper) {
this.lowerBound = lower;
this.upperBound = upper;
}
/** {@inheritDoc} */
@Override
public IStatus validate(Object value) {
IStatus status = super.validate(value);
if(status == ValidationStatus.ok()) {
double dval = ((Number)value).doubleValue();
if(dval >= lowerBound && dval <= upperBound) {
return ValidationStatus.ok();
}
return ValidationStatus.cancel("Value must be between " + lowerBound + " and " +
upperBound + "!");
}
return status;
}
}
......@@ -24,7 +24,6 @@ import static org.fortiss.af3.expression.ui.databinding.validate.StringToIntConv
import static org.fortiss.tooling.kernel.ui.util.DataBindingUtils.performComplexTextBinding;
import static org.fortiss.tooling.kernel.ui.util.ObservableUtils.observeValue;
import org.conqat.ide.commons.ui.databinding.validate.NumberPositiveValidator;
import org.conqat.ide.commons.ui.databinding.validate.TextToIntegerValidator;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.swt.SWT;
......@@ -45,10 +44,9 @@ import org.fortiss.tooling.kernel.ui.extension.base.PropertySectionBase;
* @ConQAT.Rating GREEN Hash: 9E768B733BD37201F97399293FA0DFA7
*/
public class RaspberryPiExecutionUnitPropertySection extends PropertySectionBase {
/** The execution unit. */
private RaspberryPi unit;
/** The virtual keyboard port number widget. */
/** The CAN ID of this unit. */
private Text canCoordinationIDText;
/** The cycle time widget. */
private Text cycleTimeText;
......@@ -85,13 +83,13 @@ public class RaspberryPiExecutionUnitPropertySection extends PropertySectionBase
RaspberryPiModelPackage.Literals.RASPBERRY_PI__CAN_COORDINATION_ID);
performComplexTextBinding(dbc, canCoordinationIDText, modelObservable,
INT_STRING_CONVERTER, STRING_INT_CONVERTER, TextToIntegerValidator.INSTANCE,
new NumberPositiveValidator());
new BoundedIntPositiveZeroValidator(245, 255));
modelObservable =
observeValue(unit, RaspberryPiModelPackage.Literals.RASPBERRY_PI__CYCLE_TIME);
performComplexTextBinding(dbc, cycleTimeText, modelObservable, INT_STRING_CONVERTER,
STRING_INT_CONVERTER, TextToIntegerValidator.INSTANCE,
new NumberPositiveValidator());
new BoundedIntPositiveZeroValidator(20, 10000));
modelObservable =
observeValue(unit, RaspberryPiModelPackage.Literals.RASPBERRY_PI__IP_ADDRESS);
......
......@@ -17,55 +17,51 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
+--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.executable;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.funcCall;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.createDataDictionary;
import static org.fortiss.af3.generator.common.utils.CLanguageModelElementFacade.addUserHeaderInclude;
import static org.fortiss.af3.generator.common.utils.CLanguageModelElementFactory.createCSourcePackage;
import static org.fortiss.af3.generator.common.utils.SourceModelElementFactory.createByteContentUnitForPluginFile;
import static org.fortiss.af3.platform.raspberry.generator.templates.RasPiCTemplates.getEclipseProjectFile;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getRootElement;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.error;
import static org.fortiss.tooling.kernel.utils.TransformationUtils.createTransformedObjectFor;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Set;
import org.conqat.lib.commons.collections.Pair;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.component.model.OutputPort;
import org.fortiss.af3.component.model.Port;
import org.fortiss.af3.component.model.generator.ComponentFunction;
import org.fortiss.af3.component.model.generator.LocalFunction;
import org.fortiss.af3.component.model.generator.ComponentProgram;
import org.fortiss.af3.expression.model.DataDictionary;
import org.fortiss.af3.expression.model.terms.IExpressionTerm;
import org.fortiss.af3.expression.model.terms.imperative.IStatementTerm;
import org.fortiss.af3.generator.common.model.c.CSourcePackage;
import org.fortiss.af3.generator.common.model.source.SourceUnit;
import org.fortiss.af3.platform.generic.generator.executable.GenericExecutionUnitExecutable;
import org.fortiss.af3.platform.language.executable.IInitializableExecutable;
import org.fortiss.af3.platform.language.executable.IReadableExecutable;
import org.fortiss.af3.platform.language.executable.ITerminatableExecutable;
import org.fortiss.af3.platform.language.executable.IWritableExecutable;
import org.fortiss.af3.platform.language.executable.ExecutionUnitExecutableBase;
import org.fortiss.af3.platform.model.ExecutionUnit;
import org.fortiss.af3.platform.model.PlatformConnectorUnit;
import org.fortiss.af3.platform.model.generic.GenericTransceiver;
import org.fortiss.af3.platform.raspberry.AF3PlatformRaspberryActivator;
import org.fortiss.af3.platform.raspberry.model.RaspberryPi;
import org.fortiss.tooling.kernel.extension.data.ITransformationContext;
import org.fortiss.tooling.kernel.extension.exception.ChainTransformationFailedException;
/**
* {@link IInitializableExecutable} and {@link ITerminatableExecutable} for the {@link RaspberryPi}
* platform.
*
* {@link ExecutionUnitExecutableBase} for the {@link RaspberryPi} platform.
*
* @author eder
* @author hoelzl
* @author $Author: eder $
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
*/
public class RaspberryPIExecutable extends GenericExecutionUnitExecutable {
public class RaspberryPIExecutable extends ExecutionUnitExecutableBase<RaspberryPi, CSourcePackage> {
private static final String SRC_LIB_SUB_PACKAGE_NAME = "src-lib";
private static final String INC_LIB_SUB_PACKAGE_NAME = "inc-lib";
/** Constructor. */
public RaspberryPIExecutable(ExecutionUnit modelElement) {
public RaspberryPIExecutable(RaspberryPi modelElement) {
super(modelElement);
}
......@@ -74,60 +70,51 @@ public class RaspberryPIExecutable extends GenericExecutionUnitExecutable {
protected CSourcePackage createExecutionUnitSourcePackage(String name,
List<Pair<ExecutionUnit, Component>> deployedComponents,
List<Pair<PlatformConnectorUnit, Port>> deployedPorts, ITransformationContext context) {
CSourcePackage pkg =
super.createExecutionUnitSourcePackage(name, deployedComponents, deployedPorts,
context);
// get system.h to add references to self-defined inc files
SourceUnit system = pkg.getSrcGenPackage().findSourceUnitByName("system.c");
// Add source/header files here to be copied into the deployment directory
// create the result package
CSourcePackage sourcePackage = createCSourcePackage();
sourcePackage.setBaseLocation(name);
try {
/** COMPONENTS **/
addFile(pkg, "src/main.c");
// reference is added by GenericExecutableBase -> only add file
addFile(pkg, "inc/io.h");
addFile(pkg, "src/io.c");
// add all components including references
addFilesWithReference(pkg, system, "CanConnector");
addFilesWithReference(pkg, system, "Gamepad");
addFilesWithReference(pkg, system, "GPIO");
addFilesWithReference(pkg, system, "IMU");
addFilesWithReference(pkg, system, "LaserRangeFinder");
addFilesWithReference(pkg, system, "LaserScanner");
addFilesWithReference(pkg, system, "PWM");
/** LIBRARIES **/
// add UART lib
addFile(pkg, "inc/libuart.h");
addFile(pkg, "src/libuart.c");
addFile(pkg, "inc/libmaestro.h");
addFile(pkg, "src/libmaestro.c");
addFile(pkg, "inc/libcansocket.h");
addFile(pkg, "src/libcansocket.c");
/** FIXES AND PATCHES **/
// overwrite data_dictionary, the new one has all functions
// required for the simulation commented out so there are no
// conflicts
addFile(pkg, "inc-gen/data_dictionary.h");
addFile(pkg, "src-gen/data_dictionary.c");
addDataDictionaryCode(context, sourcePackage);
addLogicalComponentCode(deployedComponents, context, sourcePackage);
addEclipseCProjectFiles(sourcePackage, modelElement.getName());
} catch(Exception ex) {
error(AF3PlatformRaspberryActivator.getDefault(), ex.getMessage(), ex);
ex.printStackTrace();
}
return sourcePackage;
}
// overwrite Makedefs, the new one uses -std=gnu99 instead of -std=c99
// so libuart compiles properly
addFile(pkg, "Makedefs");
/** Adds auxiliary files for Eclipse C project. */
private void addEclipseCProjectFiles(CSourcePackage sourcePackage, String projectName) {
sourcePackage.addUnit(getEclipseProjectFile(projectName));
}
} catch(IOException | URISyntaxException e) {
throw new RuntimeException("could not add header and source files from lib", e);
/** Creates the code for all deployed components. */
private void addLogicalComponentCode(List<Pair<ExecutionUnit, Component>> deployedComponents,
ITransformationContext context, CSourcePackage sourcePackage)
throws ChainTransformationFailedException {
for(Pair<ExecutionUnit, Component> pair : deployedComponents) {
if(pair.getFirst() != modelElement) {
continue;
}
Component cmp = pair.getSecond();
ComponentProgram cprog =
createTransformedObjectFor(cmp, ComponentProgram.class, context);
CSourcePackage cPack = createTransformedObjectFor(cprog, CSourcePackage.class, context);
cPack.mergeInto(sourcePackage);
}
}
return pkg;
/** Creates the code for the data dictionary. */
private void
addDataDictionaryCode(ITransformationContext context, CSourcePackage sourcePackage)
throws ChainTransformationFailedException {
DataDictionary dd = getRootElement(modelElement, DataDictionary.class);
if(dd == null) {
dd = createDataDictionary();
}
CSourcePackage ddPackage = createTransformedObjectFor(dd, CSourcePackage.class, context);
ddPackage.mergeInto(sourcePackage);
}
private static void addFilesWithReference(CSourcePackage pkg, SourceUnit source,
......@@ -147,60 +134,15 @@ public class RaspberryPIExecutable extends GenericExecutionUnitExecutable {
addUserHeaderInclude(source, reference);
}
/** {@inheritDoc} */
@Override
protected ComponentFunction createInitializeFunction(
List<Pair<ExecutionUnit, Component>> deployedComponents,
Set<PlatformConnectorUnit> usedUnits) {
return super.createInitializeFunction(deployedComponents, usedUnits);
}
/** {@inheritDoc} */
@Override
protected void
createReadAccess(IReadableExecutable exec, InputPort p, List<IStatementTerm> body) {
super.createReadAccess(exec, p, body);
}
/** {@inheritDoc} */
@Override
protected LocalFunction createReadInputFunction(
List<Pair<PlatformConnectorUnit, Port>> deployedPorts,
Set<GenericTransceiver> usedTransceivers) {
return super.createReadInputFunction(deployedPorts, usedTransceivers);
}
/** {@inheritDoc} */
@Override
protected ComponentFunction createStepFunction(
List<Pair<ExecutionUnit, Component>> deployedComponents,
List<Pair<PlatformConnectorUnit, Port>> deployedPorts,
Set<GenericTransceiver> usedTransceivers) {
return super.createStepFunction(deployedComponents, deployedPorts, usedTransceivers);
}
/** {@inheritDoc} */
@Override
protected LocalFunction createTerminationFunction(Set<PlatformConnectorUnit> usedUnits) {
return super.createTerminationFunction(usedUnits);
}
/** {@inheritDoc} */
@Override
protected void createWriteAccess(IWritableExecutable exec, OutputPort p,
List<IStatementTerm> body) {
super.createWriteAccess(exec, p, body);
}
/** {@inheritDoc} */
@Override
public IExpressionTerm getInitialization() {
return funcCall("init_raspberryPI_ecu");
return null;
}
/** {@inheritDoc} */
@Override
public IExpressionTerm getTermination() {
return funcCall("term_raspberryPI_ecu");
return null;
}
}
group ProjectFile;
ProjectFile(projectname) ::= <<
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>$projectname$</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
</projectDescription>
>>
\ No newline at end of file
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2017 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.templates;
import static org.fortiss.af3.generator.common.AF3GeneratorCommonActivator.getDefault;
import static org.fortiss.af3.generator.common.utils.SourceModelElementFactory.createStaticContentSourceUnit;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.error;
import java.io.IOException;
import java.io.InputStreamReader;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.language.DefaultTemplateLexer;
import org.fortiss.af3.generator.common.model.source.AbstractUnit;
import org.fortiss.af3.generator.common.model.source.StaticContentSourceUnit;
/**
* Templates used by the RasPi C code generator.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public final class RasPiCTemplates {
/** Returns the '.project' file used for Eclipse project. */
public static AbstractUnit getEclipseProjectFile(String projectName) {
StringTemplate template = makeTemplate("ProjectFile.stg", "ProjectFile");
template.setAttribute("projectname", projectName);
StaticContentSourceUnit unit =
createStaticContentSourceUnit(".project", template.toString(), false);
return unit;
}
/** Evaluates the given template. */
protected static StringTemplate makeTemplate(String stgFile, String instance) {
StringTemplateGroup stg = loadResourceSTG(stgFile);
StringTemplate st = stg.getInstanceOf(instance);
return st;
}
/** Loads the given template using the class loader of the given class. */
private static StringTemplateGroup loadResourceSTG(String stgName) {
InputStreamReader in =
new InputStreamReader(RasPiCTemplates.class.getResourceAsStream(stgName));
StringTemplateGroup templates = new StringTemplateGroup(in, DefaultTemplateLexer.class);
try {
in.close();
} catch(IOException e) {
error(getDefault(), "AF3 generator could not load stringtemplate " + stgName + ".", e);
}
return templates;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment