/*
 * destream.c
 *
 *  Created on: 23-04-2019
 *      Author: Krzysztof Jakubczyk
 */

#include <math.h>

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

#include "helper.h"
#include "destream.h"
#include "analog_in.h"

int destream_initlog(void *arguments, void *logic)
{
	struct destream_args *args = (struct destream_args *)arguments;
	struct destream_logic *log = (struct destream_logic *)logic;
	u8 i;

	if(set_pointer_in_ptr(args->io.stream_ptr_in,(u32*)&log->stream))
		return -1;

	if(set_float_ptr(args->io.A1L1_float_out,&log->A[0]))
		return -1;
	if(set_float_ptr(args->io.A1L2_float_out,&log->A[1]))
		return -1;
	if(set_float_ptr(args->io.A1L3_float_out,&log->A[2]))
		return -1;
	if(set_float_ptr(args->io.snum_float_out,&log->snum))
		return -1;

	for(i=0;i<16;i++)
		if(set_bit_ptr_struct(args->io.b_out[i],&log->b[i]))
			return -1;

	return 0;
}

void destream(void *arguments, void *logic)
{
	struct destream_logic *log = (struct destream_logic *)logic;
//	struct destream_args *args = (struct mkstream_args *)arguments;

	u32 i;

	for(i=0;i<3;i++)
	{
		*log->A[i]=log->stream->A[i];
		*log->snum=(float)log->stream->sample_stamp;
	}

	for(i=0;i<16;i++)
		check_and_set_struct(log->stream->bits & (1<<i),&log->b[i]);

}
