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

Added motorcontrol code generator extension.

parent 5672ee7f
No related branches found
No related tags found
No related merge requests found
Showing
with 96 additions and 48 deletions
......@@ -4,5 +4,5 @@ CanTransmissionCatalog.java 959d488ebec4ae6a50c3f699d42aad535b1ae0c3 YELLOW
ConsoleOutputGeneratorExtension.java d57db44d57630a50e26c9eeed90d6631bf99db5d YELLOW
MultiUnitMainGenerator.java 458754b89c2d79db3fee08baa444424772e40fb7 RED
PWMActuatorGeneratorExtension.java 8cbfd72070cfc1c8a4da4ccc1d18a6b3e75cea7f YELLOW
RaspberryPIGeneratorExtension.java c81d5606099b3922c70aecd103b2a7269b90f0a6 RED
RaspberryPIGeneratorExtension.java 2cd95ddc54d7562bd9fa0b8a4018c25eda01b5a8 RED
SingleUnitMainGenerator.java 93d0370b01330ab023e02761df818d36fac42b0f RED
......@@ -52,6 +52,8 @@ 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.framework.IPreinstalledHeaderGeneratorExtension;
import org.fortiss.af3.platform.raspberry.generator.framework.IPreinstalledLibraryGeneratorExtension;
import org.fortiss.af3.platform.raspberry.generator.framework.IRasPiCopiedHeaderGeneratorExtension;
import org.fortiss.af3.platform.raspberry.generator.framework.IRasPiCopiedLibraryBasedGeneratorExtension;
import org.fortiss.af3.platform.raspberry.generator.framework.IRasPiCopiedSourceBasedGeneratorExtension;
......@@ -80,7 +82,7 @@ public class RaspberryPIGeneratorExtension extends
/** The list of atomic components deployed on this execution unit. */
private List<Component> atomics = new ArrayList<>();
/** The map from platform elements to executables. */
private Map<PlatformConnectorUnit, ExecutableBase<?>> platformConnector2ExecutableBase =
private Map<PlatformConnectorUnit, ExecutableBase<?>> platformConnector2ExtensionBase =
new HashMap<>();
/** Set of headers to be included. */
private Set<String> includedHeaders = new HashSet<>();
......@@ -106,13 +108,13 @@ public class RaspberryPIGeneratorExtension extends
this.context = context;
findDeploymentAndLookForCanTransmissionCatalog();
createGeneratorResultSourcePackage(name);
analyzePlatformElementsAndCopyCode(deployedPorts);
try {
addEclipseCProjectFiles();
addConfigureAndMakedefsFiles();
Set<String> headers = addPlatformElementsCode(deployedPorts);
addDataDictionaryCode();
addLogicalComponentCode(deployedComponents);
addMainFile(deployedComponents, deployedPorts, headers);
addMainFile(deployedComponents, deployedPorts);
} catch(Exception ex) {
error(AF3PlatformRaspberryActivator.getDefault(), ex.getMessage(), ex);
ex.printStackTrace();
......@@ -124,46 +126,63 @@ public class RaspberryPIGeneratorExtension extends
* Adds the libraries and header files required by the used platform elements and returns the
* set of header file names.
*/
private Set<String> addPlatformElementsCode(
private void analyzePlatformElementsAndCopyCode(
List<Pair<PlatformConnectorUnit, Port>> deployedPorts) {
for(Pair<PlatformConnectorUnit, Port> pair : deployedPorts) {
PlatformConnectorUnit pcu = pair.getFirst();
ExecutableBase<?> executable =
ExecutableBase<?> extension =
createTransformedObjectWithoutExceptionFor(pcu, ExecutableBase.class, context);
platformConnector2ExecutableBase.put(pcu, executable);
if(executable instanceof IRasPiCopiedHeaderGeneratorExtension) {
IRasPiCopiedHeaderGeneratorExtension headerExec =
(IRasPiCopiedHeaderGeneratorExtension)executable;
if(!includedHeaders.contains(headerExec.getHeaderFileName())) {
platformConnector2ExtensionBase.put(pcu, extension);
if(extension instanceof IRasPiCopiedHeaderGeneratorExtension) {
IRasPiCopiedHeaderGeneratorExtension headerExt =
(IRasPiCopiedHeaderGeneratorExtension)extension;
if(!includedHeaders.contains(headerExt.getHeaderFileName())) {
generatorResult.getSubPackage(INC_LIB_SUB_PACKAGE_NAME).addUnit(
headerExec.getHeaderFileContent());
includedHeaders.add(headerExec.getHeaderFileName());
headerExt.getHeaderFileContent());
includedHeaders.add(headerExt.getHeaderFileName());
}
// ignore header file, since it is already included
}
if(executable instanceof IRasPiCopiedSourceBasedGeneratorExtension) {
IRasPiCopiedSourceBasedGeneratorExtension srcExec =
(IRasPiCopiedSourceBasedGeneratorExtension)executable;
if(!includedSources.contains(srcExec.getSourceFileName())) {
if(extension instanceof IRasPiCopiedSourceBasedGeneratorExtension) {
IRasPiCopiedSourceBasedGeneratorExtension srcExt =
(IRasPiCopiedSourceBasedGeneratorExtension)extension;
if(!includedSources.contains(srcExt.getSourceFileName())) {
generatorResult.getSubPackage(SRC_LIB_SUB_PACKAGE_NAME).addUnit(
srcExec.getSourceFileContent());
includedSources.add(srcExec.getSourceFileName());
srcExt.getSourceFileContent());
includedSources.add(srcExt.getSourceFileName());
}
// ignore source file, since it is already included
}
if(executable instanceof IRasPiCopiedLibraryBasedGeneratorExtension) {
IRasPiCopiedLibraryBasedGeneratorExtension libExec =
(IRasPiCopiedLibraryBasedGeneratorExtension)executable;
if(!includedLibraries.contains(libExec.getLibraryFileName())) {
if(extension instanceof IRasPiCopiedLibraryBasedGeneratorExtension) {
IRasPiCopiedLibraryBasedGeneratorExtension libExt =
(IRasPiCopiedLibraryBasedGeneratorExtension)extension;
if(!includedLibraries.contains(libExt.getLibraryFileName())) {
generatorResult.getSubPackage(LIB_SUB_PACKAGE_NAME).addUnit(
libExec.getLibraryFileContent());
includedLibraries.add(libExec.getLibraryFileName());
includedLibraries.addAll(libExec.getDependencyLibraries());
libExt.getLibraryFileContent());
includedLibraries.add(libExt.getLibraryFileName());
includedLibraries.addAll(libExt.getDependencyLibraries());
}
// ignore library file, since it is already included
}
if(extension instanceof IPreinstalledHeaderGeneratorExtension) {
IPreinstalledHeaderGeneratorExtension preHExt =
(IPreinstalledHeaderGeneratorExtension)extension;
for(String header : preHExt.getHeaderIncludes()) {
if(!includedHeaders.contains(header)) {
includedHeaders.add(header);
}
}
}
if(extension instanceof IPreinstalledLibraryGeneratorExtension) {
IPreinstalledLibraryGeneratorExtension preLExt =
(IPreinstalledLibraryGeneratorExtension)extension;
for(String lib : preLExt.getLibraryNames()) {
if(!includedLibraries.contains(lib)) {
includedLibraries.add(lib);
}
}
}
}
return includedHeaders;
}
/** Initializes the generator result source package. */
......@@ -239,7 +258,7 @@ public class RaspberryPIGeneratorExtension extends
/** Creates the main file by using the {@link SingleUnitMainGenerator} helper class. */
private void addMainFile(List<Pair<ExecutionUnit, Component>> deployedComponents,
List<Pair<PlatformConnectorUnit, Port>> deployedPorts, Set<String> headers) {
List<Pair<PlatformConnectorUnit, Port>> deployedPorts) {
CSourcePackage srcGenPack = (CSourcePackage)generatorResult.getSrcGenPackage();
if(canCatalog != null) {
MultiUnitMainGenerator mg =
......@@ -249,7 +268,7 @@ public class RaspberryPIGeneratorExtension extends
} else {
SingleUnitMainGenerator mg =
new SingleUnitMainGenerator(modelElement, deployedComponents, deployedPorts,
platformConnector2ExecutableBase, headers, context);
platformConnector2ExtensionBase, includedHeaders, context);
srcGenPack.addUnit(mg.createSingleUnitMain());
}
}
......
BrickLibraryGeneratorExtensionBase.java 2b22b7ef042ef6eced32f227fd4d682bab421722 YELLOW
PiHALLibraryGeneratorExtensionBase.java d6678cf07b655b33844329dae89603d7827c63b1 YELLOW
VescLibraryGeneratorExtensionBase.java 1227d3de77cab52a396b3d9751a6b43a8c373b31 YELLOW
VescLibraryGeneratorExtensionBase.java 0a78b5894b50213bb11cd2b7066b63823c7aa7c7 YELLOW
......@@ -25,7 +25,7 @@ import org.fortiss.af3.platform.raspberry.generator.framework.IPreinstalledHeade
import org.fortiss.af3.platform.raspberry.generator.framework.IPreinstalledLibraryGeneratorExtension;
/**
* Base class for executables using the Vesc library.
* Base class for executables using the vesc library.
*
* @author hoelzl
*/
......@@ -39,8 +39,8 @@ public abstract class VescLibraryGeneratorExtensionBase<T extends EObject> exten
/** {@inheritDoc} */
@Override
public String getHeaderIncludes() {
return "#include \"hal.h\"\n" + "#include \"commands.h\"\n";
public List<String> getHeaderIncludes() {
return asList("hal.h", "commands.h");
}
/** {@inheritDoc} */
......
MotorControlGeneratorExtensionBase.java 3b62fdf7052bc212bc565c8b891fc3da0912b04b RED
MotorControlInputGeneratorExtension.java fc4f86caf0867d5ec27e2db2461d2e6365eb2dd2 RED
MotorControlOutputGeneratorExtension.java 9ab48031ad519db2aed2cab21c5219d6c8feeefb RED
MotorControlGeneratorExtensionBase.java 41dfce7d14fa23340ee7135ef40828b1d4e87610 YELLOW
MotorControlInputGeneratorExtension.java fb06c42a006eb3f7bfb632739cc763de3e5aaee8 YELLOW
MotorControlOutputGeneratorExtension.java 6eab7224fd0a90eeb47da2c391f21b201791fabf YELLOW
......@@ -17,6 +17,7 @@ package org.fortiss.af3.platform.raspberry.generator.extension.motorcontrol;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.af3.platform.language.executable.ExecutableBase;
import org.fortiss.af3.platform.raspberry.generator.extension.library.VescLibraryGeneratorExtensionBase;
import org.fortiss.af3.platform.raspberry.generator.framework.ISingletonInitializationGeneratorExtension;
/**
......@@ -24,8 +25,8 @@ import org.fortiss.af3.platform.raspberry.generator.framework.ISingletonInitiali
*
* @author hoelzl
*/
abstract class MotorControlGeneratorExtensionBase<T extends EObject> extends ExecutableBase<T>
implements ISingletonInitializationGeneratorExtension {
abstract class MotorControlGeneratorExtensionBase<T extends EObject> extends
VescLibraryGeneratorExtensionBase<T> implements ISingletonInitializationGeneratorExtension {
/** Constructor. */
public MotorControlGeneratorExtensionBase(T modelElement) {
super(modelElement);
......@@ -46,8 +47,6 @@ abstract class MotorControlGeneratorExtensionBase<T extends EObject> extends Exe
/** {@inheritDoc} */
@Override
public final String getSingletonAuxiliaryFunctions(String singletonPostfix) {
// return "extern void initUSB(char* device, int baudRate);\n"
// + "extern void uint8_t get_values();";
return null;
}
......
......@@ -16,8 +16,7 @@
package org.fortiss.af3.platform.raspberry.generator.extension.motorcontrol;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.expression.model.terms.IExpressionTerm;
import org.fortiss.af3.platform.language.executable.IReadableExecutable;
import org.fortiss.af3.platform.raspberry.generator.framework.IReadableGeneratorExtension;
import org.fortiss.af3.platform.raspberry.model.motorcontrol.MotorControlInput;
/**
......@@ -26,7 +25,8 @@ import org.fortiss.af3.platform.raspberry.model.motorcontrol.MotorControlInput;
* @author hoelzl
*/
public class MotorControlInputGeneratorExtension extends
MotorControlGeneratorExtensionBase<MotorControlInput> implements IReadableExecutable {
MotorControlGeneratorExtensionBase<MotorControlInput> implements
IReadableGeneratorExtension {
/** Constructor. */
public MotorControlInputGeneratorExtension(MotorControlInput modelElement) {
super(modelElement);
......@@ -34,8 +34,15 @@ public class MotorControlInputGeneratorExtension extends
/** {@inheritDoc} */
@Override
public IExpressionTerm getValueReadAccessor(InputPort logicalSignal) {
// TODO Auto-generated method stub
public String getReadCode(String postfix, String singletonPostfix, InputPort logicalSignal,
String targetVariable) {
return targetVariable + " = get_velocity();\n";
}
/** {@inheritDoc} */
@Override
public String
getNoValReadCode(String postfix, String singletonPostfix, InputPort logicalSignal) {
return null;
}
}
......@@ -15,7 +15,9 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.extension.motorcontrol;
import org.fortiss.af3.component.model.OutputPort;
import org.fortiss.af3.platform.language.executable.ExecutableBase;
import org.fortiss.af3.platform.raspberry.generator.framework.IWriteableGeneratorExtension;
import org.fortiss.af3.platform.raspberry.model.motorcontrol.MotorControlOutput;
/**
......@@ -23,9 +25,25 @@ import org.fortiss.af3.platform.raspberry.model.motorcontrol.MotorControlOutput;
*
* @author hoelzl
*/
public class MotorControlOutputGeneratorExtension extends ExecutableBase<MotorControlOutput> {
public class MotorControlOutputGeneratorExtension extends
MotorControlGeneratorExtensionBase<MotorControlOutput> implements
IWriteableGeneratorExtension {
/** Constructor. */
public MotorControlOutputGeneratorExtension(MotorControlOutput modelElement) {
super(modelElement);
}
/** {@inheritDoc} */
@Override
public String getWriteCode(String postfix, String singletonPostfix, OutputPort logicalSignal,
String value) {
return "set_velocity(" + value + ");\n";
}
/** {@inheritDoc} */
@Override
public String getNoValWriteCode(String postfix, String singletonPostfix,
OutputPort logicalSignal) {
return ";\n";
}
}
IInstanceGeneratorExtension.java 9d20878f9a1b9f82bd8f9f090bd989af1f08c8ab YELLOW
IInstanceInitializationGeneratorExtension.java ae145d29cb2abbc492380c6af303a12fc2a0daa6 YELLOW
IInstanceTerminationGeneratorExtension.java d9632d04207a484bbe46110ec5925c9850228f30 YELLOW
IPreinstalledHeaderGeneratorExtension.java 120c52d35969b35b5ff1ea50570401d5451ba221 YELLOW
IPreinstalledHeaderGeneratorExtension.java 3da78064729ba9664650d7beacafb61ef68d7733 YELLOW
IPreinstalledLibraryGeneratorExtension.java 437fafdb45561b1acc6c54db2c43c39c48033280 YELLOW
IRasPiCopiedHeaderGeneratorExtension.java 8c08db84c6dfe01b6eb242ea584f3765210fdc56 YELLOW
IRasPiCopiedLibraryBasedGeneratorExtension.java edac836e2553f72a0487ac6455ae87d87d3f6aae YELLOW
......
......@@ -15,6 +15,8 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.framework;
import java.util.List;
/**
* Interface for generator extensions, which require one or more header files to be imported in the
* created main file. This is usually the case when the header files in question are pre-installed
......@@ -24,5 +26,5 @@ package org.fortiss.af3.platform.raspberry.generator.framework;
*/
public interface IPreinstalledHeaderGeneratorExtension {
/** Returns the included header files. */
public String getHeaderIncludes();
public List<String> getHeaderIncludes();
}
......@@ -33,6 +33,7 @@ CDTProjectFile(PROJECT_NAME) ::= <<
<listOptionValue builtIn="false" value="&quot;\${workspace_loc:/\${ProjName}/inc-lib}&quot;"/>
<listOptionValue builtIn="false" value="&quot;\${workspace_loc:/\${ProjName}}&quot;"/>
<listOptionValue builtIn="false" value="&quot;\${workspace_loc:/brick/inc}&quot;"/>
<listOptionValue builtIn="false" value="&quot;\${workspace_loc:/vesc}&quot;"/>
<listOptionValue builtIn="false" value="&quot;\${workspace_loc:/af3pihal/inc}&quot;"/>
</option>
<option id="gnu.c.compiler.option.dialect.std.995945301" name="Language standard" superClass="gnu.c.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.c.compiler.dialect.default" valueType="enumerated"/>
......@@ -55,11 +56,13 @@ CDTProjectFile(PROJECT_NAME) ::= <<
<listOptionValue builtIn="false" value="brick"/>
<listOptionValue builtIn="false" value="af3pihal"/>
<listOptionValue builtIn="false" value="rt"/>
<listOptionValue builtIn="false" value="vesc"/>
</option>
<option id="gnu.c.link.option.paths.32490919" name="Library search path (-L)" superClass="gnu.c.link.option.paths" useByScannerDiscovery="false" valueType="libPaths">
<listOptionValue builtIn="false" value="&quot;\${workspace_loc:/\${ProjName}/lib}&quot;"/>
<listOptionValue builtIn="false" value="&quot;\${workspace_loc:/af3pihal/Debug}&quot;"/>
<listOptionValue builtIn="false" value="&quot;\${workspace_loc:/brick/Debug}&quot;"/>
<listOptionValue builtIn="false" value="&quot;\${workspace_loc:/vesc}&quot;"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.c.linker.input.1755029706" superClass="cdt.managedbuild.tool.gnu.c.linker.input">
<additionalInput kind="additionalinputdependency" paths="\$(USER_OBJS)"/>
......
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