Skip to content
Snippets Groups Projects
Commit f5d201fe authored by Stefan's avatar Stefan
Browse files

Adde af3_cc_get to code generator

parent 8d7e5856
No related branches found
No related tags found
1 merge request!1Feature/control center
......@@ -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();
......
/*
* 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_ */
/*******************************************************************************
* 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_ */
No preview for this file type
......@@ -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} */
......
......@@ -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";
}
}
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