From 3e491fa7e66b35656906845b4c2d31680ca59705 Mon Sep 17 00:00:00 2001 From: Helge Brueger <noreply@fortiss.org> Date: Sat, 3 Jun 2017 21:12:44 +0000 Subject: [PATCH] Added C/H files for components and some patches, added code generation, added includes to system.h refs 7863 --- .../trunk/META-INF/MANIFEST.MF | 5 +- .../trunk/lib/Makedefs | 47 +++++++ .../trunk/lib/inc/CanConnector.h | 8 +- .../trunk/lib/inc/GPIO.h | 0 .../trunk/lib/inc/Gamepad.h | 0 .../trunk/lib/inc/IMU.h | 0 .../trunk/lib/inc/LaserRangeFinder.h | 20 +++ .../trunk/lib/inc/LaserScanner.h | 0 .../trunk/lib/inc/PWM.h | 0 .../trunk/lib/inc/libuart.h | 33 +++++ .../trunk/lib/src/CanConnector.c | 16 +-- .../trunk/lib/src/GPIO.c | 0 .../trunk/lib/src/Gamepad.c | 0 .../trunk/lib/src/IMU.c | 0 .../trunk/lib/src/LaserRangeFinder.c | 43 ++++++ .../trunk/lib/src/LaserScanner.c | 0 .../trunk/lib/src/PWM.c | 0 .../trunk/lib/src/libuart.c | 125 ++++++++++++++++++ .../trunk/lib/src/main.c | 16 ++- .../executable/CanConnectorExecutable.java | 2 +- .../LaserRangeFinderSensorExecutable.java | 10 +- .../executable/RaspberryPIExecutable.java | 70 +++++++++- .../util/RaspberryModelElementFactory.java | 28 ++-- 23 files changed, 381 insertions(+), 42 deletions(-) create mode 100644 org.fortiss.af3.platform.raspberry/trunk/lib/Makedefs create mode 100644 org.fortiss.af3.platform.raspberry/trunk/lib/inc/GPIO.h create mode 100644 org.fortiss.af3.platform.raspberry/trunk/lib/inc/Gamepad.h create mode 100644 org.fortiss.af3.platform.raspberry/trunk/lib/inc/IMU.h create mode 100644 org.fortiss.af3.platform.raspberry/trunk/lib/inc/LaserRangeFinder.h create mode 100644 org.fortiss.af3.platform.raspberry/trunk/lib/inc/LaserScanner.h create mode 100644 org.fortiss.af3.platform.raspberry/trunk/lib/inc/PWM.h create mode 100644 org.fortiss.af3.platform.raspberry/trunk/lib/inc/libuart.h create mode 100644 org.fortiss.af3.platform.raspberry/trunk/lib/src/GPIO.c create mode 100644 org.fortiss.af3.platform.raspberry/trunk/lib/src/Gamepad.c create mode 100644 org.fortiss.af3.platform.raspberry/trunk/lib/src/IMU.c create mode 100644 org.fortiss.af3.platform.raspberry/trunk/lib/src/LaserRangeFinder.c create mode 100644 org.fortiss.af3.platform.raspberry/trunk/lib/src/LaserScanner.c create mode 100644 org.fortiss.af3.platform.raspberry/trunk/lib/src/PWM.c create mode 100644 org.fortiss.af3.platform.raspberry/trunk/lib/src/libuart.c diff --git a/org.fortiss.af3.platform.raspberry/trunk/META-INF/MANIFEST.MF b/org.fortiss.af3.platform.raspberry/trunk/META-INF/MANIFEST.MF index d371b809..f1b5978b 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/META-INF/MANIFEST.MF +++ b/org.fortiss.af3.platform.raspberry/trunk/META-INF/MANIFEST.MF @@ -19,8 +19,9 @@ Require-Bundle: org.fortiss.af3.project, org.eclipse.core.runtime, org.eclipse.emf.ecore;visibility:=reexport, org.fortiss.tooling.base;visibility:=reexport, - org.fortiss.af3.platform;visibility:=reexport;bundle-version="2.5.0", - org.fortiss.tooling.base.ui;bundle-version="2.11.0" + org.fortiss.af3.platform;bundle-version="2.5.0";visibility:=reexport, + org.fortiss.tooling.base.ui;bundle-version="2.11.0", + org.fortiss.af3.generator.common Import-Package: org.fortiss.af3.deployment.generator, org.fortiss.af3.platform.model diff --git a/org.fortiss.af3.platform.raspberry/trunk/lib/Makedefs b/org.fortiss.af3.platform.raspberry/trunk/lib/Makedefs new file mode 100644 index 00000000..bce7e5bb --- /dev/null +++ b/org.fortiss.af3.platform.raspberry/trunk/lib/Makedefs @@ -0,0 +1,47 @@ +# The default application name. +ifndef APPL + APPL=my_app +endif + +# The default build path. +ifndef BPATH + BPATH=build +endif + +# The compiler. +ifndef CROSSCC + CROSSCC=gcc +endif + +# The linker. +ifndef CROSSLD + CROSSLD=gcc +endif + +# The flags which are passed to the compiler and the linker. +CCFLAGS+=-std=gnu99 -Wall -pedantic -c ${patsubst %,-I%,${subst :, ,${IPATH}}} +LDFLAGS+=-std=gnu99 -Wall -pedantic + +# The default rules, i.e. the entry point. +all: ${BPATH} +all: ${BPATH}/${APPL}.run + +# The target to clean the build directory. +clean: + @echo "cleaning up path '${BPATH}' ..." + @rm -rf ${BPATH} + +# The rule for creating the build directory. +${BPATH}: + @echo "creating path '${BPATH}' ..." + @mkdir ${BPATH} + +# The rule for building an object file from the corresponding C source file. +${BPATH}/%.o: %.c + @echo "compiling file '${<}' ..." + @${CROSSCC} ${CCFLAGS} -o ${@} ${<} + +# The rule for linking an application. +${BPATH}/%.run: + @echo "linking application '${@}' ..." + @${CROSSLD} ${LDFLAGS} -o ${@} $(filter %.o %.a, ${^}) \ No newline at end of file diff --git a/org.fortiss.af3.platform.raspberry/trunk/lib/inc/CanConnector.h b/org.fortiss.af3.platform.raspberry/trunk/lib/inc/CanConnector.h index 85a5d2a2..65a75892 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/lib/inc/CanConnector.h +++ b/org.fortiss.af3.platform.raspberry/trunk/lib/inc/CanConnector.h @@ -1,5 +1,5 @@ -#ifndef __CAN_H -#define __CAN_H +#ifndef __CANCONNECTOR_H +#define __CANCONNECTOR_H #include <stdio.h> @@ -10,7 +10,7 @@ typedef const char* PORT_T; // init, terminate, prepare void can_init(); -void can_terminate(); +void can_term(); void prepare_input_CanConnector(); void finish_input_CanConnector(); @@ -32,4 +32,4 @@ void can_write_bool(PORT_T port, GEN_TYPE_boolean value); void can_write_double(PORT_T port, GEN_TYPE_double value); void can_write_int(PORT_T port, GEN_TYPE_int value); -#endif // __CAN_H +#endif // __CANCONNECTOR_H diff --git a/org.fortiss.af3.platform.raspberry/trunk/lib/inc/GPIO.h b/org.fortiss.af3.platform.raspberry/trunk/lib/inc/GPIO.h new file mode 100644 index 00000000..e69de29b diff --git a/org.fortiss.af3.platform.raspberry/trunk/lib/inc/Gamepad.h b/org.fortiss.af3.platform.raspberry/trunk/lib/inc/Gamepad.h new file mode 100644 index 00000000..e69de29b diff --git a/org.fortiss.af3.platform.raspberry/trunk/lib/inc/IMU.h b/org.fortiss.af3.platform.raspberry/trunk/lib/inc/IMU.h new file mode 100644 index 00000000..e69de29b diff --git a/org.fortiss.af3.platform.raspberry/trunk/lib/inc/LaserRangeFinder.h b/org.fortiss.af3.platform.raspberry/trunk/lib/inc/LaserRangeFinder.h new file mode 100644 index 00000000..a73e206a --- /dev/null +++ b/org.fortiss.af3.platform.raspberry/trunk/lib/inc/LaserRangeFinder.h @@ -0,0 +1,20 @@ +#ifndef __LASERRANGEFINDER_H +#define __LASERRANGEFINDER_H + +#include <stdlib.h> + +#include "inc-gen/data_dictionary.h" +#include "inc/libuart.h" + +// constants +const char* LRF_DEVICE_NAME; + +// init, terminate +void lrf_init(); +void lrf_term(); + +// getters +GEN_TYPE_boolean lrf_is_noval(); +GEN_TYPE_int lrf_get_distance(); + +#endif // __LASERRANGEFINDER_H diff --git a/org.fortiss.af3.platform.raspberry/trunk/lib/inc/LaserScanner.h b/org.fortiss.af3.platform.raspberry/trunk/lib/inc/LaserScanner.h new file mode 100644 index 00000000..e69de29b diff --git a/org.fortiss.af3.platform.raspberry/trunk/lib/inc/PWM.h b/org.fortiss.af3.platform.raspberry/trunk/lib/inc/PWM.h new file mode 100644 index 00000000..e69de29b diff --git a/org.fortiss.af3.platform.raspberry/trunk/lib/inc/libuart.h b/org.fortiss.af3.platform.raspberry/trunk/lib/inc/libuart.h new file mode 100644 index 00000000..3e5da7f4 --- /dev/null +++ b/org.fortiss.af3.platform.raspberry/trunk/lib/inc/libuart.h @@ -0,0 +1,33 @@ +/** + * @file uart.h + * @author Bianca Forkel + */ + +#ifndef MBSE_UART_H +#define MBSE_UART_H + +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <fcntl.h> +#include <termios.h> +#include <errno.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <sys/select.h> + +extern int uart_filestream; + +char port[13]; + +int uart_setup(const char*); + +int uart_send_byte(char, int); + +int uart_send_string(char*, int, int); + +int uart_receive(char*, int, int); + +void uart_close(); + +#endif diff --git a/org.fortiss.af3.platform.raspberry/trunk/lib/src/CanConnector.c b/org.fortiss.af3.platform.raspberry/trunk/lib/src/CanConnector.c index 29127b54..8e84952e 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/lib/src/CanConnector.c +++ b/org.fortiss.af3.platform.raspberry/trunk/lib/src/CanConnector.c @@ -3,11 +3,11 @@ // init, terminate void can_init(const char* message) { - printf("initializing CAN\n"); + printf("initializing CAN\n"); } -void can_terminate() { - printf("terminating CAN\n"); +void can_term() { + printf("terminating CAN\n"); } void prepare_input_CanConnector() { @@ -28,24 +28,24 @@ void finish_output_CanConnector() { // NOVAL GEN_TYPE_boolean can_is_noval(PORT_T port) { - return true; + return true; } GEN_TYPE_boolean can_set_noval(PORT_T port) { - return true; + return true; } // readers GEN_TYPE_boolean can_read_bool(PORT_T port) { - return false; + return false; } GEN_TYPE_double can_read_double(PORT_T port) { - return 0.0; + return 0.0; } GEN_TYPE_int can_read_int(PORT_T port) { - return 0; + return 0; } // writers diff --git a/org.fortiss.af3.platform.raspberry/trunk/lib/src/GPIO.c b/org.fortiss.af3.platform.raspberry/trunk/lib/src/GPIO.c new file mode 100644 index 00000000..e69de29b diff --git a/org.fortiss.af3.platform.raspberry/trunk/lib/src/Gamepad.c b/org.fortiss.af3.platform.raspberry/trunk/lib/src/Gamepad.c new file mode 100644 index 00000000..e69de29b diff --git a/org.fortiss.af3.platform.raspberry/trunk/lib/src/IMU.c b/org.fortiss.af3.platform.raspberry/trunk/lib/src/IMU.c new file mode 100644 index 00000000..e69de29b diff --git a/org.fortiss.af3.platform.raspberry/trunk/lib/src/LaserRangeFinder.c b/org.fortiss.af3.platform.raspberry/trunk/lib/src/LaserRangeFinder.c new file mode 100644 index 00000000..0aaff79a --- /dev/null +++ b/org.fortiss.af3.platform.raspberry/trunk/lib/src/LaserRangeFinder.c @@ -0,0 +1,43 @@ + +#include "inc/LaserRangeFinder.h" + +// constants +const char* LRF_DEVICE_NAME = "/dev/ttyACM0"; + +// init, terminate +void lrf_init() { + uart_setup(LRF_DEVICE_NAME); +} + +void lrf_term() { + uart_close(); +} + +// getters +GEN_TYPE_boolean lrf_is_noval() { + return false; +} + +GEN_TYPE_int lrf_get_distance() { + char bytes[5]; + int n_read = 0; + + char value[3]; + int n = 0; + + int i; + + // looks like a blocking call and actually is but is always very fast + // since it only has to read the queue + while (1) { + n_read = uart_receive(bytes, 5, 0); + + for (i = 0; i < n_read; i++) { + if (bytes[i] != 0xd && bytes[i] != 0xa) { + value[n++] = bytes[i]; + } else if (atoi(value) != 0) { + return atoi(value); + } + } + } +} diff --git a/org.fortiss.af3.platform.raspberry/trunk/lib/src/LaserScanner.c b/org.fortiss.af3.platform.raspberry/trunk/lib/src/LaserScanner.c new file mode 100644 index 00000000..e69de29b diff --git a/org.fortiss.af3.platform.raspberry/trunk/lib/src/PWM.c b/org.fortiss.af3.platform.raspberry/trunk/lib/src/PWM.c new file mode 100644 index 00000000..e69de29b diff --git a/org.fortiss.af3.platform.raspberry/trunk/lib/src/libuart.c b/org.fortiss.af3.platform.raspberry/trunk/lib/src/libuart.c new file mode 100644 index 00000000..2f88d066 --- /dev/null +++ b/org.fortiss.af3.platform.raspberry/trunk/lib/src/libuart.c @@ -0,0 +1,125 @@ +/** + * @file uart.c + * @author Bianca Forkel + */ + +#include "inc/libuart.h" + +int uart_filestream = -1; + +int uart_setup(const char *porta) { + strcpy(port, porta); + uart_filestream = open(port, O_RDWR | O_NOCTTY | O_NDELAY); + if (uart_filestream < 0) { + fprintf(stderr, "[%s] Error opening port: %s\n", port, strerror(errno)); + } + + struct termios tty; + memset(&tty, 0, sizeof tty); + if (tcgetattr(uart_filestream, &tty) != 0) { + fprintf(stderr, "[%s] Error from tcgetattr: %s\n", port, strerror(errno)); + } + + // Baud Rate + cfsetospeed(&tty, (speed_t) B115200); + cfsetispeed(&tty, (speed_t) B115200); + + // TTY settings: 8N1 + tty.c_cflag &= ~PARENB; //no parity + tty.c_cflag &= ~CSTOPB; // 1 stop bit + tty.c_cflag &= ~CSIZE; + tty.c_cflag |= CS8; // 8 data bits + + tty.c_cflag &= ~CRTSCTS; + tty.c_cc[VMIN] = 1; + tty.c_cc[VTIME] = 5; + tty.c_cflag |= CREAD | CLOCAL; + + cfmakeraw(&tty); + tcflush(uart_filestream, TCIFLUSH); + if (tcsetattr(uart_filestream, TCSANOW, &tty) != 0) { + fprintf(stderr, "[%s] Error from tcsetattr: %s\n", port, strerror(errno)); + } + return uart_filestream; +} + +int uart_send_byte(char data, int printt) { + if (uart_filestream != -1) { + int n_written = 0; + n_written = write(uart_filestream, &data, 1); + if (n_written < 0) { + if (printt) + fprintf(stderr, "[%s] Error sending byte: %s\n", port, strerror(errno)); + } else { + if (printt) + printf("[%s] Sent byte %#02x\n", port, data); + return 0; + } + } + return -1; +} + +int uart_send_string(char *str, int length, int printt) { + if (uart_filestream != -1) { + int n_written = 0; + n_written = write(uart_filestream, str, length); + if (n_written < 0) { + if (printt) + fprintf(stderr, "[%s] Error sending string: %s\n", port, strerror(errno)); + } else { + if (printt) + printf("[%s] Sent string %s\n", port, str); + return 0; + } + } + return -1; +} + +int uart_receive(char *c, int bufLen, int printt) { + fd_set set; + struct timeval timeout; + int rv; + int n_read = -1; + + if (uart_filestream != -1) { + FD_ZERO(&set); + FD_SET(uart_filestream, &set); + + timeout.tv_sec = 0; + timeout.tv_usec = 10000; + + rv = select(uart_filestream + 1, &set, NULL, NULL, &timeout); + if (rv == -1) { + if (printt) + perror("select"); + } else if (rv == 0) { + if (printt) + perror("timeout"); + } else { + n_read = read(uart_filestream, (void *) c, bufLen); + } + + if (n_read < 0) { + if (printt) + fprintf(stderr, "[%s] Error receiving byte: %s\n", port, strerror(errno)); + n_read = 0; + } else if (n_read == 0) { + if (printt) + printf("[%s] No data to receive \n", port); + } else { + c[n_read] = '\0'; + if (printt) { + printf("[%s] %i Bytes received: 0x", port, n_read); + int i; + for (i = 0; i < n_read; i++) + printf("%02x", c[i]); + printf("\n"); + } + } + } + return n_read; +} + +void uart_close() { + close(uart_filestream); +} diff --git a/org.fortiss.af3.platform.raspberry/trunk/lib/src/main.c b/org.fortiss.af3.platform.raspberry/trunk/lib/src/main.c index 09054c94..feaad2e4 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/lib/src/main.c +++ b/org.fortiss.af3.platform.raspberry/trunk/lib/src/main.c @@ -3,10 +3,22 @@ */ #include <stdio.h> +#include <unistd.h> + +#include "inc-gen/system.h" int main(int argc, char* argv[]) { + // start a joystick thread + //pthread_t pt_joystick; + //pthread_create(&pt_joystick, NULL, joystick_main, NULL); - // TODO add actual startup code here! - printf("Hello world!\n"); + // start a rover thread + //pthread_t pt_rover; + //pthread_create(&pt_rover, NULL, rover_main, NULL); + // run endlessly + while(1) { + run_system(); + usleep(50000); + } } diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/CanConnectorExecutable.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/CanConnectorExecutable.java index 680e1347..b69b60a7 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/CanConnectorExecutable.java +++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/CanConnectorExecutable.java @@ -71,7 +71,7 @@ public class CanConnectorExecutable extends GenericTransceiverExecutable { @Override public IExpressionTerm getTermination() { // terminate the bus on the given interface - return funcCall("can_terminate"); + return funcCall("can_term"); } /** {@inheritDoc} */ diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/LaserRangeFinderSensorExecutable.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/LaserRangeFinderSensorExecutable.java index 5e71557e..0b16b400 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/LaserRangeFinderSensorExecutable.java +++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/LaserRangeFinderSensorExecutable.java @@ -17,6 +17,8 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $ +--------------------------------------------------------------------------*/ package org.fortiss.af3.platform.raspberry.generator.executable; +import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.funcCall; + import org.fortiss.af3.component.model.InputPort; import org.fortiss.af3.expression.model.terms.IExpressionTerm; import org.fortiss.af3.platform.generic.generator.executable.GenericReceiverExecutable; @@ -41,24 +43,24 @@ public class LaserRangeFinderSensorExecutable extends GenericReceiverExecutable /** {@inheritDoc} */ @Override public IExpressionTerm getInitialization() { - return super.getInitialization(); + return funcCall("lrf_init"); } /** {@inheritDoc} */ @Override public IExpressionTerm getNoValGuardAccessor(InputPort logicalSignal) { - return super.getNoValGuardAccessor(logicalSignal); + return funcCall("lrf_is_noval"); } /** {@inheritDoc} */ @Override public IExpressionTerm getTermination() { - return super.getTermination(); + return funcCall("lrf_term"); } /** {@inheritDoc} */ @Override public IExpressionTerm getValueReadAccessor(InputPort logicalSignal) { - return super.getValueReadAccessor(logicalSignal); + return funcCall("lrf_get_distance"); } } 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 7b926aaa..6bd049f7 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 @@ -18,6 +18,7 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $ package org.fortiss.af3.platform.raspberry.generator.executable; import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.funcCall; +import static org.fortiss.af3.generator.common.utils.CLanguageModelElementFacade.addUserHeaderInclude; import static org.fortiss.af3.generator.common.utils.SourceModelElementFactory.createByteContentUnitForPluginFile; import java.io.IOException; @@ -35,6 +36,7 @@ import org.fortiss.af3.component.model.generator.LocalFunction; import org.fortiss.af3.expression.model.terms.IExpressionTerm; import org.fortiss.af3.expression.model.terms.imperative.IStatementTerm; import org.fortiss.af3.generator.common.model.c.CSourcePackage; +import org.fortiss.af3.generator.common.model.source.SourceUnit; import org.fortiss.af3.platform.generic.generator.executable.GenericExecutionUnitExecutable; import org.fortiss.af3.platform.language.executable.IInitializableExecutable; import org.fortiss.af3.platform.language.executable.IReadableExecutable; @@ -59,6 +61,9 @@ import org.fortiss.tooling.kernel.extension.data.ITransformationContext; */ public class RaspberryPIExecutable extends GenericExecutionUnitExecutable { + private static final String SRC_LIB_SUB_PACKAGE_NAME = "src-lib"; + private static final String INC_LIB_SUB_PACKAGE_NAME = "inc-lib"; + /** Constructor. */ public RaspberryPIExecutable(ExecutionUnit modelElement) { super(modelElement); @@ -74,23 +79,63 @@ public class RaspberryPIExecutable extends GenericExecutionUnitExecutable { super.createExecutionUnitSourcePackage(name, deployedComponents, deployedPorts, context); - // Add source/header files here --> TODO + // TODO: doesn't work since not recognized by configure script + + // add src-lib/inc-lib sub packages (= folders in deployment) + // CSourcePackage sub = + // AF3GeneratorCommonLanguagesCFactory.eINSTANCE.createCSourcePackage(); + // sub.setBaseLocation(SRC_LIB_SUB_PACKAGE_NAME); + // pkg.getSubPackages().add(sub); + + // sub = AF3GeneratorCommonLanguagesCFactory.eINSTANCE.createCSourcePackage(); + // sub.setBaseLocation(INC_LIB_SUB_PACKAGE_NAME); + // pkg.getSubPackages().add(sub); + + // get system.h to add references to self-defined inc files + SourceUnit system = pkg.getSrcGenPackage().findSourceUnitByName("system.c"); + // pkg.getIncGenPackage().findSourceUnitByName("system.h"); + + // Add source/header files here to be copied into the deployment directory try { - // add main + /** COMPONENTS **/ + addFile(pkg, "src/main.c"); - // add IO + // reference is added by GenericExecutableBase -> only add file addFile(pkg, "inc/io.h"); addFile(pkg, "src/io.c"); - // add CAN - addFile(pkg, "inc/CanConnector.h"); - addFile(pkg, "src/CanConnector.c"); + // add all components including references + addFilesWithReference(pkg, system, "CanConnector"); + addFilesWithReference(pkg, system, "Gamepad"); + addFilesWithReference(pkg, system, "GPIO"); + addFilesWithReference(pkg, system, "IMU"); + addFilesWithReference(pkg, system, "LaserRangeFinder"); + addFilesWithReference(pkg, system, "LaserScanner"); + addFilesWithReference(pkg, system, "PWM"); + + /** LIBRARIES **/ + + // TODO: will fail during a build since not defined in Makefile - // add fix for dictionary, simply overwrite incorrect version (TODO!!) + // add UART lib + // addFile(pkg, "inc-lib/uart.h"); + // addFile(pkg, "src-lib/uart.c"); + addFile(pkg, "inc/libuart.h"); + addFile(pkg, "src/libuart.c"); + + /** FIXES AND PATCHES **/ + + // overwrite data_dictionary, the new one has all functions + // required for the simulation commented out so there are no + // conflicts addFile(pkg, "inc-gen/data_dictionary.h"); addFile(pkg, "src-gen/data_dictionary.c"); + // overwrite Makedefs, the new one uses -std=gnu99 instead of -std=c99 + // so libuart compiles properly + addFile(pkg, "Makedefs"); + } catch(IOException | URISyntaxException e) { throw new RuntimeException("could not add header and source files from lib", e); } @@ -98,12 +143,23 @@ public class RaspberryPIExecutable extends GenericExecutionUnitExecutable { return pkg; } + private static void addFilesWithReference(CSourcePackage pkg, SourceUnit source, + String fileWithoutExtension) throws IOException, URISyntaxException { + addFile(pkg, "src/" + fileWithoutExtension + ".c"); + addFile(pkg, "inc/" + fileWithoutExtension + ".h"); + addSystemCReference(source, fileWithoutExtension); + } + private static void addFile(CSourcePackage pkg, String file) throws IOException, URISyntaxException { pkg.addUnit(createByteContentUnitForPluginFile(AF3PlatformRaspberryActivator.PLUGIN_ID, "lib", file, false)); } + private static void addSystemCReference(SourceUnit source, String reference) { + addUserHeaderInclude(source, reference); + } + /** {@inheritDoc} */ @Override protected ComponentFunction createInitializeFunction( diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/util/RaspberryModelElementFactory.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/util/RaspberryModelElementFactory.java index 02052cb2..f5b95a53 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/util/RaspberryModelElementFactory.java +++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/util/RaspberryModelElementFactory.java @@ -92,7 +92,7 @@ public class RaspberryModelElementFactory { /** Creates a {@link SensorGamepad} */ public static SensorGamepad createGamepadSensor() { SensorGamepad connector = ModelFactory.eINSTANCE.createSensorGamepad(); - connector.setName("Gamepad_In"); + connector.setName("Gamepad"); createConnectorLayout(connector); return connector; } @@ -100,7 +100,7 @@ public class RaspberryModelElementFactory { /** Creates a {@link SensorIMU}. */ public static SensorIMU createSensorIMU() { SensorIMU connector = ModelFactory.eINSTANCE.createSensorIMU(); - connector.setName("IMU_In"); + connector.setName("IMU"); createConnectorLayout(connector); return connector; } @@ -108,7 +108,7 @@ public class RaspberryModelElementFactory { /** Creates a {@link SensorLaserRangeFinder}. */ public static SensorLaserRangeFinder createSensorLaserRangeFinder() { SensorLaserRangeFinder connector = ModelFactory.eINSTANCE.createSensorLaserRangeFinder(); - connector.setName("LaserRangeFinder_In"); + connector.setName("LaserRangeFinder"); createConnectorLayout(connector); return connector; } @@ -116,7 +116,7 @@ public class RaspberryModelElementFactory { /** Creates a {@link SensorLaserScanner}. */ public static SensorLaserScanner createSensorLaserScanner() { SensorLaserScanner connector = ModelFactory.eINSTANCE.createSensorLaserScanner(); - connector.setName("LaserScanner_In"); + connector.setName("LaserScanner"); createConnectorLayout(connector); return connector; } @@ -132,7 +132,7 @@ public class RaspberryModelElementFactory { /** Creates a {@link ActuatorPWM}. */ public static ActuatorPWM createActuatorPWM() { ActuatorPWM connector = ModelFactory.eINSTANCE.createActuatorPWM(); - connector.setName("PWM_Out"); + connector.setName("PWM"); createConnectorLayout(connector); return connector; } @@ -164,7 +164,7 @@ public class RaspberryModelElementFactory { /** Creates a {@link Button2}. */ public static Button2 createButton2() { Button2 button = GamepadFactory.eINSTANCE.createButton2(); - button.setName("Button1_Circle_"); + button.setName("Button2_Circle"); createConnectorLayout(button); return button; } @@ -185,6 +185,14 @@ public class RaspberryModelElementFactory { return button; } + /** Creates a {@link ButtonR1}. */ + public static ButtonR1 createButtonR1() { + ButtonR1 button = GamepadFactory.eINSTANCE.createButtonR1(); + button.setName("ButtonR1"); + createConnectorLayout(button); + return button; + } + /** Creates a {@link ButtonL1}. */ public static ButtonL1 createButtonL1() { ButtonL1 button = GamepadFactory.eINSTANCE.createButtonL1(); @@ -209,14 +217,6 @@ public class RaspberryModelElementFactory { return button; } - /** Creates a {@link ButtonR1}. */ - public static ButtonR1 createButtonR1() { - ButtonR1 button = GamepadFactory.eINSTANCE.createButtonR1(); - button.setName("ButtonR1"); - createConnectorLayout(button); - return button; - } - /** Creates a {@link Left_StickX_Position}. */ public static Left_StickX_Position createLeftStickX() { Left_StickX_Position button = GamepadFactory.eINSTANCE.createLeft_StickX_Position(); -- GitLab