Commit 52a5098a authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Move trace related stuff from controller_block to controller_block_trace

(previous commit was incomplete...)
parent ed86bece
......@@ -46,6 +46,7 @@ BLOCKSRCS= \
CONTROLLERSRCS= \
controller_block.c \
controller_block_param.c \
controller_block_trace.c \
controller_setpoint_command.c \
controller_trace.c \
controller_sample.c \
......
......@@ -39,10 +39,6 @@ struct calculate_func {
static int nr_calculates = 0;
static struct calculate_func *calculates = NULL;
static int nr_traces = 0;
static struct controller_trace **traces;
static int max_traces = 0;
static char *controller_block_context = "unknown";
#define BLOCK_PREFIX "block_"
......@@ -467,92 +463,6 @@ int controller_block_link(void)
}
static pthread_mutex_t trace_lock;
static sem_t trace_sync_sem;
static sem_t trace_waitsem;
static struct controller_trace *trace_add_ptr = NULL;
static struct controller_trace *trace_del_ptr = NULL;
void controller_block_trace_init(int max)
{
int i;
traces = malloc(sizeof(struct controller_trace *) * max);
max_traces = max;
/* touch entire trace list */
for (i = 0; i < max; i++) {
traces[i] = NULL;
}
pthread_mutex_init(&trace_lock, NULL);
sem_init(&trace_sync_sem, 0, 0);
sem_init(&trace_waitsem, 0, 0);
}
int controller_block_trace_add(char *block, char *outterm,
struct controller_trace *trace)
{
void *ptr = NULL;
enum controller_block_term_type type = 0;
int i, j;
int ret = 0;
for (i = 0; i < nr_blocks; i++) {
if (strcmp(block, blocks[i]->name))
continue;
for (j = 0; j < blocks[i]->outputs; j++) {
if (!strcmp(outterm, blocks[i]->output[j].name)){
ptr = blocks[i]->output[j].value.v;
type = blocks[i]->output[j].type;
}
}
}
trace->rd_pos = 0;
trace->wr_pos = 0;
trace->type = type;
trace->ptr = ptr;
/* touch the entire buffer atleast once */
for (i = 0; i < trace->len; i++) {
trace->buffer[i] = (float)i;
}
pthread_mutex_lock(&trace_lock);
if (nr_traces < max_traces) {
trace_add_ptr = trace;
log_send(LOG_T_DEBUG, "Addded %s.%s to trace list",
block, outterm);
} else {
ret = 1;
}
sem_wait(&trace_sync_sem);
pthread_mutex_unlock(&trace_lock);
return ret;
}
void controller_block_trace_del(struct controller_trace *trace)
{
pthread_mutex_lock(&trace_lock);
trace_del_ptr = trace;
sem_wait(&trace_sync_sem);
pthread_mutex_unlock(&trace_lock);
return;
}
void controller_block_trace_wait(void)
{
sem_wait(&trace_waitsem);
}
uint64_t controller_time_nseconds = 0;
uint32_t controller_time_seconds = 0;
......@@ -569,77 +479,6 @@ void controller_block_calculate(void)
void controller_block_trace(void)
{
int i;
int semval;
if (trace_add_ptr) {
traces[nr_traces] = trace_add_ptr;
nr_traces++;
trace_add_ptr = NULL;
sem_post(&trace_sync_sem);
}
if (trace_del_ptr) {
for (i = 0; i < nr_traces; i++) {
if (traces[i] == trace_del_ptr) {
if (i + 1 < nr_traces) {
memmove(&traces[i + 0],
&traces[i + 1],
sizeof(struct controller_trace *) *
(nr_traces - i - 1));
}
break;
}
}
nr_traces--;
trace_del_ptr = NULL;
sem_post(&trace_sync_sem);
}
for (i = 0; i < nr_traces; i++) {
if (controller_time_samplenr == 0)
{
traces[i]->wr_pos++;
if (traces[i]->wr_pos == traces[i]->len)
traces[i]->wr_pos = 0;
*((uint32_t *)&traces[i]->buffer[traces[i]->wr_pos]) =
0xffffffff; /* NaN */
traces[i]->wr_pos++;
if (traces[i]->wr_pos == traces[i]->len)
traces[i]->wr_pos = 0;
*((uint32_t *)&traces[i]->buffer[traces[i]->wr_pos]) =
controller_time_seconds;
}
traces[i]->wr_pos++;
if (traces[i]->wr_pos == traces[i]->len)
traces[i]->wr_pos = 0;
switch (traces[i]->type) {
case CONTROLLER_BLOCK_TERM_BOOL:
traces[i]->buffer[traces[i]->wr_pos] =
*(bool*)traces[i]->ptr;
break;
case CONTROLLER_BLOCK_TERM_FLOAT:
traces[i]->buffer[traces[i]->wr_pos] =
*(float*)traces[i]->ptr;
break;
case CONTROLLER_BLOCK_TERM_UINT32:
traces[i]->buffer[traces[i]->wr_pos] =
*(uint32_t*)traces[i]->ptr;
break;
default:
traces[i]->buffer[traces[i]->wr_pos] = -1;
}
}
sem_getvalue(&trace_waitsem, &semval);
if (!semval) {
sem_post(&trace_waitsem);
}
}
int controller_block_interm_list_init(struct controller_block *block,
struct controller_block_interm_list *list)
......
/*
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2007, 2009
Copyright Stichting C.A. Muller Radioastronomiestation, 2007, 2009
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2007, 2009, 2013
Copyright Stichting C.A. Muller Radioastronomiestation, 2007, 2009, 2013
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -118,12 +118,6 @@ struct controller_block_outterm_list {
size_t priv_offset;
};
/* List of params which must be initialized in the block's param pointer */
struct controller_block_param_list {
char *name;
bool sample; /* True: all access to params must be 'sample safe' */
};
/* Starting point for a block.
Additional data a block might need can be pointed to by the private pointer.
*/
......@@ -191,12 +185,6 @@ int controller_block_interm_list_init(struct controller_block *block,
int controller_block_outterm_list_init(struct controller_block *block,
struct controller_block_outterm_list *list);
void controller_block_param_init(void);
int controller_block_param_list_init(struct controller_block *block,
struct controller_block_param_list *list);
int controller_block_param_set(char *block, char *param, va_list);
int controller_block_param_get(char *block, char *param, void *value);
int controller_block_output_get_float(char *block, char *param, float *value);
int controller_block_connect(char *outblock, char *outterm,
......@@ -206,17 +194,9 @@ int controller_block_link(void);
struct controller_block_link *controller_block_link_get(int nr);
int controller_block_link_nr(void);
void controller_block_trace_init(int max);
int controller_block_trace_add(char *block, char *outterm,
struct controller_trace *trace);
void controller_block_trace_del(struct controller_trace *trace);
void controller_block_trace_wait(void);
int controller_block_sample_init(void);
void controller_block_calculate(void);
void controller_block_trace(void);
void controller_block_param_handle(void);
char *controller_block_context_get(void);
void controller_block_context_set(char *new_context);
......@@ -232,4 +212,34 @@ void controller_block_free(struct controller_block *blk);
#define DEG2RAD(val) ((val)*2.0*M_PI/360.0)
#define RAD2DEG(val) ((val)*360.0/(2.0*M_PI))
/*
controller_block_param
*/
/* List of params which must be initialized in the block's param pointer */
struct controller_block_param_list {
char *name;
bool sample; /* True: all access to params must be 'sample safe' */
};
void controller_block_param_init(void);
int controller_block_param_list_init(struct controller_block *block,
struct controller_block_param_list *list);
int controller_block_param_set(char *block, char *param, va_list);
int controller_block_param_get(char *block, char *param, void *value);
void controller_block_param_handle(void);
/*
controller_block_trace
*/
void controller_block_trace_init(int max);
int controller_block_trace_add(char *block, char *outterm,
struct controller_trace *trace);
void controller_block_trace_del(struct controller_trace *trace);
void controller_block_trace_wait(void);
void controller_block_trace(void);
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment