예제 #1
0
파일: oesr_log.c 프로젝트: agelonch/aloe
/**
 * Writes the buffer str to the log file associated to the handler log.
 * Only up to LSTR_LEN characters of the string will be copied to the log buffer.
 *
 * \param log Handler obtained by oesr_log_create()
 * \param str String to write to the buffer
 *
 * \returns 0 on success, -1 on error
 */
int oesr_log_write(log_t log, char *str) {
	oesr_log_t *l = (oesr_log_t*) log;
	oesr_context_t *ctx = l->context;
	OESR_ASSERT_PARAM(log);
	OESR_ASSERT_PARAM(str);
	sdebug("log_id=%s, buffer_len=%d\n",l->id, strnlen(l->buffer,LSTR_LEN));
	strncat(l->buffer,str,LSTR_LEN);
	return 0;
}
예제 #2
0
파일: oesr_log.c 프로젝트: agelonch/aloe
/**
 * Writes a formated string to the log file associated to the handler log.
 * \param log Handler obtained by oesr_log_create()
 * \param fmt String format
 *
 * \returns 0 on success, -1 on error
 */
int oesr_log_printf(log_t log, const char *fmt, ...) {
	oesr_log_t *l = (oesr_log_t*) log;
	oesr_context_t *ctx = l->context;
	OESR_ASSERT_PARAM(log);
	OESR_ASSERT_PARAM(fmt);
	va_list args;
	va_start(args,fmt);
	vsnprintf(tmp_buffer,LSTR_LEN,fmt,args);
	return oesr_log_write(log,tmp_buffer);
}
예제 #3
0
/**
 * Returns the current counter value after the last call to oesr_counter_stop().
 *
 */
int oesr_counter_usec(counter_t counter) {
	oesr_counter_t *cnt = (oesr_counter_t*) counter;
	oesr_context_t *ctx = cnt->context;
	OESR_ASSERT_PARAM(counter);

	return cnt->count[0].tv_usec;
}
예제 #4
0
/**
 * Initializes a counter object. This function is called by the oesr_counter_create().
 * It calls nod_module_variable_create() to create a new module variable, which is associated to the
 * counter. Then uses nod_variable_init() to allocate the memory.
 */
int oesr_counter_init(void *context, oesr_counter_t *counter, string name) {
	sdebug("context=0x%x, counter_id=%d, name=%s\n",context,counter->id,name);
	oesr_context_t *ctx = context;
	nod_module_t *module = ctx->module;
	OESR_ASSERT_PARAM(counter);
	OESR_ASSERT_PARAM(name);
	variable_t *variable = nod_module_variable_create(module, name,0);
	if (!variable) {
		return -1;
	}
	variable->size = sizeof(int);
	variable->cur_value = &counter->count[0].tv_usec;
	sdebug("variable_id=%d, addr=0x%x\n",variable->id,variable->cur_value);
	counter->variable = variable;
	counter->context = ctx;
	return 0;
}
예제 #5
0
/**
 * Starts the counter clock.
 *
 * \param counter Value returned by the oesr_counter_create() function
 * \returns 0 on success or -1 on error.
 */
int oesr_counter_start(counter_t counter) {
	oesr_counter_t *cnt = (oesr_counter_t*) counter;
	oesr_context_t *ctx = cnt->context;
	OESR_ASSERT_PARAM(counter);
	rtdal_time_get(&cnt->count[1]);
	sdebug("context=0x%x, counter_id=%d, start=%d:%d\n",ctx,cnt->id,
			cnt->count[1].tv_sec,cnt->count[1].tv_usec);
	return -1;
}
예제 #6
0
파일: oesr_var.c 프로젝트: alring/aloe
/**
 * Closes a variable handler. After a call to this function, ALOE can not access to
 * this variable anymore. However, the module may still use the contents of the memory address
 * passed as a parameter in the oesr_var_create() function.
 *
 * \param context OESR context pointer
 * \param parameter Handler returned by the oesr_var_param_get() function.
 *
 * \returns 0 on success, -1 on error
 */
int oesr_var_close(void *context, var_t var) {
	cast(ctx,context);
	variable_t *variable = (variable_t*) var;
	OESR_ASSERT_PARAM(var);
	variable->size = 0;
	variable->id = 0;
	variable->cur_value = NULL;
	return 0;
}
예제 #7
0
파일: oesr_var.c 프로젝트: alring/aloe
/**
 * Returns the parameter variable type (see enum oesr_var_type_t)
 * \param context OESR context pointer
 * \param parameter Handler returned by the oesr_var_param_get() function.
 */
