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

First working RasPi deployment.

refs 3079
parent 49339310
No related branches found
No related tags found
No related merge requests found
Showing with 59 additions and 22 deletions
No preview for this file type
......@@ -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"));
}
......
......@@ -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));
......
......@@ -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. */
......
......@@ -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
......
......@@ -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);
......
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