/*
 * 21g.h
 *
 *  Created on: 07-03-2018
 *      Author: Krzysztof Jakubczyk
 */

#ifndef R21G_H_
#define R21G_H_

#include "tdefs.h"
#include "helper.h"
#include "analog_in.h"

#define S_OFF	0
#define S_FWD	1
#define S_BKW	2
#define S_BID	3

struct r21g_logic
{
	struct binary_io stan_bl;
	struct binary_io test;
	float *U_esk;
	float *U_orta;
	float *U_ortb;
	float *I_esk;
	float *I_orta;
	float *I_ortb;

	struct analog_in_params *U_param;
	struct analog_in_params *I_param;

	struct binary_io P;
	struct binary_io Z;
	struct binary_io W;

	float y_rozr;
	float y_powr;
	float g_rozr;
	float g_powr;
	float b_rozr;
	float b_powr;
	float u_rozr;
	float u_powr;
	float umin_rozr;
	float umin_powr;
	float imin_rozr;
	float imin_powr;
	u8 p;
	u8 z;

	u8 pobi;
	u8 pobu;
	u8 poby;
	u8 pobg;
	u8 pobb;

	short lpi;
	short lpu;
	short lpy;
	short lpg;
	short lpb;

	float *y;
	float *g;
	float *b;

	float przek;
	u32 td;
	u32 td_cnt;
	float cos_shift;
	float sin_shift;
};

struct r21g_io
{
	u32 stan_bl_in;
	u32 test_in;
	u32 U_esk_float_in;
	u32 U_orta_float_in;
	u32 U_ortb_float_in;
	u32 U_param_ptr_in;
	u32 I_esk_float_in;
	u32 I_orta_float_in;
	u32 I_ortb_float_in;
	u32 I_param_ptr_in;
	u32 p_out;
	u32 z_out;
	u32 w_out;
	u32 y_float_out;
	u32 g_float_out;
	u32 b_float_out;
}__attribute__((__packed__));

struct r21g_params
{
	u32 bity;
	u32 y_enum;
	double yr;
	u32 g_enum;
	double gr;
	u32 b_enum;
	double br;
	double phi_corr;
	double kp;
	double td;
	double umin;
	double imin;
	u32 log_enum;
}__attribute__((__packed__));

struct r21g_args
{
	struct r21g_io io;
	struct r21g_params params;
//	u16 crc;
}__attribute__((__packed__));

extern int r21g_initlog(void *arguments, void *logic);
extern void r21g(void *arguments, void *logic);

#endif /* 21G_H_ */