oesr_var_type_t oesr_var_param_type(void *context, var_t parameter) {
	cast(ctx,context);

	sdebug("id=0x%x\n",parameter);

	OESR_ASSERT_PARAM(parameter);

	variable_t *variable = (variable_t*) parameter;
	return (oesr_var_type_t) variable->type;
}
예제 #8
0
파일: oesr_var.c 프로젝트: alring/aloe
/**
 * Fills the buffer parameters with up to max_elems module parameters defined in the app
 *
 * \param context OESR context pointer
 * \param parameter Pointer to a parameters buffer
 * \param max_elems Size of the parameters buffer
 *
 * \return On success, returns a non-negative number indicating the number of parameters
 * successfully copied to the buffer, on error returns -1
 */
int oesr_var_param_list(void *context, var_t *parameters, int max_elems) {
	cast(ctx,context);
	int i;

	OESR_ASSERT_PARAM(parameters);
	OESR_ASSERT_PARAM(max_elems>=0);

	nod_module_t *module = (nod_module_t*) ctx->module;

	if (max_elems > module->parent.nof_variables) {
		max_elems = module->parent.nof_variables;
	}
	for (i=0;i<max_elems;i++) {
		parameters[i] = (var_t) &module->parent.variables[i];
		sdebug("list %d %s id=0x%x size %d\n",i,module->parent.variables[i].name,
				parameters[i],module->parent.variables[i].size);
	}
	return max_elems;
}
예제 #9
0
파일: oesr_var.c 프로젝트: alring/aloe
/** Sets up to size bytes of the value of the parameter to the value of the
 * buffer pointed by ptr to the
 *
 * \param context OESR context pointer
 * \param parameter Handler returned by the oesr_var_param_get() function.
 * \param value Pointer to the user memory where the parameter value will be stored
 * \param size Size of user memory buffer
 *
 * \return On success, returns a non-negative integer indicating the number of bytes written to value.
 * On error returns -1
 */
int oesr_var_param_set_value(void *context, var_t parameter, void* value, int size) {
	int cpy_sz;

	cast(ctx,context);

	sdebug("set_value id=0x%x, size=%d\n",parameter,size);

	OESR_ASSERT_PARAM(parameter);
	OESR_ASSERT_PARAM(value);
	OESR_ASSERT_PARAM(size>0);

	nod_module_t *module = (nod_module_t*) ctx->module;
	variable_t *variable = (variable_t*) parameter;

	cpy_sz = (size > variable->size)?variable->size:size;

	memcpy(variable->init_value[module->parent.mode.cur_mode], value, (size_t) cpy_sz);
	sdebug("id=0x%x, copied=%d\n", parameter, cpy_sz);
	return cpy_sz;
}
예제 #10
0
파일: oesr_log.c 프로젝트: agelonch/aloe
/**
 * Called from oesr_log_create. Initializes the structure and creates the associated
 * filename for writing logs.
 */
int oesr_log_init(void *context, oesr_log_t *log, string name) {
	oesr_context_t *ctx = context;
	nod_module_t *module = ctx->module;
	sdebug("log_name=%s\n",name);
	lstrdef(tmp);
	OESR_ASSERT_PARAM(log);
	OESR_ASSERT_PARAM(name);
	snprintf(tmp,LSTR_LEN,"%s.%s",module->parent.name,name);
	sdebug("filename=%s\n",tmp);
	int fd = rtdal_file_open(tmp);
	if (fd < 0) {
		OESR_HWERROR("rtdal_file_open");
		return -1;
	}
	sdebug("log_fd=%d\n",fd);
	log->fd = fd;
	log->context = ctx;
	strcpy(log->name,name);
	return 0;
}
예제 #11
0
/**
 *  Stops the counter clock and sets the elapsed time.
 *
 * \param counter Value returned by the oesr_counter_create() function
 * \returns 0 on success or -1 on error.
 */
int oesr_counter_stop(counter_t counter) {
	oesr_counter_t *cnt = (oesr_counter_t*) counter;
	oesr_context_t *ctx = cnt->context;
	OESR_ASSERT_PARAM(counter);
	variable_t *variable = cnt->variable;

	rtdal_time_get(&cnt->count[2]);
	rtdal_time_interval(cnt->count);
	sdebug("context=0x%x, counter_id=%d, finish=%d:%d, count=%d, value=0x%x\n",ctx,cnt->id,
			cnt->count[2].tv_sec,cnt->count[2].tv_usec,cnt->count[0].tv_usec,
			variable->cur_value);
	return 0;
}
예제 #12
0
파일: oesr_var.c 프로젝트: alring/aloe
/** Sets up to size bytes of the value of the parameter to the value of the
 * buffer pointed by ptr to the
 *
 * \param context OESR context pointer
 * \param idx Index of the parameter in the local database
 * \param value Pointer to the user memory where the parameter value will be stored
 * \param size Size of user memory buffer
 *
 * \return On success, returns a non-negative integer indicating the number of bytes written to value.
 * On error returns -1
 */
