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.
#define MODULE_ID 0x444d4f00
typedef struct {
double high;
double low;
} demodata_t;
static char **symbols = NULL;
static int symbols_num = 0;
static void demo_filewrite(FILE *fp, void *data);
static void *demo_fileread(FILE *fp, char *name);
static int demo_print(char *buf, size_t size, void *data);
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++ ) {
}
funcs.
desc =
"Demo Module";
return;
}
static void demo_filewrite(FILE *fp, void *data)
{
demodata_t *user = data;
fprintf(fp,"%f %f\n",user->high,user->low);
}
static void *demo_fileread(FILE *fp, char *name)
{
demodata_t *user;
user = calloc(1,sizeof(*user));
fscanf(fp,"%lf %lf",&user->high,&user->low);
return (user);
}
static int demo_print(char *buf, size_t size, void *data)
{
demodata_t *user = data;
if ( data == NULL )
return 0;
snprintf(buf,size,"High %lf Low %lf",user->high,user->low);
return 1;
}
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;
}