/*
 * kier_pr.h
 *
 *  Created on: 27-02-2018
 *      Author: Krzysztof Jakubczyk
 */

#ifndef E_KIER_PR_H_
#define E_KIER_PR_H_

#include "../tdefs.h"
#include "helper.h"

struct dane_wewnetrzne_kier_pr
{
		short lp[3]; ///<licznik filtracji pobudzen
		u8 zadz[4];///< pobudzenie przekaznika faza 1

		short lp_u[3];
		u8 pob_u[3];
		short lp_i[3];
		u8 pob_i[3];

		short lp_phi[3];
		u8 pob_phi[3];
};

struct kier_pr_logic
{
	struct binary_io stan_bl;
	struct binary_io test;
	struct binary_io PL1;
	struct binary_io PL2;
	struct binary_io PL3;
	struct binary_io P3F;
	struct binary_io ZL1;
	struct binary_io ZL2;
	struct binary_io ZL3;
	struct binary_io Z3F;
	struct binary_io WL1;
	struct binary_io WL2;
	struct binary_io WL3;
	struct binary_io W3F;

	float *UL_orta[3];
	float *UL_ortb[3];
	float *UL_esk[3];

	float *IL_orta[3];
	float *IL_ortb[3];
	float *IL_esk[3];

	u8 pob[4];

	float umin;
	float umin_hyst;
	float imin;
	float imin_hyst;
	float imax;
	float imax_hyst;
	float phi_min_hyst;
	float phi_max_hyst;
	u8 phi_max_ov;
	u8 phi_min_ov;
	u32 td;
	struct dane_wewnetrzne_kier_pr dw;
};

struct kier_pr_io
{
	u32 stan_bl_in;
	u32 test_in;
	u32 UL1_orta_float_in;
	u32 UL1_ortb_float_in;
	u32 UL1_esk_float_in;
	u32 UL2_orta_float_in;
	u32 UL2_ortb_float_in;
	u32 UL2_esk_float_in;
	u32 UL3_orta_float_in;
	u32 UL3_ortb_float_in;
	u32 UL3_esk_float_in;

	u32 IL1_orta_float_in;
	u32 IL1_ortb_float_in;
	u32 IL1_esk_float_in;
	u32 IL2_orta_float_in;
	u32 IL2_ortb_float_in;
	u32 IL2_esk_float_in;
	u32 IL3_orta_float_in;
	u32 IL3_ortb_float_in;
	u32 IL3_esk_float_in;

	u32 pl1_out;
	u32 pl2_out;
	u32 pl3_out;
	u32 p3f_out;
	u32 zl1_out;
	u32 zl2_out;
	u32 zl3_out;
	u32 z3f_out;
	u32 wl1_out;
	u32 wl2_out;
	u32 wl3_out;
	u32 w3f_out;

}__attribute__((__packed__));

struct kier_pr_params
{
	u32 bity;
	double U_min;
	double I_min;
	double phi_min;
	double phi_max;
	double td;
	double kp_ui;
	double kp_phi;
	double I_max;
}__attribute__((__packed__));

struct kier_pr_args
{
	struct kier_pr_io io;
	struct kier_pr_params params;
//	u16 crc;
}__attribute__((__packed__));

extern int kier_pr_initlog(void *arguments, void *logic);
extern void kier_pr(void *arguments, void *logic);

#endif /* KIER_PR_H_ */
