From 4b45c699fdb075e5610aa065b6474b7d99b5fcb5 Mon Sep 17 00:00:00 2001 From: Florian Hoelzl <hoelzl@fortiss.org> Date: Fri, 25 May 2018 14:05:50 +0200 Subject: [PATCH] Gamepad and PWM actuator header and library copy working properly. Signed-off-by: Florian Hoelzl <hoelzl@fortiss.org> --- .../raspberry/generator/executable/.ratings | 4 +- .../executable/PWMActuatorExecutable.java | 6 ++ .../executable/RaspberryPIExecutable.java | 62 ++++++++++++++++--- .../generator/executable/gamepad/.ratings | 2 +- .../gamepad/GamepadExecutableBase.java | 6 ++ .../generator/executable/library/.ratings | 4 +- .../library/BrickLibraryExecutableBase.java | 10 ++- .../library/PiHALLibraryExecutableBase.java | 10 ++- 8 files changed, 89 insertions(+), 15 deletions(-) diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/.ratings b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/.ratings index f797ad8e..4785829b 100644 --- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/.ratings +++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/.ratings @@ -4,6 +4,6 @@ CanTransmissionCatalog.java ec4637eda80234429a9f382a37713588a0fbb83a RED ConsoleOutputExecutable.java 5b8c50f2236ad49958a0a0b599a7e60265a6fc06 YELLOW HeaderCopyGenerator.java 18239a3adae35256e32dad19df9d8f38acbf7e66 RED MultiUnitMainGenerator.java 458754b89c2d79db3fee08baa444424772e40fb7 RED -PWMActuatorExecutable.java ff4ab2e9f29af55e2564338b50533b09f86d6224 YELLOW -RaspberryPIExecutable.java fd83311332ba0ad5d2cc2f09d406b5b0d2ee6668 RED +PWMActuatorExecutable.java 9068846c7ff04c034da6493067fcebf73051de98 YELLOW +RaspberryPIExecutable.java 2c3ac0beaf690ebdb0a0a60ffcacaaf50a49e242 RED SingleUnitMainGenerator.java e1df0d82804fd0622b97ecde827844da30370e14 RED diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/PWMActuatorExecutable.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/PWMActuatorExecutable.java index ff4ab2e9..9068846c 100644 --- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/PWMActuatorExecutable.java +++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/PWMActuatorExecutable.java @@ -52,4 +52,10 @@ public class PWMActuatorExecutable extends PiHALLibraryExecutableBase<ActuatorPW public IExpressionTerm getValueWriteAccessor(OutputPort logicalSignal, IExpressionTerm value) { return funcCall("temp_actuator_set_target", intConst(modelElement.getChannelID()), value); } + + /** {@inheritDoc} */ + @Override + public String getHeaderFileName() { + return "temp_actuator.h"; + } } diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/RaspberryPIExecutable.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/RaspberryPIExecutable.java index fd833113..2c3ac0be 100644 --- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/RaspberryPIExecutable.java +++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/RaspberryPIExecutable.java @@ -18,7 +18,6 @@ package org.fortiss.af3.platform.raspberry.generator.executable; import static org.fortiss.af3.component.utils.ComponentArchitectureUtils.isAtomicComponent; import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.createDataDictionary; import static org.fortiss.af3.generator.common.utils.CLanguageModelElementFactory.createCSourcePackage; -import static org.fortiss.af3.platform.raspberry.generator.executable.HeaderCopyGenerator.copyHeaderFiles; import static org.fortiss.af3.platform.raspberry.generator.templates.RasPiCTemplates.getConfigureFile; import static org.fortiss.af3.platform.raspberry.generator.templates.RasPiCTemplates.getEclipseProjectFile; import static org.fortiss.af3.platform.raspberry.generator.templates.RasPiCTemplates.getMakedefsFile; @@ -26,9 +25,12 @@ import static org.fortiss.af3.platform.utils.PlatformArchitectureUtils.findAtomi 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 static org.fortiss.tooling.kernel.utils.TransformationUtils.createTransformedObjectWithoutExceptionFor; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.conqat.lib.commons.collections.Pair; import org.fortiss.af3.component.model.Component; @@ -41,11 +43,15 @@ import org.fortiss.af3.expression.model.DataDictionary; import org.fortiss.af3.expression.model.terms.IExpressionTerm; import org.fortiss.af3.generator.common.model.c.AF3GeneratorCommonLanguagesCFactory; import org.fortiss.af3.generator.common.model.c.CSourcePackage; +import org.fortiss.af3.platform.language.executable.ExecutableBase; 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.TransmissionUnit; import org.fortiss.af3.platform.raspberry.AF3PlatformRaspberryActivator; +import org.fortiss.af3.platform.raspberry.generator.executable.framework.IRasPiHeaderExecutable; +import org.fortiss.af3.platform.raspberry.generator.executable.framework.IRasPiLibraryBasedExecutable; +import org.fortiss.af3.platform.raspberry.generator.executable.framework.IRasPiSourceBasedExecutable; import org.fortiss.af3.platform.raspberry.model.CanBus; import org.fortiss.af3.platform.raspberry.model.RaspberryPi; import org.fortiss.tooling.kernel.extension.data.ITransformationContext; @@ -78,6 +84,7 @@ public class RaspberryPIExecutable extends ExecutionUnitExecutableBase<Raspberry private CanTransmissionCatalog canCatalog; /** The list of atomic components deployed on this execution unit. */ private List<Component> atomics = new ArrayList<>(); + // code generator output /** The C source package produced by this generator. */ private CSourcePackage generatorResult; @@ -98,10 +105,10 @@ public class RaspberryPIExecutable extends ExecutionUnitExecutableBase<Raspberry try { addEclipseCProjectFiles(); addConfigureAndMakedefsFiles(); - addStaticLibrariesAndCode(); + addPlatformElementsCode(deployedPorts); addDataDictionaryCode(); addLogicalComponentCode(deployedComponents); - addMainFile(deployedComponents, deployedPorts); + // addMainFile(deployedComponents, deployedPorts); } catch(Exception ex) { error(AF3PlatformRaspberryActivator.getDefault(), ex.getMessage(), ex); ex.printStackTrace(); @@ -109,6 +116,45 @@ public class RaspberryPIExecutable extends ExecutionUnitExecutableBase<Raspberry return generatorResult; } + /** Adds the libraries and header files required by the used platform elements. */ + private void addPlatformElementsCode(List<Pair<PlatformConnectorUnit, Port>> deployedPorts) { + Set<String> includedHeaders = new HashSet<>(); + Set<String> includedSources = new HashSet<>(); + Set<String> includedLibraries = new HashSet<>(); + for(Pair<PlatformConnectorUnit, Port> pair : deployedPorts) { + PlatformConnectorUnit pcu = pair.getFirst(); + ExecutableBase<?> executable = + createTransformedObjectWithoutExceptionFor(pcu, ExecutableBase.class, context); + if(executable instanceof IRasPiHeaderExecutable) { + IRasPiHeaderExecutable headerExec = (IRasPiHeaderExecutable)executable; + if(!includedHeaders.contains(headerExec.getHeaderFileName())) { + generatorResult.getSubPackage(INC_LIB_SUB_PACKAGE_NAME).addUnit( + headerExec.getHeaderFileContent()); + includedHeaders.add(headerExec.getHeaderFileName()); + } + // ignore header file, since it is already included + } + if(executable instanceof IRasPiSourceBasedExecutable) { + IRasPiSourceBasedExecutable srcExec = (IRasPiSourceBasedExecutable)executable; + if(!includedSources.contains(srcExec.getSourceFileName())) { + generatorResult.getSubPackage(SRC_LIB_SUB_PACKAGE_NAME).addUnit( + srcExec.getSourceFileContent()); + includedSources.add(srcExec.getSourceFileName()); + } + // ignore source file, since it is already included + } + if(executable instanceof IRasPiLibraryBasedExecutable) { + IRasPiLibraryBasedExecutable libExec = (IRasPiLibraryBasedExecutable)executable; + if(!includedLibraries.contains(libExec.getLibraryFileName())) { + generatorResult.getSubPackage(LIB_SUB_PACKAGE_NAME).addUnit( + libExec.getLibraryFileContent()); + includedLibraries.add(libExec.getLibraryFileName()); + } + // ignore library file, since it is already included + } + } + } + /** Initializes the generator result source package. */ private void createGeneratorResultSourcePackage(String name) { // create the result package @@ -122,6 +168,11 @@ public class RaspberryPIExecutable extends ExecutionUnitExecutableBase<Raspberry CSourcePackage lib = AF3GeneratorCommonLanguagesCFactory.eINSTANCE.createCSourcePackage(); lib.setBaseLocation(LIB_SUB_PACKAGE_NAME); generatorResult.getSubPackages().add(lib); + + CSourcePackage srcLib = + AF3GeneratorCommonLanguagesCFactory.eINSTANCE.createCSourcePackage(); + srcLib.setBaseLocation(SRC_LIB_SUB_PACKAGE_NAME); + generatorResult.getSubPackages().add(srcLib); } /** Adds the code for the deployed logical components. */ @@ -198,11 +249,6 @@ public class RaspberryPIExecutable extends ExecutionUnitExecutableBase<Raspberry generatorResult.addUnit(getMakedefsFile()); } - /** Adds the library code need by the deployment code generator. */ - private void addStaticLibrariesAndCode() throws Exception { - copyHeaderFiles(null); - } - /** Adds auxiliary files for Eclipse C project. */ private void addEclipseCProjectFiles() { generatorResult.addUnit(getEclipseProjectFile(modelElement.getName())); diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/gamepad/.ratings b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/gamepad/.ratings index b032c455..91bca050 100644 --- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/gamepad/.ratings +++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/gamepad/.ratings @@ -7,7 +7,7 @@ ButtonL1Executable.java ab68cddae1d323ff0ecd7956133c44d1ef0f9168 YELLOW ButtonL2Executable.java 336b9d8d26a682b701f7a2ca078369c9cc621fbb YELLOW ButtonR1Executable.java 700ef701ed77a0d3f8141166fe647ac5cd4ad570 YELLOW ButtonR2Executable.java 9b4acdc37505f41c60d8216c92bcbd3f43a2ccec YELLOW -GamepadExecutableBase.java 520499696335e537bfb2197fa53afcdacb41efcf YELLOW +GamepadExecutableBase.java 5b769ad3d004d5b9c2ced63258a6d63eb6c41579 YELLOW Left_StickXExecutable.java c3e7f28f44fa27bd79e14ed7e60f44be2dc5a9ab YELLOW Left_StickYExecutable.java f81cc1e3124eb712507825bc54e7d0f633fde640 YELLOW Right_StickXExecutable.java ade165c88d0c6758efa167e5ba445eff87a0fd79 YELLOW diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/gamepad/GamepadExecutableBase.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/gamepad/GamepadExecutableBase.java index 52049969..5b769ad3 100644 --- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/gamepad/GamepadExecutableBase.java +++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/gamepad/GamepadExecutableBase.java @@ -52,4 +52,10 @@ abstract class GamepadExecutableBase<T extends EObject> extends PiHALLibraryExec // use EMF package as singleton identifier return GamepadPackage.eNS_URI; } + + /** {@inheritDoc} */ + @Override + public final String getHeaderFileName() { + return "gamepad.h"; + } } diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/library/.ratings b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/library/.ratings index 71b633e4..ba2b4096 100644 --- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/library/.ratings +++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/library/.ratings @@ -1,2 +1,2 @@ -BrickLibraryExecutableBase.java 797162a1dbb8b18c439cd2a3eb00166053fd8834 YELLOW -PiHALLibraryExecutableBase.java be4fe458679bd8fdca4c727b3380911a0f1a3e41 YELLOW +BrickLibraryExecutableBase.java 3556b41e6ca909aaf89fa58eac31c63d0cfeb788 YELLOW +PiHALLibraryExecutableBase.java d64da670a3f39ef53a8f548955f35b588308ba76 YELLOW diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/library/BrickLibraryExecutableBase.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/library/BrickLibraryExecutableBase.java index 797162a1..3556b41e 100644 --- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/library/BrickLibraryExecutableBase.java +++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/library/BrickLibraryExecutableBase.java @@ -21,6 +21,7 @@ import org.eclipse.emf.ecore.EObject; import org.fortiss.af3.generator.common.model.source.ByteContentUnit; import org.fortiss.af3.platform.language.executable.ExecutableBase; import org.fortiss.af3.platform.raspberry.AF3PlatformRaspberryActivator; +import org.fortiss.af3.platform.raspberry.generator.executable.framework.IRasPiHeaderExecutable; import org.fortiss.af3.platform.raspberry.generator.executable.framework.IRasPiLibraryBasedExecutable; /** @@ -29,7 +30,7 @@ import org.fortiss.af3.platform.raspberry.generator.executable.framework.IRasPiL * @author hoelzl */ public abstract class BrickLibraryExecutableBase<T extends EObject> extends ExecutableBase<T> - implements IRasPiLibraryBasedExecutable { + implements IRasPiLibraryBasedExecutable, IRasPiHeaderExecutable { /** Constructor. */ public BrickLibraryExecutableBase(T modelElement) { super(modelElement); @@ -47,4 +48,11 @@ public abstract class BrickLibraryExecutableBase<T extends EObject> extends Exec return createByteContentUnitForPluginFileInRCP(AF3PlatformRaspberryActivator.PLUGIN_ID, "code-gen-hal/lib", "libbrick.a", false); } + + /** {@inheritDoc} */ + @Override + public final ByteContentUnit getHeaderFileContent() { + return createByteContentUnitForPluginFileInRCP(AF3PlatformRaspberryActivator.PLUGIN_ID, + "code-gen-hal/inc/brick", getHeaderFileName(), false); + } } diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/library/PiHALLibraryExecutableBase.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/library/PiHALLibraryExecutableBase.java index be4fe458..d64da670 100644 --- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/library/PiHALLibraryExecutableBase.java +++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/library/PiHALLibraryExecutableBase.java @@ -21,6 +21,7 @@ import org.eclipse.emf.ecore.EObject; import org.fortiss.af3.generator.common.model.source.ByteContentUnit; import org.fortiss.af3.platform.language.executable.ExecutableBase; import org.fortiss.af3.platform.raspberry.AF3PlatformRaspberryActivator; +import org.fortiss.af3.platform.raspberry.generator.executable.framework.IRasPiHeaderExecutable; import org.fortiss.af3.platform.raspberry.generator.executable.framework.IRasPiLibraryBasedExecutable; /** @@ -29,7 +30,7 @@ import org.fortiss.af3.platform.raspberry.generator.executable.framework.IRasPiL * @author hoelzl */ public abstract class PiHALLibraryExecutableBase<T extends EObject> extends ExecutableBase<T> - implements IRasPiLibraryBasedExecutable { + implements IRasPiLibraryBasedExecutable, IRasPiHeaderExecutable { /** Constructor. */ public PiHALLibraryExecutableBase(T modelElement) { super(modelElement); @@ -47,4 +48,11 @@ public abstract class PiHALLibraryExecutableBase<T extends EObject> extends Exec return createByteContentUnitForPluginFileInRCP(AF3PlatformRaspberryActivator.PLUGIN_ID, "code-gen-hal/lib", "libaf3pihal.a", false); } + + /** {@inheritDoc} */ + @Override + public final ByteContentUnit getHeaderFileContent() { + return createByteContentUnitForPluginFileInRCP(AF3PlatformRaspberryActivator.PLUGIN_ID, + "code-gen-hal/inc/af3pihal", getHeaderFileName(), false); + } } -- GitLab