int oesr_var_param_set_value_idx(void *context, int idx, void* value, int size) {
	int cpy_sz;

	cast(ctx,context);

	sdebug("%s: set_value_idx idx=%d, value 0x%x size=%d\n",oesr_module_name(ctx),idx,value,size);
	OESR_ASSERT_PARAM(idx>=0);
	OESR_ASSERT_PARAM(value);
	OESR_ASSERT_PARAM(size>0);

	nod_module_t *module = (nod_module_t*) ctx->module;
	variable_t *variable = (variable_t*) &module->parent.variables[idx];

	sdebug("%s: %d:%s: set variable %s value %d\n",oesr_module_name(ctx),oesr_tstamp(context),
				module->parent.name,variable->name,*((int*) value));

	cpy_sz = (size > variable->size)?variable->size:size;

	memcpy(variable->init_value[module->parent.mode.cur_mode], value, (size_t) cpy_sz);
	sdebug("id=0x%x, copied=%d\n", variable, cpy_sz);
	return cpy_sz;
}
예제 #13
0
파일: oesr_log.c 프로젝트: agelonch/aloe
/**
 * Closes a log associated to the handler passed as parameter.
 * \param log Handler obtained by oesr_log_create()
 *
 * \returns 0 on success, -1 on error
 */
int oesr_log_close(log_t log) {
	oesr_log_t *l = (oesr_log_t*) log;
	oesr_context_t *ctx = l->context;
	sdebug("log_id=%s, fd=%d\n",l->id, l->fd);
	OESR_ASSERT_PARAM(log);
	if (rtdal_file_close(l->fd)) {
		OESR_HWERROR("rtdal_file_close");
		return -1;
	}
	l->fd = 0;
	l->id = 0;
	return 0;
}
예제 #14
0
/**
 *
 * oesr_counter_close() closes a counter and deallocates its resources. The counter can not be used
 * after a call to this function.
 *
 * \param counter Value returned by the oesr_counter_create() function
 * \returns 0 if successfully closed or -1 on error.
 */
int oesr_counter_close(counter_t counter) {
	oesr_counter_t *cnt = (oesr_counter_t*) counter;
	oesr_context_t *ctx = cnt->context;
	sdebug("context=0x%x, counter_id=%d\n",ctx,cnt->id);
	OESR_ASSERT_PARAM(counter);
	variable_t *variable = cnt->variable;
	if (variable) {
		variable->id = 0;
		variable->size = 0;
	}
	cnt->id = 0;
	cnt->variable = NULL;
	return 0;
}
예제 #15
0
파일: oesr_var.c 프로젝트: alring/aloe
/** Sets up to size bytes of the buffer pointed by ptr to the value of the parameter
 * returned by oesr_var_param_get()
 *
 * \param context OESR context pointer
 * \param parameter Handler returned by the oesr_var_param_get() function.
 * \param value Pointer to the user memory where the parameter value will be stored
 * \param size Size of user memory buffer
 *
 * \return On success, returns a non-negative integer indicating the number of bytes written to value.
 * On error returns -1
 */
int oesr_var_param_get_value(void *context, var_t parameter, void* value, int size) {
	int cpy_sz;

	cast(ctx,context);

	OESR_ASSERT_PARAM(parameter);
	OESR_ASSERT_PARAM(value);
	OESR_ASSERT_PARAM(size>0);

	nod_module_t *module = (nod_module_t*) ctx->module;
	variable_t *variable = (variable_t*) parameter;

	sdebug("id=0x%x, size=%d, value=0x%x, cur_mode=%d\n",parameter,size,value,module->parent.mode.cur_mode);

	cpy_sz = (variable->size > size)?size:variable->size;
	if (module->parent.mode.next_tslot &&
			module->parent.mode.next_tslot <= rtdal_time_slot()) {
		module->parent.mode.cur_mode = module->parent.mode.next_mode;
		module->parent.mode.next_tslot = 0;
	}
	memcpy(value, variable->init_value[module->parent.mode.cur_mode], (size_t) cpy_sz);
	sdebug("id=0x%x, copied=%d\n", variable, cpy_sz);
	return cpy_sz;
}