diff --git a/org.fortiss.af3.platform.raspberry/code-gen-hal/inc/af3pihal/af3.h b/org.fortiss.af3.platform.raspberry/code-gen-hal/inc/af3pihal/af3.h index e1338f8a8bde05c802dc515ef065673e120399f3..87b44f3f7bff3e1ec5b9468b09b6b339462d7ba2 100644 --- a/org.fortiss.af3.platform.raspberry/code-gen-hal/inc/af3pihal/af3.h +++ b/org.fortiss.af3.platform.raspberry/code-gen-hal/inc/af3pihal/af3.h @@ -22,27 +22,62 @@ 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); +// new structure for receiveing message +typedef struct receive_message_t{ + char modulename[30]; + char variablename[30]; + char value[30]; + char time[30]; +}receive_message_t; + +/* + * Function for initializing the module and callbacks + */ +typedef void* (*af3_component_copy_value_callback_t)(uint16_t type, void* value); +typedef void (*af3_component_free_value_callback_t)(uint16_t type, void* value); +void af3_module_initialize( + char* unit_identifier, uint16_t number_of_user_types, + af3_component_copy_value_callback_t copy_value_callback, + af3_component_free_value_callback_t free_value_callback); +af3_component_copy_value_callback_t af3_get_copy_value_callback(); +af3_component_free_value_callback_t af3_get_free_value_callback(); + +/* + * Functions for creating and reading CAN messages. + */ +/** Create a message containing a NoVal value for this unit and signal id. */ +can_thread_message_t* af3_message_create_noval(uint8_t unit_id, uint16_t signal_id); +/** Create a message containing a boolean value for this unit and signal id. */ +can_thread_message_t* af3_message_create_bool(uint8_t unit_id, uint16_t signal_id, GEN_TYPE_boolean* value); +/** Create a message containing an integer value for this unit and signal id. */ +can_thread_message_t* af3_message_create_int(uint8_t unit_id, uint16_t signal_id, GEN_TYPE_int* value); +/** Create a message containing a double value for this unit and signal id. */ +can_thread_message_t* af3_message_create_double(uint8_t unit_id, uint16_t signal_id, GEN_TYPE_double* value); +// TODO: other messages for composite types + +/** Returns the unit id of the given message. */ +uint8_t af3_message_get_unit_id(can_thread_message_t* message); +/** Returns the signal id of the given message. */ +uint16_t af3_message_get_signal_id(can_thread_message_t* message); /** Returns whether the message represents a NoVal value. */ -GEN_TYPE_boolean af3_is_noval(can_thread_message_t* message); +GEN_TYPE_boolean af3_message_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); +GEN_TYPE_boolean af3_message_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); +GEN_TYPE_int af3_message_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); +GEN_TYPE_double af3_message_get_double(can_thread_message_t* message); +/** Returns the raw payload value as an unsigned 4-byte integer. */ +uint32_t af3_message_get_raw_value(can_thread_message_t* message); +/* + * Functions for communicating with the control center application via TCP socket. + */ /** 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. */ @@ -51,6 +86,10 @@ void af3_cc_send_boolean(char* signal, GEN_TYPE_boolean value, uint64_t timestam 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); +/** listener for received messages**/ +void af3_cc_listen(void (*listener_handler) (receive_message_t)); +/** Receive a message from control center. */ +void af3_cc_receive(void *listener_handler); /** Deactivates the control center connection. */ void af3_cc_deactivate(); diff --git a/org.fortiss.af3.platform.raspberry/code-gen-hal/inc/af3pihal/control_center_downstream.h b/org.fortiss.af3.platform.raspberry/code-gen-hal/inc/af3pihal/control_center_downstream.h new file mode 100644 index 0000000000000000000000000000000000000000..18e5c96ca4b620af0c73ca4195a608b0c32f15de --- /dev/null +++ b/org.fortiss.af3.platform.raspberry/code-gen-hal/inc/af3pihal/control_center_downstream.h @@ -0,0 +1,85 @@ +/* + * control_center_downstream.h + * + * Created on: 05.06.2018 + * Author: Constantin + */ + +#ifndef INC_CONTROL_CENTER_DOWNSTREAM_H_ +#define INC_CONTROL_CENTER_DOWNSTREAM_H_ + +#include "af3.h" +#define INTBASE 10 //!< Base for conversion from string to int (10 for dec) + +/** REMOVE THIS THIS IS DUMMY CODE +#define STRING_MAX_LEN 100 +// new structure for receiveing message +typedef struct receive_message_t{ + char modulename[STRING_MAX_LEN]; + char variablename[STRING_MAX_LEN]; + char value[STRING_MAX_LEN]; + char time[STRING_MAX_LEN]; +}receive_message_t; +*/ + +//void af3_cc_listen(void (*somefunctionpointer)(receive_message_t)); +//end dummy code section + +/** + * \brief Initialize the downstream communication for control center. + * Currently just initializes a mutex. + */ +void af3_cc_donwstream_init(void); + +/** + * \brief Handler function for received control center downstream messages. + * Stores a given received message in a list of received messages for further + * processing. + * @param received_message The received message to be handled. + */ +void cc_downstream_message_handler(receive_message_t received_message); + +/** + * \brief Get a received integer variable with the given name. + * Checks whether an integer variable with the given name was received. If so + * the value of the received variable is converted to integer an stored at the + * given destination. If no appropriate message was received the destination + * variable won't get modified. + * @param userfriendly_name The userfriendly name of the variable to search for. + * @param variable_to_write A pointer to the destination where the integer value + * will be stored if a message was received containing the desired variable. + * @return Positive if the destination variable was updated, negative otherwise. + */ +int af3_cc_get_int(char* userfriendly_name, GEN_TYPE_int* variable_to_write); + +/** + * \brief Get a received boolean variable with the given name. + * Checks whether an boolean variable with the given name was received. If so + * the value of the received variable is converted to boolean an stored at the + * given destination. If no appropriate message was received the destination + * variable won't get modified. + * @param userfriendly_name The userfriendly name of the variable to search for. + * @param variable_to_write A pointer to the destination where the boolean value + * will be stored if a message was received containing the desired variable. + * @return Positive if the destination variable was updated, negative otherwise. + */ +int af3_cc_get_bool(char* userfriendly_name, + GEN_TYPE_boolean* variable_to_write); + +/** + * \brief Get a received double variable with the given name. + * Checks whether an double variable with the given name was received. If so + * the value of the received variable is converted to double an stored at the + * given destination. If no appropriate message was received the destination + * variable won't get modified. + * @param userfriendly_name The userfriendly name of the variable to search for. + * @param variable_to_write A pointer to the destination where the double value + * will be stored if a message was received containing the desired variable. + * @return Positive if the destination variable was updated, negative otherwise. + */ +int af3_cc_get_double(char* userfriendly_name, + GEN_TYPE_double* variable_to_write); + + + +#endif /* INC_CONTROL_CENTER_DOWNSTREAM_H_ */ diff --git a/org.fortiss.af3.platform.raspberry/code-gen-hal/inc/af3pihal/controlcenter.h b/org.fortiss.af3.platform.raspberry/code-gen-hal/inc/af3pihal/controlcenter.h deleted file mode 100644 index e1338f8a8bde05c802dc515ef065673e120399f3..0000000000000000000000000000000000000000 --- a/org.fortiss.af3.platform.raspberry/code-gen-hal/inc/af3pihal/controlcenter.h +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * 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_ */ diff --git a/org.fortiss.af3.platform.raspberry/code-gen-hal/lib/libaf3pihal.a b/org.fortiss.af3.platform.raspberry/code-gen-hal/lib/libaf3pihal.a index 25fb2cde3c9624de13722a0fa5f49459e62633a1..2f838f910d33bb23ea49c461fa4102093071518f 100644 Binary files a/org.fortiss.af3.platform.raspberry/code-gen-hal/lib/libaf3pihal.a and b/org.fortiss.af3.platform.raspberry/code-gen-hal/lib/libaf3pihal.a differ diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/controlcenter/ControlCenterDownstreamInputGeneratorExtension.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/controlcenter/ControlCenterDownstreamInputGeneratorExtension.java index 88a3ad2c641da6a8aedf5d9a0259f4f703fb9641..ec25877f29afe62d57872d52c84cf4ecfa2a6f48 100644 --- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/controlcenter/ControlCenterDownstreamInputGeneratorExtension.java +++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/controlcenter/ControlCenterDownstreamInputGeneratorExtension.java @@ -16,6 +16,9 @@ package org.fortiss.af3.platform.raspberry.generator.extension.controlcenter; import org.fortiss.af3.component.model.InputPort; +import org.fortiss.af3.expression.model.types.TBool; +import org.fortiss.af3.expression.model.types.TDouble; +import org.fortiss.af3.expression.model.types.TInt; import org.fortiss.af3.platform.raspberry.generator.framework.IReadableGeneratorExtension; import org.fortiss.af3.platform.raspberry.model.controlcenter.ControlCenterDownstreamInput; @@ -34,7 +37,23 @@ public class ControlCenterDownstreamInputGeneratorExtension extends String targetVariable) { // TODO Auto-generated method stub // return targetVariable + " = gamepad_get_button_state(" + getButtonIdentifier() + ");\n"; - return targetVariable + " = 7891;\n"; + + String portInputName = modelElement.getName(); + // get the value depending on the logical signal data type + if(logicalSignal.getVariableType() instanceof TDouble) { + return "af3_cc_get_double(\"" + modelElement.getName() + "\" , " + "&" + + targetVariable + " );\n"; + } else if(logicalSignal.getVariableType() instanceof TInt) { + return "af3_cc_get_int(\"" + modelElement.getName() + "\" , " + "&" + targetVariable + + " );\n"; + } else if(logicalSignal.getVariableType() instanceof TBool) { + return "af3_cc_get_bool(\"" + modelElement.getName() + "\" , " + "&" + targetVariable + + " );\n"; + } else { + return "FIXME(\"Data type " + logicalSignal.getVariableType() + " of Port " + + portInputName + " not supported for control centert.\");\n"; + } + } /** {@inheritDoc} */ diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/controlcenter/ControlcenterGeneratorExtensionBase.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/controlcenter/ControlcenterGeneratorExtensionBase.java index 87146e4b7e8bec5c20fc933bc383d8bfcd6ee52e..78d814b83c49d6e9f76867c4652cf8a38d7e82e5 100644 --- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/controlcenter/ControlcenterGeneratorExtensionBase.java +++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/extension/controlcenter/ControlcenterGeneratorExtensionBase.java @@ -76,6 +76,6 @@ abstract class ControlcenterGeneratorExtensionBase<T extends EObject> extends /** {@inheritDoc} */ @Override public final String getHeaderFileName() { - return "controlcenter.h"; + return "control_center_downstream.h"; } }