-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Rule Timothy (VM/EMT3) <[email protected]>
- Loading branch information
1 parent
5bdf5ad
commit 06519f2
Showing
82 changed files
with
2,569 additions
and
1,898 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
doc/content/apis/modelc/examples/signalvector_annotation.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.