Skip to content
Snippets Groups Projects
Commit 3e491fa7 authored by fortissBot's avatar fortissBot
Browse files

Added C/H files for components and some patches, added code generation, added includes to system.h

refs 7863
parent 51ed8e0e
No related branches found
No related tags found
No related merge requests found
Showing
with 298 additions and 17 deletions
...@@ -19,8 +19,9 @@ Require-Bundle: org.fortiss.af3.project, ...@@ -19,8 +19,9 @@ Require-Bundle: org.fortiss.af3.project,
org.eclipse.core.runtime, org.eclipse.core.runtime,
org.eclipse.emf.ecore;visibility:=reexport, org.eclipse.emf.ecore;visibility:=reexport,
org.fortiss.tooling.base;visibility:=reexport, org.fortiss.tooling.base;visibility:=reexport,
org.fortiss.af3.platform;visibility:=reexport;bundle-version="2.5.0", org.fortiss.af3.platform;bundle-version="2.5.0";visibility:=reexport,
org.fortiss.tooling.base.ui;bundle-version="2.11.0" org.fortiss.tooling.base.ui;bundle-version="2.11.0",
org.fortiss.af3.generator.common
Import-Package: org.fortiss.af3.deployment.generator, Import-Package: org.fortiss.af3.deployment.generator,
org.fortiss.af3.platform.model org.fortiss.af3.platform.model
# 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
#ifndef __CAN_H #ifndef __CANCONNECTOR_H
#define __CAN_H #define __CANCONNECTOR_H
#include <stdio.h> #include <stdio.h>
...@@ -10,7 +10,7 @@ typedef const char* PORT_T; ...@@ -10,7 +10,7 @@ typedef const char* PORT_T;
// init, terminate, prepare // init, terminate, prepare
void can_init(); void can_init();
void can_terminate(); void can_term();
void prepare_input_CanConnector(); void prepare_input_CanConnector();
void finish_input_CanConnector(); void finish_input_CanConnector();
...@@ -32,4 +32,4 @@ void can_write_bool(PORT_T port, GEN_TYPE_boolean value); ...@@ -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_double(PORT_T port, GEN_TYPE_double value);
void can_write_int(PORT_T port, GEN_TYPE_int value); void can_write_int(PORT_T port, GEN_TYPE_int value);
#endif // __CAN_H #endif // __CANCONNECTOR_H
#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
/**
* @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
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
// init, terminate // init, terminate
void can_init(const char* message) { void can_init(const char* message) {
printf("initializing CAN\n"); printf("initializing CAN\n");
} }
void can_terminate() { void can_term() {
printf("terminating CAN\n"); printf("terminating CAN\n");
} }
void prepare_input_CanConnector() { void prepare_input_CanConnector() {
...@@ -28,24 +28,24 @@ void finish_output_CanConnector() { ...@@ -28,24 +28,24 @@ void finish_output_CanConnector() {
// NOVAL // NOVAL
GEN_TYPE_boolean can_is_noval(PORT_T port) { GEN_TYPE_boolean can_is_noval(PORT_T port) {
return true; return true;
} }
GEN_TYPE_boolean can_set_noval(PORT_T port) { GEN_TYPE_boolean can_set_noval(PORT_T port) {
return true; return true;
} }
// readers // readers
GEN_TYPE_boolean can_read_bool(PORT_T port) { GEN_TYPE_boolean can_read_bool(PORT_T port) {
return false; return false;
} }
GEN_TYPE_double can_read_double(PORT_T port) { GEN_TYPE_double can_read_double(PORT_T port) {
return 0.0; return 0.0;
} }
GEN_TYPE_int can_read_int(PORT_T port) { GEN_TYPE_int can_read_int(PORT_T port) {
return 0; return 0;
} }
// writers // writers
......
#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);
}
}
}
}
/**
* @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);
}
...@@ -3,10 +3,22 @@ ...@@ -3,10 +3,22 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <unistd.h>
#include "inc-gen/system.h"
int main(int argc, char* argv[]) { 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! // start a rover thread
printf("Hello world!\n"); //pthread_t pt_rover;
//pthread_create(&pt_rover, NULL, rover_main, NULL);
// run endlessly
while(1) {
run_system();
usleep(50000);
}
} }
...@@ -71,7 +71,7 @@ public class CanConnectorExecutable extends GenericTransceiverExecutable { ...@@ -71,7 +71,7 @@ public class CanConnectorExecutable extends GenericTransceiverExecutable {
@Override @Override
public IExpressionTerm getTermination() { public IExpressionTerm getTermination() {
// terminate the bus on the given interface // terminate the bus on the given interface
return funcCall("can_terminate"); return funcCall("can_term");
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
......
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