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

Rework of Raspberry platform architecture for upcoming lab course.

refs 3079
parent 37d70f35
No related branches found
No related tags found
No related merge requests found
Showing
with 566 additions and 106 deletions
org.fortiss.af3.platform.raspberry.ui/trunk/icons/gamepad.png

495 B

org.fortiss.af3.platform.raspberry.ui/trunk/icons/unknown.png

2.84 KiB

......@@ -48,12 +48,87 @@
<modelElementClass
modelElementClass="org.fortiss.af3.platform.raspberry.model.CanConnector">
</modelElementClass>
</editPartFactory>
</extension>
<extension
point="org.fortiss.tooling.kernel.ui.modelElementHandler">
<modelElementHandler
handler="org.fortiss.af3.platform.raspberry.ui.handler.PWMActuatorHandler">
<modelElementClass
modelElementClass="org.fortiss.af3.platform.raspberry.model.ActuatorPWM">
</modelElementClass>
</modelElementHandler>
<modelElementHandler
handler="org.fortiss.af3.platform.raspberry.ui.handler.GamepadReceiverHandler">
<modelElementClass
modelElementClass="org.fortiss.af3.platform.raspberry.model.SensorConnector">
modelElementClass="org.fortiss.af3.platform.raspberry.model.gamepad.Button1">
</modelElementClass>
</modelElementHandler>
<modelElementHandler
handler="org.fortiss.af3.platform.raspberry.ui.handler.GamepadReceiverHandler">
<modelElementClass
modelElementClass="org.fortiss.af3.platform.raspberry.model.ActuatorConnector">
modelElementClass="org.fortiss.af3.platform.raspberry.model.gamepad.Button2">
</modelElementClass>
</editPartFactory>
</modelElementHandler>
<modelElementHandler
handler="org.fortiss.af3.platform.raspberry.ui.handler.GamepadReceiverHandler">
<modelElementClass
modelElementClass="org.fortiss.af3.platform.raspberry.model.gamepad.Button3">
</modelElementClass>
</modelElementHandler>
<modelElementHandler
handler="org.fortiss.af3.platform.raspberry.ui.handler.GamepadReceiverHandler">
<modelElementClass
modelElementClass="org.fortiss.af3.platform.raspberry.model.gamepad.Button4">
</modelElementClass>
</modelElementHandler>
<modelElementHandler
handler="org.fortiss.af3.platform.raspberry.ui.handler.GamepadReceiverHandler">
<modelElementClass
modelElementClass="org.fortiss.af3.platform.raspberry.model.gamepad.ButtonL1">
</modelElementClass>
</modelElementHandler>
<modelElementHandler
handler="org.fortiss.af3.platform.raspberry.ui.handler.GamepadReceiverHandler">
<modelElementClass
modelElementClass="org.fortiss.af3.platform.raspberry.model.gamepad.ButtonL2">
</modelElementClass>
</modelElementHandler>
<modelElementHandler
handler="org.fortiss.af3.platform.raspberry.ui.handler.GamepadReceiverHandler">
<modelElementClass
modelElementClass="org.fortiss.af3.platform.raspberry.model.gamepad.ButtonR1">
</modelElementClass>
</modelElementHandler>
<modelElementHandler
handler="org.fortiss.af3.platform.raspberry.ui.handler.GamepadReceiverHandler">
<modelElementClass
modelElementClass="org.fortiss.af3.platform.raspberry.model.gamepad.ButtonR2">
</modelElementClass>
</modelElementHandler>
<modelElementHandler
handler="org.fortiss.af3.platform.raspberry.ui.handler.GamepadReceiverHandler">
<modelElementClass
modelElementClass="org.fortiss.af3.platform.raspberry.model.gamepad.Left_StickX_Position">
</modelElementClass>
</modelElementHandler>
<modelElementHandler
handler="org.fortiss.af3.platform.raspberry.ui.handler.GamepadReceiverHandler">
<modelElementClass
modelElementClass="org.fortiss.af3.platform.raspberry.model.gamepad.Left_StickY_Position">
</modelElementClass>
</modelElementHandler>
<modelElementHandler
handler="org.fortiss.af3.platform.raspberry.ui.handler.GamepadReceiverHandler">
<modelElementClass
modelElementClass="org.fortiss.af3.platform.raspberry.model.gamepad.Right_StickX_Position">
</modelElementClass>
</modelElementHandler>
<modelElementHandler
handler="org.fortiss.af3.platform.raspberry.ui.handler.GamepadReceiverHandler">
<modelElementClass
modelElementClass="org.fortiss.af3.platform.raspberry.model.gamepad.Right_StickY_Position">
</modelElementClass>
</modelElementHandler>
</extension>
</plugin>
......@@ -20,11 +20,9 @@ package org.fortiss.af3.platform.raspberry.ui.editpart;
import org.eclipse.gef.EditPart;
import org.eclipse.swt.graphics.Color;
import org.fortiss.af3.platform.model.PlatformConnectorUnit;
import org.fortiss.af3.platform.raspberry.model.ActuatorConnector;
import org.fortiss.af3.platform.raspberry.model.CanBus;
import org.fortiss.af3.platform.raspberry.model.CanConnector;
import org.fortiss.af3.platform.raspberry.model.RaspberryPi;
import org.fortiss.af3.platform.raspberry.model.SensorConnector;
import org.fortiss.af3.platform.ui.DefaultStyle;
import org.fortiss.af3.platform.ui.editpart.generic.ExecutionUnitEditPart;
import org.fortiss.af3.platform.ui.editpart.generic.StickyPlatformConnectorUnitEditPart;
......@@ -59,8 +57,7 @@ public class EditPartFactory implements IEditPartFactory {
};
} else if(model instanceof CanBus) {
return new TransmissionUnitDefaultEditPart((CanBus)model);
} else if(model instanceof CanConnector || model instanceof SensorConnector ||
model instanceof ActuatorConnector) {
} else if(model instanceof CanConnector) {
return new StickyPlatformConnectorUnitEditPart((PlatformConnectorUnit)model);
}
return null;
......
......@@ -17,12 +17,13 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
+--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.ui.handler;
import static org.fortiss.af3.platform.raspberry.ui.AF3PlatformRaspberryUIActivator.getImageDescriptor;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.resource.ImageDescriptor;
import org.fortiss.af3.platform.raspberry.model.CanBus;
import org.fortiss.af3.platform.raspberry.ui.AF3PlatformRaspberryUIActivator;
import org.fortiss.tooling.kernel.ui.extension.IModelElementHandler;
import org.fortiss.tooling.kernel.ui.extension.base.ModelElementHandlerBase;
......@@ -46,7 +47,7 @@ public class CanBusHandler extends ModelElementHandlerBase<CanBus> {
/** {@inheritDoc} */
@Override
public ImageDescriptor getIconImageDescriptor() {
return AF3PlatformRaspberryUIActivator.getImageDescriptor("icons/can-logo.jpeg");
return getImageDescriptor("icons/can-logo.jpeg");
}
/** {@inheritDoc} */
......
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
$Id$
| |
| Copyright 2017 fortiss GmbH |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
......@@ -15,25 +15,27 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.executable;
package org.fortiss.af3.platform.raspberry.ui.handler;
import org.fortiss.af3.platform.generic.generator.executable.GenericReceiverExecutable;
import org.fortiss.af3.platform.raspberry.model.SensorLaserRangeFinder;
import org.fortiss.af3.platform.raspberry.model.WheelEncoder;
import static org.fortiss.af3.platform.raspberry.ui.AF3PlatformRaspberryUIActivator.getImageDescriptor;
import org.eclipse.jface.resource.ImageDescriptor;
import org.fortiss.af3.platform.model.Receiver;
import org.fortiss.af3.platform.model.generic.GenericReceiver;
import org.fortiss.tooling.kernel.ui.extension.base.NamedCommentedModelElementHandlerBase;
/**
* Executable for {@link SensorLaserRangeFinder}.
* Handler for {@link GenericReceiver}s.
*
* @author eder
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: D80CF94CBBADB4627AAEDA1F34ABF0A5
*/
public class WheelEncoderExecutable extends GenericReceiverExecutable {
/** Constructor. */
public WheelEncoderExecutable(WheelEncoder modelElement) {
super(modelElement);
public class GamepadReceiverHandler extends NamedCommentedModelElementHandlerBase<Receiver> {
/** {@inheritDoc} */
@Override
public ImageDescriptor getIconImageDescriptor() {
return getImageDescriptor("icons/gamepad.png");
}
}
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
$Id$
| |
| Copyright 2017 fortiss GmbH |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
......@@ -15,50 +15,27 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.executable;
package org.fortiss.af3.platform.raspberry.ui.handler;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.expression.model.terms.IExpressionTerm;
import org.fortiss.af3.platform.generic.generator.executable.GenericReceiverExecutable;
import static org.fortiss.af3.platform.raspberry.ui.AF3PlatformRaspberryUIActivator.getImageDescriptor;
import org.eclipse.jface.resource.ImageDescriptor;
import org.fortiss.af3.platform.model.generic.GenericReceiver;
import org.fortiss.af3.platform.raspberry.model.SensorIMU;
import org.fortiss.af3.platform.raspberry.model.ActuatorPWM;
import org.fortiss.tooling.kernel.ui.extension.base.NamedCommentedModelElementHandlerBase;
/**
* Executable for {@link SensorIMU}.
* Handler for {@link GenericReceiver}s.
*
* @author eder
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: D80CF94CBBADB4627AAEDA1F34ABF0A5
*/
public class IMUSensorExecutable extends GenericReceiverExecutable {
/** Constructor. */
public IMUSensorExecutable(GenericReceiver modelElement) {
super(modelElement);
}
/** {@inheritDoc} */
@Override
public IExpressionTerm getInitialization() {
return super.getInitialization();
}
/** {@inheritDoc} */
@Override
public IExpressionTerm getNoValGuardAccessor(InputPort logicalSignal) {
return super.getNoValGuardAccessor(logicalSignal);
}
/** {@inheritDoc} */
@Override
public IExpressionTerm getTermination() {
return super.getTermination();
}
public class PWMActuatorHandler extends NamedCommentedModelElementHandlerBase<ActuatorPWM> {
/** {@inheritDoc} */
@Override
public IExpressionTerm getValueReadAccessor(InputPort logicalSignal) {
return super.getValueReadAccessor(logicalSignal);
public ImageDescriptor getIconImageDescriptor() {
return getImageDescriptor("icons/unknown.png");
}
}
......@@ -17,12 +17,13 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
+--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.ui.handler;
import static org.fortiss.af3.platform.raspberry.ui.AF3PlatformRaspberryUIActivator.getImageDescriptor;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.resource.ImageDescriptor;
import org.fortiss.af3.platform.raspberry.model.RaspberryPi;
import org.fortiss.af3.platform.raspberry.ui.AF3PlatformRaspberryUIActivator;
import org.fortiss.tooling.kernel.ui.extension.IModelElementHandler;
import org.fortiss.tooling.kernel.ui.extension.base.ModelElementHandlerBase;
......@@ -46,7 +47,7 @@ public class RaspberryPiHandler extends ModelElementHandlerBase<RaspberryPi> {
/** {@inheritDoc} */
@Override
public ImageDescriptor getIconImageDescriptor() {
return AF3PlatformRaspberryUIActivator.getImageDescriptor("icons/raspberry-pi-logo.png");
return getImageDescriptor("icons/raspberry-pi-logo.png");
}
/** {@inheritDoc} */
......@@ -54,5 +55,4 @@ public class RaspberryPiHandler extends ModelElementHandlerBase<RaspberryPi> {
public List<EObject> getConnectors(RaspberryPi element) {
return (List)element.getConnectors();
}
}
......@@ -27,13 +27,7 @@ import static org.fortiss.tooling.base.utils.LayoutModelElementFactory.createRec
import org.fortiss.af3.platform.raspberry.model.ActuatorPWM;
import org.fortiss.af3.platform.raspberry.model.CanBus;
import org.fortiss.af3.platform.raspberry.model.CanConnector;
import org.fortiss.af3.platform.raspberry.model.GPI;
import org.fortiss.af3.platform.raspberry.model.GPO;
import org.fortiss.af3.platform.raspberry.model.RaspberryPi;
import org.fortiss.af3.platform.raspberry.model.SensorIMU;
import org.fortiss.af3.platform.raspberry.model.SensorLaserRangeFinder;
import org.fortiss.af3.platform.raspberry.model.SensorLaserScanner;
import org.fortiss.af3.platform.raspberry.model.WheelEncoder;
import org.fortiss.af3.platform.raspberry.model.gamepad.Button1;
import org.fortiss.af3.platform.raspberry.model.gamepad.Button2;
import org.fortiss.af3.platform.raspberry.model.gamepad.Button3;
......@@ -82,41 +76,11 @@ public class ProtoypeProvider extends PrototypeProviderBase {
setConnectorPosition(con, 0, 0);
registerPrototype("CanConnector", con, CATEGORY_NAME);
SensorIMU imu = RaspberryModelElementFactory.createSensorIMU();
setNodePosition(imu, 0, 0);
setConnectorPosition(imu, 0, 0);
registerPrototype("IMU_Sensor", imu, CATEGORY_NAME);
SensorLaserRangeFinder slrf = RaspberryModelElementFactory.createSensorLaserRangeFinder();
setNodePosition(slrf, 0, 0);
setConnectorPosition(slrf, 0, 0);
registerPrototype("LaserRangeFinder_Sensor", slrf, CATEGORY_NAME);
SensorLaserScanner sls = RaspberryModelElementFactory.createSensorLaserScanner();
setNodePosition(sls, 0, 0);
setConnectorPosition(sls, 0, 0);
registerPrototype("LaserScanner_Sensor", sls, CATEGORY_NAME);
ActuatorPWM pwm = RaspberryModelElementFactory.createActuatorPWM();
setNodePosition(pwm, 0, 0);
setConnectorPosition(pwm, 0, 0);
registerPrototype("PWM_Actuator", pwm, CATEGORY_NAME);
GPI gpi = RaspberryModelElementFactory.createGPI();
setNodePosition(gpi, 0, 0);
setConnectorPosition(gpi, 0, 0);
registerPrototype("GPI", gpi, CATEGORY_NAME);
GPO gpo = RaspberryModelElementFactory.createGPO();
setNodePosition(gpo, 0, 0);
setConnectorPosition(gpo, 0, 0);
registerPrototype("GPO", gpo, CATEGORY_NAME);
WheelEncoder wEncoder = RaspberryModelElementFactory.createWheelEncoder();
setNodePosition(wEncoder, 0, 0);
setConnectorPosition(wEncoder, 0, 0);
registerPrototype("WheelEncoder", wEncoder, CATEGORY_NAME);
Button1 button1 = RaspberryModelElementFactory.createButton1();
setNodePosition(button1, 0, 0);
setConnectorPosition(button1, 0, 0);
......@@ -176,6 +140,5 @@ public class ProtoypeProvider extends PrototypeProviderBase {
setNodePosition(Right_StickY, 0, 0);
setConnectorPosition(Right_StickY, 0, 0);
registerPrototype(Right_StickY.getName(), Right_StickY, GAMEPAD);
}
}
......@@ -2,7 +2,7 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="generated-src"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="build"/>
</classpath>
/*******************************************************************************
* Copyright (c) 2017 fortiss GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Florian Hoelzl - initial API and implementation
*******************************************************************************/
#ifndef INC_AF3_H_
#define INC_AF3_H_
#include <canthread.h>
#include <stdbool.h>
#include <stdint.h>
// Make sure "data_dictionary.h" is included before "autofocus3_layer.h" for generated code
#ifndef __HEADER_data_dictionary_h
typedef bool GEN_TYPE_boolean;
typedef int GEN_TYPE_int;
typedef double GEN_TYPE_double;
#endif
/** Sets the unit identifier of this execution unit (mostly used when communicating with the control center. */
void af3_set_execution_unit_identifier(char* identifier);
/** Create a message containing a boolean value for this id. */
struct can_thread_message* af3_create_message_bool(uint8_t id, GEN_TYPE_boolean value);
/** Create a message containing an integer value for this id. */
struct can_thread_message* af3_create_message_int(uint8_t id, GEN_TYPE_int value);
/** Create a message containing a double value for this id. */
struct can_thread_message* af3_create_message_double(uint8_t id, GEN_TYPE_double value);
/** Returns whether the message represents a NoVal value. */
GEN_TYPE_boolean af3_is_noval(can_thread_message_t* message);
/** Returns the boolean value contained in the message. */
GEN_TYPE_boolean af3_get_boolean(can_thread_message_t* message);
/** Returns the integer value contained in the message. */
GEN_TYPE_int af3_get_int(can_thread_message_t* message);
/** Returns the double value contained in the message. */
GEN_TYPE_double af3_get_double(can_thread_message_t* message);
/** Activates the control center connection. */
void af3_cc_activate(char* server_ip_address, uint16_t server_port);
/** Sends a NoVal signal with the given name to the control center. */
void af3_cc_send_noval(char* signal, uint64_t timestamp);
/** Sends a boolean signal with the given name to the control center. */
void af3_cc_send_boolean(char* signal, GEN_TYPE_boolean value, uint64_t timestamp);
/** Sends an int signal with the given name to the control center. */
void af3_cc_send_int(char* signal, GEN_TYPE_int value, uint64_t timestamp);
/** Sends a double signal with the given name to the control center. */
void af3_cc_send_double(char* signal, GEN_TYPE_double value, uint64_t timestamp);
/** Deactivates the control center connection. */
void af3_cc_deactivate();
#endif /* INC_AF3_H_ */
/*******************************************************************************
* Copyright (c) 2017 fortiss GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Florian Hoelzl - initial API and implementation
*******************************************************************************/
#ifndef INC_CANCATALOG_H_
#define INC_CANCATALOG_H_
#include <stdint.h>
#include "canthread.h"
#include "caninbox.h"
/** Type of catalog entry receivers, which must reclaim the memory of the message after using it. */
typedef void (*can_catalog_receive_handler_t)(can_thread_message_t* message);
/** Initializes the cancatalog sub-system registering it with the canthreadsub-system. */
void can_catalog_initialize(const char* if_name, uint64_t can_thread_sleep_in_micros);
/** Sets name and handler function for the CAN message with the given id. */
void can_catalog_set_entry(uint8_t entry_id, char* signal_name, can_inbox_t* inbox);
/** Returns the catalog entry name for the CAN message with the given id. */
char* can_catalog_entry_name(uint8_t entry_id);
/** Unsets the catalog entry with the given id. */
void can_catalog_unset_entry(uint8_t entry_id);
/** Destroys the cancatalog and frees its resources. */
void can_catalog_destroy();
#endif /* INC_CANCATALOG_H_ */
/*******************************************************************************
* Copyright (c) 2017 fortiss GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Florian Hoelzl - initial API and implementation
*******************************************************************************/
#ifndef INC_CANINBOX_H_
#define INC_CANINBOX_H_
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <pthread.h>
#include "canthread.h"
typedef struct can_inbox can_inbox_t;
typedef bool (*can_inbox_acceptance_callback_t)(uint8_t message_id, uint64_t payload);
/** Creates an inbox with the given number of slots. */
can_inbox_t* can_inbox_create(char* name, int slots);
/** Adds the slot identifier to the next inbox slot and configures the blocking behavior for the pull and push requests. */
void can_inbox_add_slot(can_inbox_t* inbox, uint8_t message_id, char* signal_name);
/** Sets the synchronization option for the given inbox slot. */
void can_inbox_set_slot_synchronization(can_inbox_t* inbox, bool blocking_push, bool blocking_pull);
/** Set the acceptance callback for this inbox. */
void can_inbox_set_acceptance_callback(can_inbox_t* inbox, can_inbox_acceptance_callback_t callback);
/** Returns whether all slots in the inbox are filled. */
bool can_inbox_is_full(can_inbox_t* inbox);
/** Returns whether all slots in the inbox are empty. */
bool can_inbox_is_empty(can_inbox_t* inbox);
/** Pushes the message into inbox slots. Blocks if the slot is not empty and block flag is set. Returns true upon success. */
bool can_inbox_push_message(can_inbox_t* inbox, uint8_t slot_id, can_thread_message_t* message);
/** Pulls the message from the inbox. Blocks if the slot is not empty and block flag is set. */
struct can_thread_message* can_inbox_pull_message(can_inbox_t* inbox, uint8_t slot_id);
/** Clears all remaining messages in the inbox and frees their memory. */
void can_inbox_clear(can_inbox_t* inbox);
/** Frees the memory used by the inbox, its slots, and any message still contained therein. */
void can_inbox_destroy(can_inbox_t* inbox);
#endif /* INC_CANINBOX_H_ */
/*******************************************************************************
* Copyright (c) 2017 fortiss GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Florian Hoelzl - initial API and implementation
*******************************************************************************/
#ifndef INC_CANOUTBOX_H_
#define INC_CANOUTBOX_H_
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <pthread.h>
#include "canthread.h"
typedef struct can_outbox can_outbox_t;
/** Creates an outbox with the given name. */
can_outbox_t* can_outbox_create(char* name);
/** Pushes the message into outbox slots. Blocks if the slot is not empty and block flag is set. Returns true upon success. */
bool can_outbox_push_message(can_outbox_t* outbox, can_thread_message_t* message);
/** Pulls the message from the outbox. Blocks if the slot is not empty and block flag is set. */
struct can_thread_message* can_outbox_pull_message(can_outbox_t* outbox);
/** Clears all remaining messages in the outbox and frees their memory. */
void can_outbox_clear(can_outbox_t* outbox);
/** Frees the memory used by the outbox, its slots, and any message still contained therein. */
void can_outbox_destroy(can_outbox_t* outbox);
#endif /* INC_CANOUTBOX_H_ */
/*******************************************************************************
* Copyright (c) 2017 fortiss GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Florian Hoelzl - initial API and implementation
*******************************************************************************/
#ifndef __CANSOCKET_H
#define __CANSOCKET_H
#include <stdbool.h>
#include <stddef.h>
#include <unistd.h>
#include <sys/socket.h>
#include <linux/if.h>
#include <linux/can.h>
#define LIBCANSOCKET_ERROR -1
/** The CAN socket structure. */
struct can_socket {
int number; // socket number
struct sockaddr_can address; // socket address
struct ifreq ifreq; // socket ioctl interface
};
typedef struct can_socket can_socket_t;
typedef struct can_frame can_frame_t;
/**
* Opens a can socket on the interface (usually "can0") and returns the
* initialized socket structure.
*/
can_socket_t* can_socket_open(const char *if_name);
/** Closes the socket and frees the socket structure pointer. */
void can_socket_close(can_socket_t* can_socket);
/** Sends a can frame via the socket. */
size_t can_socket_send(can_socket_t* can_socket, can_frame_t* frame);
/** Checks if some bytes are available on the can. */
bool can_socket_available(can_socket_t* can_socket);
/** Receives a can frame via the socket. */
size_t can_socket_receive(can_socket_t* can_socket, can_frame_t* frame);
#endif // __CANSOCKET_H
/*******************************************************************************
* Copyright (c) 2017 fortiss GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Florian Hoelzl - initial API and implementation
*******************************************************************************/
#ifndef __CANTHREAD_H
#define __CANTHREAD_H
#include <cansocket.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
/** The message structure for CAN threads. */
struct can_thread_message {
uint8_t message_id;
uint8_t data[8];
};
typedef struct can_thread_message can_thread_message_t;
/**
* Creates a sender thread and a receiver thread for the interface using
* the handler functions for submission acknowledgments and retrieval handling.
* Note that the message pointers are reclaimed after the acknowledge and
* retrieve functions are called.
*/
bool can_thread_create(
const char* if_name,
void (*acknowlege)(can_thread_message_t* message),
void (*retrieve)(can_thread_message_t* message));
/**
* Creates a can message to be posted to the sender thread. Only up to
* 8 bytes from the variable argument list are used.
*/
can_thread_message_t* can_thread_message_create(uint8_t id, int vargsc, ...);
/** Fills the message with the 64-bit int value (big-endian encoding). */
void can_thread_message_set(can_thread_message_t* message, uint64_t value);
/** Returns the 64-bit int value extracted from the message. */
uint64_t can_thread_message_get(can_thread_message_t* message);
/** Set the sleep time for sender and receiver thread. */
void can_thread_set_thread_sleep_in_micros(uint32_t micros);
/** Posts a message via the sender thread. */
void can_thread_message_post(can_thread_message_t* message);
/** Terminate the can threads and wait until they have shut down. */
void can_thread_terminate();
#endif // __CANTHREAD_H
/*******************************************************************************
* Copyright (c) 2017 fortiss GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Florian Hoelzl - initial API and implementation
*******************************************************************************/
#ifndef INC_DEBUGPRINT_H_
#define INC_DEBUGPRINT_H_
#define DEBUG_PRINT_LEVEL_NONE 0
#define DEBUG_PRINT_LEVEL_FEW 1
#define DEBUG_PRINT_LEVEL_MANY 2
#define DEBUG_PRINT_LEVEL_ALL 3
extern int global_debug_print_level;
#ifdef DEBUG
#define USE_DEBUG_PRINTING 1
#else
#define USE_DEBUG_PRINTING 0
#endif
#define debug_print(lvl, fmt, ...) \
if(USE_DEBUG_PRINTING) if(lvl <= global_debug_print_level) fprintf(stderr, fmt, ##__VA_ARGS__)
#endif /* INC_DEBUGPRINT_H_ */
/*******************************************************************************
* Copyright (c) 2017 fortiss GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Thomas Boehm, Florian Hoelzl - initial API and implementation
*******************************************************************************/
#ifndef INC_GAMEPAD_H_
#define INC_GAMEPAD_H_
#include <stdint.h>
#define GAMEPAD_AXIS_LEFT_STICK_HORIZONTAL 0
#define GAMEPAD_AXIS_LEFT_STICK_VERTICAL 1
#define GAMEPAD_AXIS_RIGHT_STICK_HORIZONTAL 2
#define GAMEPAD_AXIS_RIGHT_STICK_VERTICAL 3
#define GAMEPAD_AXIS_CROSS_PAD_HORIZONTAL 4
#define GAMEPAD_AXIS_CROSS_PAD_VERTICAL 5
#define GAMEPAD_BUTTON_1 6
#define GAMEPAD_BUTTON_2 7
#define GAMEPAD_BUTTON_3 8
#define GAMEPAD_BUTTON_4 9
#define GAMEPAD_BUTTON_L1 10
#define GAMEPAD_BUTTON_R1 11
#define GAMEPAD_BUTTON_L2 12
#define GAMEPAD_BUTTON_R2 13
#define GAMEPAD_BUTTON_SELECT 14
#define GAMEPAD_BUTTON_START 15
#define GAMEPAD_BUTTON_LEFT_STICK 16
#define GAMEPAD_BUTTON_RIGHT_STICK 17
struct gamepad_configuration {
const char* device_id;
uint64_t waiting_sleep_in_micros;
void (*axis_callback)(uint8_t axis, uint16_t value);
void (*button_callback)(uint8_t button, uint16_t old_value, uint16_t new_value);
};
typedef struct gamepad_configuration gamepad_configuration_t;
/** Initializes the gamepad and starts its thread. */
void gamepad_initialize(gamepad_configuration_t* configuration);
/** Get the axis position for the given axis. */
int16_t gamepad_get_axis_position(uint8_t axisID);
/** Get the button state for the given button. */
int16_t gamepad_get_button_state(uint8_t buttonID);
/** Terminates the gamepad thread and frees its resources. */
void gamepad_terminate();
#endif /* INC_GAMEPAD_H_ */
/*******************************************************************************
* Copyright (c) 2017 fortiss GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Florian Hoelzl - initial API and implementation
*******************************************************************************/
#ifndef INC_PROTOCOL_CAN_H_
#define INC_PROTOCOL_CAN_H_
#include <stdint.h>
struct protocol_can_config {
uint8_t can_id_worker_done;
uint8_t can_id_coordinator_clock;
uint8_t can_id_global_shutdown;
};
typedef struct protocol_can_config protocol_can_config_t;
#endif /* INC_PROTOCOL_CAN_H_ */
/*******************************************************************************
* Copyright (c) 2017 fortiss GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Florian Hoelzl - initial API and implementation
*******************************************************************************/
#ifndef INC_PROTOCOL_CONTROL_CENTER_H_
#define INC_PROTOCOL_CONTROL_CENTER_H_
#include <stddef.h>
#include <stdint.h>
struct protocol_control_center_configuration {
char* server_ip_address;
uint16_t server_port;
};
typedef struct protocol_control_center_configuration protocol_control_center_configuration_t;
/** Create the connection to the control center. */
void protocol_control_center_create(protocol_control_center_configuration_t* config);
/** Writes len bytes of the given text to the control center. */
void protocol_control_center_write(char* text, size_t len);
/** Terminates the connection to the control center. */
void protocol_control_center_terminate();
#endif /* INC_PROTOCOL_CONTROL_CENTER_H_ */
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