diff --git a/org.fortiss.af3.platform.raspberry/trunk/code-gen-hal/inc/temp_actuator.h b/org.fortiss.af3.platform.raspberry/trunk/code-gen-hal/inc/af3pihal/temp_actuator.h similarity index 100% rename from org.fortiss.af3.platform.raspberry/trunk/code-gen-hal/inc/temp_actuator.h rename to org.fortiss.af3.platform.raspberry/trunk/code-gen-hal/inc/af3pihal/temp_actuator.h diff --git a/org.fortiss.af3.platform.raspberry/trunk/code-gen-hal/lib/libaf3pihal.a b/org.fortiss.af3.platform.raspberry/trunk/code-gen-hal/lib/libaf3pihal.a index 3d6219dbd5f7d4fd2e36ff267d21144e75bbfbd9..4ade60d14cacc596134c09ac0aae68d3c07f27e6 100644 Binary files a/org.fortiss.af3.platform.raspberry/trunk/code-gen-hal/lib/libaf3pihal.a and b/org.fortiss.af3.platform.raspberry/trunk/code-gen-hal/lib/libaf3pihal.a differ diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/HeaderCopyGenerator.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/HeaderCopyGenerator.java index 91c0ca31bf10b5718274a7813dad881b33e7a0a2..c3eda109d439b003f9de7f617cdfdd1a5a1caf0a 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/HeaderCopyGenerator.java +++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/HeaderCopyGenerator.java @@ -47,6 +47,7 @@ final class HeaderCopyGenerator { incLibPack.addUnit(copyAF3Hal("protocol_coordinator.h")); incLibPack.addUnit(copyAF3Hal("protocol_factory.h")); incLibPack.addUnit(copyAF3Hal("protocol_worker.h")); + incLibPack.addUnit(copyAF3Hal("temp_actuator.h")); incLibPack.addUnit(copyAF3Hal("timeutil.h")); } diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/MainGenerator.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/MainGenerator.java index 87dd2ae0e062de4cd3074b323ff7981e6af069d4..7ffc80ed767e5603d713c1d26b7646c2c355d452 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/MainGenerator.java +++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/MainGenerator.java @@ -51,17 +51,44 @@ import org.fortiss.tooling.kernel.extension.data.ITransformationContext; * @ConQAT.Rating RED Hash: */ class MainGenerator { - /** Creates the main.c file. */ - public AbstractUnit createMain(RaspberryPi executionUnit, + private static final int WAITING_SLEEP_IN_MICROS = 250; + private RaspberryPi executionUnit; + private List<Pair<ExecutionUnit, Component>> deployedComponents; + private List<Pair<PlatformConnectorUnit, Port>> deployedPorts; + private ITransformationContext context; + + private boolean useGamepad; + private boolean usePWM; + + /** Constructor. */ + public MainGenerator(RaspberryPi executionUnit, List<Pair<ExecutionUnit, Component>> deployedComponents, List<Pair<PlatformConnectorUnit, Port>> deployedPorts, ITransformationContext context) { + this.executionUnit = executionUnit; + this.deployedComponents = deployedComponents; + this.deployedPorts = deployedPorts; + this.context = context; + for(Pair<PlatformConnectorUnit, Port> p : deployedPorts) { + if(!useGamepad && p.getFirst() instanceof GamepadReceiverBase) { + useGamepad = true; + } + if(!usePWM && p.getFirst() instanceof ActuatorPWM) { + usePWM = true; + } + } + } + + /** Creates the main.c file. */ + public AbstractUnit createMain() { String includes = createIncludes(deployedComponents, deployedPorts); + // TODO: compute syncBox size + int syncBoxSize = 0; // TODO: syncbox code String initCode = createInitCode(deployedComponents); String workerCode = createWorkerCode(deployedComponents, deployedPorts); return getMainCFile(executionUnit.getName(), executionUnit.isCoordinatorUnit(), - executionUnit.getCanCoordinationID(), executionUnit.getCycleTime(), 250, includes, - "// TODO\n", initCode, workerCode); + executionUnit.getCanCoordinationID(), executionUnit.getCycleTime(), + WAITING_SLEEP_IN_MICROS, includes, syncBoxSize, "// TODO\n", initCode, workerCode); } /** Creates the includes of the system headers. */ @@ -72,17 +99,11 @@ class MainGenerator { Component c = p.getSecond(); sb.append("#include <" + c.getName() + "_ID_" + c.getId() + ".h>\n"); } - boolean useGamepad = false; - boolean usePWM = false; - for(Pair<PlatformConnectorUnit, Port> p : deployedPorts) { - if(!useGamepad && p.getFirst() instanceof GamepadReceiverBase) { - sb.append("#include <gamepad.h>\n"); - useGamepad = true; - } - if(!usePWM && p.getFirst() instanceof ActuatorPWM) { - sb.append("#include <temp_actuator.h>\n"); - usePWM = true; - } + if(useGamepad) { + sb.append("#include <gamepad.h>\n"); + } + if(usePWM) { + sb.append("#include <temp_actuator.h>\n"); } return sb.toString(); } @@ -162,6 +183,18 @@ class MainGenerator { /** Create the initialize code. */ private String createInitCode(List<Pair<ExecutionUnit, Component>> deployedComponents) { StringBuilder sb = new StringBuilder(); + if(usePWM) { + sb.append("temp_actuator_initialize(\"/dev/ttyACM0\");\n\n"); + } + if(useGamepad) { + sb.append("gamepad_configuration_t* gamepad_config = malloc(sizeof(gamepad_configuration_t));\n"); + sb.append("gamepad_config->device_id = \"/dev/input/js0\";\n"); + sb.append("gamepad_config->waiting_sleep_in_micros = " + WAITING_SLEEP_IN_MICROS + + ";\n"); + sb.append("gamepad_config->axis_callback = NULL;\n"); + sb.append("gamepad_config->button_callback = NULL;\n"); + sb.append("gamepad_initialize(gamepad_config);\n\n"); + } for(Pair<ExecutionUnit, Component> p : deployedComponents) { Component c = p.getSecond(); sb.append(makeCall("init", c)); diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/RaspberryPIExecutable.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/RaspberryPIExecutable.java index ff4a7bb3b8f120d40167e7b28d1d54affa35bd80..070ede94bf68e2bd81e968af87f500298e047da5 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/RaspberryPIExecutable.java +++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/RaspberryPIExecutable.java @@ -107,8 +107,9 @@ public class RaspberryPIExecutable extends ExecutionUnitExecutableBase<Raspberry List<Pair<ExecutionUnit, Component>> deployedComponents, List<Pair<PlatformConnectorUnit, Port>> deployedPorts, ITransformationContext context) { CSourcePackage srcGenPack = (CSourcePackage)sourcePackage.getSrcGenPackage(); - MainGenerator mg = new MainGenerator(); - srcGenPack.addUnit(mg.createMain(modelElement, deployedComponents, deployedPorts, context)); + MainGenerator mg = + new MainGenerator(modelElement, deployedComponents, deployedPorts, context); + srcGenPack.addUnit(mg.createMain()); } /** Adds the build process files: configure and Makedefs. */ diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/MainFile.stg b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/MainFile.stg index 1c7db89666202c0532daee255799f2f0df2757ef..62dd488ccc8fe4b93319c2e6bff5926c83dd8737 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/MainFile.stg +++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/MainFile.stg @@ -6,6 +6,7 @@ MainFile(UNIT_NAME, CYCLE_TIME_IN_MILLIS, WAITING_SLEEPTIME_IN_MICROS, SYSTEM_INCLUDES, + SYNC_BOX_SIZE, SYNC_BOX_SETUP_CODE, SYSTEM_INIT_CODE, WORKER_CODE) ::= << @@ -61,7 +62,7 @@ int main(int argc, char** argv) { // TODO: initialize ControlCenter connection // snychronization message box - sync_inbox = can_inbox_create("$UNIT_NAME$_sync_inbox", 2); + sync_inbox = can_inbox_create("$UNIT_NAME$_sync_inbox", $SYNC_BOX_SIZE$); $SYNC_BOX_SETUP_CODE$ // application message boxes diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/RasPiCTemplates.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/RasPiCTemplates.java index d3f470c0ece4042e312f0b434da15617e1536400..d55a37e69b3b2e3f36687774a12c6e5c12f63c1a 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/RasPiCTemplates.java +++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/templates/RasPiCTemplates.java @@ -40,10 +40,10 @@ import org.fortiss.af3.generator.common.model.source.StaticContentSourceUnit; */ public final class RasPiCTemplates { /** Returns the 'main.c' file configured using the given arguments. */ - public static AbstractUnit - getMainCFile(String unitName, boolean coordinatorOrWorker, int canIdUnitDone, - int cycletimeInMillis, int waitingSleepInMicros, String systemIncludes, - String syncBoxSetupCode, String systemInitCode, String workerCode) { + public static AbstractUnit getMainCFile(String unitName, boolean coordinatorOrWorker, + int canIdUnitDone, int cycletimeInMillis, int waitingSleepInMicros, + String systemIncludes, int syncBoxSize, String syncBoxSetupCode, String systemInitCode, + String workerCode) { StringTemplate template = makeTemplate("MainFile.stg", "MainFile"); template.setAttribute("UNIT_NAME", unitName); template.setAttribute("COORDINATOR_OR_WORKER", coordinatorOrWorker ? 1 : 0); @@ -51,6 +51,7 @@ public final class RasPiCTemplates { template.setAttribute("CYCLE_TIME_IN_MILLIS", cycletimeInMillis); template.setAttribute("WAITING_SLEEPTIME_IN_MICROS", waitingSleepInMicros); template.setAttribute("SYSTEM_INCLUDES", systemIncludes); + template.setAttribute("SYNC_BOX_SIZE", syncBoxSize); template.setAttribute("SYNC_BOX_SETUP_CODE", syncBoxSetupCode); template.setAttribute("SYSTEM_INIT_CODE", systemInitCode); template.setAttribute("WORKER_CODE", workerCode);