Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split C header #290

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 1 addition & 172 deletions include/cse.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,77 +6,14 @@
#ifndef CSE_H
#define CSE_H

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

#include "cse_types.h"

/// \defgroup csecorec C library

#ifdef __cplusplus
extern "C" {
#endif


/// The type used to specify (simulation) time points. The time unit is nanoseconds.
typedef int64_t cse_time_point;

/// The type used to specify (simulation) time durations. The time unit is nanoseconds.
typedef int64_t cse_duration;

/// Variable index.
typedef uint32_t cse_variable_index;

/// Slave index.
typedef int cse_slave_index;

/// Step number
typedef long long cse_step_number;

/// Error codes.
typedef enum
{
CSE_ERRC_SUCCESS = 0,

// --- Codes unique to the C API ---

/// Unspecified error (but message may contain details).
CSE_ERRC_UNSPECIFIED,

/// Error reported by C/C++ runtime; check `errno` to get the right code.
CSE_ERRC_ERRNO,

/// Invalid function argument.
CSE_ERRC_INVALID_ARGUMENT,

/// Index out of range.
CSE_ERRC_OUT_OF_RANGE,

/**
* The time step failed, but can be retried with a shorter step length
* (if supported by all slaves).
*/
CSE_ERRC_STEP_TOO_LONG,

// --- Codes that correspond to C++ API error conditions ---

/// An input file is corrupted or invalid.
CSE_ERRC_BAD_FILE,

/// The requested feature (e.g. an FMI feature) is unsupported.
CSE_ERRC_UNSUPPORTED_FEATURE,

/// Error loading dynamic library (e.g. model code).
CSE_ERRC_DL_LOAD_ERROR,

/// The model reported an error.
CSE_ERRC_MODEL_ERROR,

/// ZIP file error.
CSE_ERRC_ZIP_ERROR,
} cse_errc;


/**
* Returns the error code associated with the last reported error.
*
Expand Down Expand Up @@ -112,13 +49,6 @@ cse_errc cse_last_error_code();
*/
const char* cse_last_error_message();


struct cse_execution_s;

/// An opaque object which contains the state for an execution.
typedef struct cse_execution_s cse_execution;


/**
* Creates a new execution.
*
Expand Down Expand Up @@ -157,11 +87,6 @@ cse_execution* cse_ssp_execution_create(
*/
int cse_execution_destroy(cse_execution* execution);

struct cse_slave_s;

/// An opaque object which contains the state for a slave.
typedef struct cse_slave_s cse_slave;


/**
* Creates a new local slave.
Expand Down Expand Up @@ -254,31 +179,6 @@ int cse_execution_disable_real_time_simulation(cse_execution* execution);
int cse_execution_set_real_time_factor_target(cse_execution *execution, double realTimeFactor);


/// Execution states.
typedef enum
{
CSE_EXECUTION_STOPPED,
CSE_EXECUTION_RUNNING,
CSE_EXECUTION_ERROR
} cse_execution_state;

/// A struct containing the execution status.
typedef struct
{
/// Current simulation time.
cse_time_point current_time;
/// Current execution state.
cse_execution_state state;
/// Last recorded error code.
int error_code;
/// Current real time factor.
double real_time_factor;
/// Current real time factor target.
double real_time_factor_target;
/// Executing towards real time target.
int is_real_time_simulation;
} cse_execution_status;

/**
* Returns execution status.
*
Expand All @@ -295,53 +195,6 @@ int cse_execution_get_status(
cse_execution* execution,
cse_execution_status* status);

/// Max number of characters used for slave name and source.
#define SLAVE_NAME_MAX_SIZE 1024

/// Variable types.
typedef enum
{
CSE_VARIABLE_TYPE_REAL,
CSE_VARIABLE_TYPE_INTEGER,
CSE_VARIABLE_TYPE_STRING,
CSE_VARIABLE_TYPE_BOOLEAN,
} cse_variable_type;

/// Variable causalities.
typedef enum
{
CSE_VARIABLE_CAUSALITY_INPUT,
CSE_VARIABLE_CAUSALITY_PARAMETER,
CSE_VARIABLE_CAUSALITY_OUTPUT,
CSE_VARIABLE_CAUSALITY_CALCULATEDPARAMETER,
CSE_VARIABLE_CAUSALITY_LOCAL,
CSE_VARIABLE_CAUSALITY_INDEPENDENT
} cse_variable_causality;

/// Variable variabilities.
typedef enum
{
CSE_VARIABLE_VARIABILITY_CONSTANT,
CSE_VARIABLE_VARIABILITY_FIXED,
CSE_VARIABLE_VARIABILITY_TUNABLE,
CSE_VARIABLE_VARIABILITY_DISCRETE,
CSE_VARIABLE_VARIABILITY_CONTINUOUS
} cse_variable_variability;

/// A struct containing metadata for a variable.
typedef struct
{
/// The name of the variable.
char name[SLAVE_NAME_MAX_SIZE];
/// The variable index.
cse_variable_index index;
/// The variable type.
cse_variable_type type;
/// The variable causality.
cse_variable_causality causality;
/// The variable variability.
cse_variable_variability variability;
} cse_variable_description;

/// Returns the number of variables for a slave which has been added to an execution, or -1 on error.
int cse_slave_get_num_variables(cse_execution* execution, cse_slave_index slave);
Expand All @@ -363,17 +216,6 @@ int cse_slave_get_num_variables(cse_execution* execution, cse_slave_index slave)
*/
int cse_slave_get_variables(cse_execution* execution, cse_slave_index slave, cse_variable_description variables[], size_t numVariables);

/// A struct containing information about a slave which has been added to an execution.
typedef struct
{
/// The slave instance name.
char name[SLAVE_NAME_MAX_SIZE];
/// The slave source (FMU file name).
char source[SLAVE_NAME_MAX_SIZE];
/// The slave's unique index in the exeuction.
cse_slave_index index;
} cse_slave_info;


/// Returns the number of slaves which have been added to an execution.
size_t cse_execution_get_num_slaves(cse_execution* execution);
Expand All @@ -394,19 +236,6 @@ size_t cse_execution_get_num_slaves(cse_execution* execution);
int cse_execution_get_slave_infos(cse_execution* execution, cse_slave_info infos[], size_t numSlaves);


// Observer
struct cse_observer_s;

/// An opaque object which contains the state for an observer.
typedef struct cse_observer_s cse_observer;

// Manipulator
struct cse_manipulator_s;

/// An opaque object which contains the state for a manipulator.
typedef struct cse_manipulator_s cse_manipulator;


/**
* Sets the values of real variables for one slave.
*
Expand Down
Loading