/*
 * rec_an.c
 *
 *  Created on: 18-01-2021
 *      Author: KJ
 */


#include "tdefs.h"
#include "misc.h"

#include "rec_buf.h"

int rec_buf_initlog(void *arguments, void *logic)
{
	struct rec_buf_args *args = (struct rec_buf_args *)arguments;
	struct rec_buf_logic *log = (struct rec_buf_logic *)logic;

	u32 *an_params_ptr;
	u32 *buf_ptr;

	buf_ptr = (u32 *)(log_manager.nets_data + (args->io.buf_u16_ptr_in >> 3));
	if((u8*)buf_ptr > (log_manager.nets_data+sizeof(log_manager.nets_data) - sizeof(void *)))
		return -1;

	if(!*buf_ptr) // param in not connected or wrong elements order (analog_in should be run before)
		return -1;

	log->buf_ptr=(u16*)*buf_ptr;

	an_params_ptr = (u32 *)(log_manager.nets_data + (args->io.param_an_ptr_in >> 3));
	if((u8*)an_params_ptr > (log_manager.nets_data+sizeof(log_manager.nets_data) - sizeof(void *)))
		return -1;

	if(!*an_params_ptr) // param in not connected or wrong elements order (analog_in should be run before)
		return -1;

	log->an_params=(struct analog_in_params *)*an_params_ptr;

	return 0;
}

