/**************************************************************************
	Description: Функции для приёма и выдачи параметров.

	Автор: Улитовский Д.И.
	Дата последнего обновления: 2021.11.08
**************************************************************************/

#include "param.h"

int Unites[UNIT_QUA_UNITS][UNIT_LEN];
int CAN_timeout[UNIT_QUA];
RS_DATA_STRUCT rs_a = RS_DATA_STRUCT_DEFAULT, rs_b = RS_DATA_STRUCT_DEFAULT;

// Изменяет значение параметра
void readInputParameters(const real_T *u) {
	int nn = 0;

	iq_norm_ADC[0][0] = _IQ(u[nn++]/NORMA_ACP);
	iq_norm_ADC[0][1] = _IQ(u[nn++]/NORMA_ACP);
	iq_norm_ADC[0][2] = _IQ(u[nn++]/NORMA_ACP);
	iq_norm_ADC[0][3] = _IQ(u[nn++]/NORMA_ACP);
	iq_norm_ADC[0][4] = _IQ(u[nn++]/NORMA_ACP);
	iq_norm_ADC[0][5] = _IQ(u[nn++]/NORMA_ACP);
	iq_norm_ADC[0][6] = _IQ(u[nn++]/NORMA_ACP);
	iq_norm_ADC[0][7] = _IQ(u[nn++]/NORMA_ACP);

	WRotor.iqWRotorSumFilter = _IQ(u[nn++] / PI2 / NORMA_FROTOR);

	u[nn++];

	edrk.Go = u[nn++];

	u[nn++];
	edrk.Mode_ScalarVectorUFConst = ALG_MODE_FOC_OBOROTS;

	edrk.zadanie.iq_power_zad = _IQ(u[nn++]);
	edrk.zadanie.iq_oborots_zad_hz = _IQ(u[nn++]);

	edrk.MasterSlave = MODE_MASTER;
	edrk.master_theta;
	edrk.master_Iq;
	edrk.iq_power_kw_another_bs;
	edrk.tetta_to_slave;
	edrk.Iq_to_slave;
	edrk.P_to_master;

	uf_alg.winding_displacement_bs1;
} //void input_param(unsigned short num, unsigned short val)


void writeOutputParameters(real_T* xD) {
	int nn = 0;

	xD[nn++] = t1sim.ciA;
	xD[nn++] = t2sim.ciA;
	xD[nn++] = t1sim.ciB;
	xD[nn++] = t2sim.ciB;

	xD[nn++] = t3sim.ciA;
	xD[nn++] = t4sim.ciA;
	xD[nn++] = t3sim.ciB;
	xD[nn++] = t4sim.ciB;

	xD[nn++] = t5sim.ciA;
	xD[nn++] = t6sim.ciA;
	xD[nn++] = t5sim.ciB;
	xD[nn++] = t6sim.ciB;
	

	xD[nn++] = t7sim.ciA;
	xD[nn++] = t8sim.ciA;
	xD[nn++] = t7sim.ciB;
	xD[nn++] = t8sim.ciB;

	xD[nn++] = t9sim.ciA;
	xD[nn++] = t10sim.ciA;
	xD[nn++] = t9sim.ciB;
	xD[nn++] = t10sim.ciB;

	xD[nn++] = t11sim.ciA;
	xD[nn++] = t12sim.ciA;
	xD[nn++] = t11sim.ciB;
	xD[nn++] = t12sim.ciB;

	// Только для просмотра
	xD[nn++] = xpwm_time.Ta0_0;
	xD[nn++] = xpwm_time.Ta0_1;
	xD[nn++] = xpwm_time.Tb0_0;
	xD[nn++] = xpwm_time.Tb0_1;
	xD[nn++] = xpwm_time.Tc0_0;
	xD[nn++] = xpwm_time.Tc0_1;

	xD[nn++] = _IQtoF(edrk.Iq_to_slave);
	xD[nn++] = _IQtoF(WRotor.iqWRotorSumFilter);
	xD[nn++] = 0;
	xD[nn++] = 0;

	xD[nn++] = _IQtoF(WRotor.iqWRotorSumFilter);

}