This module calculates High & Low for a set of symbols and publishes them to DataSource, as well as caching them in the core. It is designed as an example of how to associate module related data with symbols held within the Transformer cache.
- Note
- This example has been written using the legacy API.
Sample configuration:
symbols /DEMO/*
Source code:
#define MODULE_ID 0x444d4f00
typedef struct {
double high;
double low;
} demodata_t;
static char **symbols = NULL;
static int symbols_num = 0;
static void demo_recv_update(
int feed,
ds_data_t *pkt, time_t arr_tim,
int id,
void *data);
{
char buf[1024];
int i;
ds_config_add_array_option(
"symbols",
"Symbols to process",
DS_CONFIG_STR_ARRAY,&symbols,&symbols_num);
snprintf(buf,sizeof(buf),"%s.conf",module_name);
if ( symbols_num == 0 ) {
ds_printf_time(
rtas_log,
"(%s) No symbols required\n",module_name);
return;
}
for ( i = 0; i < symbols_num; i++ ) {
}
return;
}
static void demo_recv_update(
int feed,
ds_data_t *pkt, time_t arr_tim,
int id,
void *data)
{
demodata_t *user;
double val;
char *value;
user = calloc(1,sizeof(*user));
user->high = 0.0;
user->low = 99999999.0;
}
val = atof(value);
if ( val > user->high ) {
user->high = val;
ds_add_record_float(dsdata,"High",val);
}
if ( val < user->low ) {
user->low = val;
ds_add_record_float(dsdata,"Low",val);
}
}
ds_free_data(dsdata);
}
return;
}