Skip to content

Commit

Permalink
New model API.
Browse files Browse the repository at this point in the history
Signed-off-by: Rule Timothy (VM/EMT3) <[email protected]>
  • Loading branch information
timrulebosch committed Jan 26, 2024
1 parent 5bdf5ad commit 06519f2
Show file tree
Hide file tree
Showing 82 changed files with 2,569 additions and 1,898 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export DSE_SCHEMA_URL ?= $(DSE_SCHEMA_REPO)/releases/download/v$(DSE_SCHEMA_VERS
###############
## DSE C Library.
DSE_CLIB_REPO ?= https://github.com/boschglobal/dse.clib
DSE_CLIB_VERSION ?= 1.0.7
DSE_CLIB_VERSION ?= 1.0.8
export DSE_CLIB_URL ?= $(DSE_CLIB_REPO)/archive/refs/tags/v$(DSE_CLIB_VERSION).zip


Expand Down
13 changes: 10 additions & 3 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ DOC_OUTPUT_model := doc/content/apis/modelc/model/index.md
DOC_LINKTITLE_model := Model
DOC_TITLE_model := "Model API Reference"

# Module "runtime"
DOC_INPUT_runtime := dse/modelc/runtime.h
DOC_CDIR_runtime := dse/modelc/controller/modelc.c,dse/modelc/controller/modelc_args.c,dse/modelc/controller/modelc_debug.c,
DOC_OUTPUT_runtime := doc/content/apis/modelc/runtime/index.md
DOC_LINKTITLE_runtime := Runtime
DOC_TITLE_runtime := "Runtime API Reference"

# Module "schema"
DOC_INPUT_schema := dse/modelc/schema.h
DOC_CDIR_schema := dse/modelc/model/schema.c
Expand All @@ -53,15 +60,15 @@ DOC_LINKTITLE_schema := Schema
DOC_TITLE_schema := "Schema API Reference"

# Module "simmock"
DOC_INPUT_simmock := dse/modelc/mocks/simmock.h
DOC_CDIR_simmock := dse/modelc/mocks/simmock.c
DOC_INPUT_simmock := dse/mocks/simmock.h
DOC_CDIR_simmock := dse/mocks/simmock.c
DOC_OUTPUT_simmock := doc/content/apis/modelc/simmock/index.md
DOC_LINKTITLE_simmock := SimMock
DOC_TITLE_simmock := "SimMock API Reference"


# Targets
DOC_C_MODULES := gateway mcl model schema simmock
DOC_C_MODULES := gateway mcl model runtime schema simmock
#DOC_C_MODULES := model

.PHONY: examples
Expand Down
1 change: 1 addition & 0 deletions doc/content/apis/modelc/examples/gateway.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: Apache-2.0

#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <dse/modelc/gateway.h>
#include <dse/logger.h>
Expand Down
44 changes: 44 additions & 0 deletions doc/content/apis/modelc/examples/model_create.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <stddef.h>
#include <string.h>
#include <dse/modelc/model.h>
#include <dse/logger.h>

typedef struct {
ModelDesc model;
/* Signal Pointers. */
struct {
double* counter;
} signals;
} ExtendedModelDesc;

static inline double* _index(ExtendedModelDesc* m, const char* v, const char* s)
{
ModelSignalIndex idx = m->model.index((ModelDesc*)m, v, s);
if (idx.scalar == NULL) log_fatal("Signal not found (%s:%s)", v, s);
return idx.scalar;
}

ModelDesc* model_create(ModelDesc* model)
{
/* Extend the ModelDesc object (using a shallow copy). */
ExtendedModelDesc* m = calloc(1, sizeof(ExtendedModelDesc));
memcpy(m, model, sizeof(ModelDesc));

/* Index the signals that are used by this model. */
m->signals.counter = _index(m, "data", "counter");

/* Set initial values. */
*(m->signals.counter) = 42;

/* Return the extended object. */
return (ModelDesc*)m;
}

int model_step(ModelDesc* model, double* model_time, double stop_time)
{
ExtendedModelDesc* m = (ExtendedModelDesc*)model;
*(m->signals.counter) += 1;

*model_time = stop_time;
return 0;
}
47 changes: 11 additions & 36 deletions doc/content/apis/modelc/examples/model_interface.c
Original file line number Diff line number Diff line change
@@ -1,50 +1,25 @@
#include <errno.h>
#include <stddef.h>
#include <dse/modelc/model.h>
#include <dse/logger.h>


#define UNUSED(x) ((void)x)


/* Signal Vector definition.
Note: Signal order should match order in related SignalGroup (YAML). */
typedef enum signal_name_index {
SIGNAL_FOO,
SIGNAL_BAR,
__SIGNAL__COUNT__
} signal_name_index;

static double* signal_value;


int model_step(double* model_time, double stop_time)
ModelDesc* model_create(ModelDesc* m)
{
signal_value[SIGNAL_FOO] += 1.2;
signal_value[SIGNAL_BAR] += 4.2;

*model_time = stop_time;
return 0;
return (ModelDesc*)m;
}

int model_setup(ModelInstanceSpec* mi)
int model_step(ModelDesc* m, double* model_time, double stop_time)
{
int rc = model_function_register(mi, "example",
0.005, model_step);
if (rc != 0) return rc;

/* Register channels (and get storage). */
static ModelChannelDesc channel_desc = {
.name = "model_channel",
.function_name = "example",
};
rc = model_configure_channel(mi, &channel_desc);
if (rc != 0) return rc;
signal_value = channel_desc.vector_double;
ModelSignalIndex counter = m->index(m, "data", "counter");
if (counter.scalar == NULL) return -EINVAL;
*(counter.scalar) += 1;

*model_time = stop_time;
return 0;
}

int model_exit(ModelInstanceSpec* mi)
void model_destroy(ModelDesc* m)
{
UNUSED(mi);
return 0;
UNUSED(m);
}
13 changes: 0 additions & 13 deletions doc/content/apis/modelc/examples/model_sv_create.c

This file was deleted.

15 changes: 15 additions & 0 deletions doc/content/apis/modelc/examples/signalvector_annotation.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <stdlib.h>
#include <dse/modelc/model.h>

ModelDesc* model_create(ModelDesc* m)
{
ModelSignalIndex idx = m->index(m, "data", "counter");

if (idx.scalar) {
/* Set initial value. */
const char* v = idx.sv->annotation(idx.sv, idx.signal, "initial_value");
if (v) *(idx.scalar) = atoi(v);
}

return m;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#include <string.h>
#include <dse/modelc/model.h>
#include <dse/logger.h>

void print_signal_vectors(ModelInstanceSpec* mi)
#define UNUSED(x) ((void)x)

int model_step(ModelDesc* m, double* model_time, double stop_time)
{
SignalVector* sv = model_sv_create(mi);
SignalVector* sv = m->sv;
while (sv && sv->name) {
log_debug("Signal Vector : %s", sv->name);

Expand All @@ -30,4 +33,7 @@ void print_signal_vectors(ModelInstanceSpec* mi)
// Next signal vector.
sv++;
}
}

*model_time = stop_time;
return 0;
}
4 changes: 2 additions & 2 deletions doc/content/apis/modelc/examples/simmock_configure.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <dse/testing.h>
#include <dse/modelc/mocks/simmock.h>
#include <dse/mocks/simmock.h>

int test_setup(void** state)
{
Expand All @@ -19,7 +19,7 @@ int test_setup(void** state)
};
SimMock* mock = simmock_alloc(inst_names, ARRAY_SIZE(inst_names));
simmock_configure(mock, argv, ARRAY_SIZE(argv), ARRAY_SIZE(inst_names));
simmock_load(mock, true);
simmock_load(mock);
simmock_setup(mock, "signal", "network");

/* Return the mock. */
Expand Down
2 changes: 1 addition & 1 deletion doc/content/apis/modelc/examples/simmock_frame_check.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <dse/testing.h>
#include <dse/modelc/mocks/simmock.h>
#include <dse/mocks/simmock.h>

void test_network__frame_check(void** state)
{
Expand Down
2 changes: 1 addition & 1 deletion doc/content/apis/modelc/examples/simmock_signal_check.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <dse/testing.h>
#include <dse/modelc/mocks/simmock.h>
#include <dse/mocks/simmock.h>

#define SIG_task_init_done 1
#define SIG_task_5_active 2
Expand Down
2 changes: 1 addition & 1 deletion doc/content/apis/modelc/mcl/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ typedef struct MclAdapterDesc {
```c
typedef struct MclInstanceDesc {
int * model_instance;
int * channel;
int * mcl_channel_sv;
MclStrategyDesc * strategy;
int models;
}
Expand Down
Loading

0 comments on commit 06519f2

Please sign in to comment.