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

Added code generator extensions for Models conference hardware.

parent 4b94ea8b
No related branches found
No related tags found
No related merge requests found
Showing
with 565 additions and 0 deletions
......@@ -8,6 +8,7 @@ Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: org.fortiss.af3.platform.modelsconference,
org.fortiss.af3.platform.modelsconference.generator,
org.fortiss.af3.platform.modelsconference.model,
org.fortiss.af3.platform.modelsconference.model.impl,
org.fortiss.af3.platform.modelsconference.model.util
......
......@@ -13,5 +13,60 @@
class="org.fortiss.af3.platform.modelsconference.model.PlatformModelsConferencePackage"
genModel="model/modelsconference.genmodel"/>
</extension>
<extension
point="org.fortiss.tooling.kernel.transformationProvider">
<transformationProvider
transformationProvider="org.fortiss.af3.platform.modelsconference.generator.ButtonTransform">
<source>
<objectClass
objectClass="org.fortiss.af3.platform.modelsconference.model.Button">
</objectClass>
</source>
<target>
<objectClass
objectClass="org.fortiss.af3.platform.modelsconference.generator.ButtonGeneratorExtension">
</objectClass>
</target>
</transformationProvider>
<transformationProvider
transformationProvider="org.fortiss.af3.platform.modelsconference.generator.LCDTransform">
<source>
<objectClass
objectClass="org.fortiss.af3.platform.modelsconference.model.LCD">
</objectClass>
</source>
<target>
<objectClass
objectClass="org.fortiss.af3.platform.modelsconference.generator.LCDGeneratorExtension">
</objectClass>
</target>
</transformationProvider>
<transformationProvider
transformationProvider="org.fortiss.af3.platform.modelsconference.generator.LEDTransform">
<source>
<objectClass
objectClass="org.fortiss.af3.platform.modelsconference.model.LED">
</objectClass>
</source>
<target>
<objectClass
objectClass="org.fortiss.af3.platform.modelsconference.generator.LEDGeneratorExtension">
</objectClass>
</target>
</transformationProvider>
<transformationProvider
transformationProvider="org.fortiss.af3.platform.modelsconference.generator.PotiTransform">
<source>
<objectClass
objectClass="org.fortiss.af3.platform.modelsconference.model.Poti">
</objectClass>
</source>
<target>
<objectClass
objectClass="org.fortiss.af3.platform.modelsconference.generator.PotiGeneratorExtension">
</objectClass>
</target>
</transformationProvider>
</extension>
</plugin>
ButtonGeneratorExtension.java 6ee031e2318652fe5e509165b5ea5ea17cc47588 RED
ButtonTransform.java 8c701414e4a92490f088c1e01be805e54a93b932 YELLOW
LCDGeneratorExtension.java a2b76fdf24ed63bd7c8dcc68c22b011d366fe1bf RED
LCDTransform.java cc49241c94e042be03e776965c4577b04cfc1273 YELLOW
LEDGeneratorExtension.java be5ae603cfe2f7015d7b3d40e46013f1e2e01d74 RED
LEDTransform.java e90532398e21ec4f3d8c0e4358e0d802fc93bb4a YELLOW
PotiGeneratorExtension.java d866773c7a0bd51fcf9bece96fd529d4e2b28514 RED
PotiTransform.java c534fa6f1cf98474be4f2fb5d405be8626f472e4 YELLOW
WiringPiLibraryGeneratorExtensionBase.java 8b33895817f1f6713178a11b94584f5ec5f72e3d YELLOW
/*-------------------------------------------------------------------------+
| Copyright 2018 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.modelsconference.generator;
import static org.fortiss.af3.platform.modelsconference.UniqueIdentifiers.BUTTON_A_UID;
import static org.fortiss.af3.platform.modelsconference.UniqueIdentifiers.BUTTON_B_UID;
import static org.fortiss.af3.platform.modelsconference.UniqueIdentifiers.BUTTON_C_UID;
import static org.fortiss.af3.platform.modelsconference.UniqueIdentifiers.BUTTON_D_UID;
import static org.fortiss.af3.platform.modelsconference.UniqueIdentifiers.BUTTON_LEFT_UID;
import static org.fortiss.af3.platform.modelsconference.UniqueIdentifiers.BUTTON_RIGHT_UID;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.platform.modelsconference.model.Button;
import org.fortiss.af3.platform.raspberry.generator.framework.IReadableGeneratorExtension;
/**
* Generator extension for {@link Button}.
*
* @author hoelzl
*/
public final class ButtonGeneratorExtension extends WiringPiLibraryGeneratorExtensionBase<Button>
implements IReadableGeneratorExtension {
/** Constructor. */
public ButtonGeneratorExtension(Button modelElement) {
super(modelElement);
}
/** {@inheritDoc} */
@Override
public String getInstanceInitializationCode() {
String pin = getPinNumber();
return "pinMode(" + pin + ", INPUT);\n" + "pullUpDnControl(" + pin + ", PUD_UP);\n";
}
/** {@inheritDoc} */
@Override
public String getReadCode(InputPort logicalSignal, String targetVariable) {
return targetVariable + " = digitalRead(" + getPinNumber() + ");\n";
}
/** {@inheritDoc} */
@Override
public String getNoValReadCode(InputPort logicalSignal) {
return null;
}
/** Returns the pin number for the given button UID. */
private String getPinNumber() {
String btnUID = modelElement.getUid();
if(BUTTON_LEFT_UID.equals(btnUID)) {
return "0"; // FIXME
}
if(BUTTON_RIGHT_UID.equals(btnUID)) {
return "0"; // FIXME
}
if(BUTTON_A_UID.equals(btnUID)) {
return "0"; // FIXME
}
if(BUTTON_B_UID.equals(btnUID)) {
return "0"; // FIXME
}
if(BUTTON_C_UID.equals(btnUID)) {
return "0"; // FIXME
}
if(BUTTON_D_UID.equals(btnUID)) {
return "0"; // FIXME
}
return "UNKNOWN_MODEL_ELEMENT_UID";
}
}
/*-------------------------------------------------------------------------+
| Copyright 2018 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.modelsconference.generator;
import org.fortiss.af3.platform.modelsconference.model.Button;
import org.fortiss.af3.platform.raspberry.generator.framework.RasPiGeneratorTransformationBase;
/**
* Transformation from model element to generator extension.
*
* @author hoelzl
*/
public final class ButtonTransform extends RasPiGeneratorTransformationBase {
/** Constructor. */
public ButtonTransform() {
super(Button.class, ButtonGeneratorExtension.class);
}
}
/*-------------------------------------------------------------------------+
| Copyright 2018 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.modelsconference.generator;
import org.fortiss.af3.component.model.OutputPort;
import org.fortiss.af3.platform.modelsconference.model.LCD;
import org.fortiss.af3.platform.raspberry.generator.framework.IWriteableGeneratorExtension;
/**
* Generator extension for {@link LCD}.
*
* @author hoelzl
*/
public final class LCDGeneratorExtension extends WiringPiLibraryGeneratorExtensionBase<LCD>
implements IWriteableGeneratorExtension {
/** Constructor. */
public LCDGeneratorExtension(LCD modelElement) {
super(modelElement);
}
/** {@inheritDoc} */
@Override
public String getWriteCode(OutputPort logicalSignal, String value) {
return "// FIXME: LCD support not implemented yet.\n";
}
/** {@inheritDoc} */
@Override
public String getNoValWriteCode(OutputPort logicalSignal) {
return null;
}
}
/*-------------------------------------------------------------------------+
| Copyright 2018 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.modelsconference.generator;
import org.fortiss.af3.platform.modelsconference.model.LCD;
import org.fortiss.af3.platform.raspberry.generator.framework.RasPiGeneratorTransformationBase;
/**
* Transformation from model element to generator extension.
*
* @author hoelzl
*/
public final class LCDTransform extends RasPiGeneratorTransformationBase {
/** Constructor. */
public LCDTransform() {
super(LCD.class, LCDGeneratorExtension.class);
}
}
/*-------------------------------------------------------------------------+
| Copyright 2018 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.modelsconference.generator;
import static org.fortiss.af3.platform.modelsconference.UniqueIdentifiers.LED_LEFT_UID;
import static org.fortiss.af3.platform.modelsconference.UniqueIdentifiers.LED_RED_UID;
import static org.fortiss.af3.platform.modelsconference.UniqueIdentifiers.LED_RIGHT_UID;
import static org.fortiss.af3.platform.modelsconference.UniqueIdentifiers.LED_WHITE_UID;
import org.fortiss.af3.component.model.OutputPort;
import org.fortiss.af3.platform.modelsconference.model.LED;
import org.fortiss.af3.platform.raspberry.generator.framework.IInstanceGeneratorExtension;
import org.fortiss.af3.platform.raspberry.generator.framework.IWriteableGeneratorExtension;
/**
* Generator extension for {@link LED}.
*
* @author hoelzl
*/
public final class LEDGeneratorExtension extends WiringPiLibraryGeneratorExtensionBase<LED>
implements IInstanceGeneratorExtension, IWriteableGeneratorExtension {
/** Constructor. */
public LEDGeneratorExtension(LED modelElement) {
super(modelElement);
}
/** {@inheritDoc} */
@Override
public String getInstanceInitializationCode() {
String pin = getPinNumber();
return "pinMode(" + pin + ", OUTPUT);\n" + "digitalWrite(" + pin + ", HIGH);\n";
}
/** {@inheritDoc} */
@Override
public String getWriteCode(OutputPort logicalSignal, String value) {
String pin = getPinNumber();
return "digitalWrite(" + pin + ", (" + value + " == 0 ? LOW : HIGH));\n";
}
/** {@inheritDoc} */
@Override
public String getNoValWriteCode(OutputPort logicalSignal) {
return null;
}
/** Returns the pin number for the given button UID. */
private String getPinNumber() {
String btnUID = modelElement.getUid();
if(LED_LEFT_UID.equals(btnUID)) {
return "0"; // FIXME
}
if(LED_RIGHT_UID.equals(btnUID)) {
return "0"; // FIXME
}
if(LED_RED_UID.equals(btnUID)) {
return "0"; // FIXME
}
if(LED_WHITE_UID.equals(btnUID)) {
return "0"; // FIXME
}
return "UNKNOWN_MODEL_ELEMENT_UID";
}
}
/*-------------------------------------------------------------------------+
| Copyright 2018 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.modelsconference.generator;
import org.fortiss.af3.platform.modelsconference.model.LED;
import org.fortiss.af3.platform.raspberry.generator.framework.RasPiGeneratorTransformationBase;
/**
* Transformation from model element to generator extension.
*
* @author hoelzl
*/
public final class LEDTransform extends RasPiGeneratorTransformationBase {
/** Constructor. */
public LEDTransform() {
super(LED.class, LEDGeneratorExtension.class);
}
}
/*-------------------------------------------------------------------------+
| Copyright 2018 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.modelsconference.generator;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.platform.modelsconference.model.Poti;
import org.fortiss.af3.platform.raspberry.generator.framework.IReadableGeneratorExtension;
/**
* Generator extension for {@link Poti}.
*
* @author hoelzl
*/
public final class PotiGeneratorExtension extends WiringPiLibraryGeneratorExtensionBase<Poti>
implements IReadableGeneratorExtension {
/** Constructor. */
public PotiGeneratorExtension(Poti modelElement) {
super(modelElement);
}
/** {@inheritDoc} */
@Override
public String getReadCode(InputPort logicalSignal, String targetVariable) {
return "// FIXME: poti support not implemented yet.\n";
}
/** {@inheritDoc} */
@Override
public String getNoValReadCode(InputPort logicalSignal) {
return null;
}
}
/*-------------------------------------------------------------------------+
| Copyright 2018 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.modelsconference.generator;
import org.fortiss.af3.platform.modelsconference.model.Poti;
import org.fortiss.af3.platform.raspberry.generator.framework.RasPiGeneratorTransformationBase;
/**
* Transformation from model element to generator extension.
*
* @author hoelzl
*/
public final class PotiTransform extends RasPiGeneratorTransformationBase {
/** Constructor. */
public PotiTransform() {
super(Poti.class, PotiGeneratorExtension.class);
}
}
/*-------------------------------------------------------------------------+
| Copyright 2018 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.modelsconference.generator;
import static java.util.Arrays.asList;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.af3.platform.language.executable.ExecutableBase;
import org.fortiss.af3.platform.raspberry.generator.framework.IInstanceGeneratorExtension;
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.ISingletonGeneratorExtension;
/**
*
* @author hoelzl
*/
abstract class WiringPiLibraryGeneratorExtensionBase<T extends EObject> extends ExecutableBase<T>
implements IPreinstalledLibraryGeneratorExtension, IPreinstalledHeaderGeneratorExtension,
ISingletonGeneratorExtension, IInstanceGeneratorExtension {
/** Stores the singleton postfix. */
protected String singletonPostfix = "";
/** Stores the instance postfix. */
protected String instancePostfix = "";
/** Constructor. */
public WiringPiLibraryGeneratorExtensionBase(T modelElement) {
super(modelElement);
}
/** {@inheritDoc} */
@Override
public List<String> getHeaderIncludes() {
return asList("wiringPi.h", "wiringPiI2C.h");
}
/** {@inheritDoc} */
@Override
public List<String> getLibraryNames() {
return asList("wiringPi");
}
/** {@inheritDoc} */
@Override
public String getSingletonIdentifier() {
return "wiringPi.h";
}
/** {@inheritDoc} */
@Override
public void setSingletonPostfix(String singletonPostfix) {
this.singletonPostfix = singletonPostfix == null ? "" : singletonPostfix;
}
/** {@inheritDoc} */
@Override
public void setInstancePostfix(String instancePostfix) {
this.instancePostfix = instancePostfix == null ? "" : instancePostfix;
}
/** {@inheritDoc} */
@Override
public String getSingletonVariableDeclarationCode() {
return null;
}
/** {@inheritDoc} */
@Override
public String getInstanceVariableDeclaration() {
return null;
}
/** {@inheritDoc} */
@Override
public String getSingletonAuxiliaryFunctions() {
return null;
}
/** {@inheritDoc} */
@Override
public String getInstanceAuxiliaryFunctions() {
return null;
}
/** {@inheritDoc} */
@Override
public String getSingletonInitializationCode() {
return " if (wiringPiSetup() == -1) {\n" + "exit(-1);\n" + "}\n";
}
/** {@inheritDoc} */
@Override
public String getInstanceInitializationCode() {
return null;
}
/** {@inheritDoc} */
@Override
public String getSingletonTerminationCode() {
return null;
}
/** {@inheritDoc} */
@Override
public String getInstanceTerminationCode() {
return null;
}
}
......@@ -35,6 +35,7 @@ CDTProjectFile(PROJECT_NAME) ::= <<
<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;"/>
<listOptionValue builtIn="false" value="&quot;\${workspace_loc:/wiringPi/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"/>
<option id="gnu.c.compiler.option.misc.other.1828262063" name="Other flags" superClass="gnu.c.compiler.option.misc.other" useByScannerDiscovery="false" value="-c -fmessage-length=0" valueType="string"/>
......@@ -53,6 +54,7 @@ CDTProjectFile(PROJECT_NAME) ::= <<
<tool command="gcc" commandLinePattern="\${COMMAND} \${FLAGS} \${OUTPUT_FLAG} \${OUTPUT_PREFIX}\${OUTPUT} \${INPUTS}" errorParsers="org.eclipse.cdt.core.GLDErrorParser" id="cdt.managedbuild.tool.gnu.cross.c.linker.552685778" name="Cross GCC Linker" superClass="cdt.managedbuild.tool.gnu.cross.c.linker">
<option id="gnu.c.link.option.libs.1721772670" name="Libraries (-l)" superClass="gnu.c.link.option.libs" useByScannerDiscovery="false" valueType="libs">
<listOptionValue builtIn="false" value="pthread"/>
<listOptionValue builtIn="false" value="wiringPi"/>
<listOptionValue builtIn="false" value="brick"/>
<listOptionValue builtIn="false" value="af3pihal"/>
<listOptionValue builtIn="false" value="rt"/>
......@@ -63,6 +65,7 @@ CDTProjectFile(PROJECT_NAME) ::= <<
<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;"/>
<listOptionValue builtIn="false" value="&quot;\${workspace_loc:/wiringPi/lib}&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